From f64f47320235f6e51d7b5bbc5d9fbeff6e617aa6 Mon Sep 17 00:00:00 2001 From: "Jaemin.Park" Date: Thu, 21 Dec 2023 16:55:30 +0900 Subject: [PATCH] Add progressDay column to GoalProofRetrieveResponse --- .../GoalProofApplicationService.kt | 7 +++- .../goalproof/GoalProofController.kt | 14 +++---- .../controller/goalproof/GoalProofDto.kt | 41 +++++++++++++++---- .../domain/goalproof/GoalProofService.kt | 6 ++- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/GoalProofApplicationService.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/GoalProofApplicationService.kt index 645cce1..9056e6e 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/GoalProofApplicationService.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/applicationservice/GoalProofApplicationService.kt @@ -4,6 +4,7 @@ import com.whatever.raisedragon.common.exception.BaseException import com.whatever.raisedragon.common.exception.ExceptionCode import com.whatever.raisedragon.controller.goalproof.GoalProofCreateUpdateResponse import com.whatever.raisedragon.controller.goalproof.GoalProofListRetrieveResponse +import com.whatever.raisedragon.controller.goalproof.GoalProofRetrieveAllResponse import com.whatever.raisedragon.controller.goalproof.GoalProofRetrieveResponse import com.whatever.raisedragon.domain.gifticon.URL import com.whatever.raisedragon.domain.goal.GoalService @@ -49,7 +50,11 @@ class GoalProofApplicationService( fun retrieveAll(goalId: Long, userId: Long): GoalProofListRetrieveResponse { val goalProofs = goalProofService.findAllByGoalIdAndUserId(goalId, userId) - return GoalProofListRetrieveResponse(goalProofs.map { GoalProofRetrieveResponse.of(it) }) + .sortedBy { goalProof -> goalProof.createdAt } + .mapIndexed { index, goalProof -> + GoalProofRetrieveAllResponse.of(goalProof, index + 1) + } + return GoalProofListRetrieveResponse(goalProofs) } @Transactional diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/controller/goalproof/GoalProofController.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/controller/goalproof/GoalProofController.kt index 4fa5d04..0f60b93 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/controller/goalproof/GoalProofController.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/controller/goalproof/GoalProofController.kt @@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.* @Tag(name = "GoalProof", description = "GoalProof API") @RestController -@RequestMapping("/v1/goal-proof") +@RequestMapping("/v1") @SecurityRequirement(name = "Authorization") class GoalProofController( private val goalProofApplicationService: GoalProofApplicationService @@ -21,7 +21,7 @@ class GoalProofController( @ResponseStatus(HttpStatus.CREATED) @Operation(summary = "GoalProof create API", description = "다짐 인증을 생성합니다.") - @PostMapping + @PostMapping("/goal-proof") fun create( @Valid @RequestBody goalProofCreateRequest: GoalProofCreateRequest, @GetAuth userInfo: UserInfo @@ -37,7 +37,7 @@ class GoalProofController( } @Operation(summary = "Retrieving single GoalProof API", description = "단건 다짐 인증을 조회합니다") - @GetMapping("/{goalProofId}") + @GetMapping("/goal-proof/{goalProofId}") fun retrieve( @PathVariable goalProofId: Long ): Response { @@ -45,16 +45,16 @@ class GoalProofController( } @Operation(summary = "Retrieving GoalProofs API", description = "모든 다짐 인증을 조회합니다") - @GetMapping + @GetMapping("goal/{goalId}/goal-proof") fun retrieveAll( @GetAuth userInfo: UserInfo, - @RequestBody request: GoalProofRetrieveAllRequest + @PathVariable goalId: Long ): Response { - return Response.success(goalProofApplicationService.retrieveAll(request.goalId, userInfo.id)) + return Response.success(goalProofApplicationService.retrieveAll(goalId, userInfo.id)) } @Operation(summary = "Updating GoalProof API", description = "다짐 인증을 수정합니다") - @PutMapping("/{goalProofId}") + @PutMapping("/goal-proof/{goalProofId}") fun update( @PathVariable goalProofId: Long, @RequestBody request: GoalProofUpdateRequest, diff --git a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/controller/goalproof/GoalProofDto.kt b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/controller/goalproof/GoalProofDto.kt index 163a719..f2793ed 100644 --- a/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/controller/goalproof/GoalProofDto.kt +++ b/raisedragon-api/src/main/kotlin/com/whatever/raisedragon/controller/goalproof/GoalProofDto.kt @@ -24,12 +24,6 @@ data class GoalProofUpdateRequest( val comment: String? = null ) -@Schema(description = "[Request] 모든 다짐 인증 조회") -data class GoalProofRetrieveAllRequest( - @Schema(description = "Goal Id") - val goalId: Long, -) - @Schema(description = "[Response] 인증내역 생성/수정") data class GoalProofCreateUpdateResponse( @Schema(description = "GoalProof") @@ -65,8 +59,41 @@ data class GoalProofRetrieveResponse( } } +@Schema(description = "[Response] 단건 다짐 인증 조회") +data class GoalProofRetrieveAllResponse( + + @Schema(description = "GoalProofId") + val id: Long, + + @Schema(description = "UserId") + val userId: Long, + + @Schema(description = "GoalId") + val goalId: Long, + + @Schema(description = "인증 사진") + val url: String, + + @Schema(description = "인증 부연설명") + val comment: String, + + @Schema(description = "인증 순서") + val progressDay: Int +) { + companion object { + fun of(goalProof: GoalProof, progressDay: Int): GoalProofRetrieveAllResponse = GoalProofRetrieveAllResponse( + id = goalProof.id, + userId = goalProof.userId, + goalId = goalProof.goalId, + url = goalProof.url.value, + comment = goalProof.comment.value, + progressDay = progressDay + ) + } +} + @Schema(description = "[Response] 모든 다짐 인증 조회") data class GoalProofListRetrieveResponse( @Schema(description = "모든 다짐 인증") - val goalProofs: List + val goalProofs: List ) \ No newline at end of file diff --git a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goalproof/GoalProofService.kt b/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goalproof/GoalProofService.kt index bbeda6b..0e1bfe9 100644 --- a/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goalproof/GoalProofService.kt +++ b/raisedragon-core/src/main/kotlin/com/whatever/raisedragon/domain/goalproof/GoalProofService.kt @@ -42,8 +42,10 @@ class GoalProofService( } fun findAllByGoalIdAndUserId(goalId: Long, userId: Long): List { - val goalEntity = goalRepository.findByIdOrNull(goalId) ?: throw IllegalArgumentException() - val userEntity = userRepository.findByIdOrNull(userId) ?: throw IllegalArgumentException() + val goalEntity = + goalRepository.findByIdOrNull(goalId) ?: throw IllegalArgumentException("cannot find goal $goalId") + val userEntity = + userRepository.findByIdOrNull(userId) ?: throw IllegalArgumentException("cannot find user $userId") return goalProofRepository.findAllByUserEntityAndGoalEntity(goalEntity = goalEntity, userEntity = userEntity) .map { it.toDto() } }