프로젝트-Biz Chemy-매칭

Jonguk Kim·2022년 1월 3일
0

Project

목록 보기
3/3

1. 와이어 프레임

2. DB

3. API

4. 구현

1) 위치 / MBTI 궁합별 사용자 리스트

controller

  • 프론트에서 GET 요청한 API 호출 ( @GetMapping("/api/chemy/list") )
  • 로그인 한 사용자 정보로 서비스 호출
  • 위치 / MBTI 궁합별 사용자 위치 정보 및 사용자 리스트 반환
    // 전체 케미 리스트 (위치 / MBTI)
    @GetMapping("/api/chemy/list")
    public ChemyAllResponseDto chemyList(@AuthenticationPrincipal UserDetailsImpl userDetails) {
        return homeService.chemyList(userDetails.getUser());
    }

service

  • 로그인 한 사용자 MBTI 조회
  • 조회된 MBTI 로 4번째 이상적 MBTI 까지 리스트 조회
  • 로그인 한 사용자 위치, MBTI 리스트에 맞는 사용자 리스트 조회
  • 사용자 리스트의 관심사 조회
  • 위치 / MBTI 궁합별 사용자 위치 정보 및 사용자 리스트 반환
    // 케미 리스트 (위치 / MBTI 케미)
    @Transactional
    public ChemyAllResponseDto chemyList(User user) {
        // MBTI 이상적 궁합 리스트 4개까지 조회
        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 궁합별 위치 정보 및 사용자 리스트 반환
    // 선택한 지역 케미 리스트 (위치 / 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 궁합별 사용자 위치 정보 및 사용자 리스트 반환
    // 지역 케미 리스트 (위치 / MBTI)
    public ChemyAllResponseDto locationList(Long locationId, User user) {
        // 위치 조회
        Location location = locationRepository.findById(locationId).orElseThrow(
                () -> new NullPointerException("해당 위치가 존재하지 않습니다.")
        );

        // MBTI 이상적 궁합 리스트 4개까지 조회
        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 조회
        Mbti findMbti = mbtiRepository.findByMbtiFirst(user.getMbti().getMbti()).orElseThrow(
                () -> new IllegalArgumentException("해당 MBTI가 존재하지 않습니다.")
        );

        // 위치 / MBTI 와 가장 이상적인 사용자 리스트 조회
        List<User> findUserList = userRepository.findAllByLocationAndMbti(user.getLocation(), findMbti);
        // 사용자 리스트 수 범위만큼 랜덤 생성 (10 이면 0~9 랜덤 생성)
        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();
    }
profile
Just Do It

0개의 댓글