Skip to content

Commit

Permalink
Merge pull request #75 from Hanaro-trip-together-bank/test/team
Browse files Browse the repository at this point in the history
feat: 간편 로그인 기능 수정
  • Loading branch information
yubin-im authored May 30, 2024
2 parents 096a2e2 + 5d9bebd commit b4597df
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
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());
}
}

0 comments on commit b4597df

Please sign in to comment.