Skip to content

Commit

Permalink
refactor: (#281) Response Wrapping 동작 담당
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 committed Jan 11, 2023
1 parent 90a35b6 commit 35e1b00
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import org.springframework.web.bind.annotation.*
import team.comit.simtong.domain.auth.dto.TokenResponse
import team.comit.simtong.domain.auth.usecase.ReissueTokenUseCase
import team.comit.simtong.domain.common.dto.request.ChangePasswordWebRequest
import team.comit.simtong.domain.common.dto.request.CheckMatchedAccountWebRequest
import team.comit.simtong.domain.common.dto.request.FindEmployeeNumberWebRequest
import team.comit.simtong.domain.common.dto.request.ResetPasswordWebRequest
import team.comit.simtong.domain.common.dto.response.FindEmployeeNumberWebResponse
import team.comit.simtong.domain.spot.dto.SpotResponse
import team.comit.simtong.domain.common.dto.response.QueryTeamsWebResponse
import team.comit.simtong.domain.common.dto.response.SpotWebResponse
import team.comit.simtong.domain.spot.usecase.ShowSpotListUseCase
import team.comit.simtong.domain.team.dto.QueryTeamsResponse
import team.comit.simtong.domain.team.usecase.QueryTeamsUseCase
import team.comit.simtong.domain.user.dto.ChangePasswordRequest
import team.comit.simtong.domain.user.dto.CheckMatchedAccountRequest
Expand Down Expand Up @@ -53,15 +54,13 @@ class WebCommonAdapter(

@GetMapping("/employee-number")
fun findEmployeeNumber(@Valid @ModelAttribute request: FindEmployeeNumberWebRequest): FindEmployeeNumberWebResponse {
val result = findEmployeeNumberUseCase.execute(
return findEmployeeNumberUseCase.execute(
FindEmployeeNumberRequest(
name = request.name,
spotId = request.spotId,
email = request.email
)
)

return FindEmployeeNumberWebResponse(result)
).run(::FindEmployeeNumberWebResponse)
}

@PutMapping("/token/reissue")
Expand Down Expand Up @@ -98,7 +97,7 @@ class WebCommonAdapter(
}

@GetMapping("/account/existence")
fun checkMatchedAccount(@Valid @ModelAttribute request: CheckMatchedAccountRequest) {
fun checkMatchedAccount(@Valid @ModelAttribute request: CheckMatchedAccountWebRequest) {
checkMatchedAccountUseCase.execute(
CheckMatchedAccountRequest(
employeeNumber = request.employeeNumber,
Expand All @@ -108,8 +107,16 @@ class WebCommonAdapter(
}

@GetMapping("/spot")
fun showSpotList(): SpotResponse {
fun showSpotList(): SpotWebResponse {
return showSpotListUseCase.execute()
.map {
SpotWebResponse.SpotElement(
id = it.id,
name = it.name,
location = it.location
)
}
.run(::SpotWebResponse)
}

@GetMapping("/password/compare")
Expand All @@ -118,8 +125,14 @@ class WebCommonAdapter(
}

@GetMapping("/team/{spot-id}")
fun queryTeams(@PathVariable(name = "spot-id") spotId: UUID): QueryTeamsResponse {
fun queryTeams(@PathVariable(name = "spot-id") spotId: UUID): QueryTeamsWebResponse {
return queryTeamsUseCase.execute(spotId)
.map {
QueryTeamsWebResponse.TeamElement(
id = it.id,
name = it.name
)
}
.run(::QueryTeamsWebResponse)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import team.comit.simtong.domain.file.dto.response.UploadImageListWebResponse
import team.comit.simtong.domain.file.dto.response.UploadImageWebResponse
import team.comit.simtong.domain.file.converter.ExcelFileConverter
import team.comit.simtong.domain.file.converter.ImageFileConverter
import team.comit.simtong.domain.file.dto.response.UploadImageListWebResponse
import team.comit.simtong.domain.file.dto.response.UploadImageWebResponse
import team.comit.simtong.domain.file.usecase.RegisterEmployeeCertificateUseCase
import team.comit.simtong.domain.file.usecase.UploadImageUseCase

Expand All @@ -31,21 +31,17 @@ class WebFileAdapter(
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
fun uploadSingleImage(file: MultipartFile): UploadImageWebResponse {
return UploadImageWebResponse(
uploadImageUseCase.execute(
file.let(ImageFileConverter::transferTo)
)
)
return uploadImageUseCase.execute(
file.let(ImageFileConverter::transferTo)
).run(::UploadImageWebResponse)
}

@PostMapping("/list")
@ResponseStatus(HttpStatus.CREATED)
fun uploadMultipleImage(files: List<MultipartFile>): UploadImageListWebResponse {
return UploadImageListWebResponse(
uploadImageUseCase.execute(
files.let(ImageFileConverter::transferToList)
)
)
return uploadImageUseCase.execute(
files.let(ImageFileConverter::transferToList)
).run(::UploadImageListWebResponse)
}

@PostMapping("/employee")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import team.comit.simtong.domain.holiday.dto.AppointHolidayPeriodRequest
import team.comit.simtong.domain.holiday.dto.QueryEmployeeHolidayResponse
import team.comit.simtong.domain.holiday.dto.QueryIndividualHolidaysResponse
import team.comit.simtong.domain.holiday.dto.response.QueryEmployeeHolidayWebResponse
import team.comit.simtong.domain.holiday.dto.QueryIndividualRequest
import team.comit.simtong.domain.holiday.dto.QueryMonthHolidayPeriodResponse
import team.comit.simtong.domain.holiday.dto.request.AppointAnnualWebRequest
Expand All @@ -20,9 +19,13 @@ import team.comit.simtong.domain.holiday.dto.request.AppointHolidayWebRequest
import team.comit.simtong.domain.holiday.dto.request.CancelHolidayWebRequest
import team.comit.simtong.domain.holiday.dto.request.ChangeEmployeeHolidayWebRequest
import team.comit.simtong.domain.holiday.dto.request.ShareHolidayWebRequest
import team.comit.simtong.domain.holiday.dto.response.IndividualHolidayResponse
import team.comit.simtong.domain.holiday.dto.response.QueryIndividualHolidaysWebResponse
import team.comit.simtong.domain.holiday.dto.response.QueryRemainAnnualWebResponse
import team.comit.simtong.domain.holiday.model.Holiday
import team.comit.simtong.domain.holiday.model.value.HolidayQueryType
import team.comit.simtong.domain.holiday.model.value.HolidayStatus
import team.comit.simtong.domain.holiday.spi.vo.EmployeeHoliday
import team.comit.simtong.domain.holiday.usecase.AppointAnnualUseCase
import team.comit.simtong.domain.holiday.usecase.AppointHolidayPeriodUseCase
import team.comit.simtong.domain.holiday.usecase.AppointHolidayUseCase
Expand Down Expand Up @@ -65,9 +68,8 @@ class WebHolidayAdapter(

@GetMapping("/annual/count")
fun queryRemainAnnual(@RequestParam year: Int): QueryRemainAnnualWebResponse {
return QueryRemainAnnualWebResponse(
queryRemainAnnualUseCase.execute(year)
)
return queryRemainAnnualUseCase.execute(year)
.run(::QueryRemainAnnualWebResponse)
}

@PostMapping("/annual")
Expand All @@ -92,14 +94,21 @@ class WebHolidayAdapter(
@RequestParam("start_at") startAt: LocalDate,
@RequestParam("end_at") endAt: LocalDate,
@RequestParam status: HolidayStatus
): QueryIndividualHolidaysResponse {
return queryIndividualHolidayUseCase.execute(
): QueryIndividualHolidaysWebResponse {
val result: List<Holiday> = queryIndividualHolidayUseCase.execute(
QueryIndividualRequest(
startAt = startAt,
endAt = endAt,
status = status.name
status = status
)
)

return result.map {
IndividualHolidayResponse(
date = it.date,
type = it.type
)
}.run(::QueryIndividualHolidaysWebResponse)
}

@PutMapping("/public")
Expand All @@ -122,13 +131,26 @@ class WebHolidayAdapter(
@RequestParam month: Int,
@RequestParam type: HolidayQueryType,
@RequestParam("team_id", required = false) teamId: UUID?
): QueryEmployeeHolidayResponse {
return queryEmployeeHolidayUseCase.execute(
): QueryEmployeeHolidayWebResponse {
val result: List<EmployeeHoliday> = queryEmployeeHolidayUseCase.execute(
year = year,
month = month,
type = type,
teamId = teamId
)

return result.map {
QueryEmployeeHolidayWebResponse.Holiday(
date = it.date,
type = it.type,
user = QueryEmployeeHolidayWebResponse.Holiday.Employee(
id = it.userId,
name = it.userName,
team = it.teamName,
spot = it.spotName
)
)
}.run(::QueryEmployeeHolidayWebResponse)
}

@PutMapping("/employee")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import team.comit.simtong.domain.file.converter.ExcelFileConverter
import team.comit.simtong.domain.menu.dto.MenuResponse
import team.comit.simtong.domain.menu.dto.SaveMenuRequest
import team.comit.simtong.domain.menu.dto.request.SaveMenuWebRequest
import team.comit.simtong.domain.menu.dto.response.MenuWebResponse
import team.comit.simtong.domain.menu.usecase.QueryMenuByMonthUseCase
import team.comit.simtong.domain.menu.usecase.QueryPublicMenuUseCase
import team.comit.simtong.domain.menu.usecase.SaveMenuUseCase
Expand All @@ -25,7 +25,7 @@ import javax.validation.Valid
* @author kimbeomjin
* @author Chokyunghyeon
* @date 2022/09/25
* @version 1.0.0
* @version 1.2.5
**/
@RestController
@RequestMapping("/menu")
Expand All @@ -39,16 +39,30 @@ class WebMenuAdapter(
fun getMenu(
@RequestParam("start_at") startAt: LocalDate,
@RequestParam("end_at") endAt: LocalDate
): MenuResponse {
): MenuWebResponse {
return queryMenuByMonthUseCase.execute(startAt, endAt)
.map {
MenuWebResponse.MenuElement(
date = it.date,
meal = it.meal
)
}
.run(::MenuWebResponse)
}

@GetMapping("/public")
fun getPublicMenu(
@RequestParam("start_at") startAt: LocalDate,
@RequestParam("end_at") endAt: LocalDate
): MenuResponse {
): MenuWebResponse {
return queryPublicMenuUseCase.execute(startAt, endAt)
.map {
MenuWebResponse.MenuElement(
date = it.date,
meal = it.meal
)
}
.run(::MenuWebResponse)
}

@PostMapping("/{spot-id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ import team.comit.simtong.domain.schedule.dto.AddIndividualScheduleRequest
import team.comit.simtong.domain.schedule.dto.AddSpotScheduleRequest
import team.comit.simtong.domain.schedule.dto.ChangeIndividualScheduleRequest
import team.comit.simtong.domain.schedule.dto.ChangeSpotScheduleRequest
import team.comit.simtong.domain.schedule.dto.QueryEntireSpotScheduleResponse
import team.comit.simtong.domain.schedule.dto.QueryIndividualSpotScheduleResponse
import team.comit.simtong.domain.schedule.dto.request.AddIndividualScheduleWebRequest
import team.comit.simtong.domain.schedule.dto.request.AddSpotScheduleWebRequest
import team.comit.simtong.domain.schedule.dto.request.ChangeIndividualScheduleWebRequest
import team.comit.simtong.domain.schedule.dto.request.ChangeSpotScheduleWebRequest
import team.comit.simtong.domain.schedule.dto.response.QueryEntireSpotScheduleWebResponse
import team.comit.simtong.domain.schedule.dto.response.QueryIndividualSpotScheduleWebResponse
import team.comit.simtong.domain.schedule.dto.response.ScheduleResponse
import team.comit.simtong.domain.schedule.dto.response.SpotScheduleResponse
import team.comit.simtong.domain.schedule.model.Schedule
import team.comit.simtong.domain.schedule.spi.vo.SpotSchedule
import team.comit.simtong.domain.schedule.usecase.AddIndividualScheduleUseCase
import team.comit.simtong.domain.schedule.usecase.AddSpotScheduleUseCase
import team.comit.simtong.domain.schedule.usecase.ChangeIndividualScheduleUseCase
Expand Down Expand Up @@ -88,16 +92,39 @@ class WebScheduleAdapter(
fun queryIndividualSpotSchedule(
@RequestParam("start_at") startAt: LocalDate,
@RequestParam("end_at") endAt: LocalDate
): QueryIndividualSpotScheduleResponse {
return queryIndividualSpotScheduleUseCase.execute(startAt, endAt)
): QueryIndividualSpotScheduleWebResponse {
val result: List<Schedule> = queryIndividualSpotScheduleUseCase.execute(startAt, endAt)

return result.map {
ScheduleResponse(
id = it.id,
startAt = it.startAt,
endAt = it.endAt,
title = it.title,
scope = it.scope
)
}.run(::QueryIndividualSpotScheduleWebResponse)
}

@GetMapping("/spots")
fun queryEntireSpotSchedule(
@RequestParam("start_at") startAt: LocalDate,
@RequestParam("end_at") endAt: LocalDate
): QueryEntireSpotScheduleResponse {
return queryEntireSpotScheduleUseCase.execute(startAt, endAt)
): QueryEntireSpotScheduleWebResponse {
val result: List<SpotSchedule> = queryEntireSpotScheduleUseCase.execute(startAt, endAt)

return result.map {
SpotScheduleResponse(
id = it.id,
title = it.title,
startAt = it.startAt,
endAt = it.endAt,
spot = SpotScheduleResponse.SpotElement(
id = it.spotId,
name = it.spotName
)
)
}.run(::QueryEntireSpotScheduleWebResponse)
}

@PostMapping("/spots/{spot-id}")
Expand Down

0 comments on commit 35e1b00

Please sign in to comment.