이전에 임시로 만들어놨던 내 정보 페이지 꾸미기.
내 정보에서 보여줘야 할 것들
해당 데이터는 저장되어있기 때문에 가져올때 필터링 해서 가져오면된다.
@PreAuthorize("isAuthenticated()")
@GetMapping("/me")
public String me(Model model) {
if (!rq.getMember().hasConnectedInstaMember()) {
return rq.historyBack("먼저 본인의 인스타그램 아이디를 입력해주세요.");
}
InstaMember instaMember = rq.getMember().getInstaMember();
long likesByGenderWomen = instaMember.getToLikeablePeople().stream().filter(likeablePerson -> likeablePerson.getToInstaMember().getGender().equals("W")).count();
long likesByGenderMen = instaMember.getToLikeablePeople().stream().filter(likeablePerson -> likeablePerson.getToInstaMember().getGender().equals("M")).count();
long typeCode1 = instaMember.getToLikeablePeople().stream().filter(likeablePerson -> likeablePerson.getAttractiveTypeCode() == 1).count();
long typeCode2 = instaMember.getToLikeablePeople().stream().filter(likeablePerson -> likeablePerson.getAttractiveTypeCode() == 2).count();
long typeCode3 = instaMember.getToLikeablePeople().stream().filter(likeablePerson -> likeablePerson.getAttractiveTypeCode() == 3).count();
model.addAttribute("likes", likesByGenderWomen + likesByGenderMen);
model.addAttribute("likesByGenderWomen", likesByGenderWomen);
model.addAttribute("likesByGenderMen", likesByGenderMen);
model.addAttribute("likesByAttractiveTypeCode1", typeCode1);
model.addAttribute("likesByAttractiveTypeCode2", typeCode2);
model.addAttribute("likesByAttractiveTypeCode3", typeCode3);
return "user/member/me";
}
connect 부분
@Transactional
public RsData<InstaMember> connect(Member member, String username, String gender) {
Optional<InstaMember> opInstaMember = findByUsername(username);
if (opInstaMember.isPresent() && !opInstaMember.get().getGender().equals("U")) {
return RsData.of("F-5", "이미 다른 사용자와 연결되어있습니다.");
}
RsData<InstaMember> instaMemberRsData = findByUsernameOrCreate(username, gender);
memberService.UpdateInstaMember(member, instaMemberRsData.getData());
return instaMemberRsData;
}
만들어져있는 계정에 성별을 추가하는 부분
@Transactional
public RsData<InstaMember> findByUsernameOrCreate(String username, String gender) {
Optional<InstaMember> opInstaMember = findByUsername(username);
if (opInstaMember.isPresent()) {
InstaMember instaMember = opInstaMember.get();
instaMember.updateGender(gender);
instaMemberRepository.save(instaMember);
return RsData.of("S-2", "인스타 계정이 등록되었습니다.", instaMember);
}
return create(username, gender);
}