diff --git a/src/main/java/jungle/HandTris/application/impl/MemberServiceImpl.java b/src/main/java/jungle/HandTris/application/impl/AuthServiceImpl.java similarity index 94% rename from src/main/java/jungle/HandTris/application/impl/MemberServiceImpl.java rename to src/main/java/jungle/HandTris/application/impl/AuthServiceImpl.java index 5cf13e5..f9ba0f5 100644 --- a/src/main/java/jungle/HandTris/application/impl/MemberServiceImpl.java +++ b/src/main/java/jungle/HandTris/application/impl/AuthServiceImpl.java @@ -2,8 +2,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.transaction.Transactional; +import jungle.HandTris.application.service.AuthService; import jungle.HandTris.application.service.BCryptPasswordService; -import jungle.HandTris.application.service.MemberService; import jungle.HandTris.domain.Member; import jungle.HandTris.domain.MemberRecord; import jungle.HandTris.domain.exception.*; @@ -21,7 +21,7 @@ @Service @RequiredArgsConstructor @Transactional -public class MemberServiceImpl implements MemberService { +public class AuthServiceImpl implements AuthService { private final MemberRepository memberRepository; private final MemberRecordRepository memberRecordRepository; private final BCryptPasswordService bCryptPasswordService; @@ -30,7 +30,7 @@ public class MemberServiceImpl implements MemberService { private String defaultImage; @Override - public Pair signin (MemberRequest memberRequest) { + public Pair signin(MemberRequest memberRequest) { String username = memberRequest.username(); String password = memberRequest.password(); diff --git a/src/main/java/jungle/HandTris/application/impl/MemberProfileServiceImpl.java b/src/main/java/jungle/HandTris/application/impl/MemberProfileServiceImpl.java index d9b1626..33df3b8 100644 --- a/src/main/java/jungle/HandTris/application/impl/MemberProfileServiceImpl.java +++ b/src/main/java/jungle/HandTris/application/impl/MemberProfileServiceImpl.java @@ -10,15 +10,13 @@ import jungle.HandTris.domain.repo.MemberRepository; import jungle.HandTris.global.jwt.JWTUtil; import jungle.HandTris.presentation.dto.request.MemberUpdateReq; -import jungle.HandTris.presentation.dto.response.MemberDetailRes; -import jungle.HandTris.presentation.dto.response.MemberProfileDetailsRes; import jungle.HandTris.presentation.dto.response.MemberProfileUpdateDetailsRes; import jungle.HandTris.presentation.dto.response.MemberRecordDetailRes; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.util.Pair; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; -import org.springframework.beans.factory.annotation.Value; import java.io.IOException; @@ -46,39 +44,7 @@ public Pair getMemberProfileWithStatsByNickname(S } @Override - public MemberDetailRes loadMemberProfileByToken(HttpServletRequest request) { - String accessToken = request.getHeader("Authorization").substring(7); - - String nickname = jwtUtil.getNickname(accessToken); - - Member member = memberRepository.findByNickname(nickname) - .orElseThrow(UserNotFoundException::new); - - String username = member.getUsername(); - return new MemberDetailRes(username, nickname); - } - - @Override - public Pair myPage(HttpServletRequest request, String username) { - String token = jwtUtil.resolveAccessToken(request); - String nickname = jwtUtil.getNickname(token); - Member member = memberRepository.findByNickname(nickname) - .orElseThrow(MemberNotFoundException::new); - - // 요청한 유저와 토큰의 주인이 같은지 검증 - if (!username.equals(member.getUsername())) { - throw new UnauthorizedAccessException(); - } - - MemberProfileDetailsRes memberInfoDetails = new MemberProfileDetailsRes(member.getNickname(), member.getProfileImageUrl()); - MemberRecordDetailRes memberRecordDetails = new MemberRecordDetailRes(memberRecordService.getMemberRecord(member.getNickname())); - - return Pair.of(memberInfoDetails, memberRecordDetails); - } - - - @Override - public MemberProfileUpdateDetailsRes updateMemberProfile(HttpServletRequest request, MemberUpdateReq memberUpdateReq, MultipartFile profileImage, Boolean deleteProfileImage, String username) { + public MemberProfileUpdateDetailsRes updateMemberProfile(HttpServletRequest request, MemberUpdateReq memberUpdateReq, MultipartFile profileImage, Boolean deleteProfileImage) { Boolean nicknameChanged = false; String token = jwtUtil.resolveAccessToken(request); @@ -86,10 +52,6 @@ public MemberProfileUpdateDetailsRes updateMemberProfile(HttpServletRequest requ Member member = memberRepository.findByNickname(nickname) .orElseThrow(MemberNotFoundException::new); - // 요청한 유저와 토큰의 주인이 같은지 검증 - if (!username.equals(member.getUsername())) { - throw new UnauthorizedAccessException(); - } // 변경할 닉네임이 있을 경우에만 업데이트 if (memberUpdateReq.nickname() != null && !memberUpdateReq.nickname().isEmpty()) { @@ -110,7 +72,7 @@ public MemberProfileUpdateDetailsRes updateMemberProfile(HttpServletRequest requ if (deleteProfileImage) { member.updateProfileImageUrl(defaultImage); } else if (profileImage != null && profileImage.getSize() > 0) { - // 이미지가 존재하는 경우에만 업데이트 + // 이미지가 존재하는 경우에만 업데이트 validateImage(profileImage); uploadImage(profileImage, member); } diff --git a/src/main/java/jungle/HandTris/application/service/MemberService.java b/src/main/java/jungle/HandTris/application/service/AuthService.java similarity index 92% rename from src/main/java/jungle/HandTris/application/service/MemberService.java rename to src/main/java/jungle/HandTris/application/service/AuthService.java index 4041574..6cb3a06 100644 --- a/src/main/java/jungle/HandTris/application/service/MemberService.java +++ b/src/main/java/jungle/HandTris/application/service/AuthService.java @@ -5,7 +5,7 @@ import jungle.HandTris.presentation.dto.request.MemberRequest; import org.springframework.data.util.Pair; -public interface MemberService { +public interface AuthService { Pair signin(MemberRequest memberRequest); void signup(MemberRequest memberRequest); diff --git a/src/main/java/jungle/HandTris/application/service/ExpirationListener.java b/src/main/java/jungle/HandTris/application/service/ExpirationListener.java index 1334abb..4714f39 100644 --- a/src/main/java/jungle/HandTris/application/service/ExpirationListener.java +++ b/src/main/java/jungle/HandTris/application/service/ExpirationListener.java @@ -11,7 +11,7 @@ @Component public class ExpirationListener implements MessageListener { - private final MemberService memberService; + private final AuthService authService; @Override public void onMessage(Message message, byte[] pattern) { diff --git a/src/main/java/jungle/HandTris/application/service/MemberProfileService.java b/src/main/java/jungle/HandTris/application/service/MemberProfileService.java index 3a4d9fa..51e59a0 100644 --- a/src/main/java/jungle/HandTris/application/service/MemberProfileService.java +++ b/src/main/java/jungle/HandTris/application/service/MemberProfileService.java @@ -2,8 +2,6 @@ import jakarta.servlet.http.HttpServletRequest; import jungle.HandTris.presentation.dto.request.MemberUpdateReq; -import jungle.HandTris.presentation.dto.response.MemberDetailRes; -import jungle.HandTris.presentation.dto.response.MemberProfileDetailsRes; import jungle.HandTris.presentation.dto.response.MemberProfileUpdateDetailsRes; import jungle.HandTris.presentation.dto.response.MemberRecordDetailRes; import org.springframework.data.util.Pair; @@ -12,9 +10,5 @@ public interface MemberProfileService { Pair getMemberProfileWithStatsByNickname(String nickname); - MemberDetailRes loadMemberProfileByToken(HttpServletRequest request); - - Pair myPage(HttpServletRequest request, String username); - - MemberProfileUpdateDetailsRes updateMemberProfile(HttpServletRequest request, MemberUpdateReq memberUpdateReq, MultipartFile profileImage, Boolean deleteProfileImage, String username); + MemberProfileUpdateDetailsRes updateMemberProfile(HttpServletRequest request, MemberUpdateReq memberUpdateReq, MultipartFile profileImage, Boolean deleteProfileImage); } diff --git a/src/main/java/jungle/HandTris/presentation/AuthController.java b/src/main/java/jungle/HandTris/presentation/AuthController.java index 03fddf7..fb11261 100644 --- a/src/main/java/jungle/HandTris/presentation/AuthController.java +++ b/src/main/java/jungle/HandTris/presentation/AuthController.java @@ -2,7 +2,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; -import jungle.HandTris.application.service.MemberService; +import jungle.HandTris.application.service.AuthService; import jungle.HandTris.domain.Member; import jungle.HandTris.global.dto.ResponseEnvelope; import jungle.HandTris.presentation.dto.request.MemberRequest; @@ -17,19 +17,19 @@ @RequiredArgsConstructor public class AuthController { - private final MemberService memberService; + private final AuthService authService; @PostMapping("/signup") @ResponseStatus(HttpStatus.CREATED) public ResponseEnvelope signup(@RequestBody @Valid MemberRequest memberRequest) { - memberService.signup(memberRequest); + authService.signup(memberRequest); return ResponseEnvelope.of("Signup Successful"); } @PostMapping("/signin") public ResponseEnvelope signin(@RequestBody MemberRequest memberRequest) { - Pair result = memberService.signin(memberRequest); + Pair result = authService.signin(memberRequest); Member member = result.getFirst(); String accessToken = result.getSecond(); @@ -46,7 +46,7 @@ public ResponseEnvelope signin(@RequestBody MemberR @PostMapping("/signout") public ResponseEnvelope signout(HttpServletRequest request) { - memberService.signout(request); + authService.signout(request); return ResponseEnvelope.of("Signout Successful"); } diff --git a/src/main/java/jungle/HandTris/presentation/MemberController.java b/src/main/java/jungle/HandTris/presentation/MemberProfileController.java similarity index 59% rename from src/main/java/jungle/HandTris/presentation/MemberController.java rename to src/main/java/jungle/HandTris/presentation/MemberProfileController.java index f82a850..77b1792 100644 --- a/src/main/java/jungle/HandTris/presentation/MemberController.java +++ b/src/main/java/jungle/HandTris/presentation/MemberProfileController.java @@ -3,38 +3,40 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import jungle.HandTris.application.service.MemberProfileService; +import jungle.HandTris.application.service.MemberRecordService; +import jungle.HandTris.domain.MemberRecord; import jungle.HandTris.global.dto.ResponseEnvelope; +import jungle.HandTris.global.validation.UserNicknameFromJwt; import jungle.HandTris.presentation.dto.request.MemberUpdateReq; -import jungle.HandTris.presentation.dto.response.MemberProfileDetailsRes; +import jungle.HandTris.presentation.dto.response.MemberProfileRes; import jungle.HandTris.presentation.dto.response.MemberProfileUpdateDetailsRes; -import jungle.HandTris.presentation.dto.response.MemberRecordDetailRes; import lombok.RequiredArgsConstructor; -import org.springframework.data.util.Pair; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @RestController @RequiredArgsConstructor @RequestMapping("/member") -public class MemberController { +public class MemberProfileController { private final MemberProfileService memberProfileService; + private final MemberRecordService memberRecordService; - @GetMapping("/{username}/mypage") - public ResponseEnvelope> myPage(HttpServletRequest request, @PathVariable("username") String username) { - Pair result = memberProfileService.myPage(request, username); - - return ResponseEnvelope.of(result); + @GetMapping("/mypage") + public ResponseEnvelope myPage(@UserNicknameFromJwt String nickname) { + MemberRecord memberRecord = memberRecordService.getMemberRecord(nickname); + MemberProfileRes memberProfileRes = new MemberProfileRes(memberRecord); + return ResponseEnvelope.of(memberProfileRes); } - @PatchMapping("/{username}/mypage") + @PatchMapping("/mypage") public ResponseEnvelope updateInfo( HttpServletRequest request, @Valid MemberUpdateReq memberUpdateReq, @RequestPart(value = "profileImage", required = false) MultipartFile profileImage, - @RequestParam(value = "deleteProfileImage", required = false, defaultValue = "false") boolean deleteProfileImage, - @PathVariable("username") String username) { + @RequestParam(value = "deleteProfileImage", required = false, defaultValue = "false") boolean deleteProfileImage + ) { - MemberProfileUpdateDetailsRes updateMemberDetails = memberProfileService.updateMemberProfile(request, memberUpdateReq, profileImage, deleteProfileImage, username); + MemberProfileUpdateDetailsRes updateMemberDetails = memberProfileService.updateMemberProfile(request, memberUpdateReq, profileImage, deleteProfileImage); return ResponseEnvelope.of(updateMemberDetails); } diff --git a/src/main/java/jungle/HandTris/presentation/MemberRecordController.java b/src/main/java/jungle/HandTris/presentation/MemberRecordController.java index 66dc3c7..aa24d73 100644 --- a/src/main/java/jungle/HandTris/presentation/MemberRecordController.java +++ b/src/main/java/jungle/HandTris/presentation/MemberRecordController.java @@ -6,8 +6,7 @@ import jungle.HandTris.global.dto.ResponseEnvelope; import jungle.HandTris.global.validation.UserNicknameFromJwt; import jungle.HandTris.presentation.dto.request.GameResultReq; -import jungle.HandTris.presentation.dto.response.MemberRecordDetailRes; -import jungle.HandTris.presentation.dto.response.ParticipantRes; +import jungle.HandTris.presentation.dto.response.MemberProfileRes; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -22,37 +21,37 @@ public class MemberRecordController { private final MemberRecordService memberRecordService; - @GetMapping("/{nickname}") - public ResponseEnvelope getMemberRecord(@PathVariable("nickname") String nickname) { + @GetMapping + public ResponseEnvelope getMyRecord(@UserNicknameFromJwt String nickname) { MemberRecord memberRecord = memberRecordService.getMemberRecord(nickname); - MemberRecordDetailRes memberRecordDetailRes = new MemberRecordDetailRes(memberRecord); - return ResponseEnvelope.of(memberRecordDetailRes); + MemberProfileRes memberProfileRes = new MemberProfileRes(memberRecord); + return ResponseEnvelope.of(memberProfileRes); } @PutMapping - public ResponseEnvelope updateMemberRecord(@Valid @RequestBody GameResultReq gameResultReq, @UserNicknameFromJwt String nickname) { + public ResponseEnvelope updateMemberRecord(@Valid @RequestBody GameResultReq gameResultReq, @UserNicknameFromJwt String nickname) { MemberRecord memberRecord = memberRecordService.updateMemberRecord(gameResultReq, nickname); - MemberRecordDetailRes memberRecordDetailRes = new MemberRecordDetailRes(memberRecord); - return ResponseEnvelope.of(memberRecordDetailRes); + MemberProfileRes memberProfileRes = new MemberProfileRes(memberRecord); + return ResponseEnvelope.of(memberProfileRes); + } + + @GetMapping("/{nickname}") + public ResponseEnvelope getMemberRecord(@PathVariable("nickname") String nickname) { + MemberRecord memberRecord = memberRecordService.getMemberRecord(nickname); + MemberProfileRes memberProfileRes = new MemberProfileRes(memberRecord); + return ResponseEnvelope.of(memberProfileRes); } @GetMapping("/participant/{roomCode}") - public ResponseEnvelope> getParticipants(@PathVariable("roomCode") String roomCode, @UserNicknameFromJwt String nickname) { + public ResponseEnvelope> getParticipants(@PathVariable("roomCode") String roomCode, @UserNicknameFromJwt String nickname) { List participantsMemberRecord = memberRecordService.getParticipants(roomCode, nickname); - List participantResList = new ArrayList<>(); + List memberProfileResList = new ArrayList<>(); for (MemberRecord memberRecord : participantsMemberRecord) { if (memberRecord == null) continue; - ParticipantRes participantRes = new ParticipantRes(memberRecord); - participantResList.add(participantRes); + MemberProfileRes memberProfileRes = new MemberProfileRes(memberRecord); + memberProfileResList.add(memberProfileRes); } - return ResponseEnvelope.of(participantResList); - } - - @GetMapping - public ResponseEnvelope getMyRecord(@UserNicknameFromJwt String nickname) { - MemberRecord memberRecord = memberRecordService.getMemberRecord(nickname); - ParticipantRes participantRes = new ParticipantRes(memberRecord); - return ResponseEnvelope.of(participantRes); + return ResponseEnvelope.of(memberProfileResList); } } diff --git a/src/main/java/jungle/HandTris/presentation/TetrisController.java b/src/main/java/jungle/HandTris/presentation/TetrisController.java index b4d71ee..0d01ef1 100644 --- a/src/main/java/jungle/HandTris/presentation/TetrisController.java +++ b/src/main/java/jungle/HandTris/presentation/TetrisController.java @@ -2,6 +2,7 @@ import jungle.HandTris.application.service.GameRoomService; import jungle.HandTris.application.service.TetrisService; +import jungle.HandTris.domain.GameRoom; import jungle.HandTris.presentation.dto.request.RoomStateReq; import jungle.HandTris.presentation.dto.request.TetrisMessageReq; import jungle.HandTris.presentation.dto.response.RoomOwnerRes; @@ -54,6 +55,7 @@ public void roomOwnerInfo(@DestinationVariable("roomCode") String roomCode, Simp @MessageMapping("/{roomCode}/disconnect") public void handleDisconnect(SimpMessageHeaderAccessor headerAccessor, @DestinationVariable(value = "roomCode") String roomCode) { System.out.println("\n========================================= controller disconnect send ========================================="); + // playing 중인 게임에서 탈주한 경우 // message에서 isStart 확인 boolean isStart = headerAccessor.getFirstNativeHeader("isStart").equals("true"); @@ -68,13 +70,15 @@ public void handleDisconnect(SimpMessageHeaderAccessor headerAccessor, @Destinat // DB 최신화 System.out.println("DB 최신화"); String user = headerAccessor.getHeader("User").toString(); - gameRoomService.exitGameRoom(user, roomCode); - - // 방장 최신화 : DB 최신화 아래 있어야 한다. - System.out.println("방장 최신화"); - RoomOwnerRes roomOwnerRes = tetrisService.checkRoomOwnerAndReady(roomCode); - messagingTemplate.convertAndSend("/topic/owner/" + roomCode, roomOwnerRes); + GameRoom gameRoom = gameRoomService.exitGameRoom(user, roomCode); + // 참여자가 나갔지만 누군가 남아 있다면 + if (gameRoom.getParticipantCount() != 0) { + // 방장 최신화 : DB 최신화 아래 있어야 한다. + System.out.println("방장 최신화"); + RoomOwnerRes roomOwnerRes = tetrisService.checkRoomOwnerAndReady(roomCode); + messagingTemplate.convertAndSend("/topic/owner/" + roomCode, roomOwnerRes); + } System.out.println("\n========================================= disconnect send 종료 ========================================="); } diff --git a/src/main/java/jungle/HandTris/presentation/TokenController.java b/src/main/java/jungle/HandTris/presentation/TokenController.java deleted file mode 100644 index bffb1c4..0000000 --- a/src/main/java/jungle/HandTris/presentation/TokenController.java +++ /dev/null @@ -1,24 +0,0 @@ -package jungle.HandTris.presentation; - -import jakarta.servlet.http.HttpServletRequest; -import jungle.HandTris.application.service.MemberProfileService; -import jungle.HandTris.global.dto.ResponseEnvelope; -import jungle.HandTris.presentation.dto.response.MemberDetailRes; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/token") -@RequiredArgsConstructor -public class TokenController { - private final MemberProfileService memberProfileService; - - @GetMapping("/member/info") - public ResponseEnvelope getMemberInfoToToken(HttpServletRequest request) { - MemberDetailRes memberDetail = memberProfileService.loadMemberProfileByToken(request); - - return ResponseEnvelope.of(memberDetail); - } -} diff --git a/src/main/java/jungle/HandTris/presentation/dto/response/ParticipantRes.java b/src/main/java/jungle/HandTris/presentation/dto/response/MemberProfileRes.java similarity index 85% rename from src/main/java/jungle/HandTris/presentation/dto/response/ParticipantRes.java rename to src/main/java/jungle/HandTris/presentation/dto/response/MemberProfileRes.java index a236467..6212ec3 100644 --- a/src/main/java/jungle/HandTris/presentation/dto/response/ParticipantRes.java +++ b/src/main/java/jungle/HandTris/presentation/dto/response/MemberProfileRes.java @@ -4,14 +4,14 @@ import java.math.BigDecimal; -public record ParticipantRes( +public record MemberProfileRes( String nickname, String profileImageUrl, long win, long lose, BigDecimal winRate ) { - public ParticipantRes(MemberRecord memberRecord) { + public MemberProfileRes(MemberRecord memberRecord) { this( memberRecord.getMember().getNickname(), memberRecord.getMember().getProfileImageUrl(), diff --git a/src/test/java/jungle/HandTris/Member/MemberServiceTest.java b/src/test/java/jungle/HandTris/Member/AuthServiceTest.java similarity index 77% rename from src/test/java/jungle/HandTris/Member/MemberServiceTest.java rename to src/test/java/jungle/HandTris/Member/AuthServiceTest.java index 3eb428f..0db6cb3 100644 --- a/src/test/java/jungle/HandTris/Member/MemberServiceTest.java +++ b/src/test/java/jungle/HandTris/Member/AuthServiceTest.java @@ -3,17 +3,15 @@ import jakarta.transaction.Transactional; import jakarta.validation.ConstraintViolation; import jakarta.validation.Validator; +import jungle.HandTris.application.service.AuthService; import jungle.HandTris.application.service.MemberProfileService; import jungle.HandTris.application.service.MemberRecordService; -import jungle.HandTris.application.service.MemberService; import jungle.HandTris.domain.Member; import jungle.HandTris.domain.MemberRecord; import jungle.HandTris.domain.exception.*; import jungle.HandTris.domain.repo.MemberRepository; import jungle.HandTris.presentation.dto.request.MemberRequest; import jungle.HandTris.presentation.dto.request.MemberUpdateReq; -import jungle.HandTris.presentation.dto.response.MemberDetailRes; -import jungle.HandTris.presentation.dto.response.MemberProfileDetailsRes; import jungle.HandTris.presentation.dto.response.MemberProfileUpdateDetailsRes; import jungle.HandTris.presentation.dto.response.MemberRecordDetailRes; import org.assertj.core.api.Assertions; @@ -28,20 +26,23 @@ import org.springframework.data.util.Pair; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import java.util.Set; @SpringBootTest @Transactional -public class MemberServiceTest { - - @Autowired MemberService memberService; - @Autowired MemberProfileService memberProfileService; - @Autowired MemberRecordService memberRecordService; - @Autowired MemberRepository memberRepository; - @Autowired BCryptPasswordEncoder bCryptPasswordEncoder; - @Autowired private Validator validator; +public class AuthServiceTest { + + @Autowired + AuthService authService; + @Autowired + MemberProfileService memberProfileService; + @Autowired + MemberRecordService memberRecordService; + @Autowired + MemberRepository memberRepository; + @Autowired + private Validator validator; @Nested @DisplayName("회원 가입") @@ -54,13 +55,12 @@ public void testSignupSuccess() { MemberRequest member = new MemberRequest("user1", "1q2w3e4r!", "user1"); // when - memberService.signup(member); + authService.signup(member); // then Member findMember = memberRepository.findByUsername(member.username()); Assertions.assertThat(findMember.getUsername()).isEqualTo(member.username()); - Assertions.assertThat(bCryptPasswordEncoder.matches(member.password(), findMember.getPassword())).isTrue(); Assertions.assertThat(findMember.getNickname()).isEqualTo(member.nickname()); } @@ -72,15 +72,15 @@ class Username { @Test @DisplayName("중복 Username") public void testSignupFailWithDuplicateUsername() { - // given - MemberRequest member1 = new MemberRequest("user1", "1q2w3e4r!", "user1"); - MemberRequest member2 = new MemberRequest("user1", "1q2w3e4r!", "user2"); - memberService.signup(member1); + // given + MemberRequest member1 = new MemberRequest("user1", "1q2w3e4r!", "user1"); + MemberRequest member2 = new MemberRequest("user1", "1q2w3e4r!", "user2"); + authService.signup(member1); - // when & then + // when & then - Assertions.assertThatThrownBy(() -> memberService.signup(member2)) - .isInstanceOf(DuplicateUsernameException.class); + Assertions.assertThatThrownBy(() -> authService.signup(member2)) + .isInstanceOf(DuplicateUsernameException.class); } @Test @@ -165,11 +165,11 @@ public void testSignupFailWithDuplicateNickname() { // given MemberRequest member1 = new MemberRequest("user1", "1q2w3e4r!", "user1"); MemberRequest member2 = new MemberRequest("user2", "1q2w3e4r!", "user1"); - memberService.signup(member1); + authService.signup(member1); // when & then - Assertions.assertThatThrownBy(() -> memberService.signup(member2)) + Assertions.assertThatThrownBy(() -> authService.signup(member2)) .isInstanceOf(DuplicateNicknameException.class); } @@ -217,7 +217,7 @@ public void testSignupFailWithSpecialCharacterNickname() { } @ParameterizedTest - @ValueSource(strings ={"admin", "administator", "useradmin", "adminuser"}) + @ValueSource(strings = {"admin", "administator", "useradmin", "adminuser"}) @DisplayName("admin 작성된 Nickname") public void testSignupFailWithAdminNickname(String nickname) { // given @@ -243,10 +243,10 @@ class Signin { public void testLoginSuccess() { // given MemberRequest member = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(member); + authService.signup(member); // when - Pair result = memberService.signin(member); + Pair result = authService.signin(member); // then Assertions.assertThat(result).isNotNull(); @@ -266,7 +266,7 @@ public void testLoginFailWithNonexistentUsername() { MemberRequest member = new MemberRequest("user1", "1q2w3e4r!", "user1"); // when & then - Assertions.assertThatThrownBy(() -> memberService.signin(member)) + Assertions.assertThatThrownBy(() -> authService.signin(member)) .isInstanceOf(UserNotFoundException.class); } @@ -276,12 +276,12 @@ public void testLoginFailWithNonexistentUsername() { public void testLoginFailWithIncorrectPassword() { // given MemberRequest member = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(member); + authService.signup(member); // when MemberRequest incorrectMember = new MemberRequest("user1", "wrongPassword", "user1"); - Assertions.assertThatThrownBy(() -> memberService.signin(incorrectMember)) + Assertions.assertThatThrownBy(() -> authService.signin(incorrectMember)) .isInstanceOf(PasswordMismatchException.class); // then @@ -293,11 +293,11 @@ public void testLoginFailWithIncorrectPassword() { class MyPage { @Test @DisplayName("정상 마이페이지 호출") - public void testMyPageSuccess () { + public void testMyPageSuccess() { // given MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(requestMember); - Pair SigninResult = memberService.signin(requestMember); + authService.signup(requestMember); + Pair SigninResult = authService.signin(requestMember); Member member = SigninResult.getFirst(); String token = SigninResult.getSecond(); @@ -308,57 +308,39 @@ public void testMyPageSuccess () { MemberRecordDetailRes memberRecordDetailRes = new MemberRecordDetailRes(memberRecord); // when - Pair profileResult = - memberProfileService.myPage(request, member.getUsername()); - - // then - Assertions.assertThat(profileResult.getFirst().nickname()).isEqualTo(member.getNickname()); - Assertions.assertThat(profileResult.getFirst().profileImageUrl()).isEqualTo(member.getProfileImageUrl()); - Assertions.assertThat(profileResult.getSecond()).isEqualTo(memberRecordDetailRes); + // todo : myPage 함수 삭제됨 +// Pair profileResult = +// memberProfileService.myPage(request, member.getUsername()); +// +// // then +// Assertions.assertThat(profileResult.getFirst().nickname()).isEqualTo(member.getNickname()); +// Assertions.assertThat(profileResult.getFirst().profileImageUrl()).isEqualTo(member.getProfileImageUrl()); +// Assertions.assertThat(profileResult.getSecond()).isEqualTo(memberRecordDetailRes); } @Test @DisplayName("A유저가 B유저의 마이페이지 호출") - public void testMyPageConnectWrongUser () { + public void testMyPageConnectWrongUser() { // given MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(requestMember); - String token = memberService.signin(requestMember).getSecond(); + authService.signup(requestMember); + String token = authService.signin(requestMember).getSecond(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("Authorization", "Bearer " + token); // when & then - Assertions.assertThatThrownBy(() -> { - Pair result = memberProfileService.myPage(request, "user2"); - }).isInstanceOf(UnauthorizedAccessException.class); + // todo : myPage 함수 삭제됨 +// Assertions.assertThatThrownBy(() -> { +// Pair result = memberProfileService.myPage(request, "user2"); +// }).isInstanceOf(UnauthorizedAccessException.class); } } @Nested @DisplayName("회원 정보 요청") class GetMemberProfile { - @Test - @DisplayName("회원 정보 요청") - public void testLoadMemberProfileByTokenSuccess () { - // given - MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(requestMember); - Pair SigninResult = memberService.signin(requestMember); - Member member = SigninResult.getFirst(); - String token = SigninResult.getSecond(); - - MockHttpServletRequest request = new MockHttpServletRequest(); - request.addHeader("Authorization", "Bearer " + token); - // when - MemberDetailRes profileResult = - memberProfileService.loadMemberProfileByToken(request); - - // then - Assertions.assertThat(profileResult.nickname()).isEqualTo(member.getNickname()); - Assertions.assertThat(profileResult.username()).isEqualTo(member.getUsername()); - } } @Nested @@ -369,11 +351,11 @@ class ChangeMemberProfile { class ChangeMemberNickname { @Test @DisplayName("정상 닉네임 변경") - public void testChangeMemberNicknameSuccess () { + public void testChangeMemberNicknameSuccess() { // given MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(requestMember); - Pair SigninResult = memberService.signin(requestMember); + authService.signup(requestMember); + Pair SigninResult = authService.signin(requestMember); Member member = SigninResult.getFirst(); String token = SigninResult.getSecond(); @@ -384,7 +366,7 @@ public void testChangeMemberNicknameSuccess () { // when MemberProfileUpdateDetailsRes changeMemberProfile = memberProfileService.updateMemberProfile( - request, changeNickname, null, false, member.getUsername()); + request, changeNickname, null, false); // then Assertions.assertThat(changeMemberProfile.nickname()).isEqualTo(member.getNickname()); @@ -396,8 +378,8 @@ public void testChangeMemberNicknameSuccess () { public void testChangeMemberNicknameWithSameNickname() { // given MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(requestMember); - Pair SigninResult = memberService.signin(requestMember); + authService.signup(requestMember); + Pair SigninResult = authService.signin(requestMember); Member member = SigninResult.getFirst(); String token = SigninResult.getSecond(); @@ -408,9 +390,9 @@ public void testChangeMemberNicknameWithSameNickname() { // when & then Assertions.assertThatThrownBy(() -> { - memberProfileService.updateMemberProfile( - request, changeNickname, null, null, member.getUsername()); - }).isInstanceOf(NicknameNotChangedException.class); + memberProfileService.updateMemberProfile( + request, changeNickname, null, null); + }).isInstanceOf(NicknameNotChangedException.class); } @Test @@ -419,9 +401,9 @@ public void testChangeMemberNicknameWithDuplicateNickname() { // given MemberRequest requestMember1 = new MemberRequest("user1", "1q2w3e4r!", "user1"); MemberRequest requestMember2 = new MemberRequest("user2", "1q2w3e4r!", "user2"); - memberService.signup(requestMember1); - memberService.signup(requestMember2); - Pair SigninResult = memberService.signin(requestMember1); + authService.signup(requestMember1); + authService.signup(requestMember2); + Pair SigninResult = authService.signin(requestMember1); Member member = SigninResult.getFirst(); String token = SigninResult.getSecond(); @@ -432,9 +414,9 @@ public void testChangeMemberNicknameWithDuplicateNickname() { // when & then Assertions.assertThatThrownBy(() -> { - memberProfileService.updateMemberProfile( - request, changeNickname, null, null, member.getUsername()); - }).isInstanceOf(DuplicateNicknameException.class); + memberProfileService.updateMemberProfile( + request, changeNickname, null, null); + }).isInstanceOf(DuplicateNicknameException.class); } } @@ -447,11 +429,11 @@ class ChangeMemberProfileImage { @Test @DisplayName("정상 프로필 사진 변경") - public void testChangeMemberProfileImageSuccess () { + public void testChangeMemberProfileImageSuccess() { // given MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(requestMember); - Pair SigninResult = memberService.signin(requestMember); + authService.signup(requestMember); + Pair SigninResult = authService.signin(requestMember); Member member = SigninResult.getFirst(); String token = SigninResult.getSecond(); @@ -471,7 +453,7 @@ public void testChangeMemberProfileImageSuccess () { // when MemberProfileUpdateDetailsRes changeMemberProfile = memberProfileService.updateMemberProfile( - request, changeNickname, changeProfileImage, false, member.getUsername()); + request, changeNickname, changeProfileImage, false); // then Assertions.assertThat(changeMemberProfile.profileImageUrl()).isEqualTo(member.getProfileImageUrl()); @@ -479,11 +461,11 @@ public void testChangeMemberProfileImageSuccess () { @Test @DisplayName("정상 프로필 사진 제거") - public void testChangeMemberDefaultProfileImageSuccess () { + public void testChangeMemberDefaultProfileImageSuccess() { // given MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(requestMember); - Pair SigninResult = memberService.signin(requestMember); + authService.signup(requestMember); + Pair SigninResult = authService.signin(requestMember); Member member = SigninResult.getFirst(); String token = SigninResult.getSecond(); @@ -500,13 +482,13 @@ public void testChangeMemberDefaultProfileImageSuccess () { ); MemberProfileUpdateDetailsRes changeMemberProfile = memberProfileService.updateMemberProfile( - request, changeNickname, changeProfileImage, false, member.getUsername()); + request, changeNickname, changeProfileImage, false); Assertions.assertThat(changeMemberProfile.profileImageUrl()).isEqualTo(member.getProfileImageUrl()); // when memberProfileService.updateMemberProfile( - request, changeNickname, null, true, member.getUsername()); + request, changeNickname, null, true); // then Assertions.assertThat(defaultImage).isEqualTo(member.getProfileImageUrl()); } @@ -516,8 +498,8 @@ public void testChangeMemberDefaultProfileImageSuccess () { public void testChangeMemberNicknameWithSameNickname() { // given MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(requestMember); - Pair SigninResult = memberService.signin(requestMember); + authService.signup(requestMember); + Pair SigninResult = authService.signin(requestMember); Member member = SigninResult.getFirst(); String token = SigninResult.getSecond(); @@ -536,7 +518,7 @@ public void testChangeMemberNicknameWithSameNickname() { // when & then Assertions.assertThatThrownBy(() -> { memberProfileService.updateMemberProfile( - request, changeNickname, changeProfileImage, false, member.getUsername()); + request, changeNickname, changeProfileImage, false); }).isInstanceOf(InvalidImageTypeException.class); } @@ -545,8 +527,8 @@ public void testChangeMemberNicknameWithSameNickname() { public void testChangeMemberNicknameWithDuplicateNickname() { // given MemberRequest requestMember = new MemberRequest("user1", "1q2w3e4r!", "user1"); - memberService.signup(requestMember); - Pair SigninResult = memberService.signin(requestMember); + authService.signup(requestMember); + Pair SigninResult = authService.signin(requestMember); Member member = SigninResult.getFirst(); String token = SigninResult.getSecond(); @@ -569,7 +551,7 @@ public void testChangeMemberNicknameWithDuplicateNickname() { // when & then Assertions.assertThatThrownBy(() -> { memberProfileService.updateMemberProfile( - request, changeNickname, changeProfileImage, false, member.getUsername()); + request, changeNickname, changeProfileImage, false); }).isInstanceOf(InvalidImageTypeException.class); } }