Skip to content

Commit

Permalink
fix : email 인증 API 호출 방식 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
phjppo0918 committed Nov 6, 2023
1 parent 5caf327 commit 2234664
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package site.qbox.qboxserver.domain.member.email
import jakarta.validation.Valid
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.*
import site.qbox.qboxserver.domain.member.email.dto.CertifyKeyReq
import site.qbox.qboxserver.domain.member.email.dto.RegisterEmailReq
import site.qbox.qboxserver.domain.member.email.svc.EmailAuthenticationSvc

Expand All @@ -16,8 +17,8 @@ class EmailAuthenticationCtrl (
fun register(@RequestBody @Valid req: RegisterEmailReq) =
emailAuthenticationSvc.register(req)

@GetMapping
fun authenticate(key: String) =
emailAuthenticationSvc.authenticate(key)
@PostMapping("key")
fun authenticate(@RequestBody @Valid req : CertifyKeyReq) =
emailAuthenticationSvc.authenticate(req)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package site.qbox.qboxserver.domain.member.email.dto

data class CertifyKeyReq(val key: String)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package site.qbox.qboxserver.domain.member.email.svc

import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service
import site.qbox.qboxserver.domain.member.email.dto.CertifyKeyReq
import site.qbox.qboxserver.domain.member.email.dto.RegisterEmailReq
import site.qbox.qboxserver.domain.member.email.dto.event.RegisteredEmailEvent
import site.qbox.qboxserver.domain.member.email.entity.Email
Expand All @@ -25,8 +26,8 @@ class EmailAuthenticationSvc (
private fun generateKey() : String =
UUID.randomUUID().toString().substring(0, 8)

fun authenticate(key: String) {
val target = emailAuthKeyRepo.findById(key)
fun authenticate(req: CertifyKeyReq) {
val target = emailAuthKeyRepo.findById(req.key)
.orElseThrow { EmailNotAuthenticatedException() }
authenticationEmailRepo.save(Email(target.email))
}
Expand Down
28 changes: 17 additions & 11 deletions src/main/resources/templates/api-docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ <h2 id="_답변_생성"><a class="link" href="#_답변_생성">답변 생성</a>
<h3 id="_http_request"><a class="link" href="#_http_request">HTTP request</a></h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /answers?_csrf=GHqBzRzMpWsbrlNeV4mPzfd51VSpUT3rLYUkRNV2qCIbv4hqLU-zr3ipnAk2nWM9YqS7-5JJ-DWcYwrGHrxGcLBEmBso2bhS HTTP/1.1
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /answers?_csrf=8kIElLx0ZQ_aQknpFkEG-6a8NgJKwbQPUPhRgP_G7MjGVojTwnY18ItBUGz3cn3YJWwyzp-JGzp89NEiaZ415M-k2fHzNOm3 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 53
Host: localhost:8080
Expand Down Expand Up @@ -743,7 +743,7 @@ <h2 id="_학과_생성"><a class="link" href="#_학과_생성">학과 생성</a>
<h3 id="_http_request_2"><a class="link" href="#_http_request_2">HTTP request</a></h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /departs?_csrf=gXUFH99z2kMLDXHFW3yNcS44euV5aJuilyF87yDtQ1Se8W84txBgK7lL6nEmOEL8OFG5QxYLV9xMW6uP8hId2kPfcWSvkwoJ HTTP/1.1
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /departs?_csrf=xhdgPX9blBkvnJV7Jw-B6kaWHROYpIZUR6lBEueHI4MsFt0AonJYBR5toS8CqaBJFiK133evMHGvwLB5cJ0jJoXmF7pNJe5m HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 62
Host: localhost:8080
Expand Down Expand Up @@ -907,7 +907,7 @@ <h2 id="_email_등록"><a class="link" href="#_email_등록">email 등록</a></h
<h3 id="_http_request_4"><a class="link" href="#_http_request_4">HTTP request</a></h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /emails?_csrf=-Jkp6PtDIjCidErH45mQSATy1YgKfxYHpLqBzykVYJe49FhRmfwe0J52G1OPQS7xhrSkKTCT-LE9GiAqlozk9xp2U6aBljo0 HTTP/1.1
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /emails?_csrf=WPM7bc2RXxVQhDK4z42A8VOOQw6zj89Rag9heztwQcGLP1p9aJECCfX0PHd9tVOM9qC0xWrvbjaKtvd8WmpWSgNHd6SzCDwf HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 33
Host: localhost:8080
Expand Down Expand Up @@ -962,8 +962,14 @@ <h2 id="_email_키_인증"><a class="link" href="#_email_키_인증">email 키
<h3 id="_http_request_5"><a class="link" href="#_http_request_5">HTTP request</a></h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">GET /emails?key=keyValue HTTP/1.1
Host: localhost:8080</code></pre>
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /emails/key?_csrf=U0ILz_ahDSrKZWp4bYxaWIcOeG7S8TWfMR1gAHMEE8eELHRIMndprM-Za0vnBgwaVKFuObA6VVbjwQCyVS1QZktmJfHmTkV8 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 24
Host: localhost:8080

{
"key" : "KeyValue"
}</code></pre>
</div>
</div>
<table class="tableblock frame-all grid-all stretch">
Expand Down Expand Up @@ -1009,7 +1015,7 @@ <h2 id="_강의_생성"><a class="link" href="#_강의_생성">강의 생성</a>
<h3 id="_http_request_6"><a class="link" href="#_http_request_6">HTTP request</a></h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /lectures?_csrf=zC3Sm4bIIHtFjGHgt97G2B87zeerIYI2rNwUkwP687HPbZLqqRWxqLWpFExo6QfS1fPy7HoC4N-fGeEbmektoGfJlob6Vffc HTTP/1.1
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /lectures?_csrf=jJY9BVtRhpgfmO5pBCDrAZAjOrY-1BBG2Jk44mNn-xdPAylVtK8JZD8wsKwyrtwMPA3fN_QXF9dY5CFrvagNh1VQmi97M0sz HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 68
Host: localhost:8080
Expand Down Expand Up @@ -1186,7 +1192,7 @@ <h2 id="_질문_생성"><a class="link" href="#_질문_생성">질문 생성</a>
<h3 id="_http_request_8"><a class="link" href="#_http_request_8">HTTP request</a></h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /questions?_csrf=SyxarLEgp9IvaGpAUduO6fLIcg_DtqClNUykBQFiuLvkdBqsc05onYBFkOECDQ95aPa63JeqXzb6j8aIVi_CNWRU3tqHEXyc HTTP/1.1
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /questions?_csrf=NpMlmwgBQGugFCVaaRg1FNfa20oeqCm-VUQfyt0913LUxIOfUKEU-T9gdFiNckY-DDUBJ7Xq9isvnUuTNiAs_r4Jsha3orH5 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 112
Host: localhost:8080
Expand Down Expand Up @@ -1289,7 +1295,7 @@ <h2 id="_대학_생성"><a class="link" href="#_대학_생성">대학 생성</a>
<h3 id="_http_request_9"><a class="link" href="#_http_request_9">HTTP request</a></h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /univ?_csrf=TRLZLnj17qrliXL4gSjmWIgmlA2-BjWQyGLWXuAl4XqJqoWLeXPvTEiRjZPIvUvM4wXSYbERuW-IMge9_VPlZ9YQ1By_z7Ky HTTP/1.1
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /univ?_csrf=CuNQTAtUhyCwpPtdL1ihqN5IXvpZVZMnpH8zvInYpfyaDzsHaNRlezg1sROdwMw-TnWVn717c8NuYaoKlB0GjLy9l577bQNm HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 62
Host: localhost:8080
Expand Down Expand Up @@ -1378,7 +1384,7 @@ <h2 id="_회원가입"><a class="link" href="#_회원가입">회원가입</a></h
<h3 id="_http_request_10"><a class="link" href="#_http_request_10">HTTP request</a></h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /members?_csrf=UXxxbhd-ij9D-O7z2hyp4n5HCjg34HWu0Ncw4MBFm2b8yPF_M0pGDCZPvAtunI3HuDGdgxh_J1pW00aD57UH1aN9-lPI_cZL HTTP/1.1
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /members?_csrf=9uHiEUFtgaL8uKZw8piP2AVZcV9FcJx0N8iySN8weW6n2IJ7z9GHJ3UI5JTRisIWkbW77zBtXD4hFKlZD_jXe74CG12QvuMa HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 96
Host: localhost:8080
Expand Down Expand Up @@ -1533,7 +1539,7 @@ <h2 id="_question_생성"><a class="link" href="#_question_생성">question 생
<h3 id="_http_request_12"><a class="link" href="#_http_request_12">HTTP request</a></h3>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /questions?_csrf=SyxarLEgp9IvaGpAUduO6fLIcg_DtqClNUykBQFiuLvkdBqsc05onYBFkOECDQ95aPa63JeqXzb6j8aIVi_CNWRU3tqHEXyc HTTP/1.1
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">POST /questions?_csrf=NpMlmwgBQGugFCVaaRg1FNfa20oeqCm-VUQfyt0913LUxIOfUKEU-T9gdFiNckY-DDUBJ7Xq9isvnUuTNiAs_r4Jsha3orH5 HTTP/1.1
Content-Type: application/json;charset=UTF-8
Content-Length: 112
Host: localhost:8080
Expand Down Expand Up @@ -1893,7 +1899,7 @@ <h3 id="_http_response_14"><a class="link" href="#_http_response_14">HTTP respon
}
var panel = id && tabs.querySelector('.tabpanel[aria-labelledby~="' + id + '"]')
if (!panel) return idx ? undefined : toggleSelected(tab, true) // invalid state
syncIds && (((syncId = tab.textContent.trim()) in syncIds) ? (syncId = undefined) : true) || (syncIds && (start = { tab: tab, panel: panel })) ? toggleHidden(panel, true) : toggleSelected(tab, true)
syncIds && (((syncId = tab.textContent.trim()) in syncIds) ? (syncId = undefined) : true) || (syncIds && (start = { tab: tab, panel: panel })) ? toggleHidden(panel, true) : toggleSelected(tab, true)
tab.setAttribute('aria-controls', panel.id)
panel.setAttribute('role', 'tabpanel')
var onClick = syncId === undefined ? activateTab : activateTabSync
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.restdocs.payload.JsonFieldType
import org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath
import org.springframework.restdocs.payload.PayloadDocumentation.requestFields
import org.springframework.restdocs.request.RequestDocumentation.parameterWithName
import org.springframework.restdocs.request.RequestDocumentation.queryParameters
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import org.springframework.util.LinkedMultiValueMap
import site.qbox.qboxserver.config.WebClientDocsTest
import site.qbox.qboxserver.domain.member.email.dto.CertifyKeyReq
import site.qbox.qboxserver.domain.member.email.dto.RegisterEmailReq
import site.qbox.qboxserver.domain.member.email.svc.EmailAuthenticationSvc

Expand All @@ -37,17 +35,17 @@ class EmailAuthenticationCtrlTest : WebClientDocsTest() {
}

it("이메일 인증을 수행한다") {
val params = LinkedMultiValueMap<String, String>()
params["key"] = "keyValue"
val action = performGet("/emails", params)

val req = CertifyKeyReq("KeyValue")
val action = performPost("/emails/key", req)

action.andExpect(status().isOk)

action.andDo(
print(
"authenticate-email",
queryParameters(
parameterWithName("key").description("인증 키"),
requestFields(
fieldWithPath("key").type(JsonFieldType.STRING).description("인증키")
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.context.ApplicationEventPublisher
import site.qbox.qboxserver.config.IntegrationTest
import site.qbox.qboxserver.domain.member.email.dto.CertifyKeyReq
import site.qbox.qboxserver.domain.member.email.dto.RegisterEmailReq
import site.qbox.qboxserver.domain.member.email.exception.EmailNotAuthenticatedException
import site.qbox.qboxserver.domain.member.email.infra.AuthenticatedEmailRepo
Expand Down Expand Up @@ -41,10 +42,11 @@ class EmailAuthenticationSvcTest : IntegrationTest() {

describe("신규 등록이 되어 있을 때 ") {
val email = "[email protected]"
var key = ""
lateinit var key : CertifyKeyReq
beforeEach {
emailAuthenticationSvc.register(RegisterEmailReq(email))
key = emailAuthKeyRepo.findAll().toList()[0].key
val keyStr = emailAuthKeyRepo.findAll().toList()[0].key
key = CertifyKeyReq(keyStr)
}
context("key 인증 수행을") {
it("성공 시 인증 성공 목록에 추가한다.") {
Expand All @@ -54,7 +56,7 @@ class EmailAuthenticationSvcTest : IntegrationTest() {

it("수행 시 인증 실패 시 예외를 반환한다.") {
shouldThrow<EmailNotAuthenticatedException> {
emailAuthenticationSvc.authenticate("whatthekey")
emailAuthenticationSvc.authenticate(CertifyKeyReq("asdf"))
}
}
}
Expand Down

0 comments on commit 2234664

Please sign in to comment.