diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8af972c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a70081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ +### IntelliJ IDEA ### +src/main/resources/application*.yml + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..0b1ffe3 --- /dev/null +++ b/build.gradle @@ -0,0 +1,73 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.5.6' + id 'io.spring.dependency-management' version '1.1.7' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +description = 'Demo project for Spring Boot' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.mysql:mysql-connector-j' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + // QueryDSL : OpenFeign + implementation "io.github.openfeign.querydsl:querydsl-jpa:7.0" + implementation "io.github.openfeign.querydsl:querydsl-core:7.0" + annotationProcessor "io.github.openfeign.querydsl:querydsl-apt:7.0:jpa" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.13' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-api:2.8.13' + + // Validation + implementation 'org.springframework.boot:spring-boot-starter-validation' +} + +tasks.named('test') { + useJUnitPlatform() +} + +// QueryDSL 관련 설정 +// generated/querydsl 폴더 생성 & 삽입 +def querydslDir = layout.buildDirectory.dir("generated/querydsl").get().asFile + +// 소스 세트에 생성 경로 추가 (구체적인 경로 지정) +sourceSets { + main.java.srcDirs += [ querydslDir ] +} + +// 컴파일 시 생성 경로 지정 +tasks.withType(JavaCompile).configureEach { + options.generatedSourceOutputDirectory.set(querydslDir) +} + +// clean 태스크에 생성 폴더 삭제 로직 추가 +clean.doLast { + file(querydslDir).deleteDir() +} + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..1b33c55 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..d4081da --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..23d15a9 --- /dev/null +++ b/gradlew @@ -0,0 +1,251 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# 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 + +CLASSPATH="\\\"\\\"" + + +# 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" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# 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" \ + -classpath "$CLASSPATH" \ + -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/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..db3a6ac --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,94 @@ +@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 + +set CLASSPATH= + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -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/settings.gradle b/settings.gradle new file mode 100644 index 0000000..0ec607f --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'umc9th' diff --git a/src/main/java/com/example/umc9th/Umc9thApplication.java b/src/main/java/com/example/umc9th/Umc9thApplication.java new file mode 100644 index 0000000..bc54005 --- /dev/null +++ b/src/main/java/com/example/umc9th/Umc9thApplication.java @@ -0,0 +1,15 @@ +package com.example.umc9th; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@SpringBootApplication +@EnableJpaAuditing +public class Umc9thApplication { + + public static void main(String[] args) { + SpringApplication.run(Umc9thApplication.class, args); + } + +} diff --git a/src/main/java/com/example/umc9th/domain/alarm/entity/Alarm.java b/src/main/java/com/example/umc9th/domain/alarm/entity/Alarm.java new file mode 100644 index 0000000..fc66ba5 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/alarm/entity/Alarm.java @@ -0,0 +1,39 @@ +package com.example.umc9th.domain.alarm.entity; + +import com.example.umc9th.domain.alarm.enums.AlarmType; +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "alarm") +public class Alarm extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "type", nullable = false) + @Enumerated(EnumType.STRING) + private AlarmType alarmType; //알림 유형 + + @Column(name = "title", nullable = false) + private String title; //알림 제목 + + @Column(name = "body", nullable = false) + private String body; //알림 내용 + + @Column(name = "is_confirmed", nullable = false) + private boolean confirmed; //확인 여부 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + +} diff --git a/src/main/java/com/example/umc9th/domain/alarm/enums/AlarmType.java b/src/main/java/com/example/umc9th/domain/alarm/enums/AlarmType.java new file mode 100644 index 0000000..876a877 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/alarm/enums/AlarmType.java @@ -0,0 +1,7 @@ +package com.example.umc9th.domain.alarm.enums; + +public enum AlarmType { + EVENT_NOTIFICATION, //새로운 이벤트 수신 + REVIEW_REPLY, //리뷰 답변 알림 + INQUIRY_REPLY //문의 내역 답변 알림 +} diff --git a/src/main/java/com/example/umc9th/domain/member/controller/MemberController.java b/src/main/java/com/example/umc9th/domain/member/controller/MemberController.java new file mode 100644 index 0000000..06196de --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/controller/MemberController.java @@ -0,0 +1,28 @@ +package com.example.umc9th.domain.member.controller; + +import com.example.umc9th.domain.member.dto.req.MemberReqDTO; +import com.example.umc9th.domain.member.dto.res.MemberResDTO; +import com.example.umc9th.domain.member.exception.code.MemberSuccessCode; +import com.example.umc9th.domain.member.service.command.MemberCommandService; +import com.example.umc9th.global.apiPayload.ApiResponse; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class MemberController { + + private final MemberCommandService memberCommandService; + + //회원가입 + @PostMapping("/auth/users/signup") + public ApiResponse signUp( + @RequestBody @Valid MemberReqDTO.JoinDTO dto + ){ + return ApiResponse.onSuccess(MemberSuccessCode.CREATED, memberCommandService.signUp(dto)); + } +} diff --git a/src/main/java/com/example/umc9th/domain/member/converter/MemberConverter.java b/src/main/java/com/example/umc9th/domain/member/converter/MemberConverter.java new file mode 100644 index 0000000..23e6ad7 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/converter/MemberConverter.java @@ -0,0 +1,28 @@ +package com.example.umc9th.domain.member.converter; + + +import com.example.umc9th.domain.member.dto.req.MemberReqDTO; +import com.example.umc9th.domain.member.dto.res.MemberResDTO; +import com.example.umc9th.domain.member.entity.Member; + +public class MemberConverter { + + // Entity -> DTO + public static MemberResDTO.JoinDTO toJoinDTO(Member member){ + return MemberResDTO.JoinDTO.builder() + .memberId(member.getId()) + .createdAt(member.getCreatedAt()) + .build(); + } + + // DTO -> Entity + public static Member toMember(MemberReqDTO.JoinDTO dto){ + return Member.builder() + .name(dto.name()) + .gender(dto.gender()) + .birth(dto.birth()) + .address(dto.address()) + .detailAddress(dto.detailAddress()) + .build(); + } +} diff --git a/src/main/java/com/example/umc9th/domain/member/dto/req/MemberReqDTO.java b/src/main/java/com/example/umc9th/domain/member/dto/req/MemberReqDTO.java new file mode 100644 index 0000000..2c61eca --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/dto/req/MemberReqDTO.java @@ -0,0 +1,26 @@ +package com.example.umc9th.domain.member.dto.req; + +import com.example.umc9th.domain.member.enums.Address; +import com.example.umc9th.domain.member.enums.Gender; +import com.example.umc9th.global.annotation.ExistFoods; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import java.time.LocalDate; +import java.util.List; + +public class MemberReqDTO { + public record JoinDTO( + @NotBlank + String name, + @NotNull + Gender gender, + @NotNull + LocalDate birth, + @NotNull + Address address, + @NotNull + String detailAddress, + @ExistFoods + List preferCategory + ){} +} diff --git a/src/main/java/com/example/umc9th/domain/member/dto/res/MemberResDTO.java b/src/main/java/com/example/umc9th/domain/member/dto/res/MemberResDTO.java new file mode 100644 index 0000000..27ef6af --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/dto/res/MemberResDTO.java @@ -0,0 +1,13 @@ +package com.example.umc9th.domain.member.dto.res; + +import java.time.LocalDateTime; +import lombok.Builder; + +public class MemberResDTO { + + @Builder + public record JoinDTO( + Long memberId, + LocalDateTime createdAt + ){} +} diff --git a/src/main/java/com/example/umc9th/domain/member/entity/Food.java b/src/main/java/com/example/umc9th/domain/member/entity/Food.java new file mode 100644 index 0000000..9b48c79 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/entity/Food.java @@ -0,0 +1,23 @@ +package com.example.umc9th.domain.member.entity; + + +import com.example.umc9th.domain.member.enums.FoodCategory; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "food") +public class Food { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "category") + @Enumerated(EnumType.STRING) + private FoodCategory category; //음식 카테고리 +} diff --git a/src/main/java/com/example/umc9th/domain/member/entity/Member.java b/src/main/java/com/example/umc9th/domain/member/entity/Member.java new file mode 100644 index 0000000..134232e --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/entity/Member.java @@ -0,0 +1,73 @@ +package com.example.umc9th.domain.member.entity; + +import com.example.umc9th.domain.member.enums.Address; +import com.example.umc9th.domain.member.enums.Gender; +import com.example.umc9th.domain.member.enums.SocialType; +import com.example.umc9th.domain.member.enums.Status; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "member") +public class Member extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "name", length = 3, nullable = false) + private String name; //이름 + + @Column(name = "nickname") + private String nickname; //닉네임 + + @Column(name = "gender", nullable = false) + @Enumerated(EnumType.STRING) + @Builder.Default + private Gender gender = Gender.NONE; //성별 + + @Column(name = "birth", nullable = false) + private LocalDate birth; //생년월일 + + @Column(name = "address", nullable = false) + @Enumerated(EnumType.STRING) + private Address address; //주소 + + @Column(name = "detail_address", nullable = false) + private String detailAddress; //상세주소 + + @Column(name = "email") + private String email; //이메일 + + @Column(name = "phone_number") + private String phoneNumber; //휴대폰번호 + + @Column(name = "social_type", nullable = false) + @Enumerated(EnumType.STRING) + @Builder.Default + private SocialType socialType = SocialType.LOCAL; //소셜로그인 타입 + + @Column(name = "point", nullable = false) + @Builder.Default + private Integer point = 0; //포인트 + + @Column(name = "status", nullable = false) + @Enumerated(EnumType.STRING) + @Builder.Default + private Status status = Status.ACTIVE; //상태 + + @Column(name = "inactive_date") + private LocalDateTime inactiveDate; //비활성일 + +} diff --git a/src/main/java/com/example/umc9th/domain/member/entity/Term.java b/src/main/java/com/example/umc9th/domain/member/entity/Term.java new file mode 100644 index 0000000..1106efa --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/entity/Term.java @@ -0,0 +1,22 @@ +package com.example.umc9th.domain.member.entity; + +import com.example.umc9th.domain.member.enums.TermName; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "term") +public class Term { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "name") + @Enumerated(EnumType.STRING) + private TermName name; +} diff --git a/src/main/java/com/example/umc9th/domain/member/entity/mapping/MemberFood.java b/src/main/java/com/example/umc9th/domain/member/entity/mapping/MemberFood.java new file mode 100644 index 0000000..2061c70 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/entity/mapping/MemberFood.java @@ -0,0 +1,27 @@ +package com.example.umc9th.domain.member.entity.mapping; + +import com.example.umc9th.domain.member.entity.Food; +import com.example.umc9th.domain.member.entity.Member; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "member_food") +public class MemberFood { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "food_id") + private Food food; +} diff --git a/src/main/java/com/example/umc9th/domain/member/entity/mapping/MemberTerm.java b/src/main/java/com/example/umc9th/domain/member/entity/mapping/MemberTerm.java new file mode 100644 index 0000000..9cba66b --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/entity/mapping/MemberTerm.java @@ -0,0 +1,31 @@ +package com.example.umc9th.domain.member.entity.mapping; + +import com.example.umc9th.domain.member.entity.Food; +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.member.entity.Term; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "member_term") +public class MemberTerm { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "agreed", nullable = false) + private boolean agreed; //동의 여부 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "term_id") + private Term term; +} diff --git a/src/main/java/com/example/umc9th/domain/member/enums/Address.java b/src/main/java/com/example/umc9th/domain/member/enums/Address.java new file mode 100644 index 0000000..06543c6 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/enums/Address.java @@ -0,0 +1,9 @@ +package com.example.umc9th.domain.member.enums; + +public enum Address { + GANGNAM_GU, //서울특별시 강남구 + MAPO_GU, //서울특별시 마포구 + SONGPA_GU, //서울특별시 송파구 + SEONGDONG_GU, //서울특별시 성동구 + YONGSAN_GU; //서울특별시 용산구 +} diff --git a/src/main/java/com/example/umc9th/domain/member/enums/FoodCategory.java b/src/main/java/com/example/umc9th/domain/member/enums/FoodCategory.java new file mode 100644 index 0000000..55e7170 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/enums/FoodCategory.java @@ -0,0 +1,8 @@ +package com.example.umc9th.domain.member.enums; + +public enum FoodCategory { + KOREAN, JAPANESE, CHINESE, //한식, 중식, 일식 + WESTERN, CHICKEN, BUNSIK, //양식, 치킨, 분식 + MEAT_BBQ, DOSIRAK, LATE_NIGHT, //고기, 도시락, 야식 + FAST_FOOD, DESSERT, ASIAN //패스트푸드, 디저트, 아시안푸드 +} diff --git a/src/main/java/com/example/umc9th/domain/member/enums/Gender.java b/src/main/java/com/example/umc9th/domain/member/enums/Gender.java new file mode 100644 index 0000000..400401b --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/enums/Gender.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.member.enums; + +public enum Gender { + MALE, FEMALE, NONE +} diff --git a/src/main/java/com/example/umc9th/domain/member/enums/SocialType.java b/src/main/java/com/example/umc9th/domain/member/enums/SocialType.java new file mode 100644 index 0000000..dad4d14 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/enums/SocialType.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.member.enums; + +public enum SocialType { + KAKAO, NAVER, APPLE, GOOGLE, LOCAL +} diff --git a/src/main/java/com/example/umc9th/domain/member/enums/Status.java b/src/main/java/com/example/umc9th/domain/member/enums/Status.java new file mode 100644 index 0000000..4c3ce25 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/enums/Status.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.member.enums; + +public enum Status { + ACTIVE, INACTIVE +} diff --git a/src/main/java/com/example/umc9th/domain/member/enums/TermName.java b/src/main/java/com/example/umc9th/domain/member/enums/TermName.java new file mode 100644 index 0000000..208b712 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/enums/TermName.java @@ -0,0 +1,9 @@ +package com.example.umc9th.domain.member.enums; + +public enum TermName { + AGE_CONFIRMATION, // 만 14세 이상 + TERMS_OF_SERVICE, // (필수) 서비스 이용약관 + PRIVACY_POLICY, // (필수) 개인정보 처리방침 + LOCATION_SERVICES, // (선택) 위치정보 제공/이용 + MARKETING_COMMUNICATIONS, // (선택) 마케팅 수신 동의(포괄) +} diff --git a/src/main/java/com/example/umc9th/domain/member/exception/FoodException.java b/src/main/java/com/example/umc9th/domain/member/exception/FoodException.java new file mode 100644 index 0000000..71f7432 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/exception/FoodException.java @@ -0,0 +1,10 @@ +package com.example.umc9th.domain.member.exception; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.exception.GeneralException; + +public class FoodException extends GeneralException { + public FoodException(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/example/umc9th/domain/member/exception/MemberException.java b/src/main/java/com/example/umc9th/domain/member/exception/MemberException.java new file mode 100644 index 0000000..1e4d7a1 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/exception/MemberException.java @@ -0,0 +1,10 @@ +package com.example.umc9th.domain.member.exception; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.exception.GeneralException; + +public class MemberException extends GeneralException { + public MemberException(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/example/umc9th/domain/member/exception/code/FoodErrorCode.java b/src/main/java/com/example/umc9th/domain/member/exception/code/FoodErrorCode.java new file mode 100644 index 0000000..8b8001b --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/exception/code/FoodErrorCode.java @@ -0,0 +1,20 @@ +package com.example.umc9th.domain.member.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum FoodErrorCode implements BaseErrorCode { + + NOT_FOUND(HttpStatus.NOT_FOUND, + "FOOD404_1", + "해당 음식을 찾지 못했습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/member/exception/code/FoodSuccessCode.java b/src/main/java/com/example/umc9th/domain/member/exception/code/FoodSuccessCode.java new file mode 100644 index 0000000..c5550f2 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/exception/code/FoodSuccessCode.java @@ -0,0 +1,20 @@ +package com.example.umc9th.domain.member.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseSuccessCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum FoodSuccessCode implements BaseSuccessCode { + + FOUND(HttpStatus.OK, + "FOOD200_1", + "성공적으로 음식을 조회했습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/member/exception/code/MemberErrorCode.java b/src/main/java/com/example/umc9th/domain/member/exception/code/MemberErrorCode.java new file mode 100644 index 0000000..64645ae --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/exception/code/MemberErrorCode.java @@ -0,0 +1,20 @@ +package com.example.umc9th.domain.member.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum MemberErrorCode implements BaseErrorCode { + + NOT_FOUND(HttpStatus.NOT_FOUND, + "MEMBER404_1", + "해당 사용자를 찾지 못했습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/member/exception/code/MemberSuccessCode.java b/src/main/java/com/example/umc9th/domain/member/exception/code/MemberSuccessCode.java new file mode 100644 index 0000000..5a4cab2 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/exception/code/MemberSuccessCode.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.member.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseSuccessCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum MemberSuccessCode implements BaseSuccessCode { + + CREATED(HttpStatus.CREATED, + "REVIEW201_1", + "성공적으로 회원가입이 완료되었습니다."), + + FOUND(HttpStatus.OK, + "MEMBER200_1", + "성공적으로 사용자를 조회했습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/member/repository/FoodRepository.java b/src/main/java/com/example/umc9th/domain/member/repository/FoodRepository.java new file mode 100644 index 0000000..0235a9f --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/repository/FoodRepository.java @@ -0,0 +1,8 @@ +package com.example.umc9th.domain.member.repository; + +import com.example.umc9th.domain.member.entity.Food; +import com.example.umc9th.domain.member.entity.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FoodRepository extends JpaRepository { +} diff --git a/src/main/java/com/example/umc9th/domain/member/repository/MemberFoodRepository.java b/src/main/java/com/example/umc9th/domain/member/repository/MemberFoodRepository.java new file mode 100644 index 0000000..81454fc --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/repository/MemberFoodRepository.java @@ -0,0 +1,8 @@ +package com.example.umc9th.domain.member.repository; + +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.member.entity.mapping.MemberFood; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberFoodRepository extends JpaRepository { +} diff --git a/src/main/java/com/example/umc9th/domain/member/repository/MemberRepository.java b/src/main/java/com/example/umc9th/domain/member/repository/MemberRepository.java new file mode 100644 index 0000000..d6fabf6 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/repository/MemberRepository.java @@ -0,0 +1,8 @@ +package com.example.umc9th.domain.member.repository; + +import com.example.umc9th.domain.member.entity.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberRepository extends JpaRepository { + +} diff --git a/src/main/java/com/example/umc9th/domain/member/service/command/MemberCommandService.java b/src/main/java/com/example/umc9th/domain/member/service/command/MemberCommandService.java new file mode 100644 index 0000000..b6f237f --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/service/command/MemberCommandService.java @@ -0,0 +1,9 @@ +package com.example.umc9th.domain.member.service.command; + +import com.example.umc9th.domain.member.dto.req.MemberReqDTO; +import com.example.umc9th.domain.member.dto.res.MemberResDTO; + +public interface MemberCommandService { + // 회원가입 + MemberResDTO.JoinDTO signUp(MemberReqDTO.JoinDTO dto); +} diff --git a/src/main/java/com/example/umc9th/domain/member/service/command/MemberCommandServiceImpl.java b/src/main/java/com/example/umc9th/domain/member/service/command/MemberCommandServiceImpl.java new file mode 100644 index 0000000..feaaf6c --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/service/command/MemberCommandServiceImpl.java @@ -0,0 +1,65 @@ +package com.example.umc9th.domain.member.service.command; + +import com.example.umc9th.domain.member.converter.MemberConverter; +import com.example.umc9th.domain.member.dto.req.MemberReqDTO; +import com.example.umc9th.domain.member.dto.res.MemberResDTO; +import com.example.umc9th.domain.member.entity.Food; +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.member.entity.mapping.MemberFood; +import com.example.umc9th.domain.member.exception.FoodException; +import com.example.umc9th.domain.member.exception.code.FoodErrorCode; +import com.example.umc9th.domain.member.repository.FoodRepository; +import com.example.umc9th.domain.member.repository.MemberFoodRepository; +import com.example.umc9th.domain.member.repository.MemberRepository; +import java.util.ArrayList; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberCommandServiceImpl implements MemberCommandService{ + + private final MemberRepository memberRepository; + private final MemberFoodRepository memberFoodRepository; + private final FoodRepository foodRepository; + + // 회원가입 + @Override + @Transactional + public MemberResDTO.JoinDTO signUp(MemberReqDTO.JoinDTO dto){ + + // 사용자 생성 + Member member = MemberConverter.toMember(dto); + + // DB 적용 + memberRepository.save(member); + + // 선호 음식 존재 여부 확인 + if(!dto.preferCategory().isEmpty()){ + List memberFoodList = new ArrayList<>(); + + // 선호 음식 ID별 조회 + for (Long id : dto.preferCategory()){ + // 음식 존재 여부 검증 + Food food = foodRepository.findById(id) + .orElseThrow(() -> new FoodException(FoodErrorCode.NOT_FOUND)); + + // MemberFood 엔티티 생성 (converter 사용해야 함) + MemberFood memberFood = MemberFood.builder() + .member(member) + .food(food) + .build(); + + // 사용자 - 음식 (선호 음식) 추가 + memberFoodList.add(memberFood); + } + // 모든 선호 음식 추가: DB 적용 + memberFoodRepository.saveAll(memberFoodList); //MemberFood 엔티티 객체들을 한 번에 DB에 INSERT + } + + // 응답 DTO 생성 + return MemberConverter.toJoinDTO(member); + } +} diff --git a/src/main/java/com/example/umc9th/domain/member/service/query/MemberQueryService.java b/src/main/java/com/example/umc9th/domain/member/service/query/MemberQueryService.java new file mode 100644 index 0000000..eaa74bc --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/service/query/MemberQueryService.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.member.service.query; + +public interface MemberQueryService { +} diff --git a/src/main/java/com/example/umc9th/domain/member/service/query/MemberQueryServiceImpl.java b/src/main/java/com/example/umc9th/domain/member/service/query/MemberQueryServiceImpl.java new file mode 100644 index 0000000..7ce41c8 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/member/service/query/MemberQueryServiceImpl.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.member.service.query; + +public class MemberQueryServiceImpl { +} diff --git a/src/main/java/com/example/umc9th/domain/mission/controller/MemberMissionController.java b/src/main/java/com/example/umc9th/domain/mission/controller/MemberMissionController.java new file mode 100644 index 0000000..58d3c5e --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/controller/MemberMissionController.java @@ -0,0 +1,27 @@ +package com.example.umc9th.domain.mission.controller; + +import com.example.umc9th.domain.mission.dto.res.MemberMissionResDTO.ChallengeResponse; +import com.example.umc9th.domain.mission.exception.code.MemberMissionSuccessCode; +import com.example.umc9th.domain.mission.service.command.MemberMissionCommandService; +import com.example.umc9th.global.apiPayload.ApiResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class MemberMissionController { + + private final MemberMissionCommandService memberMissionCommandService; + + // 미션 도전하기 + @PostMapping("/members/me/missions/{missionId}") + public ApiResponse challenge( + @PathVariable Long missionId) { + + ChallengeResponse response = memberMissionCommandService.challenge(missionId); + return ApiResponse.onSuccess(MemberMissionSuccessCode.CHALLENGED, response); + } + +} diff --git a/src/main/java/com/example/umc9th/domain/mission/converter/MemberMissionConverter.java b/src/main/java/com/example/umc9th/domain/mission/converter/MemberMissionConverter.java new file mode 100644 index 0000000..924c977 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/converter/MemberMissionConverter.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.mission.converter; + +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.mission.dto.res.MemberMissionResDTO; +import com.example.umc9th.domain.mission.entity.Mission; +import com.example.umc9th.domain.mission.entity.mapping.MemberMission; + +public class MemberMissionConverter { + + // Entity -> DTO + public static MemberMissionResDTO.ChallengeResponse toChallengeRes(MemberMission memberMission){ + return MemberMissionResDTO.ChallengeResponse.builder() + .memberMissionId(memberMission.getId()) + .missionId(memberMission.getMission().getId()) + .complete(memberMission.isComplete()) + .build(); + } + + // DTO -> Entity + public static MemberMission toMemberMission(Member member, Mission mission){ + return MemberMission.create(member, mission); + } + +} diff --git a/src/main/java/com/example/umc9th/domain/mission/dto/req/MemberMissionReqDTO.java b/src/main/java/com/example/umc9th/domain/mission/dto/req/MemberMissionReqDTO.java new file mode 100644 index 0000000..8cedbd6 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/dto/req/MemberMissionReqDTO.java @@ -0,0 +1,9 @@ +package com.example.umc9th.domain.mission.dto.req; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +public class MemberMissionReqDTO { + +} diff --git a/src/main/java/com/example/umc9th/domain/mission/dto/req/MissionReqDTO.java b/src/main/java/com/example/umc9th/domain/mission/dto/req/MissionReqDTO.java new file mode 100644 index 0000000..f3ab7ea --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/dto/req/MissionReqDTO.java @@ -0,0 +1,6 @@ +package com.example.umc9th.domain.mission.dto.req; + + +public class MissionReqDTO { + +} diff --git a/src/main/java/com/example/umc9th/domain/mission/dto/res/MemberMissionResDTO.java b/src/main/java/com/example/umc9th/domain/mission/dto/res/MemberMissionResDTO.java new file mode 100644 index 0000000..ea92a01 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/dto/res/MemberMissionResDTO.java @@ -0,0 +1,16 @@ +package com.example.umc9th.domain.mission.dto.res; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +public class MemberMissionResDTO { + @Getter + @Builder + @AllArgsConstructor + public static class ChallengeResponse { + private Long memberMissionId; + private Long missionId; + private boolean complete; + } +} diff --git a/src/main/java/com/example/umc9th/domain/mission/dto/res/MissionResDTO.java b/src/main/java/com/example/umc9th/domain/mission/dto/res/MissionResDTO.java new file mode 100644 index 0000000..a76bf11 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/dto/res/MissionResDTO.java @@ -0,0 +1,6 @@ +package com.example.umc9th.domain.mission.dto.res; + + +public class MissionResDTO { + +} diff --git a/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java b/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java new file mode 100644 index 0000000..dc9d479 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java @@ -0,0 +1,36 @@ +package com.example.umc9th.domain.mission.entity; + +import com.example.umc9th.domain.restaurant.entity.Restaurant; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import java.time.LocalDateTime; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "mission") +public class Mission extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "content", nullable = false) + private String content; //미션 내용 + + @Column(name = "verification_code", nullable = false) + private Long verificationCode; //사장님 구분 번호 + + @Column(name = "point", nullable = false) + private int point; //포인트 + + @Column(name = "expired_at", nullable = false) + private LocalDateTime expiredAt; //만료 일자 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "restaurant_id") + private Restaurant restaurant; +} diff --git a/src/main/java/com/example/umc9th/domain/mission/entity/mapping/MemberMission.java b/src/main/java/com/example/umc9th/domain/mission/entity/mapping/MemberMission.java new file mode 100644 index 0000000..f647035 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/entity/mapping/MemberMission.java @@ -0,0 +1,39 @@ +package com.example.umc9th.domain.mission.entity.mapping; + +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.mission.entity.Mission; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "member_mission") +public class MemberMission { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_id") + private Mission mission; + + @Column(name = "is_complete", nullable = false) + private boolean complete; //완료 여부 + + // 정적 팩토리 메서드 + public static MemberMission create(Member member, Mission mission){ + MemberMission mm = new MemberMission(); + mm.member = member; + mm.mission = mission; + mm.complete = false; + return mm; + } +} diff --git a/src/main/java/com/example/umc9th/domain/mission/exception/MemberMissionException.java b/src/main/java/com/example/umc9th/domain/mission/exception/MemberMissionException.java new file mode 100644 index 0000000..4166124 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/exception/MemberMissionException.java @@ -0,0 +1,10 @@ +package com.example.umc9th.domain.mission.exception; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.exception.GeneralException; + +public class MemberMissionException extends GeneralException { + public MemberMissionException(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/example/umc9th/domain/mission/exception/MissionException.java b/src/main/java/com/example/umc9th/domain/mission/exception/MissionException.java new file mode 100644 index 0000000..56fe3ab --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/exception/MissionException.java @@ -0,0 +1,10 @@ +package com.example.umc9th.domain.mission.exception; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.exception.GeneralException; + +public class MissionException extends GeneralException { + public MissionException(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/example/umc9th/domain/mission/exception/code/MemberMissionErrorCode.java b/src/main/java/com/example/umc9th/domain/mission/exception/code/MemberMissionErrorCode.java new file mode 100644 index 0000000..dcac22c --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/exception/code/MemberMissionErrorCode.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.mission.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum MemberMissionErrorCode implements BaseErrorCode { + + NOT_FOUND(HttpStatus.NOT_FOUND, + "MEMBER_MISSION404_1", + "해당 사용자 미션을 찾을 수 없습니다."), + + ALREADY_CHALLENGED(HttpStatus.BAD_REQUEST, + "MEMBER_MISSION400_1", + "이미 도전 중인 미션입니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/mission/exception/code/MemberMissionSuccessCode.java b/src/main/java/com/example/umc9th/domain/mission/exception/code/MemberMissionSuccessCode.java new file mode 100644 index 0000000..0da3433 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/exception/code/MemberMissionSuccessCode.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.mission.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseSuccessCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum MemberMissionSuccessCode implements BaseSuccessCode { + + CHALLENGED(HttpStatus.OK, + "MEMBER_MISSION200_1", + "미션 도전이 성공적으로 완료되었습니다."), + + FOUND(HttpStatus.OK, + "MEMBER_MISSION200_2", + "성공적으로 사용자 미션을 조회했습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/mission/exception/code/MissionErrorCode.java b/src/main/java/com/example/umc9th/domain/mission/exception/code/MissionErrorCode.java new file mode 100644 index 0000000..2671a9f --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/exception/code/MissionErrorCode.java @@ -0,0 +1,20 @@ +package com.example.umc9th.domain.mission.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum MissionErrorCode implements BaseErrorCode { + + NOT_FOUND(HttpStatus.NOT_FOUND, + "MISSION404_1", + "해당 미션을 찾을 수 없습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/mission/exception/code/MissionSuccessCode.java b/src/main/java/com/example/umc9th/domain/mission/exception/code/MissionSuccessCode.java new file mode 100644 index 0000000..2f232b7 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/exception/code/MissionSuccessCode.java @@ -0,0 +1,25 @@ +package com.example.umc9th.domain.mission.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseSuccessCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum MissionSuccessCode implements BaseSuccessCode { + + CREATED(HttpStatus.CREATED, + "MISSION201_1", + "성공적으로 미션을 생성했습니다."), + + FOUND(HttpStatus.OK, + "MISSION200_1", + "성공적으로 미션을 조회했습니다."), + + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/mission/repository/MemberMissionRepository.java b/src/main/java/com/example/umc9th/domain/mission/repository/MemberMissionRepository.java new file mode 100644 index 0000000..c9ed7e9 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/repository/MemberMissionRepository.java @@ -0,0 +1,8 @@ +package com.example.umc9th.domain.mission.repository; + +import com.example.umc9th.domain.mission.entity.mapping.MemberMission; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberMissionRepository extends JpaRepository { + boolean existsByMemberIdAndMissionId(Long memberId, Long missionId); +} diff --git a/src/main/java/com/example/umc9th/domain/mission/repository/MissionRepository.java b/src/main/java/com/example/umc9th/domain/mission/repository/MissionRepository.java new file mode 100644 index 0000000..d344042 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/repository/MissionRepository.java @@ -0,0 +1,46 @@ +package com.example.umc9th.domain.mission.repository; + +import com.example.umc9th.domain.mission.entity.Mission; +import java.time.LocalDate; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.repository.EntityGraph; +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 MemberMission mm + join mm.mission m + where mm.member.id = :memberId + and mm.complete = :complete + and (:lastId is null or m.id < :lastId) + order by m.id desc + """) + Slice findMissions( + @Param("memberId") Long memberId, + @Param("complete") boolean complete, //false(진행중), true(진행 완료) + @Param("lastId") Long lastId, //첫 페이지면 null + Pageable pageable + ); + + @EntityGraph(attributePaths = "restaurant") + @Query(""" + select m + from Mission m + join m.restaurant rs + join rs.region rg + where rg.name = :regionName + and m.expiredAt >= :today + and (:lastId is null or m.id < :lastId) + order by m.id desc + """) + Slice findMissionsByRegion( + @Param("regionName") String regionName, + @Param("today") LocalDate today, + @Param("lastId") Long lastId, // 첫 페이지면 null + Pageable pageable + ); +} diff --git a/src/main/java/com/example/umc9th/domain/mission/service/command/MemberMissionCommandService.java b/src/main/java/com/example/umc9th/domain/mission/service/command/MemberMissionCommandService.java new file mode 100644 index 0000000..66a059d --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/service/command/MemberMissionCommandService.java @@ -0,0 +1,9 @@ +package com.example.umc9th.domain.mission.service.command; + +import com.example.umc9th.domain.mission.dto.res.MemberMissionResDTO; + +public interface MemberMissionCommandService { + + // 미션 도전하기 + MemberMissionResDTO.ChallengeResponse challenge(Long missionId); +} diff --git a/src/main/java/com/example/umc9th/domain/mission/service/command/MemberMissionCommandServiceImpl.java b/src/main/java/com/example/umc9th/domain/mission/service/command/MemberMissionCommandServiceImpl.java new file mode 100644 index 0000000..3e0df9e --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/service/command/MemberMissionCommandServiceImpl.java @@ -0,0 +1,53 @@ +package com.example.umc9th.domain.mission.service.command; + +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.member.exception.MemberException; +import com.example.umc9th.domain.member.exception.code.MemberErrorCode; +import com.example.umc9th.domain.member.repository.MemberRepository; +import com.example.umc9th.domain.mission.converter.MemberMissionConverter; +import com.example.umc9th.domain.mission.dto.res.MemberMissionResDTO; +import com.example.umc9th.domain.mission.entity.Mission; +import com.example.umc9th.domain.mission.entity.mapping.MemberMission; +import com.example.umc9th.domain.mission.exception.MemberMissionException; +import com.example.umc9th.domain.mission.exception.MissionException; +import com.example.umc9th.domain.mission.exception.code.MemberMissionErrorCode; +import com.example.umc9th.domain.mission.exception.code.MissionErrorCode; +import com.example.umc9th.domain.mission.repository.MemberMissionRepository; +import com.example.umc9th.domain.mission.repository.MissionRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberMissionCommandServiceImpl implements MemberMissionCommandService{ + + private final MemberRepository memberRepository; + private final MissionRepository missionRepository; + private final MemberMissionRepository memberMissionRepository; + + @Override + @Transactional + public MemberMissionResDTO.ChallengeResponse challenge(Long missionId){ + + // 유저 id 하드코딩 + Long memberId = 1L; + + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberException(MemberErrorCode.NOT_FOUND)); + + Mission mission = missionRepository.findById(missionId) + .orElseThrow(() -> new MissionException(MissionErrorCode.NOT_FOUND)); + + // 이미 도전 중인 미션인지 체크 + if(memberMissionRepository.existsByMemberIdAndMissionId(memberId, missionId)) { + throw new MemberMissionException(MemberMissionErrorCode.ALREADY_CHALLENGED); + } + + MemberMission mm = MemberMissionConverter.toMemberMission(member, mission); + + memberMissionRepository.save(mm); + + return MemberMissionConverter.toChallengeRes(mm); + } +} diff --git a/src/main/java/com/example/umc9th/domain/mission/service/command/MissionCommandService.java b/src/main/java/com/example/umc9th/domain/mission/service/command/MissionCommandService.java new file mode 100644 index 0000000..8e91e51 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/service/command/MissionCommandService.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.mission.service.command; + +public interface MissionCommandService { +} diff --git a/src/main/java/com/example/umc9th/domain/mission/service/command/MissionCommandServiceImpl.java b/src/main/java/com/example/umc9th/domain/mission/service/command/MissionCommandServiceImpl.java new file mode 100644 index 0000000..52b8477 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/service/command/MissionCommandServiceImpl.java @@ -0,0 +1,9 @@ +package com.example.umc9th.domain.mission.service.command; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class MissionCommandServiceImpl implements MissionCommandService{ +} diff --git a/src/main/java/com/example/umc9th/domain/mission/service/query/MissionQueryService.java b/src/main/java/com/example/umc9th/domain/mission/service/query/MissionQueryService.java new file mode 100644 index 0000000..bf3a7c9 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/service/query/MissionQueryService.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.mission.service.query; + +public interface MissionQueryService { +} diff --git a/src/main/java/com/example/umc9th/domain/mission/service/query/MissionQueryServiceImpl.java b/src/main/java/com/example/umc9th/domain/mission/service/query/MissionQueryServiceImpl.java new file mode 100644 index 0000000..9a80a9f --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/service/query/MissionQueryServiceImpl.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.mission.service.query; + +public class MissionQueryServiceImpl { +} diff --git a/src/main/java/com/example/umc9th/domain/question/entity/Question.java b/src/main/java/com/example/umc9th/domain/question/entity/Question.java new file mode 100644 index 0000000..4eb6964 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/question/entity/Question.java @@ -0,0 +1,39 @@ +package com.example.umc9th.domain.question.entity; + +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.question.enums.QuestionType; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "question") +public class Question extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "title", nullable = false) + private String title; //문의 제목 + + @Column(name = "type", nullable = false) + @Enumerated(EnumType.STRING) + @Builder.Default + private QuestionType questionType = QuestionType.ETC; //문의 유형 + + @Column(name = "content", nullable = false) + private String content; //문의 내용 + + @Column(name = "is_answered", nullable = false) + private boolean answered; //답변 여부 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + +} diff --git a/src/main/java/com/example/umc9th/domain/question/entity/QuestionPhoto.java b/src/main/java/com/example/umc9th/domain/question/entity/QuestionPhoto.java new file mode 100644 index 0000000..3624ac1 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/question/entity/QuestionPhoto.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.question.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "question_photo") +public class QuestionPhoto { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "image_url", nullable = false) + private String imageUrl; //문의 사진 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "question_id") + private Question question; +} diff --git a/src/main/java/com/example/umc9th/domain/question/enums/QuestionType.java b/src/main/java/com/example/umc9th/domain/question/enums/QuestionType.java new file mode 100644 index 0000000..6b78a96 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/question/enums/QuestionType.java @@ -0,0 +1,8 @@ +package com.example.umc9th.domain.question.enums; + +public enum QuestionType { + ACCOUNT, // 계정/로그인 + MISSION, // 미션 + POINT, //포인트 + ETC //기타 +} diff --git a/src/main/java/com/example/umc9th/domain/restaurant/entity/Region.java b/src/main/java/com/example/umc9th/domain/restaurant/entity/Region.java new file mode 100644 index 0000000..43dcade --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/restaurant/entity/Region.java @@ -0,0 +1,20 @@ +package com.example.umc9th.domain.restaurant.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "region") +public class Region { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "name", nullable = false) + private String name; //지역명 +} diff --git a/src/main/java/com/example/umc9th/domain/restaurant/entity/Restaurant.java b/src/main/java/com/example/umc9th/domain/restaurant/entity/Restaurant.java new file mode 100644 index 0000000..a4648b6 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/restaurant/entity/Restaurant.java @@ -0,0 +1,54 @@ +package com.example.umc9th.domain.restaurant.entity; + +import com.example.umc9th.domain.restaurant.enums.RestaurantType; +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "restaurant") +public class Restaurant extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "name", nullable = false) + private String name; //가게명 + + @Column(name = "type", nullable = false) + @Enumerated(EnumType.STRING) + @Builder.Default + private RestaurantType restaurantType = RestaurantType.ETC; //가게 유형 + + @Column(name = "address", nullable = false) + private String address; //주소 + + @Column(name = "is_open", nullable = false) + private boolean open; //영업 여부 + + @Column(name = "star", nullable = false) + private float star; //별점 + + @Column(name = "latitude", nullable = false) + private Double latitude; //위도 + + @Column(name = "longitude", nullable = false) + private Double longitude; //경도 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "region_id") + private Region region; + + @OneToMany(mappedBy = "restaurant", cascade = CascadeType.REMOVE) + @Builder.Default + private List reviews = new ArrayList<>(); +} diff --git a/src/main/java/com/example/umc9th/domain/restaurant/enums/RestaurantType.java b/src/main/java/com/example/umc9th/domain/restaurant/enums/RestaurantType.java new file mode 100644 index 0000000..70058cd --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/restaurant/enums/RestaurantType.java @@ -0,0 +1,12 @@ +package com.example.umc9th.domain.restaurant.enums; + +public enum RestaurantType { + KOREAN, // 한식 + CHINESE, // 중식 + JAPANESE, // 일식 + WESTERN, // 양식 + FASTFOOD, // 패스트푸드 + CAFE, // 카페 / 디저트 + BAR, // 주점 / 펍 + ETC // 기타 +} diff --git a/src/main/java/com/example/umc9th/domain/restaurant/exception/RestaurantException.java b/src/main/java/com/example/umc9th/domain/restaurant/exception/RestaurantException.java new file mode 100644 index 0000000..c2fe04f --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/restaurant/exception/RestaurantException.java @@ -0,0 +1,10 @@ +package com.example.umc9th.domain.restaurant.exception; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.exception.GeneralException; + +public class RestaurantException extends GeneralException { + public RestaurantException(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/example/umc9th/domain/restaurant/exception/code/RestaurantErrorCode.java b/src/main/java/com/example/umc9th/domain/restaurant/exception/code/RestaurantErrorCode.java new file mode 100644 index 0000000..dc47c5b --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/restaurant/exception/code/RestaurantErrorCode.java @@ -0,0 +1,20 @@ +package com.example.umc9th.domain.restaurant.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum RestaurantErrorCode implements BaseErrorCode { + + NOT_FOUND(HttpStatus.NOT_FOUND, + "RESTAURANT404_1", + "해당 가게를 찾을 수 없습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/restaurant/exception/code/RestaurantSuccessCode.java b/src/main/java/com/example/umc9th/domain/restaurant/exception/code/RestaurantSuccessCode.java new file mode 100644 index 0000000..e71cf91 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/restaurant/exception/code/RestaurantSuccessCode.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.restaurant.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseSuccessCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum RestaurantSuccessCode implements BaseSuccessCode { + + CREATED(HttpStatus.CREATED, + "RESTAURANT201_1", + "가게가 성공적으로 등록되었습니다."), + + FOUND(HttpStatus.OK, + "RESTAURANT200_1", + "가게 정보를 성공적으로 조회했습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/restaurant/repository/RestaurantRepository.java b/src/main/java/com/example/umc9th/domain/restaurant/repository/RestaurantRepository.java new file mode 100644 index 0000000..1fc9fd0 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/restaurant/repository/RestaurantRepository.java @@ -0,0 +1,9 @@ +package com.example.umc9th.domain.restaurant.repository; + +import com.example.umc9th.domain.restaurant.entity.Restaurant; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RestaurantRepository extends JpaRepository { + Optional findByName(String name); +} diff --git a/src/main/java/com/example/umc9th/domain/review/controller/ReviewController.java b/src/main/java/com/example/umc9th/domain/review/controller/ReviewController.java new file mode 100644 index 0000000..50615e7 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/controller/ReviewController.java @@ -0,0 +1,70 @@ +package com.example.umc9th.domain.review.controller; + +import com.example.umc9th.domain.review.dto.req.ReviewReqDTO.CreateReviewRequest; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO.CreateReviewResponse; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO.MyReviewResponse; +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.review.exception.code.ReviewSuccessCode; +import com.example.umc9th.domain.review.service.command.ReviewCommandService; +import com.example.umc9th.domain.review.service.query.ReviewQueryService; +import com.example.umc9th.global.apiPayload.ApiResponse; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class ReviewController { + + private final ReviewQueryService reviewQueryService; + private final ReviewCommandService reviewCommandService; + + // 리뷰 검색 API + @GetMapping("/reviews/search") + public ApiResponse> searchReview(@RequestParam String query, + @RequestParam String type){ + + // 서비스에게 요청 + List result = reviewQueryService.searchReview(query, type); + return ApiResponse.onSuccess(ReviewSuccessCode.FOUND, result); + } + + // 내가 작성한 리뷰 보기 API + @GetMapping("/reviews/my") + public ApiResponse> searchMyReviews(@RequestParam Long memberId, + @RequestParam(required = false) String restaurantName, + @RequestParam(required = false) Integer star){ + + // 서비스에게 요청 + List result = reviewQueryService.searchMyReviews(memberId, restaurantName, star); + return ApiResponse.onSuccess(ReviewSuccessCode.FOUND, result); + } + + // 가게에 리뷰 추가하기 API + @PostMapping("/restaurants/{restaurantId}/reviews") + public ApiResponse createReview( + @PathVariable Long restaurantId, + @RequestBody CreateReviewRequest request + ){ + + CreateReviewResponse response = reviewCommandService.createReview(restaurantId, request); + return ApiResponse.onSuccess(ReviewSuccessCode.CREATED, response); + } + + // 가게의 리뷰 목록 조회 + @GetMapping("/reviews") + public ApiResponse getReviews( + @RequestParam String restaurantName, + @RequestParam Integer page // 페이지 번호 + ){ + ReviewSuccessCode code = ReviewSuccessCode.FOUND; + return ApiResponse.onSuccess(code, reviewQueryService.findReview(restaurantName, page)); + } + +} diff --git a/src/main/java/com/example/umc9th/domain/review/converter/ReviewConverter.java b/src/main/java/com/example/umc9th/domain/review/converter/ReviewConverter.java new file mode 100644 index 0000000..12a7584 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/converter/ReviewConverter.java @@ -0,0 +1,52 @@ +package com.example.umc9th.domain.review.converter; + +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.restaurant.entity.Restaurant; +import com.example.umc9th.domain.review.dto.req.ReviewReqDTO.CreateReviewRequest; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO; +import com.example.umc9th.domain.review.entity.Review; +import java.time.LocalDate; +import org.springframework.data.domain.Page; + +public class ReviewConverter { + + // Entity -> DTO + public static ReviewResDTO.CreateReviewResponse toCreateReviewRes(Review review){ + return ReviewResDTO.CreateReviewResponse.builder() + .reviewId(review.getId()) + .createdAt(review.getCreatedAt()) + .build(); + } + + public static ReviewResDTO.ReviewPreviewListDTO toReviewPreviewListDTO( + Page result + ){ + return ReviewResDTO.ReviewPreviewListDTO.builder() + .reviewList(result.getContent().stream() + .map(ReviewConverter::toReviewPreviewDTO) + .toList() + ) + .listSize(result.getSize()) + .totalPage(result.getTotalPages()) + .totalElements(result.getTotalElements()) + .isFirst(result.isFirst()) + .isLast(result.isLast()) + .build(); + } + + public static ReviewResDTO.ReviewPreviewDTO toReviewPreviewDTO( + Review review + ){ + return ReviewResDTO.ReviewPreviewDTO.builder() + .ownerNickname(review.getMember().getNickname()) + .score(review.getStar()) + .body(review.getContent()) + .createdAt(LocalDate.from(review.getCreatedAt())) + .build(); + } + + // DTO -> Entity + public static Review toReview(CreateReviewRequest dto, Member member, Restaurant restaurant){ + return Review.create(member, restaurant, dto.getStar(), dto.getContent()); + } +} diff --git a/src/main/java/com/example/umc9th/domain/review/dto/req/ReviewReqDTO.java b/src/main/java/com/example/umc9th/domain/review/dto/req/ReviewReqDTO.java new file mode 100644 index 0000000..a1c76f2 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/dto/req/ReviewReqDTO.java @@ -0,0 +1,17 @@ +package com.example.umc9th.domain.review.dto.req; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +public class ReviewReqDTO { + + @Builder + @Getter + @AllArgsConstructor + public static class CreateReviewRequest{ + private float star; + private String content; + } + +} diff --git a/src/main/java/com/example/umc9th/domain/review/dto/res/ReviewResDTO.java b/src/main/java/com/example/umc9th/domain/review/dto/res/ReviewResDTO.java new file mode 100644 index 0000000..0b9a2b5 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/dto/res/ReviewResDTO.java @@ -0,0 +1,47 @@ +package com.example.umc9th.domain.review.dto.res; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +public class ReviewResDTO { + + @Builder + @Getter + @AllArgsConstructor + public static class MyReviewResponse{ + private Long id; + private String content; + private float star; + private String reply; + } + + @Builder + @Getter + @AllArgsConstructor + public static class CreateReviewResponse{ + private Long reviewId; + private LocalDateTime createdAt; + } + + @Builder + public record ReviewPreviewListDTO( + List reviewList, + Integer listSize, + Integer totalPage, + Long totalElements, + Boolean isFirst, + Boolean isLast + ){} + + @Builder + public record ReviewPreviewDTO( + String ownerNickname, + Float score, + String body, + LocalDate createdAt + ){} +} diff --git a/src/main/java/com/example/umc9th/domain/review/entity/Reply.java b/src/main/java/com/example/umc9th/domain/review/entity/Reply.java new file mode 100644 index 0000000..0bf3b46 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/entity/Reply.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.review.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "reply") +public class Reply { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "content", nullable = false) + private String content; //답글 내용 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "review_id") + private Review review; +} diff --git a/src/main/java/com/example/umc9th/domain/review/entity/Review.java b/src/main/java/com/example/umc9th/domain/review/entity/Review.java new file mode 100644 index 0000000..7160fb8 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/entity/Review.java @@ -0,0 +1,44 @@ +package com.example.umc9th.domain.review.entity; + +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.restaurant.entity.Restaurant; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "review") +public class Review extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "star", nullable = false) + private float star; //별점 + + @Column(name = "content", nullable = false) + private String content; //리뷰 내용 + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "restaurant_id") + private Restaurant restaurant; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + // 정적 팩토리 메서드 + public static Review create(Member member, Restaurant restaurant, float star, String content){ + Review review = new Review(); + review.member = member; + review.restaurant = restaurant; + review.star = star; + review.content = content; + return review; + } +} diff --git a/src/main/java/com/example/umc9th/domain/review/entity/ReviewPhoto.java b/src/main/java/com/example/umc9th/domain/review/entity/ReviewPhoto.java new file mode 100644 index 0000000..d5b63c3 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/entity/ReviewPhoto.java @@ -0,0 +1,24 @@ +package com.example.umc9th.domain.review.entity; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@Table(name = "review_photo") +public class ReviewPhoto { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "image_url", nullable = false) + private String imageUrl; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "review_id") + private Review review; +} diff --git a/src/main/java/com/example/umc9th/domain/review/exception/ReviewException.java b/src/main/java/com/example/umc9th/domain/review/exception/ReviewException.java new file mode 100644 index 0000000..afde6b0 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/exception/ReviewException.java @@ -0,0 +1,10 @@ +package com.example.umc9th.domain.review.exception; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.exception.GeneralException; + +public class ReviewException extends GeneralException { + public ReviewException(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/example/umc9th/domain/review/exception/code/ReviewErrorCode.java b/src/main/java/com/example/umc9th/domain/review/exception/code/ReviewErrorCode.java new file mode 100644 index 0000000..242a419 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/exception/code/ReviewErrorCode.java @@ -0,0 +1,21 @@ +package com.example.umc9th.domain.review.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ReviewErrorCode implements BaseErrorCode { + + NOT_FOUND(HttpStatus.NOT_FOUND, + "REVIEW404_1", + "리뷰를 찾을 수 없습니다."), + ; + + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/review/exception/code/ReviewSuccessCode.java b/src/main/java/com/example/umc9th/domain/review/exception/code/ReviewSuccessCode.java new file mode 100644 index 0000000..d31419c --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/exception/code/ReviewSuccessCode.java @@ -0,0 +1,25 @@ +package com.example.umc9th.domain.review.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseSuccessCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum ReviewSuccessCode implements BaseSuccessCode { + + CREATED(HttpStatus.CREATED, + "REVIEW201_1", + "성공적으로 리뷰를 생성했습니다."), + + FOUND(HttpStatus.OK, + "REVIEW200_1", + "성공적으로 리뷰를 조회했습니다."), + ; + + private final HttpStatus status; + private final String code; + private final String message; + +} diff --git a/src/main/java/com/example/umc9th/domain/review/repository/ReviewQueryDsl.java b/src/main/java/com/example/umc9th/domain/review/repository/ReviewQueryDsl.java new file mode 100644 index 0000000..d26b662 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/repository/ReviewQueryDsl.java @@ -0,0 +1,15 @@ +package com.example.umc9th.domain.review.repository; + +import com.example.umc9th.domain.review.dto.res.ReviewResDTO.MyReviewResponse; +import com.example.umc9th.domain.review.entity.Review; +import com.querydsl.core.types.Predicate; +import java.util.List; + +public interface ReviewQueryDsl { + + //검색 API + List searchReview(Predicate predicate); + + // 내 리뷰 보기 API + List searchMyReviews(Predicate predicate); +} diff --git a/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepository.java b/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepository.java new file mode 100644 index 0000000..bdc5300 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepository.java @@ -0,0 +1,13 @@ +package com.example.umc9th.domain.review.repository; + +import com.example.umc9th.domain.restaurant.entity.Restaurant; +import com.example.umc9th.domain.review.entity.Review; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReviewRepository extends JpaRepository, ReviewQueryDsl { + + Page findAllByRestaurant(Restaurant restaurant, PageRequest pageRequest); +} + diff --git a/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepositoryImpl.java b/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepositoryImpl.java new file mode 100644 index 0000000..47f5d12 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepositoryImpl.java @@ -0,0 +1,63 @@ +package com.example.umc9th.domain.review.repository; + +import com.example.umc9th.domain.restaurant.entity.QRegion; +import com.example.umc9th.domain.restaurant.entity.QRestaurant; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO.MyReviewResponse; +import com.example.umc9th.domain.review.entity.QReply; +import com.example.umc9th.domain.review.entity.QReview; +import com.example.umc9th.domain.review.entity.Review; +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.Predicate; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class ReviewRepositoryImpl implements ReviewQueryDsl { + + private final JPAQueryFactory queryFactory; + + //리뷰 검색 + @Override + public List searchReview(Predicate predicate) { + // Q 클래스 선언 + QReview review = QReview.review; + QRestaurant restaurant = QRestaurant.restaurant; + QRegion region = QRegion.region; + + return queryFactory + .selectFrom(review) + .leftJoin(restaurant).on(restaurant.id.eq(review.restaurant.id)) + .leftJoin(region).on(region.id.eq(restaurant.region.id)) + .where(predicate) + .fetch(); + } + + //내가 작성한 리뷰 + @Override + public List searchMyReviews(Predicate predicate) { + // Q 클래스 선언 + QReview review = QReview.review; + QRestaurant restaurant = QRestaurant.restaurant; + QReply reply = QReply.reply; + + return queryFactory + .select(Projections.constructor( + MyReviewResponse.class, + review.id, + review.content, + review.star, + reply.content + )) + .from(review) + .leftJoin(review.restaurant, restaurant) + .leftJoin(reply).on(reply.review.eq(review)) + .where(predicate) + .orderBy(review.id.asc()) + .fetch(); + } +} diff --git a/src/main/java/com/example/umc9th/domain/review/service/command/ReviewCommandService.java b/src/main/java/com/example/umc9th/domain/review/service/command/ReviewCommandService.java new file mode 100644 index 0000000..a27b7a7 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/service/command/ReviewCommandService.java @@ -0,0 +1,9 @@ +package com.example.umc9th.domain.review.service.command; + +import com.example.umc9th.domain.review.dto.req.ReviewReqDTO.CreateReviewRequest; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO.CreateReviewResponse; + +public interface ReviewCommandService { + // 리뷰 작성하기 + CreateReviewResponse createReview(Long restaurantId, CreateReviewRequest request); +} diff --git a/src/main/java/com/example/umc9th/domain/review/service/command/ReviewCommandServiceImpl.java b/src/main/java/com/example/umc9th/domain/review/service/command/ReviewCommandServiceImpl.java new file mode 100644 index 0000000..37e4e70 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/service/command/ReviewCommandServiceImpl.java @@ -0,0 +1,51 @@ +package com.example.umc9th.domain.review.service.command; + +import com.example.umc9th.domain.member.entity.Member; +import com.example.umc9th.domain.member.exception.MemberException; +import com.example.umc9th.domain.member.exception.code.MemberErrorCode; +import com.example.umc9th.domain.member.repository.MemberRepository; +import com.example.umc9th.domain.restaurant.entity.Restaurant; +import com.example.umc9th.domain.restaurant.exception.RestaurantException; +import com.example.umc9th.domain.restaurant.exception.code.RestaurantErrorCode; +import com.example.umc9th.domain.restaurant.repository.RestaurantRepository; +import com.example.umc9th.domain.review.converter.ReviewConverter; +import com.example.umc9th.domain.review.dto.req.ReviewReqDTO.CreateReviewRequest; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO.CreateReviewResponse; +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.review.repository.ReviewRepository; +import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class ReviewCommandServiceImpl implements ReviewCommandService{ + + private final MemberRepository memberRepository; + private final RestaurantRepository restaurantRepository; + private final ReviewRepository reviewRepository; + + // 리뷰 작성하기 + @Override + @Transactional + public CreateReviewResponse createReview(Long restaurantId, CreateReviewRequest request){ + + // 유저 id 하드코딩 + Long memberId = 1L; + Member member = memberRepository.findById(memberId) + .orElseThrow(() ->new MemberException(MemberErrorCode.NOT_FOUND)); + + Restaurant restaurant = restaurantRepository.findById(restaurantId) + .orElseThrow(() -> new RestaurantException(RestaurantErrorCode.NOT_FOUND)); + + // 정적 팩토리 메서드 사용 + Review review = ReviewConverter.toReview(request, member, restaurant); + + // 리뷰 저장 + reviewRepository.save(review); + + return ReviewConverter.toCreateReviewRes(review); + + } +} diff --git a/src/main/java/com/example/umc9th/domain/review/service/query/ReviewQueryService.java b/src/main/java/com/example/umc9th/domain/review/service/query/ReviewQueryService.java new file mode 100644 index 0000000..6496a2f --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/service/query/ReviewQueryService.java @@ -0,0 +1,18 @@ +package com.example.umc9th.domain.review.service.query; + +import com.example.umc9th.domain.review.dto.res.ReviewResDTO; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO.MyReviewResponse; +import com.example.umc9th.domain.review.entity.Review; +import java.util.List; + +public interface ReviewQueryService { + // 리뷰 검색 + List searchReview(String query, String type); + + // 내가 작성한 리뷰 + List searchMyReviews(Long memberId, String restaurantName, Integer star); + + // 가게의 리뷰 목록 조회 + ReviewResDTO.ReviewPreviewListDTO findReview(String restaurantName, Integer page); + +} diff --git a/src/main/java/com/example/umc9th/domain/review/service/query/ReviewQueryServiceImpl.java b/src/main/java/com/example/umc9th/domain/review/service/query/ReviewQueryServiceImpl.java new file mode 100644 index 0000000..6579cbc --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/service/query/ReviewQueryServiceImpl.java @@ -0,0 +1,114 @@ +package com.example.umc9th.domain.review.service.query; + +import static com.example.umc9th.domain.restaurant.entity.QRegion.region; + +import com.example.umc9th.domain.restaurant.entity.Restaurant; +import com.example.umc9th.domain.restaurant.exception.RestaurantException; +import com.example.umc9th.domain.restaurant.exception.code.RestaurantErrorCode; +import com.example.umc9th.domain.restaurant.repository.RestaurantRepository; +import com.example.umc9th.domain.review.converter.ReviewConverter; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO; +import com.example.umc9th.domain.review.dto.res.ReviewResDTO.MyReviewResponse; +import com.example.umc9th.domain.review.entity.QReview; +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.review.repository.ReviewRepository; +import com.querydsl.core.BooleanBuilder; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ReviewQueryServiceImpl implements ReviewQueryService{ + + private final ReviewRepository reviewRepository; + private final RestaurantRepository restaurantRepository; + + @Override + public List searchReview(String query, String type){ + // Q클래스 정의 + QReview review = QReview.review; + + // BooleanBuilder 정의 + BooleanBuilder builder = new BooleanBuilder(); + + // BooleanBuilder 사용 + + // 동적 쿼리: 검색 조건 + if(type.equals("region")){ + builder.and(region.name.contains(query)); + } + if(type.equals("star")){ + builder.and(review.star.goe(Float.parseFloat(query))); + } + if(type.equals("both")){ + + // & 기준 변환 + String firstQuery = query.split("&")[0]; + String secondQuery = query.split("&")[1]; + + // 동적 쿼리 + builder.and(region.name.contains(firstQuery)); + builder.and(review.star.goe(Float.parseFloat(secondQuery))); + } + + // Repository 사용 & 결과 매핑 + List reviewList = reviewRepository.searchReview(builder); + + // 리턴 + return reviewList; + } + + @Override + // 내가 작성한 리뷰 + public List searchMyReviews(Long memberId, String restaurantName, Integer star){ + // Q 클래스 선언 + QReview review = QReview.review; + //QRestaurant restaurant = QRestaurant.restaurant; + + // BooleanBuilder 정의 + BooleanBuilder builder = new BooleanBuilder(); + + // BooleanBuilder 사용 + builder.and(review.member.id.eq(memberId)); //내 리뷰만 + + if(restaurantName != null && !restaurantName.isEmpty()){ + builder.and(review.restaurant.name.contains(restaurantName)); + } + if(star != null){ + float minStar = star.floatValue(); + float maxStar = star + 1.0f; + builder.and(review.star.goe(minStar)); + builder.and(review.star.lt(maxStar)); + } + + // Repository 사용 & 결과 매핑 + List myReviews = reviewRepository.searchMyReviews(builder); + + // 리턴 + return myReviews; + + } + + // 가게의 리뷰 목록 조회 + @Override + public ReviewResDTO.ReviewPreviewListDTO findReview( + String restaurantName, + Integer page + ){ + // 가게 존재 여부 검증 + Restaurant restaurant = restaurantRepository.findByName(restaurantName) + .orElseThrow(() -> new RestaurantException(RestaurantErrorCode.NOT_FOUND)); + + // 가게에 맞는 리뷰 가져오기(Offset 페이징) + PageRequest pageRequest = PageRequest.of(page, 5); + Page result = reviewRepository.findAllByRestaurant(restaurant, pageRequest); + + // 결과 응답 DTO 변환(컨버터 이용) + return ReviewConverter.toReviewPreviewListDTO(result); + } + + +} diff --git a/src/main/java/com/example/umc9th/domain/test/controller/TestController.java b/src/main/java/com/example/umc9th/domain/test/controller/TestController.java new file mode 100644 index 0000000..72458de --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/controller/TestController.java @@ -0,0 +1,47 @@ +package com.example.umc9th.domain.test.controller; + +import com.example.umc9th.domain.test.converter.TestConverter; +import com.example.umc9th.domain.test.dto.res.TestResDTO; +import com.example.umc9th.domain.test.exception.TestException; +import com.example.umc9th.domain.test.service.query.TestQueryService; +import com.example.umc9th.global.apiPayload.ApiResponse; +import com.example.umc9th.global.apiPayload.code.GeneralErrorCode; +import com.example.umc9th.global.apiPayload.code.GeneralSuccessCode; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/temp") +public class TestController { + + private final TestQueryService testQueryService; + + @GetMapping("/test") + public ApiResponse test() throws Exception{ + // 응답 코드 정의 + GeneralSuccessCode code = GeneralSuccessCode.OK; + + return ApiResponse.onSuccess( + code, + TestConverter.toTestingDTO("This is Test!") + ); + } + + // 예외 상황 + @GetMapping("/exception") + public ApiResponse exception(@RequestParam Long flag) { + + testQueryService.checkFlag(flag); + + // 응답 코드 정의 + GeneralSuccessCode code = GeneralSuccessCode.OK; + return ApiResponse.onSuccess( + code, + TestConverter.toExceptionDTO("This is Test!") + ); + } +} diff --git a/src/main/java/com/example/umc9th/domain/test/converter/TestConverter.java b/src/main/java/com/example/umc9th/domain/test/converter/TestConverter.java new file mode 100644 index 0000000..ac2430e --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/converter/TestConverter.java @@ -0,0 +1,20 @@ +package com.example.umc9th.domain.test.converter; + +import com.example.umc9th.domain.test.dto.res.TestResDTO; + +public class TestConverter { + + // 객체 -> DTO + public static TestResDTO.Testing toTestingDTO(String testing){ + return TestResDTO.Testing.builder() + .testString(testing) + .build(); + } + + // 객체 -> DTO + public static TestResDTO.Exception toExceptionDTO(String testing){ + return TestResDTO.Exception.builder() + .testString(testing) + .build(); + } +} diff --git a/src/main/java/com/example/umc9th/domain/test/dto/req/TestReqDTO.java b/src/main/java/com/example/umc9th/domain/test/dto/req/TestReqDTO.java new file mode 100644 index 0000000..405e3b9 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/dto/req/TestReqDTO.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.test.dto.req; + +public class TestReqDTO { +} diff --git a/src/main/java/com/example/umc9th/domain/test/dto/res/TestResDTO.java b/src/main/java/com/example/umc9th/domain/test/dto/res/TestResDTO.java new file mode 100644 index 0000000..d59fca5 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/dto/res/TestResDTO.java @@ -0,0 +1,18 @@ +package com.example.umc9th.domain.test.dto.res; + +import lombok.Builder; +import lombok.Getter; + +public class TestResDTO { + @Builder + @Getter + public static class Testing { + private String testString; + } + + @Builder + @Getter + public static class Exception{ + private String testString; + } +} diff --git a/src/main/java/com/example/umc9th/domain/test/exception/TestException.java b/src/main/java/com/example/umc9th/domain/test/exception/TestException.java new file mode 100644 index 0000000..1faf200 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/exception/TestException.java @@ -0,0 +1,10 @@ +package com.example.umc9th.domain.test.exception; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.exception.GeneralException; + +public class TestException extends GeneralException { + public TestException(BaseErrorCode code) { + super(code); + } +} diff --git a/src/main/java/com/example/umc9th/domain/test/exception/code/TestErrorCode.java b/src/main/java/com/example/umc9th/domain/test/exception/code/TestErrorCode.java new file mode 100644 index 0000000..43b3ee0 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/exception/code/TestErrorCode.java @@ -0,0 +1,21 @@ +package com.example.umc9th.domain.test.exception.code; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum TestErrorCode implements BaseErrorCode { + + // For test + TEST_EXCEPTION(HttpStatus.BAD_REQUEST, + "TEST400_1", + "이거는 테스트"), + ; + + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/domain/test/service/command/TestCommandService.java b/src/main/java/com/example/umc9th/domain/test/service/command/TestCommandService.java new file mode 100644 index 0000000..b1102dd --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/service/command/TestCommandService.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.test.service.command; + +public interface TestCommandService { +} diff --git a/src/main/java/com/example/umc9th/domain/test/service/command/TestCommandServiceImpl.java b/src/main/java/com/example/umc9th/domain/test/service/command/TestCommandServiceImpl.java new file mode 100644 index 0000000..3e5a276 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/service/command/TestCommandServiceImpl.java @@ -0,0 +1,4 @@ +package com.example.umc9th.domain.test.service.command; + +public class TestCommandServiceImpl { +} diff --git a/src/main/java/com/example/umc9th/domain/test/service/query/TestQueryService.java b/src/main/java/com/example/umc9th/domain/test/service/query/TestQueryService.java new file mode 100644 index 0000000..2163565 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/service/query/TestQueryService.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.test.service.query; + +public interface TestQueryService { + void checkFlag(Long flag); +} diff --git a/src/main/java/com/example/umc9th/domain/test/service/query/TestQueryServiceImpl.java b/src/main/java/com/example/umc9th/domain/test/service/query/TestQueryServiceImpl.java new file mode 100644 index 0000000..1b583e7 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/test/service/query/TestQueryServiceImpl.java @@ -0,0 +1,17 @@ +package com.example.umc9th.domain.test.service.query; + +import com.example.umc9th.domain.test.exception.TestException; +import com.example.umc9th.domain.test.exception.code.TestErrorCode; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class TestQueryServiceImpl implements TestQueryService{ + @Override + public void checkFlag(Long flag) { + if(flag == 1){ + throw new TestException(TestErrorCode.TEST_EXCEPTION); + } + } +} diff --git a/src/main/java/com/example/umc9th/global/annotation/ExistFoods.java b/src/main/java/com/example/umc9th/global/annotation/ExistFoods.java new file mode 100644 index 0000000..a55b4af --- /dev/null +++ b/src/main/java/com/example/umc9th/global/annotation/ExistFoods.java @@ -0,0 +1,22 @@ +package com.example.umc9th.global.annotation; + +import com.example.umc9th.global.validator.FoodExistValidator; +import jakarta.validation.Constraint; +import jakarta.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Constraint(validatedBy = FoodExistValidator.class) +@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +public @interface ExistFoods { + // 디폴트 메시지 설정 + String message() default "해당 음식이 존재하지 않습니다."; + Class[] groups() default {}; + Class[] payload() default {}; + +} diff --git a/src/main/java/com/example/umc9th/global/apiPayload/ApiResponse.java b/src/main/java/com/example/umc9th/global/apiPayload/ApiResponse.java new file mode 100644 index 0000000..809ea7c --- /dev/null +++ b/src/main/java/com/example/umc9th/global/apiPayload/ApiResponse.java @@ -0,0 +1,36 @@ +package com.example.umc9th.global.apiPayload; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.code.BaseSuccessCode; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@JsonPropertyOrder({"isSuccess", "code", "message", "result"}) +public class ApiResponse { + + @JsonProperty("isSuccess") + private final Boolean isSuccess; + + @JsonProperty("code") + private final String code; + + @JsonProperty("message") + private final String message; + + @JsonProperty("result") + private T result; + + // 성공한 경우 (result 포함) + public static ApiResponse onSuccess(BaseSuccessCode code, T result) { + return new ApiResponse<>(true, code.getCode(), code.getMessage(), result); + } + + // 실패한 경우 (result 포함) + public static ApiResponse onFailure(BaseErrorCode code, T result) { + return new ApiResponse<>(false, code.getCode(), code.getMessage(), result); + } +} diff --git a/src/main/java/com/example/umc9th/global/apiPayload/code/BaseErrorCode.java b/src/main/java/com/example/umc9th/global/apiPayload/code/BaseErrorCode.java new file mode 100644 index 0000000..d1e67b6 --- /dev/null +++ b/src/main/java/com/example/umc9th/global/apiPayload/code/BaseErrorCode.java @@ -0,0 +1,9 @@ +package com.example.umc9th.global.apiPayload.code; + +import org.springframework.http.HttpStatus; + +public interface BaseErrorCode { + HttpStatus getStatus(); + String getCode(); + String getMessage(); +} diff --git a/src/main/java/com/example/umc9th/global/apiPayload/code/BaseSuccessCode.java b/src/main/java/com/example/umc9th/global/apiPayload/code/BaseSuccessCode.java new file mode 100644 index 0000000..19d1b22 --- /dev/null +++ b/src/main/java/com/example/umc9th/global/apiPayload/code/BaseSuccessCode.java @@ -0,0 +1,9 @@ +package com.example.umc9th.global.apiPayload.code; + +import org.springframework.http.HttpStatus; + +public interface BaseSuccessCode { + HttpStatus getStatus(); + String getCode(); + String getMessage(); +} diff --git a/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralErrorCode.java b/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralErrorCode.java new file mode 100644 index 0000000..9cd7b3c --- /dev/null +++ b/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralErrorCode.java @@ -0,0 +1,31 @@ +package com.example.umc9th.global.apiPayload.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum GeneralErrorCode implements BaseErrorCode{ + BAD_REQUEST(HttpStatus.BAD_REQUEST, + "COMMON400_1", + "잘못된 요청입니다."), + UNAUTHORIZED(HttpStatus.UNAUTHORIZED, + "AUTH401_1", + "인증이 필요합니다."), + FORBIDDEN(HttpStatus.FORBIDDEN, + "AUTH403_1", + "요청이 거부되었습니다."), + NOT_FOUND(HttpStatus.NOT_FOUND, + "COMMON404_1", + "요청한 리소스를 찾을 수 없습니다."), + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, + "COMMON500_1", + "예기치 않은 서버 에러가 발생했습니다."), + ; + + // 각 상수가 가질 속성 + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralSuccessCode.java b/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralSuccessCode.java new file mode 100644 index 0000000..664ac1d --- /dev/null +++ b/src/main/java/com/example/umc9th/global/apiPayload/code/GeneralSuccessCode.java @@ -0,0 +1,27 @@ +package com.example.umc9th.global.apiPayload.code; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum GeneralSuccessCode implements BaseSuccessCode{ + OK(HttpStatus.OK, + "COMMON200_1", + "요청이 성공적으로 처리되었습니다."), + CREATED(HttpStatus.CREATED, + "COMMON201_1", + "리소스가 성공적으로 생성되었습니다."), + ACCEPTED(HttpStatus.ACCEPTED, + "COMMON202_1", + "요청이 접수되었으며, 처리가 진행 중입니다."), + NO_CONTENT(HttpStatus.NO_CONTENT, + "COMMON204_1", + "요청이 성공했으나 반환할 콘텐츠가 없습니다."); + + // 각 상수가 가질 속성 + private final HttpStatus status; + private final String code; + private final String message; +} diff --git a/src/main/java/com/example/umc9th/global/apiPayload/exception/GeneralException.java b/src/main/java/com/example/umc9th/global/apiPayload/exception/GeneralException.java new file mode 100644 index 0000000..2a3a34a --- /dev/null +++ b/src/main/java/com/example/umc9th/global/apiPayload/exception/GeneralException.java @@ -0,0 +1,12 @@ +package com.example.umc9th.global.apiPayload.exception; + +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class GeneralException extends RuntimeException{ + + private final BaseErrorCode code; +} diff --git a/src/main/java/com/example/umc9th/global/apiPayload/handler/GeneralExceptionAdvice.java b/src/main/java/com/example/umc9th/global/apiPayload/handler/GeneralExceptionAdvice.java new file mode 100644 index 0000000..39d91b4 --- /dev/null +++ b/src/main/java/com/example/umc9th/global/apiPayload/handler/GeneralExceptionAdvice.java @@ -0,0 +1,29 @@ +package com.example.umc9th.global.apiPayload.handler; + +import com.example.umc9th.global.apiPayload.ApiResponse; +import com.example.umc9th.global.apiPayload.code.BaseErrorCode; +import com.example.umc9th.global.apiPayload.code.GeneralErrorCode; +import com.example.umc9th.global.apiPayload.exception.GeneralException; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GeneralExceptionAdvice { + + // 애플리케이션에서 발생하는 커스텀 예외를 처리 + @ExceptionHandler(GeneralException.class) + public ResponseEntity> handleException(GeneralException ex) { + return ResponseEntity.status(ex.getCode().getStatus()) + .body(ApiResponse.onFailure(ex.getCode(), null)); + } + + + // 그 외의 정의되지 않은 모든 예외 처리 + @ExceptionHandler(Exception.class) + public ResponseEntity> handleException(Exception ex) { + BaseErrorCode code = GeneralErrorCode.INTERNAL_SERVER_ERROR; + return ResponseEntity.status(code.getStatus()) + .body(ApiResponse.onFailure(code, ex.getMessage())); + } +} diff --git a/src/main/java/com/example/umc9th/global/config/QuerydslConfig.java b/src/main/java/com/example/umc9th/global/config/QuerydslConfig.java new file mode 100644 index 0000000..7d2a62a --- /dev/null +++ b/src/main/java/com/example/umc9th/global/config/QuerydslConfig.java @@ -0,0 +1,18 @@ +package com.example.umc9th.global.config; + +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class QuerydslConfig { + @PersistenceContext + EntityManager em; + + @Bean + public JPAQueryFactory jpaQueryFactory(){ + return new JPAQueryFactory(em); + } +} diff --git a/src/main/java/com/example/umc9th/global/config/SwaggerConfig.java b/src/main/java/com/example/umc9th/global/config/SwaggerConfig.java new file mode 100644 index 0000000..37a7c11 --- /dev/null +++ b/src/main/java/com/example/umc9th/global/config/SwaggerConfig.java @@ -0,0 +1,36 @@ +package com.example.umc9th.global.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.oas.models.servers.Server; + +@Configuration +public class SwaggerConfig { + @Bean + public OpenAPI swagger() { + Info info = new Info().title("Project").description("Project 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/src/main/java/com/example/umc9th/global/entity/BaseEntity.java b/src/main/java/com/example/umc9th/global/entity/BaseEntity.java new file mode 100644 index 0000000..9261134 --- /dev/null +++ b/src/main/java/com/example/umc9th/global/entity/BaseEntity.java @@ -0,0 +1,25 @@ +package com.example.umc9th.global.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +@Getter +public abstract class BaseEntity { + + @CreatedDate + @Column(name = "created_at", nullable = false) + private LocalDateTime createdAt; //생성일자 + + @LastModifiedDate + @Column(name = "updated_at", nullable = false) + private LocalDateTime updatedAt; //수정일자 +} diff --git a/src/main/java/com/example/umc9th/global/validator/FoodExistValidator.java b/src/main/java/com/example/umc9th/global/validator/FoodExistValidator.java new file mode 100644 index 0000000..32a275a --- /dev/null +++ b/src/main/java/com/example/umc9th/global/validator/FoodExistValidator.java @@ -0,0 +1,30 @@ +package com.example.umc9th.global.validator; + +import com.example.umc9th.domain.member.exception.code.FoodErrorCode; +import com.example.umc9th.domain.member.repository.FoodRepository; +import com.example.umc9th.global.annotation.ExistFoods; +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class FoodExistValidator implements ConstraintValidator> { + + private final FoodRepository foodRepository; + + @Override + public boolean isValid(List values, ConstraintValidatorContext context) { + boolean isValid = values.stream() + .allMatch(value -> foodRepository.existsById(value)); + + if(!isValid){ + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate(FoodErrorCode.NOT_FOUND.getMessage()).addConstraintViolation(); + } + + return isValid; + } +} diff --git a/src/test/java/com/example/umc9th/Umc9thApplicationTests.java b/src/test/java/com/example/umc9th/Umc9thApplicationTests.java new file mode 100644 index 0000000..bbdf1bd --- /dev/null +++ b/src/test/java/com/example/umc9th/Umc9thApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.umc9th; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Umc9thApplicationTests { + + @Test + void contextLoads() { + } + +}