From a828bd89eaf08c5cb5c3dd98b3107b85e2ff6d9e Mon Sep 17 00:00:00 2001 From: sosow0212 Date: Thu, 30 May 2024 15:42:27 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EA=B0=9C=ED=96=89=20=EC=8A=A4=ED=83=80=EC=9D=BC=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/ui/board/BoardController.java | 18 ++++++-- .../community/ui/board/LikeController.java | 5 +- .../ui/comment/CommentController.java | 36 +++++++++------ .../coupon/ui/coupon/CouponController.java | 22 +++++---- .../coupon/ui/voucher/VoucherController.java | 10 ++-- .../market/ui/chat/ChatRoomController.java | 17 +++---- .../market/ui/product/ProductController.java | 46 +++++++++++-------- .../member/ui/member/MemberController.java | 8 ++-- 8 files changed, 99 insertions(+), 63 deletions(-) diff --git a/market-api/src/main/java/com/server/community/ui/board/BoardController.java b/market-api/src/main/java/com/server/community/ui/board/BoardController.java index 826562d..99968ec 100644 --- a/market-api/src/main/java/com/server/community/ui/board/BoardController.java +++ b/market-api/src/main/java/com/server/community/ui/board/BoardController.java @@ -33,7 +33,10 @@ public class BoardController { private final BoardQueryService boardQueryService; @PostMapping - public ResponseEntity saveBoard(@AuthMember final Long memberId, @ModelAttribute final BoardCreateRequest request) { + public ResponseEntity saveBoard( + @AuthMember final Long memberId, + @ModelAttribute final BoardCreateRequest request + ) { Long boardId = boardService.saveBoard(memberId, request); return ResponseEntity.created(URI.create("/api/boards/" + boardId)) .build(); @@ -56,16 +59,21 @@ public ResponseEntity findBoardById( } @PatchMapping("/{id}") - public ResponseEntity patchBoardById(@PathVariable("id") final Long boardId, - @AuthMember final Long memberId, - @ModelAttribute final BoardUpdateRequest request) { + public ResponseEntity patchBoardById( + @PathVariable("id") final Long boardId, + @AuthMember final Long memberId, + @ModelAttribute final BoardUpdateRequest request + ) { boardService.patchBoardById(boardId, memberId, request); return ResponseEntity.ok() .build(); } @DeleteMapping("/{id}") - public ResponseEntity deleteBoardById(@AuthMember final Long memberId, @PathVariable("id") final Long boardId) { + public ResponseEntity deleteBoardById( + @AuthMember final Long memberId, + @PathVariable("id") final Long boardId + ) { boardService.deleteBoardById(boardId, memberId); return ResponseEntity.noContent() .build(); diff --git a/market-api/src/main/java/com/server/community/ui/board/LikeController.java b/market-api/src/main/java/com/server/community/ui/board/LikeController.java index c189966..f1b6369 100644 --- a/market-api/src/main/java/com/server/community/ui/board/LikeController.java +++ b/market-api/src/main/java/com/server/community/ui/board/LikeController.java @@ -18,7 +18,10 @@ public class LikeController { private final LikeService likeService; @PatchMapping("/{boardId}/likes") - public ResponseEntity patchLike(@AuthMember final Long memberId, @PathVariable("boardId") final Long boardId) { + public ResponseEntity patchLike( + @AuthMember final Long memberId, + @PathVariable("boardId") final Long boardId + ) { boolean likeStatus = likeService.patchLike(boardId, memberId); return ResponseEntity.ok(new LikeResultResponse(boardId, likeStatus)); } diff --git a/market-api/src/main/java/com/server/community/ui/comment/CommentController.java b/market-api/src/main/java/com/server/community/ui/comment/CommentController.java index b5d25a6..2f98a0d 100644 --- a/market-api/src/main/java/com/server/community/ui/comment/CommentController.java +++ b/market-api/src/main/java/com/server/community/ui/comment/CommentController.java @@ -31,37 +31,45 @@ public class CommentController { private final CommentQueryService commentQueryService; @PostMapping("/{boardId}/comments") - public ResponseEntity createComment(@AuthMember final Long memberId, - @PathVariable("boardId") final Long boardId, - @Valid @RequestBody final CommentCreateRequest request) { + public ResponseEntity createComment( + @AuthMember final Long memberId, + @PathVariable("boardId") final Long boardId, + @Valid @RequestBody final CommentCreateRequest request + ) { commentService.createComment(memberId, boardId, request); return ResponseEntity.status(HttpStatus.CREATED) .build(); } @GetMapping("/{boardId}/comments") - public ResponseEntity> findAllCommentsByBoardId(@PathVariable("boardId") final Long boardId, - @RequestParam(name = "commentId", required = false) final Long commentId, - @AuthMember final Long memberId, - @RequestParam(name = "pageSize") final Integer pageSize) { + public ResponseEntity> findAllCommentsByBoardId( + @PathVariable("boardId") final Long boardId, + @RequestParam(name = "commentId", required = false) final Long commentId, + @AuthMember final Long memberId, + @RequestParam(name = "pageSize") final Integer pageSize + ) { List comments = commentQueryService.findAllCommentsByBoardId(boardId, memberId, commentId, pageSize); return ResponseEntity.ok(comments); } @PatchMapping("/{boardId}/comments/{commentId}") - public ResponseEntity patchComment(@PathVariable("boardId") final Long boardId, - @PathVariable("commentId") final Long commentId, - @AuthMember final Long memberId, - @Valid @RequestBody final CommentPatchRequest request) { + public ResponseEntity patchComment( + @PathVariable("boardId") final Long boardId, + @PathVariable("commentId") final Long commentId, + @AuthMember final Long memberId, + @Valid @RequestBody final CommentPatchRequest request + ) { commentService.patchCommentById(memberId, commentId, request); return ResponseEntity.ok() .build(); } @DeleteMapping("/{boardId}/comments/{commentId}") - public ResponseEntity deleteComment(@PathVariable("boardId") final Long boardId, - @PathVariable("commentId") final Long commentId, - @AuthMember final Long memberId) { + public ResponseEntity deleteComment( + @PathVariable("boardId") final Long boardId, + @PathVariable("commentId") final Long commentId, + @AuthMember final Long memberId + ) { commentService.deleteCommentById(memberId, commentId); return ResponseEntity.noContent() .build(); diff --git a/market-api/src/main/java/com/server/coupon/ui/coupon/CouponController.java b/market-api/src/main/java/com/server/coupon/ui/coupon/CouponController.java index 3d8dfe0..c5db3d2 100644 --- a/market-api/src/main/java/com/server/coupon/ui/coupon/CouponController.java +++ b/market-api/src/main/java/com/server/coupon/ui/coupon/CouponController.java @@ -35,27 +35,29 @@ public ResponseEntity createCoupon(@RequestBody final CouponCreateRequest } @GetMapping("/members/{memberId}/coupons") - public ResponseEntity findAllMemberCoupons(@PathVariable("memberId") final Long memberId, - @AuthMember final Long authId) { + public ResponseEntity findAllMemberCoupons( + @PathVariable("memberId") final Long memberId, + @AuthMember final Long authId + ) { Coupons memberCoupons = couponService.findAllMemberCoupons(memberId, authId); return ResponseEntity.ok(CouponsResponse.from(memberId, memberCoupons)); } - // TODO: - // Member에게 쿠폰을 주는 것 (API or Event) -> 관리자의 역할 - // Member가 사용한 쿠폰을 제거하는 것 (API or Event) - // /members/{memberId}/coupons @PostMapping("/members/{memberId}/coupons") - public ResponseEntity saveMemberCoupon(@PathVariable("memberId") final Long memberId, - @RequestBody final MemberCouponCreateRequest request) { + public ResponseEntity saveMemberCoupon( + @PathVariable("memberId") final Long memberId, + @RequestBody final MemberCouponCreateRequest request + ) { couponService.saveMemberCoupons(memberId, request); return ResponseEntity.ok() .build(); } @GetMapping("/coupons") - public ResponseEntity applyCoupons(@RequestParam(value = "couponIds") final List couponIds, - @RequestParam(value = "price") final Integer price) { + public ResponseEntity applyCoupons( + @RequestParam(value = "couponIds") final List couponIds, + @RequestParam(value = "price") final Integer price + ) { int discountPrice = couponService.applyCoupons(price, couponIds); return ResponseEntity.ok(new ApplyCouponResponse(price, discountPrice, couponIds)); } diff --git a/market-api/src/main/java/com/server/coupon/ui/voucher/VoucherController.java b/market-api/src/main/java/com/server/coupon/ui/voucher/VoucherController.java index 2c05819..f9d888a 100644 --- a/market-api/src/main/java/com/server/coupon/ui/voucher/VoucherController.java +++ b/market-api/src/main/java/com/server/coupon/ui/voucher/VoucherController.java @@ -41,16 +41,18 @@ public ResponseEntity createPrivateVoucher(@RequestBody final VoucherCreat } @PostMapping("/vouchers/{voucherId}") - public ResponseEntity useVoucher(@AuthMember Long memberId, - @PathVariable final Long voucherId, - @RequestBody final VoucherNumberRequest request) { + public ResponseEntity useVoucher( + @AuthMember final Long memberId, + @PathVariable final Long voucherId, + @RequestBody final VoucherNumberRequest request + ) { voucherService.useVoucher(voucherId, request, memberId); return ResponseEntity.ok() .build(); } @GetMapping("/vouchers") - public ResponseEntity findVoucherWithPaging(@PageableDefault(sort = "id", direction = DESC) Pageable pageable) { + public ResponseEntity findVoucherWithPaging(@PageableDefault(sort = "id", direction = DESC) final Pageable pageable) { Page result = voucherQueryService.findAllWithPaging(pageable); return ResponseEntity.ok(VoucherPageResponse.of(result, pageable)); } diff --git a/market-api/src/main/java/com/server/market/ui/chat/ChatRoomController.java b/market-api/src/main/java/com/server/market/ui/chat/ChatRoomController.java index 9fbaeb4..8dfc1e3 100644 --- a/market-api/src/main/java/com/server/market/ui/chat/ChatRoomController.java +++ b/market-api/src/main/java/com/server/market/ui/chat/ChatRoomController.java @@ -35,13 +35,11 @@ public class ChatRoomController { private final ChatRoomService chatRoomService; private final SimpMessagingTemplate messagingTemplate; - // 내가 채팅중인 모든 채팅방 반환 @GetMapping("/api/chats") - public ResponseEntity> findAllMyChats(@AuthMember final Long authId) { + public ResponseEntity> findAllMyChattingRooms(@AuthMember final Long authId) { return ResponseEntity.ok(chatRoomQueryService.findAllMyChats(authId)); } - // 소비자가 채팅 요청 (채팅방 생성) @PostMapping("/api/products/{productId}/chats") public ResponseEntity createChattingRoomByBuyer( @PathVariable final Long productId, @@ -53,9 +51,8 @@ public ResponseEntity createChattingRoomByBuyer( .body(ChattingRoomResponse.from(chattingRoom)); } - // 채팅방 채팅 내역 반환 @GetMapping("/api/products/{productId}/chats/{chattingRoomId}") - public ResponseEntity> findChattingHistoryByChatId( + public ResponseEntity> findChatHistoryByChattingRoomId( @AuthMember final Long authId, @PathVariable final Long productId, @PathVariable final Long chattingRoomId, @@ -65,9 +62,13 @@ public ResponseEntity> findChattingHistoryByChatId( return ResponseEntity.ok(chatRoomQueryService.findChattingHistoryByChatId(authId, chattingRoomId, chatId, pageSize)); } - // linking url : ws://localhost:8080/ws-stomp - // subscribe url : ws://localhost:8080/ws-stomp/sub/chats/1 - // publish url : ws://localhost:8080/ws-stomp/pub/chats/1/messages + /** + * Ver1. 단일 서버에서만 작동 가능한 웹 소켓 채팅 + * Date 24.05.30 + * linking url : ws://localhost:8080/ws-stomp + * subscribe url : ws://localhost:8080/ws-stomp/sub/chats/1 + * publish url : ws://localhost:8080/ws-stomp/pub/chats/1/messages + */ @MessageMapping("/chats/{chatRoomId}/messages") public ChatMessageResponse chat( @DestinationVariable final Long chatRoomId, diff --git a/market-api/src/main/java/com/server/market/ui/product/ProductController.java b/market-api/src/main/java/com/server/market/ui/product/ProductController.java index 8d414f3..5fd803a 100644 --- a/market-api/src/main/java/com/server/market/ui/product/ProductController.java +++ b/market-api/src/main/java/com/server/market/ui/product/ProductController.java @@ -43,28 +43,34 @@ public ResponseEntity> findAllProductsInCatego } @PostMapping("/{categoryId}/products") - public ResponseEntity uploadProduct(@PathVariable("categoryId") final Long categoryId, - @AuthMember final Long memberId, - @Valid @RequestBody final ProductCreateRequest request) { + public ResponseEntity uploadProduct( + @PathVariable("categoryId") final Long categoryId, + @AuthMember final Long memberId, + @Valid @RequestBody final ProductCreateRequest request + ) { Long savedProductId = productService.uploadProduct(memberId, categoryId, request); return ResponseEntity.created(URI.create("/api/categories/" + categoryId + "/products/" + savedProductId)) .build(); } @GetMapping("/{categoryId}/products/{productId}") - public ResponseEntity findProductById(@PathVariable("productId") final Long productId, - @PathVariable("categoryId") final Long categoryId, - @AuthMember final Long memberId, - @ViewCountChecker final Boolean canAddViewCount) { + public ResponseEntity findProductById( + @PathVariable("productId") final Long productId, + @PathVariable("categoryId") final Long categoryId, + @AuthMember final Long memberId, + @ViewCountChecker final Boolean canAddViewCount + ) { productService.addViewCount(productId, canAddViewCount); return ResponseEntity.ok(productQueryService.findById(productId, memberId)); } @PatchMapping("/{categoryId}/products/{productId}") - public ResponseEntity updateProduct(@PathVariable("productId") final Long productId, - @PathVariable("categoryId") final Long categoryId, - @AuthMember final Long memberId, - @Valid @RequestBody final ProductUpdateRequest request) { + public ResponseEntity updateProduct( + @PathVariable("productId") final Long productId, + @PathVariable("categoryId") final Long categoryId, + @AuthMember final Long memberId, + @Valid @RequestBody final ProductUpdateRequest request + ) { productService.update(productId, memberId, request); return ResponseEntity.ok() .build(); @@ -89,19 +95,23 @@ public ResponseEntity likesProduct( } @DeleteMapping("/{categoryId}/products/{productId}") - public ResponseEntity deleteProduct(@PathVariable("productId") final Long productId, - @PathVariable("categoryId") final Long categoryId, - @AuthMember final Long memberId) { + public ResponseEntity deleteProduct( + @PathVariable("productId") final Long productId, + @PathVariable("categoryId") final Long categoryId, + @AuthMember final Long memberId + ) { productService.delete(productId, memberId); return ResponseEntity.noContent() .build(); } @PostMapping("/{categoryId}/products/{productId}") - public ResponseEntity buyProducts(@PathVariable("productId") final Long productId, - @PathVariable("categoryId") final Long categoryId, - @AuthMember final Long memberId, - @RequestBody final UsingCouponRequest usingCouponRequest) { + public ResponseEntity buyProducts( + @PathVariable("productId") final Long productId, + @PathVariable("categoryId") final Long categoryId, + @AuthMember final Long memberId, + @RequestBody final UsingCouponRequest usingCouponRequest + ) { productService.buyProducts(productId, memberId, usingCouponRequest); return ResponseEntity.ok().build(); } diff --git a/market-api/src/main/java/com/server/member/ui/member/MemberController.java b/market-api/src/main/java/com/server/member/ui/member/MemberController.java index 5e7a63a..e3b3c2c 100644 --- a/market-api/src/main/java/com/server/member/ui/member/MemberController.java +++ b/market-api/src/main/java/com/server/member/ui/member/MemberController.java @@ -21,9 +21,11 @@ public class MemberController { private final MemberService memberService; @GetMapping("/{memberId}/histories") - public ResponseEntity> findTradeHistories(@PathVariable("memberId") final Long memberId, - @AuthMember final Long authId, - @RequestParam(value = "isSeller") final boolean isSeller) { + public ResponseEntity> findTradeHistories( + @PathVariable("memberId") final Long memberId, + @AuthMember final Long authId, + @RequestParam(value = "isSeller") final boolean isSeller + ) { List response = memberService.findTradeHistories(memberId, authId, isSeller); return ResponseEntity.ok(response); }