From 672bef5a5964900da37a474c34e71c452d063457 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 01:32:01 +0900 Subject: [PATCH 01/32] chore: initial setting --- .gitignore | 68 +++++ hackathon/.gitignore | 37 +++ hackathon/build.gradle | 32 +++ hackathon/docker-compose.yml | 18 ++ .../gradle/wrapper/gradle-wrapper.properties | 5 + hackathon/gradlew | 240 ++++++++++++++++++ hackathon/gradlew.bat | 91 +++++++ hackathon/settings.gradle | 1 + .../hackathon/HackathonApplication.java | 13 + hackathon/src/main/resources/application.yml | 18 ++ .../hackathon/HackathonApplicationTests.java | 13 + 11 files changed, 536 insertions(+) create mode 100644 .gitignore create mode 100644 hackathon/.gitignore create mode 100644 hackathon/build.gradle create mode 100644 hackathon/docker-compose.yml create mode 100644 hackathon/gradle/wrapper/gradle-wrapper.properties create mode 100755 hackathon/gradlew create mode 100644 hackathon/gradlew.bat create mode 100644 hackathon/settings.gradle create mode 100644 hackathon/src/main/java/com/techeer/hackathon/HackathonApplication.java create mode 100644 hackathon/src/main/resources/application.yml create mode 100644 hackathon/src/test/java/com/techeer/hackathon/HackathonApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0c2d1e48 --- /dev/null +++ b/.gitignore @@ -0,0 +1,68 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# ------------- spring ------------- +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac ### +.DS_Store + +.env + +gradle.properties \ No newline at end of file diff --git a/hackathon/.gitignore b/hackathon/.gitignore new file mode 100644 index 00000000..c2065bc2 --- /dev/null +++ b/hackathon/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/hackathon/build.gradle b/hackathon/build.gradle new file mode 100644 index 00000000..25c04cc2 --- /dev/null +++ b/hackathon/build.gradle @@ -0,0 +1,32 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '2.7.9' + id 'io.spring.dependency-management' version '1.0.15.RELEASE' +} + +group = 'com.techeer' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '11' + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.mysql:mysql-connector-j' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/hackathon/docker-compose.yml b/hackathon/docker-compose.yml new file mode 100644 index 00000000..a6f3823c --- /dev/null +++ b/hackathon/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3' + +volumes: + db-data: + +services: + mysql: + container_name: mysql + image: mysql:latest + expose: + - "3306" + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + ports: + - "3306:3306" + volumes: + - db-data:/msql \ No newline at end of file diff --git a/hackathon/gradle/wrapper/gradle-wrapper.properties b/hackathon/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..070cb702 --- /dev/null +++ b/hackathon/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/hackathon/gradlew b/hackathon/gradlew new file mode 100755 index 00000000..a69d9cb6 --- /dev/null +++ b/hackathon/gradlew @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original 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 POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${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 "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# 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 ;; #( + MSYS* | 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" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/hackathon/gradlew.bat b/hackathon/gradlew.bat new file mode 100644 index 00000000..f127cfd4 --- /dev/null +++ b/hackathon/gradlew.bat @@ -0,0 +1,91 @@ +@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% equ 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% equ 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! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/hackathon/settings.gradle b/hackathon/settings.gradle new file mode 100644 index 00000000..d6cc5f66 --- /dev/null +++ b/hackathon/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'hackathon' diff --git a/hackathon/src/main/java/com/techeer/hackathon/HackathonApplication.java b/hackathon/src/main/java/com/techeer/hackathon/HackathonApplication.java new file mode 100644 index 00000000..26dc8ef3 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/HackathonApplication.java @@ -0,0 +1,13 @@ +package com.techeer.hackathon; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HackathonApplication { + + public static void main(String[] args) { + SpringApplication.run(HackathonApplication.class, args); + } + +} diff --git a/hackathon/src/main/resources/application.yml b/hackathon/src/main/resources/application.yml new file mode 100644 index 00000000..f1f0d7b3 --- /dev/null +++ b/hackathon/src/main/resources/application.yml @@ -0,0 +1,18 @@ +spring: + application: + name: hackathon + jpa: + database: "mysql" + show-sql: "true" + hibernate: + ddl-auto: "update" + properties: + hibernate: + format_sql: true + generate-ddl: true + + datasource: + driver-class-name: "com.mysql.cj.jdbc.Driver" + url: "jdbc:mysql://localhost:3306/hackathon" + username: "root" + password: "0000" \ No newline at end of file diff --git a/hackathon/src/test/java/com/techeer/hackathon/HackathonApplicationTests.java b/hackathon/src/test/java/com/techeer/hackathon/HackathonApplicationTests.java new file mode 100644 index 00000000..9cabab03 --- /dev/null +++ b/hackathon/src/test/java/com/techeer/hackathon/HackathonApplicationTests.java @@ -0,0 +1,13 @@ +package com.techeer.hackathon; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class HackathonApplicationTests { + + @Test + void contextLoads() { + } + +} From 83a8127af06d8aa3377100dde6ca9dfe56338251 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 02:52:40 +0900 Subject: [PATCH 02/32] =?UTF-8?q?feat:=20JpaAuditingConfig=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hackathon/global/config/JpaAuditingConfig.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/global/config/JpaAuditingConfig.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/config/JpaAuditingConfig.java b/hackathon/src/main/java/com/techeer/hackathon/global/config/JpaAuditingConfig.java new file mode 100644 index 00000000..5114d22f --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/global/config/JpaAuditingConfig.java @@ -0,0 +1,8 @@ +package com.techeer.hackathon.global.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@Configuration +@EnableJpaAuditing +public class JpaAuditingConfig {} From 3d2a7a55b82795b0a3ff7241ca6803e5b3e6fa62 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 02:53:06 +0900 Subject: [PATCH 03/32] =?UTF-8?q?feat:=20=EB=A0=88=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=9E=91=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20Enum=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restaurant/entity/RestaurantCategory.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java new file mode 100644 index 00000000..53362952 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java @@ -0,0 +1,14 @@ +package com.techeer.hackathon.domain.restaurant.entity; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum RestaurantCategory { + KOREAN_RESTAURANT("한식"), + CHINESE_RESTAURANT("중식"), + JAPANESE_RESTAURANT("일식"); + + private final String category; +} From 5b9e898392c1cb64bce64c4f4ee12c9a647b5821 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 02:53:22 +0900 Subject: [PATCH 04/32] =?UTF-8?q?feat:=20=EB=A0=88=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=9E=91=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/restaurant/entity/Restaurant.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/Restaurant.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/Restaurant.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/Restaurant.java new file mode 100644 index 00000000..c5d0218e --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/Restaurant.java @@ -0,0 +1,55 @@ +package com.techeer.hackathon.domain.restaurant.entity; + +import com.techeer.hackathon.domain.review.entity.Review; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.DynamicInsert; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@Table(name = "RESTAURANT") +@DynamicInsert +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@EntityListeners(AuditingEntityListener.class) +public class Restaurant { + @Id + private Long id; + + // Review 와 1:N 관계 + @OneToMany(mappedBy = "restaurant", cascade = CascadeType.ALL, orphanRemoval = true) + private List reviews = new ArrayList<>(); + + @Column(nullable = false, length = 30) + private String name; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private RestaurantCategory category; + + @Column(nullable = false, columnDefinition = "boolean default false") + private Boolean isDeleted; + + @CreatedDate + private LocalDateTime createdAt; + + @Builder + public Restaurant( + String name, + RestaurantCategory category) { + this.name = name; + this.category = category; + } + + public void deleteRestaurant() { + this.isDeleted = true; + } +} From 24404f94cd00891aee633734a71398cf481ba28d Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 02:53:29 +0900 Subject: [PATCH 05/32] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B7=B0=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/review/entity/Review.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/review/entity/Review.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/entity/Review.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/entity/Review.java new file mode 100644 index 00000000..f9b3ec95 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/entity/Review.java @@ -0,0 +1,46 @@ +package com.techeer.hackathon.domain.review.entity; + +import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.time.LocalDateTime; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "REVIEW") +@EntityListeners(AuditingEntityListener.class) +public class Review { + @Id + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "restaurant_id", nullable = false) + private Restaurant restaurant; + + @Column(nullable = false) + private String title; + + @Column(nullable = false) + private String content; + + @CreatedDate + private LocalDateTime createdAt; + + @Builder + public Review( + Restaurant restaurant, + String title, + String content + ) { + this.restaurant = restaurant; + this.title = title; + this.content = content; + } +} From 2f0e84b2c9d6ad18a751c26bb6b0be8fd580dece Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 03:51:04 +0900 Subject: [PATCH 06/32] =?UTF-8?q?chore:=20swagger=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hackathon/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/hackathon/build.gradle b/hackathon/build.gradle index 25c04cc2..b8353fe5 100644 --- a/hackathon/build.gradle +++ b/hackathon/build.gradle @@ -21,6 +21,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' From 32946e615a4bac7afb99e04dc0029e8619046507 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 03:56:35 +0900 Subject: [PATCH 07/32] =?UTF-8?q?feat:=20API=EC=9D=91=EB=8B=B5=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/result/ResultResponse.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/global/result/ResultResponse.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultResponse.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultResponse.java new file mode 100644 index 00000000..254dd1f2 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultResponse.java @@ -0,0 +1,25 @@ +package com.techeer.hackathon.global.result; + +import lombok.Getter; + +@Getter +public class ResultResponse { + + private String code; + private String message; + private Object data; + + public static ResultResponse of(ResultCode resultCode, Object data) { + return new ResultResponse(resultCode, data); + } + + public static ResultResponse of(ResultCode resultCode) { + return new ResultResponse(resultCode, ""); + } + + public ResultResponse(ResultCode resultCode, Object data) { + this.code = resultCode.getCode(); + this.message = resultCode.getMessage(); + this.data = data; + } +} From 0f8bd55b0e5b97cd39b11adaeee8e934b1d8288b Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:06:55 +0900 Subject: [PATCH 08/32] =?UTF-8?q?feat:=20API=20=EC=9D=91=EB=8B=B5=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EA=B4=80=EB=A6=AC=ED=95=98=EB=8A=94=20Enu?= =?UTF-8?q?m=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hackathon/global/result/ResultCode.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java new file mode 100644 index 00000000..56099b79 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java @@ -0,0 +1,15 @@ +package com.techeer.hackathon.global.result; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ResultCode { + + EXAMPLE_RESULT_CODE("EXAM1", "예시용"), + RESTAURANT_CREATE_SUCCESS("R001", "레스토랑 생성 성공"); + + private final String code; + private final String message; +} From 880849c5b591cfcb1104053e5e08342370d68449 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:07:31 +0900 Subject: [PATCH 09/32] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EA=B4=80=EB=A6=AC=ED=95=98=EB=8A=94=20Enu?= =?UTF-8?q?m=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hackathon/global/error/ErrorCode.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java new file mode 100644 index 00000000..45df5671 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java @@ -0,0 +1,20 @@ +package com.techeer.hackathon.global.error; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ErrorCode { + // Global + INTERNAL_SERVER_ERROR(500, "G001", "서버 오류"), + INPUT_INVALID_VALUE(409, "G002", "잘못된 입력"), + + // Restaurant + RESTAURANT_DUPLICATION_ERROR(409, "R001", "레스토랑 이름이 중복됩니다."); + + private final int status; + private final String code; + private final String message; +} + From 20d27a02c0964131bed28719b4aaab1139d3869d Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:08:29 +0900 Subject: [PATCH 10/32] =?UTF-8?q?feat:=20=EB=B9=84=EC=A6=88=EB=8B=88?= =?UTF-8?q?=EC=8A=A4=20=EC=97=90=EB=9F=AC=EB=93=A4=EC=9D=98=20=EB=B6=80?= =?UTF-8?q?=EB=AA=A8=20=EA=B0=9D=EC=B2=B4=EC=9D=B8=20BusinessException=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/error/exceptions/BusinessException.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/global/error/exceptions/BusinessException.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/error/exceptions/BusinessException.java b/hackathon/src/main/java/com/techeer/hackathon/global/error/exceptions/BusinessException.java new file mode 100644 index 00000000..d77f08ba --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/global/error/exceptions/BusinessException.java @@ -0,0 +1,14 @@ +package com.techeer.hackathon.global.error.exceptions; + +import com.techeer.hackathon.global.error.ErrorCode; +import lombok.Getter; + +@Getter +public class BusinessException extends RuntimeException { + private final ErrorCode errorCode; + + public BusinessException(ErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } +} From 1984621c9e751bf953466b7677010d7133d5d23a Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:10:41 +0900 Subject: [PATCH 11/32] =?UTF-8?q?feat:=20API=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=8B=9C=20=EC=9D=91=EB=8B=B5=20=EA=B0=9D=EC=B2=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hackathon/global/error/ErrorResponse.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorResponse.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorResponse.java b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorResponse.java new file mode 100644 index 00000000..4ac725da --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorResponse.java @@ -0,0 +1,62 @@ +package com.techeer.hackathon.global.error; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import org.springframework.validation.BindingResult; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +@Builder +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class ErrorResponse { + private String businessCode; + private String errorMessage; + private List errors; + + private ErrorResponse(ErrorCode code, List fieldErrors) { + this.businessCode = code.getCode(); + this.errorMessage = code.getMessage(); + this.errors = fieldErrors; + } + + private ErrorResponse(ErrorCode code) { + this.businessCode = code.getCode(); + this.errorMessage = code.getMessage(); + this.errors = new ArrayList<>(); + } + + public static ErrorResponse of(final ErrorCode code, final BindingResult bindingResult) { + return new ErrorResponse(code, FieldError.of(bindingResult)); + } + + public static ErrorResponse of(ErrorCode code) { + return new ErrorResponse(code); + } + + @Getter + @AllArgsConstructor + public static class FieldError { + private String field; + private String value; + private String reason; + + private static List of(final BindingResult bindingResult) { + final List fieldErrors = + bindingResult.getFieldErrors(); + return fieldErrors.stream() + .map( + error -> + new FieldError( + error.getField(), + error.getRejectedValue() == null ? "" : error.getRejectedValue().toString(), + error.getDefaultMessage())) + .collect(Collectors.toList()); + } + } +} + From e2b79ff32f175d283230a547f1ce4dd6209c4390 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:11:00 +0900 Subject: [PATCH 12/32] =?UTF-8?q?feat:=20GlobalExceptionHandler=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/error/GlobalExceptionHandler.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/global/error/GlobalExceptionHandler.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/error/GlobalExceptionHandler.java b/hackathon/src/main/java/com/techeer/hackathon/global/error/GlobalExceptionHandler.java new file mode 100644 index 00000000..b4fd57af --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/global/error/GlobalExceptionHandler.java @@ -0,0 +1,43 @@ +package com.techeer.hackathon.global.error; + +import com.techeer.hackathon.global.error.exceptions.BusinessException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import static com.techeer.hackathon.global.error.ErrorCode.INPUT_INVALID_VALUE; + +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(Exception.class) + protected ResponseEntity handleException(Exception e) { + log.error(e.getMessage(), e); + ErrorResponse response = ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR); + return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler + protected ResponseEntity handleRuntimeException(BusinessException e) { + final ErrorCode errorCode = e.getErrorCode(); + final ErrorResponse response = + ErrorResponse.builder() + .errorMessage(errorCode.getMessage()) + .businessCode(errorCode.getCode()) + .build(); + log.warn(e.getMessage()); + return ResponseEntity.status(errorCode.getStatus()).body(response); + } + + @ExceptionHandler + protected ResponseEntity handleMethodArgumentNotValidException( + MethodArgumentNotValidException e) { + final ErrorResponse response = ErrorResponse.of(INPUT_INVALID_VALUE, e.getBindingResult()); + log.warn(e.getMessage()); + return ResponseEntity.status(INPUT_INVALID_VALUE.getStatus()).body(response); + } +} From 656bd1cc9cb7cddbead096bcb48e811a6ba73951 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:11:10 +0900 Subject: [PATCH 13/32] =?UTF-8?q?feat:=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/config/SwaggerConfig.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/global/config/SwaggerConfig.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/config/SwaggerConfig.java b/hackathon/src/main/java/com/techeer/hackathon/global/config/SwaggerConfig.java new file mode 100644 index 00000000..3c18e761 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/global/config/SwaggerConfig.java @@ -0,0 +1,49 @@ +package com.techeer.hackathon.global.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +import java.util.HashSet; +import java.util.Set; + +@Configuration +@EnableWebMvc +public class SwaggerConfig { + + private ApiInfo swaggerInfo() { + return new ApiInfoBuilder().title("Hackathon API").description("Hackathon API Docs").build(); + } + + @Bean + public Docket swaggerApi() { + return new Docket(DocumentationType.SWAGGER_2) + .consumes(getConsumeContentTypes()) + .produces(getProduceContentTypes()) + .apiInfo(swaggerInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage("com.techeer.hackathon")) + .paths(PathSelectors.any()) + .build() + .useDefaultResponseMessages(false); + } + + private Set getConsumeContentTypes() { + Set consumes = new HashSet<>(); + consumes.add("application/json;charset=UTF-8"); + consumes.add("application/x-www-form-urlencoded"); + return consumes; + } + + private Set getProduceContentTypes() { + Set produces = new HashSet<>(); + produces.add("application/json;charset=UTF-8"); + return produces; + } +} From 838fa3f55ca505d0071ecebde67b11b6a42d4229 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:12:19 +0900 Subject: [PATCH 14/32] =?UTF-8?q?fix:=20isDeleted=20nullable=20true?= =?UTF-8?q?=EB=A1=9C=20=EC=84=A4=EC=A0=95,=20=EA=B8=B0=EB=B3=B8=ED=82=A4?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=EC=A0=84=EB=9E=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../techeer/hackathon/domain/restaurant/entity/Restaurant.java | 3 ++- .../com/techeer/hackathon/domain/review/entity/Review.java | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/Restaurant.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/Restaurant.java index c5d0218e..2318e83a 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/Restaurant.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/Restaurant.java @@ -22,6 +22,7 @@ @EntityListeners(AuditingEntityListener.class) public class Restaurant { @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id; // Review 와 1:N 관계 @@ -35,7 +36,7 @@ public class Restaurant { @Column(nullable = false) private RestaurantCategory category; - @Column(nullable = false, columnDefinition = "boolean default false") + @Column(columnDefinition = "boolean default false") private Boolean isDeleted; @CreatedDate diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/entity/Review.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/entity/Review.java index f9b3ec95..ba7f3722 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/entity/Review.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/entity/Review.java @@ -18,6 +18,7 @@ @EntityListeners(AuditingEntityListener.class) public class Review { @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id; @ManyToOne(fetch = FetchType.LAZY) From ea67e15cae23273f7748e1ce82a4d66b30951764 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:12:58 +0900 Subject: [PATCH 15/32] =?UTF-8?q?feat:=20=EB=A0=88=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=9E=91,=20=EB=A6=AC=EB=B7=B0=20Repository=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restaurant/repository/RestaurantRepository.java | 8 ++++++++ .../domain/review/repository/ReviewRepository.java | 7 +++++++ 2 files changed, 15 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/review/repository/ReviewRepository.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java new file mode 100644 index 00000000..fe41583c --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java @@ -0,0 +1,8 @@ +package com.techeer.hackathon.domain.restaurant.repository; + +import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RestaurantRepository extends JpaRepository { + boolean existsByName(String name); +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/repository/ReviewRepository.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/repository/ReviewRepository.java new file mode 100644 index 00000000..eab3fe20 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/repository/ReviewRepository.java @@ -0,0 +1,7 @@ +package com.techeer.hackathon.domain.review.repository; + +import com.techeer.hackathon.domain.review.entity.Review; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReviewRepository extends JpaRepository { +} From d9aa2f69c2fddbd12b3171cd91807d9403710203 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:13:34 +0900 Subject: [PATCH 16/32] =?UTF-8?q?feat:=20=EB=A0=88=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=9E=91=20=EC=A4=91=EB=B3=B5=20=EC=8B=9C=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=A0=20=EC=98=88=EC=99=B8=20=EA=B0=9D=EC=B2=B4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restaurant/error/RestaurantDuplicateException.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/RestaurantDuplicateException.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/RestaurantDuplicateException.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/RestaurantDuplicateException.java new file mode 100644 index 00000000..2b673c8f --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/RestaurantDuplicateException.java @@ -0,0 +1,10 @@ +package com.techeer.hackathon.domain.restaurant.error; + +import com.techeer.hackathon.global.error.ErrorCode; +import com.techeer.hackathon.global.error.exceptions.BusinessException; + +public class RestaurantDuplicateException extends BusinessException { + public RestaurantDuplicateException() { + super(ErrorCode.RESTAURANT_DUPLICATION_ERROR); + } +} From 44769e374e5bfd0bce66666ffdb57b40b2ee4f22 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:13:59 +0900 Subject: [PATCH 17/32] =?UTF-8?q?feat:=20=EB=A0=88=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=9E=91=20=EC=83=9D=EC=84=B1=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RestaurantController.java | 28 +++++++++++++++++++ .../restaurant/service/RestaurantService.java | 21 ++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java new file mode 100644 index 00000000..44d6f829 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java @@ -0,0 +1,28 @@ +package com.techeer.hackathon.domain.restaurant.controller; + +import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import com.techeer.hackathon.domain.restaurant.service.RestaurantService; +import com.techeer.hackathon.global.result.ResultCode; +import com.techeer.hackathon.global.result.ResultResponse; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("api/v1/restaurant") +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class RestaurantController { + + private final RestaurantService restaurantService; + + @PostMapping + public ResponseEntity registerRestaurant( + @RequestBody Restaurant restaurant) { + restaurantService.createRestaurant(restaurant); + return ResponseEntity.ok(ResultResponse.of(ResultCode.RESTAURANT_CREATE_SUCCESS)); + } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java new file mode 100644 index 00000000..4e928d49 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java @@ -0,0 +1,21 @@ +package com.techeer.hackathon.domain.restaurant.service; + +import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import com.techeer.hackathon.domain.restaurant.error.RestaurantDuplicateException; +import com.techeer.hackathon.domain.restaurant.repository.RestaurantRepository; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class RestaurantService { + private final RestaurantRepository restaurantRepository; + + public void createRestaurant(Restaurant restaurant) { + if(restaurantRepository.existsByName(restaurant.getName())) { + throw new RestaurantDuplicateException(); + } + restaurantRepository.save(restaurant); + } +} From 28f87268bf4a872ab87c3321c4df04a551c11419 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:32:31 +0900 Subject: [PATCH 18/32] =?UTF-8?q?feat:=20=EB=A0=88=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=9E=91=20=EC=83=9D=EC=84=B1=EC=8B=9C=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=A0=20DTO=EC=99=80=20Mapper=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/restaurant/RestaurantMapper.java | 15 +++++++++++++++ .../domain/restaurant/dto/RestaurantCreate.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/RestaurantMapper.java create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantCreate.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/RestaurantMapper.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/RestaurantMapper.java new file mode 100644 index 00000000..4466e29a --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/RestaurantMapper.java @@ -0,0 +1,15 @@ +package com.techeer.hackathon.domain.restaurant; + +import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; +import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import org.springframework.stereotype.Component; + +@Component +public class RestaurantMapper { + public Restaurant toEntity(RestaurantCreate request) { + return Restaurant.builder() + .category(request.getCategory()) + .name(request.getName()) + .build(); + } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantCreate.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantCreate.java new file mode 100644 index 00000000..5702c62f --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantCreate.java @@ -0,0 +1,15 @@ +package com.techeer.hackathon.domain.restaurant.dto; + +import com.techeer.hackathon.domain.restaurant.entity.RestaurantCategory; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class RestaurantCreate { + private RestaurantCategory category; + private String name; +} From eb37396602e2bb02efe0654acd908ad16e09a75c Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 04:33:45 +0900 Subject: [PATCH 19/32] =?UTF-8?q?fix:=20=EB=A0=88=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=9E=91=20=EC=83=9D=EC=84=B1=20API=EB=A5=BC=20DTO=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restaurant/controller/RestaurantController.java | 6 +++--- .../domain/restaurant/service/RestaurantService.java | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java index 44d6f829..2745b019 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java @@ -1,6 +1,6 @@ package com.techeer.hackathon.domain.restaurant.controller; -import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; import com.techeer.hackathon.domain.restaurant.service.RestaurantService; import com.techeer.hackathon.global.result.ResultCode; import com.techeer.hackathon.global.result.ResultResponse; @@ -21,8 +21,8 @@ public class RestaurantController { @PostMapping public ResponseEntity registerRestaurant( - @RequestBody Restaurant restaurant) { - restaurantService.createRestaurant(restaurant); + @RequestBody RestaurantCreate request) { + restaurantService.createRestaurant(request); return ResponseEntity.ok(ResultResponse.of(ResultCode.RESTAURANT_CREATE_SUCCESS)); } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java index 4e928d49..48ea50c9 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java @@ -1,6 +1,7 @@ package com.techeer.hackathon.domain.restaurant.service; -import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import com.techeer.hackathon.domain.restaurant.RestaurantMapper; +import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; import com.techeer.hackathon.domain.restaurant.error.RestaurantDuplicateException; import com.techeer.hackathon.domain.restaurant.repository.RestaurantRepository; import lombok.AccessLevel; @@ -11,11 +12,12 @@ @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public class RestaurantService { private final RestaurantRepository restaurantRepository; + private final RestaurantMapper restaurantMapper; - public void createRestaurant(Restaurant restaurant) { - if(restaurantRepository.existsByName(restaurant.getName())) { + public void createRestaurant(RestaurantCreate restaurantCreate) { + if(restaurantRepository.existsByName(restaurantCreate.getName())) { throw new RestaurantDuplicateException(); } - restaurantRepository.save(restaurant); + restaurantRepository.save(restaurantMapper.toEntity(restaurantCreate)); } } From 7dd9429739ec4e2053f5d391950205d893310895 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 07:01:12 +0900 Subject: [PATCH 20/32] =?UTF-8?q?feat:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=EB=A1=9C=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=EC=8B=9C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/restaurant/dto/RestaurantCreate.java | 9 +++++++++ .../domain/restaurant/entity/RestaurantCategory.java | 7 +++++++ .../restaurant/error/InvalidCategoryException.java | 11 +++++++++++ .../domain/restaurant/service/RestaurantService.java | 4 ++++ .../com/techeer/hackathon/global/error/ErrorCode.java | 3 ++- 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/InvalidCategoryException.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantCreate.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantCreate.java index 5702c62f..898a2a08 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantCreate.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantCreate.java @@ -1,5 +1,7 @@ package com.techeer.hackathon.domain.restaurant.dto; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; import com.techeer.hackathon.domain.restaurant.entity.RestaurantCategory; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -12,4 +14,11 @@ public class RestaurantCreate { private RestaurantCategory category; private String name; + + @JsonCreator + public RestaurantCreate(@JsonProperty("name") String name, @JsonProperty("category") String category) { + this.name = name; + if(!RestaurantCategory.isValidCategory(category.toUpperCase())) this.category = null; + else this.category = RestaurantCategory.valueOf(category.toUpperCase()); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java index 53362952..5e18d8f7 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java @@ -11,4 +11,11 @@ public enum RestaurantCategory { JAPANESE_RESTAURANT("일식"); private final String category; + + public static Boolean isValidCategory(String category) { + for (RestaurantCategory cat : RestaurantCategory.values()) { + if(!cat.category.equals(category)) return false; + } + return true; + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/InvalidCategoryException.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/InvalidCategoryException.java new file mode 100644 index 00000000..f1f88188 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/InvalidCategoryException.java @@ -0,0 +1,11 @@ +package com.techeer.hackathon.domain.restaurant.error; + +import com.techeer.hackathon.global.error.exceptions.BusinessException; + +import static com.techeer.hackathon.global.error.ErrorCode.INVALID_CATEGORY_ERROR; + +public class InvalidCategoryException extends BusinessException { + public InvalidCategoryException() { + super(INVALID_CATEGORY_ERROR); + } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java index 48ea50c9..d268219a 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java @@ -2,6 +2,7 @@ import com.techeer.hackathon.domain.restaurant.RestaurantMapper; import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; +import com.techeer.hackathon.domain.restaurant.error.InvalidCategoryException; import com.techeer.hackathon.domain.restaurant.error.RestaurantDuplicateException; import com.techeer.hackathon.domain.restaurant.repository.RestaurantRepository; import lombok.AccessLevel; @@ -18,6 +19,9 @@ public void createRestaurant(RestaurantCreate restaurantCreate) { if(restaurantRepository.existsByName(restaurantCreate.getName())) { throw new RestaurantDuplicateException(); } + if(restaurantCreate.getCategory() == null) { + throw new InvalidCategoryException(); + } restaurantRepository.save(restaurantMapper.toEntity(restaurantCreate)); } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java index 45df5671..9b80464b 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java @@ -11,7 +11,8 @@ public enum ErrorCode { INPUT_INVALID_VALUE(409, "G002", "잘못된 입력"), // Restaurant - RESTAURANT_DUPLICATION_ERROR(409, "R001", "레스토랑 이름이 중복됩니다."); + RESTAURANT_DUPLICATION_ERROR(409, "R001", "레스토랑 이름이 중복됩니다."), + INVALID_CATEGORY_ERROR(400, "R002", "잘못된 카테고리 이름입니다."); private final int status; private final String code; From 509224eb27a153172182fc95fe2f2c31671ea11b Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 07:21:56 +0900 Subject: [PATCH 21/32] =?UTF-8?q?fix:=20isValid=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/restaurant/entity/RestaurantCategory.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java index 5e18d8f7..e3c86f34 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java @@ -13,9 +13,11 @@ public enum RestaurantCategory { private final String category; public static Boolean isValidCategory(String category) { + System.out.println(category); for (RestaurantCategory cat : RestaurantCategory.values()) { - if(!cat.category.equals(category)) return false; + System.out.println(cat.getCategory()); + if(cat.getCategory().equals(category)) return true; } - return true; + return false; } } From 5ad384be7f75ce740ed489269bd12a9c802394b8 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 07:33:27 +0900 Subject: [PATCH 22/32] =?UTF-8?q?fix:=20=EC=98=A4=EB=A5=98=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hackathon/domain/restaurant/entity/RestaurantCategory.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java index e3c86f34..e1de43fa 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java @@ -13,10 +13,9 @@ public enum RestaurantCategory { private final String category; public static Boolean isValidCategory(String category) { - System.out.println(category); for (RestaurantCategory cat : RestaurantCategory.values()) { System.out.println(cat.getCategory()); - if(cat.getCategory().equals(category)) return true; + if(cat.toString().equals(category)) return true; } return false; } From e012b13422c6ae044074f80af89411929da74452 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 07:55:05 +0900 Subject: [PATCH 23/32] =?UTF-8?q?feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EB=B3=80=EA=B2=BD=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RestaurantController.java | 13 ++++++---- .../restaurant/dto/RestaurantChange.java | 24 +++++++++++++++++++ .../repository/RestaurantRepository.java | 10 ++++++++ .../restaurant/service/RestaurantService.java | 8 +++++++ .../hackathon/global/result/ResultCode.java | 3 ++- 5 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantChange.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java index 2745b019..89219662 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java @@ -1,5 +1,6 @@ package com.techeer.hackathon.domain.restaurant.controller; +import com.techeer.hackathon.domain.restaurant.dto.RestaurantChange; import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; import com.techeer.hackathon.domain.restaurant.service.RestaurantService; import com.techeer.hackathon.global.result.ResultCode; @@ -7,10 +8,7 @@ import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("api/v1/restaurant") @@ -25,4 +23,11 @@ public ResponseEntity registerRestaurant( restaurantService.createRestaurant(request); return ResponseEntity.ok(ResultResponse.of(ResultCode.RESTAURANT_CREATE_SUCCESS)); } + + @PatchMapping + public ResponseEntity changeRestaurantCategory( + @RequestBody RestaurantChange request) { + restaurantService.changeCategory(request); + return ResponseEntity.ok(ResultResponse.of(ResultCode.CHANGE_CATEGORY_SUCCESS)); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantChange.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantChange.java new file mode 100644 index 00000000..8e016dcc --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantChange.java @@ -0,0 +1,24 @@ +package com.techeer.hackathon.domain.restaurant.dto; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.techeer.hackathon.domain.restaurant.entity.RestaurantCategory; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class RestaurantChange { + private Long id; + private RestaurantCategory category; + + @JsonCreator + public RestaurantChange(@JsonProperty("id") Long id, @JsonProperty("category") String category) { + this.id = id; + if(!RestaurantCategory.isValidCategory(category.toUpperCase())) this.category = null; + else this.category = RestaurantCategory.valueOf(category.toUpperCase()); + } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java index fe41583c..c0daf347 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java @@ -1,8 +1,18 @@ package com.techeer.hackathon.domain.restaurant.repository; import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import com.techeer.hackathon.domain.restaurant.entity.RestaurantCategory; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.transaction.annotation.Transactional; public interface RestaurantRepository extends JpaRepository { boolean existsByName(String name); + + @Modifying + @Transactional + @Query("update Restaurant r set r.category = :category where r.id = :id") + void updateCategory(@Param("id") Long id, @Param("category") RestaurantCategory category); } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java index d268219a..230974ba 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java @@ -1,6 +1,7 @@ package com.techeer.hackathon.domain.restaurant.service; import com.techeer.hackathon.domain.restaurant.RestaurantMapper; +import com.techeer.hackathon.domain.restaurant.dto.RestaurantChange; import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; import com.techeer.hackathon.domain.restaurant.error.InvalidCategoryException; import com.techeer.hackathon.domain.restaurant.error.RestaurantDuplicateException; @@ -24,4 +25,11 @@ public void createRestaurant(RestaurantCreate restaurantCreate) { } restaurantRepository.save(restaurantMapper.toEntity(restaurantCreate)); } + + public void changeCategory(RestaurantChange request) { + if(request.getCategory() == null) { + throw new InvalidCategoryException(); + } + restaurantRepository.updateCategory(request.getId(), request.getCategory()); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java index 56099b79..a6887aba 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java @@ -8,7 +8,8 @@ public enum ResultCode { EXAMPLE_RESULT_CODE("EXAM1", "예시용"), - RESTAURANT_CREATE_SUCCESS("R001", "레스토랑 생성 성공"); + RESTAURANT_CREATE_SUCCESS("R001", "레스토랑 생성 성공"), + CHANGE_CATEGORY_SUCCESS("R002", "카테고리 변경 성공"); private final String code; private final String message; From 5502c53d3a3bcad97540fcc94ea6c60f219b56a4 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 08:53:11 +0900 Subject: [PATCH 24/32] =?UTF-8?q?feat:=20=EC=8B=9D=EB=8B=B9=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=EB=B3=84=20=EC=A1=B0=ED=9A=8C=20API?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/restaurant/RestaurantMapper.java | 15 --------- .../controller/RestaurantController.java | 11 +++++++ .../restaurant/dto/RestaurantResponse.java | 18 +++++++++++ .../restaurant/entity/RestaurantCategory.java | 8 +++++ .../restaurant/mapper/RestaurantMapper.java | 32 +++++++++++++++++++ .../repository/RestaurantRepository.java | 5 +++ .../restaurant/service/RestaurantService.java | 21 +++++++++++- .../hackathon/global/result/ResultCode.java | 3 +- 8 files changed, 96 insertions(+), 17 deletions(-) delete mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/RestaurantMapper.java create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantResponse.java create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/mapper/RestaurantMapper.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/RestaurantMapper.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/RestaurantMapper.java deleted file mode 100644 index 4466e29a..00000000 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/RestaurantMapper.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.techeer.hackathon.domain.restaurant; - -import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; -import com.techeer.hackathon.domain.restaurant.entity.Restaurant; -import org.springframework.stereotype.Component; - -@Component -public class RestaurantMapper { - public Restaurant toEntity(RestaurantCreate request) { - return Restaurant.builder() - .category(request.getCategory()) - .name(request.getName()) - .build(); - } -} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java index 89219662..13d9d914 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java @@ -2,6 +2,7 @@ import com.techeer.hackathon.domain.restaurant.dto.RestaurantChange; import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; +import com.techeer.hackathon.domain.restaurant.dto.RestaurantResponse; import com.techeer.hackathon.domain.restaurant.service.RestaurantService; import com.techeer.hackathon.global.result.ResultCode; import com.techeer.hackathon.global.result.ResultResponse; @@ -10,6 +11,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequestMapping("api/v1/restaurant") @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @@ -30,4 +33,12 @@ public ResponseEntity changeRestaurantCategory( restaurantService.changeCategory(request); return ResponseEntity.ok(ResultResponse.of(ResultCode.CHANGE_CATEGORY_SUCCESS)); } + + @GetMapping("/all") + public ResponseEntity getAllRestaurantByCategories( + @RequestParam String categories) { + List restaurants = restaurantService.getRestaurantResponse(categories); + + return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_RESTAURANTS_SUCCESS, restaurants)); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantResponse.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantResponse.java new file mode 100644 index 00000000..4d0b0232 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/dto/RestaurantResponse.java @@ -0,0 +1,18 @@ +package com.techeer.hackathon.domain.restaurant.dto; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class RestaurantResponse { + String name; + String category; + LocalDateTime createdAt; +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java index e1de43fa..7db43106 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/entity/RestaurantCategory.java @@ -19,4 +19,12 @@ public static Boolean isValidCategory(String category) { } return false; } + + public static RestaurantCategory getCategory(String category) { + for (RestaurantCategory cat : RestaurantCategory.values()) { + System.out.println(cat.getCategory()); + if(cat.toString().equals(category)) return cat; + } + return null; + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/mapper/RestaurantMapper.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/mapper/RestaurantMapper.java new file mode 100644 index 00000000..9488fb3d --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/mapper/RestaurantMapper.java @@ -0,0 +1,32 @@ +package com.techeer.hackathon.domain.restaurant.mapper; + +import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; +import com.techeer.hackathon.domain.restaurant.dto.RestaurantResponse; +import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.stream.Collectors; + +@Component +public class RestaurantMapper { + public Restaurant toEntity(RestaurantCreate request) { + return Restaurant.builder() + .category(request.getCategory()) + .name(request.getName()) + .build(); + } + + public RestaurantResponse toDto(Restaurant restaurant) { + + return RestaurantResponse.builder() + .category(restaurant.getCategory().name()) + .name(restaurant.getName()) + .createdAt(restaurant.getCreatedAt()) + .build(); + } + + public List toDtoList(List list) { + return list.stream().map(this::toDto).collect(Collectors.toList()); + } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java index c0daf347..275072c6 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java @@ -8,6 +8,8 @@ import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + public interface RestaurantRepository extends JpaRepository { boolean existsByName(String name); @@ -15,4 +17,7 @@ public interface RestaurantRepository extends JpaRepository { @Transactional @Query("update Restaurant r set r.category = :category where r.id = :id") void updateCategory(@Param("id") Long id, @Param("category") RestaurantCategory category); + + @Query("SELECT r FROM Restaurant r WHERE r.category IN :categories") + List findByCategory(@Param("categories") List categories); } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java index 230974ba..007ba013 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java @@ -1,8 +1,11 @@ package com.techeer.hackathon.domain.restaurant.service; -import com.techeer.hackathon.domain.restaurant.RestaurantMapper; +import com.techeer.hackathon.domain.restaurant.mapper.RestaurantMapper; import com.techeer.hackathon.domain.restaurant.dto.RestaurantChange; import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; +import com.techeer.hackathon.domain.restaurant.dto.RestaurantResponse; +import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import com.techeer.hackathon.domain.restaurant.entity.RestaurantCategory; import com.techeer.hackathon.domain.restaurant.error.InvalidCategoryException; import com.techeer.hackathon.domain.restaurant.error.RestaurantDuplicateException; import com.techeer.hackathon.domain.restaurant.repository.RestaurantRepository; @@ -10,6 +13,9 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + @Service @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public class RestaurantService { @@ -32,4 +38,17 @@ public void changeCategory(RestaurantChange request) { } restaurantRepository.updateCategory(request.getId(), request.getCategory()); } + + public List getRestaurantResponse(String categories) { + String[] categoryArray = categories.split(","); + List categoriesList = new ArrayList<>(); + for (String category : categoryArray) { + if(RestaurantCategory.isValidCategory(category)) { + categoriesList.add(RestaurantCategory.getCategory(category)); + } + else throw new InvalidCategoryException(); + } + List restaurants = restaurantRepository.findByCategory(categoriesList); + return restaurantMapper.toDtoList(restaurants); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java index a6887aba..4f2574da 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java @@ -9,7 +9,8 @@ public enum ResultCode { EXAMPLE_RESULT_CODE("EXAM1", "예시용"), RESTAURANT_CREATE_SUCCESS("R001", "레스토랑 생성 성공"), - CHANGE_CATEGORY_SUCCESS("R002", "카테고리 변경 성공"); + CHANGE_CATEGORY_SUCCESS("R002", "카테고리 변경 성공"), + GET_RESTAURANTS_SUCCESS("R003", "전체 카테고리 조회 성공"); private final String code; private final String message; From 1da23ec6127cb0c5517fd1888b6bfbec8ce154cc Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 09:14:04 +0900 Subject: [PATCH 25/32] =?UTF-8?q?feat:=20=EB=A0=88=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=9E=91=20softdelete=20API=20=EA=B5=AC=ED=98=84=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/restaurant/controller/RestaurantController.java | 7 +++++++ .../domain/restaurant/repository/RestaurantRepository.java | 5 +++++ .../domain/restaurant/service/RestaurantService.java | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java index 13d9d914..b81569e7 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java @@ -41,4 +41,11 @@ public ResponseEntity getAllRestaurantByCategories( return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_RESTAURANTS_SUCCESS, restaurants)); } + + @PatchMapping("/{id}") + public ResponseEntity deleteRestaurant( + @PathVariable Long id) { + restaurantService.deleteRestaurant(id); + return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_RESTAURANTS_SUCCESS)); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java index 275072c6..53f30331 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java @@ -20,4 +20,9 @@ public interface RestaurantRepository extends JpaRepository { @Query("SELECT r FROM Restaurant r WHERE r.category IN :categories") List findByCategory(@Param("categories") List categories); + + @Modifying + @Transactional + @Query("update Restaurant r set r.isDeleted = 1 where r.id = :id") + void softDeleteById(Long id); } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java index 007ba013..32ec561c 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java @@ -51,4 +51,8 @@ public List getRestaurantResponse(String categories) { List restaurants = restaurantRepository.findByCategory(categoriesList); return restaurantMapper.toDtoList(restaurants); } + + public void deleteRestaurant(Long id) { + restaurantRepository.softDeleteById(id); + } } From 989df2eabbc2ed56dfc705d36a611dfc97e8b7b9 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 09:22:41 +0900 Subject: [PATCH 26/32] =?UTF-8?q?feat:=20=EC=8B=9D=EB=8B=B9=20id=EB=A1=9C?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restaurant/controller/RestaurantController.java | 10 ++++++++-- .../restaurant/error/RestaurantNotFoundException.java | 11 +++++++++++ .../domain/restaurant/service/RestaurantService.java | 5 +++++ .../com/techeer/hackathon/global/error/ErrorCode.java | 3 ++- .../techeer/hackathon/global/result/ResultCode.java | 5 +++-- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/RestaurantNotFoundException.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java index b81569e7..b58a1e13 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/controller/RestaurantController.java @@ -39,13 +39,19 @@ public ResponseEntity getAllRestaurantByCategories( @RequestParam String categories) { List restaurants = restaurantService.getRestaurantResponse(categories); - return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_RESTAURANTS_SUCCESS, restaurants)); + return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_ALL_RESTAURANTS_SUCCESS, restaurants)); } @PatchMapping("/{id}") public ResponseEntity deleteRestaurant( @PathVariable Long id) { restaurantService.deleteRestaurant(id); - return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_RESTAURANTS_SUCCESS)); + return ResponseEntity.ok(ResultResponse.of(ResultCode.DELETE_RESTAURANTS_SUCCESS)); + } + + @GetMapping("/{id}") + public ResponseEntity getRestaurant( + @PathVariable Long id) { + return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_RESTAURANTS_SUCCESS, restaurantService.getRestaurant(id))); } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/RestaurantNotFoundException.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/RestaurantNotFoundException.java new file mode 100644 index 00000000..36755e5b --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/error/RestaurantNotFoundException.java @@ -0,0 +1,11 @@ +package com.techeer.hackathon.domain.restaurant.error; + +import com.techeer.hackathon.global.error.exceptions.BusinessException; + +import static com.techeer.hackathon.global.error.ErrorCode.RESTAURANT_NOT_FOUND; + +public class RestaurantNotFoundException extends BusinessException { + public RestaurantNotFoundException() { + super(RESTAURANT_NOT_FOUND); + } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java index 32ec561c..7391d6d8 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/service/RestaurantService.java @@ -1,5 +1,6 @@ package com.techeer.hackathon.domain.restaurant.service; +import com.techeer.hackathon.domain.restaurant.error.RestaurantNotFoundException; import com.techeer.hackathon.domain.restaurant.mapper.RestaurantMapper; import com.techeer.hackathon.domain.restaurant.dto.RestaurantChange; import com.techeer.hackathon.domain.restaurant.dto.RestaurantCreate; @@ -55,4 +56,8 @@ public List getRestaurantResponse(String categories) { public void deleteRestaurant(Long id) { restaurantRepository.softDeleteById(id); } + + public RestaurantResponse getRestaurant(Long id) { + return restaurantMapper.toDto(restaurantRepository.findById(id).orElseThrow(RestaurantNotFoundException::new)); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java index 9b80464b..ea8e452a 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java @@ -12,7 +12,8 @@ public enum ErrorCode { // Restaurant RESTAURANT_DUPLICATION_ERROR(409, "R001", "레스토랑 이름이 중복됩니다."), - INVALID_CATEGORY_ERROR(400, "R002", "잘못된 카테고리 이름입니다."); + INVALID_CATEGORY_ERROR(400, "R002", "잘못된 카테고리 이름입니다."), + RESTAURANT_NOT_FOUND(404, "R003", "식당을 찾을 수 없습니다."); private final int status; private final String code; diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java index 4f2574da..35675e2e 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java @@ -7,10 +7,11 @@ @AllArgsConstructor public enum ResultCode { - EXAMPLE_RESULT_CODE("EXAM1", "예시용"), RESTAURANT_CREATE_SUCCESS("R001", "레스토랑 생성 성공"), CHANGE_CATEGORY_SUCCESS("R002", "카테고리 변경 성공"), - GET_RESTAURANTS_SUCCESS("R003", "전체 카테고리 조회 성공"); + GET_ALL_RESTAURANTS_SUCCESS("R003", "전체 카테고리 조회 성공"), + DELETE_RESTAURANTS_SUCCESS("R004", "레스토랑 삭제 성공"), + GET_RESTAURANTS_SUCCESS("R005", "카테고리 조회 성공"); private final String code; private final String message; From cc87cd7f6dccd5ea8e1d8363ae49da5b48847ded Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 09:42:08 +0900 Subject: [PATCH 27/32] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B7=B0=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/RestaurantRepository.java | 3 ++ .../review/controller/ReviewController.java | 28 +++++++++++++++++ .../domain/review/dto/ReviewCreate.java | 13 ++++++++ .../domain/review/mapper/ReviewMapper.java | 30 +++++++++++++++++++ .../domain/review/service/ReviewService.java | 24 +++++++++++++++ .../hackathon/global/result/ResultCode.java | 4 ++- 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewCreate.java create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java index 53f30331..bcc70980 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/restaurant/repository/RestaurantRepository.java @@ -9,6 +9,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Optional; public interface RestaurantRepository extends JpaRepository { boolean existsByName(String name); @@ -25,4 +26,6 @@ public interface RestaurantRepository extends JpaRepository { @Transactional @Query("update Restaurant r set r.isDeleted = 1 where r.id = :id") void softDeleteById(Long id); + + Optional findByName(String restaurantName); } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java new file mode 100644 index 00000000..d615c6f3 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java @@ -0,0 +1,28 @@ +package com.techeer.hackathon.domain.review.controller; + +import com.techeer.hackathon.domain.review.dto.ReviewCreate; +import com.techeer.hackathon.domain.review.service.ReviewService; +import com.techeer.hackathon.global.result.ResultCode; +import com.techeer.hackathon.global.result.ResultResponse; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("api/v1/review") +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class ReviewController { + private final ReviewService reviewService; + + @PostMapping + public ResponseEntity createReview( + @RequestBody ReviewCreate request + ) { + reviewService.createReview(request); + return ResponseEntity.ok(ResultResponse.of(ResultCode.REVIEW_CREATE_SUCCESS)); + } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewCreate.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewCreate.java new file mode 100644 index 00000000..9f58a368 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewCreate.java @@ -0,0 +1,13 @@ +package com.techeer.hackathon.domain.review.dto; + +import lombok.*; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ReviewCreate { + private String restaurantName; + private String title; + private String content; +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java new file mode 100644 index 00000000..4d0c0c13 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java @@ -0,0 +1,30 @@ +package com.techeer.hackathon.domain.review.mapper; + +import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import com.techeer.hackathon.domain.review.dto.ReviewCreate; +import com.techeer.hackathon.domain.review.entity.Review; +import org.springframework.stereotype.Component; + +@Component +public class ReviewMapper { + public Review toEntity(ReviewCreate request, Restaurant restaurant) { + return Review.builder() + .restaurant(restaurant) + .content(request.getContent()) + .title(request.getTitle()) + .build(); + } + +// public RestaurantResponse toDto(Restaurant restaurant) { +// +// return RestaurantResponse.builder() +// .category(restaurant.getCategory().name()) +// .name(restaurant.getName()) +// .createdAt(restaurant.getCreatedAt()) +// .build(); +// } +// +// public List toDtoList(List list) { +// return list.stream().map(this::toDto).collect(Collectors.toList()); +// } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java new file mode 100644 index 00000000..2bb2f52d --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java @@ -0,0 +1,24 @@ +package com.techeer.hackathon.domain.review.service; + +import com.techeer.hackathon.domain.restaurant.entity.Restaurant; +import com.techeer.hackathon.domain.restaurant.error.RestaurantNotFoundException; +import com.techeer.hackathon.domain.restaurant.repository.RestaurantRepository; +import com.techeer.hackathon.domain.review.dto.ReviewCreate; +import com.techeer.hackathon.domain.review.mapper.ReviewMapper; +import com.techeer.hackathon.domain.review.repository.ReviewRepository; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public class ReviewService { + private final ReviewRepository reviewRepository; + private final RestaurantRepository restaurantRepository; + private final ReviewMapper reviewMapper; + + public void createReview(ReviewCreate request) { + Restaurant restaurant = restaurantRepository.findByName(request.getRestaurantName()).orElseThrow(RestaurantNotFoundException::new); + reviewRepository.save(reviewMapper.toEntity(request, restaurant)); + } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java index 35675e2e..6944dd8e 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java @@ -11,7 +11,9 @@ public enum ResultCode { CHANGE_CATEGORY_SUCCESS("R002", "카테고리 변경 성공"), GET_ALL_RESTAURANTS_SUCCESS("R003", "전체 카테고리 조회 성공"), DELETE_RESTAURANTS_SUCCESS("R004", "레스토랑 삭제 성공"), - GET_RESTAURANTS_SUCCESS("R005", "카테고리 조회 성공"); + GET_RESTAURANTS_SUCCESS("R005", "카테고리 조회 성공"), + + REVIEW_CREATE_SUCCESS("V001", "리뷰 등록 성공"); private final String code; private final String message; From f7091b62f41e4078b21ffa842dd678a3e8ba9346 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 09:57:09 +0900 Subject: [PATCH 28/32] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B7=B0=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/review/controller/ReviewController.java | 11 +++++++---- .../hackathon/domain/review/dto/ReviewInfo.java | 13 +++++++++++++ .../review/exception/ReviewNotFoundException.java | 10 ++++++++++ .../domain/review/mapper/ReviewMapper.java | 9 +++++++++ .../domain/review/service/ReviewService.java | 8 ++++++++ .../techeer/hackathon/global/error/ErrorCode.java | 4 +++- .../techeer/hackathon/global/result/ResultCode.java | 3 ++- 7 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewInfo.java create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/review/exception/ReviewNotFoundException.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java index d615c6f3..fc013cd7 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java @@ -7,10 +7,7 @@ import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("api/v1/review") @@ -25,4 +22,10 @@ public ResponseEntity createReview( reviewService.createReview(request); return ResponseEntity.ok(ResultResponse.of(ResultCode.REVIEW_CREATE_SUCCESS)); } + + @GetMapping("/{id}") + public ResponseEntity getReview( + @PathVariable Long id) { + return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_REVIEW_SUCCESS, reviewService.getReview(id))); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewInfo.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewInfo.java new file mode 100644 index 00000000..a15b3149 --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewInfo.java @@ -0,0 +1,13 @@ +package com.techeer.hackathon.domain.review.dto; + +import lombok.*; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ReviewInfo { + private String restaurantName; + private String title; + private String content; +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/exception/ReviewNotFoundException.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/exception/ReviewNotFoundException.java new file mode 100644 index 00000000..3c8bfdbd --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/exception/ReviewNotFoundException.java @@ -0,0 +1,10 @@ +package com.techeer.hackathon.domain.review.exception; + +import com.techeer.hackathon.global.error.ErrorCode; +import com.techeer.hackathon.global.error.exceptions.BusinessException; + +public class ReviewNotFoundException extends BusinessException { + public ReviewNotFoundException() { + super(ErrorCode.REVIEW_NOT_FOUND); + } +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java index 4d0c0c13..60f71611 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java @@ -2,6 +2,7 @@ import com.techeer.hackathon.domain.restaurant.entity.Restaurant; import com.techeer.hackathon.domain.review.dto.ReviewCreate; +import com.techeer.hackathon.domain.review.dto.ReviewInfo; import com.techeer.hackathon.domain.review.entity.Review; import org.springframework.stereotype.Component; @@ -15,6 +16,14 @@ public Review toEntity(ReviewCreate request, Restaurant restaurant) { .build(); } + public ReviewInfo toDto(Review review) { + return ReviewInfo.builder() + .restaurantName(review.getRestaurant().getName()) + .content(review.getContent()) + .title(review.getTitle()) + .build(); + } + // public RestaurantResponse toDto(Restaurant restaurant) { // // return RestaurantResponse.builder() diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java index 2bb2f52d..d9e467e2 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java @@ -4,6 +4,9 @@ import com.techeer.hackathon.domain.restaurant.error.RestaurantNotFoundException; import com.techeer.hackathon.domain.restaurant.repository.RestaurantRepository; import com.techeer.hackathon.domain.review.dto.ReviewCreate; +import com.techeer.hackathon.domain.review.dto.ReviewInfo; +import com.techeer.hackathon.domain.review.entity.Review; +import com.techeer.hackathon.domain.review.exception.ReviewNotFoundException; import com.techeer.hackathon.domain.review.mapper.ReviewMapper; import com.techeer.hackathon.domain.review.repository.ReviewRepository; import lombok.AccessLevel; @@ -21,4 +24,9 @@ public void createReview(ReviewCreate request) { Restaurant restaurant = restaurantRepository.findByName(request.getRestaurantName()).orElseThrow(RestaurantNotFoundException::new); reviewRepository.save(reviewMapper.toEntity(request, restaurant)); } + + public ReviewInfo getReview(Long id) { + Review review = reviewRepository.findById(id).orElseThrow(ReviewNotFoundException::new); + return reviewMapper.toDto(review); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java index ea8e452a..59723e99 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/error/ErrorCode.java @@ -13,7 +13,9 @@ public enum ErrorCode { // Restaurant RESTAURANT_DUPLICATION_ERROR(409, "R001", "레스토랑 이름이 중복됩니다."), INVALID_CATEGORY_ERROR(400, "R002", "잘못된 카테고리 이름입니다."), - RESTAURANT_NOT_FOUND(404, "R003", "식당을 찾을 수 없습니다."); + RESTAURANT_NOT_FOUND(404, "R003", "식당을 찾을 수 없습니다."), + + REVIEW_NOT_FOUND(404, "V001", "리뷰를 찾을 수 없습니다."); private final int status; private final String code; diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java index 6944dd8e..2403b391 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java @@ -13,7 +13,8 @@ public enum ResultCode { DELETE_RESTAURANTS_SUCCESS("R004", "레스토랑 삭제 성공"), GET_RESTAURANTS_SUCCESS("R005", "카테고리 조회 성공"), - REVIEW_CREATE_SUCCESS("V001", "리뷰 등록 성공"); + REVIEW_CREATE_SUCCESS("V001", "리뷰 등록 성공"), + GET_REVIEW_SUCCESS("V002", "리뷰 조회 성공"); private final String code; private final String message; From 3593b92dff212edecff315b5ed5d470a5bc07886 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 10:03:07 +0900 Subject: [PATCH 29/32] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B7=B0=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/review/controller/ReviewController.java | 7 +++++++ .../hackathon/domain/review/service/ReviewService.java | 5 +++++ .../com/techeer/hackathon/global/result/ResultCode.java | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java index fc013cd7..3afe997a 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java @@ -28,4 +28,11 @@ public ResponseEntity getReview( @PathVariable Long id) { return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_REVIEW_SUCCESS, reviewService.getReview(id))); } + + @DeleteMapping("/{id}") + public ResponseEntity deleteReview( + @PathVariable Long id) { + reviewService.deleteReview(id); + return ResponseEntity.ok(ResultResponse.of(ResultCode.DELETE_REVIEW_SUCCESS)); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java index d9e467e2..f9258350 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java @@ -29,4 +29,9 @@ public ReviewInfo getReview(Long id) { Review review = reviewRepository.findById(id).orElseThrow(ReviewNotFoundException::new); return reviewMapper.toDto(review); } + + public void deleteReview(Long id) { + reviewRepository.findById(id).orElseThrow(ReviewNotFoundException::new); + reviewRepository.deleteById(id); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java index 2403b391..f74ddaf1 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java @@ -14,7 +14,8 @@ public enum ResultCode { GET_RESTAURANTS_SUCCESS("R005", "카테고리 조회 성공"), REVIEW_CREATE_SUCCESS("V001", "리뷰 등록 성공"), - GET_REVIEW_SUCCESS("V002", "리뷰 조회 성공"); + GET_REVIEW_SUCCESS("V002", "리뷰 조회 성공"), + DELETE_REVIEW_SUCCESS("V003", "리뷰 삭제 성공"); private final String code; private final String message; From 2ef0d2a2e496ac0249c7870932a86a1fc8c30e3e Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 10:33:52 +0900 Subject: [PATCH 30/32] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B7=B0=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/review/controller/ReviewController.java | 10 ++++++++++ .../domain/review/dto/ReviewUpdateRequest.java | 13 +++++++++++++ .../domain/review/mapper/ReviewMapper.java | 11 +++++++++++ .../domain/review/repository/ReviewRepository.java | 13 +++++++++++++ .../domain/review/service/ReviewService.java | 7 +++++++ .../techeer/hackathon/global/result/ResultCode.java | 3 ++- 6 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewUpdateRequest.java diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java index 3afe997a..96258339 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java @@ -1,6 +1,7 @@ package com.techeer.hackathon.domain.review.controller; import com.techeer.hackathon.domain.review.dto.ReviewCreate; +import com.techeer.hackathon.domain.review.dto.ReviewUpdateRequest; import com.techeer.hackathon.domain.review.service.ReviewService; import com.techeer.hackathon.global.result.ResultCode; import com.techeer.hackathon.global.result.ResultResponse; @@ -35,4 +36,13 @@ public ResponseEntity deleteReview( reviewService.deleteReview(id); return ResponseEntity.ok(ResultResponse.of(ResultCode.DELETE_REVIEW_SUCCESS)); } + + @PatchMapping("/{id}") + public ResponseEntity updateReview( + @RequestBody ReviewUpdateRequest reviewUpdateRequest + ) { + reviewService.updateReview(reviewUpdateRequest); + return ResponseEntity.ok(ResultResponse.of(ResultCode.UPDATE_REVIEW_SUCCESS)); + } + } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewUpdateRequest.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewUpdateRequest.java new file mode 100644 index 00000000..3e090ebc --- /dev/null +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/dto/ReviewUpdateRequest.java @@ -0,0 +1,13 @@ +package com.techeer.hackathon.domain.review.dto; + +import lombok.*; + +@Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ReviewUpdateRequest { + private Long id; + private String title; + private String content; +} diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java index 60f71611..e893339e 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java @@ -3,6 +3,7 @@ import com.techeer.hackathon.domain.restaurant.entity.Restaurant; import com.techeer.hackathon.domain.review.dto.ReviewCreate; import com.techeer.hackathon.domain.review.dto.ReviewInfo; +import com.techeer.hackathon.domain.review.dto.ReviewUpdateRequest; import com.techeer.hackathon.domain.review.entity.Review; import org.springframework.stereotype.Component; @@ -16,6 +17,16 @@ public Review toEntity(ReviewCreate request, Restaurant restaurant) { .build(); } + public Review toEntity(ReviewUpdateRequest request, Restaurant restaurant) { + return Review.builder() + .restaurant(restaurant) + .content(request.getContent()) + .title(request.getTitle()) + .build(); + } + + + public ReviewInfo toDto(Review review) { return ReviewInfo.builder() .restaurantName(review.getRestaurant().getName()) diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/repository/ReviewRepository.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/repository/ReviewRepository.java index eab3fe20..199a4b86 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/repository/ReviewRepository.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/repository/ReviewRepository.java @@ -2,6 +2,19 @@ import com.techeer.hackathon.domain.review.entity.Review; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.transaction.annotation.Transactional; public interface ReviewRepository extends JpaRepository { + + @Modifying + @Transactional + @Query("update Review r set r.content = '' where r.id = :id") + void softDeleteById(Long id); + +// @Modifying +// @Transactional +// @Query("update Review r set r.content = '' where r.id = :id") +// void update(Review review); } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java index f9258350..796eafb2 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java @@ -5,6 +5,7 @@ import com.techeer.hackathon.domain.restaurant.repository.RestaurantRepository; import com.techeer.hackathon.domain.review.dto.ReviewCreate; import com.techeer.hackathon.domain.review.dto.ReviewInfo; +import com.techeer.hackathon.domain.review.dto.ReviewUpdateRequest; import com.techeer.hackathon.domain.review.entity.Review; import com.techeer.hackathon.domain.review.exception.ReviewNotFoundException; import com.techeer.hackathon.domain.review.mapper.ReviewMapper; @@ -34,4 +35,10 @@ public void deleteReview(Long id) { reviewRepository.findById(id).orElseThrow(ReviewNotFoundException::new); reviewRepository.deleteById(id); } + + public void updateReview(ReviewUpdateRequest reviewUpdateRequest) { + Review findReview = reviewRepository.findById(reviewUpdateRequest.getId()).orElseThrow(ReviewNotFoundException::new); + Review review = reviewMapper.toEntity(reviewUpdateRequest, findReview.getRestaurant()); + reviewRepository.save(review); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java index f74ddaf1..7d6dd8ba 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java @@ -15,7 +15,8 @@ public enum ResultCode { REVIEW_CREATE_SUCCESS("V001", "리뷰 등록 성공"), GET_REVIEW_SUCCESS("V002", "리뷰 조회 성공"), - DELETE_REVIEW_SUCCESS("V003", "리뷰 삭제 성공"); + DELETE_REVIEW_SUCCESS("V003", "리뷰 삭제 성공"), + UPDATE_REVIEW_SUCCESS("V004", "리뷰 수정 성공"); private final String code; private final String message; From b1ef332074b585380dddaad7a0bc74f1f7ed16a7 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 11:39:52 +0900 Subject: [PATCH 31/32] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B7=B0=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EC=A1=B0=ED=9A=8C=20ResultCode,=20Control?= =?UTF-8?q?ler=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/review/controller/ReviewController.java | 13 +++++++++++++ .../techeer/hackathon/global/result/ResultCode.java | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java index 96258339..56f73892 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java @@ -1,15 +1,20 @@ package com.techeer.hackathon.domain.review.controller; import com.techeer.hackathon.domain.review.dto.ReviewCreate; +import com.techeer.hackathon.domain.review.dto.ReviewInfo; import com.techeer.hackathon.domain.review.dto.ReviewUpdateRequest; import com.techeer.hackathon.domain.review.service.ReviewService; import com.techeer.hackathon.global.result.ResultCode; import com.techeer.hackathon.global.result.ResultResponse; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequestMapping("api/v1/review") @RequiredArgsConstructor(access = AccessLevel.PRIVATE) @@ -45,4 +50,12 @@ public ResponseEntity updateReview( return ResponseEntity.ok(ResultResponse.of(ResultCode.UPDATE_REVIEW_SUCCESS)); } + @GetMapping("/{restaurantName}/{page}") + public ResponseEntity getReview( + @PathVariable String restaurantName, @PathVariable Integer page, @RequestParam(defaultValue = "20") Integer size) { + PageRequest pageRequest = PageRequest.of(page, size, Sort.by("id").descending()); + List reviews = reviewService.getReviews(restaurantName, pageRequest); + return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_ALL_REVIEW_SUCCESS, reviews)); + } + } diff --git a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java index 7d6dd8ba..c7cc1295 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java +++ b/hackathon/src/main/java/com/techeer/hackathon/global/result/ResultCode.java @@ -16,7 +16,8 @@ public enum ResultCode { REVIEW_CREATE_SUCCESS("V001", "리뷰 등록 성공"), GET_REVIEW_SUCCESS("V002", "리뷰 조회 성공"), DELETE_REVIEW_SUCCESS("V003", "리뷰 삭제 성공"), - UPDATE_REVIEW_SUCCESS("V004", "리뷰 수정 성공"); + UPDATE_REVIEW_SUCCESS("V004", "리뷰 수정 성공"), + GET_ALL_REVIEW_SUCCESS("V005", "리뷰 페이징 조회 성공"); private final String code; private final String message; From b6761f58a95e2f67edc477d3dd1980b919109291 Mon Sep 17 00:00:00 2001 From: JeongHunHui Date: Sun, 26 Feb 2023 11:50:41 +0900 Subject: [PATCH 32/32] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B7=B0=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../review/controller/ReviewController.java | 11 +++++------ .../domain/review/mapper/ReviewMapper.java | 18 ++++++------------ .../domain/review/service/ReviewService.java | 8 ++++++++ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java index 56f73892..8e31ff4e 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/controller/ReviewController.java @@ -9,7 +9,6 @@ import lombok.AccessLevel; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -50,11 +49,11 @@ public ResponseEntity updateReview( return ResponseEntity.ok(ResultResponse.of(ResultCode.UPDATE_REVIEW_SUCCESS)); } - @GetMapping("/{restaurantName}/{page}") - public ResponseEntity getReview( - @PathVariable String restaurantName, @PathVariable Integer page, @RequestParam(defaultValue = "20") Integer size) { - PageRequest pageRequest = PageRequest.of(page, size, Sort.by("id").descending()); - List reviews = reviewService.getReviews(restaurantName, pageRequest); + @GetMapping("/all/{page}") + public ResponseEntity getReviews( + @PathVariable Integer page, @RequestParam(defaultValue = "20") Integer size) { + PageRequest pageRequest = PageRequest.of(page, size); + List reviews = reviewService.getReviews(pageRequest); return ResponseEntity.ok(ResultResponse.of(ResultCode.GET_ALL_REVIEW_SUCCESS, reviews)); } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java index e893339e..2d67144b 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/mapper/ReviewMapper.java @@ -7,6 +7,9 @@ import com.techeer.hackathon.domain.review.entity.Review; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.stream.Collectors; + @Component public class ReviewMapper { public Review toEntity(ReviewCreate request, Restaurant restaurant) { @@ -35,16 +38,7 @@ public ReviewInfo toDto(Review review) { .build(); } -// public RestaurantResponse toDto(Restaurant restaurant) { -// -// return RestaurantResponse.builder() -// .category(restaurant.getCategory().name()) -// .name(restaurant.getName()) -// .createdAt(restaurant.getCreatedAt()) -// .build(); -// } -// -// public List toDtoList(List list) { -// return list.stream().map(this::toDto).collect(Collectors.toList()); -// } + public List toDtoList(List list) { + return list.stream().map(this::toDto).collect(Collectors.toList()); + } } diff --git a/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java index 796eafb2..9c6fe32c 100644 --- a/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java +++ b/hackathon/src/main/java/com/techeer/hackathon/domain/review/service/ReviewService.java @@ -12,8 +12,11 @@ import com.techeer.hackathon.domain.review.repository.ReviewRepository; import lombok.AccessLevel; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; +import java.util.List; + @Service @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public class ReviewService { @@ -41,4 +44,9 @@ public void updateReview(ReviewUpdateRequest reviewUpdateRequest) { Review review = reviewMapper.toEntity(reviewUpdateRequest, findReview.getRestaurant()); reviewRepository.save(review); } + + public List getReviews(PageRequest pageRequest) { + List reviews = reviewRepository.findAll(pageRequest).getContent(); + return reviewMapper.toDtoList(reviews); + } }