From e42e8cfd2126bd033d5a6dada340fe9f2ba356a3 Mon Sep 17 00:00:00 2001 From: pinetree Date: Tue, 27 Jun 2023 12:42:33 +0900 Subject: [PATCH] =?UTF-8?q?[#24]=20feat:=20=EC=83=81=ED=92=88=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/kiosk/build.gradle | 2 +- .../team/five/kiosk/dto/ResponseProduct.java | 2 +- .../five/kiosk/repository/ProductRepository.java | 12 ++++++++---- .../team/five/kiosk/service/ProductService.java | 1 + be/kiosk/src/main/resources/application.yml | 11 ++++------- be/kiosk/src/main/resources/schema.sql | 16 ---------------- 6 files changed, 15 insertions(+), 29 deletions(-) delete mode 100644 be/kiosk/src/main/resources/schema.sql diff --git a/be/kiosk/build.gradle b/be/kiosk/build.gradle index 5c593572..d3237020 100644 --- a/be/kiosk/build.gradle +++ b/be/kiosk/build.gradle @@ -32,7 +32,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' - runtimeOnly 'com.h2database:h2' + runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' } diff --git a/be/kiosk/src/main/java/team/five/kiosk/dto/ResponseProduct.java b/be/kiosk/src/main/java/team/five/kiosk/dto/ResponseProduct.java index 2f757350..596ccf19 100644 --- a/be/kiosk/src/main/java/team/five/kiosk/dto/ResponseProduct.java +++ b/be/kiosk/src/main/java/team/five/kiosk/dto/ResponseProduct.java @@ -15,7 +15,7 @@ public class ResponseProduct { public static ResponseProduct from(Product product) { return ResponseProduct.builder() .id(product.getId()) - .name(product.getName()) + .name(product.getName()) .price(product.getPrice()) .imageUrl(product.getImageUrl()) .build(); diff --git a/be/kiosk/src/main/java/team/five/kiosk/repository/ProductRepository.java b/be/kiosk/src/main/java/team/five/kiosk/repository/ProductRepository.java index 08d57123..d69cb025 100644 --- a/be/kiosk/src/main/java/team/five/kiosk/repository/ProductRepository.java +++ b/be/kiosk/src/main/java/team/five/kiosk/repository/ProductRepository.java @@ -20,10 +20,14 @@ public ProductRepository(final DataSource dataSource) { public List findProductsBy(final String category) { - String sql = "select * " + - "from product p, category c " + - "where p.category_id = c.id " + - "and c.name = :name"; + String sql = "SELECT p.*, SUM(sl.count) total_quantity" + + " FROM product p" + + " JOIN category c ON p.category_id = c.id" + + " JOIN sales_log sl ON p.id = sl.product_id" + + " WHERE c.name = :name" + + " AND DATE(sl.sales_at) = CURDATE()" + + " GROUP BY p.id" + + " ORDER BY total_quantity desc"; SqlParameterSource params = new MapSqlParameterSource("name", category); return jdbcTemplate.query(sql, params, (rs, rowNum) -> new Product( diff --git a/be/kiosk/src/main/java/team/five/kiosk/service/ProductService.java b/be/kiosk/src/main/java/team/five/kiosk/service/ProductService.java index 84dea8bd..a9ef7b20 100644 --- a/be/kiosk/src/main/java/team/five/kiosk/service/ProductService.java +++ b/be/kiosk/src/main/java/team/five/kiosk/service/ProductService.java @@ -19,6 +19,7 @@ public class ProductService { public List getProducts(final String category) { List products = productRepository.findProductsBy(category); + return products.stream().map(ResponseProduct::from).collect(Collectors.toList()); } } diff --git a/be/kiosk/src/main/resources/application.yml b/be/kiosk/src/main/resources/application.yml index fc3ac679..d3c00301 100644 --- a/be/kiosk/src/main/resources/application.yml +++ b/be/kiosk/src/main/resources/application.yml @@ -8,11 +8,8 @@ spring: config: activate: on-profile: local - h2: - console: - enabled: true datasource: - driver-class-name: org.h2.Driver - url: jdbc:h2:mem:testdb;MODE=MySQL; - username: sa - password: \ No newline at end of file + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://my-rds-instance.cbacrydrinw6.ap-northeast-2.rds.amazonaws.com:3306/kiosk_rds?useSSL=false + username: team5 + password: kiosk1234 diff --git a/be/kiosk/src/main/resources/schema.sql b/be/kiosk/src/main/resources/schema.sql deleted file mode 100644 index 283d1f45..00000000 --- a/be/kiosk/src/main/resources/schema.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE category ( - id bigint unsigned NOT NULL AUTO_INCREMENT, - name varchar(20) NOT NULL COMMENT '카테고리명', - PRIMARY KEY (id) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - -CREATE TABLE product ( - id bigint unsigned NOT NULL AUTO_INCREMENT, - category_id bigint unsigned NOT NULL, - name varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '상품 이름', - price int NOT NULL COMMENT '상품 가격', - image_url varchar(512) NOT NULL COMMENT '상품 이미지', - PRIMARY KEY (id), - KEY `category_id` (`category_id`), - CONSTRAINT `category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file