-
Notifications
You must be signed in to change notification settings - Fork 1
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
86 changed files
with
2,943 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
title: "[논의] " | ||
labels: ["🙋♂️ Question"] | ||
body: | ||
- type: markdown | ||
attributes: | ||
value: | | ||
This is text that will show up in the template! | ||
- type: textarea | ||
id: background | ||
attributes: | ||
label: 배경 | ||
description: "발의한 배경에 대해 간략히 서술해주세요" | ||
value: | | ||
... | ||
render: bash | ||
validations: | ||
required: true | ||
- type: textarea | ||
id: subject | ||
attributes: | ||
label: 세부 주제 | ||
description: "논의하고 싶은 세부 주제를 작성해주세요." | ||
value: | | ||
1. | ||
2. | ||
3. | ||
render: bash | ||
validations: | ||
required: true |
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
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,21 @@ | ||
name: Build-Test | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v4 | ||
- name: Setup Java | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: 17 | ||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@v4 | ||
- name: Build with Gradle | ||
run: ./gradlew build |
32 changes: 32 additions & 0 deletions
32
src/main/java/camp/woowak/lab/common/advice/DomainExceptionHandler.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,32 @@ | ||
package camp.woowak.lab.common.advice; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.AliasFor; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@RestControllerAdvice | ||
@Order(Ordered.LOWEST_PRECEDENCE - 1) | ||
public @interface DomainExceptionHandler { | ||
@AliasFor(annotation = RestControllerAdvice.class, attribute = "basePackages") | ||
String[] basePackages() default {}; | ||
|
||
@AliasFor(annotation = RestControllerAdvice.class, attribute = "basePackageClasses") | ||
Class<?>[] basePackageClasses() default {}; | ||
|
||
@AliasFor(annotation = RestControllerAdvice.class, attribute = "assignableTypes") | ||
Class<?>[] assignableTypes() default {}; | ||
|
||
@AliasFor(annotation = RestControllerAdvice.class, attribute = "annotations") | ||
Class<? extends Annotation>[] annotations() default {}; | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/camp/woowak/lab/common/advice/GlobalExceptionHandler.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 camp.woowak.lab.common.advice; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ProblemDetail; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ProblemDetail handleAllUncaughtException(Exception e) { | ||
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR, | ||
e.getMessage()); | ||
problemDetail.setProperty("errorCode", "9999"); | ||
|
||
log.error("[Unexpected Exception]", e); | ||
// TODO: Notion Hook 등록 | ||
|
||
return problemDetail; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/camp/woowak/lab/common/exception/BadRequestException.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 camp.woowak.lab.common.exception; | ||
|
||
public class BadRequestException extends HttpStatusException { | ||
public BadRequestException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
|
||
public BadRequestException(ErrorCode errorCode, String message) { | ||
super(errorCode, message); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/camp/woowak/lab/common/exception/ConflictException.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,7 @@ | ||
package camp.woowak.lab.common.exception; | ||
|
||
public class ConflictException extends HttpStatusException { | ||
public ConflictException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/camp/woowak/lab/common/exception/ErrorCode.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 camp.woowak.lab.common.exception; | ||
|
||
public interface ErrorCode { | ||
int getStatus(); | ||
|
||
String getErrorCode(); | ||
|
||
String getMessage(); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/camp/woowak/lab/common/exception/ForbiddenException.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,7 @@ | ||
package camp.woowak.lab.common.exception; | ||
|
||
public class ForbiddenException extends HttpStatusException { | ||
public ForbiddenException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/camp/woowak/lab/common/exception/HttpStatusException.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,20 @@ | ||
package camp.woowak.lab.common.exception; | ||
|
||
public class HttpStatusException extends RuntimeException { | ||
private final ErrorCode errorCode; | ||
|
||
@Deprecated | ||
public HttpStatusException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public HttpStatusException(ErrorCode errorCode, String message) { | ||
super(message); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public ErrorCode errorCode() { | ||
return errorCode; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/camp/woowak/lab/common/exception/MethodNotAllowedException.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,7 @@ | ||
package camp.woowak.lab.common.exception; | ||
|
||
public class MethodNotAllowedException extends HttpStatusException { | ||
public MethodNotAllowedException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/camp/woowak/lab/common/exception/NotFoundException.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,7 @@ | ||
package camp.woowak.lab.common.exception; | ||
|
||
public class NotFoundException extends HttpStatusException { | ||
public NotFoundException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/camp/woowak/lab/common/exception/UnauthorizedException.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,7 @@ | ||
package camp.woowak.lab.common.exception; | ||
|
||
public class UnauthorizedException extends HttpStatusException { | ||
public UnauthorizedException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
Empty file.
44 changes: 38 additions & 6 deletions
44
src/main/java/camp/woowak/lab/customer/domain/Customer.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,13 +1,45 @@ | ||
package camp.woowak.lab.customer.domain; | ||
|
||
import camp.woowak.lab.customer.exception.InvalidCreationException; | ||
import camp.woowak.lab.payaccount.domain.PayAccount; | ||
import jakarta.persistence.*; | ||
import camp.woowak.lab.web.authentication.PasswordEncoder; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OneToOne; | ||
import lombok.Getter; | ||
|
||
@Entity | ||
@Getter | ||
public class Customer { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@OneToOne(fetch = FetchType.LAZY) | ||
private PayAccount payAccount; | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
@Column(nullable = false, length = 50) | ||
private String name; | ||
@Column(unique = true, nullable = false, length = 100) | ||
private String email; | ||
@Column(nullable = false, length = 30) | ||
private String password; | ||
@Column(nullable = false, length = 30) | ||
private String phone; | ||
@OneToOne(fetch = FetchType.LAZY) | ||
private PayAccount payAccount; | ||
|
||
public Customer() { | ||
} | ||
|
||
public Customer(String name, String email, String password, String phone, PayAccount payAccount, | ||
PasswordEncoder passwordEncoder) throws | ||
InvalidCreationException { | ||
CustomerValidator.validateCreation(name, email, password, phone, payAccount); | ||
this.name = name; | ||
this.email = email; | ||
this.password = passwordEncoder.encode(password); | ||
this.phone = phone; | ||
this.payAccount = payAccount; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/camp/woowak/lab/customer/domain/CustomerValidator.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,76 @@ | ||
package camp.woowak.lab.customer.domain; | ||
|
||
import camp.woowak.lab.customer.exception.CustomerErrorCode; | ||
import camp.woowak.lab.customer.exception.InvalidCreationException; | ||
import camp.woowak.lab.payaccount.domain.PayAccount; | ||
|
||
public class CustomerValidator { | ||
private static final int MAX_NAME_LENGTH = 50; | ||
private static final int MAX_EMAIL_LENGTH = 100; | ||
private static final int MIN_PASSWORD_LENGTH = 8; | ||
private static final int MAX_PASSWORD_LENGTH = 30; | ||
private static final int MAX_PHONE_LENGTH = 30; | ||
|
||
private CustomerValidator() { | ||
} | ||
|
||
public static void validateCreation(String name, String email, String password, String phone, | ||
PayAccount payAccount) throws InvalidCreationException { | ||
validateName(name); | ||
validateEmail(email); | ||
validatePassword(password); | ||
validatePhone(phone); | ||
validatePayAccount(payAccount); | ||
} | ||
|
||
public static void validateName(String name) throws InvalidCreationException { | ||
if (name == null || name.isBlank()) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, "Customer name cannot be blank"); | ||
} | ||
if (name.length() > MAX_NAME_LENGTH) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, | ||
"Customer name cannot be longer than 50 characters"); | ||
} | ||
} | ||
|
||
public static void validateEmail(String email) throws InvalidCreationException { | ||
if (email == null || email.isBlank()) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, "Customer email cannot be blank"); | ||
} | ||
if (email.trim().length() > MAX_EMAIL_LENGTH) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, | ||
"Customer email cannot be longer than 100 characters"); | ||
} | ||
} | ||
|
||
public static void validatePassword(String password) throws InvalidCreationException { | ||
if (password == null || password.isBlank()) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, "Customer password cannot be blank"); | ||
} | ||
if (password.trim().length() < MIN_PASSWORD_LENGTH) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, | ||
"Customer password cannot be shorter than 8 characters"); | ||
} | ||
if (password.trim().length() > MAX_PASSWORD_LENGTH) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, | ||
"Customer password cannot be longer than 30 characters"); | ||
} | ||
} | ||
|
||
public static void validatePhone(String phone) throws InvalidCreationException { | ||
if (phone == null || phone.isBlank()) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, "Customer phone cannot be blank"); | ||
} | ||
if (phone.trim().length() > MAX_PHONE_LENGTH) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, | ||
"Customer phone cannot be longer than 30 characters"); | ||
} | ||
} | ||
|
||
public static void validatePayAccount(PayAccount payAccount) throws InvalidCreationException { | ||
if (payAccount == null) { | ||
throw new InvalidCreationException(CustomerErrorCode.INVALID_CREATION, | ||
"Customer payAccount cannot be null"); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/camp/woowak/lab/customer/exception/CustomerErrorCode.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 camp.woowak.lab.customer.exception; | ||
|
||
import camp.woowak.lab.common.exception.ErrorCode; | ||
|
||
public enum CustomerErrorCode implements ErrorCode { | ||
INVALID_CREATION(400, "C1", "잘못된 요청입니다."), | ||
DUPLICATE_EMAIL(400, "C2", "이미 존재하는 이메일입니다."); | ||
|
||
private final int status; | ||
private final String errorCode; | ||
private final String message; | ||
|
||
CustomerErrorCode(int status, String errorCode, String message) { | ||
this.status = status; | ||
this.errorCode = errorCode; | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public int getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public String getErrorCode() { | ||
return errorCode; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
Oops, something went wrong.