Skip to content

Commit

Permalink
Merge pull request #72 from codestates-seb/feature/NEM-248-서버운영환경설정
Browse files Browse the repository at this point in the history
Feature/nem-248 서버운영환경설정(application-server.yml, schema 추가)
  • Loading branch information
Si-Hyeak-KANG committed Oct 11, 2022
2 parents cb98a12 + 4e71867 commit b99b7d3
Show file tree
Hide file tree
Showing 23 changed files with 218 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
public interface ProductRepositoryCustom {

@Query(nativeQuery = true, value = "SELECT * FROM product WHERE vegetarian_type IN " +
"(SELECT vegetarian_type FROM vegetarian WHERE level " +
"< (SELECT level FROM vegetarian WHERE vegetarian_type = :vegetarianType) " +
"(SELECT vegetarian_type FROM vegetarian WHERE levels " +
"< (SELECT levels FROM vegetarian WHERE vegetarian_type = :vegetarianType) " +
"OR vegetarian_type = :vegetarianType)")
Page<Product> findAllByVegetarianTypeName(@Param("vegetarianType") String vegetarianType, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.noterror.app.api.entity;

import com.noterror.app.api.entity.member.Member;
import lombok.*;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
Expand All @@ -18,5 +15,5 @@ public class Vegetarian {
private String vegetarianType;

@Column
private Integer level;
private Integer levels;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
@Setter
@Getter
@Entity
@Table(name = "CART_DETAIL")
@Table(name = "cart_detail")
public class CartDetail {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cart_detail_id")
private Long cartDetailId; // CART_DETAIL_ID

@Column
private int purchaseQuantity;

@ManyToOne
Expand All @@ -41,8 +41,8 @@ public void addPurchaseQuantity(int purchaseQuantity) {
this.purchaseQuantity += purchaseQuantity;
}

public void updatePurchaseQuantity(int purchaseQuntity) {
this.purchaseQuantity = purchaseQuntity;
public void updatePurchaseQuantity(int purchaseQuantity) {
this.purchaseQuantity = purchaseQuantity;
}

public static CartDetail createCartDetail(Cart cart, Product product, int count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;

import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
Expand All @@ -16,7 +17,9 @@
public class Address {

private String zipCode;

private String city;

private String detailAddress;

protected Address() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Member extends Auditable implements Principal {
@Column(nullable = false)
private String memberName;

@Column
private String password;

@Column(nullable = false)
Expand All @@ -37,12 +38,17 @@ public class Member extends Auditable implements Principal {
@Embedded
private Address address;

@Column
private String vegetarianType;

@OneToOne(mappedBy = "member")
private Cart cart;

@ElementCollection(fetch = FetchType.EAGER)
@ElementCollection
@CollectionTable(
name = "roles",
joinColumns = @JoinColumn(name = "member_id")
)
private List<String> roles = new ArrayList<>();

//== BUSINESS LOGIC ==//
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@Builder
@Getter
@Setter
@Table(name = "order_product")
public class OrderProduct {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Builder
@Getter
@Setter
@Table(name = "ORDERS")
@Table(name = "orders")
public class Orders extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
public class Auditable {

@CreatedDate
@Column(updatable = false)
@Column(updatable = false, name = "create_date")
private LocalDateTime createDate;

@LastModifiedDate
@Column
@Column(name = "edit_date")
private LocalDateTime editDate;
}
39 changes: 27 additions & 12 deletions server/src/main/resources/application-server.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
spring:
sql:
init:
# schema-locations:
# - classpath*:db/mysql/member/roles_schema.sql
# - classpath*:db/mysql/cart_detail/cart_detail_schema.sql
# - classpath*:db/mysql/cart/cart_schema.sql
# - classpath*:db/mysql/order_product/order_product_schema.sql
# - classpath*:db/mysql/order/order_schema.sql
# - classpath*:db/mysql/member/member_schema.sql
# - classpath*:db/mysql/product/product_schema.sql
# - classpath*:db/mysql/vegetarian/vegetarian_schema.sql
# - classpath*:db/mysql/constraint.sql
data-locations:
- classpath*:db/mysql/data.sql
encoding: UTF-8
mode: always

jpa:
database: mysql
open-in-view: false
hibernate:
ddl-auto: create
#defer-datasource-initialization: true
show-sql: false
defer-datasource-initialization: true

datasource:
password: seb39main1
url: jdbc:mysql://database-3.cn22higluw0t.ap-northeast-2.rds.amazonaws.com:13306/test
username: admin
password: ${RDS_PASSWORD}
url: ${RDS_URL}
username: ${RDS_USERNAME}
driver-class-name: com.mysql.cj.jdbc.Driver

sql:
init:
mode: always


logging:
level:
org:
Expand All @@ -23,11 +38,11 @@ logging:
jpa: DEBUG

jwt:
access-token-expiration-minutes: 60
access-token-expiration-minutes: 30
refresh-token-expiration-minutes: 420
key:
secret: noterrorvegetarian7894431123412341234qwerjameshongyunAAgErt
secret: ${JWT_SECRET_KEY}

mail:
address:
admin: [email protected]
admin: ${ADMIN_MAIL}
6 changes: 3 additions & 3 deletions server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ logging:
jpa: DEBUG

jwt:
access-token-expiration-minutes: 60
access-token-expiration-minutes: 150
refresh-token-expiration-minutes: 420
key:
secret: noterrorvegetarian7894431123412341234qwerjameshongyunAAgErt
secret: ${JWT_SECRET_KEY}

mail:
address:
admin: [email protected]
admin: ${ADMIN_MAIL}
4 changes: 2 additions & 2 deletions server/src/main/resources/db/h2/data.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INSERT INTO VEGETARIAN (vegetarian_type,level)
INSERT INTO VEGETARIAN (vegetarian_type,levels)
VALUES ('프루테리언',1),
('비건', 2),
('오보', 3),
Expand All @@ -9,7 +9,7 @@ VALUES ('프루테리언',1),
('폴로-페스코', 6),
('플렉시테리언', 7);

INSERT INTO PRODUCT (product_name, price, stock_quantity, create_date,edit_date, thumbnail_image, detail_image, vegetarian_type)
INSERT INTO PRODUCT (product_name, price, stock_quantity, create_date, edit_date, thumbnail_image, detail_image, vegetarian_type)
VALUES ('아삭빨강 대추방울토마토', 9900, 100, '2022-10-01T10:11:12','2022-10-01T10:11:12', 'https://www.oasis.co.kr:48581/product/1663/detail/thumb_1663b2d53ccd-1403-47e7-8ee1-f9f593b5bb4e.jpg', 'https://www.oasis.co.kr:48580//se/2018/10/8/se_2f83f139-e44b-4aec-a464-37736735de8e.jpg', '프루테리언'),
('맛있는 단감', 16200, 100, '2022-10-01T10:11:14','2022-10-01T10:11:14', 'https://www.oasis.co.kr:48581/product/2311/detail/thumb_2311ba1c0a35-3b88-4371-b625-4dc484bb427f.jpg', 'https://oasis.co.kr:9888/view/se/?imagePath=2020/10/13/se_2020a4dc3661-a64a-494b-9425-8430a8eaa4e2.gif', '프루테리언'),
('충북 영동 샤인머스캣', 14800, 100, '2022-10-01T10:11:16','2022-10-01T10:11:16', 'https://www.oasis.co.kr:48581/product/834/detail/thumb_8348c63ad7e-cb1b-4ceb-b4a0-257717417f5d.jpg', 'https://www.oasis.co.kr:9888/view/se/?imagePath=2022/8/28/se_202218226bc2-0c52-4fcd-b807-0c8b8763f726.jpg', '프루테리언'),
Expand Down
8 changes: 8 additions & 0 deletions server/src/main/resources/db/mysql/cart/cart_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DROP TABLE IF EXISTS cart CASCADE;

create table cart (
cart_id bigint,
create_date datetime(6),
edit_date datetime(6),
member_id bigint
) engine=InnoDB;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DROP TABLE IF EXISTS cart_detail CASCADE;

create table cart_detail (
cart_detail_id bigint,
purchase_quantity integer,
cart_id bigint,
product_id bigint
) engine=InnoDB;
81 changes: 81 additions & 0 deletions server/src/main/resources/db/mysql/constraint.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
-- PK

ALTER TABLE member
ADD CONSTRAINT PK_MEMBER PRIMARY KEY (member_id);

ALTER TABLE orders
ADD CONSTRAINT PK_ORDERS PRIMARY KEY (orders_id);

ALTER TABLE cart
ADD CONSTRAINT PK_CART PRIMARY KEY (cart_id);

ALTER TABLE cart_detail
ADD CONSTRAINT PK_CART_DETAIL PRIMARY KEY (cart_detail_id);

ALTER TABLE order_product
ADD CONSTRAINT PK_ORDER_PRODUCT PRIMARY KEY (orders_product_id);

ALTER TABLE product
ADD CONSTRAINT PK_PRODUCT PRIMARY KEY (product_id);

ALTER TABLE category
ADD CONSTRAINT PK_CATEGORY PRIMARY KEY (category_id);

ALTER TABLE vegetarian
ADD CONSTRAINT PK_VEGETARIAN PRIMARY KEY (vegetarian_type);


-- AUTO INCREMENT

ALTER TABLE member
MODIFY member_id BIGINT NOT NULL AUTO_INCREMENT FIRST;

ALTER TABLE orders
MODIFY orders_id BIGINT NOT NULL AUTO_INCREMENT FIRST;

ALTER TABLE cart
MODIFY cart_id BIGINT NOT NULL AUTO_INCREMENT FIRST;

ALTER TABLE cart_detail
MODIFY cart_detail_id BIGINT NOT NULL AUTO_INCREMENT FIRST;

ALTER TABLE order_product
MODIFY order_product_id BIGINT NOT NULL AUTO_INCREMENT FIRST;

ALTER TABLE product
MODIFY product_id BIGINT NOT NULL AUTO_INCREMENT FIRST;

ALTER TABLE category
MODIFY category_id BIGINT NOT NULL AUTO_INCREMENT FIRST;


-- FK

ALTER TABLE cart
ADD FOREIGN KEY (member_id) REFERENCES member (member_id);

ALTER TABLE cart_detail
ADD FOREIGN KEY (cart_id) REFERENCES cart (cart_id);

ALTER TABLE cart_detail
ADD FOREIGN KEY (product_id) REFERENCES product (proudct_id);

ALTER TABLE orders
ADD FOREIGN KEY (member_id) REFERENCES member (member_id);

ALTER TABLE order_product
ADD FOREIGN KEY (orders_id) REFERENCES orders (orders_id);

ALTER TABLE order_product
ADD FOREIGN KEY (product_id) REFERENCES product (product_id);

ALTER TABLE roles
ADD FOREIGN KEY (member_id) REFERENCES member (member_id);

ALTER TABLE category
ADD FOREIGN KEY (parent_category_id) REFERENCES category (category_id);

-- UNIQUE
ALTER TABLE member
ADD UNIQUE (email);
-- INDEX
2 changes: 1 addition & 1 deletion server/src/main/resources/db/mysql/data.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INSERT INTO VEGETARIAN (vegetarian_type,level)
INSERT INTO VEGETARIAN (vegetarian_type, levels)
VALUES ('프루테리언',1),
('비건', 2),
('오보', 3),
Expand Down
16 changes: 16 additions & 0 deletions server/src/main/resources/db/mysql/member/member_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

DROP TABLE IF EXISTS member CASCADE;

create table member (
member_id bigint,
create_date datetime(6),
edit_date datetime(6),
city varchar(255),
detail_address varchar(255),
zip_code varchar(255),
email varchar(255),
member_name varchar(255),
password varchar(255),
phone varchar(255),
vegetarian_type varchar(255)
) engine=InnoDB;
6 changes: 6 additions & 0 deletions server/src/main/resources/db/mysql/member/roles_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP TABLE IF EXISTS roles CASCADE;

CREATE TABLE roles (
member_id bigint,
roles varchar(255)
) engine=InnoDB;
9 changes: 9 additions & 0 deletions server/src/main/resources/db/mysql/order/order_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DROP TABLE IF EXISTS orders CASCADE;

create table orders (
orders_id bigint,
create_date datetime(6),
edit_date datetime(6),
orders_status varchar(255),
member_id bigint
) engine=InnoDB;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DROP TABLE IF EXISTS order_product CASCADE;

create table order_product (
orders_product_id bigint,
orders_price integer,
orders_quantity integer,
orders_id bigint,
product_id bigint
) engine=InnoDB;
Loading

0 comments on commit b99b7d3

Please sign in to comment.