Skip to content

Commit

Permalink
[merge] resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
june-777 committed Aug 13, 2024
2 parents 8822290 + 763fabf commit 79fa970
Show file tree
Hide file tree
Showing 86 changed files with 2,943 additions and 41 deletions.
29 changes: 29 additions & 0 deletions .github/DISCUSSION_TEMPLATE/general.yml
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
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: Report bug
about: 오류가 발생한 영역에 대해 보고합니다 [Dev]
title: "[BUG] "
labels: bug
title: "[오류] "
labels: 🐞 BugFix
assignees: ''

---
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
name: Feature request
about: Github Discussion, 회의에서 화제가 된 주제에 대해 제안합니다 [Moderator, Chef]
title: '[REQ]'
labels: enhancement
title: "[기능] "
labels: ✨ Feature
assignees: ''

---
Expand Down
3 changes: 2 additions & 1 deletion .github/pr-template.md → .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
## 💡 다음 이슈를 해결했어요.

### Issue Link - #1

- (가능한 한 자세히 작성해 주시면 도움이 됩니다.)

<br>

## 💡 이슈를 처리하면서 추가된 코드가 있어요.
### Issue Link - #1

- (없다면 이 문항을 지워주세요.)

Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
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
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 {};
}
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;
}
}
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);
}
}
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 src/main/java/camp/woowak/lab/common/exception/ErrorCode.java
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();
}
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);
}
}
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;
}
}
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);
}
}
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);
}
}
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 src/main/java/camp/woowak/lab/customer/domain/Customer.java
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;
}
}
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");
}
}
}
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;
}
}
Loading

0 comments on commit 79fa970

Please sign in to comment.