-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 로그인 기능을 구현했어요. - 로그인시 유저가 존재하지 않거나, 비밀번호가 틀리면 예외가 발생해요.
- Loading branch information
Showing
6 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/com/bamdoliro/sinabro/application/auth/LogInUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.bamdoliro.sinabro.application.auth; | ||
|
||
import com.bamdoliro.sinabro.domain.auth.exception.PasswordMismatchException; | ||
import com.bamdoliro.sinabro.domain.auth.exception.WrongLogInException; | ||
import com.bamdoliro.sinabro.domain.auth.service.TokenService; | ||
import com.bamdoliro.sinabro.domain.user.domain.User; | ||
import com.bamdoliro.sinabro.domain.user.domain.value.Password; | ||
import com.bamdoliro.sinabro.domain.user.exception.UserNotFoundException; | ||
import com.bamdoliro.sinabro.domain.user.service.UserFacade; | ||
import com.bamdoliro.sinabro.presentation.auth.dto.request.LogInRequest; | ||
import com.bamdoliro.sinabro.presentation.auth.dto.response.TokenResponse; | ||
import com.bamdoliro.sinabro.shared.annotation.UseCase; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@UseCase | ||
public class LogInUseCase { | ||
|
||
private final UserFacade userFacade; | ||
private final TokenService tokenService; | ||
|
||
public TokenResponse execute(LogInRequest request) { | ||
User user; | ||
try { | ||
user = userFacade.getUser(request.getEmail()); | ||
validate(request.getPassword(), user.getPassword()); | ||
} catch (UserNotFoundException | PasswordMismatchException e) { | ||
throw new WrongLogInException(); | ||
} | ||
|
||
return TokenResponse.builder() | ||
.accessToken(tokenService.generateAccessToken(user.getEmail())) | ||
.refreshToken(tokenService.generateRefreshToken(user.getEmail())) | ||
.build(); | ||
} | ||
|
||
private void validate(String actual, Password expected) { | ||
if (!expected.match(actual)) { | ||
throw new PasswordMismatchException(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/bamdoliro/sinabro/domain/auth/exception/PasswordMismatchException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.bamdoliro.sinabro.domain.auth.exception; | ||
|
||
import com.bamdoliro.sinabro.domain.auth.exception.error.AuthErrorProperty; | ||
import com.bamdoliro.sinabro.shared.error.SinabroException; | ||
|
||
public class PasswordMismatchException extends SinabroException { | ||
public PasswordMismatchException() { | ||
super(AuthErrorProperty.PASSWORD_MISMATCH); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/bamdoliro/sinabro/domain/auth/exception/WrongLogInException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.bamdoliro.sinabro.domain.auth.exception; | ||
|
||
import com.bamdoliro.sinabro.domain.auth.exception.error.AuthErrorProperty; | ||
import com.bamdoliro.sinabro.shared.error.SinabroException; | ||
|
||
public class WrongLogInException extends SinabroException { | ||
public WrongLogInException() { | ||
super(AuthErrorProperty.WRONG_LOGIN); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/bamdoliro/sinabro/presentation/auth/dto/request/LogInRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bamdoliro.sinabro.presentation.auth.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class LogInRequest { | ||
|
||
@NotBlank(message = "필수값입니다.") | ||
private String email; | ||
|
||
@NotBlank(message = "필수값입니다.") | ||
private String password; | ||
} |