Skip to content

Commit

Permalink
Merge pull request #14 from TeamMiso/feat/mail-check
Browse files Browse the repository at this point in the history
회원가입시 이메일 인증번호 인증 api 구현
  • Loading branch information
uuuuuuuk authored Oct 11, 2023
2 parents 7112dcb + a2f10ff commit 87dc635
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package andreas311.miso.domain.auth.exception

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

class EmailKeyInvalidException : MisoException(ErrorCode.EMAIL_KEY_IS_INVALID) {
}
3 changes: 0 additions & 3 deletions src/main/kotlin/andreas311/miso/domain/email/entity/Email.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class Email(
@Column(name = "authentication")
var authentication: Boolean
) {
fun updateRandomKey(randomKey: String) {
this.randomKey = randomKey
}

fun updateAuthentication(authentication: Boolean) {
this.authentication = authentication
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package andreas311.miso.domain.email.presentation

import andreas311.miso.domain.email.presentation.data.request.EmailCheckRequestDto
import andreas311.miso.domain.email.service.EmailCheckService
import andreas311.miso.global.annotation.RequestController
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody

@RequestController("/email")
class EmailController(
private val emailCheckService: EmailCheckService
) {

@PostMapping
fun emailCheck(@RequestBody emailCheckRequestDto: EmailCheckRequestDto): ResponseEntity<Void> =
emailCheckService.execute(emailCheckRequestDto)
.let { ResponseEntity.status(HttpStatus.OK).build() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package andreas311.miso.domain.email.presentation.data.request

data class EmailCheckRequestDto(
val randomKey: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ interface EmailRepository : CrudRepository<Email, Long> {
fun deleteByEmail(email: String)

fun existsByEmail(email: String): Boolean

fun findByRandomKey(randomKey: String): Email?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package andreas311.miso.domain.email.service

import andreas311.miso.domain.email.presentation.data.request.EmailCheckRequestDto

interface EmailCheckService {

fun execute(emailCheckRequestDto: EmailCheckRequestDto)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package andreas311.miso.domain.email.service.impl

import andreas311.miso.domain.auth.exception.EmailKeyInvalidException
import andreas311.miso.domain.email.presentation.data.request.EmailCheckRequestDto
import andreas311.miso.domain.email.repository.EmailRepository
import andreas311.miso.domain.email.service.EmailCheckService
import andreas311.miso.global.annotation.RollbackService

@RollbackService
class EmailCheckServiceImpl(
private val emailRepository: EmailRepository
) : EmailCheckService {

override fun execute(emailCheckRequestDto: EmailCheckRequestDto) {

val email = emailRepository.findByRandomKey(emailCheckRequestDto.randomKey)
?: throw EmailKeyInvalidException()

email.updateAuthentication(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum class ErrorCode(
EMAIL_SEND_FAIL(500, "사용자를 찾을 수 없습니다."),

// USER
EMAIL_KEY_IS_INVALID(401, "이메일 인증번호가 일치하지 않습니다."),
EMAIL_IS_NOT_VALID(403, "인증되지 않은 이메일입니다."),
USER_NOT_FOUND(404, "사용자를 찾을 수 없습니다."),
ROLE_NOT_EXIST(404, "역할이 존재하지 않습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class SecurityConfig(
.antMatchers(HttpMethod.POST, "/auth").permitAll()
.antMatchers(HttpMethod.POST, "/auth/signIn").permitAll()

.antMatchers(HttpMethod.POST, "/email").permitAll()

.anyRequest().denyAll()
.and()
.exceptionHandling()
Expand Down

0 comments on commit 87dc635

Please sign in to comment.