Skip to content

Commit

Permalink
Merge pull request #51 from MOONSHOT-Team/feature/#50
Browse files Browse the repository at this point in the history
[Fix] #50 - TokenResponse 수정 및 만료시간 변경 / Log 생성 관련 Exception 추가
  • Loading branch information
0lynny authored Jan 10, 2024
2 parents 2af935b + 382cfb8 commit d0ed73a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.moonshot.server.domain.log.exception;

import org.moonshot.server.global.common.exception.MoonshotException;
import org.moonshot.server.global.common.response.ErrorType;

public class InvalidRecordException extends MoonshotException {

public InvalidRecordException() { super(ErrorType.INVALID_RECORD_VALUE); }

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.moonshot.server.domain.log.dto.request.LogCreateRequestDto;
import org.moonshot.server.domain.log.dto.response.LogResponseDto;
import org.moonshot.server.domain.log.exception.InvalidLogValueException;
import org.moonshot.server.domain.log.exception.InvalidRecordException;
import org.moonshot.server.domain.log.model.Log;
import org.moonshot.server.domain.log.model.LogState;
import org.moonshot.server.domain.log.repository.LogRepository;
Expand Down Expand Up @@ -41,6 +42,9 @@ public void createRecordLog(Long userId, LogCreateRequestDto request) {
if (!keyResult.getObjective().getUser().getId().equals(userId)) {
throw new AccessDeniedException();
}
if(request.logNum() > keyResult.getTarget()) {
throw new InvalidRecordException();
}
Optional<Log> prevLog = logRepository.findLatestLogByKeyResultId(LogState.RECORD, request.keyResultId());
long prevNum = -1;
if (!prevLog.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public record TokenResponse(
String refreshToken
) {
public static TokenResponse of(String accessToken, String refreshToken) {
return new TokenResponse(accessToken, refreshToken);
return new TokenResponse("Bearer " + accessToken, "Bearer " + refreshToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum ErrorType {
INVALID_KEY_RESULT_ORDER(HttpStatus.BAD_REQUEST, "정상적이지 않은 KeyResult 위치입니다."),
INVALID_TASK_ORDER(HttpStatus.BAD_REQUEST, "정상적이지 않은 Task 위치입니다."),
INVALID_LOG_VALUE(HttpStatus.BAD_REQUEST, "진척 정도는 이전 값보다 큰 값이 입력되어야합니다."),
INVALID_RECORD_VALUE(HttpStatus.BAD_REQUEST, "진척 정도는 목표값보다 작은 값이 입력되어야 합니다."),

/**
* 401 UNAUTHROZIED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public class JWTConstants {

public static final String USER_ID = "userId";
public static final Long ACCESS_TOKEN_EXPIRATION_TIME = 60 * 1000L * 20; // 액세스 토큰 만료 시간: 20분으로 지정
public static final Long REFRESH_TOKEN_EXPIRATION_TIME = 60 * 1000L * 60 * 24 * 7 * 2; // 리프레시 토큰 만료 시간: 2주로 지정
public static final Long ACCESS_TOKEN_EXPIRATION_TIME = 60 * 1000L * 60 * 24 * 7 * 2;
public static final Long REFRESH_TOKEN_EXPIRATION_TIME = 60 * 1000L * 60 * 24 * 7 * 2;

}

0 comments on commit d0ed73a

Please sign in to comment.