Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/NextLevel/demo/follow/FollowRepository.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package NextLevel.demo.follow;

import NextLevel.demo.user.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface FollowRepository extends JpaRepository<FollowEntity, Long> {
Expand All @@ -17,4 +19,11 @@ public interface FollowRepository extends JpaRepository<FollowEntity, Long> {
"from TagEntity t " +
"where t.id = 1 ")
SelectFollowCountAndIsFollowDao selectFollowCountAndFollowDao(@Param("targetUserId") Long targetUserId, @Param("userId") Long userId);

@Query("select f.user from FollowEntity f left join fetch f.user.img where f.target.id = :targetId")
List<UserEntity> gerFollowerList(@Param("targetId") Long targetId);

@Query("select f.target from FollowEntity f left join fetch f.target.img where f.user.id = :userId")
List<UserEntity> gerFollowList(@Param("userId") Long userId);

}
15 changes: 15 additions & 0 deletions src/main/java/NextLevel/demo/follow/FollowService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import NextLevel.demo.exception.CustomException;
import NextLevel.demo.exception.ErrorCode;
import NextLevel.demo.user.dto.user.response.UserProfileDto;
import NextLevel.demo.user.dto.user.response.UserSummeryInfoDto;
import NextLevel.demo.user.entity.UserEntity;
import NextLevel.demo.user.service.UserValidateService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
Expand Down Expand Up @@ -38,4 +41,16 @@ public void follow(long userId, long targetId, boolean follow) {
}
}

public List<UserProfileDto> followerList(Long targetUserId) {
userValidateService.findUserWithUserId(targetUserId);
List<UserEntity> followerList = followRepository.gerFollowerList(targetUserId);
return followerList.stream().map(UserProfileDto::of).toList();
}

public List<UserProfileDto> followList(Long userId) {
userValidateService.findUserWithUserId(userId);
List<UserEntity> followList = followRepository.gerFollowList(userId);
return followList.stream().map(UserProfileDto::of).toList();
}

}
13 changes: 13 additions & 0 deletions src/main/java/NextLevel/demo/user/controller/MypageController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package NextLevel.demo.user.controller;

import NextLevel.demo.common.SuccessResponse;
import NextLevel.demo.follow.FollowService;
import NextLevel.demo.project.project.dto.response.ProjectListWithFundingDto;
import NextLevel.demo.project.project.dto.response.ResponseProjectListDto;
import NextLevel.demo.user.dto.user.request.RequestMyPageProjectListDto;
Expand All @@ -12,6 +13,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -22,6 +24,7 @@
public class MypageController {

private final MypageProjectSelectService mypageProjectSelectService;
private final FollowService followService;

// 내가 좋아요한, 내가 최근 조회한, 내가 펀딩한(with funding) with tag
@PostMapping("/project")
Expand All @@ -38,4 +41,14 @@ public ResponseEntity<?> myPageProjectListMaker(@RequestBody @Valid RequestMyPag
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", mypageProjectSelectService.mapageProjectListWithFunding(dto)));
}

@GetMapping("/follow-list")
public ResponseEntity getMyFollowList() {
return ResponseEntity.ok().body(new SuccessResponse("success", followService.followList(JWTUtil.getUserIdFromSecurityContext())));
}

@GetMapping("/follower-list")
public ResponseEntity getMyFollowerList() {
return ResponseEntity.ok().body(new SuccessResponse("success", followService.followerList(JWTUtil.getUserIdFromSecurityContext())));
}

}
Loading