diff --git a/.gitignore b/.gitignore index 524f096..c2065bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,37 @@ -# Compiled class file -*.class +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ -# Log file -*.log +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ -# BlueJ files -*.ctxt +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ -# Mobile Tools for Java (J2ME) -.mtj.tmp/ +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ -# 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* -replay_pid* +### VS Code ### +.vscode/ diff --git a/luga/build.gradle b/luga/build.gradle new file mode 100644 index 0000000..f251431 --- /dev/null +++ b/luga/build.gradle @@ -0,0 +1,38 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.4.5' + id 'io.spring.dependency-management' version '1.1.7' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +description = 'umc10th' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +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' + testCompileOnly 'org.projectlombok:lombok' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + testAnnotationProcessor 'org.projectlombok:lombok' + + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.8' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/luga/gradle/wrapper/gradle-wrapper.jar b/luga/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..61285a6 Binary files /dev/null and b/luga/gradle/wrapper/gradle-wrapper.jar differ diff --git a/luga/gradle/wrapper/gradle-wrapper.properties b/luga/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..19a6bde --- /dev/null +++ b/luga/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.0-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/luga/gradlew b/luga/gradlew new file mode 100644 index 0000000..adff685 --- /dev/null +++ b/luga/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# 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/HEAD/platforms/jvm/plugins-application/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 + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# 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 + + + +# 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 + if ! command -v java >/dev/null 2>&1 + then + 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 +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + 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" ) + + 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 + + +# 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"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# 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/luga/gradlew.bat b/luga/gradlew.bat new file mode 100644 index 0000000..c4bdd3a --- /dev/null +++ b/luga/gradlew.bat @@ -0,0 +1,93 @@ +@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 +@rem SPDX-License-Identifier: Apache-2.0 +@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=. +@rem This is normally unused +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. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +: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/luga/settings.gradle b/luga/settings.gradle new file mode 100644 index 0000000..1a0e8e6 --- /dev/null +++ b/luga/settings.gradle @@ -0,0 +1,4 @@ +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0' +} +rootProject.name = 'umc10th' diff --git a/luga/src/main/java/com/example/umc10th/Umc10thApplication.java b/luga/src/main/java/com/example/umc10th/Umc10thApplication.java new file mode 100644 index 0000000..9983f43 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/Umc10thApplication.java @@ -0,0 +1,13 @@ +package com.example.umc10th; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Umc10thApplication { + + public static void main(String[] args) { + SpringApplication.run(Umc10thApplication.class, args); + } + +} diff --git a/luga/src/main/java/com/example/umc10th/domain/home/controller/HomeController.java b/luga/src/main/java/com/example/umc10th/domain/home/controller/HomeController.java new file mode 100644 index 0000000..51be80b --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/home/controller/HomeController.java @@ -0,0 +1,47 @@ +package com.example.umc10th.domain.home.controller; + +import com.example.umc10th.domain.home.dto.HomeReqDto; +import com.example.umc10th.domain.home.dto.HomeResDto; +import com.example.umc10th.domain.home.service.HomeService; +import com.example.umc10th.global.apiPayload.ApiResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Tag(name = "Home", description = "홈 화면 관련 API") +@RestController +@RequestMapping("/api/home") +@RequiredArgsConstructor +public class HomeController { + + private final HomeService homeService; + + @Operation(summary = "유저 정보 조회", description = "홈 화면에서 유저의 이름 & 포인트 조회") + @GetMapping("/user-info/{userId}") + public ApiResponse getUserInfo( + @PathVariable Long userId) { + return ApiResponse.onSuccess(homeService.getUserInfo(userId)); + } + + @Operation( + summary = "지역별 미션 목록 조회", + description = "특정 지역의 미션 목록 조회", + parameters = { + @Parameter(name = "page", description = "페이지 번호 (0부터)", example = "0"), + @Parameter(name = "size", description = "페이지 크기", example = "10") + } + ) + @GetMapping("/{userId}") + public ApiResponse getRegionMissions ( + @PathVariable Long userId, + @RequestParam String region, + @RequestParam(defaultValue = "0") int page, + @RequestParam(defaultValue = "10") int size) { + return ApiResponse.onSuccess( + homeService.getRegionMissions(userId, region, page, size)); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/home/converter/HomeConverter.java b/luga/src/main/java/com/example/umc10th/domain/home/converter/HomeConverter.java new file mode 100644 index 0000000..34cce0a --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/home/converter/HomeConverter.java @@ -0,0 +1,39 @@ +package com.example.umc10th.domain.home.converter; + +import com.example.umc10th.domain.home.dto.HomeResDto; +import com.example.umc10th.domain.mission.dto.MissionResDto; +import com.example.umc10th.domain.mission.entity.Mission; +import com.example.umc10th.domain.user.entity.User; +import com.example.umc10th.global.dto.CursorPageResDto; +import org.springframework.data.domain.Slice; + +import java.util.List; + +public class HomeConverter { + + public static HomeResDto.UserInfoResDto toUserInfoResDet(User user) { + int point = user.getUserPoint() == null ? 0 : Integer.parseInt(user.getUserPoint()); + + return new HomeResDto.UserInfoResDto(user.getName(), point); + } + + public static HomeResDto.RegionMissionResDto toRegionMissionResDto( + String regionName, + Slice slice + ) { + List missions = slice.getContent().stream() + .map(HomeConverter::toMissionDto) + .toList(); + + return new HomeResDto.RegionMissionResDto(regionName, CursorPageResDto.of(missions, slice.getNumber(), slice.hasNext())); + } + + private static MissionResDto.MissionDto toMissionDto(Mission mission) { + return new MissionResDto.MissionDto( + mission.getId(), + mission.getBody(), + mission.getAward(), + null + ); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/home/dto/HomeReqDto.java b/luga/src/main/java/com/example/umc10th/domain/home/dto/HomeReqDto.java new file mode 100644 index 0000000..4007ce6 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/home/dto/HomeReqDto.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.home.dto; + +public class HomeReqDto { + + public record UserInfoReqDto(Long userId) {} + + public record RegionMissionReqDto( + Long userId, + String region) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/home/dto/HomeResDto.java b/luga/src/main/java/com/example/umc10th/domain/home/dto/HomeResDto.java new file mode 100644 index 0000000..f8c175d --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/home/dto/HomeResDto.java @@ -0,0 +1,19 @@ +package com.example.umc10th.domain.home.dto; + +import com.example.umc10th.domain.mission.dto.MissionResDto; +import com.example.umc10th.global.dto.CursorPageResDto; + +import java.util.List; + +public class HomeResDto { + + public record UserInfoResDto ( + String name, + Integer point + ) {} + + public record RegionMissionResDto( + String region, + CursorPageResDto missions + ) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/home/exception/HomeException.java b/luga/src/main/java/com/example/umc10th/domain/home/exception/HomeException.java new file mode 100644 index 0000000..d5b4169 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/home/exception/HomeException.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.home.exception; + +public class HomeException extends RuntimeException { + public HomeException(String message) { + super(message); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/home/exception/code/HomeErrorCode.java b/luga/src/main/java/com/example/umc10th/domain/home/exception/code/HomeErrorCode.java new file mode 100644 index 0000000..3f08bb2 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/home/exception/code/HomeErrorCode.java @@ -0,0 +1,17 @@ +package com.example.umc10th.domain.home.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum HomeErrorCode implements BaseErrorCode { + + REGION_NOT_FOUND(HttpStatus.NOT_FOUND, "HOME4001", "해당 지역을 찾을 수 없음"); + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/home/service/HomeService.java b/luga/src/main/java/com/example/umc10th/domain/home/service/HomeService.java new file mode 100644 index 0000000..b7a2573 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/home/service/HomeService.java @@ -0,0 +1,55 @@ +package com.example.umc10th.domain.home.service; + +import com.example.umc10th.domain.home.converter.HomeConverter; +import com.example.umc10th.domain.home.dto.HomeResDto; +import com.example.umc10th.domain.home.exception.code.HomeErrorCode; +import com.example.umc10th.domain.mission.dto.MissionResDto; +import com.example.umc10th.domain.mission.entity.Mission; +import com.example.umc10th.domain.mission.repository.MissionRepository; +import com.example.umc10th.domain.restaurant.entity.Region; +import com.example.umc10th.domain.restaurant.exception.code.RestaurantErrorCode; +import com.example.umc10th.domain.restaurant.repository.RegionRepository; +import com.example.umc10th.domain.user.entity.User; +import com.example.umc10th.domain.user.exception.code.UserErrorCode; +import com.example.umc10th.domain.user.repository.UserRepository; +import com.example.umc10th.global.apiPayload.code.status.ErrorStatus; +import com.example.umc10th.global.apiPayload.exception.GeneralException; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Service +@RequiredArgsConstructor +public class HomeService { + + private final UserRepository userRepository; + private final RegionRepository regionRepository; + private final MissionRepository missionRepository; + + @Transactional(readOnly = true) + public HomeResDto.UserInfoResDto getUserInfo(Long userId) { + + User user = userRepository.findById(userId) + .orElseThrow(() -> new GeneralException(UserErrorCode.MEMBER_NOT_FOUND)); + return HomeConverter.toUserInfoResDet(user); + } + + @Transactional(readOnly = true) + public HomeResDto.RegionMissionResDto getRegionMissions( + Long userId, String regionName, int page, int size) { + + userRepository.findById(userId) + .orElseThrow(() -> new GeneralException(UserErrorCode.MEMBER_NOT_FOUND)); + + Region region = regionRepository.findByName(regionName) + .orElseThrow(() -> new GeneralException(HomeErrorCode.REGION_NOT_FOUND)); + + Slice slice = missionRepository.findMissionsByRegion( + region, PageRequest.of(page, size)); + + return HomeConverter.toRegionMissionResDto(regionName, slice); + } +} \ No newline at end of file diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/controller/MissionController.java b/luga/src/main/java/com/example/umc10th/domain/mission/controller/MissionController.java new file mode 100644 index 0000000..673a4c6 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/controller/MissionController.java @@ -0,0 +1,71 @@ +package com.example.umc10th.domain.mission.controller; + +import com.example.umc10th.domain.mission.dto.MissionReqDto; +import com.example.umc10th.domain.mission.dto.MissionResDto; +import com.example.umc10th.domain.mission.service.MissionService; +import com.example.umc10th.global.apiPayload.ApiResponse; +import com.example.umc10th.global.dto.CursorPageResDto; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDateTime; +import java.util.List; + +@Tag(name = "Mission", description = "'미션 관련 API") +@RestController +@RequestMapping("/api/mission") +@RequiredArgsConstructor +public class MissionController { + + private final MissionService missionService; + + @Operation( + summary = "미션 목록 조회", + description = "상태별 미션 목록 조회", + parameters = { + @Parameter(name = "status", description = "미션 상태", example = "IN_PROGRESS"), + @Parameter(name = "page", description = "페이지 번호 (0부터)", example = "0"), + @Parameter(name = "size", description = "페이지 크기", example = "10") + } + ) + @GetMapping("/{userId}") + public ApiResponse> getMissions( + @PathVariable Long userId, + @RequestParam(defaultValue = "IN_PROGRESS") String status, + @RequestParam(defaultValue = "0") int page, + @RequestParam(defaultValue = "10") int size) { + + return ApiResponse.onSuccess(missionService.getMissions(userId, status, page, size)); + } + + @Operation( + summary = "미션 성공 처리", + description = "미션 ID를 경로 변수로 받아 해당 미션 성공 처리 진행", + parameters = @Parameter(name = "missionId", description = "성공 처리할 미션 ID", example = "1") + ) + @PostMapping("/{userId}/{missionId}/success") + public ApiResponse completeMission( + @PathVariable Long userId, + @PathVariable Long missionId) { + + return ApiResponse.onSuccess(missionService.completeMission(userId, missionId)); + } + + @Operation( + summary = "진행 중인 미션 조회", + description = "진행 중인 미션 목록 조회 (오프셋 페이지네이션)", + parameters = @Parameter(name = "page", description = "페이지 번호 (0부터)", example = "0") + ) + @PostMapping("/my") + public ApiResponse> getMyMissions( + @RequestBody @Valid MissionReqDto.MyMissionReqDto request, + @RequestParam(defaultValue = "0") int page, + @RequestParam(defaultValue = "10") int size) { + return ApiResponse.onSuccess(missionService.getMyMissions(request.userId(), page, size)); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/converter/MissionConverter.java b/luga/src/main/java/com/example/umc10th/domain/mission/converter/MissionConverter.java new file mode 100644 index 0000000..81ec87e --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/converter/MissionConverter.java @@ -0,0 +1,37 @@ +package com.example.umc10th.domain.mission.converter; + +import com.example.umc10th.domain.mission.dto.MissionResDto; +import com.example.umc10th.domain.mission.entity.mapping.UserMission; +import com.example.umc10th.global.dto.CursorPageResDto; +import org.springframework.data.domain.Slice; + +import java.util.List; + +public class MissionConverter { + + public static MissionResDto.MissionDto toMissionDto(UserMission userMission) { + return new MissionResDto.MissionDto( + userMission.getMission().getId(), + userMission.getMission().getBody(), + userMission.getMission().getAward(), + userMission.getMission().getDDay() + ); + } + + // 진행 중인 미션 조회용 + public static MissionResDto.MissionProgressDto toMissionProgressDto(UserMission userMission) { + return new MissionResDto.MissionProgressDto( + userMission.getMission().getId(), + userMission.getMission().getBody(), + Integer.parseInt(userMission.getMission().getAward()), // String → Integer + userMission.getMission().getDDay() + ); + } + + public static MissionResDto.MissionSuccessResDto toMissionSuccessResDto(UserMission userMission) { + return new MissionResDto.MissionSuccessResDto( + userMission.getMission().getId(), + userMission.getCompletedAt() + ); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/dto/MissionReqDto.java b/luga/src/main/java/com/example/umc10th/domain/mission/dto/MissionReqDto.java new file mode 100644 index 0000000..027ef3a --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/dto/MissionReqDto.java @@ -0,0 +1,27 @@ +package com.example.umc10th.domain.mission.dto; + +import jakarta.validation.constraints.NotNull; + +import java.time.LocalDateTime; + +public class MissionReqDto { + + // 미션 생성 + public record CreateMissionReqDto( + Long restaurantId, + Long regionId, + String body, + String award, + LocalDateTime dDay + ) {} + + // 미션 도전 + public record JoinMissionReqDto( + Long missionId + ) {} + + public record MyMissionReqDto( + @NotNull(message = "사용자 Id는 필수!") + Long userId + ) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/dto/MissionResDto.java b/luga/src/main/java/com/example/umc10th/domain/mission/dto/MissionResDto.java new file mode 100644 index 0000000..8b5cc6a --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/dto/MissionResDto.java @@ -0,0 +1,47 @@ +package com.example.umc10th.domain.mission.dto; + +import com.example.umc10th.domain.mission.enums.MissionStatus; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.util.List; + +public class MissionResDto { + + public record MissionDto ( + Long missionId, + String content, + String point, + LocalDateTime endDate + ) {} + + // 진행 중인 미션 조회용 + public record MissionProgressDto( + Long missionId, + String content, + Integer point, + LocalDateTime endDate + ) {} + + // 성공 처리 결과 + public record MissionSuccessResDto ( + Long missionId, + LocalDateTime completedAt + ) {} + + // 미션 생성 결과 + public record CreateMissionResDto ( + Long missionId, + LocalDateTime createdAt + ) {} + + // 미션 참여 결과 + public record JoinMissionResDto( + Long userMissionId, + Long missionId, + MissionStatus status + ) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/entity/Mission.java b/luga/src/main/java/com/example/umc10th/domain/mission/entity/Mission.java new file mode 100644 index 0000000..ecebda2 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/entity/Mission.java @@ -0,0 +1,32 @@ +package com.example.umc10th.domain.mission.entity; + +import com.example.umc10th.domain.restaurant.entity.Restaurant; +import com.example.umc10th.domain.restaurant.entity.Region; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDateTime; + +@Entity +@Table(name = "mission") +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Mission { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "restaurant_id") + private Restaurant restaurant; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "region_id") + private Region region; + + private String body; + private String award; + private LocalDateTime dDay; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/entity/mapping/UserMission.java b/luga/src/main/java/com/example/umc10th/domain/mission/entity/mapping/UserMission.java new file mode 100644 index 0000000..f144c98 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/entity/mapping/UserMission.java @@ -0,0 +1,43 @@ +package com.example.umc10th.domain.mission.entity.mapping; + +import com.example.umc10th.domain.mission.entity.Mission; +import com.example.umc10th.domain.mission.enums.MissionStatus; +import com.example.umc10th.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDateTime; + +@Entity +@Table(name = "user_mission") +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class UserMission { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_id") + private Mission mission; + + @Enumerated(EnumType.STRING) + @Builder.Default + private MissionStatus status = MissionStatus.IN_PROGRESS; + + @Builder.Default + private LocalDateTime createdAt = LocalDateTime.now(); + + private LocalDateTime completedAt; + + public void complete() { + this.status = MissionStatus.COMPLETE; + this.completedAt = LocalDateTime.now(); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/enums/MissionStatus.java b/luga/src/main/java/com/example/umc10th/domain/mission/enums/MissionStatus.java new file mode 100644 index 0000000..56f096d --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/enums/MissionStatus.java @@ -0,0 +1,5 @@ +package com.example.umc10th.domain.mission.enums; + +public enum MissionStatus { + IN_PROGRESS, COMPLETE, EXPIRED +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/exception/MissionException.java b/luga/src/main/java/com/example/umc10th/domain/mission/exception/MissionException.java new file mode 100644 index 0000000..d01099f --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/exception/MissionException.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.mission.exception; + +public class MissionException extends RuntimeException { + public MissionException(String message) { + super(message); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/exception/code/MissionErrorCode.java b/luga/src/main/java/com/example/umc10th/domain/mission/exception/code/MissionErrorCode.java new file mode 100644 index 0000000..92008b0 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/exception/code/MissionErrorCode.java @@ -0,0 +1,19 @@ +package com.example.umc10th.domain.mission.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum MissionErrorCode implements BaseErrorCode { + + MISSION_NOT_FOUND(HttpStatus.NOT_FOUND, "MISSION4001", "미션을 찾을 수 없음"), + MISSION_ALREADY_COMPLETED(HttpStatus.BAD_REQUEST, "MISSION4002", "이미 완료된 미션"), + INVALID_MISSION_STATUS(HttpStatus.BAD_REQUEST, "MISSION4003", "유효하지 않은 미션"); + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/exception/code/MissionSuccessCode.java b/luga/src/main/java/com/example/umc10th/domain/mission/exception/code/MissionSuccessCode.java new file mode 100644 index 0000000..a30e4ea --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/exception/code/MissionSuccessCode.java @@ -0,0 +1,4 @@ +package com.example.umc10th.domain.mission.exception.code; + +public enum MissionSuccessCode { +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/repository/MissionRepository.java b/luga/src/main/java/com/example/umc10th/domain/mission/repository/MissionRepository.java new file mode 100644 index 0000000..baaf189 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/repository/MissionRepository.java @@ -0,0 +1,16 @@ +package com.example.umc10th.domain.mission.repository; + +import com.example.umc10th.domain.mission.entity.Mission; +import com.example.umc10th.domain.restaurant.entity.Region; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface MissionRepository extends JpaRepository { + + // 홈 화면 페이징 : 지역 별 미션 리스트 + @Query("SELECT m FROM Mission m WHERE m.region = :region") + Slice findMissionsByRegion(@Param("region") Region region, Pageable pageable); +} diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/repository/UserMissionRepository.java b/luga/src/main/java/com/example/umc10th/domain/mission/repository/UserMissionRepository.java new file mode 100644 index 0000000..2469371 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/repository/UserMissionRepository.java @@ -0,0 +1,28 @@ +package com.example.umc10th.domain.mission.repository; + +import com.example.umc10th.domain.mission.entity.mapping.UserMission; +import com.example.umc10th.domain.mission.enums.MissionStatus; +import com.example.umc10th.domain.user.entity.User; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface UserMissionRepository extends JpaRepository { + + // 상태별 미션 조회 (Slice - CursorPage용) + @Query("SELECT um FROM UserMission um JOIN FETCH um.mission " + + "WHERE um.user = :user AND um.status = :status") + Slice findByUserAndStatus(@Param("user") User user, + @Param("status") MissionStatus status, + Pageable pageable); + + // 진행 중인 미션 조회 (Page - 오프셋 페이지네이션용) + @Query("SELECT um FROM UserMission um JOIN FETCH um.mission " + + "WHERE um.user = :user AND um.status = :status") + Page findPageByUserAndStatus(@Param("user") User user, + @Param("status") MissionStatus status, + Pageable pageable); +} \ No newline at end of file diff --git a/luga/src/main/java/com/example/umc10th/domain/mission/service/MissionService.java b/luga/src/main/java/com/example/umc10th/domain/mission/service/MissionService.java new file mode 100644 index 0000000..304a4ec --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/mission/service/MissionService.java @@ -0,0 +1,83 @@ +package com.example.umc10th.domain.mission.service; + +import com.example.umc10th.domain.mission.converter.MissionConverter; +import com.example.umc10th.domain.mission.dto.MissionResDto; +import com.example.umc10th.domain.mission.entity.mapping.UserMission; +import com.example.umc10th.domain.mission.enums.MissionStatus; +import com.example.umc10th.domain.mission.exception.code.MissionErrorCode; +import com.example.umc10th.domain.mission.repository.UserMissionRepository; +import com.example.umc10th.domain.user.entity.User; +import com.example.umc10th.domain.user.exception.code.UserErrorCode; +import com.example.umc10th.domain.user.repository.UserRepository; +import com.example.umc10th.global.apiPayload.exception.GeneralException; +import com.example.umc10th.global.dto.CursorPageResDto; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Service +@RequiredArgsConstructor +public class MissionService { + + private final UserMissionRepository userMissionRepository; + private final UserRepository userRepository; + + @Transactional(readOnly = true) + public CursorPageResDto getMissions( + Long userId, String status, int page, int size) { + + User user = userRepository.findById(userId) + .orElseThrow(() -> new GeneralException(UserErrorCode.MEMBER_NOT_FOUND)); + + + MissionStatus missionStatus; + + try{ + missionStatus = MissionStatus.valueOf(status.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new GeneralException(MissionErrorCode.INVALID_MISSION_STATUS); + } + + Slice slice = userMissionRepository.findByUserAndStatus( + user, missionStatus, PageRequest.of(page, size)); + + return CursorPageResDto.of( + slice.getContent().stream() + .map(MissionConverter::toMissionDto) + .toList(), + slice.getNumber(), + slice.hasNext() + ); + } + + // 진행 중인 미션 조회 - Page + @Transactional(readOnly = true) + public Page getMyMissions(Long userId, int page, int size) { + + User user = userRepository.findById(userId) + .orElseThrow(() -> new GeneralException(UserErrorCode.MEMBER_NOT_FOUND)); + + Page userMissions = userMissionRepository.findPageByUserAndStatus( + user, MissionStatus.IN_PROGRESS, PageRequest.of(page, size)); + + return userMissions.map(MissionConverter::toMissionProgressDto); + } + + @Transactional + public MissionResDto.MissionSuccessResDto completeMission(Long userId, Long userMissionId) { + + User user = userRepository.findById(userId) + .orElseThrow(() -> new GeneralException(UserErrorCode.MEMBER_NOT_FOUND)); + + UserMission userMission = userMissionRepository.findById(userMissionId) + .orElseThrow(() -> new GeneralException(MissionErrorCode.MISSION_NOT_FOUND)); + + userMission.complete(); + + return MissionConverter.toMissionSuccessResDto(userMission); + } +} \ No newline at end of file diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/controller/RestaurantController.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/controller/RestaurantController.java new file mode 100644 index 0000000..1299375 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/controller/RestaurantController.java @@ -0,0 +1,33 @@ +package com.example.umc10th.domain.restaurant.controller; + +import com.example.umc10th.domain.restaurant.dto.RestaurantReqDto; +import com.example.umc10th.domain.restaurant.dto.RestaurantResDto; +import com.example.umc10th.domain.restaurant.service.RestaurantService; +import com.example.umc10th.global.apiPayload.ApiResponse; +import com.example.umc10th.global.apiPayload.code.status.SuccessStatus; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "Restaurant", description = "식당 관련 API") +@RestController +@RequestMapping("/api/restaurant") +@RequiredArgsConstructor +public class RestaurantController { + + private final RestaurantService restaurantService; + + @Operation(summary = "식당 생성", description = "지역 ID, 식당명, 주소로 식당 생성") + @PostMapping + public ApiResponse createRestaurant( + @RequestBody RestaurantReqDto.CreateRestaurantReqDto request) { + return ApiResponse.onSuccess(SuccessStatus.CREATED, restaurantService.createRestaurant(request)); + } + + @Operation(summary = "지역 생성") + @PostMapping("/region") + public ApiResponse createRegion(@RequestParam String name) { + return ApiResponse.onSuccess(restaurantService.createRegion(name)); // ✅ service 위임 + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/converter/RestaurantConverter.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/converter/RestaurantConverter.java new file mode 100644 index 0000000..c424a5d --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/converter/RestaurantConverter.java @@ -0,0 +1,26 @@ +package com.example.umc10th.domain.restaurant.converter; + +import com.example.umc10th.domain.restaurant.dto.RestaurantReqDto; +import com.example.umc10th.domain.restaurant.dto.RestaurantResDto; +import com.example.umc10th.domain.restaurant.entity.Region; +import com.example.umc10th.domain.restaurant.entity.Restaurant; + +import java.time.LocalDateTime; + +public class RestaurantConverter { + + public static Restaurant toRestaurant(RestaurantReqDto.CreateRestaurantReqDto request, Region region) { + return Restaurant.builder() + .region(region) + .name(request.name()) + .address(request.address()) + .build(); + } + + public static RestaurantResDto.CreateRestaurantResDto toCreateRestaurantResDto(Restaurant restaurant) { + return new RestaurantResDto.CreateRestaurantResDto( + restaurant.getId(), + LocalDateTime.now() + ); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/dto/RestaurantReqDto.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/dto/RestaurantReqDto.java new file mode 100644 index 0000000..6eab4ee --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/dto/RestaurantReqDto.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.restaurant.dto; + +public class RestaurantReqDto { + + public record CreateRestaurantReqDto( + Long regionId, + String name, + String address + ) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/dto/RestaurantResDto.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/dto/RestaurantResDto.java new file mode 100644 index 0000000..e240b51 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/dto/RestaurantResDto.java @@ -0,0 +1,19 @@ +package com.example.umc10th.domain.restaurant.dto; + +import java.util.List; + +public class RestaurantResDto { + + public record RestaurantDto( + Long restaurantId, + Long regionId, + String name, + String address, + String addressDetail + ) {} + + public record CreateRestaurantResDto( + Long restaurantId, + java.time.LocalDateTime createdAt + ) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/entity/Region.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/entity/Region.java new file mode 100644 index 0000000..0fa0488 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/entity/Region.java @@ -0,0 +1,19 @@ +package com.example.umc10th.domain.restaurant.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name = "region") +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Region { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/entity/Restaurant.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/entity/Restaurant.java new file mode 100644 index 0000000..42c4b13 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/entity/Restaurant.java @@ -0,0 +1,25 @@ +package com.example.umc10th.domain.restaurant.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name = "restaurant") +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Restaurant { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "region_id") + private Region region; + + private String name; + private String address; + private String addressDetail; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/exception/RestaurantException.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/exception/RestaurantException.java new file mode 100644 index 0000000..ecabf3d --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/exception/RestaurantException.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.restaurant.exception; + +public class RestaurantException extends RuntimeException { + public RestaurantException(String message) { + super(message); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/exception/code/RestaurantErrorCode.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/exception/code/RestaurantErrorCode.java new file mode 100644 index 0000000..ebe70ea --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/exception/code/RestaurantErrorCode.java @@ -0,0 +1,17 @@ +package com.example.umc10th.domain.restaurant.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum RestaurantErrorCode implements BaseErrorCode { + + RESTAURANT_NOT_FOUND(HttpStatus.NOT_FOUND, "RESTAURANT4001", "식당을 찾을 수 없음"); + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/exception/code/RestaurantSuccessCode.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/exception/code/RestaurantSuccessCode.java new file mode 100644 index 0000000..2af2d31 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/exception/code/RestaurantSuccessCode.java @@ -0,0 +1,4 @@ +package com.example.umc10th.domain.restaurant.exception.code; + +public enum RestaurantSuccessCode { +} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/repository/RegionRepository.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/repository/RegionRepository.java new file mode 100644 index 0000000..7c2a67d --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/repository/RegionRepository.java @@ -0,0 +1,9 @@ +package com.example.umc10th.domain.restaurant.repository; + +import com.example.umc10th.domain.restaurant.entity.Region; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + +public interface RegionRepository extends JpaRepository { + Optional findByName(String name); +} \ No newline at end of file diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/repository/RestaurantRepository.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/repository/RestaurantRepository.java new file mode 100644 index 0000000..e65de00 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/repository/RestaurantRepository.java @@ -0,0 +1,6 @@ +package com.example.umc10th.domain.restaurant.repository; + +import com.example.umc10th.domain.restaurant.entity.Restaurant; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RestaurantRepository extends JpaRepository {} diff --git a/luga/src/main/java/com/example/umc10th/domain/restaurant/service/RestaurantService.java b/luga/src/main/java/com/example/umc10th/domain/restaurant/service/RestaurantService.java new file mode 100644 index 0000000..527b5d0 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/restaurant/service/RestaurantService.java @@ -0,0 +1,42 @@ +package com.example.umc10th.domain.restaurant.service; + +import com.example.umc10th.domain.restaurant.converter.RestaurantConverter; +import com.example.umc10th.domain.restaurant.dto.RestaurantReqDto; +import com.example.umc10th.domain.restaurant.dto.RestaurantResDto; +import com.example.umc10th.domain.restaurant.entity.Region; +import com.example.umc10th.domain.restaurant.entity.Restaurant; +import com.example.umc10th.domain.restaurant.exception.code.RestaurantErrorCode; +import com.example.umc10th.domain.restaurant.repository.RegionRepository; +import com.example.umc10th.domain.restaurant.repository.RestaurantRepository; +import com.example.umc10th.global.apiPayload.exception.GeneralException; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class RestaurantService { + + private final RestaurantRepository restaurantRepository; + private final RegionRepository regionRepository; + + @Transactional + public RestaurantResDto.CreateRestaurantResDto createRestaurant( + RestaurantReqDto.CreateRestaurantReqDto request) { + + Region region = regionRepository.findById(request.regionId()) + .orElseThrow(() -> new GeneralException(RestaurantErrorCode.RESTAURANT_NOT_FOUND)); + + Restaurant restaurant = RestaurantConverter.toRestaurant(request, region); + Restaurant saved = restaurantRepository.save(restaurant); + + return RestaurantConverter.toCreateRestaurantResDto(saved); + } + + // 지역 생성 + @Transactional + public Long createRegion(String name) { + Region region = Region.builder().name(name).build(); + return regionRepository.save(region).getId(); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/controller/ReviewController.java b/luga/src/main/java/com/example/umc10th/domain/review/controller/ReviewController.java new file mode 100644 index 0000000..ea41613 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/controller/ReviewController.java @@ -0,0 +1,57 @@ +package com.example.umc10th.domain.review.controller; + +import com.example.umc10th.domain.review.dto.ReviewReqDto; +import com.example.umc10th.domain.review.dto.ReviewResDto; +import com.example.umc10th.domain.review.service.ReviewService; +import com.example.umc10th.global.apiPayload.ApiResponse; +import com.example.umc10th.global.apiPayload.code.status.SuccessStatus; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "Review", description = "리뷰 관련 API") +@RestController +@RequestMapping("/api/review") +@RequiredArgsConstructor +public class ReviewController { + + private final ReviewService reviewService; + + @Operation( + summary = "리뷰 작성", + description = "식당 ID를 경로 변수로 받아 해당 식당에 리뷰 작성", + parameters = @Parameter(name = "restaurantId", description = "리뷰를 작성할 식당의 Id", example = "1") + ) + @PostMapping("/{restaurantId}/reviews/{userId}") + public ApiResponse createReview( + @PathVariable Long restaurantId, + @PathVariable Long userId, + @RequestBody @Valid ReviewReqDto.CreateReviewReqDto request) { + return ApiResponse.onSuccess(SuccessStatus.CREATED, reviewService.createReview(restaurantId, userId, request)); + } + + @Operation( + summary = "내 리뷰 목록 조회", + description = "ID순 또는 별점순 정렬", + parameters = { + @Parameter(name = "memberId", description = "사용자 ID", example = "1", required = true), + @Parameter(name = "sort", description = "정렬 기준 (id | stars)", example = "id", required = true), + @Parameter(name = "cursor", description = "마지막으로 본 커서값 (첫 요청 시 생략)"), + @Parameter(name = "cursorGrade", description = "마지막으로 본 리뷰 별점 (stars 정렬 시 cursor와 함께 필요)"), + @Parameter(name = "size", description = "페이지 크기", example = "3") + } + ) + @GetMapping("/my") + public ApiResponse getMyReviews( + @RequestParam Long memberId, + @RequestParam(defaultValue = "id") String sort, // 기본값 = id + @RequestParam(required = false) Long cursor, // ID순 커서 + @RequestParam(required = false) Integer cursorGrade, // 별점순 커서 (stars 정렬 시) + @RequestParam(defaultValue = "10") int size) { + return ApiResponse.onSuccess( + reviewService.getMyReviews(memberId, sort, cursor, cursorGrade, size)); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/converter/ReviewConverter.java b/luga/src/main/java/com/example/umc10th/domain/review/converter/ReviewConverter.java new file mode 100644 index 0000000..f399ab0 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/converter/ReviewConverter.java @@ -0,0 +1,44 @@ +package com.example.umc10th.domain.review.converter; + +import com.example.umc10th.domain.review.dto.ReviewResDto; +import com.example.umc10th.domain.review.entity.Review; +import com.example.umc10th.global.dto.CursorPageResDto; +import org.springframework.data.domain.Slice; + +import java.util.List; + +public class ReviewConverter { + + public static ReviewResDto.CreateReviewResDto toCreateReviewResDto(Review review) { + return new ReviewResDto.CreateReviewResDto( + review.getId(), + review.getDate() + ); + } + + public static ReviewResDto.ReviewDto toReviewDto(Review review) { + return new ReviewResDto.ReviewDto( + review.getId(), + review.getGrade(), + review.getBody(), + review.getRestaurant().getName() + ); + } + + public static ReviewResDto.ReviewListResDto toReviewListResDto(Slice slice) { + List reviews = slice.getContent().stream() + .map(ReviewConverter::toReviewDto) + .toList(); + + Review lastReview = slice.hasNext() + ? slice.getContent().get(slice.getContent().size() - 1) + : null; + + return new ReviewResDto.ReviewListResDto( + reviews, + lastReview != null ? lastReview.getId() : null, + lastReview != null ? lastReview.getGrade() : null, + slice.hasNext() + ); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/dto/ReviewReqDto.java b/luga/src/main/java/com/example/umc10th/domain/review/dto/ReviewReqDto.java new file mode 100644 index 0000000..7fa7fbe --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/dto/ReviewReqDto.java @@ -0,0 +1,9 @@ +package com.example.umc10th.domain.review.dto; + +public class ReviewReqDto { + + public record CreateReviewReqDto( + String body, + Integer grade + ) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/dto/ReviewResDto.java b/luga/src/main/java/com/example/umc10th/domain/review/dto/ReviewResDto.java new file mode 100644 index 0000000..599c320 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/dto/ReviewResDto.java @@ -0,0 +1,26 @@ +package com.example.umc10th.domain.review.dto; + +import java.time.LocalDate; +import java.util.List; + +public class ReviewResDto { + + public record CreateReviewResDto ( + Long reviewId, + LocalDate date + ) {} + + public record ReviewDto( + Long reviewId, + Integer stars, + String content, + String restaurantName + ) {} + + public record ReviewListResDto( + List content, + Long nextCursorID, + Integer nextCursorGrade, + boolean hasNext + ) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/entity/Review.java b/luga/src/main/java/com/example/umc10th/domain/review/entity/Review.java new file mode 100644 index 0000000..02efa35 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/entity/Review.java @@ -0,0 +1,37 @@ +package com.example.umc10th.domain.review.entity; + +import com.example.umc10th.domain.restaurant.entity.Region; +import com.example.umc10th.domain.restaurant.entity.Restaurant; +import com.example.umc10th.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.*; +import java.time.LocalDate; + +@Entity +@Table(name = "review") +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Review { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "restaurant_id") + private Restaurant restaurant; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "region_id") + private Region region; + + private String body; + private Integer grade; + private LocalDate date; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/exception/ReviewException.java b/luga/src/main/java/com/example/umc10th/domain/review/exception/ReviewException.java new file mode 100644 index 0000000..1664f68 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/exception/ReviewException.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.review.exception; + +public class ReviewException extends RuntimeException { + public ReviewException(String message) { + super(message); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/exception/code/ReviewErrorCode.java b/luga/src/main/java/com/example/umc10th/domain/review/exception/code/ReviewErrorCode.java new file mode 100644 index 0000000..2391257 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/exception/code/ReviewErrorCode.java @@ -0,0 +1,17 @@ +package com.example.umc10th.domain.review.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ReviewErrorCode implements BaseErrorCode { + REVIEW_NOT_FOUND(HttpStatus.NOT_FOUND, "REVIEW4001", "리뷰를 찾을 수 없음"), + INVALID_SORT_TYPE(HttpStatus.BAD_REQUEST, "REVIEW4002", "유효하지 않은 리뷰"); + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/exception/code/ReviewSuccessCode.java b/luga/src/main/java/com/example/umc10th/domain/review/exception/code/ReviewSuccessCode.java new file mode 100644 index 0000000..079c705 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/exception/code/ReviewSuccessCode.java @@ -0,0 +1,17 @@ +package com.example.umc10th.domain.review.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseSuccessCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ReviewSuccessCode implements BaseSuccessCode { + + UPLOAD_SUCCESS(HttpStatus.CREATED, "REVIEW2001", "리뷰 등록 성공"); + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/repository/ReviewRepository.java b/luga/src/main/java/com/example/umc10th/domain/review/repository/ReviewRepository.java new file mode 100644 index 0000000..0e0f6ab --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/repository/ReviewRepository.java @@ -0,0 +1,34 @@ +package com.example.umc10th.domain.review.repository; + +import com.example.umc10th.domain.review.entity.Review; +import com.example.umc10th.domain.user.entity.User; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; + +public interface ReviewRepository extends JpaRepository { + + // Id 내림차순 커서 페이지네이션 + @Query("SELECT r FROM Review r JOIN FETCH r.restaurant " + + "WHERE r.user = :user " + + "AND (:cursorId IS NULL OR r.id < :cursorId) " + + "ORDER BY r.id DESC") + + Slice findByUserOrderById(@Param("user") User user, + @Param("cursorId") Long cursorId, + Pageable pageable); + + // 별점 내림차순 커서 페이지네이션 + @Query("SELECT r FROM Review r JOIN FETCH r.restaurant " + + "WHERE r.user = :user " + + "AND (:cursor IS NULL OR r.grade < :cursorGrade) " + + "OR (r.grade = :cursorGrage AND r.id < :cursorId)" + + "ORDER BY r.grade DESC, r.id DESC") + Slice findByUserOrderByGrade(@Param("user") User user, + @Param("cursorGrade") Integer cursorGrade, + @Param("cursorId") Long cursorId, + Pageable pageable); +} diff --git a/luga/src/main/java/com/example/umc10th/domain/review/service/ReviewService.java b/luga/src/main/java/com/example/umc10th/domain/review/service/ReviewService.java new file mode 100644 index 0000000..e5bb414 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/review/service/ReviewService.java @@ -0,0 +1,85 @@ +package com.example.umc10th.domain.review.service; + +import com.example.umc10th.domain.restaurant.entity.Restaurant; +import com.example.umc10th.domain.restaurant.exception.code.RestaurantErrorCode; +import com.example.umc10th.domain.restaurant.repository.RestaurantRepository; +import com.example.umc10th.domain.review.converter.ReviewConverter; +import com.example.umc10th.domain.review.dto.ReviewReqDto; +import com.example.umc10th.domain.review.dto.ReviewResDto; +import com.example.umc10th.domain.review.entity.Review; +import com.example.umc10th.domain.review.exception.code.ReviewErrorCode; +import com.example.umc10th.domain.review.repository.ReviewRepository; +import com.example.umc10th.domain.user.entity.User; +import com.example.umc10th.domain.user.exception.code.UserErrorCode; +import com.example.umc10th.domain.user.repository.UserRepository; +import com.example.umc10th.global.apiPayload.exception.GeneralException; +import com.example.umc10th.global.dto.CursorPageResDto; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class ReviewService { + + private final ReviewRepository reviewRepository; + private final RestaurantRepository restaurantRepository; + private final UserRepository userRepository; + + @Transactional + public ReviewResDto.CreateReviewResDto createReview(Long restaurantId, + Long userId, + ReviewReqDto.CreateReviewReqDto request) { + Restaurant restaurant = restaurantRepository.findById(restaurantId) + .orElseThrow(() -> new GeneralException(RestaurantErrorCode.RESTAURANT_NOT_FOUND)); + + + User user = userRepository.findById(userId) + .orElseThrow(() -> new GeneralException(UserErrorCode.MEMBER_NOT_FOUND)); + + Review review = Review.builder() + .body(request.body()) + .grade(request.grade()) + .restaurant(restaurant) + .user(user) + .build(); + + Review saved = reviewRepository.save(review); + + return ReviewConverter.toCreateReviewResDto(saved); + } + + @Transactional(readOnly = true) + public ReviewResDto.ReviewListResDto getMyReviews( + Long userId, String sort, Long cursorId, Integer cursorGrade, int size) { + + User user = userRepository.findById(userId) + .orElseThrow(() -> new GeneralException(UserErrorCode.MEMBER_NOT_FOUND)); + + // sort null 검즘 + if(sort == null ){ + throw new GeneralException(ReviewErrorCode.INVALID_SORT_TYPE); + } + + Slice slice; + + switch (sort.toLowerCase()) { + case "id" -> slice = reviewRepository.findByUserOrderById( + user, + cursorId, + PageRequest.of(0, size) + ); + case "stars" -> slice = reviewRepository.findByUserOrderByGrade( + user, + cursorGrade, + cursorId, + PageRequest.of(0, size) + ); + default -> throw new GeneralException(ReviewErrorCode.INVALID_SORT_TYPE); + } + + return ReviewConverter.toReviewListResDto(slice); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/controller/UserController.java b/luga/src/main/java/com/example/umc10th/domain/user/controller/UserController.java new file mode 100644 index 0000000..43679d5 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/controller/UserController.java @@ -0,0 +1,39 @@ +package com.example.umc10th.domain.user.controller; + +import com.example.umc10th.domain.user.dto.UserReqDto; +import com.example.umc10th.domain.user.dto.UserResDto; +import com.example.umc10th.domain.user.service.UserService; +import com.example.umc10th.global.apiPayload.ApiResponse; +import com.example.umc10th.global.apiPayload.code.status.SuccessStatus; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDateTime; + +@Tag(name = "User", description = "유저 관련 API") +@RestController +@RequestMapping("/api/user") +@RequiredArgsConstructor +public class UserController { + + private final UserService userService; + + @Operation(summary = "회원가입", description = "이름, 이메일, 전화번호, 주소로 회원가입") + @PostMapping("/signup") + public ApiResponse signup( + @RequestBody @Valid UserReqDto.SignupReqDto request) { + return ApiResponse.onSuccess(SuccessStatus.CREATED, userService.signup(request)); + } + + @Operation(summary = "선호 음식 등록", description = "유저 ID와 선호 음식 타입 목록으로 선호 음식 등록") + @PostMapping("/{userId}/food-preferences") + public ApiResponse addFoodPreference( + @PathVariable Long userId, + @RequestBody UserReqDto.AddFoodPreferenceReqDto request) { + return ApiResponse.onSuccess(SuccessStatus.CREATED, + userService.addFoodPreference(userId, request)); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/converter/UserConverter.java b/luga/src/main/java/com/example/umc10th/domain/user/converter/UserConverter.java new file mode 100644 index 0000000..15a54d2 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/converter/UserConverter.java @@ -0,0 +1,34 @@ +package com.example.umc10th.domain.user.converter; + +import com.example.umc10th.domain.user.dto.UserReqDto; +import com.example.umc10th.domain.user.dto.UserResDto; +import com.example.umc10th.domain.user.entity.User; + +import java.util.List; + +public class UserConverter { + + public static User toUser(UserReqDto.SignupReqDto request) { + return User.builder() + .name(request.name()) + .email(request.email()) + .phone(request.phone()) + .address(request.address()) + .addressDetail(request.addressDetail()) + .gender(request.gender()) + .birth(request.birth()) + .socialLogin(request.socialLogin()) + .build(); + } + + public static UserResDto.SignupResDto toSignupResDto(User user) { + return new UserResDto.SignupResDto( + user.getId(), + user.getCreatedAt() + ); + } + + public static UserResDto.AddFoodPreferenceResDto toAddFoodPreferenceResDto(Long userId, List foodTypes) { + return new UserResDto.AddFoodPreferenceResDto(userId, foodTypes); + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/dto/UserReqDto.java b/luga/src/main/java/com/example/umc10th/domain/user/dto/UserReqDto.java new file mode 100644 index 0000000..1d514ea --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/dto/UserReqDto.java @@ -0,0 +1,25 @@ +package com.example.umc10th.domain.user.dto; + +import com.example.umc10th.domain.user.enums.Gender; +import com.example.umc10th.domain.user.enums.SocialLogin; + +import java.time.LocalDate; + +public class UserReqDto { + + public record SignupReqDto ( + String name, + String email, + String phone, + String address, + String addressDetail, + Gender gender, + LocalDate birth, + SocialLogin socialLogin + ) {} + + // 선호 음식 등록 + public record AddFoodPreferenceReqDto( + java.util.List foodTypes + ) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/dto/UserResDto.java b/luga/src/main/java/com/example/umc10th/domain/user/dto/UserResDto.java new file mode 100644 index 0000000..34a2000 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/dto/UserResDto.java @@ -0,0 +1,28 @@ +package com.example.umc10th.domain.user.dto; + +import java.time.LocalDateTime; +import java.util.List; + +public class UserResDto { + + public record SignupResDto ( + Long userId, + LocalDateTime createdAt + ) {} + + // 마이페이지 프로필 + public record MyPageResDto( + Long userId, + String name, + String email, + String phone, + String address, + Integer point + ) {} + + // 선호 음식 등록 결과 + public record AddFoodPreferenceResDto( + Long userId, + List foodTypes + ) {} +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/entity/Agreement.java b/luga/src/main/java/com/example/umc10th/domain/user/entity/Agreement.java new file mode 100644 index 0000000..dd4f223 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/entity/Agreement.java @@ -0,0 +1,26 @@ +package com.example.umc10th.domain.user.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Table(name = "agreement") +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Agreement { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Builder.Default private Integer agreeAge14 = 0; + @Builder.Default private Integer agreeService = 0; + @Builder.Default private Integer agreePrivate = 0; + @Builder.Default private Integer agreeLocation = 0; + @Builder.Default private Integer agreeMarketing = 0; + @Builder.Default private Integer agreeEventAlarm = 0; + @Builder.Default private Integer agreeReviewAlarm = 0; + @Builder.Default private Integer agreeQaAlarm = 0; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/entity/FoodType.java b/luga/src/main/java/com/example/umc10th/domain/user/entity/FoodType.java new file mode 100644 index 0000000..adeef20 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/entity/FoodType.java @@ -0,0 +1,4 @@ +package com.example.umc10th.domain.user.entity; + +public class FoodType { +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/entity/User.java b/luga/src/main/java/com/example/umc10th/domain/user/entity/User.java new file mode 100644 index 0000000..9f7df9b --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/entity/User.java @@ -0,0 +1,51 @@ +package com.example.umc10th.domain.user.entity; + +import com.example.umc10th.domain.user.enums.Gender; +import com.example.umc10th.domain.user.enums.SocialLogin; +import jakarta.persistence.*; +import lombok.*; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Entity +@Table(name = "users") +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + @Enumerated(EnumType.STRING) + private Gender gender; + + private LocalDate birth; + private String address; + private String addressDetail; + private String email; + private String phone; + + @Builder.Default + private Integer phoneChecked = 0; + + @Enumerated(EnumType.STRING) + private SocialLogin socialLogin; + + private String userPoint; + + @Builder.Default + private Integer newAlarm = 0; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "agree_id") + private Agreement agreement; + + @Builder.Default + private LocalDateTime createdAt = LocalDateTime.now(); +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/entity/mapping/FoodPreference.java b/luga/src/main/java/com/example/umc10th/domain/user/entity/mapping/FoodPreference.java new file mode 100644 index 0000000..3c71060 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/entity/mapping/FoodPreference.java @@ -0,0 +1,4 @@ +package com.example.umc10th.domain.user.entity.mapping; + +public class FoodPreference { +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/enums/Gender.java b/luga/src/main/java/com/example/umc10th/domain/user/enums/Gender.java new file mode 100644 index 0000000..1878f25 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/enums/Gender.java @@ -0,0 +1,5 @@ +package com.example.umc10th.domain.user.enums; + +public enum Gender { + MALE, FEMALE, NONE +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/enums/SocialLogin.java b/luga/src/main/java/com/example/umc10th/domain/user/enums/SocialLogin.java new file mode 100644 index 0000000..69222b5 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/enums/SocialLogin.java @@ -0,0 +1,5 @@ +package com.example.umc10th.domain.user.enums; + +public enum SocialLogin { + KAKAO, NAVER, APPLE, GOOGLE +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/exception/UserException.java b/luga/src/main/java/com/example/umc10th/domain/user/exception/UserException.java new file mode 100644 index 0000000..7c795c1 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/exception/UserException.java @@ -0,0 +1,17 @@ +package com.example.umc10th.domain.user.exception; + + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import lombok.Getter; + +@Getter +public class UserException extends RuntimeException { + + private final BaseErrorCode errorCode; + + public UserException(BaseErrorCode errorCode) + { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/exception/code/UserErrorCode.java b/luga/src/main/java/com/example/umc10th/domain/user/exception/code/UserErrorCode.java new file mode 100644 index 0000000..1b790e2 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/exception/code/UserErrorCode.java @@ -0,0 +1,18 @@ +package com.example.umc10th.domain.user.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum UserErrorCode implements BaseErrorCode { + + MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "MEMBER4001", "사용자를 찾을 수 없음"), + MEMBER_ALREADY_EXISTS(HttpStatus.BAD_REQUEST, "MEMBER4002", "이미 존재하는 회원임"); + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/exception/code/UserSuccessCode.java b/luga/src/main/java/com/example/umc10th/domain/user/exception/code/UserSuccessCode.java new file mode 100644 index 0000000..d7b93b2 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/exception/code/UserSuccessCode.java @@ -0,0 +1,18 @@ +package com.example.umc10th.domain.user.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseSuccessCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum UserSuccessCode implements BaseSuccessCode { + + SIGNUP_SUCCESS(HttpStatus.CREATED, "MEMBER2001", "회원가입 성공"), + USER_FOUND(HttpStatus.OK, "MEMBER2002", "사용자 조회 성공"); + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/repository/UserRepository.java b/luga/src/main/java/com/example/umc10th/domain/user/repository/UserRepository.java new file mode 100644 index 0000000..b7e9486 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/repository/UserRepository.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.user.repository; + +import com.example.umc10th.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { + + // 이메일로 유저 존재 여부 검사 + boolean existsByEmail(String email); +} diff --git a/luga/src/main/java/com/example/umc10th/domain/user/service/UserService.java b/luga/src/main/java/com/example/umc10th/domain/user/service/UserService.java new file mode 100644 index 0000000..ca7934f --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/domain/user/service/UserService.java @@ -0,0 +1,45 @@ +package com.example.umc10th.domain.user.service; + +import com.example.umc10th.domain.user.converter.UserConverter; +import com.example.umc10th.domain.user.dto.UserReqDto; +import com.example.umc10th.domain.user.dto.UserResDto; +import com.example.umc10th.domain.user.entity.User; +import com.example.umc10th.domain.user.exception.code.UserErrorCode; +import com.example.umc10th.domain.user.repository.UserRepository; +import com.example.umc10th.global.apiPayload.code.status.ErrorStatus; +import com.example.umc10th.global.apiPayload.exception.GeneralException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class UserService { + + private final UserRepository userRepository; + + @Transactional + public UserResDto.SignupResDto signup(UserReqDto.SignupReqDto request) { + + if (userRepository.existsByEmail(request.email())) { + throw new GeneralException(UserErrorCode.MEMBER_ALREADY_EXISTS); + } + + User user = UserConverter.toUser(request); + User saved = userRepository.save(user); + + return UserConverter.toSignupResDto(saved); + } + + @Transactional + public UserResDto.AddFoodPreferenceResDto addFoodPreference( + Long userId, UserReqDto.AddFoodPreferenceReqDto request) { + + User user = userRepository.findById(userId) + .orElseThrow(() -> new GeneralException(UserErrorCode.MEMBER_NOT_FOUND)); + + // 선호 음식 저장 로직 (FoodPreference 엔티티/레포지토리 연동 필요) + + return UserConverter.toAddFoodPreferenceResDto(userId, request.foodTypes()); + } +} diff --git a/luga/src/main/java/com/example/umc10th/global/apiPayload/ApiResponse.java b/luga/src/main/java/com/example/umc10th/global/apiPayload/ApiResponse.java new file mode 100644 index 0000000..eefb2ea --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/global/apiPayload/ApiResponse.java @@ -0,0 +1,50 @@ +package com.example.umc10th.global.apiPayload; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import com.example.umc10th.global.apiPayload.code.BaseSuccessCode; +import com.example.umc10th.global.apiPayload.code.status.SuccessStatus; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.Getter; + +@Getter +@JsonPropertyOrder({"isSuccess", "code", "message", "result"}) +public class ApiResponse { + + @JsonProperty("isSuccess") + private final Boolean isSuccess; + private final String code; + private final String message; + private final T result; + + private ApiResponse(Boolean isSuccess, String code, String message, T result) { + this.isSuccess = isSuccess; + this.code = code; + this.message = message; + this.result = result; + } + + // 성공 with result + public static ApiResponse onSuccess(T result) { + return new ApiResponse<>(true, + SuccessStatus.OK.getCode(), + SuccessStatus.OK.getMessage(), + result); + } + + // 성공, successCode 지정 + public static ApiResponse onSuccess(BaseSuccessCode code, T result) { + return new ApiResponse<>(true, + code.getCode(), + code.getMessage(), + result); + } + + // 실패 + public static ApiResponse onFailure(BaseErrorCode code, T result ) { + return new ApiResponse<>(false, + code.getCode(), + code.getMessage(), + result); + } +} diff --git a/luga/src/main/java/com/example/umc10th/global/apiPayload/code/BaseErrorCode.java b/luga/src/main/java/com/example/umc10th/global/apiPayload/code/BaseErrorCode.java new file mode 100644 index 0000000..137c8ac --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/global/apiPayload/code/BaseErrorCode.java @@ -0,0 +1,9 @@ +package com.example.umc10th.global.apiPayload.code; + +import org.springframework.http.HttpStatus; + +public interface BaseErrorCode { + HttpStatus getStatus(); + String getCode(); + String getMessage(); +} diff --git a/luga/src/main/java/com/example/umc10th/global/apiPayload/code/BaseSuccessCode.java b/luga/src/main/java/com/example/umc10th/global/apiPayload/code/BaseSuccessCode.java new file mode 100644 index 0000000..038eb92 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/global/apiPayload/code/BaseSuccessCode.java @@ -0,0 +1,9 @@ +package com.example.umc10th.global.apiPayload.code; + +import org.springframework.http.HttpStatus; + +public interface BaseSuccessCode { + HttpStatus getStatus(); + String getCode(); + String getMessage(); +} diff --git a/luga/src/main/java/com/example/umc10th/global/apiPayload/code/status/ErrorStatus.java b/luga/src/main/java/com/example/umc10th/global/apiPayload/code/status/ErrorStatus.java new file mode 100644 index 0000000..795daae --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/global/apiPayload/code/status/ErrorStatus.java @@ -0,0 +1,22 @@ +package com.example.umc10th.global.apiPayload.code.status; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ErrorStatus implements BaseErrorCode { + + // 공통 + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON500", "서버 에러 발생"), + BAD_REQUEST(HttpStatus.BAD_REQUEST, "COMMON400", "잘못된 요청"), + UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "COMMON401", "인증 필요"), + FORBIDDEN(HttpStatus.FORBIDDEN, "COMMON403", "접근 권한 없음"), + NOT_FOUND(HttpStatus.NOT_FOUND, "COMMON404", "요청한 리소스를 찾을 수 없음"); + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/luga/src/main/java/com/example/umc10th/global/apiPayload/code/status/SuccessStatus.java b/luga/src/main/java/com/example/umc10th/global/apiPayload/code/status/SuccessStatus.java new file mode 100644 index 0000000..7703c9a --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/global/apiPayload/code/status/SuccessStatus.java @@ -0,0 +1,18 @@ +package com.example.umc10th.global.apiPayload.code.status; + +import com.example.umc10th.global.apiPayload.code.BaseSuccessCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum SuccessStatus implements BaseSuccessCode { + + OK(HttpStatus.OK, "COMMON200", "요청 성공"), + CREATED(HttpStatus.CREATED, "COMMON201", "생성 성공"); + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/luga/src/main/java/com/example/umc10th/global/apiPayload/exception/GeneralException.java b/luga/src/main/java/com/example/umc10th/global/apiPayload/exception/GeneralException.java new file mode 100644 index 0000000..fbbfd60 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/global/apiPayload/exception/GeneralException.java @@ -0,0 +1,14 @@ +package com.example.umc10th.global.apiPayload.exception; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import lombok.Getter; + +@Getter +public class GeneralException extends RuntimeException { + private final BaseErrorCode errorCode; + + public GeneralException(BaseErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } +} diff --git a/luga/src/main/java/com/example/umc10th/global/config/SwaggerConfig.java b/luga/src/main/java/com/example/umc10th/global/config/SwaggerConfig.java new file mode 100644 index 0000000..888cad0 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/global/config/SwaggerConfig.java @@ -0,0 +1,36 @@ +package com.example.umc10th.global.config; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.oas.models.servers.Server; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + + @Bean + public OpenAPI swagger() { + Info info = new Info().title("UMC10th").description("4주차 미션 Swagger").version("0.0.1"); + + // JWT 토큰 헤더 방식 + String securityScheme = "JWT TOKEN"; + SecurityRequirement securityRequirement = new SecurityRequirement().addList(securityScheme); + + Components components = new Components() + .addSecuritySchemes(securityScheme, new SecurityScheme() + .name(securityScheme) + .type(SecurityScheme.Type.HTTP) + .scheme("Bearer") + .bearerFormat("JWT")); + + return new OpenAPI() + .info(info) + .addServersItem(new Server().url("/")) + .addSecurityItem(securityRequirement) + .components(components); + } +} diff --git a/luga/src/main/java/com/example/umc10th/global/dto/CursorPageResDto.java b/luga/src/main/java/com/example/umc10th/global/dto/CursorPageResDto.java new file mode 100644 index 0000000..d40c011 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/global/dto/CursorPageResDto.java @@ -0,0 +1,14 @@ +package com.example.umc10th.global.dto; + +import java.util.List; + +// 공용 페이징 Dto +public record CursorPageResDto ( + List content, + int currentPage, + boolean hasNext +) { + public static CursorPageResDto of(List content, int currentPage, boolean hasNext) { + return new CursorPageResDto<>(content, currentPage, hasNext); + } +} diff --git a/luga/src/main/java/com/example/umc10th/global/handler/GeneralExceptionAdvice.java b/luga/src/main/java/com/example/umc10th/global/handler/GeneralExceptionAdvice.java new file mode 100644 index 0000000..b54ed22 --- /dev/null +++ b/luga/src/main/java/com/example/umc10th/global/handler/GeneralExceptionAdvice.java @@ -0,0 +1,83 @@ +package com.example.umc10th.global.handler; + +import com.example.umc10th.global.apiPayload.ApiResponse; +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import com.example.umc10th.global.apiPayload.code.status.ErrorStatus; +import com.example.umc10th.global.apiPayload.exception.GeneralException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingServletRequestParameterException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.NoHandlerFoundException; + +import java.util.stream.Collectors; + +@RestControllerAdvice +public class GeneralExceptionAdvice { + + // 커스텀 예외 처리 + @ExceptionHandler(GeneralException.class) + public ResponseEntity> handleGeneralException(GeneralException e) { + BaseErrorCode errorCode = e.getErrorCode(); + return ResponseEntity + .status(errorCode.getStatus()) + .body(ApiResponse.onFailure(errorCode, null)); + } + + // 존재하지 않는 URL + @ExceptionHandler(NoHandlerFoundException.class) + public ResponseEntity> handleNoHandlerFound(NoHandlerFoundException e) { + BaseErrorCode code = ErrorStatus.NOT_FOUND; + return ResponseEntity + .status(code.getStatus()) + .body(ApiResponse.onFailure(code, null)); + } + + // 지원하지 않는 HTTP 메서드 + @ExceptionHandler(HttpRequestMethodNotSupportedException.class) + public ResponseEntity> handleMethodNotSupported( + HttpRequestMethodNotSupportedException e) { + BaseErrorCode code = ErrorStatus.BAD_REQUEST; + return ResponseEntity + .status(code.getStatus()) + .body(ApiResponse.onFailure(code, null)); + } + + // 쿼리 파라미터 누락 + @ExceptionHandler(MissingServletRequestParameterException.class) + public ResponseEntity> handleMissingParam( + MissingServletRequestParameterException e) { + BaseErrorCode code = ErrorStatus.BAD_REQUEST; + return ResponseEntity + .status(code.getStatus()) + .body(ApiResponse.onFailure(code, e.getMessage())); + } + + // 그 외 모든 예외 + @ExceptionHandler(Exception.class) + public ResponseEntity> handleException(Exception e) { + BaseErrorCode code = ErrorStatus.INTERNAL_SERVER_ERROR; + return ResponseEntity + .status(code.getStatus()) + .body(ApiResponse.onFailure(code, e.getMessage())); + } + + // Valid 검증 실패 시 처리 + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity> handleMethodArgumentNotValid(MethodArgumentNotValidException e) { + + // 첫 번째 에러 메시지 추출 + String errorMessage = e.getBindingResult() + .getFieldErrors() + .stream() + .map(fieldError -> fieldError.getField() + ": " + fieldError.getDefaultMessage()) + .collect(Collectors.joining(", ")); + + return ResponseEntity + .status(HttpStatus.BAD_REQUEST) + .body(ApiResponse.onFailure(ErrorStatus.BAD_REQUEST, errorMessage)); + } +} diff --git a/luga/src/main/resources/application.yml b/luga/src/main/resources/application.yml new file mode 100644 index 0000000..1497201 --- /dev/null +++ b/luga/src/main/resources/application.yml @@ -0,0 +1,19 @@ +spring: + application: + name: "umc10th" + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver # MySQL JDBC 드라이버 클래스 이름 + url: ${DB_URL} # jdbc:mysql://localhost:3306/{데이터베이스명} + username: ${DB_USER} # MySQL 유저 이름 + password: ${DB_PW} # MySQL 비밀번호 + + jpa: + database: mysql # 사용할 데이터베이스 유형 지정 (MySQL) + database-platform: org.hibernate.dialect.MySQLDialect # Hibernate에서 사용할 MySQL 방언(dialect) 설정 + show-sql: true # 실행된 SQL 쿼리를 콘솔에 출력할지 여부 설정 + hibernate: + ddl-auto: update # 애플리케이션 실행 시 데이터베이스 스키마의 상태를 설정 + properties: + hibernate: + format_sql: true # 출력되는 SQL 쿼리를 보기 좋게 포맷팅 \ No newline at end of file diff --git a/luga/src/test/java/com/example/umc10th/Umc10thApplicationTests.java b/luga/src/test/java/com/example/umc10th/Umc10thApplicationTests.java new file mode 100644 index 0000000..b43a96f --- /dev/null +++ b/luga/src/test/java/com/example/umc10th/Umc10thApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.umc10th; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Umc10thApplicationTests { + + @Test + void contextLoads() { + } + +}