user 생성
user의 follow, unfollow controller 구현
public class UserRelationController {
private final UserRelationService userRelationService;
@PostMapping("/follow")
private Response<Void> followUser(@RequestBody @Valid FollowUserRequestDto dto){
userRelationService.follow(dto);
return Response.ok(null);
}
@PostMapping("/unfollow")
private Response<Void> unfollowUser(@RequestBody @Valid FollowUserRequestDto dto){
userRelationService.follow(dto);
return Response.ok(null);
}
user의 팔로우 생성
테이블 확인하여 user가 생성된 것을 확인 / follow count도 올라간 것을 확인 할 수 있다.
user의 unfollow 실행
테이블을 확인하여 user가 unfollow한 것을 확인 할 수 있다.
다시 실행을 했을 때 에러가 반환되는 것도 확인 하고 넘어가기
user의 follower리스트 조회
@GetMapping("/{userId}/follower")
public Response<List<GetUserListResponseDto>> getFollowers(@PathVariable(name = "userId") Long userId) {
List<GetUserListResponseDto> result = userListQueryRepository.getFollowerUserList(userId);
return Response.ok(result);
}
user3번의 follower리스트 반환
following 리스트 데이터 조회
@GetMapping("/{userId}/following")
public Response<List<GetUserListResponseDto>> getFollowings(@PathVariable(name = "userId") Long userId) {
List<GetUserListResponseDto> result = userListQueryRepository.getFollowingUserList(userId);
return Response.ok(result);
}
user1번의 following 조회
user 조회
public record GetUserResponseDto(Long id, String name, String profileImage ,Integer followingCount, Integer followersCount) {
public GetUserResponseDto(User user) {
this(user.getId(), user.name(), user.getProfileImage(), user.followingCount(), user.followerCount());
}
}
@GetMapping("/{userId}")
public Response<GetUserResponseDto> getUserProfile(@PathVariable(name = "userId") Long userId) {
return Response.ok(userService.getUserProfile(userId));
}
user의 조회 확인
'개발 > spring boot' 카테고리의 다른 글
comment 댓글 작성 / user별 게시글 리스트 작성 (0) | 2025.01.27 |
---|---|
post 글쓰기 (0) | 2025.01.27 |
에러 처리 (0) | 2025.01.22 |
querydsl (0) | 2025.01.19 |
querydsl (0) | 2025.01.17 |