├── .gitignore ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── http ├── menu-groups.http ├── menus.http ├── orders.http ├── products.http ├── table-groups.http └── tables.http ├── rest-client.env.json ├── settings.gradle └── src ├── main ├── java │ └── kitchenpos │ │ ├── Application.java │ │ ├── application │ │ ├── MenuGroupService.java │ │ ├── MenuService.java │ │ ├── OrderService.java │ │ ├── ProductService.java │ │ ├── TableGroupService.java │ │ └── TableService.java │ │ ├── dao │ │ ├── JdbcTemplateMenuDao.java │ │ ├── JdbcTemplateMenuGroupDao.java │ │ ├── JdbcTemplateMenuProductDao.java │ │ ├── JdbcTemplateOrderDao.java │ │ ├── JdbcTemplateOrderLineItemDao.java │ │ ├── JdbcTemplateOrderTableDao.java │ │ ├── JdbcTemplateProductDao.java │ │ ├── JdbcTemplateTableGroupDao.java │ │ ├── MenuDao.java │ │ ├── MenuGroupDao.java │ │ ├── MenuProductDao.java │ │ ├── OrderDao.java │ │ ├── OrderLineItemDao.java │ │ ├── OrderTableDao.java │ │ ├── ProductDao.java │ │ └── TableGroupDao.java │ │ ├── domain │ │ ├── Menu.java │ │ ├── MenuGroup.java │ │ ├── MenuProduct.java │ │ ├── Order.java │ │ ├── OrderLineItem.java │ │ ├── OrderStatus.java │ │ ├── OrderTable.java │ │ ├── Product.java │ │ └── TableGroup.java │ │ └── ui │ │ ├── MenuGroupRestController.java │ │ ├── MenuRestController.java │ │ ├── OrderRestController.java │ │ ├── ProductRestController.java │ │ ├── TableGroupRestController.java │ │ └── TableRestController.java └── resources │ ├── application.properties │ ├── db │ └── migration │ │ ├── V1__Initialize_project_tables.sql │ │ └── V2__Insert_default_data.sql │ ├── static │ └── empty.txt │ └── templates │ └── empty.txt └── test └── java └── kitchenpos └── ApplicationTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 키친포스 2 | 3 | ## 요구 사항 4 | 5 | ## 용어 사전 6 | 7 | | 한글명 | 영문명 | 설명 | 8 | | --- | --- | --- | 9 | | 상품 | product | 메뉴를 관리하는 기준이 되는 데이터 | 10 | | 메뉴 그룹 | menu group | 메뉴 묶음, 분류 | 11 | | 메뉴 | menu | 메뉴 그룹에 속하는 실제 주문 가능 단위 | 12 | | 메뉴 상품 | menu product | 메뉴에 속하는 수량이 있는 상품 | 13 | | 금액 | amount | 가격 * 수량 | 14 | | 주문 테이블 | order table | 매장에서 주문이 발생하는 영역 | 15 | | 빈 테이블 | empty table | 주문을 등록할 수 없는 주문 테이블 | 16 | | 주문 | order | 매장에서 발생하는 주문 | 17 | | 주문 상태 | order status | 주문은 조리 ➜ 식사 ➜ 계산 완료 순서로 진행된다. | 18 | | 방문한 손님 수 | number of guests | 필수 사항은 아니며 주문은 0명으로 등록할 수 있다. | 19 | | 단체 지정 | table group | 통합 계산을 위해 개별 주문 테이블을 그룹화하는 기능 | 20 | | 주문 항목 | order line item | 주문에 속하는 수량이 있는 메뉴 | 21 | | 매장 식사 | eat in | 포장하지 않고 매장에서 식사하는 것 | 22 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.4.1' 3 | id 'io.spring.dependency-management' version '1.0.10.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'camp.nextstep.edu' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '1.8' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.springframework.boot:spring-boot-starter-actuator' 17 | implementation 'org.springframework.boot:spring-boot-starter-jdbc' 18 | implementation 'org.springframework.boot:spring-boot-starter-web' 19 | implementation 'org.flywaydb:flyway-core' 20 | runtimeOnly 'com.h2database:h2' 21 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 22 | } 23 | 24 | test { 25 | useJUnitPlatform() 26 | } 27 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step/jwp-refactoring/9b221f4de067d8a180fa0dae7ac922e5db2d9d54/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /http/menu-groups.http: -------------------------------------------------------------------------------- 1 | ### 2 | POST {{host}}/api/menu-groups 3 | Content-Type: application/json 4 | 5 | { 6 | "name": "추천메뉴" 7 | } 8 | 9 | ### 10 | GET {{host}}/api/menu-groups 11 | 12 | ### 13 | -------------------------------------------------------------------------------- /http/menus.http: -------------------------------------------------------------------------------- 1 | ### 2 | POST {{host}}/api/menus 3 | Content-Type: application/json 4 | 5 | { 6 | "name": "후라이드+후라이드", 7 | "price": 19000, 8 | "menuGroupId": 1, 9 | "menuProducts": [ 10 | { 11 | "productId": 1, 12 | "quantity": 2 13 | } 14 | ] 15 | } 16 | 17 | ### 18 | GET {{host}}/api/menus 19 | 20 | ### 21 | -------------------------------------------------------------------------------- /http/orders.http: -------------------------------------------------------------------------------- 1 | ### 2 | POST {{host}}/api/orders 3 | Content-Type: application/json 4 | 5 | { 6 | "orderTableId": 1, 7 | "orderLineItems": [ 8 | { 9 | "menuId": 1, 10 | "quantity": 1 11 | } 12 | ] 13 | } 14 | 15 | ### 16 | GET {{host}}/api/orders 17 | 18 | ### 19 | PUT {{host}}/api/orders/1/order-status 20 | Content-Type: application/json 21 | 22 | { 23 | "orderStatus": "MEAL" 24 | } 25 | 26 | ### 27 | PUT {{host}}/api/orders/1/order-status 28 | Content-Type: application/json 29 | 30 | { 31 | "orderStatus": "COMPLETION" 32 | } 33 | 34 | ### 35 | -------------------------------------------------------------------------------- /http/products.http: -------------------------------------------------------------------------------- 1 | ### 2 | POST {{host}}/api/products 3 | Content-Type: application/json 4 | 5 | { 6 | "name": "강정치킨", 7 | "price": 17000 8 | } 9 | 10 | ### 11 | GET {{host}}/api/products 12 | 13 | ### 14 | -------------------------------------------------------------------------------- /http/table-groups.http: -------------------------------------------------------------------------------- 1 | ### 2 | POST {{host}}/api/table-groups 3 | Content-Type: application/json 4 | 5 | { 6 | "orderTables": [ 7 | { 8 | "id": 1 9 | }, 10 | { 11 | "id": 2 12 | } 13 | ] 14 | } 15 | 16 | ### 17 | DELETE {{host}}/api/table-groups/1 18 | 19 | ### 20 | -------------------------------------------------------------------------------- /http/tables.http: -------------------------------------------------------------------------------- 1 | ### 2 | POST {{host}}/api/tables 3 | Content-Type: application/json 4 | 5 | { 6 | "numberOfGuests": 0, 7 | "empty": true 8 | } 9 | 10 | ### 11 | GET {{host}}/api/tables 12 | 13 | ### 14 | PUT {{host}}/api/tables/1/empty 15 | Content-Type: application/json 16 | 17 | { 18 | "empty": false 19 | } 20 | 21 | ### 22 | PUT {{host}}/api/tables/1/number-of-guests 23 | Content-Type: application/json 24 | 25 | { 26 | "numberOfGuests": 4 27 | } 28 | 29 | ### 30 | PUT {{host}}/api/tables/1/empty 31 | Content-Type: application/json 32 | 33 | { 34 | "empty": true 35 | } 36 | 37 | ### 38 | PUT {{host}}/api/tables/2/empty 39 | Content-Type: application/json 40 | 41 | { 42 | "empty": true 43 | } 44 | 45 | ### 46 | -------------------------------------------------------------------------------- /rest-client.env.json: -------------------------------------------------------------------------------- 1 | { 2 | "local": { 3 | "host": "localhost:8080" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'kitchenpos' 2 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/Application.java: -------------------------------------------------------------------------------- 1 | package 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 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/application/MenuGroupService.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.application; 2 | 3 | import kitchenpos.dao.MenuGroupDao; 4 | import kitchenpos.domain.MenuGroup; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | import java.util.List; 9 | 10 | @Service 11 | public class MenuGroupService { 12 | private final MenuGroupDao menuGroupDao; 13 | 14 | public MenuGroupService(final MenuGroupDao menuGroupDao) { 15 | this.menuGroupDao = menuGroupDao; 16 | } 17 | 18 | @Transactional 19 | public MenuGroup create(final MenuGroup menuGroup) { 20 | return menuGroupDao.save(menuGroup); 21 | } 22 | 23 | public List list() { 24 | return menuGroupDao.findAll(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/application/MenuService.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.application; 2 | 3 | import kitchenpos.dao.MenuDao; 4 | import kitchenpos.dao.MenuGroupDao; 5 | import kitchenpos.dao.MenuProductDao; 6 | import kitchenpos.dao.ProductDao; 7 | import kitchenpos.domain.Menu; 8 | import kitchenpos.domain.MenuProduct; 9 | import kitchenpos.domain.Product; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import java.math.BigDecimal; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Objects; 17 | 18 | @Service 19 | public class MenuService { 20 | private final MenuDao menuDao; 21 | private final MenuGroupDao menuGroupDao; 22 | private final MenuProductDao menuProductDao; 23 | private final ProductDao productDao; 24 | 25 | public MenuService( 26 | final MenuDao menuDao, 27 | final MenuGroupDao menuGroupDao, 28 | final MenuProductDao menuProductDao, 29 | final ProductDao productDao 30 | ) { 31 | this.menuDao = menuDao; 32 | this.menuGroupDao = menuGroupDao; 33 | this.menuProductDao = menuProductDao; 34 | this.productDao = productDao; 35 | } 36 | 37 | @Transactional 38 | public Menu create(final Menu menu) { 39 | final BigDecimal price = menu.getPrice(); 40 | 41 | if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) { 42 | throw new IllegalArgumentException(); 43 | } 44 | 45 | if (!menuGroupDao.existsById(menu.getMenuGroupId())) { 46 | throw new IllegalArgumentException(); 47 | } 48 | 49 | final List menuProducts = menu.getMenuProducts(); 50 | 51 | BigDecimal sum = BigDecimal.ZERO; 52 | for (final MenuProduct menuProduct : menuProducts) { 53 | final Product product = productDao.findById(menuProduct.getProductId()) 54 | .orElseThrow(IllegalArgumentException::new); 55 | sum = sum.add(product.getPrice().multiply(BigDecimal.valueOf(menuProduct.getQuantity()))); 56 | } 57 | 58 | if (price.compareTo(sum) > 0) { 59 | throw new IllegalArgumentException(); 60 | } 61 | 62 | final Menu savedMenu = menuDao.save(menu); 63 | 64 | final Long menuId = savedMenu.getId(); 65 | final List savedMenuProducts = new ArrayList<>(); 66 | for (final MenuProduct menuProduct : menuProducts) { 67 | menuProduct.setMenuId(menuId); 68 | savedMenuProducts.add(menuProductDao.save(menuProduct)); 69 | } 70 | savedMenu.setMenuProducts(savedMenuProducts); 71 | 72 | return savedMenu; 73 | } 74 | 75 | public List list() { 76 | final List menus = menuDao.findAll(); 77 | 78 | for (final Menu menu : menus) { 79 | menu.setMenuProducts(menuProductDao.findAllByMenuId(menu.getId())); 80 | } 81 | 82 | return menus; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/application/OrderService.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.application; 2 | 3 | import kitchenpos.dao.MenuDao; 4 | import kitchenpos.dao.OrderDao; 5 | import kitchenpos.dao.OrderLineItemDao; 6 | import kitchenpos.dao.OrderTableDao; 7 | import kitchenpos.domain.Order; 8 | import kitchenpos.domain.OrderLineItem; 9 | import kitchenpos.domain.OrderStatus; 10 | import kitchenpos.domain.OrderTable; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | import org.springframework.util.CollectionUtils; 14 | 15 | import java.time.LocalDateTime; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.Objects; 19 | import java.util.stream.Collectors; 20 | 21 | @Service 22 | public class OrderService { 23 | private final MenuDao menuDao; 24 | private final OrderDao orderDao; 25 | private final OrderLineItemDao orderLineItemDao; 26 | private final OrderTableDao orderTableDao; 27 | 28 | public OrderService( 29 | final MenuDao menuDao, 30 | final OrderDao orderDao, 31 | final OrderLineItemDao orderLineItemDao, 32 | final OrderTableDao orderTableDao 33 | ) { 34 | this.menuDao = menuDao; 35 | this.orderDao = orderDao; 36 | this.orderLineItemDao = orderLineItemDao; 37 | this.orderTableDao = orderTableDao; 38 | } 39 | 40 | @Transactional 41 | public Order create(final Order order) { 42 | final List orderLineItems = order.getOrderLineItems(); 43 | 44 | if (CollectionUtils.isEmpty(orderLineItems)) { 45 | throw new IllegalArgumentException(); 46 | } 47 | 48 | final List menuIds = orderLineItems.stream() 49 | .map(OrderLineItem::getMenuId) 50 | .collect(Collectors.toList()); 51 | 52 | if (orderLineItems.size() != menuDao.countByIdIn(menuIds)) { 53 | throw new IllegalArgumentException(); 54 | } 55 | 56 | final OrderTable orderTable = orderTableDao.findById(order.getOrderTableId()) 57 | .orElseThrow(IllegalArgumentException::new); 58 | 59 | if (orderTable.isEmpty()) { 60 | throw new IllegalArgumentException(); 61 | } 62 | 63 | order.setOrderTableId(orderTable.getId()); 64 | order.setOrderStatus(OrderStatus.COOKING.name()); 65 | order.setOrderedTime(LocalDateTime.now()); 66 | 67 | final Order savedOrder = orderDao.save(order); 68 | 69 | final Long orderId = savedOrder.getId(); 70 | final List savedOrderLineItems = new ArrayList<>(); 71 | for (final OrderLineItem orderLineItem : orderLineItems) { 72 | orderLineItem.setOrderId(orderId); 73 | savedOrderLineItems.add(orderLineItemDao.save(orderLineItem)); 74 | } 75 | savedOrder.setOrderLineItems(savedOrderLineItems); 76 | 77 | return savedOrder; 78 | } 79 | 80 | public List list() { 81 | final List orders = orderDao.findAll(); 82 | 83 | for (final Order order : orders) { 84 | order.setOrderLineItems(orderLineItemDao.findAllByOrderId(order.getId())); 85 | } 86 | 87 | return orders; 88 | } 89 | 90 | @Transactional 91 | public Order changeOrderStatus(final Long orderId, final Order order) { 92 | final Order savedOrder = orderDao.findById(orderId) 93 | .orElseThrow(IllegalArgumentException::new); 94 | 95 | if (Objects.equals(OrderStatus.COMPLETION.name(), savedOrder.getOrderStatus())) { 96 | throw new IllegalArgumentException(); 97 | } 98 | 99 | final OrderStatus orderStatus = OrderStatus.valueOf(order.getOrderStatus()); 100 | savedOrder.setOrderStatus(orderStatus.name()); 101 | 102 | orderDao.save(savedOrder); 103 | 104 | savedOrder.setOrderLineItems(orderLineItemDao.findAllByOrderId(orderId)); 105 | 106 | return savedOrder; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/application/ProductService.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.application; 2 | 3 | import kitchenpos.dao.ProductDao; 4 | import kitchenpos.domain.Product; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | import java.math.BigDecimal; 9 | import java.util.List; 10 | import java.util.Objects; 11 | 12 | @Service 13 | public class ProductService { 14 | private final ProductDao productDao; 15 | 16 | public ProductService(final ProductDao productDao) { 17 | this.productDao = productDao; 18 | } 19 | 20 | @Transactional 21 | public Product create(final Product product) { 22 | final BigDecimal price = product.getPrice(); 23 | 24 | if (Objects.isNull(price) || price.compareTo(BigDecimal.ZERO) < 0) { 25 | throw new IllegalArgumentException(); 26 | } 27 | 28 | return productDao.save(product); 29 | } 30 | 31 | public List list() { 32 | return productDao.findAll(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/application/TableGroupService.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.application; 2 | 3 | import kitchenpos.dao.OrderDao; 4 | import kitchenpos.dao.OrderTableDao; 5 | import kitchenpos.dao.TableGroupDao; 6 | import kitchenpos.domain.OrderStatus; 7 | import kitchenpos.domain.OrderTable; 8 | import kitchenpos.domain.TableGroup; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Transactional; 11 | import org.springframework.util.CollectionUtils; 12 | 13 | import java.time.LocalDateTime; 14 | import java.util.Arrays; 15 | import java.util.List; 16 | import java.util.Objects; 17 | import java.util.stream.Collectors; 18 | 19 | @Service 20 | public class TableGroupService { 21 | private final OrderDao orderDao; 22 | private final OrderTableDao orderTableDao; 23 | private final TableGroupDao tableGroupDao; 24 | 25 | public TableGroupService(final OrderDao orderDao, final OrderTableDao orderTableDao, final TableGroupDao tableGroupDao) { 26 | this.orderDao = orderDao; 27 | this.orderTableDao = orderTableDao; 28 | this.tableGroupDao = tableGroupDao; 29 | } 30 | 31 | @Transactional 32 | public TableGroup create(final TableGroup tableGroup) { 33 | final List orderTables = tableGroup.getOrderTables(); 34 | 35 | if (CollectionUtils.isEmpty(orderTables) || orderTables.size() < 2) { 36 | throw new IllegalArgumentException(); 37 | } 38 | 39 | final List orderTableIds = orderTables.stream() 40 | .map(OrderTable::getId) 41 | .collect(Collectors.toList()); 42 | 43 | final List savedOrderTables = orderTableDao.findAllByIdIn(orderTableIds); 44 | 45 | if (orderTables.size() != savedOrderTables.size()) { 46 | throw new IllegalArgumentException(); 47 | } 48 | 49 | for (final OrderTable savedOrderTable : savedOrderTables) { 50 | if (!savedOrderTable.isEmpty() || Objects.nonNull(savedOrderTable.getTableGroupId())) { 51 | throw new IllegalArgumentException(); 52 | } 53 | } 54 | 55 | tableGroup.setCreatedDate(LocalDateTime.now()); 56 | 57 | final TableGroup savedTableGroup = tableGroupDao.save(tableGroup); 58 | 59 | final Long tableGroupId = savedTableGroup.getId(); 60 | for (final OrderTable savedOrderTable : savedOrderTables) { 61 | savedOrderTable.setTableGroupId(tableGroupId); 62 | savedOrderTable.setEmpty(false); 63 | orderTableDao.save(savedOrderTable); 64 | } 65 | savedTableGroup.setOrderTables(savedOrderTables); 66 | 67 | return savedTableGroup; 68 | } 69 | 70 | @Transactional 71 | public void ungroup(final Long tableGroupId) { 72 | final List orderTables = orderTableDao.findAllByTableGroupId(tableGroupId); 73 | 74 | final List orderTableIds = orderTables.stream() 75 | .map(OrderTable::getId) 76 | .collect(Collectors.toList()); 77 | 78 | if (orderDao.existsByOrderTableIdInAndOrderStatusIn( 79 | orderTableIds, Arrays.asList(OrderStatus.COOKING.name(), OrderStatus.MEAL.name()))) { 80 | throw new IllegalArgumentException(); 81 | } 82 | 83 | for (final OrderTable orderTable : orderTables) { 84 | orderTable.setTableGroupId(null); 85 | orderTableDao.save(orderTable); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/application/TableService.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.application; 2 | 3 | import kitchenpos.dao.OrderDao; 4 | import kitchenpos.dao.OrderTableDao; 5 | import kitchenpos.domain.OrderStatus; 6 | import kitchenpos.domain.OrderTable; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | import java.util.Objects; 13 | 14 | @Service 15 | public class TableService { 16 | private final OrderDao orderDao; 17 | private final OrderTableDao orderTableDao; 18 | 19 | public TableService(final OrderDao orderDao, final OrderTableDao orderTableDao) { 20 | this.orderDao = orderDao; 21 | this.orderTableDao = orderTableDao; 22 | } 23 | 24 | @Transactional 25 | public OrderTable create(final OrderTable orderTable) { 26 | orderTable.setTableGroupId(null); 27 | 28 | return orderTableDao.save(orderTable); 29 | } 30 | 31 | public List list() { 32 | return orderTableDao.findAll(); 33 | } 34 | 35 | @Transactional 36 | public OrderTable changeEmpty(final Long orderTableId, final OrderTable orderTable) { 37 | final OrderTable savedOrderTable = orderTableDao.findById(orderTableId) 38 | .orElseThrow(IllegalArgumentException::new); 39 | 40 | if (Objects.nonNull(savedOrderTable.getTableGroupId())) { 41 | throw new IllegalArgumentException(); 42 | } 43 | 44 | if (orderDao.existsByOrderTableIdAndOrderStatusIn( 45 | orderTableId, Arrays.asList(OrderStatus.COOKING.name(), OrderStatus.MEAL.name()))) { 46 | throw new IllegalArgumentException(); 47 | } 48 | 49 | savedOrderTable.setEmpty(orderTable.isEmpty()); 50 | 51 | return orderTableDao.save(savedOrderTable); 52 | } 53 | 54 | @Transactional 55 | public OrderTable changeNumberOfGuests(final Long orderTableId, final OrderTable orderTable) { 56 | final int numberOfGuests = orderTable.getNumberOfGuests(); 57 | 58 | if (numberOfGuests < 0) { 59 | throw new IllegalArgumentException(); 60 | } 61 | 62 | final OrderTable savedOrderTable = orderTableDao.findById(orderTableId) 63 | .orElseThrow(IllegalArgumentException::new); 64 | 65 | if (savedOrderTable.isEmpty()) { 66 | throw new IllegalArgumentException(); 67 | } 68 | 69 | savedOrderTable.setNumberOfGuests(numberOfGuests); 70 | 71 | return orderTableDao.save(savedOrderTable); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/JdbcTemplateMenuDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.Menu; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 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.util.List; 16 | import java.util.Optional; 17 | 18 | @Repository 19 | public class JdbcTemplateMenuDao implements MenuDao { 20 | private static final String TABLE_NAME = "menu"; 21 | private static final String KEY_COLUMN_NAME = "id"; 22 | 23 | private final NamedParameterJdbcTemplate jdbcTemplate; 24 | private final SimpleJdbcInsert jdbcInsert; 25 | 26 | public JdbcTemplateMenuDao(final DataSource dataSource) { 27 | jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); 28 | jdbcInsert = new SimpleJdbcInsert(dataSource) 29 | .withTableName(TABLE_NAME) 30 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 31 | ; 32 | } 33 | 34 | @Override 35 | public Menu save(final Menu entity) { 36 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 37 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 38 | return select(key.longValue()); 39 | } 40 | 41 | @Override 42 | public Optional findById(final Long id) { 43 | try { 44 | return Optional.of(select(id)); 45 | } catch (final EmptyResultDataAccessException e) { 46 | return Optional.empty(); 47 | } 48 | } 49 | 50 | @Override 51 | public List findAll() { 52 | final String sql = "SELECT id, name, price, menu_group_id FROM menu "; 53 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 54 | } 55 | 56 | @Override 57 | public long countByIdIn(final List ids) { 58 | final String sql = "SELECT COUNT(*) FROM menu WHERE id IN (:ids)"; 59 | final SqlParameterSource parameters = new MapSqlParameterSource() 60 | .addValue("ids", ids); 61 | return jdbcTemplate.queryForObject(sql, parameters, Long.class); 62 | } 63 | 64 | private Menu select(final Long id) { 65 | final String sql = "SELECT id, name, price, menu_group_id FROM menu WHERE id = (:id)"; 66 | final SqlParameterSource parameters = new MapSqlParameterSource() 67 | .addValue("id", id); 68 | return jdbcTemplate.queryForObject(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 69 | } 70 | 71 | private Menu toEntity(final ResultSet resultSet) throws SQLException { 72 | final Menu entity = new Menu(); 73 | entity.setId(resultSet.getLong("id")); 74 | entity.setName(resultSet.getString("name")); 75 | entity.setPrice(resultSet.getBigDecimal("price")); 76 | entity.setMenuGroupId(resultSet.getLong("menu_group_id")); 77 | return entity; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/JdbcTemplateMenuGroupDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.MenuGroup; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 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.util.List; 16 | import java.util.Optional; 17 | 18 | @Repository 19 | public class JdbcTemplateMenuGroupDao implements MenuGroupDao { 20 | private static final String TABLE_NAME = "menu_group"; 21 | private static final String KEY_COLUMN_NAME = "id"; 22 | 23 | private final NamedParameterJdbcTemplate jdbcTemplate; 24 | private final SimpleJdbcInsert jdbcInsert; 25 | 26 | public JdbcTemplateMenuGroupDao(final DataSource dataSource) { 27 | jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); 28 | jdbcInsert = new SimpleJdbcInsert(dataSource) 29 | .withTableName(TABLE_NAME) 30 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 31 | ; 32 | } 33 | 34 | @Override 35 | public MenuGroup save(final MenuGroup entity) { 36 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 37 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 38 | return select(key.longValue()); 39 | } 40 | 41 | @Override 42 | public Optional findById(final Long id) { 43 | try { 44 | return Optional.of(select(id)); 45 | } catch (final EmptyResultDataAccessException e) { 46 | return Optional.empty(); 47 | } 48 | } 49 | 50 | @Override 51 | public List findAll() { 52 | final String sql = "SELECT id, name FROM menu_group"; 53 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 54 | } 55 | 56 | @Override 57 | public boolean existsById(final Long id) { 58 | final String sql = "SELECT CASE WHEN COUNT(*) > 0 THEN TRUE ELSE FALSE END FROM menu_group WHERE id = (:id)"; 59 | final SqlParameterSource parameters = new MapSqlParameterSource() 60 | .addValue("id", id); 61 | return jdbcTemplate.queryForObject(sql, parameters, Boolean.class); 62 | } 63 | 64 | private MenuGroup select(final Long id) { 65 | final String sql = "SELECT id, name FROM menu_group WHERE id = (:id)"; 66 | final SqlParameterSource parameters = new MapSqlParameterSource() 67 | .addValue("id", id); 68 | return jdbcTemplate.queryForObject(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 69 | } 70 | 71 | private MenuGroup toEntity(final ResultSet resultSet) throws SQLException { 72 | final MenuGroup entity = new MenuGroup(); 73 | entity.setId(resultSet.getLong("id")); 74 | entity.setName(resultSet.getString("name")); 75 | return entity; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/JdbcTemplateMenuProductDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.MenuProduct; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 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.util.List; 16 | import java.util.Optional; 17 | 18 | @Repository 19 | public class JdbcTemplateMenuProductDao implements MenuProductDao { 20 | private static final String TABLE_NAME = "menu_product"; 21 | private static final String KEY_COLUMN_NAME = "seq"; 22 | 23 | private final NamedParameterJdbcTemplate jdbcTemplate; 24 | private final SimpleJdbcInsert jdbcInsert; 25 | 26 | public JdbcTemplateMenuProductDao(final DataSource dataSource) { 27 | jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); 28 | jdbcInsert = new SimpleJdbcInsert(dataSource) 29 | .withTableName(TABLE_NAME) 30 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 31 | ; 32 | } 33 | 34 | @Override 35 | public MenuProduct save(final MenuProduct entity) { 36 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 37 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 38 | return select(key.longValue()); 39 | } 40 | 41 | @Override 42 | public Optional findById(final Long id) { 43 | try { 44 | return Optional.of(select(id)); 45 | } catch (final EmptyResultDataAccessException e) { 46 | return Optional.empty(); 47 | } 48 | } 49 | 50 | @Override 51 | public List findAll() { 52 | final String sql = "SELECT seq, menu_id, product_id, quantity FROM menu_product"; 53 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 54 | } 55 | 56 | @Override 57 | public List findAllByMenuId(final Long menuId) { 58 | final String sql = "SELECT seq, menu_id, product_id, quantity FROM menu_product WHERE menu_id = (:menuId)"; 59 | final SqlParameterSource parameters = new MapSqlParameterSource() 60 | .addValue("menuId", menuId); 61 | return jdbcTemplate.query(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 62 | } 63 | 64 | private MenuProduct select(final Long id) { 65 | final String sql = "SELECT seq, menu_id, product_id, quantity FROM menu_product WHERE seq = (:seq)"; 66 | final SqlParameterSource parameters = new MapSqlParameterSource() 67 | .addValue("seq", id); 68 | return jdbcTemplate.queryForObject(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 69 | } 70 | 71 | private MenuProduct toEntity(final ResultSet resultSet) throws SQLException { 72 | final MenuProduct entity = new MenuProduct(); 73 | entity.setSeq(resultSet.getLong(KEY_COLUMN_NAME)); 74 | entity.setMenuId(resultSet.getLong("menu_id")); 75 | entity.setProductId(resultSet.getLong("product_id")); 76 | entity.setQuantity(resultSet.getLong("quantity")); 77 | return entity; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/JdbcTemplateOrderDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.Order; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 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.Objects; 18 | import java.util.Optional; 19 | 20 | @Repository 21 | public class JdbcTemplateOrderDao implements OrderDao { 22 | private static final String TABLE_NAME = "orders"; 23 | private static final String KEY_COLUMN_NAME = "id"; 24 | 25 | private final NamedParameterJdbcTemplate jdbcTemplate; 26 | private final SimpleJdbcInsert jdbcInsert; 27 | 28 | public JdbcTemplateOrderDao(final DataSource dataSource) { 29 | jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); 30 | jdbcInsert = new SimpleJdbcInsert(dataSource) 31 | .withTableName(TABLE_NAME) 32 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 33 | ; 34 | } 35 | 36 | @Override 37 | public Order save(final Order entity) { 38 | if (Objects.isNull(entity.getId())) { 39 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 40 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 41 | return select(key.longValue()); 42 | } 43 | update(entity); 44 | return entity; 45 | } 46 | 47 | @Override 48 | public Optional findById(final Long id) { 49 | try { 50 | return Optional.of(select(id)); 51 | } catch (final EmptyResultDataAccessException e) { 52 | return Optional.empty(); 53 | } 54 | } 55 | 56 | @Override 57 | public List findAll() { 58 | final String sql = "SELECT id, order_table_id, order_status, ordered_time FROM orders"; 59 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 60 | } 61 | 62 | @Override 63 | public boolean existsByOrderTableIdAndOrderStatusIn(final Long orderTableId, final List orderStatuses) { 64 | final String sql = "SELECT CASE WHEN COUNT(*) > 0 THEN TRUE ELSE FALSE END" + 65 | " FROM orders WHERE order_table_id = (:orderTableId) AND order_status IN (:orderStatuses)"; 66 | final SqlParameterSource parameters = new MapSqlParameterSource() 67 | .addValue("orderTableId", orderTableId) 68 | .addValue("orderStatuses", orderStatuses); 69 | return jdbcTemplate.queryForObject(sql, parameters, Boolean.class); 70 | } 71 | 72 | @Override 73 | public boolean existsByOrderTableIdInAndOrderStatusIn(final List orderTableIds, final List orderStatuses) { 74 | final String sql = "SELECT CASE WHEN COUNT(*) > 0 THEN TRUE ELSE FALSE END" + 75 | " FROM orders WHERE order_table_id IN (:orderTableIds) AND order_status IN (:orderStatuses)"; 76 | final SqlParameterSource parameters = new MapSqlParameterSource() 77 | .addValue("orderTableIds", orderTableIds) 78 | .addValue("orderStatuses", orderStatuses); 79 | return jdbcTemplate.queryForObject(sql, parameters, Boolean.class); 80 | } 81 | 82 | private Order select(final Long id) { 83 | final String sql = "SELECT id, order_table_id, order_status, ordered_time FROM orders WHERE id = (:id)"; 84 | final SqlParameterSource parameters = new MapSqlParameterSource() 85 | .addValue("id", id); 86 | return jdbcTemplate.queryForObject(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 87 | } 88 | 89 | private void update(final Order entity) { 90 | final String sql = "UPDATE orders SET order_status = (:orderStatus) WHERE id = (:id)"; 91 | final SqlParameterSource parameters = new MapSqlParameterSource() 92 | .addValue("orderStatus", entity.getOrderStatus()) 93 | .addValue("id", entity.getId()); 94 | jdbcTemplate.update(sql, parameters); 95 | } 96 | 97 | private Order toEntity(final ResultSet resultSet) throws SQLException { 98 | final Order entity = new Order(); 99 | entity.setId(resultSet.getLong(KEY_COLUMN_NAME)); 100 | entity.setOrderTableId(resultSet.getLong("order_table_id")); 101 | entity.setOrderStatus(resultSet.getString("order_status")); 102 | entity.setOrderedTime(resultSet.getObject("ordered_time", LocalDateTime.class)); 103 | return entity; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/JdbcTemplateOrderLineItemDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.OrderLineItem; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 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.util.List; 16 | import java.util.Optional; 17 | 18 | @Repository 19 | public class JdbcTemplateOrderLineItemDao implements OrderLineItemDao { 20 | private static final String TABLE_NAME = "order_line_item"; 21 | private static final String KEY_COLUMN_NAME = "seq"; 22 | 23 | private final NamedParameterJdbcTemplate jdbcTemplate; 24 | private final SimpleJdbcInsert jdbcInsert; 25 | 26 | public JdbcTemplateOrderLineItemDao(final DataSource dataSource) { 27 | jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); 28 | jdbcInsert = new SimpleJdbcInsert(dataSource) 29 | .withTableName(TABLE_NAME) 30 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 31 | ; 32 | } 33 | 34 | @Override 35 | public OrderLineItem 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 | @Override 42 | public Optional findById(final Long id) { 43 | try { 44 | return Optional.of(select(id)); 45 | } catch (final EmptyResultDataAccessException e) { 46 | return Optional.empty(); 47 | } 48 | } 49 | 50 | @Override 51 | public List findAll() { 52 | final String sql = "SELECT seq, order_id, menu_id, quantity FROM order_line_item"; 53 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 54 | } 55 | 56 | @Override 57 | public List findAllByOrderId(final Long orderId) { 58 | final String sql = "SELECT seq, order_id, menu_id, quantity FROM order_line_item WHERE order_id = (:orderId)"; 59 | final SqlParameterSource parameters = new MapSqlParameterSource() 60 | .addValue("orderId", orderId); 61 | return jdbcTemplate.query(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 62 | } 63 | 64 | private OrderLineItem select(final Long id) { 65 | final String sql = "SELECT seq, order_id, menu_id, quantity FROM order_line_item WHERE seq = (:seq)"; 66 | final SqlParameterSource parameters = new MapSqlParameterSource() 67 | .addValue("seq", id); 68 | return jdbcTemplate.queryForObject(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 69 | } 70 | 71 | private OrderLineItem toEntity(final ResultSet resultSet) throws SQLException { 72 | final OrderLineItem entity = new OrderLineItem(); 73 | entity.setSeq(resultSet.getLong(KEY_COLUMN_NAME)); 74 | entity.setOrderId(resultSet.getLong("order_id")); 75 | entity.setMenuId(resultSet.getLong("menu_id")); 76 | entity.setQuantity(resultSet.getLong("quantity")); 77 | return entity; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/JdbcTemplateOrderTableDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.OrderTable; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 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.util.List; 16 | import java.util.Objects; 17 | import java.util.Optional; 18 | 19 | @Repository 20 | public class JdbcTemplateOrderTableDao implements OrderTableDao { 21 | private static final String TABLE_NAME = "order_table"; 22 | private static final String KEY_COLUMN_NAME = "id"; 23 | 24 | private final NamedParameterJdbcTemplate jdbcTemplate; 25 | private final SimpleJdbcInsert jdbcInsert; 26 | 27 | public JdbcTemplateOrderTableDao(final DataSource dataSource) { 28 | jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); 29 | jdbcInsert = new SimpleJdbcInsert(dataSource) 30 | .withTableName(TABLE_NAME) 31 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 32 | ; 33 | } 34 | 35 | @Override 36 | public OrderTable save(final OrderTable entity) { 37 | if (Objects.isNull(entity.getId())) { 38 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 39 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 40 | return select(key.longValue()); 41 | } 42 | update(entity); 43 | return entity; 44 | } 45 | 46 | @Override 47 | public Optional findById(final Long id) { 48 | try { 49 | return Optional.of(select(id)); 50 | } catch (final EmptyResultDataAccessException e) { 51 | return Optional.empty(); 52 | } 53 | } 54 | 55 | @Override 56 | public List findAll() { 57 | final String sql = "SELECT id, table_group_id, number_of_guests, empty FROM order_table"; 58 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 59 | } 60 | 61 | @Override 62 | public List findAllByIdIn(final List ids) { 63 | final String sql = "SELECT id, table_group_id, number_of_guests, empty FROM order_table WHERE id IN (:ids)"; 64 | final SqlParameterSource parameters = new MapSqlParameterSource() 65 | .addValue("ids", ids); 66 | return jdbcTemplate.query(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 67 | } 68 | 69 | @Override 70 | public List findAllByTableGroupId(final Long tableGroupId) { 71 | final String sql = "SELECT id, table_group_id, number_of_guests, empty" + 72 | " FROM order_table WHERE table_group_id = (:tableGroupId)"; 73 | final SqlParameterSource parameters = new MapSqlParameterSource() 74 | .addValue("tableGroupId", tableGroupId); 75 | return jdbcTemplate.query(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 76 | } 77 | 78 | private OrderTable select(final Long id) { 79 | final String sql = "SELECT id, table_group_id, number_of_guests, empty FROM order_table WHERE id = (:id)"; 80 | final SqlParameterSource parameters = new MapSqlParameterSource() 81 | .addValue("id", id); 82 | return jdbcTemplate.queryForObject(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 83 | } 84 | 85 | private void update(final OrderTable entity) { 86 | final String sql = "UPDATE order_table SET table_group_id = (:tableGroupId)," + 87 | " number_of_guests = (:numberOfGuests), empty = (:empty) WHERE id = (:id)"; 88 | final SqlParameterSource parameters = new MapSqlParameterSource() 89 | .addValue("tableGroupId", entity.getTableGroupId()) 90 | .addValue("numberOfGuests", entity.getNumberOfGuests()) 91 | .addValue("empty", entity.isEmpty()) 92 | .addValue("id", entity.getId()); 93 | jdbcTemplate.update(sql, parameters); 94 | } 95 | 96 | private OrderTable toEntity(final ResultSet resultSet) throws SQLException { 97 | final OrderTable entity = new OrderTable(); 98 | entity.setId(resultSet.getLong(KEY_COLUMN_NAME)); 99 | entity.setTableGroupId(resultSet.getObject("table_group_id", Long.class)); 100 | entity.setNumberOfGuests(resultSet.getInt("number_of_guests")); 101 | entity.setEmpty(resultSet.getBoolean("empty")); 102 | return entity; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/JdbcTemplateProductDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.Product; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 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.util.List; 16 | import java.util.Optional; 17 | 18 | @Repository 19 | public class JdbcTemplateProductDao implements ProductDao { 20 | private static final String TABLE_NAME = "product"; 21 | private static final String KEY_COLUMN_NAME = "id"; 22 | 23 | private final NamedParameterJdbcTemplate jdbcTemplate; 24 | private final SimpleJdbcInsert jdbcInsert; 25 | 26 | public JdbcTemplateProductDao(final DataSource dataSource) { 27 | jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); 28 | jdbcInsert = new SimpleJdbcInsert(dataSource) 29 | .withTableName(TABLE_NAME) 30 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 31 | ; 32 | } 33 | 34 | @Override 35 | public Product save(final Product entity) { 36 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 37 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 38 | return select(key.longValue()); 39 | } 40 | 41 | @Override 42 | public Optional findById(final Long id) { 43 | try { 44 | return Optional.of(select(id)); 45 | } catch (final EmptyResultDataAccessException e) { 46 | return Optional.empty(); 47 | } 48 | } 49 | 50 | @Override 51 | public List findAll() { 52 | final String sql = "SELECT id, name, price FROM product"; 53 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 54 | } 55 | 56 | private Product select(final Long id) { 57 | final String sql = "SELECT id, name, price FROM product WHERE id = (:id)"; 58 | final SqlParameterSource parameters = new MapSqlParameterSource() 59 | .addValue("id", id); 60 | return jdbcTemplate.queryForObject(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 61 | } 62 | 63 | private Product toEntity(final ResultSet resultSet) throws SQLException { 64 | final Product entity = new Product(); 65 | entity.setId(resultSet.getLong(KEY_COLUMN_NAME)); 66 | entity.setName(resultSet.getString("name")); 67 | entity.setPrice(resultSet.getBigDecimal("price")); 68 | return entity; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/JdbcTemplateTableGroupDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.TableGroup; 4 | import org.springframework.dao.EmptyResultDataAccessException; 5 | import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; 6 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; 7 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 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 JdbcTemplateTableGroupDao implements TableGroupDao { 21 | private static final String TABLE_NAME = "table_group"; 22 | private static final String KEY_COLUMN_NAME = "id"; 23 | 24 | private final NamedParameterJdbcTemplate jdbcTemplate; 25 | private final SimpleJdbcInsert jdbcInsert; 26 | 27 | public JdbcTemplateTableGroupDao(final DataSource dataSource) { 28 | jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); 29 | jdbcInsert = new SimpleJdbcInsert(dataSource) 30 | .withTableName(TABLE_NAME) 31 | .usingGeneratedKeyColumns(KEY_COLUMN_NAME) 32 | ; 33 | } 34 | 35 | @Override 36 | public TableGroup save(final TableGroup entity) { 37 | final SqlParameterSource parameters = new BeanPropertySqlParameterSource(entity); 38 | final Number key = jdbcInsert.executeAndReturnKey(parameters); 39 | return select(key.longValue()); 40 | } 41 | 42 | @Override 43 | public Optional findById(final Long id) { 44 | try { 45 | return Optional.of(select(id)); 46 | } catch (final EmptyResultDataAccessException e) { 47 | return Optional.empty(); 48 | } 49 | } 50 | 51 | @Override 52 | public List findAll() { 53 | final String sql = "SELECT id, created_date FROM table_group"; 54 | return jdbcTemplate.query(sql, (resultSet, rowNumber) -> toEntity(resultSet)); 55 | } 56 | 57 | private TableGroup select(final Long id) { 58 | final String sql = "SELECT id, created_date FROM table_group WHERE id = (:id)"; 59 | final SqlParameterSource parameters = new MapSqlParameterSource() 60 | .addValue("id", id); 61 | return jdbcTemplate.queryForObject(sql, parameters, (resultSet, rowNumber) -> toEntity(resultSet)); 62 | } 63 | 64 | private TableGroup toEntity(final ResultSet resultSet) throws SQLException { 65 | final TableGroup entity = new TableGroup(); 66 | entity.setId(resultSet.getLong(KEY_COLUMN_NAME)); 67 | entity.setCreatedDate(resultSet.getObject("created_date", LocalDateTime.class)); 68 | return entity; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/MenuDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.Menu; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface MenuDao { 9 | Menu save(Menu entity); 10 | 11 | Optional findById(Long id); 12 | 13 | List findAll(); 14 | 15 | long countByIdIn(List ids); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/MenuGroupDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.MenuGroup; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface MenuGroupDao { 9 | MenuGroup save(MenuGroup entity); 10 | 11 | Optional findById(Long id); 12 | 13 | List findAll(); 14 | 15 | boolean existsById(Long id); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/MenuProductDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.MenuProduct; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface MenuProductDao { 9 | MenuProduct save(MenuProduct entity); 10 | 11 | Optional findById(Long id); 12 | 13 | List findAll(); 14 | 15 | List findAllByMenuId(Long menuId); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/OrderDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.Order; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface OrderDao { 9 | Order save(Order entity); 10 | 11 | Optional findById(Long id); 12 | 13 | List findAll(); 14 | 15 | boolean existsByOrderTableIdAndOrderStatusIn(Long orderTableId, List orderStatuses); 16 | 17 | boolean existsByOrderTableIdInAndOrderStatusIn(List orderTableIds, List orderStatuses); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/OrderLineItemDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.OrderLineItem; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface OrderLineItemDao { 9 | OrderLineItem save(OrderLineItem entity); 10 | 11 | Optional findById(Long id); 12 | 13 | List findAll(); 14 | 15 | List findAllByOrderId(Long orderId); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/OrderTableDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.OrderTable; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface OrderTableDao { 9 | OrderTable save(OrderTable entity); 10 | 11 | Optional findById(Long id); 12 | 13 | List findAll(); 14 | 15 | List findAllByIdIn(List ids); 16 | 17 | List findAllByTableGroupId(Long tableGroupId); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/ProductDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.Product; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface ProductDao { 9 | Product save(Product entity); 10 | 11 | Optional findById(Long id); 12 | 13 | List findAll(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/dao/TableGroupDao.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.dao; 2 | 3 | import kitchenpos.domain.TableGroup; 4 | 5 | import java.util.List; 6 | import java.util.Optional; 7 | 8 | public interface TableGroupDao { 9 | TableGroup save(TableGroup entity); 10 | 11 | Optional findById(Long id); 12 | 13 | List findAll(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/domain/Menu.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.domain; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | 6 | public class Menu { 7 | private Long id; 8 | private String name; 9 | private BigDecimal price; 10 | private Long menuGroupId; 11 | private List menuProducts; 12 | 13 | public Long getId() { 14 | return id; 15 | } 16 | 17 | public void setId(final Long id) { 18 | this.id = id; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(final String name) { 26 | this.name = name; 27 | } 28 | 29 | public BigDecimal getPrice() { 30 | return price; 31 | } 32 | 33 | public void setPrice(final BigDecimal price) { 34 | this.price = price; 35 | } 36 | 37 | public Long getMenuGroupId() { 38 | return menuGroupId; 39 | } 40 | 41 | public void setMenuGroupId(final Long menuGroupId) { 42 | this.menuGroupId = menuGroupId; 43 | } 44 | 45 | public List getMenuProducts() { 46 | return menuProducts; 47 | } 48 | 49 | public void setMenuProducts(final List menuProducts) { 50 | this.menuProducts = menuProducts; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/domain/MenuGroup.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.domain; 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/kitchenpos/domain/MenuProduct.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.domain; 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/kitchenpos/domain/Order.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.domain; 2 | 3 | import java.time.LocalDateTime; 4 | import java.util.List; 5 | 6 | public class Order { 7 | private Long id; 8 | private Long orderTableId; 9 | private String orderStatus; 10 | private LocalDateTime orderedTime; 11 | private List orderLineItems; 12 | 13 | public Long getId() { 14 | return id; 15 | } 16 | 17 | public void setId(final Long id) { 18 | this.id = id; 19 | } 20 | 21 | public Long getOrderTableId() { 22 | return orderTableId; 23 | } 24 | 25 | public void setOrderTableId(final Long orderTableId) { 26 | this.orderTableId = orderTableId; 27 | } 28 | 29 | public String getOrderStatus() { 30 | return orderStatus; 31 | } 32 | 33 | public void setOrderStatus(final String orderStatus) { 34 | this.orderStatus = orderStatus; 35 | } 36 | 37 | public LocalDateTime getOrderedTime() { 38 | return orderedTime; 39 | } 40 | 41 | public void setOrderedTime(final LocalDateTime orderedTime) { 42 | this.orderedTime = orderedTime; 43 | } 44 | 45 | public List getOrderLineItems() { 46 | return orderLineItems; 47 | } 48 | 49 | public void setOrderLineItems(final List orderLineItems) { 50 | this.orderLineItems = orderLineItems; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/domain/OrderLineItem.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.domain; 2 | 3 | public class OrderLineItem { 4 | private Long seq; 5 | private Long orderId; 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 getOrderId() { 18 | return orderId; 19 | } 20 | 21 | public void setOrderId(final Long orderId) { 22 | this.orderId = orderId; 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/kitchenpos/domain/OrderStatus.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.domain; 2 | 3 | public enum OrderStatus { 4 | COOKING, MEAL, COMPLETION 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/domain/OrderTable.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.domain; 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/kitchenpos/domain/Product.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.domain; 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/kitchenpos/domain/TableGroup.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.domain; 2 | 3 | import java.time.LocalDateTime; 4 | import java.util.List; 5 | 6 | public class TableGroup { 7 | private Long id; 8 | private LocalDateTime createdDate; 9 | private List orderTables; 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 LocalDateTime getCreatedDate() { 20 | return createdDate; 21 | } 22 | 23 | public void setCreatedDate(final LocalDateTime createdDate) { 24 | this.createdDate = createdDate; 25 | } 26 | 27 | public List getOrderTables() { 28 | return orderTables; 29 | } 30 | 31 | public void setOrderTables(final List orderTables) { 32 | this.orderTables = orderTables; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/ui/MenuGroupRestController.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.ui; 2 | 3 | import kitchenpos.application.MenuGroupService; 4 | import kitchenpos.domain.MenuGroup; 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 MenuGroupRestController { 16 | private final MenuGroupService menuGroupService; 17 | 18 | public MenuGroupRestController(final MenuGroupService menuGroupService) { 19 | this.menuGroupService = menuGroupService; 20 | } 21 | 22 | @PostMapping("/api/menu-groups") 23 | public ResponseEntity create(@RequestBody final MenuGroup menuGroup) { 24 | final MenuGroup created = menuGroupService.create(menuGroup); 25 | final URI uri = URI.create("/api/menu-groups/" + created.getId()); 26 | return ResponseEntity.created(uri) 27 | .body(created) 28 | ; 29 | } 30 | 31 | @GetMapping("/api/menu-groups") 32 | public ResponseEntity> list() { 33 | return ResponseEntity.ok() 34 | .body(menuGroupService.list()) 35 | ; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/ui/MenuRestController.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.ui; 2 | 3 | import kitchenpos.application.MenuService; 4 | import kitchenpos.domain.Menu; 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 MenuRestController { 16 | private final MenuService menuService; 17 | 18 | public MenuRestController(final MenuService menuService) { 19 | this.menuService = menuService; 20 | } 21 | 22 | @PostMapping("/api/menus") 23 | public ResponseEntity create(@RequestBody final Menu menu) { 24 | final Menu created = menuService.create(menu); 25 | final URI uri = URI.create("/api/menus/" + created.getId()); 26 | return ResponseEntity.created(uri) 27 | .body(created) 28 | ; 29 | } 30 | 31 | @GetMapping("/api/menus") 32 | public ResponseEntity> list() { 33 | return ResponseEntity.ok() 34 | .body(menuService.list()) 35 | ; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/ui/OrderRestController.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.ui; 2 | 3 | import kitchenpos.application.OrderService; 4 | import kitchenpos.domain.Order; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.net.URI; 9 | import java.util.List; 10 | 11 | @RestController 12 | public class OrderRestController { 13 | private final OrderService orderService; 14 | 15 | public OrderRestController(final OrderService orderService) { 16 | this.orderService = orderService; 17 | } 18 | 19 | @PostMapping("/api/orders") 20 | public ResponseEntity create(@RequestBody final Order order) { 21 | final Order created = orderService.create(order); 22 | final URI uri = URI.create("/api/orders/" + created.getId()); 23 | return ResponseEntity.created(uri) 24 | .body(created) 25 | ; 26 | } 27 | 28 | @GetMapping("/api/orders") 29 | public ResponseEntity> list() { 30 | return ResponseEntity.ok() 31 | .body(orderService.list()) 32 | ; 33 | } 34 | 35 | @PutMapping("/api/orders/{orderId}/order-status") 36 | public ResponseEntity changeOrderStatus( 37 | @PathVariable final Long orderId, 38 | @RequestBody final Order order 39 | ) { 40 | return ResponseEntity.ok(orderService.changeOrderStatus(orderId, order)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/ui/ProductRestController.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.ui; 2 | 3 | import kitchenpos.application.ProductService; 4 | import kitchenpos.domain.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 ProductService productService; 17 | 18 | public ProductRestController(final ProductService productService) { 19 | this.productService = productService; 20 | } 21 | 22 | @PostMapping("/api/products") 23 | public ResponseEntity create(@RequestBody final Product product) { 24 | final Product created = productService.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(productService.list()) 35 | ; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/ui/TableGroupRestController.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.ui; 2 | 3 | import kitchenpos.application.TableGroupService; 4 | import kitchenpos.domain.TableGroup; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.net.URI; 9 | 10 | @RestController 11 | public class TableGroupRestController { 12 | private final TableGroupService tableGroupService; 13 | 14 | public TableGroupRestController(final TableGroupService tableGroupService) { 15 | this.tableGroupService = tableGroupService; 16 | } 17 | 18 | @PostMapping("/api/table-groups") 19 | public ResponseEntity create(@RequestBody final TableGroup tableGroup) { 20 | final TableGroup created = tableGroupService.create(tableGroup); 21 | final URI uri = URI.create("/api/table-groups/" + created.getId()); 22 | return ResponseEntity.created(uri) 23 | .body(created) 24 | ; 25 | } 26 | 27 | @DeleteMapping("/api/table-groups/{tableGroupId}") 28 | public ResponseEntity ungroup(@PathVariable final Long tableGroupId) { 29 | tableGroupService.ungroup(tableGroupId); 30 | return ResponseEntity.noContent() 31 | .build() 32 | ; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/kitchenpos/ui/TableRestController.java: -------------------------------------------------------------------------------- 1 | package kitchenpos.ui; 2 | 3 | import kitchenpos.application.TableService; 4 | import kitchenpos.domain.OrderTable; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | import java.net.URI; 9 | import java.util.List; 10 | 11 | @RestController 12 | public class TableRestController { 13 | private final TableService tableService; 14 | 15 | public TableRestController(final TableService tableService) { 16 | this.tableService = tableService; 17 | } 18 | 19 | @PostMapping("/api/tables") 20 | public ResponseEntity create(@RequestBody final OrderTable orderTable) { 21 | final OrderTable created = tableService.create(orderTable); 22 | final URI uri = URI.create("/api/tables/" + created.getId()); 23 | return ResponseEntity.created(uri) 24 | .body(created) 25 | ; 26 | } 27 | 28 | @GetMapping("/api/tables") 29 | public ResponseEntity> list() { 30 | return ResponseEntity.ok() 31 | .body(tableService.list()) 32 | ; 33 | } 34 | 35 | @PutMapping("/api/tables/{orderTableId}/empty") 36 | public ResponseEntity changeEmpty( 37 | @PathVariable final Long orderTableId, 38 | @RequestBody final OrderTable orderTable 39 | ) { 40 | return ResponseEntity.ok() 41 | .body(tableService.changeEmpty(orderTableId, orderTable)) 42 | ; 43 | } 44 | 45 | @PutMapping("/api/tables/{orderTableId}/number-of-guests") 46 | public ResponseEntity changeNumberOfGuests( 47 | @PathVariable final Long orderTableId, 48 | @RequestBody final OrderTable orderTable 49 | ) { 50 | return ResponseEntity.ok() 51 | .body(tableService.changeNumberOfGuests(orderTableId, orderTable)) 52 | ; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.org.springframework.jdbc.core=TRACE 2 | spring.h2.console.enabled=true 3 | -------------------------------------------------------------------------------- /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 | order_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 (order_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 menu_product 81 | ADD CONSTRAINT fk_menu_product_product 82 | FOREIGN KEY (product_id) REFERENCES product (id); 83 | 84 | ALTER TABLE order_table 85 | ADD CONSTRAINT fk_order_table_table_group 86 | FOREIGN KEY (table_group_id) REFERENCES table_group (id); 87 | -------------------------------------------------------------------------------- /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 | 6 | INSERT INTO product (id, name, price) VALUES (1, '후라이드', 16000); 7 | INSERT INTO product (id, name, price) VALUES (2, '양념치킨', 16000); 8 | INSERT INTO product (id, name, price) VALUES (3, '반반치킨', 16000); 9 | INSERT INTO product (id, name, price) VALUES (4, '통구이', 16000); 10 | INSERT INTO product (id, name, price) VALUES (5, '간장치킨', 17000); 11 | INSERT INTO product (id, name, price) VALUES (6, '순살치킨', 17000); 12 | 13 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (1, '후라이드치킨', 16000, 2); 14 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (2, '양념치킨', 16000, 2); 15 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (3, '반반치킨', 16000, 2); 16 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (4, '통구이', 16000, 2); 17 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (5, '간장치킨', 17000, 2); 18 | INSERT INTO menu (id, name, price, menu_group_id) VALUES (6, '순살치킨', 17000, 2); 19 | 20 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (1, 1, 1); 21 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (2, 2, 1); 22 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (3, 3, 1); 23 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (4, 4, 1); 24 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (5, 5, 1); 25 | INSERT INTO menu_product (menu_id, product_id, quantity) VALUES (6, 6, 1); 26 | 27 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (1, 0, true); 28 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (2, 0, true); 29 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (3, 0, true); 30 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (4, 0, true); 31 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (5, 0, true); 32 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (6, 0, true); 33 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (7, 0, true); 34 | INSERT INTO order_table (id, number_of_guests, empty) VALUES (8, 0, true); 35 | -------------------------------------------------------------------------------- /src/main/resources/static/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step/jwp-refactoring/9b221f4de067d8a180fa0dae7ac922e5db2d9d54/src/main/resources/static/empty.txt -------------------------------------------------------------------------------- /src/main/resources/templates/empty.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/next-step/jwp-refactoring/9b221f4de067d8a180fa0dae7ac922e5db2d9d54/src/main/resources/templates/empty.txt -------------------------------------------------------------------------------- /src/test/java/kitchenpos/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package kitchenpos; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTest { 8 | @Test 9 | void contextLoads() { 10 | } 11 | } 12 | --------------------------------------------------------------------------------