Skip to content
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

[Fix] #50 - TokenResponse 수정 및 만료시간 변경 / Log 생성 관련 Exception 추가 #51

Merged
merged 4 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

}