Skip to content

Commit

Permalink
refactor: 코드 포맷 정렬
Browse files Browse the repository at this point in the history
  • Loading branch information
hseong3243 committed Aug 15, 2024
1 parent 001c1af commit 388a3e7
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 204 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.thirdparty.ticketing.domain.common;

import lombok.Getter;
import org.springframework.http.HttpStatus;

import lombok.Getter;

@Getter
public enum ErrorCode {
BAD_REQUEST(HttpStatus.BAD_REQUEST, "C400", "올바르지 않은 요청입니다."),
Expand Down Expand Up @@ -47,8 +48,8 @@ public enum ErrorCode {
PAYMENT_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "P500-1", "결제에 실패했습니다."),

/*
Waiting Error
*/
Waiting Error
*/
WAITING_WRITE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "W500-1", "대기열 쓰기에 실패했습니다."),
WAITING_READ_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "W500-2", "대기열 읽기에 실패했습니다.");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package com.thirdparty.ticketing.domain.waitingroom;

import com.thirdparty.ticketing.domain.waitingroom.manager.WaitingManager;
import jakarta.servlet.http.HttpServletRequest;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import lombok.RequiredArgsConstructor;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.thirdparty.ticketing.domain.waitingroom.manager.WaitingManager;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class WaitingAspect {

private final WaitingManager waitingManager;

private Object waitingRequest(ProceedingJoinPoint joinPoint) throws Throwable {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
.getRequest();
String performanceId = request.getParameter("performanceId");

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thirdparty.ticketing.domain.waitingroom;

import java.time.ZonedDateTime;

import lombok.Data;
import lombok.NoArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.thirdparty.ticketing.domain.waitingroom.manager;

import com.thirdparty.ticketing.domain.waitingroom.room.RunningRoom;
import com.thirdparty.ticketing.domain.waitingroom.WaitingMember;
import com.thirdparty.ticketing.domain.waitingroom.room.RunningRoom;
import com.thirdparty.ticketing.domain.waitingroom.room.WaitingRoom;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
Expand All @@ -17,6 +18,7 @@ public boolean isReadyToHandle(WaitingMember waitingMember) {

/**
* 사용자를 대기열에 추가하고 남은 순번을 반환한다.
*
* @param waitingMember
* @return 사용자 앞에 남은 순번
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.thirdparty.ticketing.domain.waitingroom.room;

import com.thirdparty.ticketing.domain.waitingroom.WaitingMember;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.thirdparty.ticketing.global.config;

import lombok.Setter;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
Expand All @@ -11,6 +10,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

import lombok.Setter;

@Configuration
@ConfigurationProperties(prefix = "spring.data.redis.redisson")
@Setter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
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.waitingroom.manager.WaitingManager;
import com.thirdparty.ticketing.domain.waitingroom.room.RunningRoom;
Expand All @@ -11,40 +16,43 @@
import com.thirdparty.ticketing.global.waiting.room.RedisWaitingCounter;
import com.thirdparty.ticketing.global.waiting.room.RedisWaitingLine;
import com.thirdparty.ticketing.global.waiting.room.RedisWaitingRoom;
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;

@Configuration
public class WaitingConfig {

@Bean
public WaitingManager waitingManager(RunningRoom runningRoom, WaitingRoom waitingRoom,
@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) {
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) {
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) {
public WaitingLine waitingLine(
ObjectMapper objectMapper,
@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) {
return new RedisWaitingLine(objectMapper, redisTemplate);
}

@Bean
public WaitingCounter waitingCounter(@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) {
public WaitingCounter waitingCounter(
@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) {
return new RedisWaitingCounter(redisTemplate);
}

@Bean
public RunningRoom runningRoom(@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) {
public RunningRoom runningRoom(
@Qualifier("lettuceRedisTemplate") StringRedisTemplate redisTemplate) {
return new RedisRunningRoom(redisTemplate);
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
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.waitingroom.WaitingMember;
import com.thirdparty.ticketing.domain.waitingroom.manager.WaitingManager;
import com.thirdparty.ticketing.domain.waitingroom.room.RunningRoom;
import com.thirdparty.ticketing.domain.waitingroom.room.WaitingRoom;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

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) {
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: 불필요하게 네트워크를 탐. 추후 개선 필요
managedMemberCounter.setIfAbsent(key, "0"); // todo: 불필요하게 네트워크를 탐. 추후 개선 필요
return Long.parseLong(managedMemberCounter.get(key));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.thirdparty.ticketing.global.waiting.room;

import com.thirdparty.ticketing.domain.waitingroom.WaitingMember;
import com.thirdparty.ticketing.domain.waitingroom.room.RunningRoom;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;

import com.thirdparty.ticketing.domain.waitingroom.WaitingMember;
import com.thirdparty.ticketing.domain.waitingroom.room.RunningRoom;

public class RedisRunningRoom implements RunningRoom {

private static final String RUNNING_ROOM_KEY = "running_room:";
Expand All @@ -17,7 +18,8 @@ public RedisRunningRoom(RedisTemplate<String, String> redisTemplate) {

@Override
public boolean contains(WaitingMember waitingMember) {
return runningRoom.isMember(getPerformanceRunningRoomKey(waitingMember), waitingMember.getEmail());
return runningRoom.isMember(
getPerformanceRunningRoomKey(waitingMember), waitingMember.getEmail());
}

private String getPerformanceRunningRoomKey(WaitingMember waitingMember) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.thirdparty.ticketing.global.waiting.room;

import com.thirdparty.ticketing.domain.waitingroom.WaitingMember;
import com.thirdparty.ticketing.domain.waitingroom.room.WaitingCounter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import com.thirdparty.ticketing.domain.waitingroom.WaitingMember;
import com.thirdparty.ticketing.domain.waitingroom.room.WaitingCounter;

public class RedisWaitingCounter implements WaitingCounter {

private static final String WAITING_COUNTER_KEY = "waiting_counter";
Expand All @@ -18,7 +18,8 @@ public RedisWaitingCounter(StringRedisTemplate redisTemplate) {

@Override
public long getNextCount(WaitingMember waitingMember) {
String performanceWaitingCounterKey = WAITING_COUNTER_KEY + waitingMember.getPerformanceId();
String performanceWaitingCounterKey =
WAITING_COUNTER_KEY + waitingMember.getPerformanceId();
return counter.increment(performanceWaitingCounterKey, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.thirdparty.ticketing.global.waiting.room;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.waitingroom.WaitingMember;
import com.thirdparty.ticketing.domain.waitingroom.room.WaitingLine;
import com.thirdparty.ticketing.global.waiting.ObjectMapperUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;

public class RedisWaitingLine implements WaitingLine {

Expand All @@ -22,8 +23,9 @@ public RedisWaitingLine(ObjectMapper objectMapper, StringRedisTemplate redisTemp
@Override
public void enter(WaitingMember waitingMember) {
String performanceWaitingLineKey = WAITING_LINE_KEY + waitingMember.getPerformanceId();
String waitingMemberValue = ObjectMapperUtils.writeValueAsString(objectMapper, waitingMember);
waitingLine.add(performanceWaitingLineKey, waitingMemberValue, waitingMember.getWaitingCount());
String waitingMemberValue =
ObjectMapperUtils.writeValueAsString(objectMapper, waitingMember);
waitingLine.add(
performanceWaitingLineKey, waitingMemberValue, waitingMember.getWaitingCount());
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.thirdparty.ticketing.global.waiting.room;

import java.time.ZonedDateTime;

import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.thirdparty.ticketing.domain.waitingroom.WaitingMember;
import com.thirdparty.ticketing.domain.waitingroom.room.WaitingCounter;
import com.thirdparty.ticketing.domain.waitingroom.room.WaitingLine;
import com.thirdparty.ticketing.domain.waitingroom.room.WaitingRoom;
import com.thirdparty.ticketing.global.waiting.ObjectMapperUtils;
import java.time.ZonedDateTime;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;

public class RedisWaitingRoom extends WaitingRoom {

Expand All @@ -17,23 +19,29 @@ public class RedisWaitingRoom extends WaitingRoom {
private final HashOperations<String, String, String> waitingRoom;
private final ObjectMapper objectMapper;

public RedisWaitingRoom(WaitingLine waitingLine,
WaitingCounter waitingCounter,
RedisTemplate<String, String> redisTemplate, ObjectMapper objectMapper) {
public RedisWaitingRoom(
WaitingLine waitingLine,
WaitingCounter waitingCounter,
RedisTemplate<String, String> redisTemplate,
ObjectMapper objectMapper) {
super(waitingLine, waitingCounter);
waitingRoom = redisTemplate.opsForHash();
this.objectMapper = objectMapper;
}

@Override
public long enter(WaitingMember waitingMember) {
if(enterWaitingRoomIfNotExists(waitingMember)) {
waitingMember.updateWaitingInfo(waitingCounter.getNextCount(waitingMember), ZonedDateTime.now());
if (enterWaitingRoomIfNotExists(waitingMember)) {
waitingMember.updateWaitingInfo(
waitingCounter.getNextCount(waitingMember), ZonedDateTime.now());
waitingLine.enter(waitingMember);
updateWaitingRoomMember(waitingMember);
} else {
String rawValue = waitingRoom.get(getPerformanceWaitingRoomKey(waitingMember), waitingMember.getEmail());
waitingMember = ObjectMapperUtils.readValue(objectMapper, rawValue, WaitingMember.class);
String rawValue =
waitingRoom.get(
getPerformanceWaitingRoomKey(waitingMember), waitingMember.getEmail());
waitingMember =
ObjectMapperUtils.readValue(objectMapper, rawValue, WaitingMember.class);
}
return waitingMember.getWaitingCount();
}
Expand All @@ -46,7 +54,8 @@ private Boolean enterWaitingRoomIfNotExists(WaitingMember waitingMember) {

private void updateWaitingRoomMember(WaitingMember waitingMember) {
String value = ObjectMapperUtils.writeValueAsString(objectMapper, waitingMember);
waitingRoom.put(getPerformanceWaitingRoomKey(waitingMember), waitingMember.getEmail(), value);
waitingRoom.put(
getPerformanceWaitingRoomKey(waitingMember), waitingMember.getEmail(), value);
}

private String getPerformanceWaitingRoomKey(WaitingMember waitingMember) {
Expand Down
Loading

0 comments on commit 388a3e7

Please sign in to comment.