Skip to content

Commit

Permalink
refactor: 컨트롤러 개행 스타일 통일
Browse files Browse the repository at this point in the history
  • Loading branch information
sosow0212 committed May 30, 2024
1 parent 0e3f692 commit a828bd8
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public class BoardController {
private final BoardQueryService boardQueryService;

@PostMapping
public ResponseEntity<Void> saveBoard(@AuthMember final Long memberId, @ModelAttribute final BoardCreateRequest request) {
public ResponseEntity<Void> saveBoard(
@AuthMember final Long memberId,
@ModelAttribute final BoardCreateRequest request
) {
Long boardId = boardService.saveBoard(memberId, request);
return ResponseEntity.created(URI.create("/api/boards/" + boardId))
.build();
Expand All @@ -56,16 +59,21 @@ public ResponseEntity<BoardFoundResponse> findBoardById(
}

@PatchMapping("/{id}")
public ResponseEntity<Void> patchBoardById(@PathVariable("id") final Long boardId,
@AuthMember final Long memberId,
@ModelAttribute final BoardUpdateRequest request) {
public ResponseEntity<Void> 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<Void> deleteBoardById(@AuthMember final Long memberId, @PathVariable("id") final Long boardId) {
public ResponseEntity<Void> deleteBoardById(
@AuthMember final Long memberId,
@PathVariable("id") final Long boardId
) {
boardService.deleteBoardById(boardId, memberId);
return ResponseEntity.noContent()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public class LikeController {
private final LikeService likeService;

@PatchMapping("/{boardId}/likes")
public ResponseEntity<LikeResultResponse> patchLike(@AuthMember final Long memberId, @PathVariable("boardId") final Long boardId) {
public ResponseEntity<LikeResultResponse> patchLike(
@AuthMember final Long memberId,
@PathVariable("boardId") final Long boardId
) {
boolean likeStatus = likeService.patchLike(boardId, memberId);
return ResponseEntity.ok(new LikeResultResponse(boardId, likeStatus));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,45 @@ public class CommentController {
private final CommentQueryService commentQueryService;

@PostMapping("/{boardId}/comments")
public ResponseEntity<Void> createComment(@AuthMember final Long memberId,
@PathVariable("boardId") final Long boardId,
@Valid @RequestBody final CommentCreateRequest request) {
public ResponseEntity<Void> 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<List<CommentSimpleResponse>> 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<List<CommentSimpleResponse>> 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<CommentSimpleResponse> comments = commentQueryService.findAllCommentsByBoardId(boardId, memberId, commentId, pageSize);
return ResponseEntity.ok(comments);
}

@PatchMapping("/{boardId}/comments/{commentId}")
public ResponseEntity<Void> patchComment(@PathVariable("boardId") final Long boardId,
@PathVariable("commentId") final Long commentId,
@AuthMember final Long memberId,
@Valid @RequestBody final CommentPatchRequest request) {
public ResponseEntity<Void> 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<Void> deleteComment(@PathVariable("boardId") final Long boardId,
@PathVariable("commentId") final Long commentId,
@AuthMember final Long memberId) {
public ResponseEntity<Void> deleteComment(
@PathVariable("boardId") final Long boardId,
@PathVariable("commentId") final Long commentId,
@AuthMember final Long memberId
) {
commentService.deleteCommentById(memberId, commentId);
return ResponseEntity.noContent()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,29 @@ public ResponseEntity<Long> createCoupon(@RequestBody final CouponCreateRequest
}

@GetMapping("/members/{memberId}/coupons")
public ResponseEntity<CouponsResponse> findAllMemberCoupons(@PathVariable("memberId") final Long memberId,
@AuthMember final Long authId) {
public ResponseEntity<CouponsResponse> 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<Void> saveMemberCoupon(@PathVariable("memberId") final Long memberId,
@RequestBody final MemberCouponCreateRequest request) {
public ResponseEntity<Void> saveMemberCoupon(
@PathVariable("memberId") final Long memberId,
@RequestBody final MemberCouponCreateRequest request
) {
couponService.saveMemberCoupons(memberId, request);
return ResponseEntity.ok()
.build();
}

@GetMapping("/coupons")
public ResponseEntity<ApplyCouponResponse> applyCoupons(@RequestParam(value = "couponIds") final List<Long> couponIds,
@RequestParam(value = "price") final Integer price) {
public ResponseEntity<ApplyCouponResponse> applyCoupons(
@RequestParam(value = "couponIds") final List<Long> couponIds,
@RequestParam(value = "price") final Integer price
) {
int discountPrice = couponService.applyCoupons(price, couponIds);
return ResponseEntity.ok(new ApplyCouponResponse(price, discountPrice, couponIds));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ public ResponseEntity<Long> createPrivateVoucher(@RequestBody final VoucherCreat
}

@PostMapping("/vouchers/{voucherId}")
public ResponseEntity<Void> useVoucher(@AuthMember Long memberId,
@PathVariable final Long voucherId,
@RequestBody final VoucherNumberRequest request) {
public ResponseEntity<Void> 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<VoucherPageResponse> findVoucherWithPaging(@PageableDefault(sort = "id", direction = DESC) Pageable pageable) {
public ResponseEntity<VoucherPageResponse> findVoucherWithPaging(@PageableDefault(sort = "id", direction = DESC) final Pageable pageable) {
Page<VoucherSimpleResponse> result = voucherQueryService.findAllWithPaging(pageable);
return ResponseEntity.ok(VoucherPageResponse.of(result, pageable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ public class ChatRoomController {
private final ChatRoomService chatRoomService;
private final SimpMessagingTemplate messagingTemplate;

// 내가 채팅중인 모든 채팅방 반환
@GetMapping("/api/chats")
public ResponseEntity<List<ChattingRoomSimpleResponse>> findAllMyChats(@AuthMember final Long authId) {
public ResponseEntity<List<ChattingRoomSimpleResponse>> findAllMyChattingRooms(@AuthMember final Long authId) {
return ResponseEntity.ok(chatRoomQueryService.findAllMyChats(authId));
}

// 소비자가 채팅 요청 (채팅방 생성)
@PostMapping("/api/products/{productId}/chats")
public ResponseEntity<ChattingRoomResponse> createChattingRoomByBuyer(
@PathVariable final Long productId,
Expand All @@ -53,9 +51,8 @@ public ResponseEntity<ChattingRoomResponse> createChattingRoomByBuyer(
.body(ChattingRoomResponse.from(chattingRoom));
}

// 채팅방 채팅 내역 반환
@GetMapping("/api/products/{productId}/chats/{chattingRoomId}")
public ResponseEntity<List<ChatHistoryResponse>> findChattingHistoryByChatId(
public ResponseEntity<List<ChatHistoryResponse>> findChatHistoryByChattingRoomId(
@AuthMember final Long authId,
@PathVariable final Long productId,
@PathVariable final Long chattingRoomId,
Expand All @@ -65,9 +62,13 @@ public ResponseEntity<List<ChatHistoryResponse>> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,34 @@ public ResponseEntity<List<ProductPagingSimpleResponse>> findAllProductsInCatego
}

@PostMapping("/{categoryId}/products")
public ResponseEntity<Long> uploadProduct(@PathVariable("categoryId") final Long categoryId,
@AuthMember final Long memberId,
@Valid @RequestBody final ProductCreateRequest request) {
public ResponseEntity<Long> 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<ProductSpecificResponse> findProductById(@PathVariable("productId") final Long productId,
@PathVariable("categoryId") final Long categoryId,
@AuthMember final Long memberId,
@ViewCountChecker final Boolean canAddViewCount) {
public ResponseEntity<ProductSpecificResponse> 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<Void> updateProduct(@PathVariable("productId") final Long productId,
@PathVariable("categoryId") final Long categoryId,
@AuthMember final Long memberId,
@Valid @RequestBody final ProductUpdateRequest request) {
public ResponseEntity<Void> 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();
Expand All @@ -89,19 +95,23 @@ public ResponseEntity<Boolean> likesProduct(
}

@DeleteMapping("/{categoryId}/products/{productId}")
public ResponseEntity<Long> deleteProduct(@PathVariable("productId") final Long productId,
@PathVariable("categoryId") final Long categoryId,
@AuthMember final Long memberId) {
public ResponseEntity<Long> 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<Void> buyProducts(@PathVariable("productId") final Long productId,
@PathVariable("categoryId") final Long categoryId,
@AuthMember final Long memberId,
@RequestBody final UsingCouponRequest usingCouponRequest) {
public ResponseEntity<Void> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public class MemberController {
private final MemberService memberService;

@GetMapping("/{memberId}/histories")
public ResponseEntity<List<TradeHistoryResponse>> findTradeHistories(@PathVariable("memberId") final Long memberId,
@AuthMember final Long authId,
@RequestParam(value = "isSeller") final boolean isSeller) {
public ResponseEntity<List<TradeHistoryResponse>> findTradeHistories(
@PathVariable("memberId") final Long memberId,
@AuthMember final Long authId,
@RequestParam(value = "isSeller") final boolean isSeller
) {
List<TradeHistoryResponse> response = memberService.findTradeHistories(memberId, authId, isSeller);
return ResponseEntity.ok(response);
}
Expand Down

0 comments on commit a828bd8

Please sign in to comment.