Skip to content

Commit

Permalink
[FEATURE] 유저 취향 상자 관련 API 추가 (#127)
Browse files Browse the repository at this point in the history
* feat : 유저 취향 상자 관련 API 추가 #125

* feat : UserFavor(유저 취향 상자) order 삭제, 수정 로직 변경 #125

* fix : UserFaovr order 관련 에러 수정 #125

* edit : 취향 상자 수정 시 @NotNull 추가 #125

* spotless Apply #125

* feat : 유저 프로필 조회 시 취향 상자 정보 포함 #125

* feat : 친구 프로필, 취향 정보 조회 API 작성 #125

* feat : VO 필드 변경 #125

* spotless Apply #125
  • Loading branch information
bongsh0112 authored Dec 11, 2023
1 parent 3f004af commit ff1a942
Show file tree
Hide file tree
Showing 28 changed files with 345 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@
import org.springframework.web.bind.annotation.*;
import tify.server.api.common.slice.SliceResponse;
import tify.server.api.user.model.dto.request.PatchNeighborsOrdersRequest;
import tify.server.api.user.model.dto.request.PatchUserFavorRequest;
import tify.server.api.user.model.dto.request.PostUserOpinionRequest;
import tify.server.api.user.model.dto.request.PutUserProfileRequest;
import tify.server.api.user.model.dto.request.UserOnBoardingRequest;
import tify.server.api.user.model.dto.response.OnBoardingStatusResponse;
import tify.server.api.user.model.dto.response.UserReportResponse;
import tify.server.api.user.model.dto.vo.MutualFriendsVo;
import tify.server.api.user.model.dto.vo.MyDailyQuestionAnswerVo;
import tify.server.api.user.model.dto.vo.RetrieveUserFavorBoxVo;
import tify.server.api.user.model.dto.vo.UserDailyQuestionAnswerVo;
import tify.server.api.user.model.dto.vo.UserFavorBoxVo;
import tify.server.api.user.model.dto.vo.UserOpinionVo;
import tify.server.api.user.model.dto.vo.UserReportInfoVo;
import tify.server.api.user.model.dto.vo.UserSearchInfoVo;
import tify.server.api.user.service.*;
import tify.server.api.user.service.CreateNeighborUseCase;
import tify.server.domain.domains.question.domain.DailyQuestionCategory;
import tify.server.domain.domains.user.domain.LargeCategory;
import tify.server.domain.domains.user.domain.SmallCategory;
import tify.server.domain.domains.user.dto.condition.UserCondition;
import tify.server.domain.domains.user.dto.model.GetNeighborApplicationDTO;
import tify.server.domain.domains.user.dto.model.RetrieveNeighborDTO;
import tify.server.domain.domains.user.vo.UserAnswerVo;
import tify.server.domain.domains.user.vo.UserFavorVo;
import tify.server.domain.domains.user.vo.UserInfoVo;
import tify.server.domain.domains.user.vo.UserProfileVo;

Expand All @@ -49,6 +50,7 @@ public class UserController {
private final UserFavorUseCase userFavorUseCase;
private final UpdateUserProfileUseCase updateUserProfileUseCase;
private final UserFavorFilterUseCase userFavorFilterUseCase;
private final UpdateUserFavorUseCase updateUserFavorUseCase;
private final UserOnBoardingUseCase userOnBoardingUseCase;
private final NeighborInfoUseCase neighborInfoUseCase;
private final RetrieveNeighborListUseCase retrieveNeighborListUseCase;
Expand All @@ -67,6 +69,7 @@ public class UserController {
private final RetrieveMyDailyAnswerUseCase retrieveMyDailyAnswerUseCase;
private final CreateUserOpinionUseCase createUserOpinionUseCase;
private final RetrieveUserOpinionUseCase retrieveUserOpinionUseCase;
private final RetrieveNeighborFavorBoxUseCase retrieveNeighborFavorBoxUseCase;

@Operation(summary = "유저 정보 조회")
@GetMapping("/{userId}")
Expand All @@ -87,7 +90,7 @@ public void updateNeighborViewedAt(@PathVariable Long neighborId) {
}

@Operation(summary = "유저 취향 답변 중분류 별 조회")
@GetMapping("/{userId}/tags")
@GetMapping("/{userId}/favors")
public List<UserAnswerVo> getUserTags(
@PathVariable Long userId,
@RequestParam @Parameter(description = "필터로 쓰일 중분류입니다.")
Expand All @@ -109,11 +112,18 @@ public UserInfoVo getUserProfileInfoByToken() {
return userInfoUseCase.executeByToken();
}

@Operation(summary = "대분류 별 유저 취향 조회 필터")
@GetMapping("/{userId}/category")
public List<UserFavorVo> getUserTagsByLargeCategory(
@PathVariable Long userId, @RequestParam LargeCategory largeCategory) {
return userFavorFilterUseCase.execute(userId, largeCategory);
@Operation(summary = "유저 취향 상자 조회")
@GetMapping("/{userId}/tags")
public List<UserFavorBoxVo> getUserFavorsByUserId(@PathVariable Long userId) {
return userFavorFilterUseCase.execute(userId);
}

@Operation(summary = "유저 취향 상자 수정")
@PatchMapping("/{userId}/tags")
public void patchUserFavorsByUserId(
@PathVariable Long userId,
@RequestBody @Valid PatchUserFavorRequest patchUserFavorRequest) {
updateUserFavorUseCase.execute(userId, patchUserFavorRequest);
}

@Operation(summary = "온보딩")
Expand Down Expand Up @@ -284,4 +294,10 @@ public UserOpinionVo getMyOpinion(
public List<UserOpinionVo> getMyAllOpinion() {
return retrieveUserOpinionUseCase.executeAll();
}

@Operation(summary = "친구들의 취향 상자 정보와 프로필 리스트를 조회합니다.")
@GetMapping("/neighbors/favors")
public List<RetrieveUserFavorBoxVo> getNeighborsFavorBox() {
return retrieveNeighborFavorBoxUseCase.execute();
}
}
15 changes: 15 additions & 0 deletions Api/src/main/java/tify/server/api/user/model/dto/UserFavorDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tify.server.api.user.model.dto;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import tify.server.domain.domains.user.domain.DetailCategory;

@Getter
@NoArgsConstructor
public class UserFavorDto {

@Schema(description = "취향의 종류입니다.", example = "LIP")
private DetailCategory detailCategory;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tify.server.api.user.model.dto.request;


import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.NoArgsConstructor;
import tify.server.api.user.model.dto.UserFavorDto;

@Getter
@NoArgsConstructor
public class PatchUserFavorRequest {

@NotNull private List<UserFavorDto> userFavorDtoList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@


import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.Getter;
import lombok.NoArgsConstructor;
import tify.server.api.user.model.dto.UserFavorDto;

@Getter
@NoArgsConstructor
Expand All @@ -28,4 +31,8 @@ public class UserOnBoardingRequest {

@NotBlank(message = "상태값을 입력해주세요.")
private String onBoardingState;

@Schema(description = "유저 취향 상자에 들어갈 소분류들입니다.")
@NotNull
private List<UserFavorDto> userFavorDtoList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package tify.server.api.user.model.dto.vo;


import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.Builder;
import lombok.Getter;
import tify.server.domain.domains.user.domain.DetailCategory;
import tify.server.domain.domains.user.domain.User;
import tify.server.domain.domains.user.domain.UserFavor;

@Getter
@Builder
public class RetrieveUserFavorBoxVo {

@Schema(description = "친구의 pk값입니다.", example = "1")
private final Long id;

@Schema(description = "친구의 프로필 이미지입니다.")
private final String thumbnail;

@Schema(description = "친구의 id입니다.", example = "@aaa")
private final String userId;

@Schema(description = "친구의 이름입니다.", example = "홍길동")
private final String userName;

@Schema(description = "친구의 취향 상자 정보입니다.", example = "PLACE, TOP, FAS_PRODUCT")
private final List<DetailCategory> userFavorList;

@Schema(description = "친구의 온보딩 상태 정보입니다.")
private final String userOnBoardingStatus;

public static RetrieveUserFavorBoxVo from(User user) {
return RetrieveUserFavorBoxVo.builder()
.id(user.getId())
.thumbnail(user.getProfile().getThumbNail())
.userId(user.getUserId())
.userName(user.getProfile().getUserName())
.userFavorList(
user.getUserFavors().stream().map(UserFavor::getDetailCategory).toList())
.userOnBoardingStatus(user.getOnBoardingStatus().getName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package tify.server.api.user.model.dto.vo;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import tify.server.domain.domains.user.domain.DetailCategory;
import tify.server.domain.domains.user.domain.LargeCategory;
import tify.server.domain.domains.user.domain.SmallCategory;
import tify.server.domain.domains.user.vo.UserFavorVo;

@Getter
@Builder
public class UserFavorBoxVo {

@Schema(description = "유저 취향 박스 내 취향의 pk값입니다.", example = "1")
private final Long userFavorId;

@Schema(description = "유저 취향 박스 내 취향의 대분류입니다.", example = "BEAUTY")
private final LargeCategory largeCategory;

@Schema(description = "유저 취향 박스 내 취향의 중분류입니다.", example = "MAKEUP")
private final SmallCategory smallCategory;

@Schema(description = "유저 취향 박스 내 취향의 소분류입니다.", example = "LIP")
private final DetailCategory detailCategory;

public static UserFavorBoxVo from(UserFavorVo userFavorVo) {
return UserFavorBoxVo.builder()
.userFavorId(userFavorVo.getUserFavor().getId())
.largeCategory(userFavorVo.getLargeCategory())
.smallCategory(userFavorVo.getUserFavor().getDetailCategory().getSmallCategory())
.detailCategory(userFavorVo.getUserFavor().getDetailCategory())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package tify.server.api.user.service;


import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import tify.server.api.config.security.SecurityUtils;
import tify.server.api.user.model.dto.vo.RetrieveUserFavorBoxVo;
import tify.server.core.annotation.UseCase;
import tify.server.domain.domains.user.adaptor.NeighborAdaptor;
import tify.server.domain.domains.user.adaptor.UserAdaptor;
import tify.server.domain.domains.user.adaptor.UserBlockAdaptor;
import tify.server.domain.domains.user.domain.Neighbor;
import tify.server.domain.domains.user.domain.UserBlock;
import tify.server.domain.domains.user.dto.condition.NeighborCondition;

@UseCase
@RequiredArgsConstructor
public class RetrieveNeighborFavorBoxUseCase {

private final UserAdaptor userAdaptor;
private final UserBlockAdaptor userBlockAdaptor;
private final NeighborAdaptor neighborAdaptor;

@Transactional(readOnly = true)
public List<RetrieveUserFavorBoxVo> execute() {
Long currentUserId = SecurityUtils.getCurrentUserId();

List<Long> blockedUserList =
userBlockAdaptor.queryAllByFromUserId(currentUserId).stream()
.map(UserBlock::getToUserId)
.toList();
List<Long> friendIdList =
neighborAdaptor.queryAllByToUserId(currentUserId).stream()
.map(Neighbor::getFromUserId)
.toList();
NeighborCondition neighborCondition =
new NeighborCondition(currentUserId, blockedUserList, friendIdList);

return userAdaptor.queryUserFavorBox(currentUserId, neighborCondition).stream()
.map(RetrieveUserFavorBoxVo::from)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package tify.server.api.user.service;


import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import tify.server.api.user.model.dto.request.PatchUserFavorRequest;
import tify.server.core.annotation.UseCase;
import tify.server.core.exception.BaseException;
import tify.server.domain.domains.user.adaptor.UserAdaptor;
import tify.server.domain.domains.user.adaptor.UserFavorAdaptor;
import tify.server.domain.domains.user.domain.User;
import tify.server.domain.domains.user.domain.UserFavor;
import tify.server.domain.domains.user.exception.UserException;

@UseCase
@RequiredArgsConstructor
public class UpdateUserFavorUseCase {

private final UserAdaptor userAdaptor;
private final UserFavorAdaptor userFavorAdaptor;

@Transactional
public void execute(Long userId, PatchUserFavorRequest body) {
if (body.getUserFavorDtoList().size() != 3) {
throw new BaseException(UserException.USER_FAVOR_UPDATE_ERROR);
}
User user = userAdaptor.query(userId);

List<UserFavor> updateFavors =
body.getUserFavorDtoList().stream()
.map(
dto ->
UserFavor.builder()
.user(user)
.detailCategory(dto.getDetailCategory())
.build())
.toList();
user.updateUserFavors(updateFavors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import tify.server.api.utils.UserUtils;
import tify.server.api.user.model.dto.vo.UserFavorBoxVo;
import tify.server.core.annotation.UseCase;
import tify.server.domain.domains.user.adaptor.UserAdaptor;
import tify.server.domain.domains.user.adaptor.UserFavorAdaptor;
import tify.server.domain.domains.user.domain.LargeCategory;
import tify.server.domain.domains.user.domain.User;
import tify.server.domain.domains.user.domain.UserTag;
import tify.server.domain.domains.user.vo.UserFavorVo;

@UseCase
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class UserFavorFilterUseCase {

private final UserUtils userUtils;
private final UserAdaptor userAdaptor;
private final UserFavorAdaptor userFavorAdaptor;

public List<UserFavorVo> execute(Long userId, LargeCategory largeCategory) {
// 유저를 끌고온다
@Transactional(readOnly = true)
public List<UserFavorBoxVo> execute(Long userId) {
User user = userAdaptor.query(userId);
// 유저의 Tag를 가져온다
List<UserTag> userTagList = user.getUserTags();
// largeCategory에 대한 UserFavorVo를 리턴한다
return userFavorAdaptor.queryByLargeCategory(largeCategory);
return userFavorAdaptor.queryAllByUser(user).stream()
.map(UserFavorVo::from)
.map(UserFavorBoxVo::from)
.toList();
}
}
Loading

0 comments on commit ff1a942

Please sign in to comment.