-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/persistence-ticketing
- Loading branch information
Showing
29 changed files
with
1,114 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/thirdparty/ticketing/domain/waiting/WaitingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.thirdparty.ticketing.domain.waiting; | ||
|
||
import java.util.Map; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.thirdparty.ticketing.domain.common.LoginMember; | ||
import com.thirdparty.ticketing.domain.waiting.manager.WaitingManager; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api") | ||
public class WaitingController { | ||
|
||
private final WaitingManager waitingManager; | ||
|
||
@GetMapping("/performances/{performanceId}/wait") | ||
public ResponseEntity<Map<String, Long>> getCounts( | ||
@LoginMember String email, @PathVariable("performanceId") Long performanceId) { | ||
long remainingCount = waitingManager.getRemainingCount(email, performanceId); | ||
return ResponseEntity.ok(Map.of("remainingCount", remainingCount)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/main/java/com/thirdparty/ticketing/domain/waiting/room/WaitingCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.thirdparty.ticketing.domain.waiting.room; | ||
|
||
import com.thirdparty.ticketing.domain.waiting.WaitingMember; | ||
|
||
public interface WaitingCounter { | ||
|
||
/** | ||
* @return 사용자에게 부여되는 고유한 카운트를 반환한다. | ||
*/ | ||
long getNextCount(Long performanceId); | ||
long getNextCount(WaitingMember waitingMember); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/com/thirdparty/ticketing/global/config/WaitingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.thirdparty.ticketing.global.config; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.thirdparty.ticketing.domain.waiting.manager.WaitingManager; | ||
import com.thirdparty.ticketing.domain.waiting.room.RunningRoom; | ||
import com.thirdparty.ticketing.domain.waiting.room.WaitingCounter; | ||
import com.thirdparty.ticketing.domain.waiting.room.WaitingLine; | ||
import com.thirdparty.ticketing.domain.waiting.room.WaitingRoom; | ||
import com.thirdparty.ticketing.global.waiting.manager.RedisWaitingManager; | ||
import com.thirdparty.ticketing.global.waiting.room.RedisRunningRoom; | ||
import com.thirdparty.ticketing.global.waiting.room.RedisWaitingCounter; | ||
import com.thirdparty.ticketing.global.waiting.room.RedisWaitingLine; | ||
import com.thirdparty.ticketing.global.waiting.room.RedisWaitingRoom; | ||
|
||
@Configuration | ||
public class WaitingConfig { | ||
|
||
@Bean | ||
public WaitingManager waitingManager( | ||
RunningRoom runningRoom, | ||
WaitingRoom waitingRoom, | ||
@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) { | ||
return new RedisWaitingManager(runningRoom, waitingRoom, redisTemplate); | ||
} | ||
|
||
@Bean | ||
public WaitingRoom waitingRoom( | ||
WaitingLine waitingLine, | ||
WaitingCounter waitingCounter, | ||
@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate, | ||
ObjectMapper objectMapper) { | ||
return new RedisWaitingRoom(waitingLine, waitingCounter, redisTemplate, objectMapper); | ||
} | ||
|
||
@Bean | ||
public WaitingLine waitingLine( | ||
ObjectMapper objectMapper, | ||
@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) { | ||
return new RedisWaitingLine(objectMapper, redisTemplate); | ||
} | ||
|
||
@Bean | ||
public WaitingCounter waitingCounter( | ||
@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) { | ||
return new RedisWaitingCounter(redisTemplate); | ||
} | ||
|
||
@Bean | ||
public RunningRoom runningRoom( | ||
@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) { | ||
return new RedisRunningRoom(redisTemplate); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/thirdparty/ticketing/global/waiting/ObjectMapperUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.thirdparty.ticketing.global.waiting; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.thirdparty.ticketing.domain.common.ErrorCode; | ||
import com.thirdparty.ticketing.domain.common.TicketingException; | ||
|
||
public class ObjectMapperUtils { | ||
|
||
public static String writeValueAsString(ObjectMapper objectMapper, Object value) { | ||
try { | ||
return objectMapper.writeValueAsString(value); | ||
} catch (JsonProcessingException e) { | ||
throw new TicketingException(ErrorCode.WAITING_WRITE_ERROR); | ||
} | ||
} | ||
|
||
public static <T> T readValue(ObjectMapper objectMapper, String value, Class<T> valueType) { | ||
try { | ||
return objectMapper.readValue(value, valueType); | ||
} catch (JsonProcessingException e) { | ||
throw new TicketingException(ErrorCode.WAITING_READ_ERROR); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/thirdparty/ticketing/global/waiting/manager/RedisWaitingManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.thirdparty.ticketing.global.waiting.manager; | ||
|
||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
|
||
import com.thirdparty.ticketing.domain.waiting.WaitingMember; | ||
import com.thirdparty.ticketing.domain.waiting.manager.WaitingManager; | ||
import com.thirdparty.ticketing.domain.waiting.room.RunningRoom; | ||
import com.thirdparty.ticketing.domain.waiting.room.WaitingRoom; | ||
|
||
public class RedisWaitingManager extends WaitingManager { | ||
|
||
private static final String MANAGED_MEMBER_COUNTER_KEY = "managed_member_counter:"; | ||
|
||
private final ValueOperations<String, String> managedMemberCounter; | ||
|
||
public RedisWaitingManager( | ||
RunningRoom runningRoom, WaitingRoom waitingRoom, StringRedisTemplate redisTemplate) { | ||
super(runningRoom, waitingRoom); | ||
managedMemberCounter = redisTemplate.opsForValue(); | ||
} | ||
|
||
@Override | ||
protected long countManagedMember(WaitingMember waitingMember) { | ||
String key = getPerformanceManagedMemberCounterKey(waitingMember); | ||
managedMemberCounter.setIfAbsent(key, "0"); // todo: 불필요하게 네트워크를 탐. 추후 개선 필요 | ||
return Long.parseLong(managedMemberCounter.get(key)); | ||
} | ||
|
||
@Override | ||
public long getRemainingCount(String email, Long performanceId) { | ||
return 0; | ||
} | ||
|
||
private String getPerformanceManagedMemberCounterKey(WaitingMember waitingMember) { | ||
return MANAGED_MEMBER_COUNTER_KEY + waitingMember.getPerformanceId(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/thirdparty/ticketing/global/waiting/room/RedisRunningRoom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.thirdparty.ticketing.global.waiting.room; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.core.SetOperations; | ||
|
||
import com.thirdparty.ticketing.domain.waiting.WaitingMember; | ||
import com.thirdparty.ticketing.domain.waiting.room.RunningRoom; | ||
|
||
public class RedisRunningRoom implements RunningRoom { | ||
|
||
private static final String RUNNING_ROOM_KEY = "running_room:"; | ||
|
||
private final SetOperations<String, String> runningRoom; | ||
|
||
public RedisRunningRoom(RedisTemplate<String, String> redisTemplate) { | ||
runningRoom = redisTemplate.opsForSet(); | ||
} | ||
|
||
@Override | ||
public boolean contains(WaitingMember waitingMember) { | ||
return runningRoom.isMember( | ||
getPerformanceRunningRoomKey(waitingMember), waitingMember.getEmail()); | ||
} | ||
|
||
@Override | ||
public void put(long performanceId, List<WaitingMember> waitingMembers) {} | ||
|
||
private String getPerformanceRunningRoomKey(WaitingMember waitingMember) { | ||
return RUNNING_ROOM_KEY + waitingMember.getPerformanceId(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/thirdparty/ticketing/global/waiting/room/RedisWaitingCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.thirdparty.ticketing.global.waiting.room; | ||
|
||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.springframework.data.redis.core.ValueOperations; | ||
|
||
import com.thirdparty.ticketing.domain.waiting.WaitingMember; | ||
import com.thirdparty.ticketing.domain.waiting.room.WaitingCounter; | ||
|
||
public class RedisWaitingCounter implements WaitingCounter { | ||
|
||
private static final String WAITING_COUNTER_KEY = "waiting_counter"; | ||
|
||
private final ValueOperations<String, String> counter; | ||
|
||
public RedisWaitingCounter(StringRedisTemplate redisTemplate) { | ||
this.counter = redisTemplate.opsForValue(); | ||
} | ||
|
||
@Override | ||
public long getNextCount(WaitingMember waitingMember) { | ||
String performanceWaitingCounterKey = | ||
WAITING_COUNTER_KEY + waitingMember.getPerformanceId(); | ||
return counter.increment(performanceWaitingCounterKey, 1); | ||
} | ||
} |
Oops, something went wrong.