Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 간편 로그인 기능 수정 #75

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/test/java/com/hanaro/triptogether/MemberServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
}
Loading