From a6ef6ae986e61f0c0432c8f4cc450e4ff4484fa8 Mon Sep 17 00:00:00 2001 From: Yoon-Jemin Date: Sat, 10 Feb 2024 20:27:14 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=9D=B4?= =?UTF-8?q?=EB=A9=94=EC=9D=BC=EB=A1=9C=20=EC=A0=91=EA=B7=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umcproject/converter/FriendConverter.java | 17 ++++++ .../umcproject/entity/Friend.java | 2 +- .../repository/FriendRepository.java | 10 ++-- .../repository/MemberMissionRepository.java | 7 ++- .../FriendService/FriendCommandService.java | 8 +-- .../FriendCommandServiceImpl.java | 58 ++++++++---------- .../FriendService/FriendQueryService.java | 12 ++-- .../FriendService/FriendQueryServiceImpl.java | 37 ++++++++---- .../MissionService/MissionCommandService.java | 4 +- .../MissionCommandServiceImpl.java | 14 +++-- .../MissionService/MissionQueryService.java | 2 +- .../MissionQueryServiceImpl.java | 12 +++- .../RandomNicknameService.java | 3 +- .../web/controller/FriendController.java | 59 ++++++++----------- .../web/controller/MissionController.java | 16 ++--- .../web/controller/StoreController.java | 1 - 16 files changed, 142 insertions(+), 120 deletions(-) diff --git a/src/main/java/aromanticcat/umcproject/converter/FriendConverter.java b/src/main/java/aromanticcat/umcproject/converter/FriendConverter.java index 00e0449..3aa0f51 100644 --- a/src/main/java/aromanticcat/umcproject/converter/FriendConverter.java +++ b/src/main/java/aromanticcat/umcproject/converter/FriendConverter.java @@ -1,5 +1,7 @@ package aromanticcat.umcproject.converter; +import aromanticcat.umcproject.entity.FriendStatus; +import aromanticcat.umcproject.entity.Member; import aromanticcat.umcproject.repository.LetterBoxRepository; import aromanticcat.umcproject.web.dto.Friend.FriendResponseDTO; import aromanticcat.umcproject.entity.Friend; @@ -29,4 +31,19 @@ public static FriendResponseDTO.WaitingFriendDTO toWaitingFriendDTO(Friend frien .build(); } + public static Friend toFriend(Member fromMember, Member toMember, boolean isSend){ + + return Friend.builder() + .friendName(toMember.getNickname()) + .friendId(toMember.getId()) + .member(fromMember) + .fromMemberId(fromMember.getId()) + .fromMemberName(fromMember.getNickname()) + .toMemberId(toMember.getId()) + .toMemberName(toMember.getNickname()) + .friendStatus(FriendStatus.WAITING) + .isFrom(isSend) // true이면 fromMember가 false이면 toMember가 친구 요청을 보냄 + .build(); + } + } diff --git a/src/main/java/aromanticcat/umcproject/entity/Friend.java b/src/main/java/aromanticcat/umcproject/entity/Friend.java index c25f742..4e6e995 100644 --- a/src/main/java/aromanticcat/umcproject/entity/Friend.java +++ b/src/main/java/aromanticcat/umcproject/entity/Friend.java @@ -21,7 +21,7 @@ public class Friend extends BaseEntity { private String friendName; - private Long friendId; // 친구 아이디 + private Long friendId; // 친구 아이디 (우편함 번호) @JoinColumn(name = "member_id") @ManyToOne(fetch = FetchType.LAZY) diff --git a/src/main/java/aromanticcat/umcproject/repository/FriendRepository.java b/src/main/java/aromanticcat/umcproject/repository/FriendRepository.java index 5e5e510..9b5b3dc 100644 --- a/src/main/java/aromanticcat/umcproject/repository/FriendRepository.java +++ b/src/main/java/aromanticcat/umcproject/repository/FriendRepository.java @@ -15,13 +15,13 @@ public interface FriendRepository extends JpaRepository { @Query("SELECT f FROM Friend f WHERE f.member.id = :memberId AND f.friendStatus IN (:friendStatus)") - Page findFriendByMemberIdAndFriendStatus(Long memberId, Pageable pageable, Set friendStatus); + Page findFriendByMemberAndFriendStatus(Member member, Pageable pageable, Set friendStatus); - Page findFriendByMemberIdAndFriendStatus(Long memberId, Pageable pageable, FriendStatus friendStatus); + Page findFriendByMemberAndFriendStatus(Member member, Pageable pageable, FriendStatus friendStatus); - List findFriendByMemberIdAndFriendName(Long memberId, String friendName); + List findFriendByMemberAndFriendName(Member member, String friendName); - List findFriendByMemberIdAndFriendId(Long memberId, Long friendId); + List findFriendByMemberAndFriendId(Member member, Long friendId); - Friend findByMemberIdAndFriendId(Long memberId, Long friendId); + Friend findByMemberAndFriendId(Member member, Long friendId); } diff --git a/src/main/java/aromanticcat/umcproject/repository/MemberMissionRepository.java b/src/main/java/aromanticcat/umcproject/repository/MemberMissionRepository.java index 2438a8b..de32acd 100644 --- a/src/main/java/aromanticcat/umcproject/repository/MemberMissionRepository.java +++ b/src/main/java/aromanticcat/umcproject/repository/MemberMissionRepository.java @@ -1,5 +1,6 @@ package aromanticcat.umcproject.repository; +import aromanticcat.umcproject.entity.Member; import aromanticcat.umcproject.entity.MemberMission; import org.springframework.data.jpa.repository.JpaRepository; @@ -7,8 +8,8 @@ public interface MemberMissionRepository extends JpaRepository { - List findByMemberId(Long memberId); - MemberMission findByMemberIdAndMissionId(Long memberId, Long missionId); + List findByMember(Member member); + MemberMission findByMemberAndMissionId(Member member, Long missionId); - Boolean existsByMemberIdAndMissionId(Long memberId, Long missionId); + Boolean existsByMemberAndMissionId(Member member, Long missionId); } diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java index 1138ac1..f87a511 100644 --- a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java @@ -5,11 +5,11 @@ public interface FriendCommandService { - void requestFriendship(Long memberId,Long toMemberLetterBoxId); + void requestFriendship(String userEmail,Long toMemberLetterBoxId); - void approveFriendship(Long memberId, Long friendId); + void approveFriendship(String userEmail, Long friendId); - void rejectFriendship(Long memberId, Long friendId); + void rejectFriendship(String userEmail, Long friendId); - void setCloseFriend(Long memberId, Long friendId); + void setCloseFriend(String userEmail, Long friendId); } diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java index 7b7f988..df23ebd 100644 --- a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java @@ -1,5 +1,6 @@ package aromanticcat.umcproject.service.FriendService; +import aromanticcat.umcproject.converter.FriendConverter; import aromanticcat.umcproject.entity.Friend; import aromanticcat.umcproject.entity.FriendStatus; import aromanticcat.umcproject.entity.Member; @@ -18,41 +19,26 @@ public class FriendCommandServiceImpl implements FriendCommandService { private final MemberRepository memberRepository; private final FriendRepository friendRepository; + public Member getMember(String email){ + return memberRepository.findByEmail(email) + .orElseThrow(() -> new RuntimeException("사용자를 찾을 수 없습니다. ID: " + email)); + } + @Override @Transactional - public void requestFriendship(Long memberId, Long toMemberId) { + public void requestFriendship(String userEmail, Long toMemberId) { // 친구 요청을 보내는 사용자 - Member fromMember = memberRepository.findById(memberId).orElse(null); + Member fromMember = getMember(userEmail); // 친구 요청을 받는 사용자 Member toMember = memberRepository.findById(toMemberId).orElse(null); - // dto의 정보를 기반으로 새로운 친구 객체 생성1 (fromMember 기준) - Friend newFriend1 = Friend.builder() - .friendName(toMember.getNickname()) - .friendId(toMemberId) - .member(fromMember) - .fromMemberId(fromMember.getId()) - .fromMemberName(fromMember.getNickname()) - .toMemberId(toMember.getId()) - .toMemberName(toMember.getNickname()) - .friendStatus(FriendStatus.WAITING) - .isFrom(true) // true이면 fromMember가 친구 요청을 보냄 - .build(); - - // dto의 정보를 기반으로 새로운 친구 객체 생성2 (toMember 기준) - Friend newFriend2 = Friend.builder() - .friendName(fromMember.getNickname()) - .friendId(fromMember.getId()) - .member(toMember) - .fromMemberId(toMember.getId()) - .fromMemberName(toMember.getNickname()) - .toMemberId(fromMember.getId()) - .toMemberName(fromMember.getNickname()) - .friendStatus(FriendStatus.WAITING) - .isFrom(false) // false이면 toMember가 친구 요청을 보냄 - .build(); + // 새로운 친구 객체 생성1 (fromMember 기준) + Friend newFriend1 = FriendConverter.toFriend(fromMember, toMember, true); + + // 새로운 친구 객체 생성2 (toMember 기준) + Friend newFriend2 = FriendConverter.toFriend(toMember, fromMember, false); // 각 사용자의 친구 리스트에 새로 만든 친구 객체 추가 toMember.getFriends().add(newFriend1); @@ -68,9 +54,11 @@ public void requestFriendship(Long memberId, Long toMemberId) { @Override @Transactional - public void approveFriendship(Long memberId, Long friendId) { // 친구 요청을 승인한 경우 + public void approveFriendship(String userEmail, Long friendId) { // 친구 요청을 승인한 경우 - Friend newFriend = friendRepository.findByMemberIdAndFriendId(memberId, friendId); + Member member = getMember(userEmail); + + Friend newFriend = friendRepository.findByMemberAndFriendId(member, friendId); Friend counterpart = friendRepository.findById(newFriend.getCounterpartId()).orElse(null); newFriend.changeFriendStatus(FriendStatus.APPROVED); @@ -80,9 +68,11 @@ public void approveFriendship(Long memberId, Long friendId) { // 친구 요청 @Override @Transactional - public void rejectFriendship(Long memberId, Long friendId) { + public void rejectFriendship(String userEmail, Long friendId) { + + Member member = getMember(userEmail); - Friend newFriend = friendRepository.findByMemberIdAndFriendId(memberId, friendId); + Friend newFriend = friendRepository.findByMemberAndFriendId(member, friendId); Friend counterpart = friendRepository.findById(newFriend.getCounterpartId()).orElse(null); newFriend.changeFriendStatus(FriendStatus.REJECTED); @@ -92,9 +82,11 @@ public void rejectFriendship(Long memberId, Long friendId) { @Override @Transactional - public void setCloseFriend(Long memberId, Long friendId) { + public void setCloseFriend(String userEmail, Long friendId) { + + Member member = getMember(userEmail); - Friend friend = friendRepository.findByMemberIdAndFriendId(memberId, friendId); + Friend friend = friendRepository.findByMemberAndFriendId(member, friendId); friend.changeFriendStatus(FriendStatus.CLOSE_FRIEND); diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryService.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryService.java index c3d84f9..85d0702 100644 --- a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryService.java +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryService.java @@ -11,15 +11,15 @@ public interface FriendQueryService { - List getFriendReceivedList(Long memberId); + List getFriendReceivedList(String userEmail); - List getFriendRequestedList(Long memberId); + List getFriendRequestedList(String userEmail); - List findFriendList(Long memberId, Integer page); + List findFriendList(String userEmail, Integer page); - List findCloseFriendList(Long memberId, Integer page); + List findCloseFriendList(String userEmail, Integer page); - List getFriendbyFriendName(Long memberId, String friendName); + List getFriendbyFriendName(String userEmail, String friendName); - List getFriendbyFriendId(Long memberId, Long friendId); + List getFriendbyFriendId(String userEmail, Long friendId); } diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryServiceImpl.java index 3a62303..8c5075c 100644 --- a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryServiceImpl.java +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendQueryServiceImpl.java @@ -25,12 +25,17 @@ public class FriendQueryServiceImpl implements FriendQueryService { private final MemberRepository memberRepository; private final FriendRepository friendRepository; + public Member getMember(String email){ + return memberRepository.findByEmail(email) + .orElseThrow(() -> new RuntimeException("사용자를 찾을 수 없습니다. ID: " + email)); + } + @Override @Transactional - public List getFriendReceivedList(Long memberId) { // 요청 받은 친구 정보만 가져오기 + public List getFriendReceivedList(String userEmail) { // 요청 받은 친구 정보만 가져오기 // 해당 API를 요청한 사용자 객체를 가져온 뒤 해당 객체의 친구 리스트를 가져옴 - Member member = memberRepository.findById(memberId).orElse(null); + Member member = getMember(userEmail); List friendList = member.getFriends(); List results = new ArrayList<>(); @@ -46,10 +51,10 @@ public List getFriendReceivedList(Long memberId) { // 요청 받은 @Override @Transactional - public List getFriendRequestedList(Long memberId) { + public List getFriendRequestedList(String userEmail) { // 해당 API를 요청한 사용자 객체를 가져온 뒤 해당 객체의 친구 리스트를 가져옴 - Member member = memberRepository.findById(memberId).orElse(null); + Member member = getMember(userEmail); List friendList = member.getFriends(); List results = new ArrayList<>(); @@ -65,7 +70,9 @@ public List getFriendRequestedList(Long memberId) { @Override @Transactional - public List findFriendList(Long memberId, Integer page) { + public List findFriendList(String userEmail, Integer page) { + + Member member = getMember(userEmail); // page는 페이지의 번호, 12는 한 페이지에 보여줄 친구의 수 Pageable pageable = PageRequest.of(page,12); @@ -75,7 +82,7 @@ public List findFriendList(Long memberId, Integ friendStatus.add(FriendStatus.APPROVED); friendStatus.add(FriendStatus.CLOSE_FRIEND); - Page friendPage = friendRepository.findFriendByMemberIdAndFriendStatus(memberId, pageable, friendStatus); + Page friendPage = friendRepository.findFriendByMemberAndFriendStatus(member, pageable, friendStatus); List friendList = friendPage.getContent(); @@ -89,12 +96,14 @@ public List findFriendList(Long memberId, Integ @Override @Transactional - public List findCloseFriendList(Long memberId, Integer page) { + public List findCloseFriendList(String userEmail, Integer page) { + + Member member = getMember(userEmail); // page는 페이지의 번호, 12는 한 페이지에 보여줄 친구의 수 Pageable pageable = PageRequest.of(page,12); - Page friendPage = friendRepository.findFriendByMemberIdAndFriendStatus(memberId, pageable, FriendStatus.CLOSE_FRIEND); + Page friendPage = friendRepository.findFriendByMemberAndFriendStatus(member, pageable, FriendStatus.CLOSE_FRIEND); List friendList = friendPage.getContent(); @@ -107,9 +116,11 @@ public List findCloseFriendList(Long memberId, } @Override - public List getFriendbyFriendName(Long memberId, String friendName) { // 중복된 이름이 있을 수 있으므로 List 반환 + public List getFriendbyFriendName(String userEmail, String friendName) { // 중복된 이름이 있을 수 있으므로 List 반환 + + Member member = getMember(userEmail); - List friendList = friendRepository.findFriendByMemberIdAndFriendName(memberId, friendName); + List friendList = friendRepository.findFriendByMemberAndFriendName(member, friendName); List friendInfoDTOList = friendList.stream() .map(FriendConverter::toFriendInfoDTO) @@ -120,9 +131,11 @@ public List getFriendbyFriendName(Long memberId } @Override - public List getFriendbyFriendId(Long memberId, Long friendId) { + public List getFriendbyFriendId(String userEmail, Long friendId) { + + Member member = getMember(userEmail); - List friendList = friendRepository.findFriendByMemberIdAndFriendId(memberId, friendId); + List friendList = friendRepository.findFriendByMemberAndFriendId(member, friendId); List friendInfoDTOList = friendList.stream() .map(FriendConverter::toFriendInfoDTO) diff --git a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandService.java b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandService.java index 2ae9216..6f32657 100644 --- a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandService.java +++ b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandService.java @@ -1,5 +1,7 @@ package aromanticcat.umcproject.service.MissionService; +import aromanticcat.umcproject.entity.Member; + public interface MissionCommandService { - void stepCompleted(Long memberId, Long missionId); + void stepCompleted(String userEmail, Long missionId); } diff --git a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandServiceImpl.java index 0f2177f..24703cb 100644 --- a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandServiceImpl.java +++ b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandServiceImpl.java @@ -21,12 +21,18 @@ public class MissionCommandServiceImpl implements MissionCommandService{ private final MemberRepository memberRepository; private final MissionRepository missionRepository; + public Member getMember(String email){ + return memberRepository.findByEmail(email) + .orElseThrow(() -> new RuntimeException("사용자를 찾을 수 없습니다. ID: " + email)); + } + @Override @Transactional - public void stepCompleted(Long memberId, Long missionId) { // 미션 안에서 step 하나를 완료 + public void stepCompleted(String userEmail, Long missionId) { // 미션 안에서 step 하나를 완료 + + Member member = getMember(userEmail); - Boolean isExist = memberMissionRepository.existsByMemberIdAndMissionId(memberId, missionId); - Member member = memberRepository.findById(memberId).orElse(null); + Boolean isExist = memberMissionRepository.existsByMemberAndMissionId(member, missionId); Mission mission = missionRepository.findById(missionId).orElse(null); if (!isExist) { // 처음 시작된 미션인 경우 @@ -34,7 +40,7 @@ public void stepCompleted(Long memberId, Long missionId) { // 미션 안에 memberMissionRepository.save(newMemberMission); } - MemberMission memberMission = memberMissionRepository.findByMemberIdAndMissionId(memberId, missionId); + MemberMission memberMission = memberMissionRepository.findByMemberAndMissionId(member, missionId); if (memberMission.getMissionStatus() == MissionStatus.COMPLETED) { throw new RuntimeException("미션이 이미 완료되었습니다. 미션 ID: " + missionId); diff --git a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionQueryService.java b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionQueryService.java index 52587ed..513257b 100644 --- a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionQueryService.java +++ b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionQueryService.java @@ -5,7 +5,7 @@ import java.util.List; public interface MissionQueryService { - List findMissionList(Long memberId); + List findMissionList(String userEmail); MissionResponseDTO.MissionDetailsDTO findMissionDetails(Long missionId); } diff --git a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionQueryServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionQueryServiceImpl.java index 360f4be..1f227de 100644 --- a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionQueryServiceImpl.java +++ b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionQueryServiceImpl.java @@ -20,13 +20,21 @@ public class MissionQueryServiceImpl implements MissionQueryService{ private final MissionRepository missionRepository; private final MemberMissionRepository memberMissionRepository; + private final MemberRepository memberRepository; + + public Member getMember(String email){ + return memberRepository.findByEmail(email) + .orElseThrow(() -> new RuntimeException("사용자를 찾을 수 없습니다. ID: " + email)); + } @Override @Transactional - public List findMissionList(Long memberId) { + public List findMissionList(String userEmail) { + + Member member = getMember(userEmail); // 사용자가 참여한 미션 목록 조회 - List memberMissionList = memberMissionRepository.findByMemberId(memberId); + List memberMissionList = memberMissionRepository.findByMember(member); // 모든 미션 목록 조회 List allMissionList = missionRepository.findAll(); diff --git a/src/main/java/aromanticcat/umcproject/service/nangmanLetterboxService/RandomNicknameService.java b/src/main/java/aromanticcat/umcproject/service/nangmanLetterboxService/RandomNicknameService.java index b390d64..f1ae63d 100644 --- a/src/main/java/aromanticcat/umcproject/service/nangmanLetterboxService/RandomNicknameService.java +++ b/src/main/java/aromanticcat/umcproject/service/nangmanLetterboxService/RandomNicknameService.java @@ -26,8 +26,7 @@ public class RandomNicknameService { public String generateRandomNickname() { Random random = new Random(); String adjective = ADJECTIVES[random.nextInt(ADJECTIVES.length)]; - String animal = ANIMALS[random.nextInt(ANIMALS.length)] - ; + String animal = ANIMALS[random.nextInt(ANIMALS.length)]; return adjective + " " + animal; } } diff --git a/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java b/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java index 0cebd8d..6aba573 100644 --- a/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java +++ b/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java @@ -5,6 +5,7 @@ import aromanticcat.umcproject.converter.FriendConverter; import aromanticcat.umcproject.entity.Friend; import aromanticcat.umcproject.service.FriendService.FriendCommandService; +import aromanticcat.umcproject.service.MemberService; import aromanticcat.umcproject.web.dto.Friend.FriendRequestDTO; import aromanticcat.umcproject.web.dto.Friend.FriendResponseDTO; import aromanticcat.umcproject.service.FriendService.FriendQueryService; @@ -26,6 +27,7 @@ public class FriendController { private final FriendQueryService friendQueryService; private final FriendCommandService friendCommandService; + private final MemberService memberService; @GetMapping("/") @Operation(summary = "사용자의 주소록에 있는 친구들 조회 API", description = "페이징 포함을 포함합니다, query String으로 page 번호를 주세요.") @@ -34,11 +36,10 @@ public class FriendController { }) public ApiResponse> getFriendList(@RequestParam(value = "page", defaultValue = "0") Integer page){ try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); // 요청 받은 페이지의 친구 수를 가져옴 - List friendDTOList = friendQueryService.findFriendList(memberId, page); + List friendDTOList = friendQueryService.findFriendList(userEmail, page); // 성공 응답 생성 return ApiResponse.onSuccess(friendDTOList); @@ -56,11 +57,10 @@ public ApiResponse> getFriendList(@Request public ApiResponse> getCloseFriendList(@RequestParam(value = "page", defaultValue = "0") Integer page){ try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); // 요청 받은 페이지의 친구 수를 가져옴 - List friendDTOList = friendQueryService.findCloseFriendList(memberId, page); + List friendDTOList = friendQueryService.findCloseFriendList(userEmail, page); // 성공 응답 생성 return ApiResponse.onSuccess(friendDTOList); @@ -77,17 +77,16 @@ public ApiResponse> getCloseFriendList(@Re }) public ApiResponse> getFriendbyName(@RequestParam(value = "friend_info") String friendInfo){ try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); List friendInfoDTOList; // 검색하고자 하는 친구 정보와 관련된 DTO 선언 if(friendInfo.startsWith("#")){ // 친구 아이디(우편 번호)으로 친구 검색 String friendIdString = friendInfo.substring(1); // "#"을 제외한 문자열 Long friendId = Long.parseLong(friendIdString); // Long 타입으로 변환 - friendInfoDTOList = friendQueryService.getFriendbyFriendId(memberId, friendId); + friendInfoDTOList = friendQueryService.getFriendbyFriendId(userEmail, friendId); } else { // 친구 이름(닉네임)으로 친구 검색 - friendInfoDTOList = friendQueryService.getFriendbyFriendName(memberId, friendInfo); + friendInfoDTOList = friendQueryService.getFriendbyFriendName(userEmail, friendInfo); } // 성공 응답 생성 @@ -105,11 +104,10 @@ public ApiResponse> getFriendbyName(@Reque }) public ApiResponse sendFriendRequest(@RequestParam(value = "to_member_Id") Long toMemberId){ try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); // 친구 요청 보낸기 - friendCommandService.requestFriendship(memberId, toMemberId); + friendCommandService.requestFriendship(userEmail, toMemberId); // 성공 응답 생성 return ApiResponse.onSuccess("친구 요청이 성공적으로 보내졌습니다."); @@ -123,11 +121,10 @@ public ApiResponse sendFriendRequest(@RequestParam(value = "to_member_Id @Operation(summary = "사용자가 친구 추가 받은 요청 조회 API") public ApiResponse> getReceivedFriendList() { try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); // 친구 요청을 보낸 사용자들의 목록 조회 - List friendList = friendQueryService.getFriendReceivedList(memberId); + List friendList = friendQueryService.getFriendReceivedList(userEmail); // 친구 정보를 간략하게 변환 List waitingFriendDTOS = friendList.stream() @@ -147,11 +144,10 @@ public ApiResponse> getReceivedFriendLi public ApiResponse> getRequestedFriendList() { try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); // 친구 요청을 보낸 사용자들의 목록 조회 - List friendList = friendQueryService.getFriendRequestedList(memberId); + List friendList = friendQueryService.getFriendRequestedList(userEmail); // 친구 정보를 간략하게 변환 List waitingFriendDTOS = friendList.stream() @@ -173,11 +169,10 @@ public ApiResponse> getRequestedFriendL }) public ApiResponse approveFriendRequest(@RequestParam(value = "friend_id") Long friendId){ try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); - // 친구 요청 보낸기 - friendCommandService.approveFriendship(memberId, friendId); + // 친구 요청 수락하기 + friendCommandService.approveFriendship(userEmail, friendId); // 성공 응답 생성 return ApiResponse.onSuccess("친구 요청이 성공적으로 수락되었습니다."); @@ -194,11 +189,10 @@ public ApiResponse approveFriendRequest(@RequestParam(value = "friend_id }) public ApiResponse rejectFriendRequest(@RequestParam(value = "friend_id") Long friendId) { try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); - // 친구 요청 보낸기 - friendCommandService.rejectFriendship(memberId, friendId); + // 친구 요청 거절하기 + friendCommandService.rejectFriendship(userEmail, friendId); // 성공 응답 생성 return ApiResponse.onSuccess("친구 요청이 성공적으로 거절 되었습니다."); @@ -215,11 +209,10 @@ public ApiResponse rejectFriendRequest(@RequestParam(value = "friend_id" }) public ApiResponse registerCloseFriend(@RequestParam(value = "friend_id") Long friendId){ try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); - // 친구 요청 보내기 - friendCommandService.setCloseFriend(memberId, friendId); + // 친한 친구로 등록하기 + friendCommandService.setCloseFriend(userEmail, friendId); // 성공 응답 생성 return ApiResponse.onSuccess("친구를 친한 친구로 등록하는데 성공했습니다."); @@ -229,8 +222,4 @@ public ApiResponse registerCloseFriend(@RequestParam(value = "friend_id" } } - // 스프링 시큐리티 구현 전 임시 메서드 - private Long getCurrentUserId(){ - return 1L; - } } diff --git a/src/main/java/aromanticcat/umcproject/web/controller/MissionController.java b/src/main/java/aromanticcat/umcproject/web/controller/MissionController.java index a28a7e6..274923c 100644 --- a/src/main/java/aromanticcat/umcproject/web/controller/MissionController.java +++ b/src/main/java/aromanticcat/umcproject/web/controller/MissionController.java @@ -1,6 +1,7 @@ package aromanticcat.umcproject.web.controller; import aromanticcat.umcproject.apiPayload.ApiResponse; +import aromanticcat.umcproject.service.MemberService; import aromanticcat.umcproject.service.MissionService.MissionCommandService; import aromanticcat.umcproject.service.MissionService.MissionQueryService; import aromanticcat.umcproject.web.dto.Mission.MissionResponseDTO; @@ -20,16 +21,16 @@ public class MissionController { private final MissionQueryService missionQueryService; private final MissionCommandService missionCommandService; + private final MemberService memberService; @GetMapping("/") @Operation(summary = "미션 목록 조회 API", description = "모든 미션을 조회합니다.") public ApiResponse> getAllMissions() { try{ - // 로그인한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); // 모든 미션 가져오기 - List MissionList = missionQueryService.findMissionList(memberId); + List MissionList = missionQueryService.findMissionList(userEmail); // 성공 응답 가져오기 return ApiResponse.onSuccess(MissionList); @@ -58,10 +59,9 @@ public ApiResponse MissionDetails(@PathVar @Operation(summary = "미션 한 단계 완료 API", description = "특정 미션의 한 스텝이 완료된 것을 적용합니다. 미션의 모든 단계가 완료 되었으면 보상으로 코인이 주어집니다.") public ApiResponse MissionStepCompleted(@PathVariable Long missionId){ try{ - // 로그인 한 사용자의 아이디를 가져오는 임시 메서드 - Long memberId = getCurrentUserId(); + String userEmail = memberService.getUserInfo().getEmail(); - missionCommandService.stepCompleted(memberId, missionId); + missionCommandService.stepCompleted(userEmail, missionId); return ApiResponse.onSuccess("미션의 한 단계 완료가 성공적으로 적용되었습니다."); @@ -70,8 +70,4 @@ public ApiResponse MissionStepCompleted(@PathVariable Long missionId){ } } - // 스프링 시큐리티 구현 전 임시 메서드 - private Long getCurrentUserId(){ - return 1L; - } } diff --git a/src/main/java/aromanticcat/umcproject/web/controller/StoreController.java b/src/main/java/aromanticcat/umcproject/web/controller/StoreController.java index 6ca55b9..d0568cd 100644 --- a/src/main/java/aromanticcat/umcproject/web/controller/StoreController.java +++ b/src/main/java/aromanticcat/umcproject/web/controller/StoreController.java @@ -79,7 +79,6 @@ public ApiResponse purchasedStamp(@PathVariable Long stampId) { try{ String userEmail = memberService.getUserInfo().getEmail(); - storeService.purchasedStamp(userEmail, stampId); return ApiResponse.onSuccess("우표를 성공적으로 구매하였습니다.");