diff --git a/src/main/java/com/dnd/dndtravel/auth/service/JwtTokenService.java b/src/main/java/com/dnd/dndtravel/auth/service/JwtTokenService.java index 2e56e50..14f18bb 100644 --- a/src/main/java/com/dnd/dndtravel/auth/service/JwtTokenService.java +++ b/src/main/java/com/dnd/dndtravel/auth/service/JwtTokenService.java @@ -21,15 +21,23 @@ public class JwtTokenService { public TokenResponse generateTokens(Long memberId) { RefreshToken refreshToken = refreshTokenRepository.findByMemberId(memberId); + // 리프레시 토큰이 없는경우 if (refreshToken == null) { String newRefreshToken = jwtProvider.refreshToken(); refreshTokenRepository.save(RefreshToken.of(memberId, newRefreshToken)); // refreshToken은 DB에 저장 return new TokenResponse(jwtProvider.accessToken(memberId), newRefreshToken); - } else if (refreshToken.isExpire()) { + } + + // 리프레시 토큰이 만료됐으면 재발급 받으라고 멘트줌 + if (refreshToken.isExpire()) { return null; } - - return new TokenResponse(jwtProvider.accessToken(memberId), null); + + // 리프레시 토큰이 DB에 존재하고 유효한경우 + refreshTokenRepository.delete(refreshToken); + String newRefreshToken = jwtProvider.refreshToken(); + refreshTokenRepository.save(RefreshToken.of(refreshToken.getMemberId(), newRefreshToken)); + return new TokenResponse(jwtProvider.accessToken(memberId), newRefreshToken); } @Transactional diff --git a/src/main/java/com/dnd/dndtravel/map/controller/request/RecordRequest.java b/src/main/java/com/dnd/dndtravel/map/controller/request/RecordRequest.java index f8cd993..f0c8448 100644 --- a/src/main/java/com/dnd/dndtravel/map/controller/request/RecordRequest.java +++ b/src/main/java/com/dnd/dndtravel/map/controller/request/RecordRequest.java @@ -16,24 +16,45 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -public record RecordRequest( +import lombok.Getter; +import lombok.Setter; + +/** + * record타입은 multipart로 받을때 Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of + * `*.request.RecordRequest` (although at least one Creator exists): + * no String-argument constructor/factory method to deserialize from String value 문제가 있었음 + * + */ +@Getter +@Setter +public class RecordRequest { @Schema(description = "지역 이름", requiredMode = REQUIRED) @RegionEnum(enumClass = RegionCondition.class) - String region, + String region; @Schema(description = "명소명", requiredMode = REQUIRED) @NotBlank(message = "명소명은 필수 입니다.") @Size(max = 10, message = "명소 이름은 10자 이내여야 합니다.") - String attractionName, + String attractionName; @Schema(description = "메모", requiredMode = NOT_REQUIRED) @Size(max = 25, message = "메모는 25자 이내여야 합니다.") - String memo, + String memo; @Schema(description = "방문날짜, ISO Date(yyyy-MM-dd) 형식으로 입력", requiredMode = NOT_REQUIRED) @NotNull(message = "날짜는 필수 입력 사항입니다.") - LocalDate localDate -) { + LocalDate localDate; + + public RecordRequest() { + } + + public RecordRequest(String region, String attractionName, String memo, LocalDate localDate) { + this.region = region; + this.attractionName = attractionName; + this.memo = memo; + this.localDate = localDate; + } + public RecordDto toDto(List photos) { return RecordDto.builder() .region(this.region) diff --git a/src/main/java/com/dnd/dndtravel/map/service/MapService.java b/src/main/java/com/dnd/dndtravel/map/service/MapService.java index 7caabce..b9f43bd 100644 --- a/src/main/java/com/dnd/dndtravel/map/service/MapService.java +++ b/src/main/java/com/dnd/dndtravel/map/service/MapService.java @@ -215,9 +215,11 @@ private void updateRegionVisitCount(Member member, Region region) { } private void savePhotos(List photos, MemberAttraction memberAttractionEntity) { - for (MultipartFile photo : photos) { - String imageUrl = photoService.upload(photo); - photoRepository.save(Photo.of(memberAttractionEntity, imageUrl)); + if (photos != null && !photos.isEmpty()) { + for (MultipartFile photo : photos) { + String imageUrl = photoService.upload(photo); + photoRepository.save(Photo.of(memberAttractionEntity, imageUrl)); + } } } }