diff --git a/README.md b/README.md index 416ca1d54..16c2bce62 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,15 @@ --- ## 브랜치 규칙 + ![브랜치 규칙](https://user-images.githubusercontent.com/62237639/115202663-94fcd880-a131-11eb-8708-23c7a09cc200.png) --- ## 프로젝트 관리 + ![프로젝트 관리](https://user-images.githubusercontent.com/62237639/115204101-16a13600-a133-11eb-994c-f4c8ba1d22db.png) --- ![프로젝트 진행 방식](https://user-images.githubusercontent.com/62237639/115204313-4fd9a600-a133-11eb-9e1a-13d6f06182c5.png) - - diff --git a/backend/.idea/gradle.xml b/backend/.idea/gradle.xml new file mode 100644 index 000000000..1debe0edf --- /dev/null +++ b/backend/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + diff --git a/backend/build.gradle b/backend/build.gradle new file mode 100644 index 000000000..cf9519cda --- /dev/null +++ b/backend/build.gradle @@ -0,0 +1,24 @@ +plugins { + id 'org.springframework.boot' version '2.4.5' + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'java' +} + +group = 'develop.baminchan' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '1.8' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' + implementation 'org.springframework.boot:spring-boot-starter-web' + runtimeOnly 'mysql:mysql-connector-java' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +test { + useJUnitPlatform() +} diff --git a/backend/gradle/wrapper/gradle-wrapper.jar b/backend/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..e708b1c02 Binary files /dev/null and b/backend/gradle/wrapper/gradle-wrapper.jar differ diff --git a/backend/gradle/wrapper/gradle-wrapper.properties b/backend/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..be52383ef --- /dev/null +++ b/backend/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/backend/gradlew b/backend/gradlew new file mode 100755 index 000000000..4f906e0c8 --- /dev/null +++ b/backend/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/backend/gradlew.bat b/backend/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/backend/gradlew.bat @@ -0,0 +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 diff --git a/backend/src/main/java/develop/baminchan/SidedishApplication.java b/backend/src/main/java/develop/baminchan/SidedishApplication.java new file mode 100644 index 000000000..e9379a0c9 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/SidedishApplication.java @@ -0,0 +1,12 @@ +package develop.baminchan; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SidedishApplication { + + public static void main(String[] args) { + SpringApplication.run(SidedishApplication.class, args); + } +} diff --git a/backend/src/main/java/develop/baminchan/controller/BanchanController.java b/backend/src/main/java/develop/baminchan/controller/BanchanController.java new file mode 100644 index 000000000..d5caeb3aa --- /dev/null +++ b/backend/src/main/java/develop/baminchan/controller/BanchanController.java @@ -0,0 +1,75 @@ +package develop.baminchan.controller; + +import develop.baminchan.dto.BanchanDto; +import develop.baminchan.dto.CategoryDto; +import develop.baminchan.dto.banchan.BanchanDetailDto; +import develop.baminchan.entity.Banchan; +import develop.baminchan.service.BanchanService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api") +public class BanchanController { + + private BanchanService banchanService; + + public BanchanController(BanchanService banchanService) { + this.banchanService = banchanService; + } + + @GetMapping("/main") + public ResponseEntity findMain() { + List banchanDtoList = banchanService.findBanchansByTag("main"); + Message message = new Message(Message.OK, banchanDtoList); + return new ResponseEntity(message, HttpStatus.OK); + } + + @GetMapping("/soup") + public ResponseEntity findSoup() { + List banchanDtoList = banchanService.findBanchansByTag("soup"); + Message message = new Message(Message.OK, banchanDtoList); + return new ResponseEntity(message, HttpStatus.OK); + } + + @GetMapping("/side") + public ResponseEntity findSide() { + List banchanDtoList = banchanService.findBanchansByTag("side"); + Message message = new Message(Message.OK, banchanDtoList); + return new ResponseEntity(message, HttpStatus.OK); + } + @GetMapping("/main/{detail_hash}") + public BanchanDto findOneMain(@PathVariable String detail_hash) { + BanchanDto banchanDto = banchanService.findBanchanByDetailHash(detail_hash); + return banchanDto; + } + + @GetMapping("/soup/{detail_hash}") + public BanchanDto findOneSoup(@PathVariable String detail_hash) { + BanchanDto banchanDto = banchanService.findBanchanByDetailHash(detail_hash); + return banchanDto; + } + + @GetMapping("/side/{detail_hash}") + public BanchanDto findOneSide(@PathVariable String detail_hash) { + BanchanDto banchanDto = banchanService.findBanchanByDetailHash(detail_hash); + return banchanDto; + } + + + @GetMapping("/detail/{detail_hash}") + public BanchanDetailDto findOneDetail(@PathVariable String detail_hash) { + BanchanDetailDto banchanDetailDto = banchanService.findBanchanDetailByDetailHash(detail_hash); + System.out.println(banchanDetailDto); + return banchanDetailDto; + } + + @PostMapping("/create") + public String create(@RequestBody Banchan banchan) { + banchanService.createBanchan(banchan); + return "success"; + } +} diff --git a/backend/src/main/java/develop/baminchan/controller/CategoryController.java b/backend/src/main/java/develop/baminchan/controller/CategoryController.java new file mode 100644 index 000000000..7f7934524 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/controller/CategoryController.java @@ -0,0 +1,37 @@ +package develop.baminchan.controller; + +import develop.baminchan.dto.CategoryDto; +import develop.baminchan.service.CategoryService; +import org.springframework.http.HttpStatus; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/api") +public class CategoryController { + + private CategoryService categoryService; + + public CategoryController(CategoryService categoryService) { + this.categoryService = categoryService; + } + + @GetMapping("/best") + public ResponseEntity getBest() { + List categoryDtoList = categoryService.findAllBestBanchansByCategories(); + Message message = new Message(Message.OK, categoryDtoList); + return new ResponseEntity(message, HttpStatus.OK); + } + + @GetMapping("/best/{category_id}") + public CategoryDto findBestBanchans(@PathVariable String category_id) { + CategoryDto categoryDto = categoryService.findBestBanchansByCategory(category_id); + return categoryDto; + } + +} diff --git a/backend/src/main/java/develop/baminchan/controller/Message.java b/backend/src/main/java/develop/baminchan/controller/Message.java new file mode 100644 index 000000000..a62c0a4d5 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/controller/Message.java @@ -0,0 +1,24 @@ +package develop.baminchan.controller; + +public class Message { + public static final int OK = 200; + public static final int BAD_REQUEST = 400; + public static final int NOT_FOUND = 404; + public static final int INTERNAL_SERVER_ERROR = 500; + + private int statusCode; + private Object body; + + public Message(int statusCode, Object body) { + this.statusCode = statusCode; + this.body = body; + } + + public int getStatusCode() { + return statusCode; + } + + public Object getBody() { + return body; + } +} diff --git a/backend/src/main/java/develop/baminchan/controller/OrderController.java b/backend/src/main/java/develop/baminchan/controller/OrderController.java new file mode 100644 index 000000000..53ebe8a17 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/controller/OrderController.java @@ -0,0 +1,32 @@ +package develop.baminchan.controller; + +import develop.baminchan.entity.Order; +import develop.baminchan.service.OrderService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Optional; + +@RestController +@RequestMapping("/api") +public class OrderController { + + private OrderService orderService; + + public OrderController(OrderService orderService) { + this.orderService = orderService; + } + + @GetMapping("/order/{id}") + public Optional findOrder(@PathVariable Long id) { + Optional order = orderService.findById(id); + return order; + } + + @PostMapping("/order") + public ResponseEntity createOrder(@RequestBody Order order) { + orderService.createOrder(order); + return new ResponseEntity("success", HttpStatus.OK); + } +} diff --git a/backend/src/main/java/develop/baminchan/dto/BanchanDto.java b/backend/src/main/java/develop/baminchan/dto/BanchanDto.java new file mode 100644 index 000000000..0e477ef8e --- /dev/null +++ b/backend/src/main/java/develop/baminchan/dto/BanchanDto.java @@ -0,0 +1,78 @@ +package develop.baminchan.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import develop.baminchan.entity.Banchan; + +import java.util.Set; + +import static develop.baminchan.dto.util.StringConvertor.convertToSet; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BanchanDto { + private String detail_hash; + private String image; + private String alt; + private Set delivery_type; + private String title; + private String description; + private String n_price; + private String s_price; + private Set badge; + + protected BanchanDto() { + + } + + private BanchanDto(Banchan banchan) { + this.detail_hash = banchan.getDetail_hash(); + this.image = banchan.getImage(); + this.alt = banchan.getAlt(); + this.delivery_type = convertToSet(banchan.getDelivery_type()); + this.title = banchan.getTitle(); + this.description = banchan.getDescription(); + this.n_price = banchan.getN_price(); + this.s_price = banchan.getS_price(); + this.badge = convertToSet(banchan.getBadge()); + } + + // Entity -> DTO + public static BanchanDto of(Banchan banchan) { + return new BanchanDto(banchan); + } + + public String getDetail_hash() { + return detail_hash; + } + + public String getImage() { + return image; + } + + public String getAlt() { + return alt; + } + + public Set getDelivery_type() { + return delivery_type; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public String getN_price() { + return n_price; + } + + public String getS_price() { + return s_price; + } + + public Set getBadge() { + return badge; + } +} diff --git a/backend/src/main/java/develop/baminchan/dto/CategoryDto.java b/backend/src/main/java/develop/baminchan/dto/CategoryDto.java new file mode 100644 index 000000000..dea0f1437 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/dto/CategoryDto.java @@ -0,0 +1,45 @@ +package develop.baminchan.dto; + +import develop.baminchan.entity.Category; +import org.springframework.data.annotation.Id; + +import java.util.ArrayList; +import java.util.List; + +public class CategoryDto { + @Id + private int id; + + private String category_id; + private String name; + + private List items = new ArrayList<>(); + + public CategoryDto(String category_id, String name) { + this.category_id = category_id; + this.name = name; + } + + public CategoryDto(Category category, List banchanDtoList) { + this.category_id = category.getCategory_id(); + this.name = category.getName(); + this.items = banchanDtoList; + } + + // Entity -> DTO + public static CategoryDto of(Category category, List banchanDtoList) { + return new CategoryDto(category, banchanDtoList); + } + + public String getCategory_id() { + return category_id; + } + + public String getName() { + return name; + } + + public List getItems() { + return items; + } +} diff --git a/backend/src/main/java/develop/baminchan/dto/banchan/BanchanDetailDataDto.java b/backend/src/main/java/develop/baminchan/dto/banchan/BanchanDetailDataDto.java new file mode 100644 index 000000000..42ffdd40e --- /dev/null +++ b/backend/src/main/java/develop/baminchan/dto/banchan/BanchanDetailDataDto.java @@ -0,0 +1,109 @@ +package develop.baminchan.dto.banchan; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.Set; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BanchanDetailDataDto { + + private String top_image; + private Set thumb_images; + private String product_description; + private String point; + private String delivery_info; + private String delivery_fee; + private Set prices; + + public BanchanDetailDataDto(DataDtoBuilder dataDtoBuilder) { + this.top_image = dataDtoBuilder.top_image; + this.thumb_images = dataDtoBuilder.thumb_images; + this.product_description = dataDtoBuilder.product_description; + this.point = dataDtoBuilder.point; + this.delivery_info = dataDtoBuilder.delivery_info; + this.delivery_fee = dataDtoBuilder.delivery_fee; + this.prices = dataDtoBuilder.prices; + } + + public String getTop_image() { + return top_image; + } + + public Set getThumb_images() { + return thumb_images; + } + + public String getProduct_description() { + return product_description; + } + + public String getPoint() { + return point; + } + + public String getDelivery_info() { + return delivery_info; + } + + public String getDelivery_fee() { + return delivery_fee; + } + + public Set getPrices() { + return prices; + } + + public static class DataDtoBuilder { + + private String top_image; + private Set thumb_images; + private String product_description; + private String point; + private String delivery_info; + private String delivery_fee; + private Set prices; + + DataDtoBuilder() { + + } + + public DataDtoBuilder setTop_image(String top_image) { + this.top_image = top_image; + return this; + } + + public DataDtoBuilder setThumb_images(Set thumb_images) { + this.thumb_images = thumb_images; + return this; + } + + public DataDtoBuilder setProduct_description(String product_description) { + this.product_description = product_description; + return this; + } + + public DataDtoBuilder setPoint(String point) { + this.point = point; + return this; + } + + public DataDtoBuilder setDelivery_info(String delivery_info) { + this.delivery_info = delivery_info; + return this; + } + + public DataDtoBuilder setDelivery_fee(String delivery_fee) { + this.delivery_fee = delivery_fee; + return this; + } + + public DataDtoBuilder setPrices(Set prices) { + this.prices = prices; + return this; + } + + public BanchanDetailDataDto build() { + return new BanchanDetailDataDto(this); + } + } +} diff --git a/backend/src/main/java/develop/baminchan/dto/banchan/BanchanDetailDto.java b/backend/src/main/java/develop/baminchan/dto/banchan/BanchanDetailDto.java new file mode 100644 index 000000000..8450471a5 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/dto/banchan/BanchanDetailDto.java @@ -0,0 +1,39 @@ +package develop.baminchan.dto.banchan; + +import develop.baminchan.entity.banchan.BanchanDetail; + +import static develop.baminchan.dto.util.StringConvertor.convertToSet; + +public class BanchanDetailDto { + private String hash; + private BanchanDetailDataDto data; + + public BanchanDetailDto(BanchanDetail banchanDetail) { + this.hash = banchanDetail.getDetail_hash(); + data = new BanchanDetailDataDto.DataDtoBuilder() + .setTop_image(banchanDetail.getData().getTop_image()) + .setThumb_images(convertToSet(banchanDetail.getData().getThumb_images())) + .setProduct_description(banchanDetail.getData().getProduct_description()) + .setPoint(banchanDetail.getData().getPoint()) + .setDelivery_info(banchanDetail.getData().getDelivery_info()) + .setDelivery_fee(banchanDetail.getData().getDelivery_fee()) + .setPrices(convertToSet(banchanDetail.getData().getPrices())) + .build(); + } + + public String getHash() { + return hash; + } + + public BanchanDetailDataDto getData() { + return data; + } + + @Override + public String toString() { + return "BanchanDetailDto{" + + "hash='" + hash + '\'' + + ", data=" + data + + '}'; + } +} diff --git a/backend/src/main/java/develop/baminchan/dto/util/StringConvertor.java b/backend/src/main/java/develop/baminchan/dto/util/StringConvertor.java new file mode 100644 index 000000000..48e7bc4d7 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/dto/util/StringConvertor.java @@ -0,0 +1,20 @@ +package develop.baminchan.dto.util; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class StringConvertor { + private StringConvertor() { + } + + public static Set convertToSet(String column) { + if (column == null) { + return null; + } + Set set = new HashSet<>(); + String[] arr = column.split(", "); + set.addAll(Arrays.asList(arr)); + return set; + } +} diff --git a/backend/src/main/java/develop/baminchan/entity/Banchan.java b/backend/src/main/java/develop/baminchan/entity/Banchan.java new file mode 100644 index 000000000..985a71c70 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/entity/Banchan.java @@ -0,0 +1,94 @@ +package develop.baminchan.entity; + +import develop.baminchan.entity.banchan.BanchanDetail; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Embedded; + +public class Banchan { + @Id + private Long id; + + private String detail_hash; + private String image; + private String alt; + private String delivery_type; + private String title; + private String description; + private String n_price; + private String s_price; + private String badge; + + private String tag; + private String category_id; + + @Embedded.Nullable + private BanchanDetail banchanDetail; + + public Banchan(Long id, String detail_hash, String image, String alt, String delivery_type, String title, String description, String n_price, String s_price, String badge, String tag, String category_id, BanchanDetail banchanDetail) { + this.id = id; + this.detail_hash = detail_hash; + this.image = image; + this.alt = alt; + this.delivery_type = delivery_type; + this.title = title; + this.description = description; + this.n_price = n_price; + this.s_price = s_price; + this.badge = badge; + this.tag = tag; + this.category_id = category_id; + this.banchanDetail = banchanDetail; + } + + public Long getId() { + return id; + } + + public String getDetail_hash() { + return detail_hash; + } + + public String getImage() { + return image; + } + + public String getAlt() { + return alt; + } + + public String getDelivery_type() { + return delivery_type; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public String getN_price() { + return n_price; + } + + public String getS_price() { + return s_price; + } + + public String getBadge() { + return badge; + } + + public String getTag() { + return tag; + } + + public String getCategory_id() { + return category_id; + } + + public BanchanDetail getBanchanDetail() { + return banchanDetail; + } +} diff --git a/backend/src/main/java/develop/baminchan/entity/Category.java b/backend/src/main/java/develop/baminchan/entity/Category.java new file mode 100644 index 000000000..151f94c0f --- /dev/null +++ b/backend/src/main/java/develop/baminchan/entity/Category.java @@ -0,0 +1,24 @@ +package develop.baminchan.entity; + +import org.springframework.data.annotation.Id; + +public class Category { + @Id + private int id; + + private String category_id; + private String name; + + public Category(String category_id, String name) { + this.category_id = category_id; + this.name = name; + } + + public String getCategory_id() { + return category_id; + } + + public String getName() { + return name; + } +} diff --git a/backend/src/main/java/develop/baminchan/entity/Order.java b/backend/src/main/java/develop/baminchan/entity/Order.java new file mode 100644 index 000000000..667366172 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/entity/Order.java @@ -0,0 +1,35 @@ +package develop.baminchan.entity; + +import org.springframework.data.annotation.Id; + +public class Order { + @Id + private Long id; + + private String client_id; + private String detail_hash; + private int quantity; + + public Order(Long id, String client_id, String detail_hash, int quantity) { + this.id = id; + this.client_id = client_id; + this.detail_hash = detail_hash; + this.quantity = quantity; + } + + public Long getId() { + return id; + } + + public String getClient_id() { + return client_id; + } + + public String getDetail_hash() { + return detail_hash; + } + + public int getQuantity() { + return quantity; + } +} diff --git a/backend/src/main/java/develop/baminchan/entity/banchan/BanchanDetail.java b/backend/src/main/java/develop/baminchan/entity/banchan/BanchanDetail.java new file mode 100644 index 000000000..8a6f11202 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/entity/banchan/BanchanDetail.java @@ -0,0 +1,36 @@ +package develop.baminchan.entity.banchan; + +import org.springframework.data.relational.core.mapping.Embedded; + +public class BanchanDetail { + private String detail_hash; + + @Embedded.Nullable + private BanchanDetailData banchanDetailData; + + public BanchanDetail(String detail_hash, BanchanDetailData banchanDetailData) { + this.detail_hash = detail_hash; + this.banchanDetailData = banchanDetailData; + } + + public String getDetail_hash() { + return detail_hash; + } + + public BanchanDetailData getBanchanDetailData() { + return banchanDetailData; + } + + public BanchanDetailData getData() { + return banchanDetailData; + } + + @Override + public String toString() { + return "BanchanDetail{" + + "detail_hash='" + detail_hash + '\'' + + ", banchanDetailData=" + banchanDetailData + + '}'; + } +} + diff --git a/backend/src/main/java/develop/baminchan/entity/banchan/BanchanDetailData.java b/backend/src/main/java/develop/baminchan/entity/banchan/BanchanDetailData.java new file mode 100644 index 000000000..fe01605aa --- /dev/null +++ b/backend/src/main/java/develop/baminchan/entity/banchan/BanchanDetailData.java @@ -0,0 +1,66 @@ +package develop.baminchan.entity.banchan; + +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BanchanDetailData { + + private String top_image; + private String thumb_images; + private String product_description; + private String point; + private String delivery_info; + private String delivery_fee; + private String prices; + + public BanchanDetailData(String top_image, String thumb_images, String product_description, String point, String delivery_info, String delivery_fee, String prices) { + this.top_image = top_image; + this.thumb_images = thumb_images; + this.product_description = product_description; + this.point = point; + this.delivery_info = delivery_info; + this.delivery_fee = delivery_fee; + this.prices = prices; + } + + public String getTop_image() { + return top_image; + } + + public String getThumb_images() { + return thumb_images; + } + + public String getProduct_description() { + return product_description; + } + + public String getPoint() { + return point; + } + + public String getDelivery_info() { + return delivery_info; + } + + public String getDelivery_fee() { + return delivery_fee; + } + + public String getPrices() { + return prices; + } + + @Override + public String toString() { + return "BanchanDetailData{" + + "top_image='" + top_image + '\'' + + ", thumb_images='" + thumb_images + '\'' + + ", product_description='" + product_description + '\'' + + ", point='" + point + '\'' + + ", delivery_info='" + delivery_info + '\'' + + ", delivery_fee='" + delivery_fee + '\'' + + ", prices='" + prices + '\'' + + '}'; + } +} diff --git a/backend/src/main/java/develop/baminchan/repository/BanchanRepository.java b/backend/src/main/java/develop/baminchan/repository/BanchanRepository.java new file mode 100644 index 000000000..25fb56e8a --- /dev/null +++ b/backend/src/main/java/develop/baminchan/repository/BanchanRepository.java @@ -0,0 +1,18 @@ +package develop.baminchan.repository; + +import develop.baminchan.entity.Banchan; +import org.springframework.data.jdbc.repository.query.Query; +import org.springframework.data.repository.CrudRepository; + +import java.util.List; + +public interface BanchanRepository extends CrudRepository { + @Query("select * from banchan where detail_hash = :detail_hash") + Banchan findBanchanByDetail_hash(String detail_hash); + + @Query("select * from banchan where category_id = :category_id") + List findBanchansByCategory_id(String category_id); + + @Query("select * from banchan where tag = :tag") + List findBanchansbyTag(String tag); +} diff --git a/backend/src/main/java/develop/baminchan/repository/CategoryRepository.java b/backend/src/main/java/develop/baminchan/repository/CategoryRepository.java new file mode 100644 index 000000000..3df51aae9 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/repository/CategoryRepository.java @@ -0,0 +1,10 @@ +package develop.baminchan.repository; + +import develop.baminchan.entity.Category; +import org.springframework.data.jdbc.repository.query.Query; +import org.springframework.data.repository.CrudRepository; + +public interface CategoryRepository extends CrudRepository { + @Query("select * from category where category_id = :category_id") + Category findCategoryByCategory_id(String category_id); +} diff --git a/backend/src/main/java/develop/baminchan/repository/OrderRepository.java b/backend/src/main/java/develop/baminchan/repository/OrderRepository.java new file mode 100644 index 000000000..3431f6d2b --- /dev/null +++ b/backend/src/main/java/develop/baminchan/repository/OrderRepository.java @@ -0,0 +1,7 @@ +package develop.baminchan.repository; + +import develop.baminchan.entity.Order; +import org.springframework.data.repository.CrudRepository; + +public interface OrderRepository extends CrudRepository { +} diff --git a/backend/src/main/java/develop/baminchan/service/BanchanService.java b/backend/src/main/java/develop/baminchan/service/BanchanService.java new file mode 100644 index 000000000..773f0c43b --- /dev/null +++ b/backend/src/main/java/develop/baminchan/service/BanchanService.java @@ -0,0 +1,49 @@ +package develop.baminchan.service; + +import develop.baminchan.dto.BanchanDto; +import develop.baminchan.dto.banchan.BanchanDetailDto; +import develop.baminchan.entity.Banchan; +import develop.baminchan.repository.BanchanRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class BanchanService { + + private BanchanRepository banchanRepository; + + public BanchanService(BanchanRepository banchanRepository) { + this.banchanRepository = banchanRepository; + } + + public BanchanDto findBanchanByDetailHash(String detail_hash) { + Banchan banchan = banchanRepository.findBanchanByDetail_hash(detail_hash); + BanchanDto banchanDto = BanchanDto.of(banchan); + return banchanDto; + } + + @Transactional + public void createBanchan(Banchan banchan) { + banchanRepository.save(banchan); + } + + public BanchanDetailDto findBanchanDetailByDetailHash(String detail_hash) { + Banchan banchan = banchanRepository.findBanchanByDetail_hash(detail_hash); + System.out.println(banchan); + BanchanDetailDto banchanDetailDto = new BanchanDetailDto(banchan.getBanchanDetail()); + return banchanDetailDto; + } + + public List findBanchansByTag(String tag) { + List banchanList = banchanRepository.findBanchansbyTag(tag); + + List banchanDtoList = new ArrayList<>(); + for (int i = 0; i < banchanList.size(); i++) { + banchanDtoList.add(BanchanDto.of(banchanList.get(i))); + } + return banchanDtoList; + } +} diff --git a/backend/src/main/java/develop/baminchan/service/CategoryService.java b/backend/src/main/java/develop/baminchan/service/CategoryService.java new file mode 100644 index 000000000..db404596a --- /dev/null +++ b/backend/src/main/java/develop/baminchan/service/CategoryService.java @@ -0,0 +1,57 @@ +package develop.baminchan.service; + +import develop.baminchan.dto.BanchanDto; +import develop.baminchan.dto.CategoryDto; +import develop.baminchan.entity.Banchan; +import develop.baminchan.entity.Category; +import develop.baminchan.repository.BanchanRepository; +import develop.baminchan.repository.CategoryRepository; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Service +public class CategoryService { + private CategoryRepository categoryRepository; + private BanchanRepository banchanRepository; + + public CategoryService(CategoryRepository categoryRepository, BanchanRepository banchanRepository) { + this.categoryRepository = categoryRepository; + this.banchanRepository = banchanRepository; + } + + public List findAllBestBanchansByCategories() { + Iterable categoryList = categoryRepository.findAll(); + Set setOfCategoryIds = new HashSet<>(); + for (Category category : categoryList) { + setOfCategoryIds.add(category.getCategory_id()); + } + System.out.println(setOfCategoryIds); //테스트 // null도 들어가나? + + List categoryDtoList = new ArrayList<>(); + for (String category_id : setOfCategoryIds) { + categoryDtoList.add(findBestBanchansByCategory(category_id)); + } + return categoryDtoList; + } + + public CategoryDto findBestBanchansByCategory(String category_id) { + Category category = categoryRepository.findCategoryByCategory_id(category_id); + CategoryDto categoryDto = CategoryDto.of(category, findBanchanListByCategoryId(category_id)); + return categoryDto; + } + + private List findBanchanListByCategoryId(String catrgory_id) { + List banchanDtoList = new ArrayList<>(); + List banchanList = new ArrayList<>(); + + banchanList = banchanRepository.findBanchansByCategory_id(catrgory_id); + for (int i = 0; i < banchanList.size(); i++) { + banchanDtoList.add(BanchanDto.of(banchanList.get(i))); + } + return banchanDtoList; + } +} diff --git a/backend/src/main/java/develop/baminchan/service/OrderService.java b/backend/src/main/java/develop/baminchan/service/OrderService.java new file mode 100644 index 000000000..ac339b7d6 --- /dev/null +++ b/backend/src/main/java/develop/baminchan/service/OrderService.java @@ -0,0 +1,26 @@ +package develop.baminchan.service; + +import develop.baminchan.entity.Order; +import develop.baminchan.repository.OrderRepository; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@Service +public class OrderService { + + private OrderRepository orderRepository; + + public OrderService(OrderRepository orderRepository) { + this.orderRepository = orderRepository; + } + + public Order createOrder(Order order) { + return orderRepository.save(order); + } + + public Optional findById(Long id) { + Optional order = orderRepository.findById(id); + return order; + } +} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties new file mode 100644 index 000000000..8db293f31 --- /dev/null +++ b/backend/src/main/resources/application.properties @@ -0,0 +1,6 @@ +logging.level.sql=DEBUG + +spring.datasource.url=jdbc:mysql://localhost:3306/sidedish?autoReconnect=true&useUnicode=true&characterEncoding=UTF8 +spring.datasource.username=root +spring.datasource.password=1234 +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/backend/src/test/java/develop/baminchan/SidedishApplicationTests.java b/backend/src/test/java/develop/baminchan/SidedishApplicationTests.java new file mode 100644 index 000000000..6657655ac --- /dev/null +++ b/backend/src/test/java/develop/baminchan/SidedishApplicationTests.java @@ -0,0 +1,7 @@ +package develop.baminchan; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SidedishApplicationTests { +}