diff --git a/src/main/java/com/hanaro/triptogether/member/controller/MemberController.java b/src/main/java/com/hanaro/triptogether/member/controller/MemberController.java index dfa40c2..2bc93cf 100644 --- a/src/main/java/com/hanaro/triptogether/member/controller/MemberController.java +++ b/src/main/java/com/hanaro/triptogether/member/controller/MemberController.java @@ -1,6 +1,7 @@ package com.hanaro.triptogether.member.controller; import com.hanaro.triptogether.member.dto.request.LoginReqDto; +import com.hanaro.triptogether.member.dto.response.LoginResDto; import com.hanaro.triptogether.member.service.MemberService; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; @@ -19,7 +20,7 @@ public class MemberController { // 간편 로그인 @PostMapping("/login") - public String login(@RequestBody LoginReqDto loginReqDto, HttpServletRequest request) { + public LoginResDto login(@RequestBody LoginReqDto loginReqDto, HttpServletRequest request) { Long memberIdx = loginReqDto.getMemberIdx(); String memberLoginPw = loginReqDto.getMemberLoginPw(); diff --git a/src/main/java/com/hanaro/triptogether/member/dto/response/LoginResDto.java b/src/main/java/com/hanaro/triptogether/member/dto/response/LoginResDto.java new file mode 100644 index 0000000..9629a7a --- /dev/null +++ b/src/main/java/com/hanaro/triptogether/member/dto/response/LoginResDto.java @@ -0,0 +1,11 @@ +package com.hanaro.triptogether.member.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class LoginResDto { + private String message; + private String memberName; +} diff --git a/src/main/java/com/hanaro/triptogether/member/service/MemberService.java b/src/main/java/com/hanaro/triptogether/member/service/MemberService.java index 0996f2e..68716b9 100644 --- a/src/main/java/com/hanaro/triptogether/member/service/MemberService.java +++ b/src/main/java/com/hanaro/triptogether/member/service/MemberService.java @@ -1,10 +1,11 @@ package com.hanaro.triptogether.member.service; import com.hanaro.triptogether.member.domain.Member; +import com.hanaro.triptogether.member.dto.response.LoginResDto; public interface MemberService { // 간편 로그인 - String login(Long memberIdx, String memberLoginPw); + LoginResDto login(Long memberIdx, String memberLoginPw); //멤머 아이디로 멤버 검색 Member findByMemberIdx(Long memberIdx); // 알림설정 (on/off) diff --git a/src/main/java/com/hanaro/triptogether/member/service/impl/MemberServiceImpl.java b/src/main/java/com/hanaro/triptogether/member/service/impl/MemberServiceImpl.java index 6ed91b6..c3a57c2 100644 --- a/src/main/java/com/hanaro/triptogether/member/service/impl/MemberServiceImpl.java +++ b/src/main/java/com/hanaro/triptogether/member/service/impl/MemberServiceImpl.java @@ -4,6 +4,7 @@ import com.hanaro.triptogether.exception.ExceptionEnum; import com.hanaro.triptogether.member.domain.Member; import com.hanaro.triptogether.member.domain.MemberRepository; +import com.hanaro.triptogether.member.dto.response.LoginResDto; import com.hanaro.triptogether.member.service.MemberService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -17,18 +18,26 @@ public class MemberServiceImpl implements MemberService { // 간편 로그인 @Transactional @Override - public String login(Long memberIdx, String memberLoginPw) { + public LoginResDto login(Long memberIdx, String memberLoginPw) { Member member = memberRepository.findMemberByMemberIdxAndMemberLoginPw(memberIdx, memberLoginPw); if(member == null) { - return "비밀번호가 맞지 않습니다."; + return LoginResDto.builder() + .message("비밀번호가 맞지 않습니다.") + .memberName("비회원") + .build(); } if (!memberLoginPw.equals(member.getMemberLoginPw())) { - return "비밀번호가 맞지 않습니다."; + return LoginResDto.builder() + .message("비밀번호가 맞지 않습니다.") + .memberName("비회원") + .build(); } else { - - return "로그인이 완료되었습니다!"; + return LoginResDto.builder() + .message("로그인이 완료되었습니다!") + .memberName(member.getMemberName()) + .build(); } } diff --git a/src/test/java/com/hanaro/triptogether/MemberServiceTests.java b/src/test/java/com/hanaro/triptogether/MemberServiceTests.java index bdd140f..cb70c46 100644 --- a/src/test/java/com/hanaro/triptogether/MemberServiceTests.java +++ b/src/test/java/com/hanaro/triptogether/MemberServiceTests.java @@ -2,6 +2,7 @@ import com.hanaro.triptogether.member.domain.Member; import com.hanaro.triptogether.member.domain.MemberRepository; +import com.hanaro.triptogether.member.dto.response.LoginResDto; import com.hanaro.triptogether.member.service.impl.MemberServiceImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -43,10 +44,11 @@ void testLoginSuccess() { when(memberRepository.findMemberByMemberIdxAndMemberLoginPw(1L, "123456")).thenReturn(member); // When - String result = memberService.login(1L, "123456"); + LoginResDto result = memberService.login(1L, "123456"); // Then - assertEquals("로그인이 완료되었습니다!", result); + assertEquals("로그인이 완료되었습니다!", result.getMessage()); + assertEquals(member.getMemberName(), result.getMemberName()); } @Test @@ -56,9 +58,9 @@ void testLoginIncorrectPw() { when(memberRepository.findMemberByMemberIdxAndMemberLoginPw(1L, "123456")).thenReturn(member); // When - String result = memberService.login(1L, "456789"); + LoginResDto result = memberService.login(1L, "456789"); // Then - assertEquals("비밀번호가 맞지 않습니다.", result); + assertEquals("비밀번호가 맞지 않습니다.", result.getMessage()); } }