Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE][Team09][Bat & Pyro] API 를 JDBC 와 연동 #59

Open
wants to merge 28 commits into
base: ghojeong
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f1ae674
feat: JDBC연동 - category class
kjk402 Apr 26, 2021
cb11c76
Merge pull request #44 from ghojeong/feature/be/jdbc
Apr 26, 2021
f307e56
feat: Add category test code
kjk402 Apr 26, 2021
01cdef4
[test] Softl Assertion 적용
Apr 26, 2021
6650342
Merge pull request #47 from ghojeong/feature/be/jdbc
Apr 26, 2021
f8654db
feat: JDBC 연동 도메인, 데이터베이스 데이터 삽입
kjk402 Apr 26, 2021
5de75e1
feat: dish table currentDateTime 컬럼추가
kjk402 Apr 27, 2021
42f75af
feat: image, sale, delivery에 set으로 매핑 추가
kjk402 Apr 27, 2021
9061ab7
Merge branch 'backend-develop' into feature/be/jdbc
Apr 28, 2021
71719dd
Merge pull request #49 from ghojeong/feature/be/jdbc
Apr 28, 2021
f41a420
feat: create DTO
kjk402 Apr 28, 2021
9d33a4e
[fix] 빌드가 실패하는 버그를 수정함
Apr 28, 2021
59f8f50
Merge pull request #56 from ghojeong/feature/be/jdbc
Apr 28, 2021
2371a00
feat: h2 에 맞추어 properties 와 schema 작성
Apr 29, 2021
2d4c4c0
feat: Spring profile 설정; prod & dev
Apr 29, 2021
a544477
feat: findAll 이 동작하지 않던 문제 해결
Apr 29, 2021
a779680
refactor: Query 를 통해 dish 목록을 가져오도록 수정
Apr 29, 2021
4172f10
feat: dishDetail 에서 이미지 목록이 나오도록 함
Apr 29, 2021
f3d5fb3
feat: dish 목록에서 delivery 타입과, badges 가 나오도록 함
Apr 29, 2021
de90a33
Merge pull request #58 from ghojeong/feature/be/profile
Apr 29, 2021
07e69c4
feat: 주문하기 기능 구현
kjk402 Apr 30, 2021
997048b
feat: post -> patch 매핑으로 변경
kjk402 Apr 30, 2021
95c6ff6
Merge pull request #59 from ghojeong/feature/be/order
Apr 30, 2021
8452983
feat: JDBC Template 으로 N + 1 문제 해결
Apr 30, 2021
96d1d2e
Merge pull request #60 from ghojeong/feature/be/nplus1
kjk402 Apr 30, 2021
7719658
Merge pull request #61 from ghojeong/backend-develop
Apr 30, 2021
4db8370
feat: pstm 으로 SQL Injection 해킹 방지
May 2, 2021
c2f0380
Merge branch 'backend-develop' into backend
May 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

build
.gradle
.gradle/**/*

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
Expand Down
Binary file modified backend/.gradle/6.8.3/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified backend/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
4 changes: 2 additions & 2 deletions backend/.gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Tue Apr 20 01:45:16 KST 2021
gradle.version=6.8.3
#Thu Apr 29 14:48:25 KST 2021
gradle.version=7.0
Binary file modified backend/.gradle/checksums/checksums.lock
Binary file not shown.
10 changes: 10 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@
## API 배포 링크

http://3.37.26.82:8080/swagger-ui.html

## 로컬 IntelliJ 로 실행하는 법

Edit Configurations 에서 Active profile 을 "dev" 혹은 "prod" 로 설정하자

## 빌드한 jar 를 실행하는 법

```sh
java -jar SideDish-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev
```
2 changes: 2 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

runtimeOnly 'mysql:mysql-connector-java'
runtimeOnly 'com.h2database:h2'

// swagger
implementation 'io.springfox:springfox-swagger2:2.9.2'
Expand Down
2 changes: 1 addition & 1 deletion backend/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Empty file modified backend/gradlew
100644 → 100755
Empty file.
178 changes: 89 additions & 89 deletions backend/gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;

// FIXME: DB 연동을 무효화하기 위해서 임시로 exclude 함, 나중에 수정할 예정
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class})
@SpringBootApplication
public class SideDishApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand Down Expand Up @@ -53,24 +50,34 @@ public ResponseEntity<QuantityDto> getDetailQuantity(@ApiParam("요리의 식별
return ResponseEntity.ok().body(quantityDto);
}

@PatchMapping("/detail/{detailHash}/{count}")
@ApiOperation(value = "주문하기", notes = "주문하기")
public ResponseEntity<String> orderDish(@ApiParam("요리의 식별자") @PathVariable("detailHash") String detailHash, @PathVariable("count") int count) {
if (dishService.order(detailHash, count)) {
return ResponseEntity.ok().body("주문완료");
}
return ResponseEntity.ok().body("주문불가");
Comment on lines +56 to +59
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dishService.order() 의 리턴 타입이 스트링이었으면 코드가 조금 더 간결해졌겠네요.
같은 메소드를 소비하는 다른 소비처가 있나요? 그리고 그곳이 boolean 타입 리턴을 필요로 하나요?
그렇지 않다면, 서비스에서 바로 스트링을 내리는 구현도 좋을 것 같습니다.

다만 지금은 주문의 상태에 관한, 그러니까 경우의 수 를 다루는 메소드이므로 enum 을 사용하기에 아주 적절한 상황으로 보입니다.

public enum OrderResult {

    ORDER_SUCCESSFUL("주문완료"),
    ORDER_NOT_MADE("주문불가")

...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다만 지금은 주문의 상태에 관한, 그러니까 경우의 수 를 다루는 메소드이므로 enum 을 사용하기에 아주 적절한 상황으로 보입니다.

enum 을 더 적극적으로 사용해보도록 하겠습니다!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum 생각을 하지 못하고 개발하였습니다....
image 구분할 때도 enum으로 했으면 더 좋았을 것 같습니다.
감사합니다.

}

@GetMapping("/main")
@ApiOperation(value = "메인 요리", notes = "메인 요리의 목록을 반환합니다.")
public ResponseEntity<List<DishDto>> getMainList() {
List<DishDto> dishes = dishService.getList(1);
List<DishDto> dishes = dishService.getList(1L);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1L, 2L 은 상수로 관리돼야 할 것 같군요.

Copy link
Collaborator Author

@ghojeong ghojeong May 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 enum 으로 main 과 1L 상수를 하나로 묶는게 좋겠군요.
생각없이 막코딩한 밑천이 다 드러나네요...

return ResponseEntity.ok().body(dishes);
}

@GetMapping("/soup")
@ApiOperation(value = "국물 요리", notes = "국물 요리의 목록을 반환합니다.")
public ResponseEntity<List<DishDto>> getSoupList() {
List<DishDto> dishes = dishService.getList(2L);
return ResponseEntity.ok().body(dishes);
}

@GetMapping("/side")
@ApiOperation(value = "반찬 요리", notes = "반찬 요리의 목록을 반환합니다.")
public ResponseEntity<List<DishDto>> getSideList() {
List<DishDto> dishes = dishService.getList(3);
List<DishDto> dishes = dishService.getList(3L);
return ResponseEntity.ok().body(dishes);
}

@GetMapping("/soup")
@ApiOperation(value = "국물 요리", notes = "국물 요리의 목록을 반환합니다.")
public ResponseEntity<List<DishDto>> getSoupList() {
List<DishDto> dishes = dishService.getList(2);
return ResponseEntity.ok().body(dishes);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.codesquad.sidedish.SideDish.domain;

import org.springframework.data.annotation.Id;

public class Category {
private final long id;
@Id
private final Long id;
private final String categoryName;
private final String endPoint;

public Category(long id, String categoryName, String endPoint) {
public Category(Long id, String categoryName, String endPoint) {
this.id = id;
this.categoryName = categoryName;
this.endPoint = endPoint;
Expand All @@ -22,4 +25,13 @@ public String getCategoryName() {
public String getEndPoint() {
return endPoint;
}

@Override
public String toString() {
return "Category{" +
"id=" + id +
", categoryName='" + categoryName + '\'' +
", endPoint='" + endPoint + '\'' +
'}';
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.codesquad.sidedish.SideDish.domain;

import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface CategoryRepository {
public interface CategoryRepository extends CrudRepository<Category, Long> {
@Override
@Query("SELECT * from sidedish.category")
List<Category> findAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.codesquad.sidedish.SideDish.domain;

import java.util.Objects;

public class Delivery {
private String deliveryType;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type 이라면... 문자열 필드보단 더 좋은 방법이 있지 않을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type 이라면, enum 으로 만들어서 관리하는 편이 훨씬 좋겠군요.
지적해주셔서 감사합니다.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'deliveryType',' imageType' 그리고 sale에서 'Badge' 모두 enum으로 관리하면 더 좋았을 것 같습니다.
감사합니다.^^


public Delivery(String deliveryType) {
this.deliveryType = deliveryType;
}

public String getDeliveryType() {
return deliveryType;
}


@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Delivery delivery = (Delivery) o;
return Objects.equals(deliveryType, delivery.deliveryType);
}

@Override
public int hashCode() {
return Objects.hash(deliveryType);
}
}
Loading