Merge branch 'be/refactor/response' into 'be/develop'

Refactor: 응답 리팩토링

See merge request s11-s-project/S11P21S002!74
This commit is contained in:
김태수 2024-09-14 14:19:19 +09:00
commit 3f0c5cd487
8 changed files with 72 additions and 140 deletions

View File

@ -46,10 +46,7 @@ public class AuthController {
@SwaggerApiSuccess(description = "Return Access Token") @SwaggerApiSuccess(description = "Return Access Token")
@SwaggerApiError({ErrorCode.INVALID_TOKEN, ErrorCode.USER_ALREADY_SIGN_OUT, ErrorCode.REFRESH_TOKEN_EXPIRED, ErrorCode.INVALID_REFRESH_TOKEN}) @SwaggerApiError({ErrorCode.INVALID_TOKEN, ErrorCode.USER_ALREADY_SIGN_OUT, ErrorCode.REFRESH_TOKEN_EXPIRED, ErrorCode.INVALID_REFRESH_TOKEN})
@PostMapping("/reissue") @PostMapping("/reissue")
public SuccessResponse<AccessTokenResponse> reissue( public AccessTokenResponse reissue(HttpServletRequest request, HttpServletResponse response) {
HttpServletRequest request,
HttpServletResponse response
) {
log.debug("reissue request"); log.debug("reissue request");
String refresh = parseRefreshCookie(request); String refresh = parseRefreshCookie(request);
try { try {
@ -59,7 +56,7 @@ public class AuthController {
response.addCookie(createCookie(newToken.getRefreshToken())); response.addCookie(createCookie(newToken.getRefreshToken()));
authService.saveRefreshToken(id, newToken.getRefreshToken(),refreshExpiry); authService.saveRefreshToken(id, newToken.getRefreshToken(),refreshExpiry);
return SuccessResponse.of(AccessTokenResponse.from(newToken.getAccessToken())); return AccessTokenResponse.from(newToken.getAccessToken());
} catch (CustomException e) { } catch (CustomException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
@ -71,9 +68,8 @@ public class AuthController {
@SwaggerApiSuccess(description = "Return Member Info") @SwaggerApiSuccess(description = "Return Member Info")
@SwaggerApiError({ErrorCode.INVALID_TOKEN, ErrorCode.USER_ALREADY_SIGN_OUT, ErrorCode.REFRESH_TOKEN_EXPIRED, ErrorCode.INVALID_REFRESH_TOKEN, ErrorCode.USER_NOT_FOUND}) @SwaggerApiError({ErrorCode.INVALID_TOKEN, ErrorCode.USER_ALREADY_SIGN_OUT, ErrorCode.REFRESH_TOKEN_EXPIRED, ErrorCode.INVALID_REFRESH_TOKEN, ErrorCode.USER_NOT_FOUND})
@GetMapping("/profile") @GetMapping("/profile")
public SuccessResponse<MemberResponse> getMemberInfo(@CurrentUser Integer currentMember){ public MemberResponse getMemberInfo(@CurrentUser Integer currentMember){
MemberResponse memberResponse = memberService.getMemberId(currentMember); return memberService.getMemberId(currentMember);
return SuccessResponse.of(memberResponse);
} }
private static String parseRefreshCookie(HttpServletRequest request) { private static String parseRefreshCookie(HttpServletRequest request) {
@ -93,7 +89,7 @@ public class AuthController {
cookie.setMaxAge((int) (refreshExpiry / 1000)); cookie.setMaxAge((int) (refreshExpiry / 1000));
cookie.setPath("/"); cookie.setPath("/");
cookie.setHttpOnly(true); cookie.setHttpOnly(true);
// cookie.setSecure(true); // 배포 HTTPS에서 사용 cookie.setSecure(true); // 배포 HTTPS에서 사용
return cookie; return cookie;
} }
} }

View File

@ -29,61 +29,57 @@ public class CommentController {
@SwaggerApiSuccess(description = "댓글 목록을 성공적으로 조회합니다.") @SwaggerApiSuccess(description = "댓글 목록을 성공적으로 조회합니다.")
@Operation(summary = "댓글 목록 조회", description = "댓글 목록을 조회합니다.") @Operation(summary = "댓글 목록 조회", description = "댓글 목록을 조회합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
public BaseResponse<CommentResponses> getAllComments( public CommentResponses getAllComments(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("image_id") final Long imageId) { @PathVariable("image_id") final Long imageId) {
List<CommentResponse> comments = commentService.getAllComments(memberId, projectId, imageId); List<CommentResponse> comments = commentService.getAllComments(memberId, projectId, imageId);
return new SuccessResponse<>(CommentResponses.from(comments)); return CommentResponses.from(comments);
} }
@GetMapping("/{comment_id}") @GetMapping("/{comment_id}")
@SwaggerApiSuccess(description = "댓글을 성공적으로 조회합니다.") @SwaggerApiSuccess(description = "댓글을 성공적으로 조회합니다.")
@Operation(summary = "댓글 조회", description = "댓글을 조회합니다.") @Operation(summary = "댓글 조회", description = "댓글을 조회합니다.")
@SwaggerApiError({ErrorCode.COMMENT_NOT_FOUND, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.COMMENT_NOT_FOUND, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
public BaseResponse<CommentResponse> getCommentById( public CommentResponse getCommentById(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("comment_id") final Integer commentId) { @PathVariable("comment_id") final Integer commentId) {
CommentResponse comment = commentService.getCommentById(memberId, projectId, commentId); return commentService.getCommentById(memberId, projectId, commentId);
return new SuccessResponse<>(comment);
} }
@PostMapping("/images/{image_id}") @PostMapping("/images/{image_id}")
@SwaggerApiSuccess(description = "댓글을 성공적으로 생성합니다.") @SwaggerApiSuccess(description = "댓글을 성공적으로 생성합니다.")
@Operation(summary = "댓글 생성", description = "댓글을 생성합니다.") @Operation(summary = "댓글 생성", description = "댓글을 생성합니다.")
@SwaggerApiError({ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
public BaseResponse<CommentResponse> createComment( public CommentResponse createComment(
@RequestBody final CommentRequest commentRequest, @RequestBody final CommentRequest commentRequest,
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("image_id") final Long imageId) { @PathVariable("image_id") final Long imageId) {
CommentResponse comment = commentService.createComment(commentRequest, memberId, projectId, imageId); return commentService.createComment(commentRequest, memberId, projectId, imageId);
return new SuccessResponse<>(comment);
} }
@PutMapping("/{comment_id}") @PutMapping("/{comment_id}")
@SwaggerApiSuccess(description = "댓글을 성공적으로 수정합니다.") @SwaggerApiSuccess(description = "댓글을 성공적으로 수정합니다.")
@Operation(summary = "댓글 수정", description = "댓글을 수정합니다.") @Operation(summary = "댓글 수정", description = "댓글을 수정합니다.")
@SwaggerApiError({ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
public BaseResponse<CommentResponse> updateComment( public CommentResponse updateComment(
@RequestBody final CommentRequest commentRequest, @RequestBody final CommentRequest commentRequest,
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("comment_id") final Integer commentId) { @PathVariable("comment_id") final Integer commentId) {
CommentResponse comment = commentService.updateComment(commentRequest, memberId, projectId, commentId); return commentService.updateComment(commentRequest, memberId, projectId, commentId);
return new SuccessResponse<>(comment);
} }
@DeleteMapping("/{comment_id}") @DeleteMapping("/{comment_id}")
@SwaggerApiSuccess(description = "댓글을 성공적으로 생성합니다.") @SwaggerApiSuccess(description = "댓글을 성공적으로 생성합니다.")
@Operation(summary = "댓글 생성", description = "댓글을 생성합니다.") @Operation(summary = "댓글 생성", description = "댓글을 생성합니다.")
@SwaggerApiError({ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
public BaseResponse<Void> deleteComment( public void deleteComment(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("comment_id") final Integer commentId) { @PathVariable("comment_id") final Integer commentId) {
commentService.deleteComment(memberId, projectId, commentId); commentService.deleteComment(memberId, projectId, commentId);
return new SuccessResponse<>();
} }
} }

View File

@ -27,60 +27,55 @@ public class FolderController {
@SwaggerApiSuccess(description = "폴더를 성공적으로 생성합니다.") @SwaggerApiSuccess(description = "폴더를 성공적으로 생성합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@PostMapping @PostMapping
public BaseResponse<FolderResponse> createFolder( public FolderResponse createFolder(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@RequestBody final FolderRequest folderRequest) { @RequestBody final FolderRequest folderRequest) {
FolderResponse folderResponse = folderService.createFolder(memberId, projectId, folderRequest); return folderService.createFolder(memberId, projectId, folderRequest);
return SuccessResponse.of(folderResponse);
} }
@Operation(summary = "폴더 조회", description = "폴더의 내용을 조회합니다.") @Operation(summary = "폴더 조회", description = "폴더의 내용을 조회합니다.")
@SwaggerApiSuccess(description = "폴더를 성공적으로 조회합니다.") @SwaggerApiSuccess(description = "폴더를 성공적으로 조회합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@GetMapping("/{folder_id}") @GetMapping("/{folder_id}")
public BaseResponse<FolderResponse> getFolderById( public FolderResponse getFolderById(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("folder_id") final Integer folderId) { @PathVariable("folder_id") final Integer folderId) {
FolderResponse folderResponse = folderService.getFolderById(memberId, projectId, folderId); return folderService.getFolderById(memberId, projectId, folderId);
return SuccessResponse.of(folderResponse);
} }
@Operation(summary = "폴더 하위 리뷰해야할 목록만 조회", description = "폴더하위 리뷰해야할 목록을 조회합니다.") @Operation(summary = "폴더 하위 리뷰해야할 목록만 조회", description = "폴더하위 리뷰해야할 목록을 조회합니다.")
@SwaggerApiSuccess(description = "폴더 하위 리뷰해야할 목록을 성공적으로 조회합니다.") @SwaggerApiSuccess(description = "폴더 하위 리뷰해야할 목록을 성공적으로 조회합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@GetMapping("/{folder_id}/review") @GetMapping("/{folder_id}/review")
public BaseResponse<FolderResponse> getFolderByIdWithNeedReview( public FolderResponse getFolderByIdWithNeedReview(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("folder_id") final Integer folderId) { @PathVariable("folder_id") final Integer folderId) {
FolderResponse folderResponse = folderService.getFolderByIdWithNeedReview(memberId, projectId, folderId); return folderService.getFolderByIdWithNeedReview(memberId, projectId, folderId);
return SuccessResponse.of(folderResponse);
} }
@Operation(summary = "폴더 수정", description = "폴더 정보를 수정합니다.") @Operation(summary = "폴더 수정", description = "폴더 정보를 수정합니다.")
@SwaggerApiSuccess(description = "폴더를 성공적으로 수정합니다.") @SwaggerApiSuccess(description = "폴더를 성공적으로 수정합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@PutMapping("/{folder_id}") @PutMapping("/{folder_id}")
public BaseResponse<FolderResponse> updateFolder( public FolderResponse updateFolder(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("folder_id") final Integer folderId, @PathVariable("folder_id") final Integer folderId,
@RequestBody FolderRequest folderRequest) { @RequestBody FolderRequest folderRequest) {
FolderResponse folderResponse = folderService.updateFolder(memberId, projectId, folderId, folderRequest); return folderService.updateFolder(memberId, projectId, folderId, folderRequest);
return SuccessResponse.of(folderResponse);
} }
@Operation(summary = "폴더 삭제", description = "폴더를 삭제합니다.") @Operation(summary = "폴더 삭제", description = "폴더를 삭제합니다.")
@SwaggerApiSuccess(description = "폴더를 성공적으로 삭제합니다.") @SwaggerApiSuccess(description = "폴더를 성공적으로 삭제합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@DeleteMapping("/{folder_id}") @DeleteMapping("/{folder_id}")
public BaseResponse<Void> deleteFolder( public void deleteFolder(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("folder_id") final Integer folderId) { @PathVariable("folder_id") final Integer folderId) {
folderService.deleteFolder(memberId, projectId, folderId); folderService.deleteFolder(memberId, projectId, folderId);
return SuccessResponse.empty();
} }
} }

View File

@ -33,79 +33,66 @@ public class ImageController {
@SwaggerApiSuccess(description = "이미지 목록을 성공적으로 업로드합니다.") @SwaggerApiSuccess(description = "이미지 목록을 성공적으로 업로드합니다.")
@Operation(summary = "이미지 목록 업로드", description = "이미지 목록을 업로드합니다.") @Operation(summary = "이미지 목록 업로드", description = "이미지 목록을 업로드합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
public BaseResponse<Void> uploadImage( public void uploadImage(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId, @PathVariable("folder_id") final Integer folderId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@Parameter(name = "폴더에 추가 할 이미지 리스트", description = "MultiPartFile을 imageList로 추가해준다.", example = "") @RequestBody final List<MultipartFile> imageList @Parameter(name = "폴더에 추가 할 이미지 리스트", description = "MultiPartFile을 imageList로 추가해준다.", example = "") @RequestBody final List<MultipartFile> imageList) {
) {
log.debug("project: {} , folder: {}, imageList upload, 현재 로그인 중인 사용자 : {}, 이미지 개수 : {}", projectId, folderId, memberId, imageList.size()); log.debug("project: {} , folder: {}, imageList upload, 현재 로그인 중인 사용자 : {}, 이미지 개수 : {}", projectId, folderId, memberId, imageList.size());
imageService.uploadImageList(imageList, folderId, projectId, memberId); imageService.uploadImageList(imageList, folderId, projectId, memberId);
return SuccessResponse.empty();
} }
@GetMapping("/{image_id}") @GetMapping("/{image_id}")
@SwaggerApiSuccess(description = "이미지를 조회합니다.") @SwaggerApiSuccess(description = "이미지를 조회합니다.")
@Operation(summary = "이미지 조회", description = "이미지 정보를 조회합니다.") @Operation(summary = "이미지 조회", description = "이미지 정보를 조회합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
public BaseResponse<ImageResponse> getImageById( public ImageResponse getImageById(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId, @PathVariable("folder_id") final Integer folderId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("image_id") final Long imageId @PathVariable("image_id") final Long imageId) {
) {
log.debug("project: {} , folder: {}, image: {}, 현재 로그인 중인 사용자 : {}", projectId, folderId, memberId, imageId); log.debug("project: {} , folder: {}, image: {}, 현재 로그인 중인 사용자 : {}", projectId, folderId, memberId, imageId);
ImageResponse imageResponse = imageService.getImageById(projectId, folderId, imageId, memberId); return imageService.getImageById(projectId, folderId, imageId, memberId);
return SuccessResponse.of(imageResponse);
} }
@PutMapping("/{image_id}") @PutMapping("/{image_id}")
@SwaggerApiSuccess(description = "이미지 폴더 이동.") @SwaggerApiSuccess(description = "이미지 폴더 이동.")
@Operation(summary = "이미지 폴더 이동", description = "이미지가 위치한 폴더를 변경합니다.") @Operation(summary = "이미지 폴더 이동", description = "이미지가 위치한 폴더를 변경합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND})
public BaseResponse<Void> moveFolderImage( public void moveFolderImage(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId, @PathVariable("folder_id") final Integer folderId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("image_id") final Long imageId, @PathVariable("image_id") final Long imageId,
@RequestBody final ImageMoveRequest imageMoveRequest @RequestBody final ImageMoveRequest imageMoveRequest) {
) {
log.debug("project: {} , folder: {}, image: {}, 현재 로그인 중인 사용자 : {}, 이동하는 폴더 {}", projectId, folderId, memberId, imageId, imageMoveRequest.getMoveFolderId()); log.debug("project: {} , folder: {}, image: {}, 현재 로그인 중인 사용자 : {}, 이동하는 폴더 {}", projectId, folderId, memberId, imageId, imageMoveRequest.getMoveFolderId());
imageService.moveFolder(projectId, folderId, imageMoveRequest.getMoveFolderId(), imageId, memberId); imageService.moveFolder(projectId, folderId, imageMoveRequest.getMoveFolderId(), imageId, memberId);
return SuccessResponse.empty();
} }
@DeleteMapping("/{image_id}") @DeleteMapping("/{image_id}")
@SwaggerApiSuccess(description = "이미지 삭제.") @SwaggerApiSuccess(description = "이미지 삭제.")
@Operation(summary = "이미지 삭제", description = "폴더에서 해당 이미지를 제거합니다.") @Operation(summary = "이미지 삭제", description = "폴더에서 해당 이미지를 제거합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND})
public BaseResponse<Void> deleteImage( public void deleteImage(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId, @PathVariable("folder_id") final Integer folderId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("image_id") final Long imageId @PathVariable("image_id") final Long imageId) {
) {
log.debug("project: {} , folder: {}, 삭제하려는 이미지: {}, 현재 로그인 중인 사용자 : {}", projectId, folderId, imageId, memberId); log.debug("project: {} , folder: {}, 삭제하려는 이미지: {}, 현재 로그인 중인 사용자 : {}", projectId, folderId, imageId, memberId);
imageService.deleteImage(projectId, folderId, imageId, memberId); imageService.deleteImage(projectId, folderId, imageId, memberId);
return SuccessResponse.empty();
} }
@PutMapping("/{image_id}/status") @PutMapping("/{image_id}/status")
@SwaggerApiSuccess(description = "이미지 상태 변경.") @SwaggerApiSuccess(description = "이미지 상태 변경.")
@Operation(summary = "이미지 상태 변경", description = "특정 이미지의 상태를 변경합니다.") @Operation(summary = "이미지 상태 변경", description = "특정 이미지의 상태를 변경합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.FOLDER_NOT_FOUND, ErrorCode.IMAGE_NOT_FOUND})
public BaseResponse<ImageResponse> changeImageStatus( public ImageResponse changeImageStatus(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId, @PathVariable("folder_id") final Integer folderId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@PathVariable("image_id") final Long imageId, @PathVariable("image_id") final Long imageId,
@RequestBody final ImageStatusRequest imageStatusRequest @RequestBody final ImageStatusRequest imageStatusRequest) {
) {
log.debug("project: {} , folder: {}, 수정하려는 이미지: {}, 현재 로그인 중인 사용자 : {}", projectId, folderId, imageId, memberId); log.debug("project: {} , folder: {}, 수정하려는 이미지: {}, 현재 로그인 중인 사용자 : {}", projectId, folderId, imageId, memberId);
ImageResponse imageResponse = imageService.changeImageStatus(projectId, folderId, imageId, memberId, imageStatusRequest); return imageService.changeImageStatus(projectId, folderId, imageId, memberId, imageStatusRequest);
return SuccessResponse.of(imageResponse);
} }
} }

View File

@ -6,8 +6,6 @@ import com.worlabel.global.annotation.CurrentUser;
import com.worlabel.global.config.swagger.SwaggerApiError; import com.worlabel.global.config.swagger.SwaggerApiError;
import com.worlabel.global.config.swagger.SwaggerApiSuccess; import com.worlabel.global.config.swagger.SwaggerApiSuccess;
import com.worlabel.global.exception.ErrorCode; import com.worlabel.global.exception.ErrorCode;
import com.worlabel.global.response.BaseResponse;
import com.worlabel.global.response.SuccessResponse;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;

View File

@ -34,105 +34,94 @@ public class ProjectController {
@SwaggerApiSuccess(description = "프로젝트를 성공적으로 생성합니다.") @SwaggerApiSuccess(description = "프로젝트를 성공적으로 생성합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@PostMapping("/workspaces/{workspace_id}/projects") @PostMapping("/workspaces/{workspace_id}/projects")
public BaseResponse<ProjectResponse> createProject( public ProjectResponse createProject(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("workspace_id") final Integer workspaceId, @PathVariable("workspace_id") final Integer workspaceId,
@Valid @RequestBody final ProjectRequest projectRequest) { @Valid @RequestBody final ProjectRequest projectRequest) {
ProjectResponse project = projectService.createProject(memberId, workspaceId, projectRequest); return projectService.createProject(memberId, workspaceId, projectRequest);
return SuccessResponse.of(project);
} }
@Operation(summary = "프로젝트 조회", description = "프로젝트를 조회합니다.") @Operation(summary = "프로젝트 조회", description = "프로젝트를 조회합니다.")
@SwaggerApiSuccess(description = "프로젝트를 성공적으로 조회합니다.") @SwaggerApiSuccess(description = "프로젝트를 성공적으로 조회합니다.")
@SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.SERVER_ERROR})
@GetMapping("/projects/{project_id}") @GetMapping("/projects/{project_id}")
public BaseResponse<ProjectResponse> getProject(@CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId) { public ProjectResponse getProject(@CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId) {
ProjectResponse project = projectService.getProjectById(memberId, projectId); return projectService.getProjectById(memberId, projectId);
return SuccessResponse.of(project);
} }
@Operation(summary = "전체 프로젝트 조회", description = "모든 프로젝트를 조회합니다.") @Operation(summary = "전체 프로젝트 조회", description = "모든 프로젝트를 조회합니다.")
@SwaggerApiSuccess(description = "전체 프로젝트를 성공적으로 조회합니다.") @SwaggerApiSuccess(description = "전체 프로젝트를 성공적으로 조회합니다.")
@SwaggerApiError({ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.SERVER_ERROR})
@GetMapping("/workspaces/{workspace_id}/projects") @GetMapping("/workspaces/{workspace_id}/projects")
public BaseResponse<ProjectResponses> getProjects( public ProjectResponses getProjects(
@PathVariable("workspace_id") Integer workspaceId, @PathVariable("workspace_id") Integer workspaceId,
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@Parameter(name = "마지막 프로젝트 id", description = "마지막 프로젝트 id를 넣으면 그 아래 부터 가져옴, 넣지않으면 가장 최신", example = "1") @RequestParam(required = false) Integer lastProjectId, @Parameter(name = "마지막 프로젝트 id", description = "마지막 프로젝트 id를 넣으면 그 아래 부터 가져옴, 넣지않으면 가장 최신", example = "1") @RequestParam(required = false) Integer lastProjectId,
@Parameter(name = "가져올 프로젝트 수", description = "가져올 프로젝트 수 default = 10", example = "20") @RequestParam(defaultValue = "10") Integer limitPage) { @Parameter(name = "가져올 프로젝트 수", description = "가져올 프로젝트 수 default = 10", example = "20") @RequestParam(defaultValue = "10") Integer limitPage) {
List<ProjectResponse> projects = projectService.getProjectsByWorkspaceId(workspaceId, memberId, lastProjectId, limitPage); List<ProjectResponse> projects = projectService.getProjectsByWorkspaceId(workspaceId, memberId, lastProjectId, limitPage);
return SuccessResponse.of(ProjectResponses.from(projects)); return ProjectResponses.from(projects);
} }
@Operation(summary = "프로젝트 수정", description = "프로젝트를 수정합니다.") @Operation(summary = "프로젝트 수정", description = "프로젝트를 수정합니다.")
@SwaggerApiSuccess(description = "프로젝트를 성공적으로 수정합니다.") @SwaggerApiSuccess(description = "프로젝트를 성공적으로 수정합니다.")
@SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.SERVER_ERROR})
@PutMapping("/projects/{project_id}") @PutMapping("/projects/{project_id}")
public BaseResponse<ProjectResponse> updateProject( public ProjectResponse updateProject(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@Valid @RequestBody final ProjectRequest projectRequest) { @Valid @RequestBody final ProjectRequest projectRequest) {
ProjectResponse project = projectService.updateProject(memberId, projectId, projectRequest); return projectService.updateProject(memberId, projectId, projectRequest);
return SuccessResponse.of(project);
} }
@Operation(summary = "프로젝트 모델 학습", description = "프로젝트 모델을 학습시킵니다..") @Operation(summary = "프로젝트 모델 학습", description = "프로젝트 모델을 학습시킵니다..")
@SwaggerApiSuccess(description = "프로젝트 모델이 성공적으로 학습됩니다.") @SwaggerApiSuccess(description = "프로젝트 모델이 성공적으로 학습됩니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@PostMapping("/projects/{project_id}/train") @PostMapping("/projects/{project_id}/train")
public BaseResponse<Void> trainModel( public void trainModel(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId) { @PathVariable("project_id") final Integer projectId) {
projectService.train(memberId, projectId); projectService.train(memberId, projectId);
return SuccessResponse.empty();
} }
@Operation(summary = "프로젝트 삭제", description = "프로젝트를 삭제합니다.") @Operation(summary = "프로젝트 삭제", description = "프로젝트를 삭제합니다.")
@SwaggerApiSuccess(description = "프로젝트를 성공적으로 삭제합니다.") @SwaggerApiSuccess(description = "프로젝트를 성공적으로 삭제합니다.")
@SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.PROJECT_NOT_FOUND, ErrorCode.PARTICIPANT_EDITOR_UNAUTHORIZED, ErrorCode.SERVER_ERROR})
@DeleteMapping("/projects/{project_id}") @DeleteMapping("/projects/{project_id}")
public BaseResponse<Void> deleteProject(@CurrentUser final Integer memberId, public void deleteProject(@CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId) { @PathVariable("project_id") final Integer projectId) {
projectService.deleteProject(memberId, projectId); projectService.deleteProject(memberId, projectId);
return SuccessResponse.empty();
} }
@Operation(summary = "프로젝트 멤버 추가", description = "새로운 프로젝트 멤버를 추가합니다.") @Operation(summary = "프로젝트 멤버 추가", description = "새로운 프로젝트 멤버를 추가합니다.")
@SwaggerApiSuccess(description = "프로젝트 멤버를 성공적으로 추가합니다.") @SwaggerApiSuccess(description = "프로젝트 멤버를 성공적으로 추가합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@PostMapping("/projects/{project_id}/members") @PostMapping("/projects/{project_id}/members")
public BaseResponse<Void> addProjectMember( public void addProjectMember(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@Valid @RequestBody final ParticipantRequest participantRequest) { @Valid @RequestBody final ParticipantRequest participantRequest) {
projectService.addProjectMember(memberId, projectId, participantRequest); projectService.addProjectMember(memberId, projectId, participantRequest);
return SuccessResponse.empty();
} }
@Operation(summary = "프로젝트 멤버 권한 수정", description = "프로젝트 멤버 권한을 수정합니다.") @Operation(summary = "프로젝트 멤버 권한 수정", description = "프로젝트 멤버 권한을 수정합니다.")
@SwaggerApiSuccess(description = "프로젝트 멤버 권한을 성공적으로 수정합니다.") @SwaggerApiSuccess(description = "프로젝트 멤버 권한을 성공적으로 수정합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@PutMapping("/projects/{project_id}/members") @PutMapping("/projects/{project_id}/members")
public BaseResponse<Void> changeProjectMember( public void changeProjectMember(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@Valid @RequestBody final ParticipantRequest participantRequest) { @Valid @RequestBody final ParticipantRequest participantRequest) {
projectService.changeProjectMember(memberId, projectId, participantRequest); projectService.changeProjectMember(memberId, projectId, participantRequest);
return SuccessResponse.empty();
} }
@Operation(summary = "프로젝트 멤버 제거", description = "프로젝트 멤버를 제거합니다.") @Operation(summary = "프로젝트 멤버 제거", description = "프로젝트 멤버를 제거합니다.")
@SwaggerApiSuccess(description = "프로젝트 멤버를 성공적으로 제거합니다.") @SwaggerApiSuccess(description = "프로젝트 멤버를 성공적으로 제거합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@DeleteMapping("/projects/{project_id}/members") @DeleteMapping("/projects/{project_id}/members")
public BaseResponse<Void> removeProjectMember( public void removeProjectMember(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("project_id") final Integer projectId, @PathVariable("project_id") final Integer projectId,
@Valid @RequestBody final Integer removeMemberId) { @Valid @RequestBody final Integer removeMemberId) {
projectService.removeProjectMember(memberId, projectId, removeMemberId); projectService.removeProjectMember(memberId, projectId, removeMemberId);
return SuccessResponse.empty();
} }
} }

View File

@ -31,74 +31,68 @@ public class WorkspaceController {
@SwaggerApiSuccess(description = "워크스페이스를 성공적으로 생성합니다.") @SwaggerApiSuccess(description = "워크스페이스를 성공적으로 생성합니다.")
@SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.EMPTY_REQUEST_PARAMETER, ErrorCode.SERVER_ERROR})
@PostMapping @PostMapping
public BaseResponse<WorkspaceResponse> createWorkspace(@CurrentUser final Integer memberId, @Valid @RequestBody final WorkspaceRequest workspaceRequest) { public WorkspaceResponse createWorkspace(@CurrentUser final Integer memberId, @Valid @RequestBody final WorkspaceRequest workspaceRequest) {
WorkspaceResponse workspace = workspaceService.createWorkspace(memberId, workspaceRequest); return workspaceService.createWorkspace(memberId, workspaceRequest);
return SuccessResponse.of(workspace);
} }
@Operation(summary = "특정 워크스페이스 조회", description = "특정 워크스페이스를 조회합니다.") @Operation(summary = "특정 워크스페이스 조회", description = "특정 워크스페이스를 조회합니다.")
@SwaggerApiSuccess(description = "특정 워크스페이스를 성공적으로 조회합니다.") @SwaggerApiSuccess(description = "특정 워크스페이스를 성공적으로 조회합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
@GetMapping("/{workspace_id}") @GetMapping("/{workspace_id}")
public BaseResponse<WorkspaceResponse> getWorkspace(@CurrentUser final Integer memberId, @PathVariable("workspace_id") final Integer workspaceId) { public WorkspaceResponse getWorkspace(@CurrentUser final Integer memberId, @PathVariable("workspace_id") final Integer workspaceId) {
WorkspaceResponse workspace = workspaceService.getWorkspaceById(memberId, workspaceId); return workspaceService.getWorkspaceById(memberId, workspaceId);
return SuccessResponse.of(workspace);
} }
@Operation(summary = "전체 워크스페이스 조회", description = "모든 워크스페이스를 조회합니다.") @Operation(summary = "전체 워크스페이스 조회", description = "모든 워크스페이스를 조회합니다.")
@SwaggerApiSuccess(description = "전체 워크스페이스를 성공적으로 조회합니다.") @SwaggerApiSuccess(description = "전체 워크스페이스를 성공적으로 조회합니다.")
@SwaggerApiError({ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.SERVER_ERROR})
@GetMapping @GetMapping
public BaseResponse<WorkspaceResponses> getAllWorkspaces( public WorkspaceResponses getAllWorkspaces(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@Parameter(name = "마지막 워크스페이스 id", description = "마지막 워크스페이스 id를 넣으면 그 아래 부터 가져옴, 넣지않으면 가장 최신", example = "1") @RequestParam(required = false) Integer lastWorkspaceId, @Parameter(name = "마지막 워크스페이스 id", description = "마지막 워크스페이스 id를 넣으면 그 아래 부터 가져옴, 넣지않으면 가장 최신", example = "1") @RequestParam(required = false) Integer lastWorkspaceId,
@Parameter(name = "가져올 워크스페이스 수", description = "가져올 워크스페이스 수 default = 10", example = "20") @RequestParam(defaultValue = "10") Integer limitPage) { @Parameter(name = "가져올 워크스페이스 수", description = "가져올 워크스페이스 수 default = 10", example = "20") @RequestParam(defaultValue = "10") Integer limitPage) {
List<WorkspaceResponse> workspaces = workspaceService.getAllWorkspaces(memberId, lastWorkspaceId, limitPage); List<WorkspaceResponse> workspaces = workspaceService.getAllWorkspaces(memberId, lastWorkspaceId, limitPage);
return SuccessResponse.of(WorkspaceResponses.from(workspaces)); return WorkspaceResponses.from(workspaces);
} }
@Operation(summary = "워크스페이스 수정", description = "특정 워크스페이스를 수정합니다.") @Operation(summary = "워크스페이스 수정", description = "특정 워크스페이스를 수정합니다.")
@SwaggerApiSuccess(description = "특정 워크스페이스를 성공적으로 수정합니다.") @SwaggerApiSuccess(description = "특정 워크스페이스를 성공적으로 수정합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
@PutMapping("/{workspace_id}") @PutMapping("/{workspace_id}")
public BaseResponse<WorkspaceResponse> updateWorkspace( public WorkspaceResponse updateWorkspace(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("workspace_id") final Integer workspaceId, @PathVariable("workspace_id") final Integer workspaceId,
@Valid @RequestBody final WorkspaceRequest updatedWorkspace ) { @Valid @RequestBody final WorkspaceRequest updatedWorkspace ) {
WorkspaceResponse workspace = workspaceService.updateWorkspace(memberId, workspaceId, updatedWorkspace); return workspaceService.updateWorkspace(memberId, workspaceId, updatedWorkspace);
return SuccessResponse.of(workspace);
} }
@Operation(summary = "워크스페이스 삭제", description = "특정 워크스페이스를 삭제합니다.") @Operation(summary = "워크스페이스 삭제", description = "특정 워크스페이스를 삭제합니다.")
@SwaggerApiSuccess(description = "특정 워크스페이스를 성공적으로 삭제합니다.") @SwaggerApiSuccess(description = "특정 워크스페이스를 성공적으로 삭제합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
@DeleteMapping("/{workspace_id}") @DeleteMapping("/{workspace_id}")
public BaseResponse<Void> deleteWorkspace(@CurrentUser final Integer memberId, @PathVariable("workspace_id") final Integer workspaceId) { public void deleteWorkspace(@CurrentUser final Integer memberId, @PathVariable("workspace_id") final Integer workspaceId) {
workspaceService.deleteWorkspace(memberId, workspaceId); workspaceService.deleteWorkspace(memberId, workspaceId);
return SuccessResponse.empty();
} }
@Operation(summary = "워크스페이스 멤버 추가", description = "특정 워크스페이스에 멤버를 추가합니다.") @Operation(summary = "워크스페이스 멤버 추가", description = "특정 워크스페이스에 멤버를 추가합니다.")
@SwaggerApiSuccess(description = "특정 워크스페이스에 멤버를 성공적으로 추가합니다.") @SwaggerApiSuccess(description = "특정 워크스페이스에 멤버를 성공적으로 추가합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
@PostMapping("/{workspace_id}/members/{member_id}") @PostMapping("/{workspace_id}/members/{member_id}")
public BaseResponse<Void> addWorkspaceMember( public void addWorkspaceMember(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("workspace_id") final Integer workspaceId, @PathVariable("workspace_id") final Integer workspaceId,
@PathVariable("member_id") final Integer newMemberId) { @PathVariable("member_id") final Integer newMemberId) {
workspaceService.addWorkspaceMember(memberId, workspaceId, newMemberId); workspaceService.addWorkspaceMember(memberId, workspaceId, newMemberId);
return SuccessResponse.empty();
} }
@Operation(summary = "워크스페이스 멤버 제거", description = "특정 워크스페이스에 멤버를 제거합니다.") @Operation(summary = "워크스페이스 멤버 제거", description = "특정 워크스페이스에 멤버를 제거합니다.")
@SwaggerApiSuccess(description = "특정 워크스페이스에 멤버를 성공적으로 제거합니다.") @SwaggerApiSuccess(description = "특정 워크스페이스에 멤버를 성공적으로 제거합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR}) @SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
@DeleteMapping("/{workspace_id}/members/{member_id}") @DeleteMapping("/{workspace_id}/members/{member_id}")
public BaseResponse<Void> removeWorkspaceMember( public void removeWorkspaceMember(
@CurrentUser final Integer memberId, @CurrentUser final Integer memberId,
@PathVariable("workspace_id") final Integer workspaceId, @PathVariable("workspace_id") final Integer workspaceId,
@PathVariable("member_id") final Integer newMemberId) { @PathVariable("member_id") final Integer newMemberId) {
workspaceService.removeWorkspaceMember(memberId, workspaceId, newMemberId); workspaceService.removeWorkspaceMember(memberId, workspaceId, newMemberId);
return SuccessResponse.empty();
} }
} }

View File

@ -1,5 +1,6 @@
package com.worlabel.global.advice; package com.worlabel.global.advice;
import com.amazonaws.Response;
import com.worlabel.global.exception.CustomException; import com.worlabel.global.exception.CustomException;
import com.worlabel.global.exception.ErrorCode; import com.worlabel.global.exception.ErrorCode;
import com.worlabel.global.response.ErrorResponse; import com.worlabel.global.response.ErrorResponse;
@ -30,54 +31,30 @@ public class CustomControllerAdvice {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ErrorResponse handleException(Exception e, HttpServletRequest request) { public void handleException(Exception e, HttpServletRequest request) {
log.error("", e);
sendNotification(e, request); sendNotification(e, request);
return ErrorResponse.of(new CustomException(ErrorCode.SERVER_ERROR));
} }
@ExceptionHandler({HttpMessageNotReadableException.class})
public ErrorResponse handleReadableException(Exception e,HttpServletRequest request) {
log.error("",e);
sendNotification(e, request);
return ErrorResponse.of(new CustomException(ErrorCode.BAD_REQUEST));
}
@ExceptionHandler(NoResourceFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND) @ResponseStatus(HttpStatus.NOT_FOUND)
public ErrorResponse handleNoHandlerFoundException(NoResourceFoundException e, HttpServletRequest request) { @ExceptionHandler({NoResourceFoundException.class})
log.error("", e); public void handleNotFountException(NoResourceFoundException e, HttpServletRequest request) {
sendNotification(e, request); sendNotification(e, request);
return ErrorResponse.of(new CustomException(ErrorCode.INVALID_URL));
} }
@ExceptionHandler({MissingServletRequestParameterException.class}) @ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResponse handleRequestParameterException(Exception e, HttpServletRequest request) { @ExceptionHandler({HttpRequestMethodNotSupportedException.class, MissingServletRequestParameterException.class, HttpMessageNotReadableException.class})
log.error("",e); public void handleBadRequestException(Exception e, HttpServletRequest request) {
sendNotification(e, request); sendNotification(e, request);
return ErrorResponse.of(new CustomException(ErrorCode.EMPTY_REQUEST_PARAMETER));
}
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ErrorResponse handleRequestMethodNotSupportedException(Exception e, HttpServletRequest request) {
log.error("", e);
sendNotification(e, request);
return ErrorResponse.of(new CustomException(ErrorCode.BAD_REQUEST, "지원하지 않는 API입니다. 요청을 확인해주세요"));
} }
@ExceptionHandler(CustomException.class) @ExceptionHandler(CustomException.class)
public ResponseEntity<ErrorResponse> handleCustomException(CustomException e, HttpServletRequest request) { public ResponseEntity<Void> handleCustomException(CustomException e, HttpServletRequest request) {
log.error("", e);
sendNotification(e, request); sendNotification(e, request);
return ResponseEntity.status(e.getErrorCode().getStatus()) return ResponseEntity.status(e.getErrorCode().getStatus()).build();
.body(ErrorResponse.of(e));
} }
private void sendNotification(Exception e, HttpServletRequest request) { private void sendNotification(Exception e, HttpServletRequest request) {
// TODO: 필요시 주석 처리 log.error("", e);
notificationManager.sendNotification(e, request.getRequestURI(), getParams(request)); notificationManager.sendNotification(e, request.getRequestURI(), getParams(request));
} }