Skip to content

Commit

Permalink
Merge pull request #56 from Workout-Study/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
12OneTwo12 authored Aug 14, 2024
2 parents e366c49 + 69cdf18 commit 7272073
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 17 deletions.
36 changes: 31 additions & 5 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,6 @@ http-request

include::{snippets}/get-proceeding-fit-off-by-group-id/http-request.adoc[]

request-fields

include::{snippets}/get-proceeding-fit-off-by-group-id/request-fields.adoc[]

request-body

include::{snippets}/get-proceeding-fit-off-by-group-id/request-body.adoc[]
Expand All @@ -700,4 +696,34 @@ include::{snippets}/get-proceeding-fit-off-by-group-id/response-body.adoc[]

http-response

include::{snippets}/get-proceeding-fit-off-by-group-id/http-response.adoc[]
include::{snippets}/get-proceeding-fit-off-by-group-id/http-response.adoc[]

=== Get Proceeding Fit Off List by user id ( user id로 현재 진행중인 fit off 조회 )

path-parameters

include::{snippets}/get-proceeding-fit-off-by-user-id/path-parameters.adoc[]

http-request

include::{snippets}/get-proceeding-fit-off-by-user-id/http-request.adoc[]

request-body

include::{snippets}/get-proceeding-fit-off-by-user-id/request-body.adoc[]

curl-request

include::{snippets}/get-proceeding-fit-off-by-user-id/curl-request.adoc[]

response-fields

include::{snippets}/get-proceeding-fit-off-by-user-id/response-fields.adoc[]

response-body

include::{snippets}/get-proceeding-fit-off-by-user-id/response-body.adoc[]

http-response

include::{snippets}/get-proceeding-fit-off-by-user-id/http-response.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class GlobalURI {
const val PATH_VARIABLE_FIT_PENALTY_ID_WITH_BRACE = "/{$PATH_VARIABLE_FIT_PENALTY_ID}"

const val FIT_OFF_ROOT = "$ROOT_URI/fit-offs"
const val FIT_OFF_USER = "$FIT_OFF_ROOT/users"

const val PATH_VARIABLE_FIT_OFF_ID = "fit-off-id"
const val PATH_VARIABLE_FIT_OFF_ID_WITH_BRACE = "/{$PATH_VARIABLE_FIT_OFF_ID}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@ class FitOffController(
val command = FitOffDtoMapper.proceedingFitOffRequestToCommand(fitGroupId)
return ResponseEntity.ok().body(readFitOffUseCase.getProceedingFitOffByGroupId(command))
}

@GetMapping(GlobalURI.FIT_OFF_USER + GlobalURI.PATH_VARIABLE_USER_ID_WITH_BRACE)
fun getProceedingFitOffByUser(@PathVariable(GlobalURI.PATH_VARIABLE_USER_ID) userId: Int): ResponseEntity<ProceedingFitOffResponse> {
val command = FitOffDtoMapper.proceedingFitOffRequestUserToCommand(userId)
return ResponseEntity.ok().body(readFitOffUseCase.getProceedingFitOffByUser(command))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import com.fitmate.myfit.adapter.`in`.web.fit.off.response.DeleteFitOffResponse
import com.fitmate.myfit.adapter.`in`.web.fit.off.response.RegisterFitOffResponse
import com.fitmate.myfit.adapter.`in`.web.fit.off.response.UpdateFitOffResponse
import com.fitmate.myfit.adapter.out.api.DateParseUtils
import com.fitmate.myfit.application.port.`in`.fit.off.command.DeleteFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.GetProceedingFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.RegisterFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.UpdateFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.*
import com.fitmate.myfit.application.port.`in`.fit.off.response.DeleteFitOffResponseDto
import com.fitmate.myfit.application.port.`in`.fit.off.response.RegisterFitOffResponseDto
import com.fitmate.myfit.application.port.`in`.fit.off.response.UpdateFitOffResponseDto
Expand Down Expand Up @@ -59,5 +56,9 @@ class FitOffDtoMapper {
fun proceedingFitOffRequestToCommand(fitGroupId: Long): GetProceedingFitOffCommand {
return GetProceedingFitOffCommand(fitGroupId)
}

fun proceedingFitOffRequestUserToCommand(userId: Int): GetProceedingFitOffUserCommand {
return GetProceedingFitOffUserCommand(userId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ interface FitOffRepository : JpaRepository<FitOffEntity, Long> {
startDate: Instant,
endDate: Instant
): List<FitOffEntity>

fun findByUserIdAndStateAndFitOffStartDateLessThanEqualAndFitOffEndDateGreaterThanEqual(
userId: Int,
state: Boolean,
fitOffStartDate: Instant,
fitOffEndDate: Instant
): List<FitOffEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.fitmate.myfit.application.port.`in`.fit.off.command

import com.fitmate.myfit.common.SelfValidating

data class GetProceedingFitOffUserCommand(
val userId: Int
) : SelfValidating<GetProceedingFitOffUserCommand>() {
init {
this.validateSelf()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.fitmate.myfit.application.port.`in`.fit.off.usecase

import com.fitmate.myfit.adapter.`in`.web.fit.off.response.ProceedingFitOffResponse
import com.fitmate.myfit.application.port.`in`.fit.off.command.GetProceedingFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.GetProceedingFitOffUserCommand

interface ReadFitOffUseCase {

fun getProceedingFitOffByGroupId(command: GetProceedingFitOffCommand): ProceedingFitOffResponse
fun getProceedingFitOffByUser(command: GetProceedingFitOffUserCommand): ProceedingFitOffResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ interface ReadFitOffPort {
fun countByUserIdAndFitOffDate(userId: Int, fitOffStartDate: Instant, fitOffEndDate: Instant): Int
fun findById(fitOffId: Long): Optional<FitOff>
fun findProceedingFitOffByUserIds(userIdList: List<Int>): List<FitOff>
fun findProceedingFitOffByUserId(userId: Int): List<FitOff>
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ class FitOffPersistenceAdapter(
return fitOffEntityList.map { FitOff.entityToDomain(it) }.toList()
}

@Transactional(readOnly = true)
override fun findProceedingFitOffByUserId(userId: Int): List<FitOff> {
val now = Instant.now()

val fitOffEntityList =
fitOffRepository.findByUserIdAndStateAndFitOffStartDateLessThanEqualAndFitOffEndDateGreaterThanEqual(
userId,
GlobalStatus.PERSISTENCE_NOT_DELETED,
now,
now
)

return fitOffEntityList.map { FitOff.entityToDomain(it) }.toList()
}

@Transactional
override fun updateFitOff(fitOff: FitOff) {
val fitOffEntity = FitOffEntity.domainToEntity(fitOff)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package com.fitmate.myfit.application.service.service

import com.fitmate.myfit.adapter.`in`.web.fit.off.response.FitOffDetail
import com.fitmate.myfit.adapter.`in`.web.fit.off.response.ProceedingFitOffResponse
import com.fitmate.myfit.application.port.`in`.fit.off.command.DeleteFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.GetProceedingFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.RegisterFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.UpdateFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.*
import com.fitmate.myfit.application.port.`in`.fit.off.response.DeleteFitOffResponseDto
import com.fitmate.myfit.application.port.`in`.fit.off.response.RegisterFitOffResponseDto
import com.fitmate.myfit.application.port.`in`.fit.off.response.UpdateFitOffResponseDto
Expand Down Expand Up @@ -136,4 +133,13 @@ class FitOffService(

return ProceedingFitOffResponse(fitOffDetailList)
}

@Transactional(readOnly = true)
override fun getProceedingFitOffByUser(command: GetProceedingFitOffUserCommand): ProceedingFitOffResponse {
val fitOffDetailList = readFitOffPort.findProceedingFitOffByUserId(command.userId)
.map { FitOffDetail(it.id!!, it.userId, it.fitOffStartDate, it.fitOffEndDate, it.fitOffReason) }
.toList()

return ProceedingFitOffResponse(fitOffDetailList)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import com.fitmate.myfit.adapter.`in`.web.fit.off.response.FitOffDetail
import com.fitmate.myfit.adapter.`in`.web.fit.off.response.ProceedingFitOffResponse
import com.fitmate.myfit.adapter.out.api.DateParseUtils
import com.fitmate.myfit.adapter.out.api.SenderUtils
import com.fitmate.myfit.application.port.`in`.fit.off.command.DeleteFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.GetProceedingFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.RegisterFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.UpdateFitOffCommand
import com.fitmate.myfit.application.port.`in`.fit.off.command.*
import com.fitmate.myfit.application.port.`in`.fit.off.response.DeleteFitOffResponseDto
import com.fitmate.myfit.application.port.`in`.fit.off.response.RegisterFitOffResponseDto
import com.fitmate.myfit.application.port.`in`.fit.off.response.UpdateFitOffResponseDto
Expand Down Expand Up @@ -248,4 +245,47 @@ class FitOffControllerTest {
)
)
}

@Test
@DisplayName("[단위][Web Adapter] 진행중인 Fit off user id로 조회 - 성공 테스트")
@Throws(Exception::class)
fun `get proceeding fit off by user id controller success test`() {
//given
val responseDto = listOf<FitOffDetail>(FitOffDetail(51L, 16, Instant.now(), Instant.now(), "test"))
val response = ProceedingFitOffResponse(responseDto)

whenever(readFitOffUseCase.getProceedingFitOffByUser(any<GetProceedingFitOffUserCommand>()))
.thenReturn(response)
//when
val resultActions = mockMvc.perform(
get(
GlobalURI.FIT_OFF_USER + GlobalURI.PATH_VARIABLE_USER_ID_WITH_BRACE, requestUserId
).contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
)
//then
resultActions.andExpect(status().isOk())
.andDo(print())
.andDo(
document(
"get-proceeding-fit-off-by-user-id",
pathParameters(
parameterWithName(GlobalURI.PATH_VARIABLE_USER_ID)
.description("조회할 fit user id")
),
responseFields(
fieldWithPath("content[]").type(JsonFieldType.ARRAY).description("현재 진행중인 fit off 목록"),
fieldWithPath("content[].fitOffId").type(JsonFieldType.NUMBER).description("fit off id"),
fieldWithPath("content[].userId").type(JsonFieldType.NUMBER)
.description("fit off를 등록한 user id"),
fieldWithPath("content[].fitOffStartDate").type(JsonFieldType.STRING)
.description("fit off 시작일"),
fieldWithPath("content[].fitOffEndDate").type(JsonFieldType.STRING)
.description("fit off 종료일"),
fieldWithPath("content[].fitOffReason").type(JsonFieldType.STRING)
.description("fit off 사유")
)
)
)
}
}

0 comments on commit 7272073

Please sign in to comment.