Skip to content

Commit

Permalink
Merge pull request #110 from Clubber2024/feat/#109-swagger-데이터-추가
Browse files Browse the repository at this point in the history
feat : 109 swagger 데이터 추가 (Review, Favorite, User, Auth)
  • Loading branch information
mjKim1229 authored May 27, 2024
2 parents 09ca557 + dea8b63 commit ee0fe5a
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import com.clubber.ClubberServer.global.infrastructure.outer.api.oauth.dto.KakaoTokenResponse;
import com.clubber.ClubberServer.global.infrastructure.outer.api.oauth.dto.KakaoUserInfoResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -44,12 +47,16 @@ public ResponseEntity getCredentialFromKakao(@RequestParam String code){
.body(kakaoOauthResponse);
}

@Operation(summary = "토큰 재발급", description = "토큰 만료시 호출 API")
@Operation(summary = "토큰 재발급", description = "토큰 만료시 호출 API",
parameters = {
@Parameter(name = "refreshToken", description = "헤더에 리프레시 토큰 전달", in = ParameterIn.HEADER),
@Parameter(name = "refreshToken", description = "쿠키에 리프레시 토큰 전달 (추후에 적용)", in = ParameterIn.COOKIE)
})
@PostMapping("/refresh")
@DisableSwaggerSecurity
public ResponseEntity<KakaoOauthResponse> tokenRefresh(
@CookieValue(value = "refreshToken", required = false) String refreshTokenCookie,
@RequestHeader(value = "token", required = false, defaultValue = "") String refreshToken){
@RequestHeader(value = "refreshToken", required = false, defaultValue = "") String refreshToken){

KakaoOauthResponse kakaoOauthResponse = authService.tokenRefresh(
refreshTokenCookie != null ? refreshTokenCookie : refreshToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@


import com.clubber.ClubberServer.domain.user.domain.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;

@Builder(access = AccessLevel.PRIVATE)
@Getter
public class KakaoOauthResponse {

@Schema(description = "유저 id", example = "1")
private final Long userId;

@Schema(description = "액세스 토큰")
private final String accessToken;

@Schema(description = "리프레시 토큰")
private final String refreshToken;

public static KakaoOauthResponse of(User user, String accessToken, String refreshToken){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.clubber.ClubberServer.domain.club.domain.Club;
import com.clubber.ClubberServer.domain.favorite.domain.Favorite;
import com.clubber.ClubberServer.domain.user.domain.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -11,8 +12,13 @@
@Builder(access = AccessLevel.PRIVATE)
public class FavoriteResponse {

@Schema(description = "즐겨찾기 id", example = "1")
private final Long favoriteId;

@Schema(description = "유저 id", example = "1")
private final Long userId;

@Schema(description = "동아리 id", example = "1")
private final Long clubId;

public static FavoriteResponse from(Favorite favorite){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.clubber.ClubberServer.domain.club.domain.Club;
import com.clubber.ClubberServer.domain.review.domain.Keyword;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Map;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -10,8 +11,11 @@
@Getter
@Builder(access = AccessLevel.PRIVATE)
public class ClubReviewKeywordStatsResponse {
@Schema(description = "동아리 id", example = "1")
private final Long clubId;

@Schema(description = "작성한 리뷰 키워드",
example = "{\"CULTURE\": 10, \"FEE\": 20, \"ACTIVITY\": 30, \"CAREER\": 40, \"MANAGE\": 50}")
private final Map<Keyword, Long> keywordStats;

public static ClubReviewKeywordStatsResponse of (Club club, Map<Keyword, Long> keywordStats){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.clubber.ClubberServer.domain.review.domain.Review;
import com.clubber.ClubberServer.domain.review.domain.ReviewKeyword;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
Expand All @@ -16,23 +17,33 @@
@Getter
@Builder(access = AccessLevel.PRIVATE)
public class ClubReviewResponse {

@Schema(description = "동아리 id", example = "1")
private final Long clubId;

private final List<ReviewResponse> reviews;
@Schema(description = "리뷰 목록")
private final List<ClubReviewDetailResponse> clubReviews;

@Getter
@Builder(access = AccessLevel.PRIVATE)
private static class ReviewResponse{
private static class ClubReviewDetailResponse{

@Schema(description = "리뷰 id", example = "1")
private final Long reviewId;

@Schema(description = "유저 id", example = "1")
private final Long userId;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd", timezone = "Asia/Seoul")
@Schema(description = "리뷰 작성 일자", example = "2024.01.01", type = "string")
private final LocalDateTime dateTime;

@Schema(description = "작성한 리뷰 키워드",
example = "[\"CULTURE\", \"FEE\", \"ACTIVITY\", \"CAREER\", \"MANAGE\"]")
private final List<Keyword> keywords;

public static ReviewResponse of(Review review, List<Keyword> keywords){
return ReviewResponse.builder()
public static ClubReviewDetailResponse of(Review review, List<Keyword> keywords){
return ClubReviewDetailResponse.builder()
.userId(review.getUser().getId())
.reviewId(review.getId())
.keywords(keywords)
Expand All @@ -45,18 +56,18 @@ public static ReviewResponse of(Review review, List<Keyword> keywords){
public static ClubReviewResponse of(Club club, List<ReviewKeyword> reviewKeywords){

Map<Review, List<Keyword>> reviewMap = getReviewListMap(reviewKeywords);
List<ReviewResponse> reviews = getCollectReviewResponse(reviewMap);
List<ClubReviewDetailResponse> reviews = getCollectClubReviewDetailResponse(reviewMap);

return ClubReviewResponse.builder()
.clubId(club.getId())
.reviews(reviews)
.clubReviews(reviews)
.build();
}

private static List<ReviewResponse> getCollectReviewResponse(Map<Review, List<Keyword>> reviewMap) {
private static List<ClubReviewDetailResponse> getCollectClubReviewDetailResponse(Map<Review, List<Keyword>> reviewMap) {
return reviewMap.entrySet()
.stream()
.map(e -> ReviewResponse.of(e.getKey(), e.getValue())).
.map(e -> ClubReviewDetailResponse.of(e.getKey(), e.getValue())).
collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.clubber.ClubberServer.domain.review.domain.Review;
import com.clubber.ClubberServer.domain.review.domain.ReviewKeyword;
import com.clubber.ClubberServer.domain.user.domain.User;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
Expand All @@ -16,8 +17,14 @@
@Builder(access = AccessLevel.PRIVATE)
public class ReviewCreateResponse {

@Schema(description = "유저 id", example = "1")
private final Long userId;

@Schema(description = "동아리 id", example = "1")
private final Long clubId;

@Schema(description = "작성한 리뷰 키워드",
example = "[\"CULTURE\", \"FEE\", \"ACTIVITY\", \"CAREER\", \"MANAGE\"]")
private final List<Keyword> keywords;

public static ReviewCreateResponse of(Review review, List<ReviewKeyword> reviewkeywords){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ReviewRequest {

// @Schema(description = "선택한 리뷰 키워드들",
// example = "[\"CULTURE\", \"FEE\"]")
@Schema(description = "선택한 리뷰 키워드들",
example = "[\"CULTURE\", \"FEE\"]")
example = "[\"CULTURE\", \"FEE\", \"ACTIVITY\", \"CAREER\", \"MANAGE\"]")
@NotNull
@Size(min = 1, message = "하나 이상의 리뷰 키워드를 입력해주세요.")
private List<Keyword> keywords;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.clubber.ClubberServer.domain.review.domain.ReviewKeyword;
import com.clubber.ClubberServer.domain.user.domain.User;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
Expand All @@ -18,20 +19,31 @@
public class UserReviewResponse {
private Long userId;

private List<ReviewResponse> reviewResponses;
private List<UserReviewDetailResponse> userReviews;

@Getter
@Builder(access = AccessLevel.PRIVATE)
public static class ReviewResponse {
public static class UserReviewDetailResponse {

@Schema(description = "리뷰 id", example = "1")
private Long reviewId;
private List<Keyword> keywords;

@Schema(description = "동아리 id", example = "1")
private Long clubId;

@Schema(description = "동아리 이름", example = "1")
private String clubName;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy.MM.dd", timezone = "Asia/Seoul")
@Schema(description = "리뷰 작성 일자", example = "2024.01.01", type = "string")
private LocalDateTime dateTime;

private static ReviewResponse of(Review review, List<Keyword> keywords){
return ReviewResponse.builder()
@Schema(description = "리뷰 작성 시 선택한 키워드",
example = "[\"CULTURE\", \"FEE\", \"ACTIVITY\", \"CAREER\", \"MANAGE\"]")
private List<Keyword> keywords;

private static UserReviewDetailResponse of(Review review, List<Keyword> keywords){
return UserReviewDetailResponse.builder()
.reviewId(review.getId())
.keywords(keywords)
.clubId(review.getClub().getId())
Expand All @@ -42,17 +54,17 @@ private static ReviewResponse of(Review review, List<Keyword> keywords){

public static UserReviewResponse of (User user, List<ReviewKeyword> keywords){
Map<Review, List<Keyword>> reviewListMap = getReviewListMap(keywords);
List<ReviewResponse> reviews = getCollectReviewResponse(reviewListMap);
List<UserReviewDetailResponse> reviews = getCollectUserReviewDetailResponse(reviewListMap);
return UserReviewResponse.builder()
.userId(user.getId())
.reviewResponses(reviews).build();
.userReviews(reviews).build();
}

private static List<ReviewResponse> getCollectReviewResponse(
private static List<UserReviewDetailResponse> getCollectUserReviewDetailResponse(
Map<Review, List<Keyword>> reviewListMap) {

return reviewListMap.entrySet().stream()
.map(e -> ReviewResponse.of(e.getKey(), e.getValue()))
.map(e -> UserReviewDetailResponse.of(e.getKey(), e.getValue()))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.clubber.ClubberServer.domain.club.domain.Club;
import com.clubber.ClubberServer.domain.favorite.domain.Favorite;
import com.clubber.ClubberServer.domain.user.domain.User;
import com.clubber.ClubberServer.domain.user.dto.UserFavoritesResponse.FavoriteResponse.ClubResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -16,50 +16,60 @@
@Getter
public class UserFavoritesResponse {

@Schema(description = "유저 id", example = "1")
private final Long userId;
private final List<FavoriteResponse> favorites;

private final List<FavoriteDetailResponse> userFavorites;

@AllArgsConstructor
@Getter
@Builder
public static class FavoriteResponse {
public static class FavoriteDetailResponse {

private final Long id;
@Schema(description = "즐겨찾기 id", example = "1")
private final Long favoriteId;

private final ClubResponse clubResponse;
@Schema(description = "즐겨찾기한 동아리")
private final FavoriteClubDetailResponse favoriteClub;

@AllArgsConstructor
@Getter
@Builder
public static class ClubResponse {
private final Long id;
private final String name;
private final String type;

private static ClubResponse of(Club club){
return ClubResponse.builder()
.id(club.getId())
.name(club.getName())
.type(club.getClubType()).build();
public static class FavoriteClubDetailResponse {

@Schema(description = "동아리 id", example = "1")
private final Long clubId;

@Schema(description = "동아리 이름", example = "로타랙트")
private final String clubName;

@Schema(description = "동아리 id", example = "center")
private final String clubType;

private static FavoriteClubDetailResponse of(Club club){
return FavoriteClubDetailResponse.builder()
.clubId(club.getId())
.clubName(club.getName())
.clubType(club.getClubType()).build();
}
}

private static FavoriteResponse of(Favorite favorite){
ClubResponse clubResponse = ClubResponse.of(favorite.getClub());
return FavoriteResponse
private static FavoriteDetailResponse of(Favorite favorite){
FavoriteClubDetailResponse favoriteClubDetailResponse = FavoriteClubDetailResponse.of(favorite.getClub());
return FavoriteDetailResponse
.builder()
.id(favorite.getId())
.clubResponse(clubResponse).build();
.favoriteId(favorite.getId())
.favoriteClub(favoriteClubDetailResponse).build();
}
}

public static UserFavoritesResponse of (User user, List<Favorite> favorites){
List<FavoriteResponse> favoriteResponse = favorites.stream()
.map(FavoriteResponse::of).collect(Collectors.toList());
List<FavoriteDetailResponse> favoriteDetailResponse = favorites.stream()
.map(FavoriteDetailResponse::of).collect(Collectors.toList());

return UserFavoritesResponse.builder()
.userId(user.getId())
.favorites(favoriteResponse).build();
.userFavorites(favoriteDetailResponse).build();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.clubber.ClubberServer.domain.user.domain.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -10,7 +11,10 @@
@Builder(access = AccessLevel.PRIVATE)
public class UserProfileResponse {

@Schema(description = "유저 id", example = "1")
private Long id;

@Schema(description = "유저 이메일", example = "[email protected]")
private String email;

public static UserProfileResponse of(User user){
Expand Down

0 comments on commit ee0fe5a

Please sign in to comment.