Skip to content

Commit

Permalink
Merge pull request #100 from Review-zip/dev
Browse files Browse the repository at this point in the history
[Docs] Swagger 응닡 μž‘μ„±
  • Loading branch information
hsuush authored Jan 28, 2024
2 parents ddf78d1 + 968329d commit 36df1f4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<PostResponseDto.PostInfoDto> getPostInfo(@PathVariable(name = "postId") Long postId){

PostResponseDto.PostInfoDto postInfoDto = postsService.getPostInfoDto(postId);
Expand All @@ -44,7 +55,7 @@ public ApiResponse<PostResponseDto.PostInfoDto> 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<PostResponseDto.CreatedPostResponseDto> createPost(@RequestBody PostRequestDto postRequestDto){
Expand All @@ -55,7 +66,7 @@ public ApiResponse<PostResponseDto.CreatedPostResponseDto> 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<List<PostResponseDto.PostInfoDto>> getRandomPosts(@RequestParam Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ApiResponse<UserResponseDto.UserPreviewListDto> 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({
Expand All @@ -53,8 +53,20 @@ public ApiResponse<UserResponseDto.UserPreviewListDto> 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<FollowResponseDto.FollowingPreviewListDto> getOtherFollowingList(@PathVariable(name = "userId") Long userId, @RequestParam(name = "page") Integer page, @RequestParam(name = "size")Integer size){
Page<Follows> FollowsPage = usersService.getOtherFollowingList(userId, page, size);

Expand All @@ -63,14 +75,37 @@ public ApiResponse<FollowResponseDto.FollowingPreviewListDto> 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<FollowResponseDto.FollowerPreviewListDto> getOtherFollowerList(@PathVariable(name = "userId")Long userId, @RequestParam(name = "page") Integer page, @RequestParam(name = "size") Integer size){
Page<Follows> FollowsPage = usersService.getOtherFollowerList(userId, page, size);

return ApiResponse.onSuccess(UsersConverter.toFollowerPreviewListDto(FollowsPage));
}

// νŠΉμ • μœ μ €μ˜ κ²Œμ‹œκΈ€λ“€ κ°€μ Έμ˜€κΈ°

@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<UserResponseDto.PostPreviewListDto> getOtherPostList(@PathVariable(name = "userId") Long userId
, @RequestParam(name = "page") Integer page , @RequestParam(name = "size") Integer size){
Page<Posts> UserPage = usersService.getOtherPostList(userId, page, size);
Expand All @@ -85,6 +120,17 @@ public ApiResponse<UserResponseDto.PostPreviewListDto> 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<UserResponseDto.PostPreviewListDto> getOtherScrabList(@PathVariable(name = "userId") Long userId, @RequestParam(name = "page")Integer page, @RequestParam(name = "size") Integer size){
Page<Scrabs> UserPage = usersService.getOtherScrabList(userId,page, size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,15 +101,19 @@ public Page<Follows> getOtherFollowerList(Long userId, Integer page, Integer siz
public Page<Posts> getOtherPostList(Long userId, Integer page, Integer size){
Users user = usersRepository.findById(userId).orElseThrow(()->new UsersHandler(ErrorStatus.USER_NOT_FOUND));
Page<Posts> UserPage = postsRepository.findAllByUser(user, PageRequest.of(page, size));

if(UserPage.isEmpty()){
throw new PostsHandler(ErrorStatus.POST_LIST_NOT_FOUND);
}
return UserPage;
}

@Transactional
public Page<Scrabs> getOtherScrabList(Long userId, Integer page, Integer size){
Users user = usersRepository.findById(userId).orElseThrow(()->new UsersHandler(ErrorStatus.USER_NOT_FOUND));
Page<Scrabs> UserPage = scrabsRepository.findAllByUser(user, PageRequest.of(page, size));

if(UserPage.isEmpty()){
throw new PostsHandler(ErrorStatus.POST_LIST_NOT_FOUND);
}
return UserPage;
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” ν•΄μ‰¬νƒœκ·Έμž…λ‹ˆλ‹€."),
Expand Down

0 comments on commit 36df1f4

Please sign in to comment.