-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[YS-256] feat: 회원가입 연락 받을 이메일 중복 비허용 로직 추가 #80
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8af49ee
feat: implement gateway to add duplicate signup verification
chock-cho 2dc853b
feat: define contactEmailVerificationRequest dto
chock-cho 17518ce
feat: define application level and exception
chock-cho 4c200de
feat: define presentation level(controller, mapper)
chock-cho 5877588
test: add test codes for VerifyContactEmailUseCase
chock-cho 3a9e7f4
refact: rename appropriate parameter naming
chock-cho b7b180a
refact: rename appropriate exception message to meet the convention
chock-cho 5c46772
refact: convert find method to exists method for optimization
chock-cho baedb8b
fix: fix test codes to reflect updation
chock-cho 796b069
fix: convert PostMapping to GetMapping
chock-cho 09c9ea3
fix: add unique constraint in field value to prevent race condition
chock-cho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/dobby/backend/application/usecase/member/VerifyContactEmailUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.dobby.backend.application.usecase.member | ||
|
||
import com.dobby.backend.application.usecase.UseCase | ||
import com.dobby.backend.domain.exception.ContactEmailDuplicateException | ||
import com.dobby.backend.domain.gateway.member.MemberGateway | ||
|
||
class VerifyContactEmailUseCase( | ||
private val memberGateway: MemberGateway | ||
): UseCase<VerifyContactEmailUseCase.Input, VerifyContactEmailUseCase.Output> { | ||
data class Input( | ||
val contactEmail: String | ||
) | ||
|
||
data class Output( | ||
val success: Boolean | ||
) | ||
|
||
override fun execute(input: Input): Output { | ||
if(!memberGateway.existsByContactEmail(input.contactEmail)) | ||
return Output(success = true) | ||
else | ||
throw ContactEmailDuplicateException | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
package com.dobby.backend.presentation.api.controller | ||
|
||
import com.dobby.backend.application.service.MemberService | ||
import com.dobby.backend.presentation.api.dto.request.member.ParticipantSignupRequest | ||
import com.dobby.backend.presentation.api.dto.request.member.ResearcherSignupRequest | ||
import com.dobby.backend.presentation.api.dto.request.member.UpdateParticipantInfoRequest | ||
import com.dobby.backend.presentation.api.dto.request.member.UpdateResearcherInfoRequest | ||
import com.dobby.backend.presentation.api.dto.request.member.* | ||
import com.dobby.backend.presentation.api.dto.response.member.DefaultResponse | ||
import com.dobby.backend.presentation.api.dto.response.member.ParticipantInfoResponse | ||
import com.dobby.backend.presentation.api.dto.response.member.ResearcherInfoResponse | ||
import com.dobby.backend.presentation.api.dto.response.member.SignupResponse | ||
|
@@ -50,6 +48,19 @@ class MemberController( | |
return MemberMapper.toResearcherSignupResponse(output) | ||
} | ||
|
||
@GetMapping("/signup/validate/contact-email") | ||
@Operation( | ||
summary = "연락 받을 이메일 주소 검증 API - 회원가입 시 필수 API", | ||
description = "연락 받을 이메일이 사용 가능한지 검증해주는 API입니다. 사용가능하면 true, 아니면 예외를 던집니다." | ||
) | ||
fun emailAvailableCheck( | ||
@RequestParam contactEmail: String | ||
Comment on lines
+56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) : DefaultResponse { | ||
val input = MemberMapper.toContactEmailVerificationInput(contactEmail) | ||
val output = memberService.validateDuplicatedContactEmail(input) | ||
return MemberMapper.toContactEmailVerificationResponse(output) | ||
} | ||
|
||
@PreAuthorize("hasRole('RESEARCHER')") | ||
@GetMapping("/researchers/me") | ||
@Operation( | ||
|
12 changes: 12 additions & 0 deletions
12
.../com/dobby/backend/presentation/api/dto/request/member/ContactEmailVerificationRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.dobby.backend.presentation.api.dto.request.member | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
import jakarta.validation.constraints.Email | ||
import jakarta.validation.constraints.NotBlank | ||
|
||
data class ContactEmailVerificationRequest ( | ||
@Email(message= "연락 받을 이메일이 유효하지 않습니다.") | ||
@NotBlank(message = "연락 받을 이메일은 공백일 수 없습니다.") | ||
@Schema(description = "연락 받을 이메일") | ||
val contactEmail: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...test/kotlin/com/dobby/backend/application/usecase/member/VerifyContactEmailUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.dobby.backend.application.usecase.member | ||
|
||
import com.dobby.backend.domain.exception.ContactEmailDuplicateException | ||
import com.dobby.backend.domain.gateway.member.MemberGateway | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.assertions.throwables.shouldThrow | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
|
||
class VerifyContactEmailUseCaseTest : BehaviorSpec({ | ||
|
||
val memberGateway = mockk<MemberGateway>() | ||
val verifyContactEmailUseCase = VerifyContactEmailUseCase(memberGateway) | ||
|
||
given("회원 가입 시 이메일 중복 확인") { | ||
|
||
`when`("이메일이 데이터베이스에 존재하지 않는 경우") { | ||
val input = VerifyContactEmailUseCase.Input(contactEmail = "[email protected]") | ||
|
||
every { memberGateway.existsByContactEmail(input.contactEmail) } returns false | ||
|
||
then("이메일 사용 가능 응답을 반환해야 한다") { | ||
val result = verifyContactEmailUseCase.execute(input) | ||
result.success shouldBe true | ||
} | ||
} | ||
|
||
`when`("이메일이 이미 존재하는 경우") { | ||
val input = VerifyContactEmailUseCase.Input(contactEmail = "[email protected]") | ||
|
||
every { memberGateway.existsByContactEmail(input.contactEmail) } returns true | ||
|
||
then("ContactEmailDuplication 예외가 발생해야 한다") { | ||
shouldThrow<ContactEmailDuplicateException> { | ||
verifyContactEmailUseCase.execute(input) | ||
} | ||
} | ||
} | ||
} | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저번 PR에서랑 이번 PR에서 추가된 예외들은 노션에 있는 예외 코드 정리에 업데이트 해주시면 감사합니다~