Skip to content

Commit

Permalink
Merge pull request #63 from Leets-Official/Refactor-#62-api-응답-형식-변경-…
Browse files Browse the repository at this point in the history
…및-커런트-유저-관련-수정

Refactor #62 api 응답 형식 변경,  @parameter(hidden = true) 추가
  • Loading branch information
huncozyboy authored Oct 26, 2024
2 parents 81b4e9e + 2a45216 commit d8cac32
Show file tree
Hide file tree
Showing 30 changed files with 289 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package leets.weeth.domain.account.presentation;

import static leets.weeth.domain.account.presentation.ResponseMessage.ACCOUNT_SAVE_SUCCESS;

import jakarta.validation.Valid;
import leets.weeth.domain.account.application.dto.AccountDTO;
import leets.weeth.domain.account.application.usecase.AccountUseCase;
Expand All @@ -20,6 +22,6 @@ public class AccountAdminController {
@PostMapping
public CommonResponse<Void> save(@RequestBody @Valid AccountDTO.Save dto) {
accountUseCase.save(dto);
return CommonResponse.createSuccess();
return CommonResponse.createSuccess(ACCOUNT_SAVE_SUCCESS.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package leets.weeth.domain.account.presentation;

import static leets.weeth.domain.account.presentation.ResponseMessage.ACCOUNT_FIND_SUCCESS;

import leets.weeth.domain.account.application.dto.AccountDTO;
import leets.weeth.domain.account.application.usecase.AccountUseCase;
import leets.weeth.global.common.response.CommonResponse;
Expand All @@ -18,6 +20,6 @@ public class AccountController {

@GetMapping("/{cardinal}")
public CommonResponse<AccountDTO.Response> find(@PathVariable Integer cardinal) {
return CommonResponse.createSuccess(accountUseCase.find(cardinal));
return CommonResponse.createSuccess(ACCOUNT_FIND_SUCCESS.getMessage(),accountUseCase.find(cardinal));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package leets.weeth.domain.account.presentation;

import static leets.weeth.domain.account.presentation.ResponseMessage.RECEIPT_DELETE_SUCCESS;
import static leets.weeth.domain.account.presentation.ResponseMessage.RECEIPT_SAVE_SUCCESS;

import jakarta.validation.Valid;
import leets.weeth.domain.account.application.dto.ReceiptDTO;
import leets.weeth.domain.account.application.usecase.ReceiptUseCase;
Expand All @@ -21,12 +24,12 @@ public class ReceiptAdminController {
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public CommonResponse<Void> save(@RequestPart @Valid ReceiptDTO.Save dto, @RequestPart(required = false) List<MultipartFile> images) {
receiptUseCase.save(dto, images);
return CommonResponse.createSuccess();
return CommonResponse.createSuccess(RECEIPT_SAVE_SUCCESS.getMessage());
}

@DeleteMapping("/{receiptId}")
public CommonResponse<Void> delete(@PathVariable Long receiptId) {
receiptUseCase.delete(receiptId);
return CommonResponse.createSuccess();
return CommonResponse.createSuccess(RECEIPT_DELETE_SUCCESS.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package leets.weeth.domain.account.presentation;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ResponseMessage {
// AccountAdminController 관련
ACCOUNT_SAVE_SUCCESS("회비가 성공적으로 저장되었습니다."),

// AccountController 관련
ACCOUNT_FIND_SUCCESS("회비가 성공적으로 조회되었습니다."),

// ReceiptAdminController 관련
RECEIPT_SAVE_SUCCESS("영수증이 성공적으로 저장되었습니다."),
RECEIPT_DELETE_SUCCESS("영수증이 성공적으로 삭제되었습니다.");

private final String message;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package leets.weeth.domain.attendance.presentation;

import static leets.weeth.domain.attendance.presentation.ResponseMessage.ATTENDANCE_CLOSE_SUCCESS;

import leets.weeth.domain.attendance.application.usecase.AttendanceUseCase;
import leets.weeth.global.common.response.CommonResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,6 +22,6 @@ public class AttendanceAdminController {
@PatchMapping
public CommonResponse<Void> close(@RequestParam LocalDate now, @RequestParam Integer cardinal) {
attendanceUseCase.close(now, cardinal);
return CommonResponse.createSuccess();
return CommonResponse.createSuccess(ATTENDANCE_CLOSE_SUCCESS.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package leets.weeth.domain.attendance.presentation;

import io.swagger.v3.oas.annotations.Parameter;
import leets.weeth.domain.attendance.application.dto.AttendanceDTO;
import leets.weeth.domain.attendance.application.usecase.AttendanceUseCase;
import leets.weeth.global.auth.annotation.CurrentUser;
Expand All @@ -9,6 +10,9 @@
import org.springframework.web.bind.annotation.*;

import static leets.weeth.domain.attendance.application.dto.AttendanceDTO.*;
import static leets.weeth.domain.attendance.presentation.ResponseMessage.ATTENDANCE_CHECKIN_SUCCESS;
import static leets.weeth.domain.attendance.presentation.ResponseMessage.ATTENDANCE_FIND_ALL_SUCCESS;
import static leets.weeth.domain.attendance.presentation.ResponseMessage.ATTENDANCE_FIND_SUCCESS;

@RestController
@RequiredArgsConstructor
Expand All @@ -18,18 +22,18 @@ public class AttendanceController {
private final AttendanceUseCase attendanceUseCase;

@PatchMapping
public CommonResponse<Void> checkIn(@CurrentUser Long userId, @RequestBody AttendanceDTO.CheckIn checkIn) throws AttendanceCodeMismatchException {
public CommonResponse<Void> checkIn(@Parameter(hidden = true) @CurrentUser Long userId, @RequestBody AttendanceDTO.CheckIn checkIn) throws AttendanceCodeMismatchException {
attendanceUseCase.checkIn(userId, checkIn.code());
return CommonResponse.createSuccess();
return CommonResponse.createSuccess(ATTENDANCE_CHECKIN_SUCCESS.getMessage());
}

@GetMapping
public CommonResponse<Main> find(@CurrentUser Long userId) {
return CommonResponse.createSuccess(attendanceUseCase.find(userId));
public CommonResponse<Main> find(@Parameter(hidden = true) @CurrentUser Long userId) {
return CommonResponse.createSuccess(ATTENDANCE_FIND_SUCCESS.getMessage(), attendanceUseCase.find(userId));
}

@GetMapping("/detail")
public CommonResponse<Detail> findAll(@CurrentUser Long userId) {
return CommonResponse.createSuccess(attendanceUseCase.findAll(userId));
public CommonResponse<Detail> findAll(@Parameter(hidden = true) @CurrentUser Long userId) {
return CommonResponse.createSuccess(ATTENDANCE_FIND_ALL_SUCCESS.getMessage(), attendanceUseCase.findAll(userId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package leets.weeth.domain.attendance.presentation;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ResponseMessage {
//AttendanceAdminController 관련
ATTENDANCE_CLOSE_SUCCESS("출석이 성공적으로 마감되었습니다."),

//AttendanceController 관련
ATTENDANCE_CHECKIN_SUCCESS("출석이 성공적으로 처리되었습니다."),
ATTENDANCE_FIND_SUCCESS("사용자의 출석 정보가 성공적으로 조회되었습니다."),
ATTENDANCE_FIND_ALL_SUCCESS("사용자의 상세 출석 정보가 성공적으로 조회되었습니다.");

private final String message;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import java.util.List;

import static leets.weeth.domain.board.domain.entity.enums.ResponseMessage.*;
import static leets.weeth.domain.board.presentation.ResponseMessage.*;

@RestController
@RequiredArgsConstructor
Expand All @@ -35,13 +35,13 @@ public CommonResponse<String> save(@RequestPart @Valid NoticeDTO.Save dto,
public CommonResponse<String> update(@PathVariable Long noticeId,
@RequestPart @Valid NoticeDTO.Update dto,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
@CurrentUser Long userId) throws UserNotMatchException {
@Parameter(hidden = true) @CurrentUser Long userId) throws UserNotMatchException {
noticeUsecase.update(noticeId, dto, files, userId);
return CommonResponse.createSuccess(NOTICE_UPDATED_SUCCESS.getMessage());
}

@DeleteMapping("/{noticeId}")
public CommonResponse<String> delete(@PathVariable Long noticeId, @CurrentUser Long userId) throws UserNotMatchException {
public CommonResponse<String> delete(@PathVariable Long noticeId, @Parameter(hidden = true) @CurrentUser Long userId) throws UserNotMatchException {
noticeUsecase.delete(noticeId, userId);
return CommonResponse.createSuccess(NOTICE_DELETED_SUCCESS.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package leets.weeth.domain.board.presentation;


import static leets.weeth.domain.board.presentation.ResponseMessage.NOTICE_FIND_ALL_SUCCESS;
import static leets.weeth.domain.board.presentation.ResponseMessage.NOTICE_FIND_BY_ID_SUCCESS;

import leets.weeth.domain.board.application.dto.NoticeDTO;
import leets.weeth.domain.board.application.usecase.NoticeUsecase;
import leets.weeth.global.common.response.CommonResponse;
Expand All @@ -18,11 +21,11 @@ public class NoticeController {

@GetMapping
public CommonResponse<List<NoticeDTO.ResponseAll>> findNotices(@RequestParam(required = false) Long noticeId, @RequestParam Integer count) {
return CommonResponse.createSuccess(noticeUsecase.findNotices(noticeId, count));
return CommonResponse.createSuccess(NOTICE_FIND_ALL_SUCCESS.getMessage(), noticeUsecase.findNotices(noticeId, count));
}

@GetMapping("/{noticeId}")
public CommonResponse<NoticeDTO.Response> findNoticeById(@PathVariable Long noticeId) {
return CommonResponse.createSuccess(noticeUsecase.findNotice(noticeId));
return CommonResponse.createSuccess(NOTICE_FIND_BY_ID_SUCCESS.getMessage(), noticeUsecase.findNotice(noticeId));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package leets.weeth.domain.board.presentation;

import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import leets.weeth.domain.board.application.dto.PostDTO;
import leets.weeth.domain.board.application.usecase.PostUsecase;
Expand All @@ -13,7 +14,7 @@

import java.util.List;

import static leets.weeth.domain.board.domain.entity.enums.ResponseMessage.*;
import static leets.weeth.domain.board.presentation.ResponseMessage.*;

@RestController
@RequiredArgsConstructor
Expand All @@ -25,32 +26,32 @@ public class PostController {
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public CommonResponse<String> save(@RequestPart @Valid PostDTO.Save dto,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
@CurrentUser Long userId) {
@Parameter(hidden = true) @CurrentUser Long userId) {
postUsecase.save(dto, files, userId);
return CommonResponse.createSuccess(POST_CREATED_SUCCESS.getMessage());
}

@GetMapping
public CommonResponse<List<PostDTO.ResponseAll>> findPosts(@RequestParam(required = false) Long postId, @RequestParam Integer count) {
return CommonResponse.createSuccess(postUsecase.findPosts(postId, count));
return CommonResponse.createSuccess(POST_FIND_ALL_SUCCESS.getMessage(), postUsecase.findPosts(postId, count));
}

@GetMapping("/{postId}")
public CommonResponse<PostDTO.Response> findPost(@PathVariable Long postId) {
return CommonResponse.createSuccess(postUsecase.findPost(postId));
return CommonResponse.createSuccess(POST_FIND_BY_ID_SUCCESS.getMessage(),postUsecase.findPost(postId));
}

@PatchMapping(value = "/{postId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public CommonResponse<String> update(@PathVariable Long postId,
@RequestPart @Valid PostDTO.Update dto,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
@CurrentUser Long userId) throws UserNotMatchException {
@Parameter(hidden = true) @CurrentUser Long userId) throws UserNotMatchException {
postUsecase.update(postId, dto, files, userId);
return CommonResponse.createSuccess(POST_UPDATED_SUCCESS.getMessage());
}

@DeleteMapping("/{postId}")
public CommonResponse<String> delete(@PathVariable Long postId, @CurrentUser Long userId) throws UserNotMatchException {
public CommonResponse<String> delete(@PathVariable Long postId, @Parameter(hidden = true) @CurrentUser Long userId) throws UserNotMatchException {
postUsecase.delete(postId, userId);
return CommonResponse.createSuccess(POST_DELETED_SUCCESS.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package leets.weeth.domain.board.presentation;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ResponseMessage {
//NoticeAdminController 관련
NOTICE_CREATED_SUCCESS("공지사항이 성공적으로 생성되었습니다."),
NOTICE_UPDATED_SUCCESS("공지사항이 성공적으로 수정되었습니다."),
NOTICE_DELETED_SUCCESS("공지사항이 성공적으로 삭제되었습니다."),
//NoticeController 관련
NOTICE_FIND_ALL_SUCCESS("공지사항 목록이 성공적으로 조회되었습니다."),
NOTICE_FIND_BY_ID_SUCCESS("공지사항이 성공적으로 조회되었습니다."),
//PostController 관련
POST_CREATED_SUCCESS("게시글이 성공적으로 생성되었습니다."),
POST_UPDATED_SUCCESS("게시글이 성공적으로 수정되었습니다."),
POST_DELETED_SUCCESS("게시글이 성공적으로 삭제되었습니다."),
POST_FIND_ALL_SUCCESS("게시글 목록이 성공적으로 조회되었습니다."),
POST_FIND_BY_ID_SUCCESS("게시글이 성공적으로 조회되었습니다.");

private final String message;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package leets.weeth.domain.comment.presentation;

import static leets.weeth.domain.comment.presentation.ResponseMessage.COMMENT_CREATED_SUCCESS;
import static leets.weeth.domain.comment.presentation.ResponseMessage.COMMENT_DELETED_SUCCESS;
import static leets.weeth.domain.comment.presentation.ResponseMessage.COMMENT_UPDATED_SUCCESS;

import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.Valid;
import leets.weeth.domain.comment.application.dto.CommentDTO;
import leets.weeth.domain.comment.application.usecase.NoticeCommentUsecase;
Expand All @@ -9,7 +14,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import static leets.weeth.domain.comment.domain.entity.enums.ResponseMessage.*;

@RestController
@RequiredArgsConstructor
Expand All @@ -19,19 +23,22 @@ public class NoticeCommentController {
private final NoticeCommentUsecase noticeCommentUsecase;

@PostMapping
public CommonResponse<String> saveNoticeComment(@RequestBody @Valid CommentDTO.Save dto, @PathVariable Long noticeId, @CurrentUser Long userId) {
public CommonResponse<String> saveNoticeComment(@RequestBody @Valid CommentDTO.Save dto, @PathVariable Long noticeId,
@Parameter(hidden = true) @CurrentUser Long userId) {
noticeCommentUsecase.saveNoticeComment(dto, noticeId, userId);
return CommonResponse.createSuccess(COMMENT_CREATED_SUCCESS.getMessage());
}

@PatchMapping("{commentId}")
public CommonResponse<String> updateNoticeComment(@RequestBody @Valid CommentDTO.Update dto, @PathVariable Long noticeId, @PathVariable Long commentId, @CurrentUser Long userId) throws UserNotMatchException {
public CommonResponse<String> updateNoticeComment(@RequestBody @Valid CommentDTO.Update dto, @PathVariable Long noticeId,
@PathVariable Long commentId,@Parameter(hidden = true) @CurrentUser Long userId) throws UserNotMatchException {
noticeCommentUsecase.updateNoticeComment(dto, noticeId, commentId, userId);
return CommonResponse.createSuccess(COMMENT_UPDATED_SUCCESS.getMessage());
}

@DeleteMapping("{commentId}")
public CommonResponse<String> deleteNoticeComment(@PathVariable Long commentId, @CurrentUser Long userId) throws UserNotMatchException {
public CommonResponse<String> deleteNoticeComment(@PathVariable Long commentId,
@Parameter(hidden = true) @CurrentUser Long userId) throws UserNotMatchException {
noticeCommentUsecase.deleteNoticeComment(commentId, userId);
return CommonResponse.createSuccess(COMMENT_DELETED_SUCCESS.getMessage());
}
Expand Down
Loading

0 comments on commit d8cac32

Please sign in to comment.