Skip to content
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

🔀 :: 이메일 인증 API 구현 #34

Merged
merged 14 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/main/kotlin/andreas311/miso/common/entitiy/BaseIdxEntity.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class SignUpService(
private val passwordEncodePort: PasswordEncodePort
) : SignUpUseCase {
override fun execute(signUpDto: SignUpDto) {

passwordEncodePort.isPasswordMatch(signUpDto.password, signUpDto.passwordCheck)

if (!queryUserPort.existsByEmail(signUpDto.email)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package andreas311.miso.domain.email.adapter.input

import andreas311.miso.common.annotation.RequestController
import andreas311.miso.domain.email.adapter.input.data.request.RandomKeyRequest
import andreas311.miso.domain.email.adapter.input.mapper.EmailDataMapper
import andreas311.miso.domain.email.application.port.input.RandomKeyConfirmUseCase
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import javax.validation.Valid

@RequestController("/email")
class EmailAdapter(
private val emailDataMapper: EmailDataMapper,
private val randomKeyConfirmUseCase: RandomKeyConfirmUseCase
) {
@PostMapping
fun emailCheck(@RequestBody @Valid randomKeyRequest: RandomKeyRequest): ResponseEntity<Void> =
randomKeyConfirmUseCase.execute(emailDataMapper toDto randomKeyRequest)
.let { ResponseEntity.status(HttpStatus.OK).build() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package andreas311.miso.domain.email.adapter.input.data.request

import javax.validation.constraints.NotNull

data class RandomKeyRequest(
@field:NotNull
val randomKey: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package andreas311.miso.domain.email.adapter.input.mapper

import andreas311.miso.domain.email.adapter.input.data.request.RandomKeyRequest
import andreas311.miso.domain.email.application.port.input.dto.RandomKeyDto
import org.springframework.stereotype.Component

@Component
class EmailDataMapper {
infix fun toDto(randomKeyRequest: RandomKeyRequest): RandomKeyDto =
RandomKeyDto(
randomKey = randomKeyRequest.randomKey
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ class QueryEmailPersistenceAdapter(

override fun existsByEmail(email: String): Boolean =
emailRepository.existsByEmail(email)

override fun findByRandomKeyOrNull(randomKey: String): Email? {
val emailEntity = emailRepository.findByRandomKey(randomKey)
return emailMapper.toDomain(emailEntity)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package andreas311.miso.domain.email.adapter.output.persistence.entity

import andreas311.miso.common.entitiy.BaseIdxEntity
import javax.persistence.*

@Entity
@Table(name = "email")
class EmailEntity(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "email_id", nullable = false)
val id: Long,

Expand All @@ -17,4 +18,4 @@ class EmailEntity(

@Column(name = "authentication", nullable = false)
var authentication: Boolean
): BaseIdxEntity(id)
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class EmailMapper {
authentication = domain.authentication
)

fun toDomain(entity: EmailEntity): Email? =
fun toDomain(entity: EmailEntity?): Email? =
entity?.let {
Email(
id = entity.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import org.springframework.data.repository.CrudRepository
interface EmailRepository: CrudRepository<EmailEntity, Long> {
fun findByEmail(email: String): EmailEntity
fun existsByEmail(email: String): Boolean
fun findByRandomKey(randomKey: String): EmailEntity?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package andreas311.miso.domain.email.application.exception

import andreas311.miso.global.error.ErrorCode
import andreas311.miso.global.error.exception.MisoException

class EmailKeyInvalidException : MisoException(ErrorCode.EMAIL_KEY_IS_INVALID)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package andreas311.miso.domain.email.application.port.input

import andreas311.miso.domain.email.application.port.input.dto.RandomKeyDto

interface RandomKeyConfirmUseCase {
fun execute(randomKeyDto: RandomKeyDto)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package andreas311.miso.domain.email.application.port.input.dto

data class RandomKeyDto(
val randomKey: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import andreas311.miso.domain.email.domain.Email
interface QueryEmailPort {
fun findByEmailOrNull(email: String): Email?
fun existsByEmail(email: String): Boolean
fun findByRandomKeyOrNull(randomKey: String): Email?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package andreas311.miso.domain.email.application.service

import andreas311.miso.common.annotation.RollbackService
import andreas311.miso.domain.email.application.exception.EmailKeyInvalidException
import andreas311.miso.domain.email.application.port.input.RandomKeyConfirmUseCase
import andreas311.miso.domain.email.application.port.input.dto.RandomKeyDto
import andreas311.miso.domain.email.application.port.output.CommandEmailPort
import andreas311.miso.domain.email.application.port.output.QueryEmailPort

@RollbackService
class RandomKeyConfirmService(
private val commandEmailPort: CommandEmailPort,
private val queryEmailPort: QueryEmailPort
): RandomKeyConfirmUseCase {
override fun execute(randomKeyDto: RandomKeyDto) {
val email = queryEmailPort.findByRandomKeyOrNull(randomKeyDto.randomKey)
?: throw EmailKeyInvalidException()

commandEmailPort.saveEmail(email.updateAuthentication(true))
}
}
3 changes: 2 additions & 1 deletion src/main/kotlin/andreas311/miso/domain/email/domain/Email.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ data class Email(
var randomKey: String,
var authentication: Boolean
) {
fun updateAuthentication(authentication: Boolean) {
fun updateAuthentication(authentication: Boolean): Email {
this.authentication = authentication
return this
}
}
Loading