diff --git a/src/main/java/org/runimo/runimo/records/controller/RecordController.java b/src/main/java/org/runimo/runimo/records/controller/RecordController.java index 9a6f53e1..b5ba34be 100644 --- a/src/main/java/org/runimo/runimo/records/controller/RecordController.java +++ b/src/main/java/org/runimo/runimo/records/controller/RecordController.java @@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.constraints.NotNull; import java.net.URI; import java.time.LocalDate; import lombok.RequiredArgsConstructor; @@ -90,9 +91,10 @@ public ResponseEntity> viewRecord( @PatchMapping("/{recordId}") public ResponseEntity updateRecord( @RequestBody RecordUpdateRequest request, + @NotNull @PathVariable String recordId, @UserId Long userId ) { - recordUpdateUsecase.updateRecord(RecordUpdateRequest.toCommand(userId, request)); + recordUpdateUsecase.updateRecord(RecordUpdateRequest.toCommand(userId, recordId, request)); return ResponseEntity.ok().build(); } diff --git a/src/main/java/org/runimo/runimo/records/controller/request/RecordUpdateRequest.java b/src/main/java/org/runimo/runimo/records/controller/request/RecordUpdateRequest.java index df6215f7..f7fe4f30 100644 --- a/src/main/java/org/runimo/runimo/records/controller/request/RecordUpdateRequest.java +++ b/src/main/java/org/runimo/runimo/records/controller/request/RecordUpdateRequest.java @@ -2,31 +2,25 @@ import io.swagger.v3.oas.annotations.media.Schema; -import java.time.LocalDateTime; import org.runimo.runimo.records.service.usecases.dtos.RecordUpdateCommand; @Schema(description = "사용자 달리기 기록 수정 요청 DTO") public record RecordUpdateRequest( @Schema(description = "달리기 제목", example = "오늘의 달리기") String title, - @Schema(description = "달리기 시작 시각", example = "2021-10-10T10:10:10") - LocalDateTime startedAt, - @Schema(description = "달리기 종료 시각", example = "2021-10-10T10:20:10") - LocalDateTime endAt, - @Schema(description = "달린 거리 (미터)", example = "10000") - Long totalDistanceInMeters, - @Schema(description = "평균 페이스 (밀리초)", example = "300000") - Long averagePaceInMilliSeconds + @Schema(description = "달리기 설명", example = "오늘은 올림픽 공원을 달렸어요") + String description, + @Schema(description = "대표 이미지 URL", example = "https://example.com/image.jpg") + String imgUrl ) { - public static RecordUpdateCommand toCommand(Long userId, RecordUpdateRequest request) { + public static RecordUpdateCommand toCommand(Long userId, String recordPublicId, RecordUpdateRequest request) { return RecordUpdateCommand.builder() + .recordPublicId(recordPublicId) .editorId(userId) .title(request.title) - .startedAt(request.startedAt) - .endAt(request.endAt) - .totalDistanceInMeters(request.totalDistanceInMeters) - .averagePaceInMilliSeconds(request.averagePaceInMilliSeconds) + .description(request.description) + .imgUrl(request.imgUrl) .build(); } } diff --git a/src/main/java/org/runimo/runimo/records/domain/RunningRecord.java b/src/main/java/org/runimo/runimo/records/domain/RunningRecord.java index b82b590a..bc49a9dd 100644 --- a/src/main/java/org/runimo/runimo/records/domain/RunningRecord.java +++ b/src/main/java/org/runimo/runimo/records/domain/RunningRecord.java @@ -6,6 +6,7 @@ import jakarta.persistence.Convert; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; +import jakarta.persistence.PrePersist; import jakarta.persistence.Table; import java.time.Duration; import java.time.LocalDateTime; @@ -30,6 +31,8 @@ public class RunningRecord extends BaseEntity { private String recordPublicId; private Long userId; private String title; + private String description; + private String imgUrl; private LocalDateTime startedAt; private LocalDateTime endAt; @Embedded @@ -44,12 +47,22 @@ public class RunningRecord extends BaseEntity { private List pacePerKm; @Builder - public RunningRecord(Long userId, String title, LocalDateTime startedAt, LocalDateTime endAt, - Distance totalDistance, Pace averagePace, Boolean isRewarded, List pacePerKm) { + public RunningRecord( + Long userId, + String title, + String description, + String imgUrl, + LocalDateTime startedAt, + LocalDateTime endAt, + Distance totalDistance, + Pace averagePace, + Boolean isRewarded, + List pacePerKm) { this.userId = userId; this.title = title; + this.description = description; + this.imgUrl = imgUrl; this.pacePerKm = pacePerKm; - this.recordPublicId = UUID.randomUUID().toString(); this.startedAt = startedAt; this.endAt = endAt; this.isRewarded = isRewarded; @@ -58,26 +71,19 @@ public RunningRecord(Long userId, String title, LocalDateTime startedAt, LocalDa setTitleIfNull(); } - public static RunningRecord withoutId(Long userId, String title, LocalDateTime startedAt, - LocalDateTime endAt, Distance totalDistance, Pace averagePace) { - return RunningRecord.builder() - .userId(userId) - .title(title) - .startedAt(startedAt) - .endAt(endAt) - .totalDistance(totalDistance) - .averagePace(averagePace) - .build(); + public void updateTitle(Long editor, String title) { + validateEditor(editor); + this.title = title; + } + + public void updateDescription(Long editor, String description) { + validateEditor(editor); + this.description = description; } - public void update(RunningRecord updatedEntity) { - validateEditor(updatedEntity.userId); - this.title = updatedEntity.getTitle(); - this.startedAt = updatedEntity.getStartedAt(); - this.endAt = updatedEntity.getEndAt(); - this.averagePace = updatedEntity.averagePace; - this.recordPublicId = updatedEntity.recordPublicId; - this.isRewarded = updatedEntity.isRewarded; + public void updateImageUrl(Long editor, String imgUrl) { + validateEditor(editor); + this.imgUrl = imgUrl; } public void reward(Long editorId) { @@ -101,6 +107,13 @@ public Duration getRunningTime() { return Duration.between(startedAt, endAt); } + @PrePersist + public void generateRecordPublicId() { + if (recordPublicId == null) { + this.recordPublicId = UUID.randomUUID().toString(); + } + } + private void setTitleIfNull() { if (this.title != null) return; this.title = DefaultTitle.fromTime(this.startedAt).getTitle(); diff --git a/src/main/java/org/runimo/runimo/records/service/RecordCommandService.java b/src/main/java/org/runimo/runimo/records/service/RecordCommandService.java index d8589246..c50c3770 100644 --- a/src/main/java/org/runimo/runimo/records/service/RecordCommandService.java +++ b/src/main/java/org/runimo/runimo/records/service/RecordCommandService.java @@ -2,12 +2,9 @@ import java.util.NoSuchElementException; import lombok.RequiredArgsConstructor; -import org.runimo.runimo.common.scale.Distance; -import org.runimo.runimo.common.scale.Pace; import org.runimo.runimo.records.domain.RunningRecord; import org.runimo.runimo.records.repository.RecordRepository; import org.runimo.runimo.records.service.usecases.dtos.RecordCreateCommand; -import org.runimo.runimo.records.service.usecases.dtos.RecordSaveResponse; import org.runimo.runimo.records.service.usecases.dtos.RecordUpdateCommand; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -19,10 +16,9 @@ public class RecordCommandService { private final RecordRepository recordRepository; @Transactional - public RecordSaveResponse saveRecord(Long userId, RecordCreateCommand command) { + public RunningRecord saveRecord(Long userId, RecordCreateCommand command) { RunningRecord runningRecord = mapToCreatedRunningRecord(userId, command); - recordRepository.save(runningRecord); - return new RecordSaveResponse(runningRecord.getId()); + return recordRepository.save(runningRecord); } @Transactional @@ -30,20 +26,13 @@ public void updateRecord(RecordUpdateCommand command) { RunningRecord runningRecord = recordRepository.findByRecordPublicId( command.recordPublicId()) .orElseThrow(NoSuchElementException::new); - runningRecord.update(mapToUpdateRecord(command)); + + runningRecord.updateTitle(command.editorId(), command.title()); + runningRecord.updateDescription(command.editorId(), command.description()); + runningRecord.updateImageUrl(command.editorId(), command.imgUrl()); recordRepository.save(runningRecord); } - private RunningRecord mapToUpdateRecord(RecordUpdateCommand command) { - return RunningRecord.withoutId( - command.editorId(), - command.title(), - command.startedAt(), - command.endAt(), - new Distance(command.totalDistanceInMeters()), - new Pace(command.averagePaceInMilliSeconds()) - ); - } private RunningRecord mapToCreatedRunningRecord(Long id, RecordCreateCommand command) { return RunningRecord.builder() diff --git a/src/main/java/org/runimo/runimo/records/service/usecases/RecordCreateUsecaseImpl.java b/src/main/java/org/runimo/runimo/records/service/usecases/RecordCreateUsecaseImpl.java index 544993f8..4728b502 100644 --- a/src/main/java/org/runimo/runimo/records/service/usecases/RecordCreateUsecaseImpl.java +++ b/src/main/java/org/runimo/runimo/records/service/usecases/RecordCreateUsecaseImpl.java @@ -33,6 +33,6 @@ public RecordSaveResponse execute(RecordCreateCommand command) { runimoService.updateRunimoStat(user.getMainRunimoId(), command.totalDistanceInMeters()); } - return commandService.saveRecord(user.getId(), command); + return new RecordSaveResponse(commandService.saveRecord(user.getId(), command).getRecordPublicId()); } } diff --git a/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordDetailViewResponse.java b/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordDetailViewResponse.java index cc703e27..33e35837 100644 --- a/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordDetailViewResponse.java +++ b/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordDetailViewResponse.java @@ -1,28 +1,40 @@ package org.runimo.runimo.records.service.usecases.dtos; +import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDateTime; import java.util.List; import lombok.Builder; import org.runimo.runimo.records.domain.RunningRecord; +@Schema(description = "기록 상세 정보") @Builder public record RecordDetailViewResponse( - Long recordId, + @Schema(description = "기록 ID", example = "UUID-String") + String recordId, + @Schema(description = "기록 제목") String title, + @Schema(description = "기록 시작 시간") LocalDateTime startedAt, LocalDateTime endAt, + @Schema(description = "총 기록 시간 (초 단위)") + Long totalRunningTime, + @Schema(description = "평균 페이스 (밀리세컨드 단위)") Long averagePace, + @Schema(description = "총 거리 (미터 단위)") Long totalDistance, + @Schema(description = "구간 페이스 리스트") List segmentPaceList, + @Schema(description = "기록 이미지 URL") String imgUrl ) { - public static RecordDetailViewResponse from(RunningRecord runningRecord) { + public static RecordDetailViewResponse from(final RunningRecord runningRecord) { return RecordDetailViewResponse.builder() - .recordId(runningRecord.getId()) + .recordId(runningRecord.getRecordPublicId()) .title(runningRecord.getTitle()) .startedAt(runningRecord.getStartedAt()) .endAt(runningRecord.getEndAt()) + .totalRunningTime(runningRecord.getRunningTime().getSeconds()) .averagePace(runningRecord.getAveragePace().getPaceInMilliSeconds()) .totalDistance(runningRecord.getTotalDistance().getAmount()) .segmentPaceList(runningRecord.getPacePerKm()) diff --git a/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordSaveResponse.java b/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordSaveResponse.java index f66cdcd0..5a8db71c 100644 --- a/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordSaveResponse.java +++ b/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordSaveResponse.java @@ -1,6 +1,11 @@ package org.runimo.runimo.records.service.usecases.dtos; -public record RecordSaveResponse(Long savedId +import io.swagger.v3.oas.annotations.media.Schema; + +@Schema(description = "기록 저장 응답 DTO") +public record RecordSaveResponse( + @Schema(description = "저장된 기록 ID", example = "UUID-String") + String savedId ) { } diff --git a/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordUpdateCommand.java b/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordUpdateCommand.java index 0fa835a1..7e001864 100644 --- a/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordUpdateCommand.java +++ b/src/main/java/org/runimo/runimo/records/service/usecases/dtos/RecordUpdateCommand.java @@ -1,17 +1,15 @@ package org.runimo.runimo.records.service.usecases.dtos; -import java.time.LocalDateTime; +import jakarta.validation.constraints.NotEmpty; import lombok.Builder; @Builder public record RecordUpdateCommand( - Long editorId, - String recordPublicId, + @NotEmpty Long editorId, + @NotEmpty String recordPublicId, String title, - LocalDateTime startedAt, - LocalDateTime endAt, - Long totalDistanceInMeters, - Long averagePaceInMilliSeconds + String description, + String imgUrl ) { } diff --git a/src/main/java/org/runimo/runimo/rewards/controller/request/RewardClaimRequest.java b/src/main/java/org/runimo/runimo/rewards/controller/request/RewardClaimRequest.java index 01f19ddd..96b6b1a7 100644 --- a/src/main/java/org/runimo/runimo/rewards/controller/request/RewardClaimRequest.java +++ b/src/main/java/org/runimo/runimo/rewards/controller/request/RewardClaimRequest.java @@ -4,7 +4,7 @@ @Schema(description = "리워드 클레임 요청 DTO") public record RewardClaimRequest( - @Schema(description = "보상을 요청하는 달리기 기록 ID", example = "1") Long recordId + @Schema(description = "보상을 요청하는 달리기 기록 ID", example = "UUID-record-id") String recordId ) { } diff --git a/src/main/java/org/runimo/runimo/rewards/service/RewardService.java b/src/main/java/org/runimo/runimo/rewards/service/RewardService.java index 28942248..5a99eb53 100644 --- a/src/main/java/org/runimo/runimo/rewards/service/RewardService.java +++ b/src/main/java/org/runimo/runimo/rewards/service/RewardService.java @@ -29,7 +29,7 @@ public class RewardService { @Transactional public RewardResponse claimReward(RewardClaimCommand command) { - RunningRecord runningRecord = recordFinder.findById(command.recordId()) + RunningRecord runningRecord = recordFinder.findByPublicId(command.recordPublicId()) .orElseThrow(NoSuchElementException::new); validateRecord(runningRecord); Egg grantedEgg = rewardEgg(command); @@ -61,7 +61,7 @@ private boolean validateRecordIsFirstRecordOfWeek(RewardClaimCommand command) { log.info("유저 {}의 첫번째 달리기 기록이 없습니다.", command.userId()); return false; } - if (!command.recordId().equals(firstRecordOfWeek.get().getId())) { + if (!command.recordPublicId().equals(firstRecordOfWeek.get().getRecordPublicId())) { log.info("유저 {}의 첫번째 달리기 기록이 아닙니다.", command.userId()); return false; } diff --git a/src/main/java/org/runimo/runimo/rewards/service/dto/RewardClaimCommand.java b/src/main/java/org/runimo/runimo/rewards/service/dto/RewardClaimCommand.java index 635ea04e..4f222b8b 100644 --- a/src/main/java/org/runimo/runimo/rewards/service/dto/RewardClaimCommand.java +++ b/src/main/java/org/runimo/runimo/rewards/service/dto/RewardClaimCommand.java @@ -2,7 +2,7 @@ public record RewardClaimCommand( Long userId, - Long recordId + String recordPublicId ) { } diff --git a/src/main/resources/sql/schema.sql b/src/main/resources/sql/schema.sql index e39c59e7..f5565007 100644 --- a/src/main/resources/sql/schema.sql +++ b/src/main/resources/sql/schema.sql @@ -93,6 +93,8 @@ CREATE TABLE `running_record` `user_id` INTEGER NOT NULL, `record_public_id` VARCHAR(255) NOT NULL, `title` VARCHAR(255), + `description` VARCHAR(255), + `img_url` VARCHAR(255), `started_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `end_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `total_distance` INTEGER, diff --git a/src/test/java/org/runimo/runimo/records/api/RecordAcceptanceTest.java b/src/test/java/org/runimo/runimo/records/api/RecordAcceptanceTest.java index ac9f0fa5..8a552e83 100644 --- a/src/test/java/org/runimo/runimo/records/api/RecordAcceptanceTest.java +++ b/src/test/java/org/runimo/runimo/records/api/RecordAcceptanceTest.java @@ -5,6 +5,7 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.notNullValue; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import io.restassured.RestAssured; import io.restassured.http.ContentType; @@ -16,6 +17,7 @@ import org.runimo.runimo.CleanUpUtil; import org.runimo.runimo.auth.jwt.JwtTokenFactory; import org.runimo.runimo.records.controller.request.RecordSaveRequest; +import org.runimo.runimo.records.controller.request.RecordUpdateRequest; import org.runimo.runimo.records.service.usecases.dtos.SegmentPace; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -129,7 +131,7 @@ void tearDown() { .then() .log().all() .statusCode(200) - .body("payload.record_id", equalTo(1)) + .body("payload.record_id", notNullValue()) .body("payload.segment_pace_list.size()", greaterThanOrEqualTo(1)) .body("payload.segment_pace_list[0].distance", equalTo(1.0f)) .body("payload.segment_pace_list[0].pace", equalTo(732000)); @@ -281,5 +283,42 @@ void tearDown() { .statusCode(HttpStatus.OK.value()) .body("payload.record_list.size()", equalTo(5)); } + + @Test + @Sql(scripts = "/sql/weekly_record_data.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) + void 사용자_기록_페이지네이션_조회_잘못된_요청() { + String token = AUTH_HEADER_PREFIX + jwtTokenFactory.generateAccessToken(USER_UUID); + + given() + .contentType(ContentType.JSON) + .header("Authorization", token) + .param("page", -1) // 잘못된 페이지 번호 + .param("size", 5) + .when() + .get("/api/v1/records/me") + .then() + .log().all() + .statusCode(HttpStatus.BAD_REQUEST.value()); + } + + @Test + @Sql(scripts = "/sql/weekly_record_data.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) + void 사용자_기록_업데이트() throws JsonProcessingException { + String token = AUTH_HEADER_PREFIX + jwtTokenFactory.generateAccessToken(USER_UUID); + RecordUpdateRequest request = new RecordUpdateRequest( + "예시 제목", + "오늘은 올림픽 공원을 달렸어요.", + "https://example.com/image.jpg" + ); + + given() + .contentType(ContentType.JSON) + .header("Authorization", token) + .body(objectMapper.writeValueAsString(request)) + .when() + .patch("/api/v1/records/record-public-id-1") + .then() + .statusCode(HttpStatus.OK.value()); + } } diff --git a/src/test/java/org/runimo/runimo/rewards/api/RewardAcceptanceTest.java b/src/test/java/org/runimo/runimo/rewards/api/RewardAcceptanceTest.java index 83728757..e991ebf1 100644 --- a/src/test/java/org/runimo/runimo/rewards/api/RewardAcceptanceTest.java +++ b/src/test/java/org/runimo/runimo/rewards/api/RewardAcceptanceTest.java @@ -70,9 +70,9 @@ void tearDown() { .body("payload", notNullValue()) .body("payload.saved_id", notNullValue()); - Integer recordId = res.extract().path("payload.saved_id"); + String recordId = res.extract().path("payload.saved_id"); - RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(Long.valueOf(recordId)); + RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(recordId); given() .header("Authorization", header) @@ -102,9 +102,9 @@ void tearDown() { .body("payload", notNullValue()) .body("payload.saved_id", notNullValue()); - Integer recordId = res.extract().path("payload.saved_id"); + String recordId = res.extract().path("payload.saved_id"); - RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(Long.valueOf(recordId)); + RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(recordId); given() .header("Authorization", header) @@ -152,7 +152,7 @@ void tearDown() { .body("payload", notNullValue()) .body("payload.saved_id", notNullValue()); - Integer firstRecordId = firstRes.extract().path("payload.saved_id"); + String firstRecordId = firstRes.extract().path("payload.saved_id"); // 두번째 기록 저장 (startedAt이 더 빠르게) RecordSaveRequest secondRequest = new RecordSaveRequest( @@ -174,7 +174,7 @@ void tearDown() { .body("payload.saved_id", notNullValue()); // 첫번째 기록의 id로 보상 요청 - RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(Long.valueOf(firstRecordId)); + RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(firstRecordId); given() .header("Authorization", header) @@ -207,9 +207,9 @@ void tearDown() { .body("payload", notNullValue()) .body("payload.saved_id", notNullValue()); - Integer recordId = res.extract().path("payload.saved_id"); + String recordId = res.extract().path("payload.saved_id"); - RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(Long.valueOf(recordId)); + RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(recordId); given() .header("Authorization", header) @@ -247,9 +247,9 @@ void tearDown() { .body("payload", notNullValue()) .body("payload.saved_id", notNullValue()); - Integer recordId = res.extract().path("payload.saved_id"); + String recordId = res.extract().path("payload.saved_id"); - RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(Long.valueOf(recordId)); + RewardClaimRequest rewardClaimRequest = new RewardClaimRequest(recordId); given() .header("Authorization", header) diff --git a/src/test/java/org/runimo/runimo/rewards/service/RewardServiceTest.java b/src/test/java/org/runimo/runimo/rewards/service/RewardServiceTest.java index 10366c60..6aece609 100644 --- a/src/test/java/org/runimo/runimo/rewards/service/RewardServiceTest.java +++ b/src/test/java/org/runimo/runimo/rewards/service/RewardServiceTest.java @@ -13,6 +13,7 @@ import java.time.LocalDateTime; import java.util.Optional; +import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -50,6 +51,8 @@ private static RunningRecord getRunningRecordWithIds(Long userId, Long recordId, .startedAt(LocalDateTime.now()) .build(); ReflectionTestUtils.setField(runningRecord, "id", recordId); + ReflectionTestUtils.setField(runningRecord, "recordPublicId", + UUID.randomUUID().toString()); return runningRecord; } @@ -65,9 +68,9 @@ void setUp() { @Test void 보상을_받지_않은_이번주_첫_기록이라면_알을_지급한다() { RunningRecord unRewardedRecord = getRunningRecordWithIds(1L, 1L, false); - RewardClaimCommand command = new RewardClaimCommand(1L, 1L); + RewardClaimCommand command = new RewardClaimCommand(1L, unRewardedRecord.getRecordPublicId()); - when(recordFinder.findById(any())).thenReturn(java.util.Optional.of(unRewardedRecord)); + when(recordFinder.findByPublicId(any())).thenReturn(java.util.Optional.of(unRewardedRecord)); when(recordFinder.findFirstRunOfCurrentWeek(any())).thenReturn( java.util.Optional.of(unRewardedRecord)); when(eggGrantService.grantRandomEggToUser(any())).thenReturn( @@ -82,9 +85,10 @@ void setUp() { @Test void 이미_보상을_받은_기록이면_예외를_던진다() { RunningRecord alreadyRewardedRecord = getRunningRecordWithIds(1L, 1L, true); - RewardClaimCommand command = new RewardClaimCommand(1L, 1L); + RewardClaimCommand command = new RewardClaimCommand(1L, + alreadyRewardedRecord.getRecordPublicId()); - when(recordFinder.findById(any())).thenReturn(java.util.Optional.of(alreadyRewardedRecord)); + when(recordFinder.findByPublicId(any())).thenReturn(java.util.Optional.of(alreadyRewardedRecord)); when(recordFinder.findFirstRunOfCurrentWeek(any())).thenReturn( java.util.Optional.of(alreadyRewardedRecord)); when(eggGrantService.grantRandomEggToUser(any())).thenReturn( @@ -98,9 +102,9 @@ void setUp() { void 이번주_첫_기록이_아니면_알을_지급하지_않는다() { RunningRecord unRewardedRecord = getRunningRecordWithIds(1L, 1L, false); RunningRecord anotherRecord = getRunningRecordWithIds(1L, 2L, false); - RewardClaimCommand command = new RewardClaimCommand(1L, 1L); + RewardClaimCommand command = new RewardClaimCommand(1L, unRewardedRecord.getRecordPublicId()); - when(recordFinder.findById(any())).thenReturn(java.util.Optional.of(unRewardedRecord)); + when(recordFinder.findByPublicId(any())).thenReturn(java.util.Optional.of(unRewardedRecord)); when(recordFinder.findFirstRunOfCurrentWeek(any())).thenReturn(Optional.of(anotherRecord)); when(loveGrantService.grantLoveToUserWithDistance(any())).thenReturn(10L); diff --git a/src/test/resources/sql/schema.sql b/src/test/resources/sql/schema.sql index e39c59e7..f5565007 100644 --- a/src/test/resources/sql/schema.sql +++ b/src/test/resources/sql/schema.sql @@ -93,6 +93,8 @@ CREATE TABLE `running_record` `user_id` INTEGER NOT NULL, `record_public_id` VARCHAR(255) NOT NULL, `title` VARCHAR(255), + `description` VARCHAR(255), + `img_url` VARCHAR(255), `started_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `end_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `total_distance` INTEGER,