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

refactor : 자기소개서 조회 API 응답값 수정 #114

Merged
merged 3 commits into from
May 20, 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
2 changes: 1 addition & 1 deletion Api-Module/src/docs/asciidoc/Auth.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ operation::AuthControllerTest/reissueToken[snippets='http-request,http-response,
[[Auth-Logout]]
=== 로그아웃

operation::AuthControllerTest/logout[snippets='http-request,http-response,request-fields']
operation::AuthControllerTest/logout[snippets='http-request,request-headers,http-response']

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bamyanggang.apimodule.domain.jobDescription.application.dto

import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus

class ApplyInfo {

sealed class Request {
Expand All @@ -10,7 +12,8 @@ class ApplyInfo {
}

data class Response(
val applyContentList: List<ContentInfo>
val applyContentList: List<ContentInfo>,
val writeStatus: WriteStatus
)

data class ContentInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ package com.bamyanggang.apimodule.domain.jobDescription.application.service

import com.bamyanggang.apimodule.domain.jobDescription.application.dto.ApplyInfo
import com.bamyanggang.domainmodule.domain.jobDescription.service.ApplyReader
import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionReader
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Service
class ApplyInfoGetService(
private val applyReader: ApplyReader
private val applyReader: ApplyReader,
private val jobDescriptionReader: JobDescriptionReader
) {

@Transactional(readOnly = true)
fun getApplyInfo(jobDescriptionId: UUID): ApplyInfo.Response {
return applyReader.readApplyByJobDescriptionId(jobDescriptionId).contents.map {
ApplyInfo.ContentInfo(
it.question,
it.answer
)
}.let {
ApplyInfo.Response(it)
val jobDescription = jobDescriptionReader.readJobDescriptionById(jobDescriptionId)
val contents = applyReader.readApplyByJobDescriptionId(jobDescriptionId).contents.map {
ApplyInfo.ContentInfo(it.question, it.answer)
}
return ApplyInfo.Response(contents, jobDescription.writeStatus)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bamyanggang.apimodule.domain.user.application.service

import com.bamyanggang.apimodule.domain.user.application.dto.Logout
import com.bamyanggang.apimodule.domain.user.application.dto.Reissue
import com.bamyanggang.apimodule.domain.user.application.dto.SocialLogin
import com.bamyanggang.apimodule.domain.user.application.service.handler.AuthHandler
Expand All @@ -26,7 +25,8 @@ class AuthService(
private val tokenAppender: TokenAppender,
private val claimsExtractor: ClaimsExtractor,
private val tokenRemover: TokenRemover,
private val tokenReader : TokenReader
private val tokenReader : TokenReader,
private val tokenExtractor: TokenExtractor
){
fun executeSocialLogin(provider: SocialLoginProvider, request: SocialLogin.Request): SocialLogin.Response {
val socialLoginHandler = authHandlerManager.getHandler(provider)
Expand Down Expand Up @@ -63,7 +63,8 @@ class AuthService(
}

@Transactional
fun logout(logoutRequest: Logout.Request) {
tokenReader.readToken(logoutRequest.refreshToken).also { tokenRemover.removeToken(it) }
fun logout(refreshToken: String) {
val refreshToken = tokenExtractor.extractValue(refreshToken)
tokenReader.readToken(refreshToken).also { tokenRemover.removeToken(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ object AuthApi {
const val LOGOUT = "$BASE_URL/logout"
const val REISSUE = "$BASE_URL/reissue"

}
const val REFRESH_TOKEN_HEADER = "RefreshToken"

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package com.bamyanggang.apimodule.domain.user.presentation

import com.bamyanggang.apimodule.domain.user.application.dto.Logout
import com.bamyanggang.apimodule.domain.user.application.dto.Reissue
import com.bamyanggang.apimodule.domain.user.application.dto.SocialLogin
import com.bamyanggang.apimodule.domain.user.application.service.AuthService
import com.bamyanggang.domainmodule.domain.user.enums.SocialLoginProvider
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RestController
class AuthController(
Expand All @@ -30,9 +24,9 @@ class AuthController(

@DeleteMapping(AuthApi.LOGOUT)
fun logout(
@RequestBody request: Logout.Request
@RequestHeader(AuthApi.REFRESH_TOKEN_HEADER) refreshTokenHeader: String
) {
authService.logout(request)
authService.logout(refreshTokenHeader)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package com.bamyanggang.apimodule.domain.jobDescription.application

import com.bamyanggang.apimodule.domain.jobDescription.application.service.ApplyInfoGetService
import com.bamyanggang.domainmodule.domain.jobDescription.service.ApplyReader
import com.bamyanggang.domainmodule.domain.jobDescription.service.JobDescriptionReader
import io.kotest.core.spec.style.BehaviorSpec
import io.mockk.mockk
import io.mockk.verify
import java.util.UUID

class ApplicationInfoGetServiceTest: BehaviorSpec({
class ApplyInfoGetServiceTest: BehaviorSpec({
val mockApplyReader = mockk<ApplyReader>(relaxed = true)
val service = ApplyInfoGetService(mockApplyReader)
val mockJobDescriptionReader = mockk<JobDescriptionReader>(relaxed = true)
val service = ApplyInfoGetService(mockApplyReader, mockJobDescriptionReader)

given("ApplyInfoGetService.getApplyInfo") {
val jobDescriptionId: UUID = UUID.randomUUID()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ class JobDescriptionControllerTest : BaseRestDocsTest() {
),
responseFields(
fieldWithPath("applyContentList[].question").description("질문"),
fieldWithPath("applyContentList[].answer").description("답변")
fieldWithPath("applyContentList[].answer").description("답변"),
fieldWithPath("writeStatus").description("작성 상태. NOT_APPLIED(칩 없음, 작성 전), WRITING(작성 중), WRITTEN(작성 완료), CLOSED(마감)")
)
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bamyanggang.apimodule.domain.user.presentation

import com.bamyanggang.apimodule.BaseRestDocsTest
import com.bamyanggang.apimodule.domain.user.application.dto.Logout
import com.bamyanggang.apimodule.domain.user.application.dto.Reissue
import com.bamyanggang.apimodule.domain.user.application.dto.SocialLogin
import com.bamyanggang.apimodule.domain.user.application.service.AuthService
Expand All @@ -18,6 +17,8 @@ import org.springframework.restdocs.request.RequestDocumentation.parameterWithNa
import org.springframework.restdocs.request.RequestDocumentation.pathParameters
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import com.bamyanggang.commonmodule.fixture.generateFixture
import org.springframework.restdocs.headers.HeaderDocumentation.headerWithName
import org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders

@WebMvcTest(AuthController::class)
class AuthControllerTest : BaseRestDocsTest(){
Expand Down Expand Up @@ -125,19 +126,20 @@ class AuthControllerTest : BaseRestDocsTest(){
@DisplayName("로그아웃 요청시 성공한다.")
fun logout() {
//given
val refreshToken : String= generateFixture()
val logoutRequest = Reissue.Request(refreshToken)
val request = RestDocumentationRequestBuilders.delete(AuthApi.LOGOUT)
.header("Authorization","Bearer accessToken")
.header("RefreshToken","Bearer refreshToken")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(logoutRequest))

//when
val result = mockMvc.perform(request)
//then
result.andExpect(status().isOk)
.andDo(
resultHandler.document(
requestFields(
fieldWithPath("refreshToken").description("로그아웃을 위한 refreshToken"),
requestHeaders(
headerWithName("Authorization").description("Access Token"),
headerWithName("RefreshToken").description("refreshToken")
)
)
)
Expand Down
Loading