Skip to content

Commit 63b6c5e

Browse files
authored
Merge pull request #52 from DMU-NextLevel/feat/social-list
Feat/social list
2 parents 74ed3a9 + a10aa46 commit 63b6c5e

File tree

6 files changed

+77
-23
lines changed

6 files changed

+77
-23
lines changed

q

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
community-answer
2+
coupon
3+
feat/admin
4+
feat/project-status
5+
feat/recent-project
6+
* feat/social-list
7+
fix
8+
follow
9+
funding-rollback
10+
main
11+
mypage-maker
12+
project-detail
13+
query-test
14+
refactor-img
15+
refactor/funding
16+
refactor/project-all
17+
refactor/project-detail
18+
socket

src/main/java/NextLevel/demo/follow/FollowController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lombok.RequiredArgsConstructor;
77
import org.springframework.http.ResponseEntity;
88
import org.springframework.stereotype.Controller;
9+
import org.springframework.web.bind.annotation.GetMapping;
910
import org.springframework.web.bind.annotation.PostMapping;
1011
import org.springframework.web.bind.annotation.RequestBody;
1112

@@ -21,4 +22,14 @@ public ResponseEntity follow(@RequestBody @Valid FollowDto dto) {
2122
return ResponseEntity.ok().body(new SuccessResponse("success", null));
2223
}
2324

25+
@GetMapping("/social/user/follow-list")
26+
public ResponseEntity getMyFollowList() {
27+
return ResponseEntity.ok().body(new SuccessResponse("success", followService.followList(JWTUtil.getUserIdFromSecurityContext())));
28+
}
29+
30+
@GetMapping("/social/user/follower-list")
31+
public ResponseEntity getMyFollowerList() {
32+
return ResponseEntity.ok().body(new SuccessResponse("success", followService.followerList(JWTUtil.getUserIdFromSecurityContext())));
33+
}
34+
2435
}

src/main/java/NextLevel/demo/follow/FollowRepository.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,27 @@ public interface FollowRepository extends JpaRepository<FollowEntity, Long> {
2020
"where t.id = 1 ")
2121
SelectFollowCountAndIsFollowDao selectFollowCountAndFollowDao(@Param("targetUserId") Long targetUserId, @Param("userId") Long userId);
2222

23-
@Query("select f.user from FollowEntity f left join fetch f.user.img where f.target.id = :targetId")
24-
List<UserEntity> gerFollowerList(@Param("targetId") Long targetId);
25-
26-
@Query("select f.target from FollowEntity f left join fetch f.target.img where f.user.id = :userId")
27-
List<UserEntity> gerFollowList(@Param("userId") Long userId);
23+
@Query("select new NextLevel.demo.follow.ResponseFollowDto(" +
24+
"follower , " +
25+
"(select count(f1) from FollowEntity f1 where f1.target.id = follower.id and f1.user.id = :targetId) as isFollow " +
26+
")" +
27+
"from FollowEntity f " +
28+
"left join f.user follower " +
29+
"left join fetch follower.img " +
30+
"where f.target.id = :targetId " +
31+
"group by f.user")
32+
List<ResponseFollowDto> gerFollowerList(@Param("targetId") Long targetId);
33+
34+
@Query("select new NextLevel.demo.follow.ResponseFollowDto(" +
35+
"follow , " +
36+
"(select count(f1) from FollowEntity f1 where f1.user.id = follow.id and f1.target.id = :userId) as isFollow " +
37+
")" +
38+
"follow " +
39+
"from FollowEntity f " +
40+
"left join f.target follow " +
41+
"left join fetch follow.img " +
42+
"where f.user.id = :userId " +
43+
"group by follow")
44+
List<ResponseFollowDto> gerFollowList(@Param("userId") Long userId);
2845

2946
}

src/main/java/NextLevel/demo/follow/FollowService.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ public void follow(long userId, long targetId, boolean follow) {
4141
}
4242
}
4343

44-
public List<UserProfileDto> followerList(Long targetUserId) {
44+
public List<ResponseFollowDto> followerList(Long targetUserId) {
4545
userValidateService.findUserWithUserId(targetUserId);
46-
List<UserEntity> followerList = followRepository.gerFollowerList(targetUserId);
47-
return followerList.stream().map(UserProfileDto::of).toList();
46+
return followRepository.gerFollowerList(targetUserId);
4847
}
4948

50-
public List<UserProfileDto> followList(Long userId) {
49+
public List<ResponseFollowDto> followList(Long userId) {
5150
userValidateService.findUserWithUserId(userId);
52-
List<UserEntity> followList = followRepository.gerFollowList(userId);
53-
return followList.stream().map(UserProfileDto::of).toList();
51+
return followRepository.gerFollowList(userId);
5452
}
5553

5654
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package NextLevel.demo.follow;
2+
3+
import NextLevel.demo.user.dto.user.response.UserProfileDto;
4+
import NextLevel.demo.user.entity.UserEntity;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@NoArgsConstructor
10+
@Getter
11+
@Setter
12+
public class ResponseFollowDto {
13+
14+
private UserProfileDto user;
15+
private boolean isFollow;
16+
17+
public ResponseFollowDto (UserEntity user, Long isFollow) {
18+
this.user = UserProfileDto.of(user);
19+
this.isFollow = isFollow!=null?isFollow.equals(1L):false;
20+
}
21+
22+
}

src/main/java/NextLevel/demo/user/controller/MypageController.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
public class MypageController {
2525

2626
private final MypageProjectSelectService mypageProjectSelectService;
27-
private final FollowService followService;
2827

2928
// 내가 좋아요한, 내가 최근 조회한, 내가 펀딩한(with funding) with tag
3029
@PostMapping("/project")
@@ -40,15 +39,4 @@ public ResponseEntity<?> myPageProjectListMaker(@RequestBody @Valid RequestMyPag
4039
dto.setUserId(JWTUtil.getUserIdFromSecurityContext());
4140
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", mypageProjectSelectService.mapageProjectListWithFunding(dto)));
4241
}
43-
44-
@GetMapping("/follow-list")
45-
public ResponseEntity getMyFollowList() {
46-
return ResponseEntity.ok().body(new SuccessResponse("success", followService.followList(JWTUtil.getUserIdFromSecurityContext())));
47-
}
48-
49-
@GetMapping("/follower-list")
50-
public ResponseEntity getMyFollowerList() {
51-
return ResponseEntity.ok().body(new SuccessResponse("success", followService.followerList(JWTUtil.getUserIdFromSecurityContext())));
52-
}
53-
5442
}

0 commit comments

Comments
 (0)