Skip to content

Commit

Permalink
fix: api response 요청 사항 반영 (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
punchdrunkard authored Aug 31, 2024
1 parent 1392324 commit 5d0bc30
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 52 deletions.
20 changes: 0 additions & 20 deletions src/main/java/com/odiga/fiesta/common/config/JsonCustomConfig.java

This file was deleted.

3 changes: 2 additions & 1 deletion src/main/java/com/odiga/fiesta/common/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public enum ErrorCode {
INTERNAL_SERVER_ERROR(500, "S001", "서버에 문제가 생겼습니다."),
UPLOAD_FAIL(500, "S002", "파일 업로드에 실패하였습니다."),
JSON_PARSING_ERROR(500, "S003", "JSON 파싱 오류가 발생했습니다."),
USER_TYPE_NOT_FOUND(500, "S004", "유저 유형 도출에 실패했습니다."),

// Client Error
METHOD_NOT_ALLOWED(405, "C001", "적절하지 않은 HTTP 메소드입니다."),
Expand Down Expand Up @@ -44,6 +43,8 @@ public enum ErrorCode {
INVALID_NICKNAME_LENGTH(400, "U008", "닉네임은 1자 이상 10자 이하여야 합니다."),
CAN_NOT_FIND_KAKAO_USER(400, "U009", "카카오 사용자를 찾을 수 없습니다."),
ROLE_NOT_FOUND(404, "U010", "존재하지 않는 권한입니다."),
USER_TYPE_NOT_FOUND(500, "U011", "유저 유형을 찾을 수 없습니다."),
PROFILE_NOT_REGISTERED(400, "U012", "프로필을 등록해주세요."),

// Festival
INVALID_FESTIVAL_MONTH(400, "F001", "입력된 월이 유효하지 않습니다. 월은 1월부터 12월 사이여야 합니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.odiga.fiesta.festival.dto.response.FestivalInfo;
import com.odiga.fiesta.festival.dto.response.FestivalInfoWithBookmark;
import com.odiga.fiesta.festival.dto.response.FestivalMonthlyResponse;
import com.odiga.fiesta.festival.dto.response.RecommendFestivalResponse;
import com.odiga.fiesta.festival.service.FestivalBookmarkService;
import com.odiga.fiesta.festival.service.FestivalService;
import com.odiga.fiesta.user.domain.User;
Expand Down Expand Up @@ -242,14 +243,14 @@ public ResponseEntity<BasicResponse<PageResponse<FestivalInfo>>> getHotFestival(

@Operation(summary = "유형별 추천 페스티벌 조회", description = "유저 유형 별 추천 페스티벌을 랜덤으로 조회합니다.")
@GetMapping("/recommend")
public ResponseEntity<BasicResponse<List<FestivalInfo>>> getRecommendFestival(
public ResponseEntity<BasicResponse<RecommendFestivalResponse>> getRecommendFestival(
@AuthUser User user,
@RequestParam(required = false, defaultValue = "5") Long size
) {
checkLogin(user);

List<FestivalInfo> recommendFestivals = festivalService.getRecommendFestivals(
isNull(user) ? null : user.getId(), size);
RecommendFestivalResponse recommendFestivals = festivalService.getRecommendFestivals(
isNull(user) ? null : user, size);

return ResponseEntity.ok(BasicResponse.ok("유형별 추천 페스티벌 조회 성공", recommendFestivals));
}
Expand All @@ -266,7 +267,7 @@ private static void validateLatAndLng(Double latitude, Double longitude, Pageabl
for (Sort.Order order : pageable.getSort()) {
String property = order.getProperty();

if ("dist" .equals(property) && (isNull(latitude) || isNull(longitude))) {
if ("dist".equals(property) && (isNull(latitude) || isNull(longitude))) {
throw new CustomException(INVALID_CURRENT_LOCATION);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.odiga.fiesta.festival.dto.response;

import java.util.List;

import com.odiga.fiesta.user.domain.UserType;
import com.odiga.fiesta.user.dto.response.UserTypeResponse;

import lombok.Builder;
import lombok.Getter;

@Getter
public class RecommendFestivalResponse {

List<FestivalInfo> festivals;
UserTypeResponse userType;

@Builder
private RecommendFestivalResponse(List<FestivalInfo> festivals, UserTypeResponse userType) {
this.festivals = festivals;
this.userType = userType;
}

public static RecommendFestivalResponse of(List<FestivalInfo> festivals, UserType userType) {
return RecommendFestivalResponse.builder()
.festivals(festivals)
.userType(UserTypeResponse.of(userType))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@
import com.odiga.fiesta.festival.dto.response.FestivalInfoWithBookmark;
import com.odiga.fiesta.festival.dto.response.FestivalMonthlyResponse;
import com.odiga.fiesta.festival.dto.response.MoodResponse;
import com.odiga.fiesta.festival.dto.response.RecommendFestivalResponse;
import com.odiga.fiesta.festival.repository.FestivalCategoryRepository;
import com.odiga.fiesta.festival.repository.FestivalImageRepository;
import com.odiga.fiesta.festival.repository.FestivalMoodRepository;
import com.odiga.fiesta.festival.repository.FestivalRepository;
import com.odiga.fiesta.festival.repository.FestivalUserTypeRepository;
import com.odiga.fiesta.mood.repository.MoodRepository;
import com.odiga.fiesta.sido.repository.SidoRepository;
import com.odiga.fiesta.user.domain.User;
import com.odiga.fiesta.user.domain.UserType;
import com.odiga.fiesta.user.dto.response.UserTypeResponse;
import com.odiga.fiesta.user.repository.UserRepository;
import com.odiga.fiesta.user.repository.UserTypeRepository;
import com.odiga.fiesta.user.service.UserTypeService;

import lombok.RequiredArgsConstructor;
Expand All @@ -71,8 +75,10 @@
@Transactional(readOnly = true)
@Slf4j
public class FestivalService {

private final FestivalUserTypeRepository festivalUserTypeRepository;
private final UserRepository userRepository;
private final UserTypeRepository userTypeRepository;

private final Clock clock;

Expand Down Expand Up @@ -288,17 +294,26 @@ public FestivalDetailResponse getFestival(Long userId, Long festivalId) {
return FestivalDetailResponse.of(festivalDetail, categories, moods, images);
}

public List<FestivalInfo> getRecommendFestivals(Long userId, Long size) {
validateUserId(userId);
public RecommendFestivalResponse getRecommendFestivals(User user, Long size) {
validateUserId(user.getId());

if (isNull(user.getUserTypeId())) {
throw new CustomException(PROFILE_NOT_REGISTERED);
}

Long userTypeId = userRepository.findUserTypeIdById(userId)
UserType userType = userTypeRepository.findById(user.getUserTypeId())
.orElseThrow(() -> new CustomException(USER_TYPE_NOT_FOUND));

LocalDate date = LocalDate.now(clock);

List<FestivalWithSido> festivals = festivalRepository.findRecommendFestivals(userTypeId, size, date);
List<FestivalWithSido> festivals = festivalRepository.findRecommendFestivals(user.getUserTypeId(), size, date);
List<FestivalInfo> festivalInfos = getFestivalAndSidoWithThumbnailImage(festivals);

return RecommendFestivalResponse.builder()
.festivals(festivalInfos)
.userType(UserTypeResponse.of(userType))
.build();

return getFestivalAndSidoWithThumbnailImage(festivals);
}

// 필터링을 위해, request list 내부의 중복 제거
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

@Getter
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ReviewSimpleResponse extends ReviewIdResponse {

private Long festivalId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.odiga.fiesta.auth.domain.AuthUser;
import com.odiga.fiesta.auth.service.AuthService;
import com.odiga.fiesta.common.BasicResponse;
import com.odiga.fiesta.common.error.ErrorCode;
import com.odiga.fiesta.common.error.exception.CustomException;
import com.odiga.fiesta.user.domain.User;
import com.odiga.fiesta.user.dto.request.ProfileCreateRequest;
import com.odiga.fiesta.user.dto.request.SocialLoginRequest;
Expand Down Expand Up @@ -51,6 +53,9 @@ public ResponseEntity<BasicResponse<LoginResponse>> kakaoLogin(@RequestBody Soci
@GetMapping("/me")
@Operation(summary = "내 정보 조회", description = "로그인한 유저의 정보를 조회합니다.")
public ResponseEntity<BasicResponse<UserInfoResponse>> getUserInfo(@AuthUser User user) {
if (user == null) {
throw new CustomException(ErrorCode.NOT_LOGGED_IN);
}

UserInfoResponse response = UserInfoResponse.builder()
.userId(user.getId())
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/odiga/fiesta/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@Getter
@NoArgsConstructor(access = PROTECTED)
@Table(name = "users")
@ToString
public class User extends BaseEntity {

private static final Pattern EMAIL_PATTERN = Pattern.compile("^[a-z0-9._-]+@[a-z]+[.]+[a-z]{2,3}$");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/odiga/fiesta/user/domain/UserType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@AllArgsConstructor
@Getter
@NoArgsConstructor(access = PROTECTED)
@Table(name = "user_type")
@Builder
@ToString
public class UserType extends BaseEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.odiga.fiesta.user.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Builder;
import lombok.Getter;

Expand All @@ -15,7 +13,5 @@ public class UserInfoResponse {
private String statusMessage;
private String profileImage;
private Boolean isProfileCreated;

@JsonInclude(JsonInclude.Include.NON_NULL)
private Long userTypeId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.odiga.fiesta.user.dto.response;

import com.odiga.fiesta.user.domain.UserType;

import lombok.Builder;
import lombok.Getter;

@Getter
public class UserTypeResponse {

private Long userTypeId;
private String name;

@Builder
private UserTypeResponse(Long userTypeId, String name) {
this.userTypeId = userTypeId;
this.name = name;
}

public static UserTypeResponse of(UserType usertype) {
return UserTypeResponse.builder()
.userTypeId(usertype.getId())
.name(usertype.getName())
.build();
}
}
Loading

0 comments on commit 5d0bc30

Please sign in to comment.