Skip to content

Commit

Permalink
merge: (#281) 파일 & 이메일 & 관리자 dto 리팩토링 (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
khcho0125 authored Jan 18, 2023
2 parents 70288c1 + aeed9b5 commit bf6335f
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team.comit.simtong.domain.auth.dto.request

/**
*
* 인증 코드 확인 요청 정보를 전달하는 CheckAuthCodeData
*
* @author Chokyunghyeon
* @date 2023/01/14
* @version 1.2.5
**/
data class CheckAuthCodeData(
val email: String,

val code: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package team.comit.simtong.domain.auth.dto.request

/**
*
* 인증 코드 전송 요청 정보를 전달하는 SendAuthCodeData
*
* @author Chokyunghyeon
* @date 2023/01/14
* @version 1.2.5
**/
data class SendAuthCodeData(
val email: String
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.comit.simtong.domain.auth.usecase

import team.comit.simtong.domain.auth.dto.request.CheckAuthCodeData
import team.comit.simtong.domain.auth.exception.AuthExceptions
import team.comit.simtong.domain.auth.model.AuthCodeLimit
import team.comit.simtong.domain.auth.spi.CommandAuthCodeLimitPort
Expand All @@ -21,16 +22,16 @@ class CheckAuthCodeUseCase(
private val queryAuthCodePort: QueryAuthCodePort
) {

fun execute(email: String, code: String) {
val authCode = queryAuthCodePort.queryAuthCodeByEmail(email)
fun execute(request: CheckAuthCodeData) {
val authCode = queryAuthCodePort.queryAuthCodeByEmail(request.email)
?: throw AuthExceptions.RequiredNewEmailAuthentication()

if (!authCode.code.match(code)) {
if (!authCode.code.match(request.code)) {
throw AuthExceptions.DifferentAuthCode()
}

commandAuthCodeLimitPort.save(
AuthCodeLimit.certified(email)
AuthCodeLimit.certified(request.email)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team.comit.simtong.domain.auth.usecase

import team.comit.simtong.domain.auth.dto.request.SendAuthCodeData
import team.comit.simtong.domain.auth.model.AuthCode
import team.comit.simtong.domain.auth.model.AuthCodeLimit
import team.comit.simtong.domain.auth.spi.CommandAuthCodeLimitPort
Expand All @@ -24,18 +25,18 @@ class SendAuthCodeUseCase(
private val sendEmailPort: SendEmailPort
) {

fun execute(email: String) {
val authCodeLimit = queryAuthCodeLimitPort.queryAuthCodeLimitByEmail(email)
?: AuthCodeLimit.issue(email)
fun execute(request: SendAuthCodeData) {
val authCodeLimit = queryAuthCodeLimitPort.queryAuthCodeLimitByEmail(request.email)
?: AuthCodeLimit.issue(request.email)

commandAuthCodeLimitPort.save(
authCodeLimit.increaseCount()
)

val authCode = commandAuthCodePort.save(
AuthCode.issue(email)
AuthCode.issue(request.email)
)

sendEmailPort.sendAuthCode(authCode.code.value, email)
sendEmailPort.sendAuthCode(authCode.code.value, request.email)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package team.comit.simtong.domain.file.dto.response

/**
*
* 다중 이미지 업로드 요청 결과를 전송하는 UploadImageListWebResponse
* 다중 이미지 업로드 요청 결과를 전송하는 UploadImageListResponse
*
* @author Chokyunghyeon
* @date 2022/09/21
* @version 1.0.0
* @version 1.2.5
**/
data class UploadImageListWebResponse(
data class UploadImageListResponse(
val filePathList: List<String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package team.comit.simtong.domain.file.dto.response

/**
*
* 단일 이미지 업로드 요청 결과를 전송하는 UploadImageWebResponse
* 단일 이미지 업로드 요청 결과를 전송하는 UploadImageResponse
*
* @author Chokyunghyeon
* @date 2022/09/21
* @version 1.0.0
* @version 1.2.5
**/
data class UploadImageWebResponse(
data class UploadImageResponse(
val filePath: String
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package team.comit.simtong.domain.file.usecase

import team.comit.simtong.domain.file.dto.response.UploadImageListResponse
import team.comit.simtong.domain.file.dto.response.UploadImageResponse
import team.comit.simtong.domain.file.spi.UploadFilePort
import team.comit.simtong.global.annotation.UseCase
import java.io.File
Expand All @@ -10,18 +12,20 @@ import java.io.File
*
* @author Chokyunghyeon
* @date 2022/09/20
* @version 1.0.0
* @version 1.2.5
**/
@UseCase
class UploadImageUseCase(
private val uploadFilePort: UploadFilePort
) {

fun execute(file: File): String {
fun execute(file: File): UploadImageResponse {
return uploadFilePort.upload(file)
.let(::UploadImageResponse)
}

fun execute(files: List<File>): List<String> {
fun execute(files: List<File>): UploadImageListResponse {
return uploadFilePort.upload(files)
.let(::UploadImageListResponse)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows
import org.mockito.BDDMockito.given
import org.springframework.boot.test.mock.mockito.MockBean
import team.comit.simtong.domain.auth.dto.request.CheckAuthCodeData
import team.comit.simtong.domain.auth.exception.AuthExceptions
import team.comit.simtong.domain.auth.model.AuthCode
import team.comit.simtong.domain.auth.model.Code
Expand Down Expand Up @@ -36,14 +37,16 @@ class CheckAuthCodeUseCaseTests {
)
}

private val differentAuthCodeStub by lazy {
private val differentAuthCodeStub: AuthCode by lazy {
AuthCode(
key = email,
code = Code.of("654321"),
expirationTime = AuthCode.EXPIRED
)
}

private val requestStub = CheckAuthCodeData(email, code)

@BeforeEach
fun setUp() {
checkAuthCodeUseCase = CheckAuthCodeUseCase(
Expand All @@ -60,7 +63,7 @@ class CheckAuthCodeUseCaseTests {

// when & then
assertDoesNotThrow {
checkAuthCodeUseCase.execute(email, code)
checkAuthCodeUseCase.execute(requestStub)
}
}

Expand All @@ -72,7 +75,7 @@ class CheckAuthCodeUseCaseTests {

// when & then
assertThrows<AuthExceptions.RequiredNewEmailAuthentication> {
checkAuthCodeUseCase.execute(email, code)
checkAuthCodeUseCase.execute(requestStub)
}
}

Expand All @@ -84,7 +87,7 @@ class CheckAuthCodeUseCaseTests {

// when & then
assertThrows<AuthExceptions.DifferentAuthCode> {
checkAuthCodeUseCase.execute(email, code)
checkAuthCodeUseCase.execute(requestStub)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.mockito.BDDMockito.given
import org.mockito.BDDMockito.willDoNothing
import org.mockito.kotlin.any
import org.springframework.boot.test.mock.mockito.MockBean
import team.comit.simtong.domain.auth.dto.request.SendAuthCodeData
import team.comit.simtong.domain.auth.exception.AuthExceptions
import team.comit.simtong.domain.auth.model.AuthCode
import team.comit.simtong.domain.auth.model.AuthCodeLimit
Expand Down Expand Up @@ -65,6 +66,8 @@ class SendAuthCodeUseCaseTests {
)
}

private val requestStub = SendAuthCodeData(email)

@BeforeEach
fun setUp() {
sendAuthCodeUseCase = SendAuthCodeUseCase(
Expand All @@ -88,7 +91,7 @@ class SendAuthCodeUseCaseTests {

// when & then
assertDoesNotThrow {
sendAuthCodeUseCase.execute(email)
sendAuthCodeUseCase.execute(requestStub)
}
}

Expand All @@ -100,7 +103,7 @@ class SendAuthCodeUseCaseTests {

// when & then
assertThrows<AuthExceptions.AlreadyCertifiedEmail> {
sendAuthCodeUseCase.execute(email)
sendAuthCodeUseCase.execute(requestStub)
}
}

Expand All @@ -112,7 +115,7 @@ class SendAuthCodeUseCaseTests {

// when & then
assertThrows<AuthExceptions.ExceededSendAuthCodeRequest> {
sendAuthCodeUseCase.execute(email)
sendAuthCodeUseCase.execute(requestStub)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class UploadImageUseCaseTests {
val response = uploadImageUseCase.execute(fileStub)

// then
assertEquals(response, filePathStub)
assertEquals(response.filePath, filePathStub)

}

Expand All @@ -57,7 +57,7 @@ class UploadImageUseCaseTests {
// when
val response = uploadImageUseCase.execute(filesStub)

assertEquals(response, filePathListStub)
assertEquals(response.filePathList, filePathListStub)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ 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.RestController
import team.comit.simtong.domain.admin.dto.request.SignInWebRequest
import team.comit.simtong.domain.admin.dto.AdminSignInRequest
import team.comit.simtong.domain.auth.dto.TokenResponse
import team.comit.simtong.domain.user.dto.request.AdminSignInData
import team.comit.simtong.domain.user.dto.response.QueryAdminInfoResponse
import team.comit.simtong.domain.user.usecase.AdminSignInUseCase
import team.comit.simtong.domain.user.usecase.QueryAdminInfoUseCase
Expand All @@ -29,13 +28,8 @@ class WebAdminAdapter(
) {

@PostMapping("/tokens")
fun signIn(@Valid @RequestBody request: SignInWebRequest): TokenResponse {
return adminSignInUseCase.execute(
AdminSignInData(
employeeNumber = request.employeeNumber.value,
password = request.password.value
)
)
fun signIn(@Valid @RequestBody request: AdminSignInRequest): TokenResponse {
return adminSignInUseCase.execute(request.toData())
}

@GetMapping("/information")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package team.comit.simtong.domain.admin.dto

import org.hibernate.validator.constraints.Range
import team.comit.simtong.domain.user.dto.request.AdminSignInData
import team.comit.simtong.domain.user.model.EmployeeNumber
import javax.validation.constraints.NotBlank

/**
*
* 관리자가 로그인을 요청하는 AdminSignInRequest
*
* @author kimbeomjin
* @author Chokyunghyeon
* @date 2023/01/01
* @version 1.2.5
**/
data class AdminSignInRequest(

@field:Range(min = EmployeeNumber.MIN_VALUE, max = EmployeeNumber.MAX_VALUE)
val employeeNumber: Int,

@field:NotBlank
val password: String
) {

fun toData() = AdminSignInData(
employeeNumber = employeeNumber,
password = password
)
}

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.RequestMapping
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.request.CheckAuthCodeWebRequest
import team.comit.simtong.domain.email.dto.request.SendAuthCodeWebRequest
import team.comit.simtong.domain.email.dto.CheckAuthCodeRequest
import team.comit.simtong.domain.email.dto.SendAuthCodeRequest
import javax.validation.Valid

/**
Expand All @@ -27,13 +27,13 @@ class WebEmailAdapter(
) {

@PostMapping("/code")
fun sendAuthCode(@Valid @RequestBody request: SendAuthCodeWebRequest) {
sendAuthCodeUseCase.execute(request.email)
fun sendAuthCode(@Valid @RequestBody request: SendAuthCodeRequest) {
sendAuthCodeUseCase.execute(request.toData())
}

@GetMapping
fun checkAuthCode(@Valid request: CheckAuthCodeWebRequest) {
checkAuthCodeUseCase.execute(request.email, request.code)
fun checkAuthCode(@Valid request: CheckAuthCodeRequest) {
checkAuthCodeUseCase.execute(request.toData())
}

}
Loading

0 comments on commit bf6335f

Please sign in to comment.