Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

점주 회원가입 #12

Merged
merged 32 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
99db493
[feat] Vendor 생성자
Dr-KoKo Aug 10, 2024
54ea7e9
[fix] Order 테이블 이름 변경
Dr-KoKo Aug 10, 2024
e7bc581
[style] 코딩 컨벤션 적용
Dr-KoKo Aug 10, 2024
82f364f
[feat] jpa 설정
Dr-KoKo Aug 10, 2024
ed11df9
[feat] SignUpVendorService
Dr-KoKo Aug 10, 2024
03dd63c
[feat] Vendor 회원가입 전송 계층 구현
Dr-KoKo Aug 10, 2024
17a2834
[chore] .gitkeep 삭제
Dr-KoKo Aug 10, 2024
6c2522b
[test] Vendor 도메인 테스트
Dr-KoKo Aug 10, 2024
bcc20a3
[test] Vendor 레포지토리 테스트
Dr-KoKo Aug 10, 2024
a0a49f3
[test] Vendor 서비스 테스트
Dr-KoKo Aug 10, 2024
db202b2
[fix] Vendor 컨트롤러 변경
Dr-KoKo Aug 10, 2024
dc51829
[feat] Phone 검증 기능
Dr-KoKo Aug 10, 2024
0900ed4
[test] Vendor 컨트롤러 테스트
Dr-KoKo Aug 10, 2024
3abdeb9
[feat] Vendor 생성은 비밀번호를 8자부터 허용한다.
Dr-KoKo Aug 11, 2024
c92a634
[test] Vendor 생성은 비밀번호를 8자부터 허용한다.
Dr-KoKo Aug 11, 2024
4e8fa20
[feat] Vendor 회원가입 RequestDto 수정
Dr-KoKo Aug 11, 2024
7bab415
[fix] Vendor 회원가입 RequestDto 수정
Dr-KoKo Aug 11, 2024
8d52b59
[test] 파리미터가 비어있는 Vendor 회원가입 요청
Dr-KoKo Aug 11, 2024
c5755f2
[fix] open-in-view 기본 설정으로 복구
Dr-KoKo Aug 11, 2024
1383d37
Merge remote-tracking branch 'origin/main' into feature/6_Dr-KoKo_점주_…
Dr-KoKo Aug 12, 2024
f9073b5
[fix] 전역 ExceptionHandler 수정
Dr-KoKo Aug 12, 2024
49d8714
[fix] DuplicateEmailException
Dr-KoKo Aug 12, 2024
a967a2c
[feat] Vendor 전용 ErrorCode 생성
Dr-KoKo Aug 12, 2024
819b08d
[fix] Vandor 도메인에서 검증 로직 분리
Dr-KoKo Aug 12, 2024
033b759
[test] Vandor 도메인 테스트 수정
Dr-KoKo Aug 12, 2024
ffdb3a4
[fix] SignUpVendorService는 UncheckedException을 던진다
Dr-KoKo Aug 13, 2024
f1798b2
Merge remote-tracking branch 'origin/main' into feature/6_Dr-KoKo_점주_…
Dr-KoKo Aug 13, 2024
2f94a72
[refactor] 코딩 컨벤션 적용
Dr-KoKo Aug 13, 2024
d6895c3
[fix] VendorApiController는 APIResponse를 응답
Dr-KoKo Aug 13, 2024
5fbc11a
[refactor] 코딩 컨벤션 적용
Dr-KoKo Aug 13, 2024
5235f93
[test] 중복 이메일은 ProblemDetail로 응답
Dr-KoKo Aug 13, 2024
1c0386f
[fix] 기존의 CheckedException 제거
Dr-KoKo Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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