From 60f966288e05c6d89177ff8ffbfc4b1e1ac9a3a1 Mon Sep 17 00:00:00 2001 From: 1223v <1223v@naver.com> Date: Tue, 14 Nov 2023 06:01:23 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20DB=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyvery/readyverydemo/domain/Cart.java | 50 ++++++++++ .../readyverydemo/domain/CartItem.java | 54 +++++++++++ .../readyverydemo/domain/CartOption.java | 45 +++++++++ .../readyverydemo/domain/CeoInfo.java | 94 +++++++++++++++++++ .../readyverydemo/domain/Foodie.java | 74 +++++++++++++++ .../readyverydemo/domain/FoodieOption.java | 53 +++++++++++ .../domain/FoodieOptionCategory.java | 57 +++++++++++ .../readyvery/readyverydemo/domain/Grade.java | 15 +++ .../readyvery/readyverydemo/domain/Store.java | 80 ++++++++++++++++ .../readyverydemo/domain/TakeOut.java | 34 +++++++ .../readyverydemo/domain/UserInfo.java | 59 ++++++++++-- 11 files changed, 608 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/Cart.java create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/CartItem.java create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/CartOption.java create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/CeoInfo.java create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/Foodie.java create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/FoodieOption.java create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/FoodieOptionCategory.java create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/Grade.java create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/Store.java create mode 100644 src/main/java/com/readyvery/readyverydemo/domain/TakeOut.java diff --git a/src/main/java/com/readyvery/readyverydemo/domain/Cart.java b/src/main/java/com/readyvery/readyverydemo/domain/Cart.java new file mode 100644 index 0000000..41ae319 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/Cart.java @@ -0,0 +1,50 @@ +package com.readyvery.readyverydemo.domain; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.persistence.CascadeType; +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.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "CARTS") +@AllArgsConstructor +@Slf4j +public class Cart { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "cart_idx") + private Long id; + + // 장바구니 유저 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_idx") + private UserInfo userInfo; + + // 장바구니 가게 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_idx") + private Store store; + + // 장바구니 장바구니 아이템 연관관계 매핑 + @OneToMany(mappedBy = "cart", cascade = CascadeType.ALL) + private List cartItems = new ArrayList(); + +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/CartItem.java b/src/main/java/com/readyvery/readyverydemo/domain/CartItem.java new file mode 100644 index 0000000..0708382 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/CartItem.java @@ -0,0 +1,54 @@ +package com.readyvery.readyverydemo.domain; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.persistence.CascadeType; +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.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "CART_ITEMS") +@AllArgsConstructor +@Slf4j +public class CartItem { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "cart_item_idx") + private Long id; + + // 장바구니 아이템 수량 + @Column(nullable = false) + private Long count; + + // 장바구니 메뉴 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "foodie_idx") + private Foodie foodie; + + // 장바구니 아이템 장바구니 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "cart_idx") + private Cart cart; + + // 장바구니 아이템 - 장바구니 옵션 연관관계 매핑 + @OneToMany(mappedBy = "cartItem", cascade = CascadeType.ALL) + private List cartOptions = new ArrayList(); + +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/CartOption.java b/src/main/java/com/readyvery/readyverydemo/domain/CartOption.java new file mode 100644 index 0000000..d43475e --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/CartOption.java @@ -0,0 +1,45 @@ +package com.readyvery.readyverydemo.domain; + +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.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "CART_OPTIONS") +@AllArgsConstructor +@Slf4j +public class CartOption { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "cart_option_idx") + private Long id; + + // 장바구니 옵션 - 메뉴 옵션 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "foodie_option_idx") + private FoodieOption foodieOption; + + // 장바구니 옵션 - 장바구니 아이템 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "cart_item_idx") + private CartItem cartItem; + + // 장바구니 옵션 - 메뉴 카테고리 옵션 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "foodie_option_category_idx") + private FoodieOptionCategory foodieOptionCategory; + +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/CeoInfo.java b/src/main/java/com/readyvery/readyverydemo/domain/CeoInfo.java new file mode 100644 index 0000000..6ec406c --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/CeoInfo.java @@ -0,0 +1,94 @@ +package com.readyvery.readyverydemo.domain; + +import static jakarta.persistence.FetchType.*; + +import java.time.LocalDateTime; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Builder +@Table(name = "CEOS") +@AllArgsConstructor +@Slf4j +public class CeoInfo extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ceo_idx") + private Long id; + + // 이메일 + @Column(nullable = false, length = 45) + private String email; + + // 닉네임 + @Column(nullable = false) + private String nickName; + + // 프로필 이미지 + @Column(nullable = false, columnDefinition = "TEXT") + private String imageUrl; + + // 연령대 + @Column + private String age; + + // 생일 + @Column(nullable = false) + private String birth; + + // 전화번호 + @Column(nullable = false) + private String phone; + + // 계좌번호 + @Column + private String accountNumber; + + // 소셜 로그인 타입 + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private SocialType socialType; // KAKAO, NAVER, GOOGLE + + // 소셜 로그인 타입의 식별자 값 (일반 로그인인 경우 null) + @Column(nullable = false) + private String socialId; // 로그인한 소셜 타입의 식별자 값 (일반 로그인인 경우 null) + + // 유저 상태 + @Column(nullable = false, columnDefinition = "BOOLEAN default true") + private boolean status; + + // 리프레시 토큰 + @Column(columnDefinition = "TEXT") + private String refreshToken; + + // 계정 삭제 요청일 + @Column + private LocalDateTime deleteDate; + + // 마지막 로그인 일시 + @Column + private LocalDateTime lastLoginDate; + + // 사장님 가게 연관관계 매핑 + @OneToOne(mappedBy = "ceoInfo", fetch = LAZY) + private Store store; + +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/Foodie.java b/src/main/java/com/readyvery/readyverydemo/domain/Foodie.java new file mode 100644 index 0000000..94ee134 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/Foodie.java @@ -0,0 +1,74 @@ +package com.readyvery.readyverydemo.domain; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.persistence.CascadeType; +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.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "FOODIES") +@AllArgsConstructor +@Slf4j +public class Foodie { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "foodie_idx") + private Long id; + + //식품 이름 + @Column(nullable = false) + private String name; + + //식품 가격 + @Column(nullable = false) + private Long price; + + //식품 이미지 + @Column(nullable = false) + private String imgUrl; + + //식품 매진 + @Column(nullable = false, columnDefinition = "BOOLEAN default false") + private boolean soldOut; + + //식품 카테고리 + @Column(nullable = false) + private String category; + + //메뉴 - 가게 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_idx") + private Store store; + + //메뉴 - 식품 카테고리 연관관계 매핑 + @OneToMany(mappedBy = "foodie", cascade = CascadeType.ALL) + private List foodieOptionCategory = new ArrayList(); + + //메뉴 - 테이크 아웃 연관관계 매핑 + @OneToOne(mappedBy = "foodie", cascade = CascadeType.ALL) + private TakeOut takeOut; + + //메뉴 - 장바구니 아이템 연관관계 매핑 + @OneToMany(mappedBy = "foodie", cascade = CascadeType.ALL) + private List cartItems = new ArrayList(); + +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/FoodieOption.java b/src/main/java/com/readyvery/readyverydemo/domain/FoodieOption.java new file mode 100644 index 0000000..4cd6000 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/FoodieOption.java @@ -0,0 +1,53 @@ +package com.readyvery.readyverydemo.domain; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.persistence.CascadeType; +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.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "FOODIE_OPTIONS") +@AllArgsConstructor +@Slf4j +public class FoodieOption { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "foodie_option_idx") + private Long id; + + //식품 옵션 이름 + @Column(nullable = false) + private String name; + + //식품 옵션 가격 + @Column(nullable = false) + private Long price; + + //식품 옵션 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "foodie_option_category_idx") + private FoodieOptionCategory foodieOptionCategory; + + // 식품 옵션 - 장바구니 옵션 연관관계 매핑 + @OneToMany(mappedBy = "foodieOption", cascade = CascadeType.ALL) + private List cartOptions = new ArrayList(); + +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/FoodieOptionCategory.java b/src/main/java/com/readyvery/readyverydemo/domain/FoodieOptionCategory.java new file mode 100644 index 0000000..453ef7d --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/FoodieOptionCategory.java @@ -0,0 +1,57 @@ +package com.readyvery.readyverydemo.domain; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.persistence.CascadeType; +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.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "FOODIE_OPTION_CATEGORIES") +@AllArgsConstructor +@Slf4j +public class FoodieOptionCategory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "foodie_option_category_idx") + private Long id; + + //식품 옵션 카테고리 이름 + @Column(nullable = false) + private String name; + + //식품 선택 필수 여부 + @Column(nullable = false, columnDefinition = "BOOLEAN default false") + private boolean required; + + //식품 옵션 카테고리 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "foodie_idx") + private Foodie foodie; + + //식품 옵션 연관관계 매핑 + @OneToMany(mappedBy = "foodieOptionCategory", cascade = CascadeType.ALL) + private List foodieOptions = new ArrayList(); + + // 식품 옵션 카테고리 - 장바구니 옵션 연관관계 매핑 + @OneToMany(mappedBy = "foodieOptionCategory", cascade = CascadeType.ALL) + private List cartOptions = new ArrayList(); + +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/Grade.java b/src/main/java/com/readyvery/readyverydemo/domain/Grade.java new file mode 100644 index 0000000..f6d5ae1 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/Grade.java @@ -0,0 +1,15 @@ +package com.readyvery.readyverydemo.domain; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum Grade { + + ORDA("ORDA", 4.0D), + DEFAULT("Earlier", 6.3D); + + private final String description; + private final Double fee; +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/Store.java b/src/main/java/com/readyvery/readyverydemo/domain/Store.java new file mode 100644 index 0000000..bd4cf40 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/Store.java @@ -0,0 +1,80 @@ +package com.readyvery.readyverydemo.domain; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "STORES") +@AllArgsConstructor +@Slf4j +public class Store { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "store_idx") + private Long id; + + //가게 이름 + @Column(nullable = false) + private String name; + + //가게 주소 + @Column(nullable = false) + private String address; + + //가게 전화번호 + @Column(nullable = false) + private String phone; + + //가게 영업시간 + @Column(nullable = false) + private String time; + + //가게 영업중 여부 + @Column(nullable = false, columnDefinition = "BOOLEAN default true") + private boolean status; + + //가게 광고 이미지 + @Column + private String adImgUrl; + + //가게 등급 + @Column + @Enumerated(EnumType.STRING) + private Grade grade; + + //가게 사장님 연관관계 매핑 + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "ceo_idx") + private CeoInfo ceoInfo; + + //가게 메뉴 연관관계 매핑 + @OneToMany(mappedBy = "store", cascade = CascadeType.ALL) + private List foodies = new ArrayList<>(); + + //가게 장바구니 연관관계 매핑 + @OneToMany(mappedBy = "store", cascade = CascadeType.ALL) + private List carts = new ArrayList<>(); + +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/TakeOut.java b/src/main/java/com/readyvery/readyverydemo/domain/TakeOut.java new file mode 100644 index 0000000..2e3c4a9 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/TakeOut.java @@ -0,0 +1,34 @@ +package com.readyvery.readyverydemo.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Table(name = "TAKE_OUTS") +@AllArgsConstructor +@Slf4j +public class TakeOut { + + //테이크 아웃 메뉴 연관관계 매핑 + @Id + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "foodie_idx") + private Foodie foodie; + + //테이크 아웃 가격 + @Column + private Long price; + +} diff --git a/src/main/java/com/readyvery/readyverydemo/domain/UserInfo.java b/src/main/java/com/readyvery/readyverydemo/domain/UserInfo.java index e9b52ab..8d3f5b7 100644 --- a/src/main/java/com/readyvery/readyverydemo/domain/UserInfo.java +++ b/src/main/java/com/readyvery/readyverydemo/domain/UserInfo.java @@ -1,5 +1,10 @@ package com.readyvery.readyverydemo.domain; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -7,6 +12,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -23,33 +29,72 @@ @AllArgsConstructor @Slf4j public class UserInfo extends BaseTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "user_id") + @Column(name = "user_idx") private Long id; - @Column(nullable = false) - private String email; // 이메일 + // 이메일 + @Column(nullable = false, length = 45) + private String email; + // 닉네임 @Column(nullable = false) - private String nickName; // 닉네임 + private String nickName; + // 프로필 이미지 + @Column(nullable = false, columnDefinition = "TEXT") + private String imageUrl; - private String imageUrl; // 프로필 이미지 - private int age; // 나이 + // 연령대 + @Column + private String age; + // 생일 + @Column(nullable = false) + private String birth; + + // 전화번호 + @Column(nullable = false) + private String phone; + + // 유저 권한 + @Column(nullable = false, columnDefinition = "VARCHAR(10) default 'USER'") @Enumerated(EnumType.STRING) private Role role; + // 소셜 로그인 타입 @Column(nullable = false) @Enumerated(EnumType.STRING) private SocialType socialType; // KAKAO, NAVER, GOOGLE + // 소셜 로그인 타입의 식별자 값 (일반 로그인인 경우 null) @Column(nullable = false) private String socialId; // 로그인한 소셜 타입의 식별자 값 (일반 로그인인 경우 null) - private String refreshToken; // 리프레시 토큰 + // 유저 상태 + @Column(nullable = false, columnDefinition = "BOOLEAN default true") + private boolean status; + + // 리프레시 토큰 + @Column(columnDefinition = "TEXT") + private String refreshToken; + + // 계정 삭제 요청일 + @Column + private LocalDateTime deleteDate; + + // 마지막 로그인 일시 + @Column + private LocalDateTime lastLoginDate; + + // 유저 장바구니 연관관계 매핑 + @Builder.Default + @OneToMany(mappedBy = "userInfo", cascade = CascadeType.ALL) + private List carts = new ArrayList(); + // 리프레시토큰 업데이트 public void updateRefresh(String updateRefreshToken) { this.refreshToken = updateRefreshToken; } From c32693d26d6aab0b4574e48d26a1b699636249d1 Mon Sep 17 00:00:00 2001 From: 1223v <1223v@naver.com> Date: Tue, 14 Nov 2023 06:02:58 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Config:=20properties=20redirect=20url?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyverydemo/domain/UserInfo.java | 4 +-- .../security/jwt/service/JwtService.java | 28 ++++++++----------- .../handler/OAuth2LoginSuccessHandler.java | 2 +- src/main/resources/application.properties | 2 ++ 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/domain/UserInfo.java b/src/main/java/com/readyvery/readyverydemo/domain/UserInfo.java index 8d3f5b7..ebf7338 100644 --- a/src/main/java/com/readyvery/readyverydemo/domain/UserInfo.java +++ b/src/main/java/com/readyvery/readyverydemo/domain/UserInfo.java @@ -52,11 +52,11 @@ public class UserInfo extends BaseTimeEntity { private String age; // 생일 - @Column(nullable = false) + @Column private String birth; // 전화번호 - @Column(nullable = false) + @Column private String phone; // 유저 권한 diff --git a/src/main/java/com/readyvery/readyverydemo/security/jwt/service/JwtService.java b/src/main/java/com/readyvery/readyverydemo/security/jwt/service/JwtService.java index 8936789..70aea91 100644 --- a/src/main/java/com/readyvery/readyverydemo/security/jwt/service/JwtService.java +++ b/src/main/java/com/readyvery/readyverydemo/security/jwt/service/JwtService.java @@ -26,21 +26,6 @@ @Slf4j public class JwtService { - @Value("${jwt.secretKey}") - private String secretKey; - - @Value("${jwt.access.expiration}") - private Long accessTokenExpirationPeriod; - - @Value("${jwt.refresh.expiration}") - private Long refreshTokenExpirationPeriod; - - @Value("${jwt.access.cookie}") - private String accessCookie; - - @Value("${jwt.refresh.cookie}") - private String refreshCookie; - /** * JWT의 Subject와 Claim으로 email 사용 -> 클레임의 name을 "email"으로 설정 * JWT의 헤더에 들어오는 값 : 'Authorization(Key) = Bearer {토큰} (Value)' 형식 @@ -50,8 +35,19 @@ public class JwtService { private static final String EMAIL_CLAIM = "email"; //private static final String BEARER = "Bearer "; private static final String USER_NUMBER = "userNumber"; - private final UserRepository userRepository; + @Value("${jwt.secretKey}") + private String secretKey; + @Value("${jwt.access.expiration}") + private Long accessTokenExpirationPeriod; + @Value("${jwt.refresh.expiration}") + private Long refreshTokenExpirationPeriod; + @Value("${jwt.access.cookie}") + private String accessCookie; + @Value("${jwt.refresh.cookie}") + private String refreshCookie; + @Value("${jwt.redirect-uri}") + private String frontendUrl; /** * AccessToken 생성 메소드 diff --git a/src/main/java/com/readyvery/readyverydemo/security/oauth2/handler/OAuth2LoginSuccessHandler.java b/src/main/java/com/readyvery/readyverydemo/security/oauth2/handler/OAuth2LoginSuccessHandler.java index face0cc..454ea8f 100644 --- a/src/main/java/com/readyvery/readyverydemo/security/oauth2/handler/OAuth2LoginSuccessHandler.java +++ b/src/main/java/com/readyvery/readyverydemo/security/oauth2/handler/OAuth2LoginSuccessHandler.java @@ -34,7 +34,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo loginSuccess(response, oAuth2User); // 로그인에 성공한 경우 access, refresh 토큰 생성 log.info("OAuth2 Login 성공! - 로그인 성공 후 리다이렉트"); - response.sendRedirect("http://localhost:3000/login"); + response.sendRedirect(jwtService.getFrontendUrl()); } catch (Exception e) { throw e; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index bd6a215..737d443 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -9,6 +9,7 @@ jwt.access.expiration=86400 jwt.access.cookie=accessToken jwt.refresh.expiration=604800 jwt.refresh.cookie=refreshToken +jwt.redirect-uri=http://localhost:3000/login # Kakao spring.security.oauth2.client.registration.kakao.client-id=e35c097c37d24f762290ec7e9e81887b spring.security.oauth2.client.registration.kakao.client-secret=bMT73UM5sM7xfB5yulXMtsxPtjmsJfGS @@ -21,3 +22,4 @@ spring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kak spring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token spring.security.oauth2.client.provider.kakao.user-info-uri=https://kapi.kakao.com/v2/user/me spring.security.oauth2.client.provider.kakao.user-name-attribute=id +