From 9e010802e1d3bbca526238c843c072a244916ea9 Mon Sep 17 00:00:00 2001 From: youKeon Date: Mon, 11 Sep 2023 14:44:14 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20=EC=88=98=EC=A0=95,=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20API=20=EC=83=81=ED=83=9C=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/AuthController.java | 7 +++-- .../comment/controller/CommentController.java | 6 ++-- .../follow/controller/FollowController.java | 7 +++-- .../project/controller/ProjectController.java | 28 +++++++++---------- .../project/service/ProjectService.java | 7 +++-- .../auth/controller/AuthControllerTest.java | 4 +-- .../controller/CommentControllerTest.java | 4 +-- 7 files changed, 34 insertions(+), 29 deletions(-) diff --git a/backend/src/main/java/com/graphy/backend/domain/auth/controller/AuthController.java b/backend/src/main/java/com/graphy/backend/domain/auth/controller/AuthController.java index 5c1aefb8..ff587800 100644 --- a/backend/src/main/java/com/graphy/backend/domain/auth/controller/AuthController.java +++ b/backend/src/main/java/com/graphy/backend/domain/auth/controller/AuthController.java @@ -13,6 +13,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; @@ -33,7 +34,8 @@ public class AuthController { @PostMapping("/signup") public ResponseEntity signUp(@Validated @RequestBody SignUpMemberRequest request) { authService.signUp(request); - return ResponseEntity.ok(ResultResponse.of(ResultCode.AUTH_SIGNUP_SUCCESS)); + return ResponseEntity.status(HttpStatus.CREATED) + .body(ResultResponse.of(ResultCode.AUTH_SIGNUP_SUCCESS)); } @Operation(summary = "signin", description = "로그인") @@ -47,7 +49,8 @@ public ResponseEntity signIn(@Validated @RequestBody SignInMembe @PostMapping(value = "/logout") public ResponseEntity logout(@Validated @RequestBody LogoutRequest dto) { authService.logout(dto); - return ResponseEntity.ok(ResultResponse.of(ResultCode.AUTH_LOGOUT_SUCCESS)); + return ResponseEntity.status(HttpStatus.NO_CONTENT) + .body(ResultResponse.of(ResultCode.AUTH_LOGOUT_SUCCESS)); } @Operation(summary = "reIssue", description = "토큰 재발급") diff --git a/backend/src/main/java/com/graphy/backend/domain/comment/controller/CommentController.java b/backend/src/main/java/com/graphy/backend/domain/comment/controller/CommentController.java index 2944fab6..b17b6347 100644 --- a/backend/src/main/java/com/graphy/backend/domain/comment/controller/CommentController.java +++ b/backend/src/main/java/com/graphy/backend/domain/comment/controller/CommentController.java @@ -32,7 +32,6 @@ public class CommentController { public ResponseEntity commentAdd(@Validated @RequestBody CreateCommentRequest dto, @CurrentUser Member loginUser) { commentService.addComment(dto, loginUser); - return ResponseEntity.status(HttpStatus.CREATED) .body(ResultResponse.of(ResultCode.COMMENT_CREATE_SUCCESS)); } @@ -43,8 +42,7 @@ public ResponseEntity commentUpdate(@Validated @RequestBody Upda @PathVariable Long commentId, @CurrentUser Member loginUser) { commentService.modifyComment(commentId, dto); - - return ResponseEntity.status(HttpStatus.OK) + return ResponseEntity.status(HttpStatus.NO_CONTENT) .body(ResultResponse.of(ResultCode.COMMENT_UPDATE_SUCCESS)); } @@ -53,7 +51,7 @@ public ResponseEntity commentUpdate(@Validated @RequestBody Upda public ResponseEntity commentDelete(@PathVariable Long id, @CurrentUser Member loginUser) { commentService.deleteComment(id); - return ResponseEntity.status(HttpStatus.OK) + return ResponseEntity.status(HttpStatus.NO_CONTENT) .body(ResultResponse.of(ResultCode.COMMENT_DELETE_SUCCESS)); } diff --git a/backend/src/main/java/com/graphy/backend/domain/follow/controller/FollowController.java b/backend/src/main/java/com/graphy/backend/domain/follow/controller/FollowController.java index 3c1da771..3f425bef 100644 --- a/backend/src/main/java/com/graphy/backend/domain/follow/controller/FollowController.java +++ b/backend/src/main/java/com/graphy/backend/domain/follow/controller/FollowController.java @@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -26,14 +27,16 @@ public class FollowController { @PostMapping("/{id}") public ResponseEntity followAdd(@PathVariable Long id, @CurrentUser Member loginUser) { followService.addFollow(id, loginUser); - return ResponseEntity.ok(ResultResponse.of(ResultCode.FOLLOWING_CREATE_SUCCESS)); + return ResponseEntity.status(HttpStatus.CREATED) + .body(ResultResponse.of(ResultCode.FOLLOWING_CREATE_SUCCESS)); } @Operation(summary = "unfollow", description = "언팔로우") @DeleteMapping("/{id}") public ResponseEntity followRemove(@PathVariable Long id, @CurrentUser Member loginUser) { followService.removeFollow(id, loginUser); - return ResponseEntity.ok(ResultResponse.of(ResultCode.FOLLOW_DELETE_SUCCESS)); + return ResponseEntity.status(HttpStatus.NO_CONTENT) + .body(ResultResponse.of(ResultCode.FOLLOW_DELETE_SUCCESS)); } @Operation(summary = "Get Follower", description = "팔로워 조회") diff --git a/backend/src/main/java/com/graphy/backend/domain/project/controller/ProjectController.java b/backend/src/main/java/com/graphy/backend/domain/project/controller/ProjectController.java index b433ce89..b82f3cbf 100644 --- a/backend/src/main/java/com/graphy/backend/domain/project/controller/ProjectController.java +++ b/backend/src/main/java/com/graphy/backend/domain/project/controller/ProjectController.java @@ -21,6 +21,7 @@ import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -40,36 +41,35 @@ public class ProjectController { @PostMapping public ResponseEntity projectAdd(@Validated @RequestBody CreateProjectRequest dto, @CurrentUser Member loginUser) { CreateProjectResponse response = projectService.addProject(dto, loginUser); - return ResponseEntity.ok(ResultResponse.of(ResultCode.PROJECT_CREATE_SUCCESS, response)); + return ResponseEntity.status(HttpStatus.CREATED) + .body(ResultResponse.of(ResultCode.PROJECT_CREATE_SUCCESS, response)); } @Operation(summary = "deleteProject", description = "프로젝트 삭제(soft delete)") - @DeleteMapping("/{project_id}") - public ResponseEntity projectRemove(@PathVariable Long project_id, @CurrentUser Member loginUser) { - projectService.removeProject(project_id); - return ResponseEntity.ok(ResultResponse.of(ResultCode.PROJECT_DELETE_SUCCESS)); + @DeleteMapping("/{projectId}") + public ResponseEntity projectRemove(@PathVariable Long projectId, @CurrentUser Member loginUser) { + projectService.removeProject(projectId); + return ResponseEntity.status(HttpStatus.NO_CONTENT) + .body(ResultResponse.of(ResultCode.PROJECT_DELETE_SUCCESS)); } - @Operation(summary = "updateProject", description = "프로젝트 수정(변경감지)") + @Operation(summary = "updateProject", description = "프로젝트 수정") @PutMapping("/{projectId}") public ResponseEntity projectModify(@PathVariable Long projectId, @RequestBody @Validated UpdateProjectRequest dto, @CurrentUser Member loginUser) { UpdateProjectResponse result = projectService.modifyProject(projectId, dto); - return ResponseEntity.ok(ResultResponse.of(ResultCode.PROJECT_UPDATE_SUCCESS, result)); + return ResponseEntity.status(HttpStatus.NO_CONTENT) + .body(ResultResponse.of(ResultCode.PROJECT_UPDATE_SUCCESS, result)); } - @Operation(summary = "findProjects", description = "프로젝트 조회 \n\n" + "\t⚠️ sort 주의사항 ⚠️\n\n" + - "\t\t1. sort는 공백(\"\"), id, createdAt, updatedAt, content, description, projectName 중 하나 입력\n\n" + - "\t\t2. 오름차순이 기본입니다. 내림차순을 원하실 경우 {정렬기준},desc (ex. \"id,desc\")를 입력해주세요 (콤마 사이 띄어쓰기 X)\n\n" + - "\t\t3. sort의 default(공백 입력) : createdAt(최신순), 내림차순") - - @GetMapping("/search") + @Operation(summary = "findProjectList", description = "프로젝트 조회") + @GetMapping public ResponseEntity projectList(GetProjectsRequest dto, PageRequest pageRequest) { Pageable pageable = pageRequest.of(); List result = projectService.findProjectList(dto, pageable); - if (result.size() == 0) throw new EmptyResultException(ErrorCode.PROJECT_DELETED_OR_NOT_EXIST); + if (result.isEmpty()) throw new EmptyResultException(ErrorCode.PROJECT_DELETED_OR_NOT_EXIST); return ResponseEntity.ok(ResultResponse.of(ResultCode.PROJECT_PAGING_GET_SUCCESS, result)); } diff --git a/backend/src/main/java/com/graphy/backend/domain/project/service/ProjectService.java b/backend/src/main/java/com/graphy/backend/domain/project/service/ProjectService.java index 16c5ffd8..8bee84e5 100644 --- a/backend/src/main/java/com/graphy/backend/domain/project/service/ProjectService.java +++ b/backend/src/main/java/com/graphy/backend/domain/project/service/ProjectService.java @@ -21,6 +21,7 @@ import com.graphy.backend.global.error.exception.LongRequestException; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.core.io.ClassPathResource; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.data.domain.Page; @@ -40,7 +41,7 @@ import static com.graphy.backend.global.config.ChatGPTConfig.MAX_REQUEST_TOKEN; -@Service +@Service @Slf4j @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class ProjectService { private final ProjectRepository projectRepository; @@ -143,9 +144,9 @@ public CompletableFuture getProjectPlanAsync(String prompt) { } private void GptApiCall(GptCompletionRequest request, Consumer callback) { - System.out.println("비동기 작업 시작"); + log.info("비동기 작업 시작"); GptCompletionResponse result = gptChatRestService.completion(request); - System.out.println("비동기 작업 완료"); + log.info("비동기 작업 완료"); String response = result.getMessages().get(0).getText() .replace("\n", " ").replace("\n\n", " "); callback.accept(response); diff --git a/backend/src/test/java/com/graphy/backend/domain/auth/controller/AuthControllerTest.java b/backend/src/test/java/com/graphy/backend/domain/auth/controller/AuthControllerTest.java index 070d5622..15035029 100644 --- a/backend/src/test/java/com/graphy/backend/domain/auth/controller/AuthControllerTest.java +++ b/backend/src/test/java/com/graphy/backend/domain/auth/controller/AuthControllerTest.java @@ -72,7 +72,7 @@ public void signUpTest() throws Exception { mvc.perform(post(BASE_URL + "/signup") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(request))) - .andExpect(status().isOk()) + .andExpect(status().isCreated()) .andDo(print()) .andDo(document("auth/signUp/success", @@ -407,7 +407,7 @@ public void logoutTest() throws Exception { .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(request))) - .andExpect(status().isOk()) + .andExpect(status().isNoContent()) .andDo(print()) .andDo(document("auth/logout/success", diff --git a/backend/src/test/java/com/graphy/backend/domain/comment/controller/CommentControllerTest.java b/backend/src/test/java/com/graphy/backend/domain/comment/controller/CommentControllerTest.java index 0d3d0265..7bf9c97a 100644 --- a/backend/src/test/java/com/graphy/backend/domain/comment/controller/CommentControllerTest.java +++ b/backend/src/test/java/com/graphy/backend/domain/comment/controller/CommentControllerTest.java @@ -247,7 +247,7 @@ void modifyCommentTest() throws Exception { mvc.perform(put(BASE_URL + "/{commentId}", parentComment.getId()) .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(request))) - .andExpect(status().isOk()) + .andExpect(status().isNoContent()) .andDo(print()) .andDo(document("comment/modify/success", getDocumentRequest(), @@ -302,7 +302,7 @@ void removeCommentTest() throws Exception { // given, when, then mvc.perform(delete(BASE_URL + "/{commentId}", parentComment.getId())) - .andExpect(status().isOk()) + .andExpect(status().isNoContent()) .andDo(print()) .andDo(document("comment/remove/success", getDocumentRequest(),