Skip to content

Commit

Permalink
[#24] feat: 상품목록조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
daewon-ko committed Jun 27, 2023
1 parent 50c1f43 commit e42e8cf
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 29 deletions.
2 changes: 1 addition & 1 deletion be/kiosk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public ProductRepository(final DataSource dataSource) {


public List<Product> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ProductService {

public List<ResponseProduct> getProducts(final String category) {
List<Product> products = productRepository.findProductsBy(category);

return products.stream().map(ResponseProduct::from).collect(Collectors.toList());
}
}
11 changes: 4 additions & 7 deletions be/kiosk/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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
16 changes: 0 additions & 16 deletions be/kiosk/src/main/resources/schema.sql

This file was deleted.

0 comments on commit e42e8cf

Please sign in to comment.