Skip to content

Commit

Permalink
refactor: (#301) Request 개선 적용 - adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 committed Jan 23, 2023
1 parent 3042bbd commit dcc89b3
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.*
import team.comit.simtong.domain.auth.dto.response.TokenResponse
import team.comit.simtong.domain.auth.usecase.ReissueTokenUseCase
import team.comit.simtong.domain.common.dto.ChangePasswordRequest
import team.comit.simtong.domain.common.dto.FindEmployeeNumberRequest
import team.comit.simtong.domain.common.dto.ResetPasswordRequest
import team.comit.simtong.domain.spot.dto.SpotResponse
import team.comit.simtong.domain.spot.usecase.ShowSpotListUseCase
Expand All @@ -25,6 +24,8 @@ import java.util.UUID
import javax.validation.Valid
import javax.validation.constraints.Email
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotEmpty
import javax.validation.constraints.NotNull

/**
*
Expand All @@ -50,13 +51,21 @@ class WebCommonAdapter(
) {

@GetMapping("/employee-number")
fun findEmployeeNumber(@Valid @ModelAttribute request: FindEmployeeNumberRequest): FindEmployeeNumberResponse {
return findEmployeeNumberUseCase.execute(request.toData())
fun findEmployeeNumber(
@NotBlank @RequestParam name: String?,
@NotNull @RequestParam("spot_id") spotId: UUID?,
@NotEmpty @Email @RequestParam email: String?
): FindEmployeeNumberResponse {
return findEmployeeNumberUseCase.execute(
name = name!!,
spotId = spotId!!,
email = email!!
)
}

@PutMapping("/token/reissue")
fun reissueJsonWebToken(@RequestHeader("Refresh-Token") request: String): TokenResponse {
return reissueTokenUseCase.execute(request)
fun reissueJsonWebToken(@NotNull @RequestHeader("Refresh-Token") token: String?): TokenResponse {
return reissueTokenUseCase.execute(token!!)
}

@PutMapping("/password/initialization")
Expand All @@ -66,8 +75,8 @@ class WebCommonAdapter(
}

@GetMapping("/email/duplication")
fun checkEmailDuplication(@Email @NotBlank @RequestParam email: String) {
checkEmailDuplicationUseCase.execute(email)
fun checkEmailDuplication(@NotEmpty @Email @RequestParam email: String?) {
checkEmailDuplicationUseCase.execute(email!!)
}

@PutMapping("/password")
Expand All @@ -78,12 +87,14 @@ class WebCommonAdapter(

@GetMapping("/account/existence")
fun checkMatchedAccount(
@Range(min = EmployeeNumber.MIN_VALUE, max = EmployeeNumber.MAX_VALUE)
@RequestParam employeeNumber: Int,
@NotBlank @Email
@RequestParam email: String
@NotNull @Range(min = EmployeeNumber.MIN_VALUE, max = EmployeeNumber.MAX_VALUE)
@RequestParam employeeNumber: Int?,
@NotEmpty @Email @RequestParam email: String?
) {
checkMatchedAccountUseCase.execute(employeeNumber, email)
checkMatchedAccountUseCase.execute(
employeeNumber = employeeNumber!!,
email = email!!
)
}

@GetMapping("/spot")
Expand All @@ -92,8 +103,8 @@ class WebCommonAdapter(
}

@GetMapping("/password/compare")
fun comparePassword(@NotBlank @RequestParam password: String) {
comparePasswordUseCase.execute(password)
fun comparePassword(@NotBlank @RequestParam password: String?) {
comparePasswordUseCase.execute(password!!)
}

@GetMapping("/team/{spot-id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package team.comit.simtong.domain.email

import org.hibernate.validator.constraints.Length
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
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.auth.usecase.CheckAuthCodeUseCase
import team.comit.simtong.domain.auth.usecase.SendAuthCodeUseCase
import team.comit.simtong.domain.email.dto.CheckAuthCodeRequest
import team.comit.simtong.domain.email.dto.SendAuthCodeRequest
import javax.validation.Valid
import javax.validation.constraints.Email
import javax.validation.constraints.NotEmpty
import javax.validation.constraints.NotNull

/**
*
Expand All @@ -19,6 +24,7 @@ import javax.validation.Valid
* @date 2022/09/24
* @version 1.0.0
**/
@Validated
@RestController
@RequestMapping("/emails")
class WebEmailAdapter(
Expand All @@ -32,8 +38,14 @@ class WebEmailAdapter(
}

@GetMapping
fun checkAuthCode(@Valid request: CheckAuthCodeRequest) {
checkAuthCodeUseCase.execute(request.toData())
fun checkAuthCode(
@NotEmpty @Email @RequestParam email: String?,
@NotNull @Length(min = 6, max = 6) @RequestParam code: String?
) {
checkAuthCodeUseCase.execute(
email = email!!,
code = code!!
)
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package team.comit.simtong.domain.file

import org.springframework.http.HttpStatus
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
Expand All @@ -12,6 +14,7 @@ import team.comit.simtong.domain.file.dto.response.UploadImageListResponse
import team.comit.simtong.domain.file.dto.response.UploadImageResponse
import team.comit.simtong.domain.file.usecase.RegisterEmployeeCertificateUseCase
import team.comit.simtong.domain.file.usecase.UploadImageUseCase
import javax.validation.constraints.NotNull

/**
*
Expand All @@ -21,6 +24,7 @@ import team.comit.simtong.domain.file.usecase.UploadImageUseCase
* @date 2022/09/21
* @version 1.2.5
**/
@Validated
@RestController
@RequestMapping("/files")
class WebFileAdapter(
Expand All @@ -30,25 +34,25 @@ class WebFileAdapter(

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
fun uploadSingleImage(file: MultipartFile): UploadImageResponse {
fun uploadSingleImage(@NotNull @RequestPart file: MultipartFile?): UploadImageResponse {
return uploadImageUseCase.execute(
file.let(ImageFileConverter::transferTo)
file!!.let(ImageFileConverter::transferTo)
)
}

@PostMapping("/list")
@ResponseStatus(HttpStatus.CREATED)
fun uploadMultipleImage(files: List<MultipartFile>): UploadImageListResponse {
fun uploadMultipleImage(@NotNull @RequestPart files: List<MultipartFile>?): UploadImageListResponse {
return uploadImageUseCase.execute(
files.let(ImageFileConverter::transferToList)
files!!.let(ImageFileConverter::transferToList)
)
}

@PostMapping("/employee")
@ResponseStatus(HttpStatus.CREATED)
fun importEmployeeCertificate(file: MultipartFile) {
fun importEmployeeCertificate(@NotNull @RequestPart file: MultipartFile?) {
registerEmployeeCertificateUseCase.execute(
file.let(ExcelFileConverter::transferTo)
file!!.let(ExcelFileConverter::transferTo)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.comit.simtong.domain.holiday

import org.springframework.http.HttpStatus
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
Expand Down Expand Up @@ -35,6 +36,7 @@ import team.comit.simtong.domain.holiday.usecase.ShareHolidayUseCase
import java.time.LocalDate
import java.util.UUID
import javax.validation.Valid
import javax.validation.constraints.NotNull

/**
*
Expand All @@ -45,6 +47,7 @@ import javax.validation.Valid
* @date 2022/12/03
* @version 1.2.3
**/
@Validated
@RestController
@RequestMapping("/holidays")
class WebHolidayAdapter(
Expand All @@ -62,37 +65,37 @@ class WebHolidayAdapter(
) {

@GetMapping("/annual/count")
fun queryRemainAnnual(@RequestParam year: Int): QueryRemainAnnualResponse {
return queryRemainAnnualUseCase.execute(year)
fun queryRemainAnnual(@NotNull @RequestParam year: Int?): QueryRemainAnnualResponse {
return queryRemainAnnualUseCase.execute(year!!)
}

@PostMapping("/annual")
@ResponseStatus(HttpStatus.CREATED)
fun appointAnnual(@RequestBody request: AppointAnnualRequest) {
fun appointAnnual(@Valid @RequestBody request: AppointAnnualRequest) {
appointAnnualUseCase.execute(request.toData())
}

@PostMapping("/dayoff")
@ResponseStatus(HttpStatus.CREATED)
fun appointHoliday(@RequestBody request: AppointHolidayRequest) {
fun appointHoliday(@Valid @RequestBody request: AppointHolidayRequest) {
appointHolidayUseCase.execute(request.toData())
}

@PutMapping("/work")
fun cancelHoliday(@RequestBody request: CancelHolidayRequest) {
fun cancelHoliday(@Valid @RequestBody request: CancelHolidayRequest) {
cancelHolidayUseCase.execute(request.toData())
}

@GetMapping("/individual")
fun queryIndividualHolidays(
@RequestParam("start_at") startAt: LocalDate,
@RequestParam("end_at") endAt: LocalDate,
@RequestParam status: HolidayStatus
@NotNull @RequestParam("start_at") startAt: LocalDate?,
@NotNull @RequestParam("end_at") endAt: LocalDate?,
@NotNull @RequestParam status: HolidayStatus?
): QueryIndividualHolidaysResponse {
return queryIndividualHolidayUseCase.execute(
startAt = startAt,
endAt = endAt,
status = status
startAt = startAt!!,
endAt = endAt!!,
status = status!!
)
}

Expand All @@ -109,15 +112,15 @@ class WebHolidayAdapter(

@GetMapping("/employee")
fun queryEmployeeHolidays(
@RequestParam year: Int,
@RequestParam month: Int,
@RequestParam type: HolidayQueryType,
@NotNull @RequestParam year: Int?,
@NotNull @RequestParam month: Int?,
@NotNull @RequestParam type: HolidayQueryType?,
@RequestParam("team_id", required = false) teamId: UUID?
): QueryEmployeeHolidayResponse {
return queryEmployeeHolidayUseCase.execute(
year = year,
month = month,
type = type,
year = year!!,
month = month!!,
type = type!!,
teamId = teamId
)
}
Expand All @@ -135,9 +138,12 @@ class WebHolidayAdapter(

@GetMapping("/period")
fun queryMonthHolidayPeriod(
@RequestParam year: Int,
@RequestParam month: Int
@NotNull @RequestParam year: Int?,
@NotNull @RequestParam month: Int?
): QueryMonthHolidayPeriodResponse {
return queryMonthHolidayPeriodUseCase.execute(year, month)
return queryMonthHolidayPeriodUseCase.execute(
year = year!!,
month = month!!
)
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package team.comit.simtong.domain.menu

import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RestController
import team.comit.simtong.domain.menu.dto.SaveMenuRequest
import org.springframework.web.multipart.MultipartFile
import team.comit.simtong.domain.file.converter.ExcelFileConverter
import team.comit.simtong.domain.menu.dto.response.MenuResponse
import team.comit.simtong.domain.menu.usecase.QueryMenuByMonthUseCase
import team.comit.simtong.domain.menu.usecase.QueryPublicMenuUseCase
import team.comit.simtong.domain.menu.usecase.SaveMenuUseCase
import java.time.LocalDate
import java.util.UUID
import javax.validation.Valid
import javax.validation.constraints.NotNull

/**
*
Expand All @@ -25,6 +27,7 @@ import javax.validation.Valid
* @date 2022/09/25
* @version 1.0.0
**/
@Validated
@RestController
@RequestMapping("/menu")
class WebMenuAdapter(
Expand All @@ -35,25 +38,38 @@ class WebMenuAdapter(

@GetMapping
fun getMenu(
@RequestParam("start_at") startAt: LocalDate,
@RequestParam("end_at") endAt: LocalDate
@NotNull @RequestParam("start_at") startAt: LocalDate?,
@NotNull @RequestParam("end_at") endAt: LocalDate?
): MenuResponse {
return queryMenuByMonthUseCase.execute(startAt, endAt)
return queryMenuByMonthUseCase.execute(
startAt = startAt!!,
endAt = endAt!!
)
}

@GetMapping("/public")
fun getPublicMenu(
@RequestParam("start_at") startAt: LocalDate,
@RequestParam("end_at") endAt: LocalDate
@NotNull @RequestParam("start_at") startAt: LocalDate?,
@NotNull @RequestParam("end_at") endAt: LocalDate?
): MenuResponse {
return queryPublicMenuUseCase.execute(startAt, endAt)
return queryPublicMenuUseCase.execute(
startAt = startAt!!,
endAt = endAt!!
)
}

@PostMapping("/{spot-id}")
fun saveMenu(
@PathVariable("spot-id") spotId: UUID,
@Valid @ModelAttribute request: SaveMenuRequest
@NotNull @RequestPart file: MultipartFile?,
@NotNull @RequestParam year: Int?,
@NotNull @RequestParam month: Int?
) {
saveMenuUseCase.execute(request.toData(), spotId)
saveMenuUseCase.execute(
spotId = spotId,
file = file!!.let(ExcelFileConverter::transferTo),
year = year!!,
month = month!!
)
}
}
Loading

0 comments on commit dcc89b3

Please sign in to comment.