Skip to content

Commit

Permalink
Merge pull request #200 from techeer-sv/BE/#199
Browse files Browse the repository at this point in the history
BE/#199 수정, 삭제 API 상태 코드 변경
  • Loading branch information
youKeon authored Sep 11, 2023
2 parents 18033d5 + 9e01080 commit bb42474
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +34,8 @@ public class AuthController {
@PostMapping("/signup")
public ResponseEntity<ResultResponse> 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 = "로그인")
Expand All @@ -47,7 +49,8 @@ public ResponseEntity<ResultResponse> signIn(@Validated @RequestBody SignInMembe
@PostMapping(value = "/logout")
public ResponseEntity<ResultResponse> 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 = "토큰 재발급")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class CommentController {
public ResponseEntity<ResultResponse> commentAdd(@Validated @RequestBody CreateCommentRequest dto,
@CurrentUser Member loginUser) {
commentService.addComment(dto, loginUser);

return ResponseEntity.status(HttpStatus.CREATED)
.body(ResultResponse.of(ResultCode.COMMENT_CREATE_SUCCESS));
}
Expand All @@ -43,8 +42,7 @@ public ResponseEntity<ResultResponse> 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));
}

Expand All @@ -53,7 +51,7 @@ public ResponseEntity<ResultResponse> commentUpdate(@Validated @RequestBody Upda
public ResponseEntity<ResultResponse> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -26,14 +27,16 @@ public class FollowController {
@PostMapping("/{id}")
public ResponseEntity<ResultResponse> 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<ResultResponse> 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 = "팔로워 조회")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -40,36 +41,35 @@ public class ProjectController {
@PostMapping
public ResponseEntity<ResultResponse> 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<ResultResponse> 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<ResultResponse> 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<ResultResponse> 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<ResultResponse> projectList(GetProjectsRequest dto, PageRequest pageRequest) {
Pageable pageable = pageRequest.of();
List<GetProjectResponse> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -143,9 +144,9 @@ public CompletableFuture<String> getProjectPlanAsync(String prompt) {
}

private void GptApiCall(GptCompletionRequest request, Consumer<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit bb42474

Please sign in to comment.