From 987da48701b0b48f51d7376c5d64cf0f7850a275 Mon Sep 17 00:00:00 2001 From: Hanna Lee <8annahxxl@gmail.com> Date: Mon, 4 Mar 2024 11:28:06 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20ApiResponse=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?(#54)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kw/api/common/dto/response/ApiResponse.kt | 17 -------- .../domain/auth/controller/AuthController.kt | 10 ++--- .../bundle/controller/BundleController.kt | 41 ++++++++----------- .../claim/controller/ClaimController.kt | 13 +++--- .../member/controller/MemberController.kt | 24 +++++------ .../question/controller/QuestionController.kt | 24 ++++------- .../domain/tag/controller/TagController.kt | 6 +-- 7 files changed, 50 insertions(+), 85 deletions(-) delete mode 100644 server/api/src/main/kotlin/com/kw/api/common/dto/response/ApiResponse.kt diff --git a/server/api/src/main/kotlin/com/kw/api/common/dto/response/ApiResponse.kt b/server/api/src/main/kotlin/com/kw/api/common/dto/response/ApiResponse.kt deleted file mode 100644 index a90cb67..0000000 --- a/server/api/src/main/kotlin/com/kw/api/common/dto/response/ApiResponse.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.kw.api.common.dto.response - -data class ApiResponse(val message: String, val data: T?) { - companion object { - fun ok(result: T): ApiResponse { - return ApiResponse("ok", result) - } - - fun created(result: T): ApiResponse { - return ApiResponse("created", result) - } - - fun noContent(): ApiResponse { - return ApiResponse("noContent", null) - } - } -} diff --git a/server/api/src/main/kotlin/com/kw/api/domain/auth/controller/AuthController.kt b/server/api/src/main/kotlin/com/kw/api/domain/auth/controller/AuthController.kt index 172b895..203a0bd 100644 --- a/server/api/src/main/kotlin/com/kw/api/domain/auth/controller/AuthController.kt +++ b/server/api/src/main/kotlin/com/kw/api/domain/auth/controller/AuthController.kt @@ -1,6 +1,5 @@ package com.kw.api.domain.auth.controller -import com.kw.api.common.dto.response.ApiResponse import com.kw.api.domain.auth.dto.request.RefreshTokenRequest import com.kw.api.domain.auth.dto.response.TokenResponse import com.kw.api.domain.auth.service.AuthService @@ -17,6 +16,7 @@ import org.springframework.web.bind.annotation.* class AuthController(val authService: AuthService) { @Operation(summary = "로그아웃을 합니다.") + @ResponseStatus(HttpStatus.NO_CONTENT) @GetMapping("/logout") fun logout(@RequestBody refreshTokenRequest: RefreshTokenRequest) { authService.logout(refreshTokenRequest) @@ -24,16 +24,14 @@ class AuthController(val authService: AuthService) { @Operation(summary = "리프레시 토큰으로 어세스 토큰을 재발급합니다.") @GetMapping("/refresh-access-token") - fun refreshAccessToken(@RequestBody refreshTokenRequest: RefreshTokenRequest) : ApiResponse { - val response = authService.refreshAccessToken(refreshTokenRequest) - return ApiResponse.ok(response) + fun refreshAccessToken(@RequestBody refreshTokenRequest: RefreshTokenRequest): TokenResponse { + return authService.refreshAccessToken(refreshTokenRequest) } @Operation(summary = "회원탈퇴합니다.") @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/withdraw") - fun withdrawMember(@AuthToMember member: Member): ApiResponse { + fun withdrawMember(@AuthToMember member: Member) { authService.withdrawMember(member) - return ApiResponse.noContent() } } diff --git a/server/api/src/main/kotlin/com/kw/api/domain/bundle/controller/BundleController.kt b/server/api/src/main/kotlin/com/kw/api/domain/bundle/controller/BundleController.kt index 97afd13..6c03205 100644 --- a/server/api/src/main/kotlin/com/kw/api/domain/bundle/controller/BundleController.kt +++ b/server/api/src/main/kotlin/com/kw/api/domain/bundle/controller/BundleController.kt @@ -1,7 +1,6 @@ package com.kw.api.domain.bundle.controller import com.kw.api.common.dto.request.PageCondition -import com.kw.api.common.dto.response.ApiResponse import com.kw.api.common.dto.response.PageResponse import com.kw.api.domain.bundle.dto.request.* import com.kw.api.domain.bundle.dto.response.BundleDetailResponse @@ -30,8 +29,8 @@ class BundleController( fun createBundle( @RequestBody @Valid request: BundleCreateRequest, @AuthToMember member: Member - ): ApiResponse { - return ApiResponse.created(bundleService.createBundle(request, member)) + ): BundleDetailResponse { + return bundleService.createBundle(request, member) } //TODO: ES @@ -40,8 +39,8 @@ class BundleController( fun searchBundles( @ModelAttribute @Valid searchCondition: BundleSearchCondition, @ModelAttribute @Valid pageCondition: PageCondition - ): ApiResponse> { - return ApiResponse.ok(bundleService.searchBundles(searchCondition, pageCondition)) + ): PageResponse { + return bundleService.searchBundles(searchCondition, pageCondition) } @Operation(summary = "내 꾸러미 목록 조회") @@ -49,8 +48,8 @@ class BundleController( fun getMyBundles( @ModelAttribute @Valid getCondition: BundleGetCondition, @AuthToMember member: Member - ): ApiResponse> { - return ApiResponse.ok(bundleService.getMyBundles(getCondition, member)) + ): List { + return bundleService.getMyBundles(getCondition, member) } @Operation(summary = "꾸러미 상세 조회") @@ -59,8 +58,8 @@ class BundleController( @PathVariable id: Long, @RequestParam("showOnlyMyQuestions", required = false, defaultValue = "false") showOnlyMyQuestions: Boolean, @AuthToMember member: Member - ): ApiResponse { - return ApiResponse.ok(bundleService.getBundle(id, showOnlyMyQuestions, member)) + ): BundleDetailResponse { + return bundleService.getBundle(id, showOnlyMyQuestions, member) } @Operation(summary = "꾸러미 수정") @@ -69,8 +68,8 @@ class BundleController( @PathVariable id: Long, @RequestBody @Valid request: BundleUpdateRequest, @AuthToMember member: Member - ): ApiResponse { - return ApiResponse.ok(bundleService.updateBundle(id, request, member)) + ): BundleResponse { + return bundleService.updateBundle(id, request, member) } @Operation(summary = "꾸러미 삭제") @@ -79,43 +78,40 @@ class BundleController( fun deleteBundle( @PathVariable id: Long, @AuthToMember member: Member - ): ApiResponse { + ) { bundleService.deleteBundle(id, member) - return ApiResponse.noContent() } @Operation(summary = "꾸러미 스크랩") - @ResponseStatus(HttpStatus.CREATED) + @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/bundles/{id}/scrape") fun scrapeBundle( @PathVariable id: Long, @AuthToMember member: Member - ): ApiResponse { + ) { bundleService.scrapeBundle(id, member) - return ApiResponse.created(Unit) } @Operation(summary = "꾸러미 내 질문 순서 변경") + @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/bundles/{id}/question-order") fun updateQuestionOrder( @PathVariable id: Long, @RequestBody @Valid request: BundleQuestionOrderUpdateRequest, @AuthToMember member: Member - ): ApiResponse { + ) { bundleService.updateQuestionOrder(id, request, member) - return ApiResponse.noContent() } @Operation(summary = "선택한 질문 꾸러미에 추가") - @ResponseStatus(HttpStatus.CREATED) + @ResponseStatus(HttpStatus.NO_CONTENT) @PostMapping("/bundles/{id}/questions") fun addQuestion( @PathVariable id: Long, @RequestBody @Valid request: BundleQuestionAddRequest, @AuthToMember member: Member - ): ApiResponse { + ) { bundleService.addQuestion(id, request, member) - return ApiResponse.created(Unit) } @Operation(summary = "선택한 질문 꾸러미에서 삭제") @@ -125,8 +121,7 @@ class BundleController( @PathVariable id: Long, @RequestBody @Valid request: BundleQuestionRemoveRequest, @AuthToMember member: Member - ): ApiResponse { + ) { bundleService.removeQuestion(id, request, member) - return ApiResponse.noContent() } } diff --git a/server/api/src/main/kotlin/com/kw/api/domain/claim/controller/ClaimController.kt b/server/api/src/main/kotlin/com/kw/api/domain/claim/controller/ClaimController.kt index de24404..c8ffe0b 100644 --- a/server/api/src/main/kotlin/com/kw/api/domain/claim/controller/ClaimController.kt +++ b/server/api/src/main/kotlin/com/kw/api/domain/claim/controller/ClaimController.kt @@ -1,15 +1,12 @@ package com.kw.api.domain.claim.controller -import com.kw.api.common.dto.response.ApiResponse import com.kw.api.domain.claim.dto.request.CreateClaimRequest import com.kw.api.domain.claim.dto.response.ClaimResponse import com.kw.api.domain.claim.service.ClaimService import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.* @Tag(name = "건의") @RestController @@ -17,9 +14,9 @@ import org.springframework.web.bind.annotation.RestController class ClaimController(val claimService: ClaimService) { @Operation(summary = "건의 생성") + @ResponseStatus(HttpStatus.CREATED) @PostMapping("/claims") - fun createClaim(@RequestBody createClaimRequest: CreateClaimRequest): ApiResponse { - val response = claimService.createClaim(createClaimRequest) - return ApiResponse.created(response) + fun createClaim(@RequestBody createClaimRequest: CreateClaimRequest): ClaimResponse { + return claimService.createClaim(createClaimRequest) } } diff --git a/server/api/src/main/kotlin/com/kw/api/domain/member/controller/MemberController.kt b/server/api/src/main/kotlin/com/kw/api/domain/member/controller/MemberController.kt index 4dd71af..708d25e 100644 --- a/server/api/src/main/kotlin/com/kw/api/domain/member/controller/MemberController.kt +++ b/server/api/src/main/kotlin/com/kw/api/domain/member/controller/MemberController.kt @@ -1,6 +1,5 @@ package com.kw.api.domain.member.controller -import com.kw.api.common.dto.response.ApiResponse import com.kw.api.domain.member.dto.response.MemberInfoResponse import com.kw.api.domain.member.service.MemberService import com.kw.data.domain.member.Member @@ -18,24 +17,25 @@ class MemberController(private val memberService: MemberService) { @Operation(summary = "로그인된 사용자의 정보를 가져옵니다.") @GetMapping("/me") - fun getUserInfo(@AuthToMember member: Member): ApiResponse { - val response = memberService.getMemberInfo(member) - return ApiResponse.ok(response) + fun getUserInfo(@AuthToMember member: Member): MemberInfoResponse { + return memberService.getMemberInfo(member) } @Operation(summary = "사용자의 닉네임을 변경합니다.") @PatchMapping("/me/nickname") - fun updateMemberNickname(@AuthToMember member: Member, - @RequestParam nickname: String): ApiResponse { - val response = memberService.updateMemberNickname(member, nickname) - return ApiResponse.ok(response) + fun updateMemberNickname( + @AuthToMember member: Member, + @RequestParam nickname: String + ): MemberInfoResponse { + return memberService.updateMemberNickname(member, nickname) } @Operation(summary = "회원 프로필 사진을 저장합니다.") @PatchMapping(value = ["/me/profile-image"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) - fun updateMemberProfileImage(@AuthToMember member: Member, - @RequestPart(value = "file", required = true) file: MultipartFile): ApiResponse { - val response = memberService.updateMemberProfileImage(member, file) - return ApiResponse.ok(response) + fun updateMemberProfileImage( + @AuthToMember member: Member, + @RequestPart(value = "file", required = true) file: MultipartFile + ): MemberInfoResponse { + return memberService.updateMemberProfileImage(member, file) } } diff --git a/server/api/src/main/kotlin/com/kw/api/domain/question/controller/QuestionController.kt b/server/api/src/main/kotlin/com/kw/api/domain/question/controller/QuestionController.kt index 0e16dcc..52ac70a 100644 --- a/server/api/src/main/kotlin/com/kw/api/domain/question/controller/QuestionController.kt +++ b/server/api/src/main/kotlin/com/kw/api/domain/question/controller/QuestionController.kt @@ -1,6 +1,5 @@ package com.kw.api.domain.question.controller -import com.kw.api.common.dto.response.ApiResponse import com.kw.api.domain.question.dto.request.QuestionCreateRequest import com.kw.api.domain.question.dto.request.QuestionSearchRequest import com.kw.api.domain.question.dto.request.QuestionUpdateRequest @@ -27,9 +26,8 @@ class QuestionController(val questionService: QuestionService) { fun createQuestion( @RequestBody @Valid request: QuestionCreateRequest, @AuthToMember member: Member - ): ApiResponse { - val response = questionService.createQuestion(request, member) - return ApiResponse.created(response) + ): QuestionResponse { + return questionService.createQuestion(request, member) } @Operation(summary = "질문 수정") @@ -38,9 +36,8 @@ class QuestionController(val questionService: QuestionService) { @PathVariable id: Long, @RequestBody @Valid request: QuestionUpdateRequest, @AuthToMember member: Member - ): ApiResponse { - val response = questionService.updateQuestion(id, request, member) - return ApiResponse.ok(response) + ): QuestionResponse { + return questionService.updateQuestion(id, request, member) } @Operation(summary = "질문 삭제") @@ -49,9 +46,8 @@ class QuestionController(val questionService: QuestionService) { fun deleteQuestion( @PathVariable id: Long, @AuthToMember member: Member - ): ApiResponse { + ) { questionService.deleteQuestion(id, member) - return ApiResponse.noContent() } @Operation(summary = "질문 신고") @@ -60,15 +56,13 @@ class QuestionController(val questionService: QuestionService) { fun reportQuestion( @RequestParam reason: String, @PathVariable id: Long - ): ApiResponse { - val response = questionService.reportQuestion(reason, id) - return ApiResponse.created(response) + ): QuestionReportResponse { + return questionService.reportQuestion(reason, id) } @Operation(summary = "질문 검색") @GetMapping("/questions/search") - fun searchQuestion(@ModelAttribute questionSearchRequest: QuestionSearchRequest): ApiResponse { - val responses = questionService.searchQuestion(questionSearchRequest) - return ApiResponse.ok(responses) + fun searchQuestion(@ModelAttribute questionSearchRequest: QuestionSearchRequest): QuestionListResponse { + return questionService.searchQuestion(questionSearchRequest) } } diff --git a/server/api/src/main/kotlin/com/kw/api/domain/tag/controller/TagController.kt b/server/api/src/main/kotlin/com/kw/api/domain/tag/controller/TagController.kt index 7554c87..a11ef56 100644 --- a/server/api/src/main/kotlin/com/kw/api/domain/tag/controller/TagController.kt +++ b/server/api/src/main/kotlin/com/kw/api/domain/tag/controller/TagController.kt @@ -1,6 +1,5 @@ package com.kw.api.domain.tag.controller -import com.kw.api.common.dto.response.ApiResponse import com.kw.api.domain.tag.dto.response.TagResponse import com.kw.api.domain.tag.service.TagService import io.swagger.v3.oas.annotations.Operation @@ -16,8 +15,7 @@ class TagController(val tagService: TagService) { @Operation(summary = "태그 목록 조회") @GetMapping("/tags") - fun getTags(): ApiResponse> { - val responses = tagService.getTags() - return ApiResponse.ok(responses) + fun getTags(): List { + return tagService.getTags() } }