-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
1,090 additions
and
246 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ application-local.yml | |
|
||
### Kotlin ### | ||
.kotlin | ||
/src/main/resources/application.yml |
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
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/com/dobby/backend/application/mapper/VerificationMapper.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,33 @@ | ||
package com.dobby.backend.application.mapper | ||
|
||
import com.dobby.backend.infrastructure.database.entity.VerificationEntity | ||
import com.dobby.backend.infrastructure.database.entity.enum.VerificationStatus | ||
import com.dobby.backend.presentation.api.dto.request.signup.EmailSendRequest | ||
import com.dobby.backend.presentation.api.dto.response.signup.EmailSendResponse | ||
import com.dobby.backend.presentation.api.dto.response.signup.EmailVerificationResponse | ||
|
||
object VerificationMapper { | ||
fun toEntity(req: EmailSendRequest, code : String): VerificationEntity { | ||
return VerificationEntity( | ||
id= 0, | ||
univMail = req.univEmail, | ||
verificationCode = code, | ||
status = VerificationStatus.HOLD, | ||
expiresAt = null | ||
) | ||
} | ||
|
||
fun toSendResDto() : EmailSendResponse{ | ||
return EmailSendResponse( | ||
isSuccess = true, | ||
message = "해당 학교 이메일로 성공적으로 코드를 전송했습니다. 10분 이내로 인증을 완료해주세요." | ||
) | ||
} | ||
|
||
fun toVerifyResDto() : EmailVerificationResponse { | ||
return EmailVerificationResponse( | ||
isSuccess = true, | ||
message = "학교 메일 인증이 완료되었습니다." | ||
) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/dobby/backend/application/service/EmailService.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,26 @@ | ||
package com.dobby.backend.application.service | ||
|
||
import com.dobby.backend.application.usecase.signupUseCase.email.EmailCodeSendUseCase | ||
import com.dobby.backend.application.usecase.signupUseCase.email.EmailVerificationUseCase | ||
import com.dobby.backend.presentation.api.dto.request.signup.EmailSendRequest | ||
import com.dobby.backend.presentation.api.dto.request.signup.EmailVerificationRequest | ||
import com.dobby.backend.presentation.api.dto.response.signup.EmailSendResponse | ||
import com.dobby.backend.presentation.api.dto.response.signup.EmailVerificationResponse | ||
import jakarta.transaction.Transactional | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class EmailService( | ||
private val emailCodeSendUseCase: EmailCodeSendUseCase, | ||
private val emailVerificationUseCase: EmailVerificationUseCase | ||
) { | ||
@Transactional | ||
fun sendEmail(req: EmailSendRequest) : EmailSendResponse{ | ||
return emailCodeSendUseCase.execute(req) | ||
} | ||
|
||
@Transactional | ||
fun verifyCode(req: EmailVerificationRequest) : EmailVerificationResponse { | ||
return emailVerificationUseCase.execute(req) | ||
} | ||
} |
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
25 changes: 21 additions & 4 deletions
25
src/main/kotlin/com/dobby/backend/application/service/SignupService.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 |
---|---|---|
@@ -1,17 +1,34 @@ | ||
package com.dobby.backend.application.service | ||
|
||
import com.dobby.backend.application.usecase.ParticipantSignupUseCase | ||
import com.dobby.backend.application.usecase.signupUseCase.CreateResearcherUseCase | ||
import com.dobby.backend.application.usecase.signupUseCase.ParticipantSignupUseCase | ||
import com.dobby.backend.application.usecase.signupUseCase.VerifyResearcherEmailUseCase | ||
import com.dobby.backend.domain.exception.EmailNotValidateException | ||
import com.dobby.backend.presentation.api.dto.request.signup.ParticipantSignupRequest | ||
import com.dobby.backend.presentation.api.dto.request.signup.ResearcherSignupRequest | ||
import com.dobby.backend.presentation.api.dto.response.signup.SignupResponse | ||
import jakarta.transaction.Transactional | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SignupService( | ||
private val participantSignupUseCase: ParticipantSignupUseCase | ||
private val participantSignupUseCase: ParticipantSignupUseCase, | ||
private val createResearcherUseCase: CreateResearcherUseCase, | ||
private val verifyResearcherEmailUseCase: VerifyResearcherEmailUseCase | ||
) { | ||
@Transactional | ||
fun participantSignup(input: ParticipantSignupRequest): SignupResponse { | ||
return participantSignupUseCase.execute(input) | ||
return participantSignupUseCase.execute(input) | ||
} | ||
} | ||
|
||
@Transactional | ||
fun researcherSignup(input: ResearcherSignupRequest) : SignupResponse{ | ||
if(!input.emailVerified) { | ||
throw EmailNotValidateException() | ||
} | ||
verifyResearcherEmailUseCase.execute(input.univEmail) | ||
|
||
return createResearcherUseCase.execute(input) | ||
} | ||
|
||
} |
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
31 changes: 31 additions & 0 deletions
31
...ain/kotlin/com/dobby/backend/application/usecase/signupUseCase/CreateResearcherUseCase.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,31 @@ | ||
package com.dobby.backend.application.usecase.signupUseCase | ||
|
||
import com.dobby.backend.application.mapper.SignupMapper | ||
import com.dobby.backend.application.usecase.UseCase | ||
import com.dobby.backend.infrastructure.database.repository.ResearcherRepository | ||
import com.dobby.backend.infrastructure.token.JwtTokenProvider | ||
import com.dobby.backend.presentation.api.dto.request.signup.ResearcherSignupRequest | ||
import com.dobby.backend.presentation.api.dto.response.MemberResponse | ||
import com.dobby.backend.presentation.api.dto.response.signup.SignupResponse | ||
import com.dobby.backend.util.AuthenticationUtils | ||
|
||
class CreateResearcherUseCase( | ||
private val researcherRepository: ResearcherRepository, | ||
private val jwtTokenProvider: JwtTokenProvider | ||
) : UseCase<ResearcherSignupRequest, SignupResponse> { | ||
override fun execute(input: ResearcherSignupRequest): SignupResponse { | ||
val memberEntity = SignupMapper.toResearcherMember(input) | ||
val newResearcher = SignupMapper.toResearcher(memberEntity, input) | ||
researcherRepository.save(newResearcher) | ||
|
||
val authentication = AuthenticationUtils.createAuthentication(memberEntity) | ||
val accessToken = jwtTokenProvider.generateAccessToken(authentication) | ||
val refreshToken = jwtTokenProvider.generateRefreshToken(authentication) | ||
|
||
return SignupResponse( | ||
accessToken = accessToken, | ||
refreshToken = refreshToken, | ||
memberInfo = MemberResponse.fromDomain(newResearcher.member.toDomain()) | ||
) | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...otlin/com/dobby/backend/application/usecase/signupUseCase/VerifyResearcherEmailUseCase.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,22 @@ | ||
package com.dobby.backend.application.usecase.signupUseCase | ||
|
||
import com.dobby.backend.application.usecase.UseCase | ||
import com.dobby.backend.domain.exception.EmailNotValidateException | ||
import com.dobby.backend.domain.exception.VerifyInfoNotFoundException | ||
import com.dobby.backend.infrastructure.database.entity.VerificationEntity | ||
import com.dobby.backend.infrastructure.database.entity.enum.VerificationStatus | ||
import com.dobby.backend.infrastructure.database.repository.VerificationRepository | ||
|
||
class VerifyResearcherEmailUseCase( | ||
private val verificationRepository: VerificationRepository | ||
) : UseCase<String, VerificationEntity> { | ||
override fun execute(input: String): VerificationEntity { | ||
val verificationEntity = verificationRepository.findByUnivMail(input) | ||
?: throw VerifyInfoNotFoundException() | ||
|
||
if (verificationEntity.status != VerificationStatus.VERIFIED) { | ||
throw EmailNotValidateException() | ||
} | ||
return verificationEntity | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
.../kotlin/com/dobby/backend/application/usecase/signupUseCase/email/EmailCodeSendUseCase.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,71 @@ | ||
package com.dobby.backend.application.usecase.signupUseCase.email | ||
|
||
import com.dobby.backend.application.mapper.VerificationMapper | ||
import com.dobby.backend.application.usecase.UseCase | ||
import com.dobby.backend.domain.exception.* | ||
import com.dobby.backend.domain.gateway.EmailGateway | ||
import com.dobby.backend.infrastructure.database.entity.enum.VerificationStatus | ||
import com.dobby.backend.infrastructure.database.repository.VerificationRepository | ||
import com.dobby.backend.presentation.api.dto.request.signup.EmailSendRequest | ||
import com.dobby.backend.presentation.api.dto.response.signup.EmailSendResponse | ||
import com.dobby.backend.util.EmailUtils | ||
import java.time.LocalDateTime | ||
|
||
class EmailCodeSendUseCase( | ||
private val verificationRepository: VerificationRepository, | ||
private val emailGateway: EmailGateway | ||
) : UseCase<EmailSendRequest, EmailSendResponse> { | ||
override fun execute(input: EmailSendRequest): EmailSendResponse { | ||
validateEmail(input.univEmail) | ||
|
||
val code = EmailUtils.generateCode() | ||
reflectVerification(input, code) | ||
|
||
sendVerificationEmail(input, code) | ||
return VerificationMapper.toSendResDto() | ||
} | ||
|
||
private fun validateEmail(email : String){ | ||
if(!EmailUtils.isDomainExists(email)) throw EmailDomainNotFoundException() | ||
if(!EmailUtils.isUnivMail(email)) throw EmailNotUnivException() | ||
} | ||
|
||
private fun reflectVerification(input: EmailSendRequest, code: String) { | ||
val existingInfo = verificationRepository.findByUnivMail(input.univEmail) | ||
|
||
if (existingInfo != null) { | ||
when (existingInfo.status) { | ||
VerificationStatus.HOLD -> { | ||
existingInfo.verificationCode = code | ||
existingInfo.expiresAt = LocalDateTime.now().plusMinutes(10) | ||
verificationRepository.save(existingInfo) | ||
} | ||
|
||
VerificationStatus.VERIFIED -> { | ||
throw EmailAlreadyVerifiedException() | ||
} | ||
} | ||
} else { | ||
val newVerificationInfo = VerificationMapper.toEntity(input, code) | ||
verificationRepository.save(newVerificationInfo) | ||
} | ||
} | ||
|
||
private fun sendVerificationEmail(input: EmailSendRequest, code: String) { | ||
val content = EMAIL_CONTENT_TEMPLATE.format(code) | ||
emailGateway.sendEmail(input.univEmail, EMAIL_SUBJECT, content) | ||
} | ||
|
||
companion object { | ||
private const val EMAIL_SUBJECT = "그라밋 - 이메일 인증 코드 입니다." | ||
private const val EMAIL_CONTENT_TEMPLATE = """ | ||
안녕하세요, 그라밋입니다. | ||
아래의 코드는 이메일 인증을 위한 코드입니다: | ||
%s | ||
10분 이내에 인증을 완료해주세요. | ||
""" | ||
} | ||
} |
Oops, something went wrong.