1. 와이어 프레임
2. DB
3. API
4. 구현
1) 위치 / MBTI 궁합별 사용자 리스트
controller
- 프론트에서 GET 요청한 API 호출 ( @GetMapping("/api/chemy/list") )
- 로그인 한 사용자 정보로 서비스 호출
- 위치 / MBTI 궁합별 사용자 위치 정보 및 사용자 리스트 반환
@GetMapping("/api/chemy/list")
public ChemyAllResponseDto chemyList(@AuthenticationPrincipal UserDetailsImpl userDetails) {
return homeService.chemyList(userDetails.getUser());
}
service
- 로그인 한 사용자 MBTI 조회
- 조회된 MBTI 로 4번째 이상적 MBTI 까지 리스트 조회
- 로그인 한 사용자 위치, MBTI 리스트에 맞는 사용자 리스트 조회
- 사용자 리스트의 관심사 조회
- 위치 / MBTI 궁합별 사용자 위치 정보 및 사용자 리스트 반환
@Transactional
public ChemyAllResponseDto chemyList(User user) {
String mbtiChemy = user.getMbti().getMbti();
List<Mbti> findMbtiList = mbtiRepository.findAllByMbtiFirstOrMbtiSecondOrMbtiThirdOrMbtiForth(
mbtiChemy,
mbtiChemy,
mbtiChemy,
mbtiChemy);
List<User> findUserList = userRepository.findAllByLocationAndMbtiIn(user.getLocation(), findMbtiList);
List<ChemyUserListDto> chemyUserListDtos = new ArrayList<>();
for (User oneUser : findUserList) {
List<UserInterest> userInterestList = userInterestRepository.findAllByUser(oneUser);
List<InterestListDto> interestList = new ArrayList<>();
for (UserInterest userInterest : userInterestList) {
interestList.add(InterestListDto.builder()
.interest(userInterest.getInterest().getInterest())
.build());
}
chemyUserListDtos.add(ChemyUserListDto.builder()
.userId(oneUser.getId())
.nickname(oneUser.getNickname())
.profileImage(oneUser.getProfileImage())
.intro(oneUser.getIntro())
.location(oneUser.getLocation().getLocation())
.mbti(oneUser.getMbti().getMbti())
.interestList(interestList)
.build());
}
return ChemyAllResponseDto.builder()
.location(user.getLocation().getLocation())
.longitude(user.getLocation().getLongitude())
.latitude(user.getLocation().getLatitude())
.userCount(findUserList.size())
.userList(chemyUserListDtos)
.build();
}
2) 지역 선택
controller
- 프론트에서 GET 요청한 API 호출 ( @GetMapping("/api/chemy/list/{locationId}") )
- 로그인 한 사용자 정보, 선택한 위치 정보로 서비스 호출
- 위치 / MBTI 궁합별 위치 정보 및 사용자 리스트 반환
@GetMapping("/api/chemy/list/{locationId}")
public ChemyAllResponseDto locationList(@PathVariable Long locationId,
@AuthenticationPrincipal UserDetailsImpl userDetails) {
return homeService.locationList(locationId, userDetails.getUser());
}
service
- 선택한 위치 조회
- 로그인 한 사용자 MBTI 조회
- 조회된 MBTI 로 4번째 이상적 MBTI 까지 리스트 조회
- 선택한 위치, MBTI 리스트에 맞는 사용자 리스트 조회
- 사용자 리스트의 관심사 조회
- 위치 / MBTI 궁합별 사용자 위치 정보 및 사용자 리스트 반환
public ChemyAllResponseDto locationList(Long locationId, User user) {
Location location = locationRepository.findById(locationId).orElseThrow(
() -> new NullPointerException("해당 위치가 존재하지 않습니다.")
);
String mbtiChemy = user.getMbti().getMbti();
List<Mbti> findMbtiList = mbtiRepository.findAllByMbtiFirstOrMbtiSecondOrMbtiThirdOrMbtiForth(
mbtiChemy,
mbtiChemy,
mbtiChemy,
mbtiChemy);
List<User> findUserList = userRepository.findAllByLocationAndMbtiIn(location, findMbtiList);
List<ChemyUserListDto> chemyUserListDtos = new ArrayList<>();
for (User oneUser : findUserList) {
List<UserInterest> userInterestList = userInterestRepository.findAllByUser(oneUser);
List<InterestListDto> interestList = new ArrayList<>();
for (UserInterest userInterest : userInterestList) {
interestList.add(InterestListDto.builder()
.interest(userInterest.getInterest().getInterest())
.build());
}
chemyUserListDtos.add(ChemyUserListDto.builder()
.userId(oneUser.getId())
.nickname(oneUser.getNickname())
.profileImage(oneUser.getProfileImage())
.intro(oneUser.getIntro())
.location(oneUser.getLocation().getLocation())
.mbti(oneUser.getMbti().getMbti())
.interestList(interestList)
.build());
}
return ChemyAllResponseDto.builder()
.location(location.getLocation())
.longitude(location.getLongitude())
.latitude(location.getLatitude())
.userCount(findUserList.size())
.userList(chemyUserListDtos)
.build();
}
3) 사용자 리스트에서 선택
controller
- 프론트에서 GET 요청한 API 호출 ( @GetMapping("/api/chemy/{userId}") )
- 선택한 사용자 정보로 서비스 호출
- 사용자 정보 반환
@GetMapping("/api/chemy/{userId}")
public ChemyUserResponseDto chemyUser(@PathVariable Long userId) {
return chemyService.chemyUser(userId);
}
service
- 로그인 한 사용자 조회
- 관심사 조회
- 사용자 정보 반환
@Transactional
public ChemyUserResponseDto chemyUser(Long userId) {
User findUser = userRepository.getById(userId);
List<UserInterest> userInterestList = userInterestRepository.findAllByUser(findUser);
List<InterestListDto> interestList = new ArrayList<>();
for (UserInterest userInterest : userInterestList) {
interestList.add(InterestListDto.builder()
.interest(userInterest.getInterest().getInterest())
.build());
}
return ChemyUserResponseDto.builder()
.userId(findUser.getId())
.nickname(findUser.getNickname())
.profileImage(findUser.getProfileImage())
.gender(findUser.getGender())
.ageRange(findUser.getAgeRange())
.intro(findUser.getIntro())
.location(findUser.getLocation().getLocation())
.mbti(findUser.getMbti().getMbti())
.interestList(interestList)
.build();
}
4) 자동 매칭
controller
- 프론트에서 GET 요청한 API 호출 ( @GetMapping("/api/chemy/auto") )
- 로그인 한 사용자 정보로 서비스 호출
- 사용자 정보 반환
@GetMapping("/api/chemy/auto")
public ChemyUserResponseDto chemyAuto(@AuthenticationPrincipal UserDetailsImpl userDetails) {
return chemyService.chemyAuto(userDetails.getUser());
}
service
- 로그인 한 사용자 가장 이상적 MBTI 조회
- 사용자 위치와 가장 이상적 MBTI에 맞는 사용자 리스트 조회
- 사용자 리스트에서 랜덤 생성 (사용자 10명이면 0~9 랜덤 생성)
- 랜덤 사용자 관심사 조회
- 사용자 정보 반환
@Transactional
public ChemyUserResponseDto chemyAuto(User user) {
Mbti findMbti = mbtiRepository.findByMbtiFirst(user.getMbti().getMbti()).orElseThrow(
() -> new IllegalArgumentException("해당 MBTI가 존재하지 않습니다.")
);
List<User> findUserList = userRepository.findAllByLocationAndMbti(user.getLocation(), findMbti);
Random generator = new Random();
int size = generator.nextInt(findUserList.size());
List<UserInterest> userInterestList = userInterestRepository.findAllByUser(findUserList.get(size));
List<InterestListDto> interestList = new ArrayList<>();
for (UserInterest userInterest : userInterestList) {
interestList.add(InterestListDto.builder()
.interest(userInterest.getInterest().getInterest())
.build());
}
return ChemyUserResponseDto.builder()
.userId(findUserList.get(size).getId())
.nickname(findUserList.get(size).getNickname())
.profileImage(findUserList.get(size).getProfileImage())
.gender(findUserList.get(size).getGender())
.ageRange(findUserList.get(size).getAgeRange())
.intro(findUserList.get(size).getIntro())
.location(findUserList.get(size).getLocation().getLocation())
.mbti(findUserList.get(size).getMbti().getMbti())
.interestList(interestList)
.build();
}