├── src ├── main │ ├── resources │ │ ├── static │ │ │ └── empty.txt │ │ ├── templates │ │ │ └── empty.txt │ │ ├── application.properties │ │ └── db │ │ │ └── migration │ │ │ ├── V2__Insert_default_data.sql │ │ │ └── V1__Initialize_project_tables.sql │ └── java │ │ └── camp │ │ └── nextstep │ │ └── edu │ │ ├── calculator │ │ └── empty.txt │ │ ├── kitchenpos │ │ ├── dto │ │ │ └── empty.txt │ │ ├── model │ │ │ ├── OrderStatus.java │ │ │ ├── MenuGroup.java │ │ │ ├── TableGroup.java │ │ │ ├── Product.java │ │ │ ├── OrderLineItem.java │ │ │ ├── MenuProduct.java │ │ │ ├── Menu.java │ │ │ ├── OrderTable.java │ │ │ └── Order.java │ │ ├── Application.java │ │ ├── bo │ │ │ └── ProductBo.java │ │ ├── controller │ │ │ └── ProductRestController.java │ │ └── dao │ │ │ ├── MenuGroupDao.java │ │ │ ├── ProductDao.java │ │ │ ├── MenuDao.java │ │ │ ├── TableGroupDao.java │ │ │ ├── MenuProductDao.java │ │ │ ├── OrderTableDao.java │ │ │ ├── OrderLineItemDao.java │ │ │ └── OrderDao.java │ │ └── racingcar │ │ ├── RandomMovingStrategy.java │ │ └── Car.java └── test │ └── java │ └── camp │ └── nextstep │ └── edu │ └── kitchenpos │ └── ApplicationTests.java ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── .gitignore ├── gradlew.bat └── gradlew /src/main/resources/static/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/templates/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/calculator/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'ddd-kitchenpos' 2 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/dto/empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step/ddd-legacy-old/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/model/OrderStatus.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.model; 2 | 3 | public enum OrderStatus { 4 | COOKING, MEAL, COMPLETION 5 | } 6 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.schema=classpath*:db/schema.sql 2 | spring.datasource.data=classpath*:db/data.sql 3 | 4 | spring.h2.console.enabled=true 5 | 6 | logging.level.org.springframework.jdbc=TRACE 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ddd-kitchenpos 2 | 3 | ## 요구 사항 4 | 5 | - 간단한 포스 프로그램을 구현한다. 6 | 7 | ## 용어 사전 8 | 9 | | 한글명 | 영문명 | 설명 | 10 | | --- | --- | --- | 11 | | 포스 | POS | 판매 시점 정보 관리. 판매와 관련한 데이터를 일괄적으로 관리하고, 고객정보를 수집하여 부가가치를 향상시키는 시스템이다. | 12 | 13 | ## 모델링 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/racingcar/RandomMovingStrategy.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.racingcar; 2 | 3 | import java.util.Random; 4 | 5 | public class RandomMovingStrategy { 6 | boolean movable() { 7 | return new Random().nextInt(9) >= 4; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/camp/nextstep/edu/kitchenpos/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | public class ApplicationTests { 8 | @Test 9 | void contextLoads() { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/Application.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | public static void main(String[] args) { 9 | SpringApplication.run(Application.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/model/MenuGroup.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.model; 2 | 3 | public class MenuGroup { 4 | private Long id; 5 | private String name; 6 | 7 | public Long getId() { 8 | return id; 9 | } 10 | 11 | public void setId(final Long id) { 12 | this.id = id; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public void setName(final String name) { 20 | this.name = name; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/model/TableGroup.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.model; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public class TableGroup { 6 | private Long id; 7 | private LocalDateTime createdDate; 8 | 9 | public Long getId() { 10 | return id; 11 | } 12 | 13 | public void setId(final Long id) { 14 | this.id = id; 15 | } 16 | 17 | public LocalDateTime getCreatedDate() { 18 | return createdDate; 19 | } 20 | 21 | public void setCreatedDate(final LocalDateTime createdDate) { 22 | this.createdDate = createdDate; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/model/Product.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.model; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Product { 6 | private Long id; 7 | private String name; 8 | private BigDecimal price; 9 | 10 | public Long getId() { 11 | return id; 12 | } 13 | 14 | public void setId(final Long id) { 15 | this.id = id; 16 | } 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public void setName(final String name) { 23 | this.name = name; 24 | } 25 | 26 | public BigDecimal getPrice() { 27 | return price; 28 | } 29 | 30 | public void setPrice(final BigDecimal price) { 31 | this.price = price; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/racingcar/Car.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.racingcar; 2 | 3 | public class Car { 4 | private final String name; 5 | private int position; 6 | 7 | Car(final String name) { 8 | this(name, 0); 9 | } 10 | 11 | Car(final String name, final int position) { 12 | validate(name); 13 | this.name = name; 14 | this.position = position; 15 | } 16 | 17 | void move(final RandomMovingStrategy movingStrategy) { 18 | if (movingStrategy.movable()) { 19 | position++; 20 | } 21 | } 22 | 23 | boolean isInPosition(final int position) { 24 | return this.position == position; 25 | } 26 | 27 | private void validate(final String name) { 28 | if (name == null || name.length() > 5) { 29 | throw new IllegalArgumentException(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/bo/ProductBo.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.bo; 2 | 3 | import camp.nextstep.edu.kitchenpos.dao.ProductDao; 4 | import camp.nextstep.edu.kitchenpos.model.Product; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.math.BigDecimal; 8 | import java.util.List; 9 | 10 | @Component 11 | public class ProductBo { 12 | private final ProductDao productDao; 13 | 14 | public ProductBo(final ProductDao productDao) { 15 | this.productDao = productDao; 16 | } 17 | 18 | public Product create(final Product product) { 19 | final BigDecimal price = product.getPrice(); 20 | 21 | if (price == null || price.compareTo(BigDecimal.ZERO) < 0) { 22 | throw new IllegalArgumentException(); 23 | } 24 | 25 | return productDao.save(product); 26 | } 27 | 28 | public List list() { 29 | return productDao.findAll(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/model/OrderLineItem.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.model; 2 | 3 | public class OrderLineItem { 4 | private Long seq; 5 | private Long ordersId; 6 | private Long menuId; 7 | private long quantity; 8 | 9 | public Long getSeq() { 10 | return seq; 11 | } 12 | 13 | public void setSeq(final Long seq) { 14 | this.seq = seq; 15 | } 16 | 17 | public Long getOrdersId() { 18 | return ordersId; 19 | } 20 | 21 | public void setOrdersId(final Long ordersId) { 22 | this.ordersId = ordersId; 23 | } 24 | 25 | public Long getMenuId() { 26 | return menuId; 27 | } 28 | 29 | public void setMenuId(final Long menuId) { 30 | this.menuId = menuId; 31 | } 32 | 33 | public long getQuantity() { 34 | return quantity; 35 | } 36 | 37 | public void setQuantity(final long quantity) { 38 | this.quantity = quantity; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/model/MenuProduct.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.model; 2 | 3 | public class MenuProduct { 4 | private Long seq; 5 | private Long menuId; 6 | private Long productId; 7 | private long quantity; 8 | 9 | public Long getSeq() { 10 | return seq; 11 | } 12 | 13 | public void setSeq(final Long seq) { 14 | this.seq = seq; 15 | } 16 | 17 | public Long getMenuId() { 18 | return menuId; 19 | } 20 | 21 | public void setMenuId(final Long menuId) { 22 | this.menuId = menuId; 23 | } 24 | 25 | public Long getProductId() { 26 | return productId; 27 | } 28 | 29 | public void setProductId(final Long productId) { 30 | this.productId = productId; 31 | } 32 | 33 | public long getQuantity() { 34 | return quantity; 35 | } 36 | 37 | public void setQuantity(final long quantity) { 38 | this.quantity = quantity; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/model/Menu.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.model; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Menu { 6 | private Long id; 7 | private String name; 8 | private BigDecimal price; 9 | private Long menuGroupId; 10 | 11 | public Long getId() { 12 | return id; 13 | } 14 | 15 | public void setId(final Long id) { 16 | this.id = id; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(final String name) { 24 | this.name = name; 25 | } 26 | 27 | public BigDecimal getPrice() { 28 | return price; 29 | } 30 | 31 | public void setPrice(final BigDecimal price) { 32 | this.price = price; 33 | } 34 | 35 | public Long getMenuGroupId() { 36 | return menuGroupId; 37 | } 38 | 39 | public void setMenuGroupId(final Long menuGroupId) { 40 | this.menuGroupId = menuGroupId; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/model/OrderTable.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.model; 2 | 3 | public class OrderTable { 4 | private Long id; 5 | private Long tableGroupId; 6 | private int numberOfGuests; 7 | private boolean empty; 8 | 9 | public Long getId() { 10 | return id; 11 | } 12 | 13 | public void setId(final Long id) { 14 | this.id = id; 15 | } 16 | 17 | public Long getTableGroupId() { 18 | return tableGroupId; 19 | } 20 | 21 | public void setTableGroupId(final Long tableGroupId) { 22 | this.tableGroupId = tableGroupId; 23 | } 24 | 25 | public int getNumberOfGuests() { 26 | return numberOfGuests; 27 | } 28 | 29 | public void setNumberOfGuests(final int numberOfGuests) { 30 | this.numberOfGuests = numberOfGuests; 31 | } 32 | 33 | public boolean isEmpty() { 34 | return empty; 35 | } 36 | 37 | public void setEmpty(final boolean empty) { 38 | this.empty = empty; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/model/Order.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.model; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | public class Order { 6 | private Long id; 7 | private Long orderTableId; 8 | private String orderStatus; 9 | private LocalDateTime orderedTime; 10 | 11 | public Long getId() { 12 | return id; 13 | } 14 | 15 | public void setId(final Long id) { 16 | this.id = id; 17 | } 18 | 19 | public Long getOrderTableId() { 20 | return orderTableId; 21 | } 22 | 23 | public void setOrderTableId(final Long orderTableId) { 24 | this.orderTableId = orderTableId; 25 | } 26 | 27 | public String getOrderStatus() { 28 | return orderStatus; 29 | } 30 | 31 | public void setOrderStatus(final String orderStatus) { 32 | this.orderStatus = orderStatus; 33 | } 34 | 35 | public LocalDateTime getOrderedTime() { 36 | return orderedTime; 37 | } 38 | 39 | public void setOrderedTime(final LocalDateTime orderedTime) { 40 | this.orderedTime = orderedTime; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/controller/ProductRestController.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.controller; 2 | 3 | import camp.nextstep.edu.kitchenpos.bo.ProductBo; 4 | import camp.nextstep.edu.kitchenpos.model.Product; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.net.URI; 12 | import java.util.List; 13 | 14 | @RestController 15 | public class ProductRestController { 16 | private final ProductBo productBo; 17 | 18 | public ProductRestController(final ProductBo productBo) { 19 | this.productBo = productBo; 20 | } 21 | 22 | @PostMapping("/api/products") 23 | public ResponseEntity create(@RequestBody final Product product) { 24 | final Product created = productBo.create(product); 25 | final URI uri = URI.create("/api/products/" + created.getId()); 26 | return ResponseEntity.created(uri) 27 | .body(created) 28 | ; 29 | } 30 | 31 | @GetMapping("/api/products") 32 | public ResponseEntity> list() { 33 | return ResponseEntity.ok() 34 | .body(productBo.list()) 35 | ; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/resources/db/migration/V2__Insert_default_data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO menu_group (id, name) VALUES (1, '두마리메뉴'); 2 | INSERT INTO menu_group (id, name) VALUES (2, '한마리메뉴'); 3 | INSERT INTO menu_group (id, name) VALUES (3, '순살파닭두마리메뉴'); 4 | INSERT INTO menu_group (id, name) VALUES (4, '신메뉴'); 5 | INSERT INTO menu_group (id, name) VALUES (5, '추천메뉴'); 6 | 7 | INSERT INTO product (id, name, price) VALUES (1, '후라이드', 16000); 8 | INSERT INTO product (id, name, price) VALUES (2, '양념치킨', 16000); 9 | INSERT INTO product (id, name, price) VALUES (3, '반반치킨', 16000); 10 | INSERT INTO product (id, name, price) VALUES (4, '통구이', 16000); 11 | INSERT INTO product (id, name, price) VALUES (5, '간장치킨', 17000); 12 | INSERT INTO product (id, name, price) VALUES (6, '순살치킨', 17000); 13 | 14 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (1, '후라이드치킨', 16000, 2); 15 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (2, '양념치킨', 16000, 2); 16 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (3, '반반치킨', 16000, 2); 17 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (4, '통구이', 16000, 2); 18 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (5, '간장치킨', 17000, 2); 19 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (6, '순살치킨', 17000, 2); 20 | 21 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (1, 1, 1); 22 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (2, 2, 1); 23 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (3, 3, 1); 24 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (4, 4, 1); 25 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (5, 5, 1); 26 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (6, 6, 1); 27 | 28 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (1, 0, true); 29 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (2, 0, true); 30 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (3, 0, true); 31 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (4, 0, true); 32 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (5, 0, true); 33 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (6, 0, true); 34 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (7, 0, true); 35 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (8, 0, true); 36 | -------------------------------------------------------------------------------- /src/main/resources/db/migration/V1__Initialize_project_tables.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE orders ( 2 | id BIGINT(20) NOT NULL AUTO_INCREMENT, 3 | order_table_id BIGINT(20) NOT NULL, 4 | order_status VARCHAR(255) NOT NULL, 5 | ordered_time DATETIME NOT NULL, 6 | PRIMARY KEY (id) 7 | ); 8 | 9 | CREATE TABLE order_line_item ( 10 | seq BIGINT(20) NOT NULL AUTO_INCREMENT, 11 | orders_id BIGINT(20) NOT NULL, 12 | menu_id BIGINT(20) NOT NULL, 13 | quantity BIGINT(20) NOT NULL, 14 | PRIMARY KEY (seq) 15 | ); 16 | 17 | CREATE TABLE menu ( 18 | id BIGINT(20) NOT NULL AUTO_INCREMENT, 19 | name VARCHAR(255) NOT NULL, 20 | price DECIMAL(19, 2) NOT NULL, 21 | menu_group_id BIGINT(20) NOT NULL, 22 | PRIMARY KEY (id) 23 | ); 24 | 25 | CREATE TABLE menu_group ( 26 | id BIGINT(20) NOT NULL AUTO_INCREMENT, 27 | name VARCHAR(255) NOT NULL, 28 | PRIMARY KEY (id) 29 | ); 30 | 31 | CREATE TABLE menu_product ( 32 | seq BIGINT(20) NOT NULL AUTO_INCREMENT, 33 | menu_id BIGINT(20) NOT NULL, 34 | product_id BIGINT(20) NOT NULL, 35 | quantity BIGINT(20) NOT NULL, 36 | PRIMARY KEY (seq) 37 | ); 38 | 39 | CREATE TABLE order_table ( 40 | id BIGINT(20) NOT NULL AUTO_INCREMENT, 41 | table_group_id BIGINT(20), 42 | number_of_guests INT(11) NOT NULL, 43 | empty BIT(1) NOT NULL, 44 | PRIMARY KEY (id) 45 | ); 46 | 47 | CREATE TABLE table_group ( 48 | id BIGINT(20) NOT NULL AUTO_INCREMENT, 49 | created_date DATETIME NOT NULL, 50 | PRIMARY KEY (id) 51 | ); 52 | 53 | CREATE TABLE product ( 54 | id BIGINT(20) NOT NULL AUTO_INCREMENT, 55 | name VARCHAR(255) NOT NULL, 56 | price DECIMAL(19, 2) NOT NULL, 57 | PRIMARY KEY (id) 58 | ); 59 | 60 | ALTER TABLE orders 61 | ADD CONSTRAINT fk_orders_order_table 62 | FOREIGN KEY (order_table_id) REFERENCES order_table (id); 63 | 64 | ALTER TABLE order_line_item 65 | ADD CONSTRAINT fk_order_line_item_orders 66 | FOREIGN KEY (orders_id) REFERENCES orders (id); 67 | 68 | ALTER TABLE order_line_item 69 | ADD CONSTRAINT fk_order_line_item_menu 70 | FOREIGN KEY (menu_id) REFERENCES menu (id); 71 | 72 | ALTER TABLE menu 73 | ADD CONSTRAINT fk_menu_menu_group 74 | FOREIGN KEY (menu_group_id) REFERENCES menu_group (id); 75 | 76 | ALTER TABLE menu_product 77 | ADD CONSTRAINT fk_menu_product_menu 78 | FOREIGN KEY (menu_id) REFERENCES menu (id); 79 | 80 | ALTER TABLE order_table 81 | ADD CONSTRAINT fk_order_table_table_group 82 | FOREIGN KEY (table_group_id) REFERENCES table_group (id); 83 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/dao/MenuGroupDao.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.dao; 2 | 3 | import camp.nextstep.edu.kitchenpos.model.MenuGroup; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 8 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import javax.sql.DataSource; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | @Repository 18 | public class MenuGroupDao { 19 | private static final String TABLE_NAME = "menu_group"; 20 | private static final String KEY_COLUMN_NAME = "id"; 21 | 22 | private final JdbcTemplate jdbcTemplate; 23 | private final SimpleJdbcInsert jdbcInsert; 24 | 25 | public MenuGroupDao(final DataSource dataSource) { 26 | jdbcTemplate = new JdbcTemplate(dataSource); 27 | jdbcInsert = new SimpleJdbcInsert(dataSource) 28 | .withTableName(TABLE_NAME) 29 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 30 | ; 31 | } 32 | 33 | public MenuGroup save(final MenuGroup entity) { 34 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 35 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 36 | return select(key.longValue()); 37 | } 38 | 39 | public Optional findById(final Long id) { 40 | try { 41 | return Optional.of(select(id)); 42 | } catch (final EmptyResultDataAccessException e) { 43 | return Optional.empty(); 44 | } 45 | } 46 | 47 | public List findAll() { 48 | final String sql = "SELECT id, name FROM menu_group"; 49 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 50 | } 51 | 52 | private MenuGroup select(final Long id) { 53 | final String sql = "SELECT id, name FROM menu_group WHERE id = ?"; 54 | return jdbcTemplate.queryForObject(sql, (resultSet, rowNumber) -> toEntity(resultSet), id); 55 | } 56 | 57 | private MenuGroup toEntity(final ResultSet resultSet) throws SQLException { 58 | final MenuGroup entity = new MenuGroup(); 59 | entity.setId(resultSet.getLong("id")); 60 | entity.setName(resultSet.getString("name")); 61 | return entity; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/dao/ProductDao.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.dao; 2 | 3 | import camp.nextstep.edu.kitchenpos.model.Product; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 8 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import javax.sql.DataSource; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | @Repository 18 | public class ProductDao { 19 | private static final String TABLE_NAME = "product"; 20 | private static final String KEY_COLUMN_NAME = "id"; 21 | 22 | private final JdbcTemplate jdbcTemplate; 23 | private final SimpleJdbcInsert jdbcInsert; 24 | 25 | public ProductDao(final DataSource dataSource) { 26 | jdbcTemplate = new JdbcTemplate(dataSource); 27 | jdbcInsert = new SimpleJdbcInsert(dataSource) 28 | .withTableName(TABLE_NAME) 29 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 30 | ; 31 | } 32 | 33 | public Product save(final Product entity) { 34 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 35 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 36 | return select(key.longValue()); 37 | } 38 | 39 | public Optional findById(final Long id) { 40 | try { 41 | return Optional.of(select(id)); 42 | } catch (final EmptyResultDataAccessException e) { 43 | return Optional.empty(); 44 | } 45 | } 46 | 47 | public List findAll() { 48 | final String sql = "SELECT id, name, price FROM product"; 49 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 50 | } 51 | 52 | private Product select(final Long id) { 53 | final String sql = "SELECT id, name, price FROM product WHERE id = ?"; 54 | return jdbcTemplate.queryForObject(sql, (resultSet, rowNumber) -> toEntity(resultSet), id); 55 | } 56 | 57 | private Product toEntity(final ResultSet resultSet) throws SQLException { 58 | final Product entity = new Product(); 59 | entity.setId(resultSet.getLong(KEY_COLUMN_NAME)); 60 | entity.setName(resultSet.getString("name")); 61 | entity.setPrice(resultSet.getBigDecimal("price")); 62 | return entity; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/dao/MenuDao.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.dao; 2 | 3 | import camp.nextstep.edu.kitchenpos.model.Menu; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 8 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import javax.sql.DataSource; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | @Repository 18 | public class MenuDao { 19 | private static final String TABLE_NAME = "menu"; 20 | private static final String KEY_COLUMN_NAME = "id"; 21 | 22 | private final JdbcTemplate jdbcTemplate; 23 | private final SimpleJdbcInsert jdbcInsert; 24 | 25 | public MenuDao(final DataSource dataSource) { 26 | jdbcTemplate = new JdbcTemplate(dataSource); 27 | jdbcInsert = new SimpleJdbcInsert(dataSource) 28 | .withTableName(TABLE_NAME) 29 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 30 | ; 31 | } 32 | 33 | public Menu save(final Menu menu) { 34 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(menu); 35 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 36 | return select(key.longValue()); 37 | } 38 | 39 | public Optional findById(final Long id) { 40 | try { 41 | return Optional.of(select(id)); 42 | } catch (final EmptyResultDataAccessException e) { 43 | return Optional.empty(); 44 | } 45 | } 46 | 47 | public List findAll() { 48 | final String sql = "SELECT id, name, price, menu_group_id FROM menu "; 49 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 50 | } 51 | 52 | private Menu select(final Long id) { 53 | final String sql = "SELECT id, name, price, menu_group_id FROM menu WHERE id = ?"; 54 | return jdbcTemplate.queryForObject(sql, (resultSet, rowNumber) -> toEntity(resultSet), id); 55 | } 56 | 57 | private Menu toEntity(final ResultSet resultSet) throws SQLException { 58 | final Menu menu = new Menu(); 59 | menu.setId(resultSet.getLong("id")); 60 | menu.setName(resultSet.getString("name")); 61 | menu.setPrice(resultSet.getBigDecimal("price")); 62 | resultSet.getLong("menu_group_id"); 63 | return menu; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/dao/TableGroupDao.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.dao; 2 | 3 | import camp.nextstep.edu.kitchenpos.model.TableGroup; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 8 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import javax.sql.DataSource; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.time.LocalDateTime; 15 | import java.util.List; 16 | import java.util.Optional; 17 | 18 | @Repository 19 | public class TableGroupDao { 20 | private static final String TABLE_NAME = "table_group"; 21 | private static final String KEY_COLUMN_NAME = "id"; 22 | 23 | private final JdbcTemplate jdbcTemplate; 24 | private final SimpleJdbcInsert jdbcInsert; 25 | 26 | public TableGroupDao(final DataSource dataSource) { 27 | jdbcTemplate = new JdbcTemplate(dataSource); 28 | jdbcInsert = new SimpleJdbcInsert(dataSource) 29 | .withTableName(TABLE_NAME) 30 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 31 | ; 32 | } 33 | 34 | public TableGroup save(final TableGroup entity) { 35 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 36 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 37 | return select(key.longValue()); 38 | } 39 | 40 | public Optional findById(final Long id) { 41 | try { 42 | return Optional.of(select(id)); 43 | } catch (final EmptyResultDataAccessException e) { 44 | return Optional.empty(); 45 | } 46 | } 47 | 48 | public List findAll() { 49 | final String sql = "SELECT id, created_date FROM table_group"; 50 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 51 | } 52 | 53 | private TableGroup select(final Long id) { 54 | final String sql = "SELECT id, created_date FROM table_group WHERE id = ?"; 55 | return jdbcTemplate.queryForObject(sql, (resultSet, rowNumber) -> toEntity(resultSet), id); 56 | } 57 | 58 | private TableGroup toEntity(final ResultSet resultSet) throws SQLException { 59 | final TableGroup entity = new TableGroup(); 60 | entity.setId(resultSet.getLong(KEY_COLUMN_NAME)); 61 | entity.setCreatedDate(resultSet.getObject("created_date", LocalDateTime.class)); 62 | return entity; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/dao/MenuProductDao.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.dao; 2 | 3 | import camp.nextstep.edu.kitchenpos.model.MenuProduct; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 8 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import javax.sql.DataSource; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | @Repository 18 | public class MenuProductDao { 19 | private static final String TABLE_NAME = "menu_product"; 20 | private static final String KEY_COLUMN_NAME = "seq"; 21 | 22 | private final JdbcTemplate jdbcTemplate; 23 | private final SimpleJdbcInsert jdbcInsert; 24 | 25 | public MenuProductDao(final DataSource dataSource) { 26 | jdbcTemplate = new JdbcTemplate(dataSource); 27 | jdbcInsert = new SimpleJdbcInsert(dataSource) 28 | .withTableName(TABLE_NAME) 29 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 30 | ; 31 | } 32 | 33 | public MenuProduct save(final MenuProduct entity) { 34 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 35 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 36 | return select(key.longValue()); 37 | } 38 | 39 | public Optional findById(final Long id) { 40 | try { 41 | return Optional.of(select(id)); 42 | } catch (final EmptyResultDataAccessException e) { 43 | return Optional.empty(); 44 | } 45 | } 46 | 47 | public List findAll() { 48 | final String sql = "SELECT seq, menu_id, product_id, quantity FROM menu_product"; 49 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 50 | } 51 | 52 | private MenuProduct select(final Long id) { 53 | final String sql = "SELECT seq, menu_id, product_id, quantity FROM menu_product WHERE seq = ?"; 54 | return jdbcTemplate.queryForObject(sql, (resultSet, rowNumber) -> toEntity(resultSet), id); 55 | } 56 | 57 | private MenuProduct toEntity(final ResultSet resultSet) throws SQLException { 58 | final MenuProduct entity = new MenuProduct(); 59 | entity.setSeq(resultSet.getLong(KEY_COLUMN_NAME)); 60 | entity.setMenuId(resultSet.getLong("menu_id")); 61 | entity.setProductId(resultSet.getLong("product_id")); 62 | entity.setQuantity(resultSet.getLong("quantity")); 63 | return entity; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/dao/OrderTableDao.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.dao; 2 | 3 | import camp.nextstep.edu.kitchenpos.model.OrderTable; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 8 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import javax.sql.DataSource; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | @Repository 18 | public class OrderTableDao { 19 | private static final String TABLE_NAME = "order_table"; 20 | private static final String KEY_COLUMN_NAME = "id"; 21 | 22 | private final JdbcTemplate jdbcTemplate; 23 | private final SimpleJdbcInsert jdbcInsert; 24 | 25 | public OrderTableDao(final DataSource dataSource) { 26 | jdbcTemplate = new JdbcTemplate(dataSource); 27 | jdbcInsert = new SimpleJdbcInsert(dataSource) 28 | .withTableName(TABLE_NAME) 29 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 30 | ; 31 | } 32 | 33 | public OrderTable save(final OrderTable entity) { 34 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 35 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 36 | return select(key.longValue()); 37 | } 38 | 39 | public Optional findById(final Long id) { 40 | try { 41 | return Optional.of(select(id)); 42 | } catch (final EmptyResultDataAccessException e) { 43 | return Optional.empty(); 44 | } 45 | } 46 | 47 | public List findAll() { 48 | final String sql = "SELECT id, table_group_id, number_of_guests, empty FROM order_table"; 49 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 50 | } 51 | 52 | private OrderTable select(final Long id) { 53 | final String sql = "SELECT id, table_group_id, number_of_guests, empty FROM order_table WHERE seq = ?"; 54 | return jdbcTemplate.queryForObject(sql, (resultSet, rowNumber) -> toEntity(resultSet), id); 55 | } 56 | 57 | private OrderTable toEntity(final ResultSet resultSet) throws SQLException { 58 | final OrderTable entity = new OrderTable(); 59 | entity.setId(resultSet.getLong(KEY_COLUMN_NAME)); 60 | entity.setTableGroupId(resultSet.getLong("table_group_id")); 61 | entity.setNumberOfGuests(resultSet.getInt("number_of_guests")); 62 | entity.setEmpty(resultSet.getBoolean("empty")); 63 | return entity; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/dao/OrderLineItemDao.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.dao; 2 | 3 | import camp.nextstep.edu.kitchenpos.model.OrderLineItem; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 8 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import javax.sql.DataSource; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | @Repository 18 | public class OrderLineItemDao { 19 | private static final String TABLE_NAME = "order_line_item"; 20 | private static final String KEY_COLUMN_NAME = "seq"; 21 | 22 | private final JdbcTemplate jdbcTemplate; 23 | private final SimpleJdbcInsert jdbcInsert; 24 | 25 | public OrderLineItemDao(final DataSource dataSource) { 26 | jdbcTemplate = new JdbcTemplate(dataSource); 27 | jdbcInsert = new SimpleJdbcInsert(dataSource) 28 | .withTableName(TABLE_NAME) 29 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 30 | ; 31 | } 32 | 33 | public OrderLineItem save(final OrderLineItem entity) { 34 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 35 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 36 | return select(key.longValue()); 37 | } 38 | 39 | public Optional findById(final Long id) { 40 | try { 41 | return Optional.of(select(id)); 42 | } catch (final EmptyResultDataAccessException e) { 43 | return Optional.empty(); 44 | } 45 | } 46 | 47 | public List findAll() { 48 | final String sql = "SELECT seq, orders_id, menu_id, quantity FROM order_line_item"; 49 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 50 | } 51 | 52 | private OrderLineItem select(final Long id) { 53 | final String sql = "SELECT seq, orders_id, menu_id, quantity FROM order_line_item WHERE seq = ?"; 54 | return jdbcTemplate.queryForObject(sql, (resultSet, rowNumber) -> toEntity(resultSet), id); 55 | } 56 | 57 | private OrderLineItem toEntity(final ResultSet resultSet) throws SQLException { 58 | final OrderLineItem entity = new OrderLineItem(); 59 | entity.setSeq(resultSet.getLong(KEY_COLUMN_NAME)); 60 | entity.setOrdersId(resultSet.getLong("orders_id")); 61 | entity.setMenuId(resultSet.getLong("menu_id")); 62 | entity.setQuantity(resultSet.getLong("quantity")); 63 | return entity; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/camp/nextstep/edu/kitchenpos/dao/OrderDao.java: -------------------------------------------------------------------------------- 1 | package camp.nextstep.edu.kitchenpos.dao; 2 | 3 | import camp.nextstep.edu.kitchenpos.model.Order; 4 | import camp.nextstep.edu.kitchenpos.model.OrderLineItem; 5 | import org.springframework.dao.EmptyResultDataAccessException; 6 | import org.springframework.jdbc.core.JdbcTemplate; 7 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 8 | import org.springframework.jdbc.core.namedparam.SqlParameterSource; 9 | import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 10 | import org.springframework.stereotype.Repository; 11 | 12 | import javax.sql.DataSource; 13 | import java.sql.ResultSet; 14 | import java.sql.SQLException; 15 | import java.time.LocalDateTime; 16 | import java.util.List; 17 | import java.util.Optional; 18 | 19 | @Repository 20 | public class OrderDao { 21 | private static final String TABLE_NAME = "orders"; 22 | private static final String KEY_COLUMN_NAME = "id"; 23 | 24 | private final JdbcTemplate jdbcTemplate; 25 | private final SimpleJdbcInsert jdbcInsert; 26 | 27 | public OrderDao(final DataSource dataSource) { 28 | jdbcTemplate = new JdbcTemplate(dataSource); 29 | jdbcInsert = new SimpleJdbcInsert(dataSource) 30 | .withTableName(TABLE_NAME) 31 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 32 | ; 33 | } 34 | 35 | public Order save(final OrderLineItem entity) { 36 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 37 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 38 | return select(key.longValue()); 39 | } 40 | 41 | public Optional findById(final Long id) { 42 | try { 43 | return Optional.of(select(id)); 44 | } catch (final EmptyResultDataAccessException e) { 45 | return Optional.empty(); 46 | } 47 | } 48 | 49 | public List findAll() { 50 | final String sql = "SELECT id, order_table_id, order_status, ordered_time FROM orders"; 51 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 52 | } 53 | 54 | private Order select(final Long id) { 55 | final String sql = "SELECT id, order_table_id, order_status, ordered_time FROM orders WHERE id = ?"; 56 | return jdbcTemplate.queryForObject(sql, (resultSet, rowNumber) -> toEntity(resultSet), id); 57 | } 58 | 59 | private Order toEntity(final ResultSet resultSet) throws SQLException { 60 | final Order entity = new Order(); 61 | entity.setId(resultSet.getLong(KEY_COLUMN_NAME)); 62 | entity.setOrderTableId(resultSet.getLong("order_table_id")); 63 | entity.setOrderStatus(resultSet.getString("order_status")); 64 | entity.setOrderedTime(resultSet.getObject("ordered_time", LocalDateTime.class)); 65 | return entity; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | --------------------------------------------------------------------------------