-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] EventUserArgumentResolver 적용 및 FE 요청에 따른 추가 API 구현 (#35) #38
Changes from 21 commits
59eaf16
e0fe948
b1fc018
17c0ad2
fd263e3
4a095b9
96903b0
7c50d87
732743c
b4f81dc
5348547
9c856c1
d52bd05
2063d85
5864bea
7fba82c
191b4ff
2f7cf59
7fa66a1
81b36a2
149dead
bf64b81
3348767
70bd40b
c6296c0
544357d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,19 @@ public class ConstantUtil { | |
public static final String PHONE_NUMBER_REGEX = "010\\d{8}"; // 010 + 8자리 숫자 | ||
public static final String AUTH_CODE_REGEX = "\\d{6}"; // 6자리 숫자 | ||
public static final String AUTH_CODE_CREATE_REGEX = "%06d"; | ||
public static final String CLAIMS_KEY = "user"; | ||
public static final String CLAIMS_USER_KEY = "userId"; | ||
public static final String CLAIMS_ROLE_KEY = "role"; | ||
public static final String CLAIMS_USER_NAME_KEY = "userName"; | ||
public static final String JWT_USER_KEY = "eventUser"; | ||
public static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
public static final String LOCATION = "Location"; | ||
|
||
public static final double LIMIT_NEGATIVE_CONFIDENCE = 99.5; | ||
public static final int COMMENTS_SIZE = 20; | ||
public static final int SCHEDULED_TIME = 1000 * 60 * 60 * 2; | ||
public static final int SHORT_URL_LENGTH = 10; | ||
public static final int USER_ID_LENGTH = 8; | ||
public static final int AUTH_CODE_LENGTH = 6; | ||
public static final int JWT_LIFESPAN = 1; // 1시간 | ||
public static final int AUTH_CODE_EXPIRE_TIME = 5; // 5분 | ||
Comment on lines
+15
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 파편화된 Key 문자열과 매직넘버를 상수로 관리하고자 했습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 것 같습니다. 저도 여기에다 admin 부분을 등록해서 변경해둬야겠네요 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
import hyundai.softeer.orange.admin.component.AdminArgumentResolver; | ||
import hyundai.softeer.orange.core.auth.AuthInterceptor; | ||
import hyundai.softeer.orange.eventuser.component.EventUserArgumentResolver; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
|
@@ -10,13 +12,13 @@ | |
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
@Autowired | ||
private AuthInterceptor authInterceptor; | ||
|
||
@Autowired | ||
private AdminArgumentResolver adminArgumentResolver; | ||
private final AuthInterceptor authInterceptor; | ||
private final AdminArgumentResolver adminArgumentResolver; | ||
private final EventUserArgumentResolver eventUserArgumentResolver; | ||
Comment on lines
+15
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필드 주입이 3개 이상이라 생성자 주입으로 바꾸었습니다. |
||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
|
@@ -28,5 +30,6 @@ public void addInterceptors(InterceptorRegistry registry) { | |
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { | ||
resolvers.add(adminArgumentResolver); | ||
resolvers.add(eventUserArgumentResolver); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,14 @@ | |
import hyundai.softeer.orange.core.jwt.JWTManager; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.method.HandlerMethod; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
import java.util.*; | ||
|
||
@Slf4j | ||
@Component // 문제 있으면 변경 | ||
public class AuthInterceptor implements HandlerInterceptor { | ||
private final JWTManager jwtManager; | ||
|
@@ -21,6 +23,11 @@ public AuthInterceptor(JWTManager jwtManager) { | |
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
// 유효하지 않은 요청은 정적 리소스로 간주하여 ResourceHttpRequestHandler가 대신 처리하기에, HandlerMethod가 아닌 경우는 무시 | ||
if (!(handler instanceof HandlerMethod)) { | ||
return true; | ||
} | ||
|
||
Comment on lines
+26
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 404가 발생해야 하는데 요청을 가로채는 과정에서 500이 뜨던 버그가 있어 수정했습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 내부 경로가 아니면 HandlerMethod가 아닌 handler이 올 수도 있다는 것을 새롭게 알게 되었네요. 기존에 swagger-ui 경로에 접근하지 못하던 문제도 이걸로 처리할 수 있었겠네요 |
||
HandlerMethod handlerMethod = (HandlerMethod) handler; | ||
|
||
Auth classAnnotation = handlerMethod.getClass().getAnnotation(Auth.class); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package hyundai.softeer.orange.event.fcfs.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ResponseFcfsInfoDto implements Serializable { | ||
|
||
@JsonSerialize(using = LocalDateTimeSerializer.class) // 직렬화 시 필요 | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS") | ||
private LocalDateTime nowDateTime; | ||
|
||
private String eventStatus; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package hyundai.softeer.orange.event.fcfs.service; | ||
|
||
import hyundai.softeer.orange.common.ErrorCode; | ||
import hyundai.softeer.orange.event.fcfs.dto.ResponseFcfsInfoDto; | ||
import hyundai.softeer.orange.event.fcfs.dto.ResponseFcfsWinnerDto; | ||
import hyundai.softeer.orange.event.fcfs.entity.FcfsEvent; | ||
import hyundai.softeer.orange.event.fcfs.entity.FcfsEventWinningInfo; | ||
|
@@ -69,6 +70,38 @@ public void registerWinners() { | |
} | ||
} | ||
|
||
// 특정 선착순 이벤트의 정보 조회 | ||
public ResponseFcfsInfoDto getFcfsInfo(Long eventSequence) { | ||
String startTime = stringRedisTemplate.opsForValue().get(FcfsUtil.startTimeFormatting(eventSequence.toString())); | ||
// 선착순 이벤트가 존재하지 않는 경우 | ||
if (startTime == null) { | ||
throw new FcfsEventException(ErrorCode.FCFS_EVENT_NOT_FOUND); | ||
} | ||
|
||
LocalDateTime nowDateTime = LocalDateTime.now(); | ||
LocalDateTime eventStartTime = LocalDateTime.parse(startTime); | ||
|
||
// 서버시간 < 이벤트시작시간 < 서버시간+3시간 -> countdown | ||
// 이벤트시작시간 < 서버시간 < 이벤트시작시간+7시간 -> progress | ||
// 그 외 -> waiting | ||
if(nowDateTime.isBefore(eventStartTime) && nowDateTime.plusHours(3).isAfter(eventStartTime)) { | ||
return new ResponseFcfsInfoDto(nowDateTime, "countdown"); | ||
} else if(eventStartTime.isBefore(nowDateTime) && eventStartTime.plusHours(7).isAfter(nowDateTime)) { | ||
return new ResponseFcfsInfoDto(nowDateTime, "progress"); | ||
} else { | ||
return new ResponseFcfsInfoDto(nowDateTime, "waiting"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FE에서 요구한 대로 이벤트에 대한 정보를 추출하는 메서드를 작성했습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3, 7이라는 숫자는 추후에 변경될 수도 있으니 별도로 분리해두는 것도 좋을 것 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 말씀주신 부분까지 반영해서 머지하겠습니다:) |
||
} | ||
|
||
// 특정 유저가 선착순 이벤트의 참여자인지 조회 (정답을 맞힌 경우 참여자로 간주) | ||
@Transactional(readOnly = true) | ||
public boolean isParticipated(Long eventSequence, String userId) { | ||
if(!fcfsEventRepository.existsById(eventSequence)) { | ||
throw new FcfsEventException(ErrorCode.FCFS_EVENT_NOT_FOUND); | ||
} | ||
return stringRedisTemplate.opsForZSet().rank(FcfsUtil.participantFormatting(eventSequence.toString()), userId) != null; | ||
} | ||
|
||
// 특정 선착순 이벤트의 당첨자 조회 - 어드민에서 사용 | ||
@Transactional(readOnly = true) | ||
public List<ResponseFcfsWinnerDto> getFcfsWinnersInfo(Long eventSequence) { | ||
|
@@ -94,6 +127,8 @@ private void prepareEventInfo(FcfsEvent event) { | |
|
||
public void deleteEventInfo(String eventId) { | ||
stringRedisTemplate.delete(FcfsUtil.startTimeFormatting(eventId)); | ||
stringRedisTemplate.delete(FcfsUtil.answerFormatting(eventId)); | ||
stringRedisTemplate.delete(FcfsUtil.participantFormatting(eventId)); | ||
stringRedisTemplate.delete(FcfsUtil.winnerFormatting(eventId)); | ||
numberRedisTemplate.delete(FcfsUtil.keyFormatting(eventId)); | ||
booleanRedisTemplate.delete(FcfsUtil.endFlagFormatting(eventId)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResponseFcfsInfoDto에 존재하는 DateTime 타입 필드의 직렬화를 위해 jackson 라이브러리를 추가하였습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jackson이 스프링부트에 내장되어 있어서 필요 없을 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
말씀주신 부분 반영했습니다:)