diff --git a/.gradle/7.6/checksums/checksums.lock b/.gradle/7.6/checksums/checksums.lock new file mode 100644 index 00000000..8c5abd2b Binary files /dev/null and b/.gradle/7.6/checksums/checksums.lock differ diff --git a/.gradle/7.6/checksums/md5-checksums.bin b/.gradle/7.6/checksums/md5-checksums.bin new file mode 100644 index 00000000..6c18002e Binary files /dev/null and b/.gradle/7.6/checksums/md5-checksums.bin differ diff --git a/.gradle/7.6/checksums/sha1-checksums.bin b/.gradle/7.6/checksums/sha1-checksums.bin new file mode 100644 index 00000000..d8c27169 Binary files /dev/null and b/.gradle/7.6/checksums/sha1-checksums.bin differ diff --git a/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock b/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 00000000..66bab6af Binary files /dev/null and b/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock differ diff --git a/.gradle/7.6/dependencies-accessors/gc.properties b/.gradle/7.6/dependencies-accessors/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/.gradle/7.6/executionHistory/executionHistory.bin b/.gradle/7.6/executionHistory/executionHistory.bin new file mode 100644 index 00000000..a4e254a1 Binary files /dev/null and b/.gradle/7.6/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.6/executionHistory/executionHistory.lock b/.gradle/7.6/executionHistory/executionHistory.lock new file mode 100644 index 00000000..ad41903a Binary files /dev/null and b/.gradle/7.6/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.6/fileChanges/last-build.bin b/.gradle/7.6/fileChanges/last-build.bin new file mode 100644 index 00000000..f76dd238 Binary files /dev/null and b/.gradle/7.6/fileChanges/last-build.bin differ diff --git a/.gradle/7.6/fileHashes/fileHashes.bin b/.gradle/7.6/fileHashes/fileHashes.bin new file mode 100644 index 00000000..063a146f Binary files /dev/null and b/.gradle/7.6/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.6/fileHashes/fileHashes.lock b/.gradle/7.6/fileHashes/fileHashes.lock new file mode 100644 index 00000000..787fe157 Binary files /dev/null and b/.gradle/7.6/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.6/fileHashes/resourceHashesCache.bin b/.gradle/7.6/fileHashes/resourceHashesCache.bin new file mode 100644 index 00000000..48cd9f2f Binary files /dev/null and b/.gradle/7.6/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/7.6/gc.properties b/.gradle/7.6/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/.gradle/build/classes/java/main/com/example/demo/DemoApplication.class b/.gradle/build/classes/java/main/com/example/demo/DemoApplication.class new file mode 100644 index 00000000..37bc981b Binary files /dev/null and b/.gradle/build/classes/java/main/com/example/demo/DemoApplication.class differ diff --git a/.gradle/build/classes/java/test/com/example/demo/DemoApplicationTests.class b/.gradle/build/classes/java/test/com/example/demo/DemoApplicationTests.class new file mode 100644 index 00000000..27b8e189 Binary files /dev/null and b/.gradle/build/classes/java/test/com/example/demo/DemoApplicationTests.class differ diff --git a/.gradle/build/resources/main/application.properties b/.gradle/build/resources/main/application.properties new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/.gradle/build/resources/main/application.properties @@ -0,0 +1 @@ + diff --git a/.gradle/build/tmp/compileJava/previous-compilation-data.bin b/.gradle/build/tmp/compileJava/previous-compilation-data.bin new file mode 100644 index 00000000..7cea29c1 Binary files /dev/null and b/.gradle/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/.gradle/build/tmp/compileTestJava/previous-compilation-data.bin b/.gradle/build/tmp/compileTestJava/previous-compilation-data.bin new file mode 100644 index 00000000..5b8e98b5 Binary files /dev/null and b/.gradle/build/tmp/compileTestJava/previous-compilation-data.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 00000000..012e7ca1 Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 00000000..7c0a2cae --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Sat Feb 25 23:27:14 KST 2023 +gradle.version=7.6 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 00000000..561320a3 Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe new file mode 100644 index 00000000..2924547e Binary files /dev/null and b/.gradle/file-system.probe differ diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..e3f094ee --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +project \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..688ff233 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 00000000..ce412026 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..32703c56 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..fdc392fe --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..1429a1d3 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..8b463067 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules/project.main.iml b/.idea/modules/project.main.iml new file mode 100644 index 00000000..ec81b538 --- /dev/null +++ b/.idea/modules/project.main.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..ccc1d68a --- /dev/null +++ b/build.gradle @@ -0,0 +1,35 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '2.7.9' + id 'io.spring.dependency-management' version '1.0.15.RELEASE' +} + +group = 'com.example' +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-validation' + implementation 'org.springframework.boot:spring-boot-starter-web' + testImplementation 'junit:junit:4.13.1' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.h2database:h2' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..249e5832 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..070cb702 --- /dev/null +++ b/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/gradlew b/gradlew new file mode 100755 index 00000000..a69d9cb6 --- /dev/null +++ b/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/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..53a6b238 --- /dev/null +++ b/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/settings.gradle b/settings.gradle new file mode 100644 index 00000000..682509ee --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'project' diff --git a/src/main/java/com/project/hackathon/HackatonApplication.java b/src/main/java/com/project/hackathon/HackatonApplication.java new file mode 100644 index 00000000..3d38755a --- /dev/null +++ b/src/main/java/com/project/hackathon/HackatonApplication.java @@ -0,0 +1,13 @@ +package com.project.hackathon; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HackatonApplication { + + public static void main(String[] args) { + SpringApplication.run(HackatonApplication.class, args); + } + +} diff --git a/src/main/java/com/project/hackathon/domain/restaurant/controller/RestaurantController.java b/src/main/java/com/project/hackathon/domain/restaurant/controller/RestaurantController.java new file mode 100644 index 00000000..e2270ab9 --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/restaurant/controller/RestaurantController.java @@ -0,0 +1,59 @@ +package com.project.hackathon.domain.restaurant.controller; + +import javax.validation.Valid; +import com.project.hackathon.domain.restaurant.dto.RestaurantCreateRequest; +import com.project.hackathon.domain.restaurant.dto.RestaurantDetailResponse; +import com.project.hackathon.domain.restaurant.dto.RestaurantUpdateRequest; +import com.project.hackathon.domain.restaurant.entity.Category; +import com.project.hackathon.domain.restaurant.entity.Restaurant; +import com.project.hackathon.domain.restaurant.service.RestaurantService; +import com.project.hackathon.global.dto.ResultResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import java.util.List; + +@RequestMapping("/api/v1/restaurant") +@RequiredArgsConstructor +@RestController +public class RestaurantController { + + private final RestaurantService restaurantService; + @PostMapping("/create") + public ResponseEntity createRestaurant( + @Validated @RequestBody RestaurantCreateRequest request + ) { + RestaurantDetailResponse restaurantDetailResponse = restaurantService.create(request); + return ResponseEntity.ok(restaurantDetailResponse); + } + + @GetMapping("/list") + public ResponseEntity> getAllRestaurants() { + List restaurants = restaurantService.getAllRestaurants(); + return ResponseEntity.ok(restaurants); + } + + @GetMapping("/list/{category}") + public ResponseEntity> loadRestaurantByCategory(@PathVariable Category category) { + List restaurantDetailResponses = restaurantService.getRestaurantsByCategory(category); + return ResponseEntity.ok(restaurantDetailResponses); + } + + @PatchMapping("/{id}") + public ResponseEntity updateRestaurant( + @PathVariable Long id, + @Valid @RequestBody RestaurantUpdateRequest request) { + RestaurantDetailResponse restaurantDetailResponse = restaurantService.update(id, request); + return ResponseEntity.ok(restaurantDetailResponse); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteRestaurant( + @PathVariable Long id) { + restaurantService.delete(id); + String message = ResultResponse.RESTAURANT_DELETE_SUCCESS.getMessage(); + RestaurantDetailResponse response = new RestaurantDetailResponse(message); + return ResponseEntity.ok(response); + } +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantCreateRequest.java b/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantCreateRequest.java new file mode 100644 index 00000000..23d7afef --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantCreateRequest.java @@ -0,0 +1,17 @@ +package com.project.hackathon.domain.restaurant.dto; + +import com.project.hackathon.domain.restaurant.entity.Category; +import lombok.*; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Getter +@Builder +@Data +public class RestaurantCreateRequest { + @NotBlank(message = "레스토랑 제목은 빈칸일 수 없습니다.") + private String title; + + @NotNull(message = "레스토랑 카테고리는 공백이 올 수 없습니다.") + private Category category; +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantDetailResponse.java b/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantDetailResponse.java new file mode 100644 index 00000000..66a2a10f --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantDetailResponse.java @@ -0,0 +1,26 @@ +package com.project.hackathon.domain.restaurant.dto; + +import java.time.LocalDateTime; +import com.project.hackathon.domain.restaurant.entity.Category; +import lombok.*; + +@Setter +@Builder +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class RestaurantDetailResponse { + private Long id; + // 레스토랑 이름 + private String title; + // 레스토랑 카테고리 + private Category category; + // 레스토랑 생성일자 + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + public RestaurantDetailResponse(String message) { + // 메시지만 필요한 경우에 사용하는 생성자 + this.title = message; + } +} diff --git a/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantInfo.java b/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantInfo.java new file mode 100644 index 00000000..f283a639 --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantInfo.java @@ -0,0 +1,28 @@ +package com.project.hackathon.domain.restaurant.dto; + +import java.time.LocalDateTime; +import lombok.*; + +@Setter +@Getter +@NoArgsConstructor +public class RestaurantInfo { + + // 게시판 제목 + private String title; + // 게시글 작성자 이름 + private String userName; + // 게시판 작성 일시 + private LocalDateTime createdDate; + // 이미지 첨부 여부 + private boolean hasImages; + + @Builder + public RestaurantInfo( + String title, String userName, LocalDateTime createdDate, boolean hasImages) { + this.title = title; + this.userName = userName; + this.createdDate = createdDate; + this.hasImages = hasImages; + } +} diff --git a/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantUpdateRequest.java b/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantUpdateRequest.java new file mode 100644 index 00000000..ffd182d6 --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/restaurant/dto/RestaurantUpdateRequest.java @@ -0,0 +1,22 @@ +package com.project.hackathon.domain.restaurant.dto; + +import com.project.hackathon.domain.restaurant.entity.Category; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +@Getter +@Builder +@AllArgsConstructor +public class RestaurantUpdateRequest { + @NotBlank(message = "레스토랑 제목은 빈칸일 수 없습니다.") + private final String title; + + @NotNull(message = "레스토랑 카테고리는 공백이 올 수 없습니다.") + private final Category category; + + private final LocalDateTime createdAt; +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/restaurant/entity/Category.java b/src/main/java/com/project/hackathon/domain/restaurant/entity/Category.java new file mode 100644 index 00000000..46746795 --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/restaurant/entity/Category.java @@ -0,0 +1,7 @@ +package com.project.hackathon.domain.restaurant.entity; + +public enum Category { + 한식, + 중식, + 일식 +} diff --git a/src/main/java/com/project/hackathon/domain/restaurant/entity/Restaurant.java b/src/main/java/com/project/hackathon/domain/restaurant/entity/Restaurant.java new file mode 100644 index 00000000..b7a42a12 --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/restaurant/entity/Restaurant.java @@ -0,0 +1,54 @@ +package com.project.hackathon.domain.restaurant.entity; + +import com.project.hackathon.global.entity.BaseEntity; +import lombok.*; +import org.hibernate.annotations.CreationTimestamp; +import javax.persistence.*; +import java.time.LocalDateTime; + +@Getter +@Entity +@Table(name = "restaurant") +@NoArgsConstructor +public class Restaurant extends BaseEntity{ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + @Column(name = "title", nullable = false) + private String title; + + // 레스토랑 카테고리 + @Column(name = "category", nullable = false) + @Enumerated(EnumType.STRING) + private Category category; + + @CreationTimestamp + private LocalDateTime createdAt; + + @Column(name = "is_removed", nullable = false) + private boolean isRemoved; + + @Builder + public Restaurant( + String title, + Category category + ) { + this.title = title; + this.category = category; + this.isRemoved = false; + } + public void setTitle(String title) { + this.title = title; + } + public void setCategory(Category category) { + this.category = category; + } + public void setUpdatedAt() { + this.updatedAt = LocalDateTime.now(); + } + public void deleteRestaurant() { //soft delete + this.isRemoved = true; + } +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/restaurant/repository/RestaurantRepository.java b/src/main/java/com/project/hackathon/domain/restaurant/repository/RestaurantRepository.java new file mode 100644 index 00000000..e12c0795 --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/restaurant/repository/RestaurantRepository.java @@ -0,0 +1,28 @@ +package com.project.hackathon.domain.restaurant.repository; + +import com.project.hackathon.domain.restaurant.entity.Category; +import com.project.hackathon.domain.restaurant.entity.Restaurant; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import java.util.List; +import java.util.Optional; + +public interface RestaurantRepository extends JpaRepository { + + @Query("select r from Restaurant r where r.id = :id and r.isActive = true") + Optional findRestaurantById(@Param("id") Long id); + List findAll(); + + @Query("select r from Restaurant r where r.category = :category and r.isActive is true") + List findByCategory(Category category); + + @Query("select r from Restaurant r where r.isActive is true") + Page findRestaurantWithPagination(Pageable pageable); + + @Query("select r from Restaurant r where r.isActive is true and r.title like %:keyword%") + Page findContainingTitleRestaurantWithPagination( + Pageable pageable, @Param("keyword") String keyword); +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/restaurant/service/RestaurantService.java b/src/main/java/com/project/hackathon/domain/restaurant/service/RestaurantService.java new file mode 100644 index 00000000..b734b89b --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/restaurant/service/RestaurantService.java @@ -0,0 +1,81 @@ +package com.project.hackathon.domain.restaurant.service; + +import com.project.hackathon.domain.restaurant.dto.RestaurantCreateRequest; +import com.project.hackathon.domain.restaurant.dto.RestaurantDetailResponse; +import com.project.hackathon.domain.restaurant.dto.RestaurantUpdateRequest; +import com.project.hackathon.domain.restaurant.entity.Category; +import com.project.hackathon.domain.restaurant.entity.Restaurant; +import com.project.hackathon.domain.restaurant.repository.RestaurantRepository; +import lombok.Builder; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class RestaurantService { + private final RestaurantRepository restaurantRepository; + + public RestaurantDetailResponse create(RestaurantCreateRequest restaurantCreateRequest) { + Restaurant newRestaurant = + Restaurant.builder() + .title(restaurantCreateRequest.getTitle()) + .category(restaurantCreateRequest.getCategory()) + .build(); + + restaurantRepository.save(newRestaurant); + + return RestaurantDetailResponse.builder() + .id(newRestaurant.getId()) + .title(newRestaurant.getTitle()) + .category(newRestaurant.getCategory()) + .createdAt(newRestaurant.getCreatedAt()) + .build(); + } + + @Transactional + public List getAllRestaurants() { + return restaurantRepository.findAll(); + } + + @Transactional(readOnly = true) + public List getRestaurantsByCategory(Category category) { + List restaurants = restaurantRepository.findByCategory(category); + List restaurantDetailResponses = new ArrayList<>(); + for(Restaurant restaurant : restaurants) { + restaurantDetailResponses.add(RestaurantDetailResponse.builder() + .id(restaurant.getId()) + .title(restaurant.getTitle()) + .category(restaurant.getCategory()) + .build()); + } + return restaurantDetailResponses; + } + + @Builder + @Transactional + public RestaurantDetailResponse update(Long id, RestaurantUpdateRequest restaurantUpdateRequest) { + Restaurant restaurant = restaurantRepository.findById(id).orElseThrow(null); + restaurant.setTitle(restaurantUpdateRequest.getTitle()); + restaurant.setCategory(restaurantUpdateRequest.getCategory()); + restaurant.setUpdatedAt(); + + Restaurant savedRestaurant = restaurantRepository.save(restaurant); + return new RestaurantDetailResponse( + savedRestaurant.getId(), + savedRestaurant.getTitle(), + savedRestaurant.getCategory(), + savedRestaurant.getCreatedAt(), + savedRestaurant.getUpdatedAt() + ); + } + + @Transactional + public void delete(Long id) { + Restaurant restaurant = restaurantRepository.findRestaurantById(id).orElseThrow(null); + restaurant.deleteRestaurant(); + restaurantRepository.save(restaurant); + } +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/review/controller/ReviewController.java b/src/main/java/com/project/hackathon/domain/review/controller/ReviewController.java new file mode 100644 index 00000000..cfb52ce4 --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/review/controller/ReviewController.java @@ -0,0 +1,76 @@ +package com.project.hackathon.domain.review.controller; + +import com.project.hackathon.domain.review.dto.ReviewCreateRequest; +import com.project.hackathon.domain.review.dto.ReviewDetailResponse; +import com.project.hackathon.domain.review.dto.ReviewUpdateRequest; +import com.project.hackathon.domain.review.entity.Review; +import com.project.hackathon.domain.review.service.ReviewService; +import com.project.hackathon.global.dto.ResultResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; +import java.util.List; + +@RequestMapping("/api/v1/{restaurant}/review") +@RequiredArgsConstructor +@RestController +public class ReviewController { + + private final ReviewService reviewService; + @PostMapping("/create") + public ResponseEntity createReview( + @Validated @RequestBody ReviewCreateRequest request, + @PathVariable String restaurant) { + ReviewDetailResponse reviewDetailResponse = reviewService.create(request); + return ResponseEntity.ok(reviewDetailResponse); + } + + @GetMapping("/list") + public ResponseEntity> getAllReviews(@PathVariable String restaurant) { + List reviews = reviewService.getAllReviews(); + return ResponseEntity.ok(reviews); + } + + @GetMapping("/list/createdAt") + public ResponseEntity> getAllReviewsByCreatedAt(@PathVariable String restaurant) { + List reviews = reviewService.getAllReviewsByCreatedAt(); + return ResponseEntity.ok(reviews); + } + + @GetMapping("/list/createdAtDesc") + public ResponseEntity> getAllReviewsByCreatedAtDesc() { + List reviews = reviewService.getAllReviewsByCreatedAtDesc(); + return ResponseEntity.ok(reviews); + } + + @GetMapping("/search/{keyword}?page=0&size=10리&sort=id,desc") + public ResponseEntity> searchReviews( + @PathVariable String keyword, + @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) { + Page reviews = reviewService.search(keyword, pageable); + return ResponseEntity.ok(reviews); + } + + @PatchMapping("/{id}") + public ResponseEntity updateReview( + @PathVariable Long id, + @Valid @RequestBody ReviewUpdateRequest request) { + ReviewDetailResponse reviewDetailResponse = reviewService.update(id, request); + return ResponseEntity.ok(reviewDetailResponse); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteReview( + @PathVariable Long id) { + reviewService.delete(id); + String message = ResultResponse.REVIEW_DELETE_SUCCESS.getMessage(); + ReviewDetailResponse response = new ReviewDetailResponse(message); + return ResponseEntity.ok(response); + } +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/review/dto/ReviewCreateRequest.java b/src/main/java/com/project/hackathon/domain/review/dto/ReviewCreateRequest.java new file mode 100644 index 00000000..9542a54f --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/review/dto/ReviewCreateRequest.java @@ -0,0 +1,21 @@ +package com.project.hackathon.domain.review.dto; + +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import javax.validation.constraints.NotBlank; + +@Getter +@Builder +@Data +public class ReviewCreateRequest { + @NotBlank(message = "리뷰 제목은 빈칸일 수 없습니다.") + private String title; + + @NotBlank(message = "리뷰 내용은 빈칸일 수 없습니다.") + private String content; + + @NotBlank(message = "리뷰 내용은 빈칸일 수 없습니다.") + private String restaurant; + +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/review/dto/ReviewDetailResponse.java b/src/main/java/com/project/hackathon/domain/review/dto/ReviewDetailResponse.java new file mode 100644 index 00000000..7a7b708b --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/review/dto/ReviewDetailResponse.java @@ -0,0 +1,25 @@ +package com.project.hackathon.domain.review.dto; + +import lombok.*; +import java.time.LocalDateTime; + +@Setter +@Builder +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class ReviewDetailResponse { + private Long id; + // 리뷰 이름 + private String title; + // 리뷰 내용 + private String content; + private String restaurant; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + public ReviewDetailResponse(String message) { + // 메시지만 필요한 경우에 사용하는 생성자 + this.title = message; + } +} diff --git a/src/main/java/com/project/hackathon/domain/review/dto/ReviewUpdateRequest.java b/src/main/java/com/project/hackathon/domain/review/dto/ReviewUpdateRequest.java new file mode 100644 index 00000000..dc9c334b --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/review/dto/ReviewUpdateRequest.java @@ -0,0 +1,21 @@ +package com.project.hackathon.domain.review.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import javax.validation.constraints.NotBlank; +import java.time.LocalDateTime; + +@Getter +@Builder +@AllArgsConstructor +public class ReviewUpdateRequest { + + @NotBlank(message = "리뷰 제목은 빈칸일 수 없습니다.") + private final String title; + + @NotBlank(message = "리뷰 내용은 빈칸일 수 없습니다.") + private final String content; + + private final LocalDateTime createdAt; +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/review/entity/Review.java b/src/main/java/com/project/hackathon/domain/review/entity/Review.java new file mode 100644 index 00000000..3e6676d1 --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/review/entity/Review.java @@ -0,0 +1,67 @@ +package com.project.hackathon.domain.review.entity; + +import com.project.hackathon.global.entity.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.CreationTimestamp; +import javax.persistence.*; +import java.time.LocalDateTime; + +@Getter +@Entity +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "review") +public class Review extends BaseEntity { + + @Id + @GeneratedValue + @Column(name = "id") + private Long id; + + // 리뷰 제목 + @Column(name = "title", nullable = false) + private String title; + + // 리뷰 내용 + @Lob // 엄청나게 긴 text + @Column(name = "content", nullable = false) + private String content; + + @Column(name = "restaurant", nullable = false) + private String restaurant; + + @CreationTimestamp + @Column(name = "createdAt") + private LocalDateTime createdAt = LocalDateTime.now(); + + @Column(name = "is_removed", nullable = false) + private boolean isRemoved; + + @Builder + public Review( + String title, + String content, + String restaurant){ + this.title = title; + this.content = content; + this.restaurant = restaurant; + this.isRemoved = false; + } + + public void setTitle(String title) { + this.title = title; + } + public void setContent(String content) { + this.content = content; + } + public void setUpdatedAt() { + this.updatedAt = LocalDateTime.now(); + } + public void deleteReview() { //soft delete + this.isRemoved = true; + } + +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/review/repository/ReviewRepository.java b/src/main/java/com/project/hackathon/domain/review/repository/ReviewRepository.java new file mode 100644 index 00000000..a118ff7b --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/review/repository/ReviewRepository.java @@ -0,0 +1,25 @@ +package com.project.hackathon.domain.review.repository; + +import com.project.hackathon.domain.review.entity.Review; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import java.util.List; +import java.util.Optional; + +public interface ReviewRepository extends JpaRepository { + + @Query("select r from Review r where r.id = :id and r.isActive = true") + Optional findReviewById(@Param("id") Long id); + List findAll(); + + @Query("select r from Review r where r.isActive = true and (r.title like %:keyword% or r.content like %:keyword%)") + Page findContainingTitleOrContentReviewWithPagination( + Pageable pageable, @Param("keyword") String keyword); + + List findAllByOrderByCreatedAt(); + List findAllByOrderByCreatedAtDesc(); + +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/domain/review/service/ReviewService.java b/src/main/java/com/project/hackathon/domain/review/service/ReviewService.java new file mode 100644 index 00000000..9b8603a4 --- /dev/null +++ b/src/main/java/com/project/hackathon/domain/review/service/ReviewService.java @@ -0,0 +1,85 @@ +package com.project.hackathon.domain.review.service; + +import com.project.hackathon.domain.review.dto.ReviewCreateRequest; +import com.project.hackathon.domain.review.dto.ReviewDetailResponse; +import com.project.hackathon.domain.review.dto.ReviewUpdateRequest; +import com.project.hackathon.domain.review.entity.Review; +import com.project.hackathon.domain.review.repository.ReviewRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ReviewService { + private final ReviewRepository reviewRepository; + public ReviewDetailResponse create(ReviewCreateRequest reviewCreateRequest) { + Review newReview = + Review.builder() + .title(reviewCreateRequest.getTitle()) + .content(reviewCreateRequest.getContent()) + .restaurant(reviewCreateRequest.getRestaurant()) + .build(); + reviewRepository.save(newReview); + return ReviewDetailResponse.builder() + .id(newReview.getId()) + .title(newReview.getTitle()) + .content(newReview.getContent()) + .restaurant(reviewCreateRequest.getRestaurant()) + .createdAt(newReview.getCreatedAt()) + .build(); + } + + @Transactional + public List getAllReviews() { + return reviewRepository.findAll(); + } + + @Transactional + public List getAllReviewsByCreatedAt() { + return reviewRepository.findAllByOrderByCreatedAt(); + } + + @Transactional + public List getAllReviewsByCreatedAtDesc() { + return reviewRepository.findAllByOrderByCreatedAtDesc(); + } + + @Transactional(readOnly = true) + public Page search(String keyword, Pageable pageable) { + Page reviews = reviewRepository.findContainingTitleOrContentReviewWithPagination(pageable, keyword); + return reviews.map(review -> ReviewDetailResponse.builder() + .id(review.getId()) + .title(review.getTitle()) + .content(review.getContent()) + .build()); + } + + @Transactional + public ReviewDetailResponse update(Long id, ReviewUpdateRequest reviewUpdateRequest) { + Review review = reviewRepository.findById(id).orElseThrow(null); + review.setTitle(reviewUpdateRequest.getTitle()); + review.setContent(reviewUpdateRequest.getContent()); + review.setUpdatedAt(); + + Review savedReview = reviewRepository.save(review); + return new ReviewDetailResponse( + savedReview.getId(), + savedReview.getTitle(), + savedReview.getContent(), + savedReview.getRestaurant(), + savedReview.getCreatedAt(), + savedReview.getUpdatedAt() + ); + } + + @Transactional + public void delete(Long id) { + Review review = reviewRepository.findReviewById(id).orElseThrow(null); + review.deleteReview(); + reviewRepository.save(review); + } +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/global/config/JpaAuditingConfiguration.java b/src/main/java/com/project/hackathon/global/config/JpaAuditingConfiguration.java new file mode 100644 index 00000000..95125f41 --- /dev/null +++ b/src/main/java/com/project/hackathon/global/config/JpaAuditingConfiguration.java @@ -0,0 +1,8 @@ +package com.project.hackathon.global.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@EnableJpaAuditing +@Configuration +public class JpaAuditingConfiguration {} diff --git a/src/main/java/com/project/hackathon/global/dto/ErrorResponse.java b/src/main/java/com/project/hackathon/global/dto/ErrorResponse.java new file mode 100644 index 00000000..fb873ab0 --- /dev/null +++ b/src/main/java/com/project/hackathon/global/dto/ErrorResponse.java @@ -0,0 +1,23 @@ +package com.project.hackathon.global.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ErrorResponse { + // Global + INTERNAL_SERVER_ERROR(500, "G001", "서버 오류"), + + // Restaurant + RESTAURANT_NOT_FOUND(400, "RT001", "레스토랑을 찾을 수 없습니다."), + + // Review + REVIEW_NOT_FOUND(400, "RV001", "리뷰를 찾을 수 없습니다."), + CANT_DELETE_REVIEW(400, "RV003", "이미 삭제된 이미지입니다.") + ; + + private final int status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/project/hackathon/global/dto/ResultResponse.java b/src/main/java/com/project/hackathon/global/dto/ResultResponse.java new file mode 100644 index 00000000..c7265375 --- /dev/null +++ b/src/main/java/com/project/hackathon/global/dto/ResultResponse.java @@ -0,0 +1,25 @@ +package com.project.hackathon.global.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum ResultResponse { + + // restaurant + RESTAURANT_CREATE_SUCCESS("RT001", "레스토랑 등록 성공"), + RESTAURANT_DELETE_SUCCESS("RT002", "레스토랑 삭제 성공"), + RESTAURANT_UPDATE_SUCCESS("RT003", "레스토랑 수정 성공"), + + // review + REVIEW_CREATE_SUCCESS("RV001", "리뷰 업로드 성공"), + REVIEW_GET_SUCCESS("RV002", "리뷰 조회 성공"), + REVIEW_DELETE_SUCCESS("RV003", "리뷰 삭제 성공"), + REVIEW_LIST_PAGE_GET_SUCCESS("RV005", "리뷰 리스트 페이징 조회 성공"), + REVIEW_LIST_PAGE_SEARCH_SUCCESS("RV006", "리뷰 검색 성공"), + ; + + private final String code; + private final String message; +} \ No newline at end of file diff --git a/src/main/java/com/project/hackathon/global/entity/BaseEntity.java b/src/main/java/com/project/hackathon/global/entity/BaseEntity.java new file mode 100644 index 00000000..d8c26a88 --- /dev/null +++ b/src/main/java/com/project/hackathon/global/entity/BaseEntity.java @@ -0,0 +1,38 @@ +package com.project.hackathon.global.entity; + +import java.time.LocalDateTime; +import javax.persistence.Column; +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; +import javax.persistence.PrePersist; +import lombok.Getter; +import org.hibernate.annotations.DynamicInsert; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@MappedSuperclass +@EntityListeners(value = {AuditingEntityListener.class}) +@Getter +@DynamicInsert +public abstract class BaseEntity { + @CreatedDate + @Column(name = "created_at", updatable = false) + private LocalDateTime createdAt; + + @LastModifiedDate + @Column(name = "updated_at") + protected LocalDateTime updatedAt; + + @Column(name = "is_active", nullable = false) + private Boolean isActive; + + @PrePersist + public void prePersist() { + this.isActive = this.isActive == null ? true : this.isActive; + } + + protected void delete() { + this.isActive = false; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 00000000..f83ed709 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,7 @@ +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.username=sa +spring.datasource.password= +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect \ No newline at end of file diff --git a/src/test/HELP.md b/src/test/HELP.md new file mode 100644 index 00000000..14640c8c --- /dev/null +++ b/src/test/HELP.md @@ -0,0 +1,27 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Gradle documentation](https://docs.gradle.org) +* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.7.9/gradle-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.7.9/gradle-plugin/reference/html/#build-image) +* [Validation](https://docs.spring.io/spring-boot/docs/2.7.9/reference/htmlsingle/#io.validation) +* [Spring Web](https://docs.spring.io/spring-boot/docs/2.7.9/reference/htmlsingle/#web) +* [Spring Data JPA](https://docs.spring.io/spring-boot/docs/2.7.9/reference/htmlsingle/#data.sql.jpa-and-spring-data) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Validation](https://spring.io/guides/gs/validating-form-input/) +* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/) + +### Additional Links +These additional references should also help you: + +* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) + diff --git a/src/test/java/com/project/hackathon/DemoApplicationTests.java b/src/test/java/com/project/hackathon/DemoApplicationTests.java new file mode 100644 index 00000000..2778a6a7 --- /dev/null +++ b/src/test/java/com/project/hackathon/DemoApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.demo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DemoApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/src/test/java/com/project/hackathon/domain/restaurant/controller/RestaurantController.java b/src/test/java/com/project/hackathon/domain/restaurant/controller/RestaurantController.java new file mode 100644 index 00000000..c2457869 --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/restaurant/controller/RestaurantController.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.restaurant.controller; + +public class RestaurantController { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/restaurant/dto/RestaurantCreateRequest.java b/src/test/java/com/project/hackathon/domain/restaurant/dto/RestaurantCreateRequest.java new file mode 100644 index 00000000..d1043238 --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/restaurant/dto/RestaurantCreateRequest.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.restaurant.dto; + +public class RestaurantCreateRequest { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/restaurant/dto/RestaurantUpdateRequest.java b/src/test/java/com/project/hackathon/domain/restaurant/dto/RestaurantUpdateRequest.java new file mode 100644 index 00000000..6846d293 --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/restaurant/dto/RestaurantUpdateRequest.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.restaurant.dto; + +public class RestaurantUpdateRequest { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/restaurant/entity/Restaurant.java b/src/test/java/com/project/hackathon/domain/restaurant/entity/Restaurant.java new file mode 100644 index 00000000..edda91b8 --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/restaurant/entity/Restaurant.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.restaurant.entity; + +public class Restaurant { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/restaurant/repository/RestaurantRepository.java b/src/test/java/com/project/hackathon/domain/restaurant/repository/RestaurantRepository.java new file mode 100644 index 00000000..77b0e095 --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/restaurant/repository/RestaurantRepository.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.restaurant.repository; + +public class RestaurantRepository { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/restaurant/service/RestaurantService.java b/src/test/java/com/project/hackathon/domain/restaurant/service/RestaurantService.java new file mode 100644 index 00000000..5b344b61 --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/restaurant/service/RestaurantService.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.restaurant.service; + +public class RestaurantService { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/review/controller/ReviewController.java b/src/test/java/com/project/hackathon/domain/review/controller/ReviewController.java new file mode 100644 index 00000000..efc5dbaf --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/review/controller/ReviewController.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.review.controller; + +public class ReviewController { +} diff --git a/src/test/java/com/project/hackathon/domain/review/dto/ReviewCreateRequest.java b/src/test/java/com/project/hackathon/domain/review/dto/ReviewCreateRequest.java new file mode 100644 index 00000000..ec1d4055 --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/review/dto/ReviewCreateRequest.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.review.dto; + +public class ReviewCreateRequest { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/review/dto/ReviewUpdateRequest.java b/src/test/java/com/project/hackathon/domain/review/dto/ReviewUpdateRequest.java new file mode 100644 index 00000000..e844508c --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/review/dto/ReviewUpdateRequest.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.review.dto; + +public class ReviewUpdateRequest { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/review/entity/Review.java b/src/test/java/com/project/hackathon/domain/review/entity/Review.java new file mode 100644 index 00000000..4d6ff9dd --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/review/entity/Review.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.review.entity; + +public class Review { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/review/repository/ReviewRepository.java b/src/test/java/com/project/hackathon/domain/review/repository/ReviewRepository.java new file mode 100644 index 00000000..5be3c77b --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/review/repository/ReviewRepository.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.review.repository; + +public class ReviewRepository { +} \ No newline at end of file diff --git a/src/test/java/com/project/hackathon/domain/review/service/RestaurantService.java b/src/test/java/com/project/hackathon/domain/review/service/RestaurantService.java new file mode 100644 index 00000000..57d01d78 --- /dev/null +++ b/src/test/java/com/project/hackathon/domain/review/service/RestaurantService.java @@ -0,0 +1,4 @@ +package com.project.hackathon.domain.review.service; + +public class RestaurantService { +} \ No newline at end of file diff --git a/src/test/java/dbTest/MySQLConnectionTest.java b/src/test/java/dbTest/MySQLConnectionTest.java new file mode 100644 index 00000000..153c87e3 --- /dev/null +++ b/src/test/java/dbTest/MySQLConnectionTest.java @@ -0,0 +1,28 @@ +package dbTest; + +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; + +public class MySQLConnectionTest { + + // MySQL Connector 의 클래스. DB 연결 드라이버 정의 + private static final String DRIVER = "com.mysql.cj.jdbc.Driver"; + // DB 경로 + private static final String URL = "jdbc:mysql://localhost:3306/데이터베이스?serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false"; + private static final String USER = "유저 ID"; + private static final String PASSWORD = "비밀번호"; + + @Test + public void testConnection() throws Exception { + // DBMS에게 DB 연결 드라이버의 위치를 알려주기 위한 메소드 + Class.forName(DRIVER); + try { + Connection connection = DriverManager.getConnection(URL, USER, PASSWORD); + System.out.println(connection); + } catch (Exception e) { + e.printStackTrace(); + } + } +}