Skip to content

Commit

Permalink
KL-166/refactor: use CREATED for post responses
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhamma committed Sep 9, 2024
1 parent 97aaa54 commit f0fe22c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public List<CommentResponse> findCommentsByProductId(@PathVariable final Long pr
}

@PostMapping
@Operation(summary = "댓글 등록", description = "작성한 댓글을 저장합니다.")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "댓글 등록", description = "작성한 댓글을 저장합니다.")
public CommentResponse addComment(
@PathVariable final Long productId,
@RequestBody @Valid final CommentCreateUpdateRequest commentCreateRequestDto
Expand All @@ -50,8 +50,8 @@ public CommentResponse addComment(
}

@PutMapping("/{commentId}")
@Operation(summary = "댓글 수정", description = "작성한 댓글을 수정합니다.")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "댓글 수정", description = "작성한 댓글을 수정합니다.")
public CommentResponse updateComment(
@PathVariable final Long productId,
@PathVariable final Long commentId,
Expand All @@ -65,8 +65,8 @@ public CommentResponse updateComment(
}

@DeleteMapping("/{commentId}")
@Operation(summary = "댓글 삭제", description = "작성한 댓글을 삭제합니다.")
@ResponseStatus(HttpStatus.NO_CONTENT)
@Operation(summary = "댓글 삭제", description = "작성한 댓글을 삭제합니다.")
public ResponseEntity<Void> deleteComment(
@PathVariable final Long productId,
@PathVariable final Long commentId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -29,45 +31,47 @@ public class ImageController {

private final ImageService imageService;

@PostMapping("/v1/users/me/upload-url")
@ResponseStatus(HttpStatus.CREATED)
@Operation(
summary = "유저 이미지 업로드 Presigned URL 생성",
description = "유저 이미지 업로드를 위한 Presigned URL를 생성합니다."
)
@PostMapping("/v1/users/me/upload-url")
public PresignedUrlResponse createUserImageUploadUrl(
@Valid @RequestBody final SingleImageUploadRequest request
) {
return imageService.createUserImageUploadUrl(request);
}

@PostMapping("/v1/products/{productId}/upload-url")
@ResponseStatus(HttpStatus.CREATED)
@Operation(
summary = "상품 이미지 업로드 Presigned URL 생성",
description = "상품 이미지 업로드를 위한 Presigned URL를 생성합니다."
)
@PostMapping("/v1/products/{productId}/upload-url")
public List<PresignedUrlResponse> createProductImageUploadUrls(
@PathVariable final Long productId,
@Valid @RequestBody final MultipleImagesUploadRequest request
) {
return imageService.createProductImageUploadUrls(productId, request);
}

@PostMapping("/v1/users/me/upload-complete")
@Operation(
summary = "유저 이미지 업로드 완료 처리",
description = "유저 이미지 업로드를 완료 처리합니다."
)
@PostMapping("/v1/users/me/upload-complete")
public SingleUploadCompleteResponse uploadCompleteUserImage(
@Valid @RequestBody final SingleImageUpdateRequest request
) {
return imageService.uploadCompleteUserImage(request);
}

@PostMapping("/v1/products/{productId}/upload-complete")
@Operation(
summary = "상품 이미지 업로드 완료 처리",
description = "상품 이미지 업로드를 완료 처리합니다."
)
@PostMapping("/v1/products/{productId}/upload-complete")
public MultipleUploadCompleteResponse uploadCompleteProductImages(
@PathVariable final Long productId,
@Valid @RequestBody final MultipleImagesUpdateRequest request
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package taco.klkl.domain.like.controller;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -23,6 +25,7 @@ public class LikeController {
private final LikeService likeService;

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "좋아요 누르기", description = "상품에 좋아요를 누릅니다.")
public LikeResponse addLike(@PathVariable final Long productId) {
return likeService.createLike(productId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -14,6 +15,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

Expand Down Expand Up @@ -94,6 +96,7 @@ public ProductDetailResponse findProductById(
}

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "상품 등록", description = "상품을 등록합니다.")
public ResponseEntity<ProductDetailResponse> createProduct(
@Valid @RequestBody final ProductCreateUpdateRequest createRequest
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/taco/klkl/domain/user/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -40,67 +42,68 @@ public class UserController {
private final UserService userService;
private final UserUtil userUtil;

@Operation(summary = "내 정보 조회", description = "내 정보를 조회합니다.")
@GetMapping("/me")
@Operation(summary = "내 정보 조회", description = "내 정보를 조회합니다.")
public UserDetailResponse getMe() {
final User me = userUtil.getCurrentUser();
return userService.getUserById(me.getId());
}

@Operation(summary = "유저 정보 조회", description = "유저 정보를 조회합니다.")
@GetMapping("/{userId}")
@Operation(summary = "유저 정보 조회", description = "유저 정보를 조회합니다.")
public UserDetailResponse getUser(@PathVariable final Long userId) {
return userService.getUserById(userId);
}

@Operation(summary = "내 상품 목록 조회", description = "내 상품 목록을 조회합니다.")
@GetMapping("/me/products")
@Operation(summary = "내 상품 목록 조회", description = "내 상품 목록을 조회합니다.")
public PagedResponse<ProductSimpleResponse> getMyProducts(
@PageableDefault(size = ProductConstants.DEFAULT_PAGE_SIZE) Pageable pageable
) {
final User me = userUtil.getCurrentUser();
return userService.getUserProductsById(me.getId(), pageable);
}

@Operation(summary = "유저의 상품 목록 조회", description = "유저의 상품 목록을 조회합니다.")
@GetMapping("/{userId}/products")
@Operation(summary = "유저의 상품 목록 조회", description = "유저의 상품 목록을 조회합니다.")
public PagedResponse<ProductSimpleResponse> getUserProducts(
@PathVariable final Long userId,
@PageableDefault(size = ProductConstants.DEFAULT_PAGE_SIZE) Pageable pageable
) {
return userService.getUserProductsById(userId, pageable);
}

@Operation(summary = "내 종아요 목록 조회", description = "내 좋아요 목록을 조회합니다.")
@GetMapping("/me/likes")
@Operation(summary = "내 종아요 목록 조회", description = "내 좋아요 목록을 조회합니다.")
public PagedResponse<ProductSimpleResponse> getMyLikes(
@PageableDefault(size = ProductConstants.DEFAULT_PAGE_SIZE) Pageable pageable
) {
final User me = userUtil.getCurrentUser();
return userService.getUserLikesById(me.getId(), pageable);
}

@Operation(summary = "내 팔로잉 목록 조회", description = "내 팔로잉 목록을 조회합니다.")
@GetMapping("/following")
@Operation(summary = "내 팔로잉 목록 조회", description = "내 팔로잉 목록을 조회합니다.")
public List<UserSimpleResponse> getMyFollowing() {
final User me = userUtil.getCurrentUser();
return userService.getUserFollowingById(me.getId());
}

@Operation(summary = "유저 팔로우", description = "유저를 팔로우합니다.")
@PostMapping("/following")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "유저 팔로우", description = "유저를 팔로우합니다.")
public UserFollowResponse followUser(@Valid @RequestBody final UserFollowRequest request) {
return userService.createUserFollow(request);
}

@Operation(summary = "유저 팔로우 취소", description = "유저 팔로우를 취소합니다.")
@DeleteMapping("/following/{userId}")
@Operation(summary = "유저 팔로우 취소", description = "유저 팔로우를 취소합니다.")
public UserFollowResponse cancelUserFollow(@PathVariable final Long userId) {
return userService.removeUserFollow(userId);
}

@Operation(summary = "내 정보 수정", description = "내 정보를 수정합니다.")
@PutMapping("/me")
@Operation(summary = "내 정보 수정", description = "내 정보를 수정합니다.")
public UserDetailResponse updateMe(@Valid @RequestBody final UserUpdateRequest request) {
return userService.updateUser(request);
}
Expand Down

0 comments on commit f0fe22c

Please sign in to comment.