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/.github/ISSUE_TEMPLATE/feat.md b/.github/ISSUE_TEMPLATE/feat.md new file mode 100644 index 0000000..bf7cc41 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feat.md @@ -0,0 +1,16 @@ +--- +name: feat +about: feature issue template +title: "[Feat] #์ฃผ์ฐจ - ์ œ๋ชฉ" +labels: '' +assignees: '' + +--- + +## ๐Ÿ’ก About +> ๊ฐœ๋ฐœ ๋‚ด์šฉ์— ๋Œ€ํ•ด ๊ฐ„๋‹จํžˆ ์ ์–ด์ฃผ์„ธ์š”! + +## โœ… To Do +- [ ] task1 + +## ๐Ÿ’ฌ ETC diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..4c082df --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,16 @@ +## ๐Ÿ› ๏ธ ์ž‘์—… ๋‚ด์šฉ + +> ์ž‘์—…ํ•˜์‹  ๋‚ด์šฉ์„ ๊ฐ„๋žตํ•˜๊ฒŒ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. + +## ๐Ÿง ๋ฆฌ๋ทฐ ํฌ์ธํŠธ + +> ๋ฆฌ๋ทฐ์–ด๊ฐ€ ์ง‘์ค‘์ ์œผ๋กœ ๋ด์•ผ ํ•  ๋ถ€๋ถ„์„ ์•Œ๋ ค์ฃผ์„ธ์š”. + +## โœ… ์ฒดํฌ๋ฆฌ์ŠคํŠธ + +- [ ] ์ปค๋ฐ‹ ์ปจ๋ฒค์…˜์„ ๋งž์ท„๋‚˜์š”? +- [ ] ์ฝ”๋“œ์— ์˜คํƒ€๋Š” ์—†๋‚˜์š”? + +--- + +> `close #์ด์Šˆ๋ฒˆํ˜ธ` diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..af18a61 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,44 @@ +name: Spring Boot CI Pipeline + +# ์›Œํฌํ”Œ๋กœ์šฐ ์‹คํ–‰ ์กฐ๊ฑด +on: + push: + branches: [ "main" ] # main ๋ธŒ๋žœ์น˜์— push๋  ๋•Œ + pull_request: + branches: [ "develop" ] # develop ๋ธŒ๋žœ์น˜๋กœ PR์ด ์ƒ์„ฑ/์—…๋ฐ์ดํŠธ๋  ๋•Œ + +jobs: + build-and-test: # ๋นŒ๋“œ์™€ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ๋‹จ์ผ ์ž‘์—… + runs-on: ubuntu-latest + + steps: + # 1. ์ €์žฅ์†Œ ์ฝ”๋“œ ์ฒดํฌ์•„์›ƒ (์ตœ์‹  ๋ฒ„์ „ v4 ์‚ฌ์šฉ) + - name: Checkout repository + uses: actions/checkout@v4 + + # 2. JDK 17 ์„ค์ • ๋ฐ Gradle ์บ์‹ฑ (์ตœ์‹  ๋ฒ„์ „ v4 ์‚ฌ์šฉ) + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: 'gradle' # Gradle ์˜์กด์„ฑ์„ ์บ์‹ฑํ•˜์—ฌ ๋‹ค์Œ ๋นŒ๋“œ๋ถ€ํ„ฐ ์†๋„๋ฅผ ํ–ฅ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค. + + # 3. GitHub Secret์„ ์‚ฌ์šฉํ•˜์—ฌ application.yml ํŒŒ์ผ ์ƒ์„ฑ + # ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ์—๋„ ์•ˆ์ „ํ•˜๊ฒŒ ์ƒ์„ฑํ•˜๋„๋ก 'mkdir -p'๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. + - name: Make application.yml + run: | + mkdir -p ./src/main/resources + echo "${{ secrets.APPLICATION_YML }}" > ./src/main/resources/application.yml + shell: bash + + # 4. gradlew ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + # 5. Gradle๋กœ ๋นŒ๋“œ ๋ฐ ํ…Œ์ŠคํŠธ ์‹คํ–‰ (์ตœ์‹  ๋ฒ„์ „ v3 ์‚ฌ์šฉ) + # Gradle์˜ 'build' ๋ช…๋ น์–ด๋Š” ์ปดํŒŒ์ผ, ํ…Œ์ŠคํŠธ ์‹คํ–‰, jar ํŒŒ์ผ ํŒจํ‚ค์ง•์„ ๋ชจ๋‘ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค. + - name: Build with Gradle + uses: gradle/gradle-build-action@v3 + with: + arguments: build diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b1ac64 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +application.yml +\n# Ignore environment-specific yml files\napplication-*.yml\n!application.yml diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..118b98c --- /dev/null +++ b/build.gradle @@ -0,0 +1,39 @@ +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(17) + } +} + +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' +} + +tasks.named('test') { + useJUnitPlatform() +} 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 100755 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/category/entity/Category.java b/src/main/java/com/example/umc9th/domain/category/entity/Category.java new file mode 100644 index 0000000..d85fd30 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/category/entity/Category.java @@ -0,0 +1,32 @@ +package com.example.umc9th.domain.category.entity; + +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.user.entity.User; +import com.example.umc9th.domain.user.entity.UserCategory; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.util.Set; + +@Table(name = "category") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class Category extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "category_id") + private Long id; + + @Column(nullable = false) + private String categoryName; + + @OneToMany(mappedBy = "category", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private Set userCategories; +} diff --git a/src/main/java/com/example/umc9th/domain/inqury/entity/Inquiry.java b/src/main/java/com/example/umc9th/domain/inqury/entity/Inquiry.java new file mode 100644 index 0000000..bf3f1cd --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/inqury/entity/Inquiry.java @@ -0,0 +1,49 @@ +package com.example.umc9th.domain.inqury.entity; + +import com.example.umc9th.domain.inqury.enums.InquiryType; +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.user.entity.User; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.util.ArrayList; +import java.util.List; + +@Table(name = "inquiry") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class Inquiry extends BaseEntity { + + @Id + @Column(name = "inquiry_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @Column(nullable = false) + private String title; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private InquiryType type; + + @Column(nullable = false) + private String content; + + @Builder.Default + private Boolean isAnswered = false; + + @OneToMany(mappedBy = "inquiry", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @Builder.Default + private List inquiryImages = new ArrayList<>(); + +} diff --git a/src/main/java/com/example/umc9th/domain/inqury/entity/InquiryImage.java b/src/main/java/com/example/umc9th/domain/inqury/entity/InquiryImage.java new file mode 100644 index 0000000..678cf3a --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/inqury/entity/InquiryImage.java @@ -0,0 +1,27 @@ +package com.example.umc9th.domain.inqury.entity; + +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Table(name = "inquiry_image") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class InquiryImage extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "inquiry_id") + private Inquiry inquiry; + + @Column(nullable = false, length = 1024) + private String imageUrl; +} diff --git a/src/main/java/com/example/umc9th/domain/inqury/enums/InquiryType.java b/src/main/java/com/example/umc9th/domain/inqury/enums/InquiryType.java new file mode 100644 index 0000000..4b6d15f --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/inqury/enums/InquiryType.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.inqury.enums; + +public enum InquiryType { + a,b,c +} diff --git a/src/main/java/com/example/umc9th/domain/inqury/repository/InquiryRepository.java b/src/main/java/com/example/umc9th/domain/inqury/repository/InquiryRepository.java new file mode 100644 index 0000000..35f51aa --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/inqury/repository/InquiryRepository.java @@ -0,0 +1,13 @@ +package com.example.umc9th.domain.inqury.repository; + +import com.example.umc9th.domain.inqury.entity.Inquiry; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface InquiryRepository extends JpaRepository { + @Modifying + @Query("DELETE FROM Inquiry i WHERE i.user.id = :userId") + void deleteByUserId(@Param("userId") Long userId); +} diff --git a/src/main/java/com/example/umc9th/domain/mission/dto/MissionInAreaDTO.java b/src/main/java/com/example/umc9th/domain/mission/dto/MissionInAreaDTO.java new file mode 100644 index 0000000..be35a0a --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/dto/MissionInAreaDTO.java @@ -0,0 +1,15 @@ +package com.example.umc9th.domain.mission.dto; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.time.LocalDateTime; + +@Getter +@RequiredArgsConstructor +public class MissionInAreaDTO { + private final String storeName; + private final LocalDateTime createdAt; + private final String missionContent; + private final Integer point; +} diff --git a/src/main/java/com/example/umc9th/domain/mission/dto/UserMissionDTO.java b/src/main/java/com/example/umc9th/domain/mission/dto/UserMissionDTO.java new file mode 100644 index 0000000..fb40d9c --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/dto/UserMissionDTO.java @@ -0,0 +1,14 @@ +package com.example.umc9th.domain.mission.dto; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class UserMissionDTO { + private final Long id; + private final Integer point; + private final String storeName; + private final String missionContent; + private final boolean isCompleted; +} 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..99f9438 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/entity/Mission.java @@ -0,0 +1,32 @@ +package com.example.umc9th.domain.mission.entity; + +import com.example.umc9th.domain.store.entity.Store; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Table(name = "mission") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class Mission extends BaseEntity { + + @Id + @Column(name = "mission_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_id") + private Store store; + + @Column(nullable = false) + private Integer point; + + @Column(nullable = false) + private String content; +} diff --git a/src/main/java/com/example/umc9th/domain/mission/entity/UserMission.java b/src/main/java/com/example/umc9th/domain/mission/entity/UserMission.java new file mode 100644 index 0000000..fd80d75 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/entity/UserMission.java @@ -0,0 +1,35 @@ +package com.example.umc9th.domain.mission.entity; + +import com.example.umc9th.domain.user.entity.User; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Table(name = "user_mission") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class UserMission extends BaseEntity { + + @Id + @Column(name = "user_mission_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_id", nullable = false) + private Mission mission; + + @Column(nullable = false) + @Builder.Default + private Boolean isCompleted = false; + +} 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..574cb69 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/repository/MissionRepository.java @@ -0,0 +1,20 @@ +package com.example.umc9th.domain.mission.repository; + +import com.example.umc9th.domain.mission.dto.MissionInAreaDTO; +import com.example.umc9th.domain.mission.entity.Mission; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.time.LocalDateTime; + +public interface MissionRepository extends JpaRepository { + + @Query("SELECT new com.example.umc9th.domain.mission.dto.MissionInAreaDTO(s.name, m.createdAt, m.content, m.point) " + + "FROM Mission m JOIN m.store s " + + "WHERE s.address LIKE CONCAT(:regionName, '%') AND m.createdAt < :lastCreatedAt " + + "ORDER BY m.createdAt DESC") + Slice findMissionsInArea(@Param("regionName") String regionName, @Param("lastCreatedAt") LocalDateTime lastCreatedAt, Pageable pageable); +} diff --git a/src/main/java/com/example/umc9th/domain/mission/repository/UserMissionRepository.java b/src/main/java/com/example/umc9th/domain/mission/repository/UserMissionRepository.java new file mode 100644 index 0000000..03e0052 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/mission/repository/UserMissionRepository.java @@ -0,0 +1,25 @@ +package com.example.umc9th.domain.mission.repository; + +import com.example.umc9th.domain.mission.dto.UserMissionDTO; +import com.example.umc9th.domain.mission.entity.UserMission; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface UserMissionRepository extends JpaRepository { + @Modifying + @Query("DELETE FROM UserMission um WHERE um.user.id = :userId") + void deleteByUserId(@Param("userId") Long userId); + + + @Query("SELECT new com.example.umc9th.domain.mission.dto.UserMissionDTO(um.id, m.point, s.name, m.content, um.isCompleted) " + + "FROM UserMission um " + + "JOIN um.mission m " + + "JOIN m.store s " + + "WHERE um.user.id = :userId AND um.isCompleted = :isCompleted AND um.id < :lastMissionId " + + "ORDER BY um.id DESC") + Slice findUserMissionsByIsCompleted(@Param("userId") Long userId, @Param("isCompleted") Boolean isCompleted, @Param("lastMissionId") Long lastMissionId, Pageable pageable); +} \ No newline at end of file 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..ccdab19 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/entity/Review.java @@ -0,0 +1,57 @@ +package com.example.umc9th.domain.review.entity; + +import com.example.umc9th.domain.inqury.entity.InquiryImage; +import com.example.umc9th.domain.store.entity.Store; +import com.example.umc9th.domain.user.entity.User; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.util.ArrayList; +import java.util.List; + +@Table(name = "review") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class Review extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "review_id") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_id", nullable = false) + private Store store; + + @Column(nullable = false) + private String content; + + @OneToMany(mappedBy = "review", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + @Builder.Default + private List reviewImages = new ArrayList<>(); + + @Builder.Default + @OneToOne(mappedBy = "review", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private ReviewReply reviewReply = null; + /* + ==== ์ฒ˜์Œ ์ž‘์„ฑํ–ˆ๋˜ ์ฝ”๋“œ ==== + @Column(nullable = false) + @Builder.Default + private Boolean hasReply = false; + + -> 1. ๋ฆฌ๋ทฐ ์‚ญ์ œ์‹œ ๋ฆฌ๋ทฐ ๋‹ต๊ธ€์€ ์–ด๋–ป๊ฒŒ? + 2. 'select * from review_reply where review_id = ?' vs 'select hasReply from review where review_id = ?' + (์‹ค์ œ ์ฟผ๋ฆฌ ๋น„์Šทํ• ๊ฑฐ ๊ฐ™์€๋ฐ ๊ตณ์ด ํ•„๋“œ ์ถ”๊ฐ€..?) + */ + +} diff --git a/src/main/java/com/example/umc9th/domain/review/entity/ReviewImage.java b/src/main/java/com/example/umc9th/domain/review/entity/ReviewImage.java new file mode 100644 index 0000000..7e6f6ca --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/entity/ReviewImage.java @@ -0,0 +1,28 @@ +package com.example.umc9th.domain.review.entity; + +import com.example.umc9th.domain.inqury.entity.Inquiry; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Table(name = "review_image") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class ReviewImage extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "review_id") + private Review review; + + @Column(nullable = false, length = 1024) + private String imageUrl; +} diff --git a/src/main/java/com/example/umc9th/domain/review/entity/ReviewReply.java b/src/main/java/com/example/umc9th/domain/review/entity/ReviewReply.java new file mode 100644 index 0000000..683e8be --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/entity/ReviewReply.java @@ -0,0 +1,27 @@ +package com.example.umc9th.domain.review.entity; + +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Table(name = "review_reply") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class ReviewReply extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "review_id", nullable = false) + private Review review; + + @Column(nullable = false) + private String content; +} 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..628838a --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/repository/ReviewRepository.java @@ -0,0 +1,15 @@ +package com.example.umc9th.domain.review.repository; + +import com.example.umc9th.domain.review.entity.Review; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.transaction.annotation.Transactional; + +public interface ReviewRepository extends JpaRepository { + @Modifying + @Query("DELETE FROM Review r WHERE r.user.id = :userId") + void deleteByUserId(@Param("userId") Long userId); + +} diff --git a/src/main/java/com/example/umc9th/domain/review/service/ReviewService.java b/src/main/java/com/example/umc9th/domain/review/service/ReviewService.java new file mode 100644 index 0000000..0115189 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/service/ReviewService.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.review.service; + +public interface ReviewService { + void createReview(String content, Long userId, Long storeId); +} diff --git a/src/main/java/com/example/umc9th/domain/review/service/ReviewServiceImpl.java b/src/main/java/com/example/umc9th/domain/review/service/ReviewServiceImpl.java new file mode 100644 index 0000000..04fee8c --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/review/service/ReviewServiceImpl.java @@ -0,0 +1,30 @@ +package com.example.umc9th.domain.review.service; + +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.review.repository.ReviewRepository; +import com.example.umc9th.domain.store.repository.StoreRepository; +import com.example.umc9th.domain.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class ReviewServiceImpl implements ReviewService{ + private final UserRepository userRepository; + private final StoreRepository storeRepository; + private final ReviewRepository reviewRepository; + + + @Override + public void createReview(String content, Long userId, Long storeId) { + Review review = Review.builder() + .content(content) + .user(userRepository.getReferenceById(userId)) + .store(storeRepository.getReferenceById(storeId)) + .build(); + + reviewRepository.save(review); + } +} diff --git a/src/main/java/com/example/umc9th/domain/store/entity/Store.java b/src/main/java/com/example/umc9th/domain/store/entity/Store.java new file mode 100644 index 0000000..3606ffb --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/store/entity/Store.java @@ -0,0 +1,44 @@ +package com.example.umc9th.domain.store.entity; + + +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.util.Set; + +@Table(name = "store") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class Store extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "store_id") + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private String address; + + @Column(nullable = false) + @Builder.Default + private Boolean isOpened = false; + + @Column(nullable = false) + @Builder.Default + private Boolean isDeleted = false; + + @OneToMany(mappedBy = "store", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private Set storeReviews; + + +} diff --git a/src/main/java/com/example/umc9th/domain/store/repository/StoreRepository.java b/src/main/java/com/example/umc9th/domain/store/repository/StoreRepository.java new file mode 100644 index 0000000..e3be7c8 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/store/repository/StoreRepository.java @@ -0,0 +1,7 @@ +package com.example.umc9th.domain.store.repository; + +import com.example.umc9th.domain.store.entity.Store; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface StoreRepository extends JpaRepository { +} diff --git a/src/main/java/com/example/umc9th/domain/user/controller/UserController.java b/src/main/java/com/example/umc9th/domain/user/controller/UserController.java new file mode 100644 index 0000000..e149d8b --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/controller/UserController.java @@ -0,0 +1,20 @@ +package com.example.umc9th.domain.user.controller; + +import com.example.umc9th.domain.user.service.UserService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/users") +public class UserController { + + private final UserService userService; + + @DeleteMapping("/{userId}") + public ResponseEntity deleteUser(@PathVariable("userId") Long userId) { + userService.deleteUser(userId); + return ResponseEntity.noContent().build(); + } +} diff --git a/src/main/java/com/example/umc9th/domain/user/dto/MyPageDTO.java b/src/main/java/com/example/umc9th/domain/user/dto/MyPageDTO.java new file mode 100644 index 0000000..2cbcaeb --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/dto/MyPageDTO.java @@ -0,0 +1,13 @@ +package com.example.umc9th.domain.user.dto; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class MyPageDTO { + private final Long id; + private final String email; + private final Integer point; + private final String phone; +} diff --git a/src/main/java/com/example/umc9th/domain/user/dto/UserHomeInfoDTO.java b/src/main/java/com/example/umc9th/domain/user/dto/UserHomeInfoDTO.java new file mode 100644 index 0000000..e5a5b63 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/dto/UserHomeInfoDTO.java @@ -0,0 +1,11 @@ +package com.example.umc9th.domain.user.dto; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class UserHomeInfoDTO { + private final Integer point; + private final Long completedMissionCount; +} diff --git a/src/main/java/com/example/umc9th/domain/user/entity/NotificationAgreement.java b/src/main/java/com/example/umc9th/domain/user/entity/NotificationAgreement.java new file mode 100644 index 0000000..abde20c --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/entity/NotificationAgreement.java @@ -0,0 +1,35 @@ +package com.example.umc9th.domain.user.entity; + +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Table(name = "notifiaction_agreement") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class NotificationAgreement extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_category_id") + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @Column(nullable = false) + private Boolean reviewReplyAgree; + + @Column(nullable = false) + private Boolean inquiryReplyAgree; + + @Column(nullable = false) + private Boolean eventAgree; + +} diff --git a/src/main/java/com/example/umc9th/domain/user/entity/PhoneVerification.java b/src/main/java/com/example/umc9th/domain/user/entity/PhoneVerification.java new file mode 100644 index 0000000..5d38b2b --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/entity/PhoneVerification.java @@ -0,0 +1,27 @@ +package com.example.umc9th.domain.user.entity; + +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Table(name = "phone_verifiaction") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) + +public class PhoneVerification extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @Column(nullable = false) + private String phone; +} diff --git a/src/main/java/com/example/umc9th/domain/user/entity/TermAgreement.java b/src/main/java/com/example/umc9th/domain/user/entity/TermAgreement.java new file mode 100644 index 0000000..bb925dd --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/entity/TermAgreement.java @@ -0,0 +1,34 @@ +package com.example.umc9th.domain.user.entity; + +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.swing.text.StyledEditorKit; + +@Table(name = "term_agreement") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@Getter +@EntityListeners(AuditingEntityListener.class) +public class TermAgreement extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_category_id") + private Long id; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @Column(nullable = false) + Boolean locationAgree; + + @Column(nullable = false) + Boolean marketingNoticeAgree; + +} diff --git a/src/main/java/com/example/umc9th/domain/user/entity/User.java b/src/main/java/com/example/umc9th/domain/user/entity/User.java new file mode 100644 index 0000000..8543d29 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/entity/User.java @@ -0,0 +1,92 @@ +package com.example.umc9th.domain.user.entity; + +import com.example.umc9th.domain.inqury.entity.Inquiry; +import com.example.umc9th.domain.mission.entity.UserMission; +import com.example.umc9th.domain.review.entity.Review; +import com.example.umc9th.domain.user.enums.Gender; +import com.example.umc9th.domain.user.enums.SocialType; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.util.Set; + +@Table(name = "user") +@Entity +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +/* +[PROTECTED] +ORM ๊ธฐ์ˆ ์€ ๊ฐ์ฒด๋ฅผ ๋จผ์ € ์ƒ์„ฑ ํ›„ ํ•„๋“œ ๊ฐ’์„ ์ฑ„์›Œ ๋„ฃ์Œ +-> ์ด๋•Œ, ๊ธฐ๋ณธ ์ƒ์„ฑ์ž๊ฐ€ ๋ฐ˜๋“œ์‹œ ํ•„์š” +-> ๋งŒ์•ฝ public์ด๋ผ๋ฉด ์™ธ๋ถ€์—์„œ ์˜๋„์น˜์•Š์€ ๊ฐ’์ด ์ฃผ์ž…๋  ์ˆ˜ ์žˆ์Œ +-> ๋งŒ์•ฝ private์ด๋ผ๋ฉด JPA์กฐ์ฐจ ์ ‘๊ทผํ•˜๊ธฐ ์–ด๋ ค์›€ +=> ํŒจํ‚ค์ง€ ๋‹จ์œ„ or ์ƒ์† ๋ฐ›์€ ์ž์‹ ํด๋ž˜์Šค์—๊ฒŒ๋งŒ ์ ‘๊ทผ ํ—ˆ์šฉ(protected) + +[PRIVATE] +๊ฐ์ฒด ์ƒ์„ฑ ๋‚ด๋ถ€ ๋กœ์ง์„ ์ˆจ๊น€ +-> ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ or ๋นŒ๋” ํŒจํ„ด +(๊ฐ์ฒด ์ƒ์„ฑ์˜ ์ฑ…์ž„(์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋“ฑ)์„ ์œ„์ž„) +*/ +@Getter +@EntityListeners(AuditingEntityListener.class) +public class User extends BaseEntity { + + @Id + @Column(name = "user_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String email; + + @Enumerated(EnumType.STRING) + private Gender gender; + + @Column(nullable = false) + private String address; + + @Column(nullable = false) + private Integer point; + + @Column(nullable = false) + private String nickname; + + @Column(nullable = false) + private SocialType socialType; + + @Column(nullable = false) + private Boolean isPhoneVerified; + + @Column(nullable = false) + @Builder.Default + private Boolean isDeleted = false; + + /* + List<> : ์ค‘๋ณต ์š”์†Œ ํ—ˆ์šฉ o, ์ˆœ์„œ ๋ณด์žฅ o + Set<> : ์ค‘๋ณต ์š”์†Œ ํ—ˆ์šฉ x, ์ˆœ์„œ ๋ณด์žฅ x, + ๊ฐ์ฒด equals(), hashCode() ์˜ค๋ฒ„๋ผ์ด๋”ฉ ํ•„์ˆ˜ + */ + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private Set userMissions; + + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private Set inquiries; + + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private Set userReviews; + + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) + private Set userCategories; + + @OneToOne(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) + private PhoneVerification userPhoneVerification; + + @OneToOne(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) + private NotificationAgreement userNotificationAgreement; + + @OneToOne(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) + private TermAgreement userTermAgreement; + +} diff --git a/src/main/java/com/example/umc9th/domain/user/entity/UserCategory.java b/src/main/java/com/example/umc9th/domain/user/entity/UserCategory.java new file mode 100644 index 0000000..523a803 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/entity/UserCategory.java @@ -0,0 +1,40 @@ +package com.example.umc9th.domain.user.entity; + +import com.example.umc9th.domain.category.entity.Category; +import com.example.umc9th.global.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Table(name = "user_category", uniqueConstraints = { + @UniqueConstraint( + name = "user_category_unique", + columnNames = {"user_id", "category_id"} + ) +}) +/* +JPA์—์„œ ๋ณตํ•ฉํ‚ค ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ ๋ณ„๋„์˜ ํด๋ž˜์Šค ํ•„์š” +-> ๋‹จ์ผ ํ‚ค(๋Œ€๋ฆฌํ‚ค?)๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์œ ๋‹ˆํฌ ์ œ์•ฝ ์กฐ๊ฑด ์ถ”๊ฐ€ + */ +@Entity +@Builder +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@EntityListeners(AuditingEntityListener.class) +public class UserCategory extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_category_id") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private Category category; + +} diff --git a/src/main/java/com/example/umc9th/domain/user/enums/FoodCategory.java b/src/main/java/com/example/umc9th/domain/user/enums/FoodCategory.java new file mode 100644 index 0000000..8c527e9 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/enums/FoodCategory.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.user.enums; + +public enum FoodCategory { + KOREAN, JAPANESE, CHINESE +} diff --git a/src/main/java/com/example/umc9th/domain/user/enums/Gender.java b/src/main/java/com/example/umc9th/domain/user/enums/Gender.java new file mode 100644 index 0000000..9c637bd --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/enums/Gender.java @@ -0,0 +1,6 @@ +package com.example.umc9th.domain.user.enums; + +public enum Gender { + MALE, + FEMALE +} \ No newline at end of file diff --git a/src/main/java/com/example/umc9th/domain/user/enums/SocialType.java b/src/main/java/com/example/umc9th/domain/user/enums/SocialType.java new file mode 100644 index 0000000..e4477a2 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/enums/SocialType.java @@ -0,0 +1,7 @@ +package com.example.umc9th.domain.user.enums; + +public enum SocialType { + KAKAO, + NAVER, + GOOGLE +} \ No newline at end of file diff --git a/src/main/java/com/example/umc9th/domain/user/repository/NotificationAgreementRepository.java b/src/main/java/com/example/umc9th/domain/user/repository/NotificationAgreementRepository.java new file mode 100644 index 0000000..2d1ecc5 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/repository/NotificationAgreementRepository.java @@ -0,0 +1,13 @@ +package com.example.umc9th.domain.user.repository; + +import com.example.umc9th.domain.user.entity.NotificationAgreement; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface NotificationAgreementRepository extends JpaRepository { + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("DELETE FROM NotificationAgreement na WHERE na.user.id = :userId") + void deleteByUserId(@Param("userId") Long userId); +} diff --git a/src/main/java/com/example/umc9th/domain/user/repository/PhoneVerificationRepository.java b/src/main/java/com/example/umc9th/domain/user/repository/PhoneVerificationRepository.java new file mode 100644 index 0000000..c657a06 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/repository/PhoneVerificationRepository.java @@ -0,0 +1,13 @@ +package com.example.umc9th.domain.user.repository; + +import com.example.umc9th.domain.user.entity.PhoneVerification; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface PhoneVerificationRepository extends JpaRepository { + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("DELETE FROM PhoneVerification pv WHERE pv.user.id = :userId") + void deleteByUserId(@Param("userId") Long userId); +} diff --git a/src/main/java/com/example/umc9th/domain/user/repository/TermAgreementRepository.java b/src/main/java/com/example/umc9th/domain/user/repository/TermAgreementRepository.java new file mode 100644 index 0000000..8630696 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/repository/TermAgreementRepository.java @@ -0,0 +1,13 @@ +package com.example.umc9th.domain.user.repository; + +import com.example.umc9th.domain.user.entity.TermAgreement; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface TermAgreementRepository extends JpaRepository { + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("DELETE FROM TermAgreement ta WHERE ta.user.id = :userId") + void deleteByUserId(@Param("userId") Long userId); +} diff --git a/src/main/java/com/example/umc9th/domain/user/repository/UserCategoryRepository.java b/src/main/java/com/example/umc9th/domain/user/repository/UserCategoryRepository.java new file mode 100644 index 0000000..18077da --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/repository/UserCategoryRepository.java @@ -0,0 +1,13 @@ +package com.example.umc9th.domain.user.repository; + +import com.example.umc9th.domain.user.entity.UserCategory; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface UserCategoryRepository extends JpaRepository { + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("DELETE FROM UserCategory uc WHERE uc.user.id = :userId") + void deleteByUserId(@Param("userId") Long userId); +} diff --git a/src/main/java/com/example/umc9th/domain/user/repository/UserRepository.java b/src/main/java/com/example/umc9th/domain/user/repository/UserRepository.java new file mode 100644 index 0000000..a506cd4 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/repository/UserRepository.java @@ -0,0 +1,31 @@ +package com.example.umc9th.domain.user.repository; + +import com.example.umc9th.domain.user.dto.MyPageDTO; +import com.example.umc9th.domain.user.dto.UserHomeInfoDTO; +import com.example.umc9th.domain.user.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface UserRepository extends JpaRepository { + /* + @Modifying : ์˜์†์„ฑ ์ปจํ…์ŠคํŠธ์™€ ์ƒ๊ด€์—†์ด DB์— ์ง์ ‘ ์‹คํ–‰ -> ๋ฐ์ดํ„ฐ ๋ถˆ์ผ์น˜ ๊ฐ€๋Šฅ์„ฑ(์˜ต์…˜ ์„ค์ •) + + clearAutomatically : clear() + flushAutomatically : flush() + => ๋‘˜ ๋‹ค default๋Š” false + */ + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("UPDATE User u SET u.isDeleted = true WHERE u.id = :userId") + void softDeleteUser(@Param("userId") Long userId); + + @Query("SELECT new com.example.umc9th.domain.user.dto.MyPageDTO(u.id, u.email, u.point, CASE WHEN u.isPhoneVerified = true THEN pv.phone ELSE '๋ฏธ์ธ์ฆ' END) " + + "FROM User u LEFT JOIN u.userPhoneVerification pv " + + "WHERE u.id = :userId") + MyPageDTO getMyPageInfo(@Param("userId") Long userId); + + @Query("SELECT new com.example.umc9th.domain.user.dto.UserHomeInfoDTO(u.point, (SELECT COUNT(um) FROM UserMission um WHERE um.user = u AND um.isCompleted = true)) " + + "FROM User u WHERE u.id = :userId") + UserHomeInfoDTO getHomeInfo(@Param("userId") Long userId); +} diff --git a/src/main/java/com/example/umc9th/domain/user/service/UserService.java b/src/main/java/com/example/umc9th/domain/user/service/UserService.java new file mode 100644 index 0000000..53b1850 --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/service/UserService.java @@ -0,0 +1,5 @@ +package com.example.umc9th.domain.user.service; + +public interface UserService { + void deleteUser(Long userId); +} diff --git a/src/main/java/com/example/umc9th/domain/user/service/UserServiceImpl.java b/src/main/java/com/example/umc9th/domain/user/service/UserServiceImpl.java new file mode 100644 index 0000000..f9451bb --- /dev/null +++ b/src/main/java/com/example/umc9th/domain/user/service/UserServiceImpl.java @@ -0,0 +1,36 @@ +package com.example.umc9th.domain.user.service; + +import com.example.umc9th.domain.inqury.repository.InquiryRepository; +import com.example.umc9th.domain.mission.repository.UserMissionRepository; +import com.example.umc9th.domain.review.repository.ReviewRepository; +import com.example.umc9th.domain.user.repository.*; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class UserServiceImpl implements UserService { + + private final UserRepository userRepository; + private final UserMissionRepository userMissionRepository; + private final InquiryRepository inquiryRepository; + private final ReviewRepository reviewRepository; + private final UserCategoryRepository userCategoryRepository; + private final PhoneVerificationRepository phoneVerificationRepository; + private final NotificationAgreementRepository notificationAgreementRepository; + private final TermAgreementRepository termAgreementRepository; + + @Override + @Transactional + public void deleteUser(Long userId) { + userMissionRepository.deleteByUserId(userId); + inquiryRepository.deleteByUserId(userId); + reviewRepository.deleteByUserId(userId); + userCategoryRepository.deleteByUserId(userId); + phoneVerificationRepository.deleteByUserId(userId); + notificationAgreementRepository.deleteByUserId(userId); + termAgreementRepository.deleteByUserId(userId); + userRepository.softDeleteUser(userId); + } +} 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..a99a689 --- /dev/null +++ b/src/main/java/com/example/umc9th/global/entity/BaseEntity.java @@ -0,0 +1,32 @@ +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 +/* +@MappedSuperclass๊ฐ€ ์„ ์–ธ๋˜์–ด ์žˆ๋Š” ํด๋ž˜์Šค๋Š” ์—”ํ‹ฐํ‹ฐ X +<-> ์ž์‹ ํด๋ž˜์Šค์—๊ฒŒ ๋งคํ•‘ ์ •๋ณด๋งŒ ์ œ๊ณตํ•จ ++ ์กฐํšŒ, ๊ฒ€์ƒ‰ ๋ถˆ๊ฐ€๋Šฅ +(JPA์—์„œ @Entity ํด๋ž˜์Šค๋Š” @Entity, @MappedSuperclass๋กœ ์ง€์ •๋œ ํด๋ž˜์Šค๋งŒ ์ƒ์† ๊ฐ€๋Šฅ) + */ +@EntityListeners(AuditingEntityListener.class) +@Getter +public abstract class BaseEntity { + + @CreatedDate + @Column(name = "created_at", nullable = false, updatable = false) + private LocalDateTime createdAt; + + @LastModifiedDate + @Column(name = "updated_at", nullable = false) + private LocalDateTime updatedAt; +} 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() { + } + +}