Skip to content

Commit

Permalink
Merge pull request #12 from woowa-techcamp-2024/feature/6_Dr-KoKo_점주_…
Browse files Browse the repository at this point in the history
…회원가입

점주 회원가입
  • Loading branch information
Dr-KoKo authored Aug 13, 2024
2 parents 10c1b8c + 1c0386f commit 2b44166
Show file tree
Hide file tree
Showing 40 changed files with 1,318 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import org.springframework.http.ResponseEntity;
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 {
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

@ExceptionHandler(Exception.class)
public ResponseEntity<ProblemDetail> handleAllUncaughtException(Exception e) {
Expand Down
17 changes: 11 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,18 @@
package camp.woowak.lab.customer.domain;

import camp.woowak.lab.payaccount.domain.PayAccount;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;

@Entity
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;
@OneToOne(fetch = FetchType.LAZY)
private PayAccount payAccount;
}
17 changes: 11 additions & 6 deletions src/main/java/camp/woowak/lab/menu/domain/Menu.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package camp.woowak.lab.menu.domain;

import camp.woowak.lab.store.domain.Store;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;

@Entity
public class Menu {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Store store;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Store store;
}
23 changes: 15 additions & 8 deletions src/main/java/camp/woowak/lab/order/domain/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@

import camp.woowak.lab.customer.domain.Customer;
import camp.woowak.lab.store.domain.Store;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

@Entity
@Table(name = "ORDERS")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Customer requester;
@ManyToOne(fetch = FetchType.LAZY)
private Store store;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Customer requester;
@ManyToOne(fetch = FetchType.LAZY)
private Store store;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Entity
public class PayAccount {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package camp.woowak.lab.payaccount.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import camp.woowak.lab.payaccount.domain.PayAccount;

public interface PayAccountRepository extends JpaRepository<PayAccount, Long> {
}
25 changes: 15 additions & 10 deletions src/main/java/camp/woowak/lab/payment/domain/PointPayment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import camp.woowak.lab.customer.domain.Customer;
import camp.woowak.lab.order.domain.Order;
import camp.woowak.lab.vendor.domain.Vendor;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;

@Entity
public class PointPayment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Order order;
@ManyToOne(fetch = FetchType.LAZY)
private Customer sender;
@ManyToOne(fetch = FetchType.LAZY)
private Vendor recipient;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Order order;
@ManyToOne(fetch = FetchType.LAZY)
private Customer sender;
@ManyToOne(fetch = FetchType.LAZY)
private Vendor recipient;
}
17 changes: 11 additions & 6 deletions src/main/java/camp/woowak/lab/store/domain/Store.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package camp.woowak.lab.store.domain;

import camp.woowak.lab.vendor.domain.Vendor;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;

@Entity
public class Store {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Vendor owner;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
private Vendor owner;
}
48 changes: 42 additions & 6 deletions src/main/java/camp/woowak/lab/vendor/domain/Vendor.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
package camp.woowak.lab.vendor.domain;

import camp.woowak.lab.payaccount.domain.PayAccount;
import jakarta.persistence.*;
import camp.woowak.lab.vendor.exception.InvalidVendorCreationException;
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;

@Entity
public class Vendor {
@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;

protected Vendor() {
}

/**
* @throws InvalidVendorCreationException 검증에 실패하면
*/
public Vendor(String name, String email, String password, String phone, PayAccount payAccount,
PasswordEncoder passwordEncoder) {
VendorValidator.validate(name, email, password, phone, payAccount);
this.name = name;
this.email = email;
this.password = passwordEncoder.encode(password);
this.phone = phone;
this.payAccount = payAccount;
}

public Long getId() {
return id;
}
}
64 changes: 64 additions & 0 deletions src/main/java/camp/woowak/lab/vendor/domain/VendorValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package camp.woowak.lab.vendor.domain;

import camp.woowak.lab.payaccount.domain.PayAccount;
import camp.woowak.lab.vendor.exception.InvalidVendorCreationException;
import camp.woowak.lab.vendor.exception.VendorErrorCode;

public final class VendorValidator {
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;

public static void validate(final String name, final String email, final String password, final String phone,
final PayAccount payAccount) throws InvalidVendorCreationException {
checkName(name);
checkEmail(email);
checkPassword(password);
checkPhone(phone);
checkPayAccount(payAccount);
}

private static void checkName(String name) throws InvalidVendorCreationException {
if (name == null || name.isBlank()) {
throw new InvalidVendorCreationException(VendorErrorCode.INVALID_NAME_EMPTY);
}
if (name.length() > MAX_NAME_LENGTH) {
throw new InvalidVendorCreationException(VendorErrorCode.INVALID_NAME_RANGE);
}
}

private static void checkEmail(String email) throws InvalidVendorCreationException {
if (email == null || email.isBlank()) {
throw new InvalidVendorCreationException(VendorErrorCode.INVALID_EMAIL_EMPTY);
}
if (email.trim().length() > MAX_EMAIL_LENGTH) {
throw new InvalidVendorCreationException(VendorErrorCode.INVALID_EMAIL_RANGE);
}
}

private static void checkPassword(String password) throws InvalidVendorCreationException {
if (password == null || password.isBlank()) {
throw new InvalidVendorCreationException(VendorErrorCode.INVALID_PASSWORD_EMPTY);
}
if (password.trim().length() < MIN_PASSWORD_LENGTH || password.trim().length() > MAX_PASSWORD_LENGTH) {
throw new InvalidVendorCreationException(VendorErrorCode.INVALID_PASSWORD_RANGE);
}
}

private static void checkPhone(String phone) throws InvalidVendorCreationException {
if (phone == null || phone.isBlank()) {
throw new InvalidVendorCreationException(VendorErrorCode.INVALID_PHONE_EMPTY);
}
if (phone.trim().length() > MAX_PHONE_LENGTH) {
throw new InvalidVendorCreationException(VendorErrorCode.INVALID_PHONE_RANGE);
}
}

private static void checkPayAccount(PayAccount payAccount) throws InvalidVendorCreationException {
if (payAccount == null) {
throw new InvalidVendorCreationException(VendorErrorCode.INVALID_PAY_ACCOUNT_EMPTY);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package camp.woowak.lab.vendor.exception;

import camp.woowak.lab.common.exception.BadRequestException;

public class DuplicateEmailException extends BadRequestException {
public DuplicateEmailException() {
super(VendorErrorCode.DUPLICATE_EMAIL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package camp.woowak.lab.vendor.exception;

import camp.woowak.lab.common.exception.BadRequestException;
import camp.woowak.lab.common.exception.ErrorCode;

public class InvalidVendorCreationException extends BadRequestException {
public InvalidVendorCreationException(ErrorCode errorCode) {
super(errorCode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package camp.woowak.lab.vendor.exception;

import org.springframework.http.HttpStatus;

import camp.woowak.lab.common.exception.ErrorCode;

public enum VendorErrorCode implements ErrorCode {
INVALID_PHONE_EMPTY(HttpStatus.BAD_REQUEST, "v_1_1", "전화번호가 입력되지 않았습니다."),
INVALID_PHONE_RANGE(HttpStatus.BAD_REQUEST, "v_1_2", "전화번호는 30자를 넘을 수 없습니다."),
INVALID_PASSWORD_EMPTY(HttpStatus.BAD_REQUEST, "v1_3", "비밀번호가 입력되지 않았습니다."),
INVALID_PASSWORD_RANGE(HttpStatus.BAD_REQUEST, "v1_4", "비밀번호는 8-30자 입력되어야 합니다."),
INVALID_EMAIL_EMPTY(HttpStatus.BAD_REQUEST, "v1_5", "이메일이 입력되지 않았습니다."),
INVALID_EMAIL_RANGE(HttpStatus.BAD_REQUEST, "v1_6", "이메일은 100자를 넘을 수 없습니다."),
INVALID_NAME_EMPTY(HttpStatus.BAD_REQUEST, "v1_7", "이름이 입력되지 않았습니다."),
INVALID_NAME_RANGE(HttpStatus.BAD_REQUEST, "v1_8", "이름은 50자를 넘을 수 없습니다."),
INVALID_PAY_ACCOUNT_EMPTY(HttpStatus.BAD_REQUEST, "v_1_9", "포인트 계좌가 입력되지 않았습니다."),
DUPLICATE_EMAIL(HttpStatus.BAD_REQUEST, "v_2", "이미 가입된 이메일입니다.");

private final int status;
private final String errorCode;
private final String message;

VendorErrorCode(HttpStatus httpStatus, String errorCode, String message) {
this.status = httpStatus.value();
this.errorCode = errorCode;
this.message = message;
}

@Override
public int getStatus() {
return status;
}

@Override
public String getErrorCode() {
return errorCode;
}

@Override
public String getMessage() {
return message;
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package camp.woowak.lab.vendor.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import camp.woowak.lab.vendor.domain.Vendor;

public interface VendorRepository extends JpaRepository<Vendor, Long> {
}
Empty file.
Loading

0 comments on commit 2b44166

Please sign in to comment.