Skip to content

Commit

Permalink
Merge pull request #132 from BETTER-iTER/feature/98
Browse files Browse the repository at this point in the history
[Feature/98] 마이페이지 profiel api 구현
  • Loading branch information
luke0408 authored Dec 30, 2023
2 parents f3925e6 + 70598f9 commit 7d2b94b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public List<Users> getFolloweeList(Users user) {
.map(Follow::getFollower)
.collect(Collectors.toList());
}
/**
* - 팔로우 여부 체크 메소드
**/

public boolean isFollow(Users follower, Users followee) {
return this.followReadRepository.existsByFollowerAndFollowee(follower,followee);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,18 @@ public ResponseDto<List<MypageResponse.FollowerDto>> getFollowee(
List<Users> followeeList = mypageService.getFolloweeList(id);
return ResponseDto.onSuccess(MypageResponseConverter.toFollowerDtoList(followeeList));
}

/**
* user profile 조회
*
* @param id 사용자 id
* @return MypageResponse.UserProfileDto
*/
@GetMapping("/profile/{id}")
public ResponseDto<MypageResponse.UserProfileDto> getUserProfile(
@PathVariable Long id
) {
MypageResponse.UserProfileDto result = mypageService.getUserProfile(id);
return ResponseDto.onSuccess(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.betteriter.fo_domain.mypage.dto.MypageResponse;
import com.example.betteriter.fo_domain.review.domain.Review;
import com.example.betteriter.fo_domain.user.domain.Users;
import lombok.extern.java.Log;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -40,4 +41,18 @@ public static List<MypageResponse.FollowerDto> toFollowerDtoList(List<Users> fol

return followerDtoList;
}

public static MypageResponse.UserProfileDto toUserProfileDto(
Users user, Boolean isFollow, Boolean isSelf, Long followerCount, Long followingCount
) {
return MypageResponse.UserProfileDto.builder()
.profileImage(user.getUsersDetail().getProfileImage())
.nickname(user.getUsersDetail().getNickName())
.job(user.getUsersDetail().getJob())
.followerCount(followerCount)
.followingCount(followingCount)
.isFollow(isFollow)
.isSelf(isSelf)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.betteriter.fo_domain.mypage.dto;

import com.example.betteriter.global.constant.Job;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -22,4 +23,17 @@ public static class FollowerDto {
private String profileImage;
private String nickname;
}

@Getter
@Builder
public static class UserProfileDto {
private String profileImage;
private String nickname;
private Job job;
private Long followerCount;
private Long followingCount;
private Boolean isFollow;
private Boolean isSelf;
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.example.betteriter.fo_domain.mypage.service;

import com.example.betteriter.fo_domain.follow.service.FollowService;
import com.example.betteriter.fo_domain.mypage.converter.MypageResponseConverter;
import com.example.betteriter.fo_domain.mypage.dto.MypageResponse;
import com.example.betteriter.fo_domain.review.domain.Review;
import com.example.betteriter.fo_domain.review.service.ReviewService;
import com.example.betteriter.fo_domain.user.domain.Users;
import com.example.betteriter.fo_domain.user.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -67,4 +71,26 @@ public boolean checkUserSelf(Long id) {
return user.getId().equals(id);
}

@Transactional(readOnly = true)
public MypageResponse.UserProfileDto getUserProfile(Long id) {
Users user = userService.getUserById(id);
Users currentUser = userService.getCurrentUser();

boolean isFollow = false;
boolean isSelf = true;

if (!Objects.equals(user.getId(), currentUser.getId())) {
isFollow = followService.isFollow(currentUser, user);
isSelf = false;
}

List<Users> followerList = followService.getFollowerList(user);
List<Users> followeeList = followService.getFolloweeList(user);

return MypageResponseConverter.toUserProfileDto(
user, isFollow, isSelf,
(long) followerList.size(),
(long) followeeList.size()
);
}
}

0 comments on commit 7d2b94b

Please sign in to comment.