-
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.
MemberService ์ถฉ๋ ํด๊ฒฐ
- Loading branch information
Showing
42 changed files
with
818 additions
and
108 deletions.
There are no files selected for viewing
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
17 changes: 15 additions & 2 deletions
17
src/main/java/com/dnd/dndtravel/auth/controller/request/AppleLoginRequest.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 |
---|---|---|
@@ -1,9 +1,22 @@ | ||
package com.dnd.dndtravel.auth.controller.request; | ||
|
||
//todo ํ๋๊ฐ๋ค ์ ํจ์ฑ ์ฒดํฌ | ||
// todo ์ ๋ ฅ ์์ ์์๋ ํด๋ผ์์ String ํ์ ๋ค. RED, ORANGE, YELLOW, MELON, BLUE, PURPLE | ||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
import com.dnd.dndtravel.auth.controller.request.validation.ColorValidation; | ||
import com.dnd.dndtravel.member.domain.SelectedColor; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public record AppleLoginRequest( | ||
@Schema(description = "authorization code", requiredMode = REQUIRED) | ||
@NotBlank(message = "authorization code๋ ํ์ ์ ๋๋ค.") | ||
@Size(max = 300, message = "authorization code ํ์์ด ์๋๋๋ค") | ||
String appleToken, | ||
|
||
@Schema(description = "์ ์ ๊ฐ ์ ํํ ์์", requiredMode = REQUIRED) | ||
@ColorValidation(enumClass = SelectedColor.class) | ||
String selectedColor | ||
){ | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/dnd/dndtravel/auth/controller/request/validation/ColorValidation.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,16 @@ | ||
package com.dnd.dndtravel.auth.controller.request.validation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.validation.Constraint; | ||
|
||
@Constraint(validatedBy = {ColorValidator.class}) | ||
@Target(ElementType.FIELD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ColorValidation { | ||
String message() default "invalid region"; | ||
Class<? extends java.lang.Enum<?>> enumClass(); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/dnd/dndtravel/auth/controller/request/validation/ColorValidator.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,37 @@ | ||
package com.dnd.dndtravel.auth.controller.request.validation; | ||
|
||
import java.util.Arrays; | ||
|
||
import com.dnd.dndtravel.map.controller.request.validation.RegionCondition; | ||
import com.dnd.dndtravel.map.controller.request.validation.RegionEnum; | ||
import com.dnd.dndtravel.member.domain.SelectedColor; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
public class ColorValidator implements ConstraintValidator<ColorValidation, String> { | ||
|
||
private ColorValidation annotation; | ||
|
||
|
||
@Override | ||
public void initialize(ColorValidation constraintAnnotation) { | ||
this.annotation = constraintAnnotation; | ||
} | ||
|
||
@Override | ||
public boolean isValid(String color, ConstraintValidatorContext context) { | ||
// ์์ ์์ผ๋ฉด ์์ธ | ||
if (color == null || color.isBlank()) { | ||
return false; | ||
} | ||
|
||
Object[] enumValues = this.annotation.enumClass().getEnumConstants(); | ||
if (enumValues == null) { | ||
return false; | ||
} | ||
|
||
// ์์ Enum์ค ํ๋๋ผ๋ ํด๋น๋๋ฉด true | ||
return Arrays.stream(enumValues).anyMatch(enumValue -> SelectedColor.isMatch(color)); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/dnd/dndtravel/auth/controller/swagger/AuthControllerSwagger.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,67 @@ | ||
package com.dnd.dndtravel.auth.controller.swagger; | ||
|
||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import com.dnd.dndtravel.auth.controller.request.AppleLoginRequest; | ||
import com.dnd.dndtravel.auth.controller.request.ReIssueTokenRequest; | ||
import com.dnd.dndtravel.auth.service.dto.response.ReissueTokenResponse; | ||
import com.dnd.dndtravel.auth.service.dto.response.TokenResponse; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
@Tag(name = "auth", description = "์ธ์ฆ API") | ||
public interface AuthControllerSwagger { | ||
|
||
String STATUS_CODE_400_BODY_MESSAGE = "{\"message\":\"์๋ชป๋ ์์ฒญ์ ๋๋ค\"}"; | ||
|
||
@Operation( | ||
summary = "์ ํ OAuth login API" | ||
) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "์ ์ ๋ก๊ทธ์ธ", | ||
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), | ||
@ApiResponse(responseCode = "204", description = "refresh token ์ฌ๋ฐ๊ธ ํ์์", | ||
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), | ||
@ApiResponse( | ||
responseCode = "500", description = "์๋ฒ ์ค๋ฅ", | ||
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(example = "{\"message\":\"Internal Server Error\"}") | ||
) | ||
) | ||
}) | ||
ResponseEntity<TokenResponse> appleOAuthLogin( | ||
@Parameter(description = "๋ก๊ทธ์ธ ์์ฒญ ์ ๋ณด(authorization code, color)", required = true) | ||
AppleLoginRequest appleLoginRequest | ||
); | ||
|
||
@Operation( | ||
summary = "Refresh Token ์ฌ๋ฐ๊ธ API" | ||
) | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "์ ์ ๋ฐ๊ธ", | ||
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = ReissueTokenResponse.class))), | ||
@ApiResponse(responseCode = "400", description = "์ ํจํ์ง ์์ RefreshToken ์์ฒญ์", | ||
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(example = STATUS_CODE_400_BODY_MESSAGE) | ||
) | ||
), | ||
@ApiResponse( | ||
responseCode = "500", description = "์๋ฒ ์ค๋ฅ", | ||
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(example = "{\"message\":\"Internal Server Error\"}") | ||
) | ||
) | ||
}) | ||
ReissueTokenResponse reissueToken( | ||
@Parameter(description = "refreshToken", required = true) | ||
ReIssueTokenRequest reissueTokenRequest | ||
); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dnd/dndtravel/auth/exception/AppleTokenDecodingException.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,9 @@ | ||
package com.dnd.dndtravel.auth.exception; | ||
|
||
public class AppleTokenDecodingException extends RuntimeException { | ||
private static final String MESSAGE = "Apple ํ ํฐ payload ํด๋ ์คํจ"; | ||
|
||
public AppleTokenDecodingException(Exception e) { | ||
super(MESSAGE, e); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/dnd/dndtravel/auth/exception/JwtTokenDecodingException.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,11 @@ | ||
package com.dnd.dndtravel.auth.exception; | ||
|
||
import io.jsonwebtoken.JwtException; | ||
|
||
public class JwtTokenDecodingException extends RuntimeException { | ||
private static final String MESSAGE = "Jwt ํ ํฐ ํด๋ ์คํจ"; | ||
|
||
public JwtTokenDecodingException(JwtException e) { | ||
super(MESSAGE, e); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/dnd/dndtravel/auth/exception/JwtTokenExpiredException.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,11 @@ | ||
package com.dnd.dndtravel.auth.exception; | ||
|
||
import io.jsonwebtoken.ExpiredJwtException; | ||
|
||
public class JwtTokenExpiredException extends RuntimeException { | ||
private static final String MESSAGE = "Jwt ํ ํฐ์ด ๋ง๋ฃ๋์์"; | ||
|
||
public JwtTokenExpiredException(ExpiredJwtException e) { | ||
super(MESSAGE, e); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dnd/dndtravel/auth/exception/RefreshTokenInvalidException.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,9 @@ | ||
package com.dnd.dndtravel.auth.exception; | ||
|
||
public class RefreshTokenInvalidException extends RuntimeException { | ||
private static final String MESSAGE = "์ ํจํ์ง ์์ RefreshToken ํ ํฐ [refreshToken=%s]"; | ||
|
||
public RefreshTokenInvalidException(String refreshToken) { | ||
super(String.format(MESSAGE, 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
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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/dnd/dndtravel/auth/service/MemberNameGenerator.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,33 @@ | ||
package com.dnd.dndtravel.auth.service; | ||
|
||
import java.util.Random; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MemberNameGenerator { | ||
private static final String[] ADJECTIVES = { | ||
"๊ฐ๋ํ", "๊ฐ์พ์", "๊ฑฐ์ผ", "๊ฑฐ์น", "๊ฑด์กฐํ", | ||
"๊ฒ์ผ๋ฅธ", "๊ณ ๋ฌํ", "๊ท์ฌ์ด", "๊ทธ๋ฆฌ์ด", "๊นจ๋ํ", | ||
"๋๋ฐ", "๋๋ฆฐ", "๋๋ฌ์ด", "๋๋", "๋๊ทธ๋", "๋ฐ์ด๋", | ||
"๋ฌด์์ด", "๋ฏธ์น", "๋ณด๋์ฐฌ", "๋ฝ์", "๋น์ผ", "์ํฐ","์ฃ๋ถ๋ฅธ", | ||
"์ฑ๊ฐ์ ","์์ค์","์์ด๊ฐ์","๋ชป๋", "๋ชป์๊ธด", "๋ฌด๊ฑฐ์ด", "๋น ๋ฅธ", | ||
"์ฉ๊ฐํ", "ํ๋ณตํ", "์ฌํ", "ํ์ค๋ฌ์ด", "ํ๊ฒฐ๊ฐ์","ํฌ๋ง์ฐฌ" | ||
}; | ||
|
||
private static final String[] ANIMALS = { | ||
"์ฌ์", "ํธ๋์ด", "๊ณฐ", "์ฌ์ฐ", "ํ ๋ผ", | ||
"๊ฑฐ๋ถ์ด", "๊ณ ์์ด", "๋๋", "๊ฐ์์ง", "ํฌ๋", | ||
"๋ณ์๋ฆฌ", "๋ง์์ง", "์ฝ๋ผ๋ฆฌ", "์ค์ง์ด", "๋ฐํด๋ฒ๋ ", | ||
"๊ฑฐ๋จธ๋ฆฌ", "๊ฐ๋ฏธํฅ๊ธฐ", "๋๊ณ ๋", "์๋ก", "์ฌ๋นผ๋ฏธ", "๋ฐ์ฅ", | ||
"ํญ๊ท", "๋๋ฌด๋๋ณด", "์ค์๋ฆฌ", "ํ์ด์๋", "ํ์คํฐ" | ||
}; | ||
|
||
private final Random random = new Random(); | ||
|
||
public String generateRandomName() { | ||
String adjective = ADJECTIVES[this.random.nextInt(ADJECTIVES.length)]; | ||
String animal = ANIMALS[this.random.nextInt(ANIMALS.length)]; | ||
return adjective + animal; | ||
} | ||
} |
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
Oops, something went wrong.