From 8208aefe953ef2a562404dec288845a6ec393dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=ED=98=9C=EC=88=98?= Date: Sun, 28 Jan 2024 21:50:41 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20Swagger=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config | 2 +- .../domain/post/PostsController.java | 17 +++++-- .../domain/user/UsersController.java | 48 ++++++++++++++++++- .../ReviewZIP/domain/user/UsersService.java | 9 +++- .../user/dto/response/UserResponseDto.java | 4 -- .../response/code/resultCode/ErrorStatus.java | 1 + 6 files changed, 70 insertions(+), 11 deletions(-) diff --git a/config b/config index 55b6b0c9..80f8e462 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 55b6b0c9f1b201f28139ebaeb902929c668e64ac +Subproject commit 80f8e4625eeb7370198551642b111a3eca7e6b84 diff --git a/src/main/java/com/example/ReviewZIP/domain/post/PostsController.java b/src/main/java/com/example/ReviewZIP/domain/post/PostsController.java index e0147ac9..4ecc6021 100644 --- a/src/main/java/com/example/ReviewZIP/domain/post/PostsController.java +++ b/src/main/java/com/example/ReviewZIP/domain/post/PostsController.java @@ -4,6 +4,8 @@ import com.example.ReviewZIP.domain.post.dto.response.PostResponseDto; import com.example.ReviewZIP.global.response.ApiResponse; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponses; @@ -30,10 +32,19 @@ @RequestMapping("/v1/posts") public class PostsController { private final PostsService postsService; - private final PostsConverter postsConverter; // 특정 게시글의 정보 가져오기 @GetMapping("/{postId}") + @Operation(summary = "특정 게시글의 정보 가져오기 API",description = "게시글의 id를 이용하여 상세정보 출력, UserInfoDto & ImageListDto & PostInfoDto 이용") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST401", description = "해당 게시물이 존재하지 않음",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) + @Parameters({ + @Parameter(name = "postId", description = "게시글의 아이디"), + @Parameter(name = "page", description = "페이지 번호"), + @Parameter(name = "size", description = "페이징 사이즈") + }) public ApiResponse getPostInfo(@PathVariable(name = "postId") Long postId){ PostResponseDto.PostInfoDto postInfoDto = postsService.getPostInfoDto(postId); @@ -44,7 +55,7 @@ public ApiResponse getPostInfo(@PathVariable(name = @PostMapping @Operation(summary = "게시글 생성", description = "PostRequestDto, CreatedPostResponseDto 사용") @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "SEARCH203",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST403", description = "게시글 작성 실패",content = @Content(schema = @Schema(implementation = ApiResponse.class))), }) public ApiResponse createPost(@RequestBody PostRequestDto postRequestDto){ @@ -55,7 +66,7 @@ public ApiResponse createPost(@RequestBo @GetMapping("/random") @Operation(summary = "랜덤으로 게시글 3개 가져오기", description = "PostInfoDto") @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "SEARCH203",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST405", description = "랜덤으로 게시글 3개 가져오기 실패",content = @Content(schema = @Schema(implementation = ApiResponse.class))), }) public ApiResponse> getRandomPosts(@RequestParam Long userId) { diff --git a/src/main/java/com/example/ReviewZIP/domain/user/UsersController.java b/src/main/java/com/example/ReviewZIP/domain/user/UsersController.java index a9d580d7..f9e2e978 100644 --- a/src/main/java/com/example/ReviewZIP/domain/user/UsersController.java +++ b/src/main/java/com/example/ReviewZIP/domain/user/UsersController.java @@ -39,7 +39,7 @@ public ApiResponse searchUsersByName(@Reques @GetMapping("/search/nickname") @Operation(summary = "닉네임으로 유저 검색 API",description = "유저의 닉네임으로 특정 유저를 검색 (자신이 팔로잉한 대상은 제외)") @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "SEARCH203",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER408", description = "유저를 찾을 수 없음",content = @Content(schema = @Schema(implementation = ApiResponse.class))), }) @Parameters({ @@ -53,8 +53,20 @@ public ApiResponse searchUsersByNickname(@Re return ApiResponse.onSuccess(userListDto); } + // 특정 유저의 팔로잉 목록 가져오기 @GetMapping("{userId}/following") + @Operation(summary = "특정 유저의 팔로잉 목록 가져오기 API",description = "특정 유저의 id를 이용하여 해당 유저의 팔로잉 목록 조회, FollowerPreviewDto와 FollowerPreviewListDto 이용") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER404", description = "유저가 존재하지 않습니다",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER406", description = "팔로잉 목록이 존재하지 않습니다",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) + @Parameters({ + @Parameter(name = "userId", description = "유저의 아이디"), + @Parameter(name = "page", description = "페이지 번호"), + @Parameter(name = "size", description = "페이징 사이즈") + }) public ApiResponse getOtherFollowingList(@PathVariable(name = "userId") Long userId, @RequestParam(name = "page") Integer page, @RequestParam(name = "size")Integer size){ Page FollowsPage = usersService.getOtherFollowingList(userId, page, size); @@ -63,6 +75,17 @@ public ApiResponse getOtherFollowingL // 특정 유저의 팔로워 목록 가져오기 @GetMapping("/{userId}/followers") + @Operation(summary = "특정 유저의 팔로워 목록 가져오기 API",description = "특정 유저의 id를 이용하여 해당 유저의 팔로워 목록 조회, FollowingPreviewDto와 FollowingPreviewListDto 이용") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER404", description = "유저가 존재하지 않습니다",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST405", description = "팔로워 목록이 존재하지 않습니다",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) + @Parameters({ + @Parameter(name = "userId", description = "유저의 아이디"), + @Parameter(name = "page", description = "페이지 번호"), + @Parameter(name = "size", description = "페이징 사이즈") + }) public ApiResponse getOtherFollowerList(@PathVariable(name = "userId")Long userId, @RequestParam(name = "page") Integer page, @RequestParam(name = "size") Integer size){ Page FollowsPage = usersService.getOtherFollowerList(userId, page, size); @@ -70,7 +93,19 @@ public ApiResponse getOtherFollowerLis } // 특정 유저의 게시글들 가져오기 + @GetMapping("/{userId}/posts") + @Operation(summary = "특정 유저의 게시글 목록 가져오기 API",description = "특정 유저의 id를 받아 게시글들의 목록(대표 이미지들)을 반환, PostPreviewDto와 PostPreviewListDto 이용") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER404", description = "유저가 존재하지 않습니다",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST406", description = "게시글 목록이 존재하지 않습니다",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) + @Parameters({ + @Parameter(name = "userId", description = "유저의 아이디"), + @Parameter(name = "page", description = "페이지 번호"), + @Parameter(name = "size", description = "페이징 사이즈") + }) public ApiResponse getOtherPostList(@PathVariable(name = "userId") Long userId , @RequestParam(name = "page") Integer page , @RequestParam(name = "size") Integer size){ Page UserPage = usersService.getOtherPostList(userId, page, size); @@ -85,6 +120,17 @@ public ApiResponse getOtherPostList(@PathVar // 특정 유저의 스크랩들 가져오기 @GetMapping("/{userId}/posts/scrabs") + @Operation(summary = "특정 유저가 스크랩한 게시물 가져오기 API",description = "특정 유저의 id를 받아 스크랩한 게시글들의 목록(대표 이미지들)을 반환, PostPreviewDto와 PostPreviewListDto 이용") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER404", description = "유저가 존재하지 않습니다",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST406", description = "게시글 목록이 존재하지 않습니다",content = @Content(schema = @Schema(implementation = ApiResponse.class))), + }) + @Parameters({ + @Parameter(name = "userId", description = "유저의 아이디"), + @Parameter(name = "page", description = "페이지 번호"), + @Parameter(name = "size", description = "페이징 사이즈") + }) public ApiResponse getOtherScrabList(@PathVariable(name = "userId") Long userId, @RequestParam(name = "page")Integer page, @RequestParam(name = "size") Integer size){ Page UserPage = usersService.getOtherScrabList(userId,page, size); diff --git a/src/main/java/com/example/ReviewZIP/domain/user/UsersService.java b/src/main/java/com/example/ReviewZIP/domain/user/UsersService.java index e29a1e30..8deea098 100644 --- a/src/main/java/com/example/ReviewZIP/domain/user/UsersService.java +++ b/src/main/java/com/example/ReviewZIP/domain/user/UsersService.java @@ -9,6 +9,7 @@ import com.example.ReviewZIP.domain.scrab.Scrabs; import com.example.ReviewZIP.domain.scrab.ScrabsRepository; import com.example.ReviewZIP.global.response.code.resultCode.ErrorStatus; +import com.example.ReviewZIP.global.response.exception.handler.PostsHandler; import com.example.ReviewZIP.global.response.exception.handler.UsersHandler; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -100,7 +101,9 @@ public Page getOtherFollowerList(Long userId, Integer page, Integer siz public Page getOtherPostList(Long userId, Integer page, Integer size){ Users user = usersRepository.findById(userId).orElseThrow(()->new UsersHandler(ErrorStatus.USER_NOT_FOUND)); Page UserPage = postsRepository.findAllByUser(user, PageRequest.of(page, size)); - + if(UserPage.isEmpty()){ + throw new PostsHandler(ErrorStatus.POST_LIST_NOT_FOUND); + } return UserPage; } @@ -108,7 +111,9 @@ public Page getOtherPostList(Long userId, Integer page, Integer size){ public Page getOtherScrabList(Long userId, Integer page, Integer size){ Users user = usersRepository.findById(userId).orElseThrow(()->new UsersHandler(ErrorStatus.USER_NOT_FOUND)); Page UserPage = scrabsRepository.findAllByUser(user, PageRequest.of(page, size)); - + if(UserPage.isEmpty()){ + throw new PostsHandler(ErrorStatus.POST_LIST_NOT_FOUND); + } return UserPage; } } diff --git a/src/main/java/com/example/ReviewZIP/domain/user/dto/response/UserResponseDto.java b/src/main/java/com/example/ReviewZIP/domain/user/dto/response/UserResponseDto.java index 49378e69..54aa70df 100644 --- a/src/main/java/com/example/ReviewZIP/domain/user/dto/response/UserResponseDto.java +++ b/src/main/java/com/example/ReviewZIP/domain/user/dto/response/UserResponseDto.java @@ -1,14 +1,10 @@ package com.example.ReviewZIP.domain.user.dto.response; -import com.example.ReviewZIP.domain.user.Status; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import java.time.LocalDate; import java.util.List; public class UserResponseDto { diff --git a/src/main/java/com/example/ReviewZIP/global/response/code/resultCode/ErrorStatus.java b/src/main/java/com/example/ReviewZIP/global/response/code/resultCode/ErrorStatus.java index 81644ba9..809dd9c5 100644 --- a/src/main/java/com/example/ReviewZIP/global/response/code/resultCode/ErrorStatus.java +++ b/src/main/java/com/example/ReviewZIP/global/response/code/resultCode/ErrorStatus.java @@ -37,6 +37,7 @@ public enum ErrorStatus implements BaseErrorCode { POST_CREATE_FAIL(HttpStatus.BAD_REQUEST,"POST403", "게시글 작성에 실패하였습니다"), SCRAB_LIST_NOT_FOUND(HttpStatus.NOT_FOUND, "POST404", "스크랩 목록을 찾을 수 없습니다."), POST_RANDOM_FAIL(HttpStatus.BAD_REQUEST,"POST405", "사용자가 작성하지 않은 게시글이 최소 3개 이상 존재해야합니다."), + POST_LIST_NOT_FOUND(HttpStatus.NOT_FOUND, "POST406", "게시글 목록이 존재하지 않습니다."), // Hashtag HASHTAG_NOT_FOUND(HttpStatus.NOT_FOUND, "HASHTAG401", "존재하지 않는 해쉬태그입니다."),