From 22346640f1c8726d3426636abb508b1194ede137 Mon Sep 17 00:00:00 2001 From: phjppo0918 Date: Mon, 6 Nov 2023 20:24:56 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20email=20=EC=9D=B8=EC=A6=9D=20API=20?= =?UTF-8?q?=ED=98=B8=EC=B6=9C=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/email/EmailAuthenticationCtrl.kt | 7 +++-- .../domain/member/email/dto/CertifyKeyReq.kt | 3 ++ .../email/svc/EmailAuthenticationSvc.kt | 5 ++-- src/main/resources/templates/api-docs.html | 28 +++++++++++-------- .../email/EmailAuthenticationCtrlTest.kt | 14 ++++------ .../email/svc/EmailAuthenticationSvcTest.kt | 8 ++++-- 6 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 src/main/kotlin/site/qbox/qboxserver/domain/member/email/dto/CertifyKeyReq.kt diff --git a/src/main/kotlin/site/qbox/qboxserver/domain/member/email/EmailAuthenticationCtrl.kt b/src/main/kotlin/site/qbox/qboxserver/domain/member/email/EmailAuthenticationCtrl.kt index 9cb80a6..88f85eb 100644 --- a/src/main/kotlin/site/qbox/qboxserver/domain/member/email/EmailAuthenticationCtrl.kt +++ b/src/main/kotlin/site/qbox/qboxserver/domain/member/email/EmailAuthenticationCtrl.kt @@ -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 @@ -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) } \ No newline at end of file diff --git a/src/main/kotlin/site/qbox/qboxserver/domain/member/email/dto/CertifyKeyReq.kt b/src/main/kotlin/site/qbox/qboxserver/domain/member/email/dto/CertifyKeyReq.kt new file mode 100644 index 0000000..95377de --- /dev/null +++ b/src/main/kotlin/site/qbox/qboxserver/domain/member/email/dto/CertifyKeyReq.kt @@ -0,0 +1,3 @@ +package site.qbox.qboxserver.domain.member.email.dto + +data class CertifyKeyReq(val key: String) \ No newline at end of file diff --git a/src/main/kotlin/site/qbox/qboxserver/domain/member/email/svc/EmailAuthenticationSvc.kt b/src/main/kotlin/site/qbox/qboxserver/domain/member/email/svc/EmailAuthenticationSvc.kt index aba1f21..6f5e05f 100644 --- a/src/main/kotlin/site/qbox/qboxserver/domain/member/email/svc/EmailAuthenticationSvc.kt +++ b/src/main/kotlin/site/qbox/qboxserver/domain/member/email/svc/EmailAuthenticationSvc.kt @@ -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 @@ -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)) } diff --git a/src/main/resources/templates/api-docs.html b/src/main/resources/templates/api-docs.html index 04ff7b9..8b1447a 100644 --- a/src/main/resources/templates/api-docs.html +++ b/src/main/resources/templates/api-docs.html @@ -681,7 +681,7 @@

답변 생성

HTTP request

-
POST /answers?_csrf=GHqBzRzMpWsbrlNeV4mPzfd51VSpUT3rLYUkRNV2qCIbv4hqLU-zr3ipnAk2nWM9YqS7-5JJ-DWcYwrGHrxGcLBEmBso2bhS HTTP/1.1
+
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
@@ -743,7 +743,7 @@ 

학과 생성

HTTP request

-
POST /departs?_csrf=gXUFH99z2kMLDXHFW3yNcS44euV5aJuilyF87yDtQ1Se8W84txBgK7lL6nEmOEL8OFG5QxYLV9xMW6uP8hId2kPfcWSvkwoJ HTTP/1.1
+
POST /departs?_csrf=xhdgPX9blBkvnJV7Jw-B6kaWHROYpIZUR6lBEueHI4MsFt0AonJYBR5toS8CqaBJFiK133evMHGvwLB5cJ0jJoXmF7pNJe5m HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Content-Length: 62
 Host: localhost:8080
@@ -907,7 +907,7 @@ 

email 등록HTTP request

-
POST /emails?_csrf=-Jkp6PtDIjCidErH45mQSATy1YgKfxYHpLqBzykVYJe49FhRmfwe0J52G1OPQS7xhrSkKTCT-LE9GiAqlozk9xp2U6aBljo0 HTTP/1.1
+
POST /emails?_csrf=WPM7bc2RXxVQhDK4z42A8VOOQw6zj89Rag9heztwQcGLP1p9aJECCfX0PHd9tVOM9qC0xWrvbjaKtvd8WmpWSgNHd6SzCDwf HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Content-Length: 33
 Host: localhost:8080
@@ -962,8 +962,14 @@ 

email 키

HTTP request

-
GET /emails?key=keyValue HTTP/1.1
-Host: localhost:8080
+
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"
+}
@@ -1009,7 +1015,7 @@

강의 생성

HTTP request

-
POST /lectures?_csrf=zC3Sm4bIIHtFjGHgt97G2B87zeerIYI2rNwUkwP687HPbZLqqRWxqLWpFExo6QfS1fPy7HoC4N-fGeEbmektoGfJlob6Vffc HTTP/1.1
+
POST /lectures?_csrf=jJY9BVtRhpgfmO5pBCDrAZAjOrY-1BBG2Jk44mNn-xdPAylVtK8JZD8wsKwyrtwMPA3fN_QXF9dY5CFrvagNh1VQmi97M0sz HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Content-Length: 68
 Host: localhost:8080
@@ -1186,7 +1192,7 @@ 

질문 생성

HTTP request

-
POST /questions?_csrf=SyxarLEgp9IvaGpAUduO6fLIcg_DtqClNUykBQFiuLvkdBqsc05onYBFkOECDQ95aPa63JeqXzb6j8aIVi_CNWRU3tqHEXyc HTTP/1.1
+
POST /questions?_csrf=NpMlmwgBQGugFCVaaRg1FNfa20oeqCm-VUQfyt0913LUxIOfUKEU-T9gdFiNckY-DDUBJ7Xq9isvnUuTNiAs_r4Jsha3orH5 HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Content-Length: 112
 Host: localhost:8080
@@ -1289,7 +1295,7 @@ 

대학 생성

HTTP request

-
POST /univ?_csrf=TRLZLnj17qrliXL4gSjmWIgmlA2-BjWQyGLWXuAl4XqJqoWLeXPvTEiRjZPIvUvM4wXSYbERuW-IMge9_VPlZ9YQ1By_z7Ky HTTP/1.1
+
POST /univ?_csrf=CuNQTAtUhyCwpPtdL1ihqN5IXvpZVZMnpH8zvInYpfyaDzsHaNRlezg1sROdwMw-TnWVn717c8NuYaoKlB0GjLy9l577bQNm HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Content-Length: 62
 Host: localhost:8080
@@ -1378,7 +1384,7 @@ 

회원가입HTTP request

-
POST /members?_csrf=UXxxbhd-ij9D-O7z2hyp4n5HCjg34HWu0Ncw4MBFm2b8yPF_M0pGDCZPvAtunI3HuDGdgxh_J1pW00aD57UH1aN9-lPI_cZL HTTP/1.1
+
POST /members?_csrf=9uHiEUFtgaL8uKZw8piP2AVZcV9FcJx0N8iySN8weW6n2IJ7z9GHJ3UI5JTRisIWkbW77zBtXD4hFKlZD_jXe74CG12QvuMa HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Content-Length: 96
 Host: localhost:8080
@@ -1533,7 +1539,7 @@ 

question 생

HTTP request

-
POST /questions?_csrf=SyxarLEgp9IvaGpAUduO6fLIcg_DtqClNUykBQFiuLvkdBqsc05onYBFkOECDQ95aPa63JeqXzb6j8aIVi_CNWRU3tqHEXyc HTTP/1.1
+
POST /questions?_csrf=NpMlmwgBQGugFCVaaRg1FNfa20oeqCm-VUQfyt0913LUxIOfUKEU-T9gdFiNckY-DDUBJ7Xq9isvnUuTNiAs_r4Jsha3orH5 HTTP/1.1
 Content-Type: application/json;charset=UTF-8
 Content-Length: 112
 Host: localhost:8080
@@ -1893,7 +1899,7 @@ 

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 diff --git a/src/test/kotlin/site/qbox/qboxserver/domain/member/email/EmailAuthenticationCtrlTest.kt b/src/test/kotlin/site/qbox/qboxserver/domain/member/email/EmailAuthenticationCtrlTest.kt index 5bf2abc..367003a 100644 --- a/src/test/kotlin/site/qbox/qboxserver/domain/member/email/EmailAuthenticationCtrlTest.kt +++ b/src/test/kotlin/site/qbox/qboxserver/domain/member/email/EmailAuthenticationCtrlTest.kt @@ -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 @@ -37,17 +35,17 @@ class EmailAuthenticationCtrlTest : WebClientDocsTest() { } it("이메일 인증을 수행한다") { - val params = LinkedMultiValueMap() - 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("인증키") ) ) ) diff --git a/src/test/kotlin/site/qbox/qboxserver/domain/member/email/svc/EmailAuthenticationSvcTest.kt b/src/test/kotlin/site/qbox/qboxserver/domain/member/email/svc/EmailAuthenticationSvcTest.kt index 1756252..0e4ab63 100644 --- a/src/test/kotlin/site/qbox/qboxserver/domain/member/email/svc/EmailAuthenticationSvcTest.kt +++ b/src/test/kotlin/site/qbox/qboxserver/domain/member/email/svc/EmailAuthenticationSvcTest.kt @@ -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 @@ -41,10 +42,11 @@ class EmailAuthenticationSvcTest : IntegrationTest() { describe("신규 등록이 되어 있을 때 ") { val email = "aaa@example.com" - 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("성공 시 인증 성공 목록에 추가한다.") { @@ -54,7 +56,7 @@ class EmailAuthenticationSvcTest : IntegrationTest() { it("수행 시 인증 실패 시 예외를 반환한다.") { shouldThrow { - emailAuthenticationSvc.authenticate("whatthekey") + emailAuthenticationSvc.authenticate(CertifyKeyReq("asdf")) } } }