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

View File

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

View File

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

View File

@ -33,79 +33,66 @@ public class ImageController {
@SwaggerApiSuccess(description = "이미지 목록을 성공적으로 업로드합니다.")
@Operation(summary = "이미지 목록 업로드", description = "이미지 목록을 업로드합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
public BaseResponse<Void> uploadImage(
public void uploadImage(
@CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId,
@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());
imageService.uploadImageList(imageList, folderId, projectId, memberId);
return SuccessResponse.empty();
}
@GetMapping("/{image_id}")
@SwaggerApiSuccess(description = "이미지를 조회합니다.")
@Operation(summary = "이미지 조회", description = "이미지 정보를 조회합니다.")
@SwaggerApiError({ErrorCode.BAD_REQUEST, ErrorCode.NOT_AUTHOR, ErrorCode.SERVER_ERROR})
public BaseResponse<ImageResponse> getImageById(
public ImageResponse getImageById(
@CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId,
@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);
ImageResponse imageResponse = imageService.getImageById(projectId, folderId, imageId, memberId);
return SuccessResponse.of(imageResponse);
return imageService.getImageById(projectId, folderId, imageId, memberId);
}
@PutMapping("/{image_id}")
@SwaggerApiSuccess(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})
public BaseResponse<Void> moveFolderImage(
public void moveFolderImage(
@CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId,
@PathVariable("project_id") final Integer projectId,
@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());
imageService.moveFolder(projectId, folderId, imageMoveRequest.getMoveFolderId(), imageId, memberId);
return SuccessResponse.empty();
}
@DeleteMapping("/{image_id}")
@SwaggerApiSuccess(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})
public BaseResponse<Void> deleteImage(
public void deleteImage(
@CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId,
@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);
imageService.deleteImage(projectId, folderId, imageId, memberId);
return SuccessResponse.empty();
}
@PutMapping("/{image_id}/status")
@SwaggerApiSuccess(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})
public BaseResponse<ImageResponse> changeImageStatus(
public ImageResponse changeImageStatus(
@CurrentUser final Integer memberId,
@PathVariable("folder_id") final Integer folderId,
@PathVariable("project_id") final Integer projectId,
@PathVariable("image_id") final Long imageId,
@RequestBody final ImageStatusRequest imageStatusRequest
) {
@RequestBody final ImageStatusRequest imageStatusRequest) {
log.debug("project: {} , folder: {}, 수정하려는 이미지: {}, 현재 로그인 중인 사용자 : {}", projectId, folderId, imageId, memberId);
ImageResponse imageResponse = imageService.changeImageStatus(projectId, folderId, imageId, memberId, imageStatusRequest);
return SuccessResponse.of(imageResponse);
return imageService.changeImageStatus(projectId, folderId, imageId, memberId, imageStatusRequest);
}
}

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.SwaggerApiSuccess;
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.tags.Tag;
import lombok.RequiredArgsConstructor;

View File

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

View File

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

View File

@ -1,5 +1,6 @@
package com.worlabel.global.advice;
import com.amazonaws.Response;
import com.worlabel.global.exception.CustomException;
import com.worlabel.global.exception.ErrorCode;
import com.worlabel.global.response.ErrorResponse;
@ -30,55 +31,31 @@ public class CustomControllerAdvice {
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ErrorResponse handleException(Exception e, HttpServletRequest request) {
log.error("", e);
public void handleException(Exception e, HttpServletRequest 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)
public ErrorResponse handleNoHandlerFoundException(NoResourceFoundException e, HttpServletRequest request) {
log.error("", e);
@ExceptionHandler({NoResourceFoundException.class})
public void handleNotFountException(NoResourceFoundException e, HttpServletRequest request) {
sendNotification(e, request);
return ErrorResponse.of(new CustomException(ErrorCode.INVALID_URL));
}
@ExceptionHandler({MissingServletRequestParameterException.class})
public ErrorResponse handleRequestParameterException(Exception e, HttpServletRequest request) {
log.error("",e);
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler({HttpRequestMethodNotSupportedException.class, MissingServletRequestParameterException.class, HttpMessageNotReadableException.class})
public void handleBadRequestException(Exception e, HttpServletRequest 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)
public ResponseEntity<ErrorResponse> handleCustomException(CustomException e, HttpServletRequest request) {
log.error("", e);
public ResponseEntity<Void> handleCustomException(CustomException e, HttpServletRequest request) {
sendNotification(e, request);
return ResponseEntity.status(e.getErrorCode().getStatus())
.body(ErrorResponse.of(e));
return ResponseEntity.status(e.getErrorCode().getStatus()).build();
}
private void sendNotification(Exception e, HttpServletRequest request) {
// TODO: 필요시 주석 처리
notificationManager.sendNotification(e, request.getRequestURI(),getParams(request));
log.error("", e);
notificationManager.sendNotification(e, request.getRequestURI(), getParams(request));
}
private String getParams(HttpServletRequest req) {