-
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.
* feat: add api of register user * feat: add api of login * feat: add validation about creating user * feat: add api of reissuing tokens * feat: separate method of parsing token - add subject of token claim * feat: add api of logout - add argument resolver of logined user * feat: add api of checking login id duplication - with using strategy pattern * test: add test of api checking login id * feat: add api of checking nickname duplication * style: reformat code * build: set property of yml
- Loading branch information
Showing
50 changed files
with
1,762 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,47 @@ | ||
package gymmi.controller; | ||
|
||
import gymmi.entity.User; | ||
import gymmi.global.Logined; | ||
import gymmi.request.LoginRequest; | ||
import gymmi.request.RegistrationRequest; | ||
import gymmi.request.ReissueRequest; | ||
import gymmi.response.TokensResponse; | ||
import gymmi.service.AuthService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class AuthController { | ||
|
||
private final AuthService authService; | ||
|
||
@PostMapping("/auth/join") | ||
public ResponseEntity<Void> registerUser(@Validated @RequestBody RegistrationRequest request) { | ||
authService.registerUser(request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@PostMapping("/auth/welcome") | ||
public ResponseEntity<TokensResponse> login(@Validated @RequestBody LoginRequest request) { | ||
TokensResponse response = authService.login(request); | ||
return ResponseEntity.ok().body(response); | ||
} | ||
|
||
@PostMapping("/auth/reissue") | ||
public ResponseEntity<TokensResponse> reissue(@Validated @RequestBody ReissueRequest request) { | ||
TokensResponse response = authService.reissue(request); | ||
return ResponseEntity.ok().body(response); | ||
} | ||
|
||
@PostMapping("/auth/goodbye") | ||
public ResponseEntity<Void> logout(@Logined User user) { | ||
authService.logout(user); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/gymmi/controller/DuplicationCheckController.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,26 @@ | ||
package gymmi.controller; | ||
|
||
import gymmi.global.DuplicationCheckType; | ||
import gymmi.response.DuplicationResponse; | ||
import gymmi.service.DuplicationCheckService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class DuplicationCheckController { | ||
|
||
private final DuplicationCheckService duplicationCheckService; | ||
|
||
@GetMapping("/check-duplication") | ||
public ResponseEntity<DuplicationResponse> checkDuplication( | ||
@RequestParam("type") DuplicationCheckType type, | ||
@RequestParam("value") String value | ||
) { | ||
DuplicationResponse response = duplicationCheckService.checkDuplication(type, value); | ||
return ResponseEntity.ok().body(response); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package gymmi.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Logined { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@JoinColumn(name = "user_id", nullable = false, unique = true, updatable = false) | ||
@OneToOne(fetch = FetchType.LAZY) | ||
private User user; | ||
|
||
@Column | ||
private String refreshToken; | ||
|
||
public Logined(User user) { | ||
this.user = user; | ||
} | ||
|
||
public void saveRefreshToken(String refreshToken) { | ||
this.refreshToken = refreshToken; | ||
} | ||
|
||
public void destroyRefreshToken() { | ||
this.refreshToken = null; | ||
} | ||
|
||
public boolean isActivatedRefreshToken(String refreshToken) { | ||
if (this.refreshToken == null) { | ||
return false; | ||
} | ||
return this.refreshToken.equals(refreshToken); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package gymmi.exception; | ||
|
||
public class AlreadyExistException extends BadRequestException { | ||
|
||
public static final String ERROR_CODE = "ALREADY_EXIST"; | ||
public static final String ERROR_DESCRIPTION = "(어떠한 것이든) 이미 존재하는 경우"; | ||
|
||
public AlreadyExistException(String message) { | ||
super(message, ERROR_CODE, ERROR_DESCRIPTION); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/gymmi/exception/AuthenticationException.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,15 @@ | ||
package gymmi.exception; | ||
|
||
public class AuthenticationException extends BadRequestException { | ||
|
||
public static final String ERROR_CODE = "AUTHENTICATION"; | ||
public static final String ERROR_DESCRIPTION = "인증에 실패한 경우"; | ||
|
||
public AuthenticationException(String message) { | ||
super(message, ERROR_CODE, ERROR_DESCRIPTION); | ||
} | ||
|
||
public AuthenticationException(String message, Throwable cause) { | ||
super(message, cause, ERROR_CODE, ERROR_DESCRIPTION); | ||
} | ||
} |
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,29 @@ | ||
package gymmi.exception; | ||
|
||
public class BadRequestException extends GymmiException { | ||
|
||
public static final String ERROR_CODE = "INVALID_REQUEST"; | ||
public static final String ERROR_DESCRIPTION = "요청이 잘못 된 경우"; | ||
|
||
public BadRequestException(String message, String errorCode, String errorDescription) { | ||
super(message, errorCode, errorDescription); | ||
} | ||
|
||
public BadRequestException(String message, Throwable cause, String errorCode, String errorDescription) { | ||
super(message, cause, errorCode, errorDescription); | ||
} | ||
|
||
public BadRequestException(String message) { | ||
this(message, ERROR_CODE, ERROR_DESCRIPTION); | ||
} | ||
|
||
@Override | ||
public String getErrorCode() { | ||
return super.getErrorCode(); | ||
} | ||
|
||
@Override | ||
public String getErrorDescription() { | ||
return super.getErrorDescription(); | ||
} | ||
} |
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,16 @@ | ||
package gymmi.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ErrorResponse { | ||
|
||
private final String errorCode; | ||
private final String message; | ||
|
||
public ErrorResponse(String errorCode, String message) { | ||
this.errorCode = errorCode; | ||
this.message = message; | ||
} | ||
} | ||
|
Oops, something went wrong.