Skip to content

Commit

Permalink
Add progressDay column to GoalProofRetrieveResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
mkSpace committed Dec 21, 2023
1 parent 2cdee37 commit f64f473
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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
) {

@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "GoalProof create API", description = "다짐 인증을 생성합니다.")
@PostMapping
@PostMapping("/goal-proof")
fun create(
@Valid @RequestBody goalProofCreateRequest: GoalProofCreateRequest,
@GetAuth userInfo: UserInfo
Expand All @@ -37,24 +37,24 @@ class GoalProofController(
}

@Operation(summary = "Retrieving single GoalProof API", description = "단건 다짐 인증을 조회합니다")
@GetMapping("/{goalProofId}")
@GetMapping("/goal-proof/{goalProofId}")
fun retrieve(
@PathVariable goalProofId: Long
): Response<GoalProofRetrieveResponse> {
return Response.success(goalProofApplicationService.retrieve(goalProofId))
}

@Operation(summary = "Retrieving GoalProofs API", description = "모든 다짐 인증을 조회합니다")
@GetMapping
@GetMapping("goal/{goalId}/goal-proof")
fun retrieveAll(
@GetAuth userInfo: UserInfo,
@RequestBody request: GoalProofRetrieveAllRequest
@PathVariable goalId: Long
): Response<GoalProofListRetrieveResponse> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<GoalProofRetrieveResponse>
val goalProofs: List<GoalProofRetrieveAllResponse>
)
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ class GoalProofService(
}

fun findAllByGoalIdAndUserId(goalId: Long, userId: Long): List<GoalProof> {
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() }
}
Expand Down

0 comments on commit f64f473

Please sign in to comment.