Skip to content

Commit

Permalink
[FIX] 유저 검색, 신고 관련 API 수정 (#88)
Browse files Browse the repository at this point in the history
* feat : User 관련 기능 API 작성 #83

* spotlessApply #83

* feat : User 차단 관련 검색, 조회 API 로직 변경 #83

* feat : User 신고 정보 조회 API 작성 #83

* spotless Apply #83

* edit : @transactional 추가 #83

* feat : 유저 검색 시 친구 여부 보여지도록 수정, 검색 로직 수정, 신고 api에서 request body 삭제 #83

* spotless Apply #83
  • Loading branch information
bongsh0112 authored Nov 5, 2023
1 parent a7b12a0 commit f2bdf31
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import tify.server.api.user.model.dto.request.PatchNeighborsOrdersRequest;
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.request.UserReportRequest;
import tify.server.api.user.model.dto.response.OnBoardingStatusResponse;
import tify.server.api.user.model.dto.vo.MutualFriendsVo;
import tify.server.api.user.model.dto.vo.UserReportInfoVo;
Expand Down Expand Up @@ -208,9 +207,8 @@ public void deleteUserBlock(@PathVariable Long toUserId) {

@Operation(summary = "유저를 신고합니다.")
@PostMapping("/report/{userId}")
public void postUserReport(
@PathVariable Long userId, @RequestBody @Valid UserReportRequest body) {
createUserReportUseCase.execute(userId, body);
public void postUserReport(@PathVariable Long userId) {
createUserReportUseCase.execute(userId);
}

@Operation(summary = "유저가 당한 신고의 정보를 조회합니다.")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ public class UserSearchInfoVo {
@Schema(description = "검색하여 찾은 친구와 함께 아는 친구 수")
private final int mutualFriends;

public static UserSearchInfoVo of(User user, int mutualFriends) {
@Schema(description = "검색하여 찾은 친구와의 친구 여부")
private final boolean isFriend;

public static UserSearchInfoVo of(User user, int mutualFriends, boolean isFriend) {
return UserSearchInfoVo.builder()
.id(user.getId())
.userId(user.getUserId())
.userName(user.getProfile().getUserName())
.imgUrl(user.getProfile().getThumbNail())
.mutualFriends(mutualFriends)
.isFriend(isFriend)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import tify.server.api.config.security.SecurityUtils;
import tify.server.api.user.model.dto.request.UserReportRequest;
import tify.server.core.annotation.UseCase;
import tify.server.domain.domains.user.adaptor.UserAdaptor;
import tify.server.domain.domains.user.adaptor.UserReportAdaptor;
import tify.server.domain.domains.user.domain.UserReport;
import tify.server.domain.domains.user.validator.UserValidator;
Expand All @@ -15,18 +15,14 @@
public class CreateUserReportUseCase {

private final UserReportAdaptor userReportAdaptor;
private final UserAdaptor userAdaptor;
private final UserValidator userValidator;

@Transactional
public void execute(Long userId, UserReportRequest body) {
public void execute(Long userId) {
Long currentUserId = SecurityUtils.getCurrentUserId();
userValidator.isValidUserId(body.getUserId());
userValidator.isValidUserId(userAdaptor.query(userId).getUserId());
userReportAdaptor.save(
UserReport.builder()
.fromUserId(currentUserId)
.toUserId(userId)
.title(body.getTitle())
.content(body.getContent())
.build());
UserReport.builder().fromUserId(currentUserId).toUserId(userId).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Slice<UserSearchInfoVo> execute(Pageable pageable, UserCondition conditio
.toList();

return userAdaptor
.searchUsers(pageable, condition)
.searchUsers(pageable, condition, userId)
.map(
user -> {
List<Long> findUserNeighbors =
Expand All @@ -43,7 +43,8 @@ public Slice<UserSearchInfoVo> execute(Pageable pageable, UserCondition conditio
myNeighbors.stream()
.filter(findUserNeighbors::contains)
.count();
return UserSearchInfoVo.of(user, mutualFriends);
boolean isFriend = neighborAdaptor.existsNeighbor(userId, user.getId());
return UserSearchInfoVo.of(user, mutualFriends, isFriend);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public List<UserOnBoardingStatusInfoVo> searchByKeyword(String keyword) {
return userOnBoardingStatusRepository.searchByKeyword(keyword);
}

public Slice<User> searchUsers(Pageable pageable, UserCondition condition) {
return userRepository.searchUsers(pageable, condition);
public Slice<User> searchUsers(Pageable pageable, UserCondition condition, Long currentUserId) {
return userRepository.searchUsers(pageable, condition, currentUserId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tify.server.domain.domains.user.domain;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand All @@ -28,17 +27,9 @@ public class UserReport extends AbstractTimeStamp {

@NotNull private Long toUserId;

@NotNull private String title;

@NotNull
@Column(columnDefinition = "TEXT")
private String content;

@Builder
public UserReport(Long fromUserId, Long toUserId, String title, String content) {
public UserReport(Long fromUserId, Long toUserId) {
this.fromUserId = fromUserId;
this.toUserId = toUserId;
this.title = title;
this.content = content;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

public interface UserCustomRepository {

Slice<User> searchUsers(Pageable pageable, UserCondition userCondition);
Slice<User> searchUsers(Pageable pageable, UserCondition userCondition, Long currentUserId);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package tify.server.domain.domains.user.repository;

import static tify.server.domain.domains.user.domain.QNeighbor.neighbor;
import static tify.server.domain.domains.user.domain.QUser.user;
import static tify.server.domain.domains.user.domain.QUserBlock.userBlock;
import static tify.server.domain.domains.user.domain.QUserOnBoardingStatus.userOnBoardingStatus;
import static tify.server.domain.domains.user.domain.QUserTag.userTag;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -22,19 +19,14 @@ public class UserCustomRepositoryImpl implements UserCustomRepository {
private final JPAQueryFactory jpaQueryFactory;

@Override
public Slice<User> searchUsers(Pageable pageable, UserCondition userCondition) {
public Slice<User> searchUsers(
Pageable pageable, UserCondition userCondition, Long currentUserId) {
List<User> contents =
jpaQueryFactory
.selectFrom(user)
.leftJoin(user.userTags, userTag)
.fetchJoin()
.leftJoin(user.onBoardingStatus, userOnBoardingStatus)
.fetchJoin()
.join(userBlock)
.on(userBlock.fromUserId.eq(neighbor.fromUserId))
.where(
userIdEquals(userCondition.getUserId()),
neighbor.toUserId.ne(userBlock.toUserId))
.leftJoin(userBlock)
.on(user.id.eq(userBlock.toUserId), userBlock.fromUserId.eq(currentUserId))
.where(userBlock.toUserId.isNull(), userIdEquals(userCondition.getUserId()))
.orderBy(user.id.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize() + 1)
Expand Down

0 comments on commit f2bdf31

Please sign in to comment.