diff --git a/bean/umc10th/.gitattributes b/bean/umc10th/.gitattributes new file mode 100644 index 0000000..8af972c --- /dev/null +++ b/bean/umc10th/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/bean/umc10th/.gitignore b/bean/umc10th/.gitignore new file mode 100644 index 0000000..5cbf6be --- /dev/null +++ b/bean/umc10th/.gitignore @@ -0,0 +1,41 @@ +HELP.md +.gradle +.gradle-user-home*/ +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/ + +# local secrets +.env diff --git a/bean/umc10th/build.gradle b/bean/umc10th/build.gradle new file mode 100644 index 0000000..43915b1 --- /dev/null +++ b/bean/umc10th/build.gradle @@ -0,0 +1,32 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '4.0.5' + id 'io.spring.dependency-management' version '1.1.7' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +description = 'umc10th' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-validation' + 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' + + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.1' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-api:3.0.1' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/bean/umc10th/gradle/wrapper/gradle-wrapper.jar b/bean/umc10th/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d997cfc Binary files /dev/null and b/bean/umc10th/gradle/wrapper/gradle-wrapper.jar differ diff --git a/bean/umc10th/gradle/wrapper/gradle-wrapper.properties b/bean/umc10th/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..c61a118 --- /dev/null +++ b/bean/umc10th/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/bean/umc10th/gradlew b/bean/umc10th/gradlew new file mode 100644 index 0000000..739907d --- /dev/null +++ b/bean/umc10th/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/2d6327017519d23b96af35865dc997fcb544fb40/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/bean/umc10th/gradlew.bat b/bean/umc10th/gradlew.bat new file mode 100644 index 0000000..c4bdd3a --- /dev/null +++ b/bean/umc10th/gradlew.bat @@ -0,0 +1,93 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/bean/umc10th/settings.gradle b/bean/umc10th/settings.gradle new file mode 100644 index 0000000..67a1b8e --- /dev/null +++ b/bean/umc10th/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'umc10th' diff --git a/bean/umc10th/src/main/java/com/example/umc10th/Umc10thApplication.java b/bean/umc10th/src/main/java/com/example/umc10th/Umc10thApplication.java new file mode 100644 index 0000000..9983f43 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/Umc10thApplication.java @@ -0,0 +1,13 @@ +package com.example.umc10th; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Umc10thApplication { + + public static void main(String[] args) { + SpringApplication.run(Umc10thApplication.class, args); + } + +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/controller/MemberController.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/controller/MemberController.java new file mode 100644 index 0000000..13c0241 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/controller/MemberController.java @@ -0,0 +1,38 @@ +package com.example.umc10th.domain.member.controller; + +import com.example.umc10th.domain.member.dto.MemberReqDto; +import com.example.umc10th.domain.member.dto.MemberResDto; +import com.example.umc10th.domain.member.exception.MemberException; +import com.example.umc10th.domain.member.exception.code.MemberErrorCode; +import com.example.umc10th.domain.member.exception.code.MemberSuccessCode; +import com.example.umc10th.global.apiPayload.ApiResponse; +import jakarta.validation.Valid; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1/users") +public class MemberController { + + @PostMapping("/me") + public ResponseEntity> getMyPage( + @Valid @RequestBody MemberReqDto.GetMyPageRequest request + ) { + if (request.id() <= 0) { + throw new MemberException(MemberErrorCode.MEMBER_NOT_FOUND); + } + + MemberResDto.GetMyPageResponse result = new MemberResDto.GetMyPageResponse( + "bean", + "https://example.com/profile/bean.png", + "bean@umc.com", + null, + 2500 + ); + + return ResponseEntity.ok(ApiResponse.of(MemberSuccessCode.GET_MY_PAGE_SUCCESS, result)); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/converter/MemberConverter.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/converter/MemberConverter.java new file mode 100644 index 0000000..479a2d4 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/converter/MemberConverter.java @@ -0,0 +1,32 @@ +package com.example.umc10th.domain.member.converter; + +import com.example.umc10th.domain.member.dto.MemberReqDto; +import com.example.umc10th.domain.member.dto.MemberResDto; +import com.example.umc10th.domain.member.entity.Member; + +public final class MemberConverter { + + private MemberConverter() { + } + + public static Member toEntity(MemberReqDto.Create request) { + return Member.builder() + .name(request.name()) + .gender(request.gender()) + .birthDate(request.birthDate()) + .address(request.address()) + .nickname(request.nickname()) + .build(); + } + + public static MemberResDto.MemberInfo toMemberInfo(Member member) { + return new MemberResDto.MemberInfo( + member.getId(), + member.getName(), + member.getGender(), + member.getBirthDate(), + member.getAddress(), + member.getNickname() + ); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/dto/MemberReqDto.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/dto/MemberReqDto.java new file mode 100644 index 0000000..adfafa5 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/dto/MemberReqDto.java @@ -0,0 +1,25 @@ +package com.example.umc10th.domain.member.dto; + +import com.example.umc10th.domain.member.enums.Gender; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Positive; +import jakarta.validation.constraints.Size; +import java.time.LocalDate; + +public class MemberReqDto { + + public record Create( + @NotBlank @Size(max = 20) String name, + @NotNull Gender gender, + @NotNull LocalDate birthDate, + @NotBlank @Size(max = 255) String address, + @NotBlank @Size(max = 20) String nickname + ) { + } + + public record GetMyPageRequest( + @NotNull @Positive Long id + ) { + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/dto/MemberResDto.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/dto/MemberResDto.java new file mode 100644 index 0000000..8ba3e08 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/dto/MemberResDto.java @@ -0,0 +1,26 @@ +package com.example.umc10th.domain.member.dto; + +import com.example.umc10th.domain.member.enums.Gender; +import java.time.LocalDate; + +public class MemberResDto { + + public record MemberInfo( + Long memberId, + String name, + Gender gender, + LocalDate birthDate, + String address, + String nickname + ) { + } + + public record GetMyPageResponse( + String name, + String profileUrl, + String email, + String phoneNumber, + Integer point + ) { + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/entity/Member.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/entity/Member.java new file mode 100644 index 0000000..92e388f --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/entity/Member.java @@ -0,0 +1,88 @@ +package com.example.umc10th.domain.member.entity; + +import com.example.umc10th.domain.member.enums.Gender; +import com.example.umc10th.domain.mission.entity.MemberMission; +import com.example.umc10th.domain.review.entity.Review; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.PrePersist; +import jakarta.persistence.PreUpdate; +import jakarta.persistence.Table; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "member") +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Member { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_id") + private Long id; + + @Column(name = "name", nullable = false, length = 20) + private String name; + + @Enumerated(EnumType.STRING) + @Column(name = "gender", nullable = false, length = 20) + private Gender gender; + + @Column(name = "birth_date", nullable = false) + private LocalDate birthDate; + + @Column(name = "address", nullable = false, length = 255) + private String address; + + @Column(name = "nickname", nullable = false, length = 20) + private String nickname; + + @Column(name = "created_at", nullable = false) + private LocalDateTime createdAt; + + @Column(name = "updated_at") + private LocalDateTime updatedAt; + + @Column(name = "deleted_at") + private LocalDateTime deletedAt; + + @Builder.Default + @OneToMany(mappedBy = "member") + private List memberPrefers = new ArrayList<>(); + + @Builder.Default + @OneToMany(mappedBy = "member") + private List memberMissions = new ArrayList<>(); + + @Builder.Default + @OneToMany(mappedBy = "member") + private List reviews = new ArrayList<>(); + + @PrePersist + protected void onCreate() { + LocalDateTime now = LocalDateTime.now(); + this.createdAt = now; + this.updatedAt = now; + } + + @PreUpdate + protected void onUpdate() { + this.updatedAt = LocalDateTime.now(); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/entity/MemberPrefer.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/entity/MemberPrefer.java new file mode 100644 index 0000000..a6c4a6e --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/entity/MemberPrefer.java @@ -0,0 +1,38 @@ +package com.example.umc10th.domain.member.entity; + +import com.example.umc10th.domain.store.entity.FoodCategory; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "member_prefer") +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class MemberPrefer { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_prefer_id") + private Long id; + + @ManyToOne(optional = false) + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @ManyToOne(optional = false) + @JoinColumn(name = "catetory_id", nullable = false) + private FoodCategory category; +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/enums/Gender.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/enums/Gender.java new file mode 100644 index 0000000..2323d2c --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/enums/Gender.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.member.enums; + +public enum Gender { + MALE, + FEMALE, + NONE +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/exception/MemberException.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/exception/MemberException.java new file mode 100644 index 0000000..5e0d1f9 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/exception/MemberException.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.member.exception; + +import com.example.umc10th.domain.member.exception.code.MemberErrorCode; +import com.example.umc10th.global.apiPayload.exception.GeneralException; + +public class MemberException extends GeneralException { + public MemberException(MemberErrorCode errorCode) { + super(errorCode); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/exception/code/MemberErrorCode.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/exception/code/MemberErrorCode.java new file mode 100644 index 0000000..371c66d --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/exception/code/MemberErrorCode.java @@ -0,0 +1,27 @@ +package com.example.umc10th.domain.member.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum MemberErrorCode implements BaseErrorCode { + MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "MEMBER404", "사용자를 찾을 수 없습니다."); + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + @Override + public ReasonDto getReason() { + return new ReasonDto(httpStatus, false, code, message); + } + + @Override + public ReasonDto getReasonHttpStatus() { + return getReason(); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/exception/code/MemberSuccessCode.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/exception/code/MemberSuccessCode.java new file mode 100644 index 0000000..cba0595 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/exception/code/MemberSuccessCode.java @@ -0,0 +1,27 @@ +package com.example.umc10th.domain.member.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseSuccessCode; +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum MemberSuccessCode implements BaseSuccessCode { + GET_MY_PAGE_SUCCESS(HttpStatus.OK, "MEMBER2001", "성공적으로 사용자 정보를 조회했습니다."); + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + @Override + public ReasonDto getReason() { + return new ReasonDto(httpStatus, true, code, message); + } + + @Override + public ReasonDto getReasonHttpStatus() { + return getReason(); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/repository/MemberPreferRepository.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/repository/MemberPreferRepository.java new file mode 100644 index 0000000..e9c5e2a --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/repository/MemberPreferRepository.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.member.repository; + +import com.example.umc10th.domain.member.entity.MemberPrefer; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberPreferRepository extends JpaRepository { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/repository/MemberRepository.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/repository/MemberRepository.java new file mode 100644 index 0000000..e878bbb --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/repository/MemberRepository.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.member.repository; + +import com.example.umc10th.domain.member.entity.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberRepository extends JpaRepository { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/service/MemberService.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/service/MemberService.java new file mode 100644 index 0000000..86dbcad --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/service/MemberService.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.member.service; + +import com.example.umc10th.domain.member.dto.MemberReqDto; +import com.example.umc10th.domain.member.dto.MemberResDto; + +public interface MemberService { + MemberResDto.MemberInfo getMember(Long memberId); + + MemberResDto.MemberInfo createMember(MemberReqDto.Create request); +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/member/service/MemberServiceImpl.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/service/MemberServiceImpl.java new file mode 100644 index 0000000..76794fe --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/member/service/MemberServiceImpl.java @@ -0,0 +1,35 @@ +package com.example.umc10th.domain.member.service; + +import com.example.umc10th.domain.member.converter.MemberConverter; +import com.example.umc10th.domain.member.dto.MemberReqDto; +import com.example.umc10th.domain.member.dto.MemberResDto; +import com.example.umc10th.domain.member.entity.Member; +import com.example.umc10th.domain.member.exception.MemberException; +import com.example.umc10th.domain.member.exception.code.MemberErrorCode; +import com.example.umc10th.domain.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class MemberServiceImpl implements MemberService { + + private final MemberRepository memberRepository; + + @Override + public MemberResDto.MemberInfo getMember(Long memberId) { + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberException(MemberErrorCode.MEMBER_NOT_FOUND)); + + return MemberConverter.toMemberInfo(member); + } + + @Override + @Transactional + public MemberResDto.MemberInfo createMember(MemberReqDto.Create request) { + Member savedMember = memberRepository.save(MemberConverter.toEntity(request)); + return MemberConverter.toMemberInfo(savedMember); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/controller/MissionController.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/controller/MissionController.java new file mode 100644 index 0000000..79c6c87 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/controller/MissionController.java @@ -0,0 +1,33 @@ +package com.example.umc10th.domain.mission.controller; + +import com.example.umc10th.domain.mission.dto.MissionReqDto; +import com.example.umc10th.domain.mission.dto.MissionResDto; +import com.example.umc10th.domain.mission.service.MissionService; +import com.example.umc10th.global.apiPayload.ApiResponse; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/missions") +@RequiredArgsConstructor +public class MissionController { + + private final MissionService missionService; + + @GetMapping("/{missionId}") + public ResponseEntity> getMission(@PathVariable Long missionId) { + return ResponseEntity.ok(ApiResponse.onSuccess(missionService.getMission(missionId))); + } + + @PostMapping + public ResponseEntity> createMission(@Valid @RequestBody MissionReqDto.Create request) { + return ResponseEntity.ok(ApiResponse.onSuccess(missionService.createMission(request))); + } +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/converter/MissionConverter.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/converter/MissionConverter.java new file mode 100644 index 0000000..c3c7f68 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/converter/MissionConverter.java @@ -0,0 +1,29 @@ +package com.example.umc10th.domain.mission.converter; + +import com.example.umc10th.domain.mission.dto.MissionReqDto; +import com.example.umc10th.domain.mission.dto.MissionResDto; +import com.example.umc10th.domain.mission.entity.Mission; +import com.example.umc10th.domain.store.entity.Store; + +public final class MissionConverter { + + private MissionConverter() { + } + + public static Mission toEntity(MissionReqDto.Create request, Store store) { + return Mission.builder() + .store(store) + .content(request.content()) + .rewardPoint(request.rewardPoint()) + .build(); + } + + public static MissionResDto.MissionInfo toMissionInfo(Mission mission) { + return new MissionResDto.MissionInfo( + mission.getId(), + mission.getStore().getId(), + mission.getContent(), + mission.getRewardPoint() + ); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/dto/MissionReqDto.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/dto/MissionReqDto.java new file mode 100644 index 0000000..5c39322 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/dto/MissionReqDto.java @@ -0,0 +1,15 @@ +package com.example.umc10th.domain.mission.dto; + +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; + +public class MissionReqDto { + + public record Create( + @NotNull Long storeId, + @NotBlank String content, + @Min(0) int rewardPoint + ) { + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/dto/MissionResDto.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/dto/MissionResDto.java new file mode 100644 index 0000000..fc37061 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/dto/MissionResDto.java @@ -0,0 +1,12 @@ +package com.example.umc10th.domain.mission.dto; + +public class MissionResDto { + + public record MissionInfo( + Long missionId, + Long storeId, + String content, + int rewardPoint + ) { + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/entity/MemberMission.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/entity/MemberMission.java new file mode 100644 index 0000000..ffea05b --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/entity/MemberMission.java @@ -0,0 +1,46 @@ +package com.example.umc10th.domain.mission.entity; + +import com.example.umc10th.domain.member.entity.Member; +import com.example.umc10th.domain.mission.enums.MemberMissionStatus; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "member_mission") +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class MemberMission { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_mission_id") + private Long id; + + @ManyToOne(optional = false) + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @ManyToOne(optional = false) + @JoinColumn(name = "mission_id", nullable = false) + private Mission mission; + + @Enumerated(EnumType.STRING) + @Column(name = "status", nullable = false, length = 20) + @Builder.Default + private MemberMissionStatus status = MemberMissionStatus.CHALLENGING; +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/entity/Mission.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/entity/Mission.java new file mode 100644 index 0000000..a4e7dd4 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/entity/Mission.java @@ -0,0 +1,47 @@ +package com.example.umc10th.domain.mission.entity; + +import com.example.umc10th.domain.store.entity.Store; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.util.ArrayList; +import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "mission") +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Mission { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "mission_id") + private Long id; + + @ManyToOne(optional = false) + @JoinColumn(name = "store_id", nullable = false) + private Store store; + + @Column(name = "content", nullable = false, length = 255) + private String content; + + @Column(name = "reward_point", nullable = false) + private Integer rewardPoint; + + @Builder.Default + @OneToMany(mappedBy = "mission") + private List memberMissions = new ArrayList<>(); +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/enums/MemberMissionStatus.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/enums/MemberMissionStatus.java new file mode 100644 index 0000000..b00303a --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/enums/MemberMissionStatus.java @@ -0,0 +1,6 @@ +package com.example.umc10th.domain.mission.enums; + +public enum MemberMissionStatus { + CHALLENGING, + COMPLETE +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/exception/MissionException.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/exception/MissionException.java new file mode 100644 index 0000000..41fdeaa --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/exception/MissionException.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.mission.exception; + +import com.example.umc10th.domain.mission.exception.code.MissionErrorCode; +import com.example.umc10th.global.apiPayload.exception.GeneralException; + +public class MissionException extends GeneralException { + public MissionException(MissionErrorCode errorCode) { + super(errorCode); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/exception/code/MissionErrorCode.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/exception/code/MissionErrorCode.java new file mode 100644 index 0000000..120f51f --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/exception/code/MissionErrorCode.java @@ -0,0 +1,28 @@ +package com.example.umc10th.domain.mission.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum MissionErrorCode implements BaseErrorCode { + MISSION_NOT_FOUND(HttpStatus.NOT_FOUND, "MISSION404", "미션을 찾을 수 없습니다."), + STORE_NOT_FOUND(HttpStatus.NOT_FOUND, "STORE404", "가게를 찾을 수 없습니다."); + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + @Override + public ReasonDto getReason() { + return new ReasonDto(httpStatus, false, code, message); + } + + @Override + public ReasonDto getReasonHttpStatus() { + return getReason(); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/repository/MemberMissionRepository.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/repository/MemberMissionRepository.java new file mode 100644 index 0000000..d9d5164 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/repository/MemberMissionRepository.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.mission.repository; + +import com.example.umc10th.domain.mission.entity.MemberMission; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberMissionRepository extends JpaRepository { +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/repository/MissionRepository.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/repository/MissionRepository.java new file mode 100644 index 0000000..71f7528 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/repository/MissionRepository.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.mission.repository; + +import com.example.umc10th.domain.mission.entity.Mission; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MissionRepository extends JpaRepository { +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/service/MissionService.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/service/MissionService.java new file mode 100644 index 0000000..594e659 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/service/MissionService.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.mission.service; + +import com.example.umc10th.domain.mission.dto.MissionReqDto; +import com.example.umc10th.domain.mission.dto.MissionResDto; + +public interface MissionService { + MissionResDto.MissionInfo getMission(Long missionId); + + MissionResDto.MissionInfo createMission(MissionReqDto.Create request); +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/service/MissionServiceImpl.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/service/MissionServiceImpl.java new file mode 100644 index 0000000..42873ba --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/mission/service/MissionServiceImpl.java @@ -0,0 +1,41 @@ +package com.example.umc10th.domain.mission.service; + +import com.example.umc10th.domain.mission.converter.MissionConverter; +import com.example.umc10th.domain.mission.dto.MissionReqDto; +import com.example.umc10th.domain.mission.dto.MissionResDto; +import com.example.umc10th.domain.mission.entity.Mission; +import com.example.umc10th.domain.store.entity.Store; +import com.example.umc10th.domain.mission.exception.MissionException; +import com.example.umc10th.domain.mission.exception.code.MissionErrorCode; +import com.example.umc10th.domain.mission.repository.MissionRepository; +import com.example.umc10th.domain.store.repository.StoreRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class MissionServiceImpl implements MissionService { + + private final MissionRepository missionRepository; + private final StoreRepository storeRepository; + + @Override + public MissionResDto.MissionInfo getMission(Long missionId) { + Mission mission = missionRepository.findById(missionId) + .orElseThrow(() -> new MissionException(MissionErrorCode.MISSION_NOT_FOUND)); + + return MissionConverter.toMissionInfo(mission); + } + + @Override + @Transactional + public MissionResDto.MissionInfo createMission(MissionReqDto.Create request) { + Store store = storeRepository.findById(request.storeId()) + .orElseThrow(() -> new MissionException(MissionErrorCode.STORE_NOT_FOUND)); + + Mission savedMission = missionRepository.save(MissionConverter.toEntity(request, store)); + return MissionConverter.toMissionInfo(savedMission); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/controller/ReviewController.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/controller/ReviewController.java new file mode 100644 index 0000000..57cfa3e --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/controller/ReviewController.java @@ -0,0 +1,33 @@ +package com.example.umc10th.domain.review.controller; + +import com.example.umc10th.domain.review.dto.ReviewReqDto; +import com.example.umc10th.domain.review.dto.ReviewResDto; +import com.example.umc10th.domain.review.service.ReviewService; +import com.example.umc10th.global.apiPayload.ApiResponse; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +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.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/reviews") +@RequiredArgsConstructor +public class ReviewController { + + private final ReviewService reviewService; + + @GetMapping("/{reviewId}") + public ResponseEntity> getReview(@PathVariable Long reviewId) { + return ResponseEntity.ok(ApiResponse.onSuccess(reviewService.getReview(reviewId))); + } + + @PostMapping + public ResponseEntity> createReview(@Valid @RequestBody ReviewReqDto.Create request) { + return ResponseEntity.ok(ApiResponse.onSuccess(reviewService.createReview(request))); + } +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/converter/ReviewConverter.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/converter/ReviewConverter.java new file mode 100644 index 0000000..99f6080 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/converter/ReviewConverter.java @@ -0,0 +1,32 @@ +package com.example.umc10th.domain.review.converter; + +import com.example.umc10th.domain.member.entity.Member; +import com.example.umc10th.domain.store.entity.Store; +import com.example.umc10th.domain.review.dto.ReviewReqDto; +import com.example.umc10th.domain.review.dto.ReviewResDto; +import com.example.umc10th.domain.review.entity.Review; + +public final class ReviewConverter { + + private ReviewConverter() { + } + + public static Review toEntity(ReviewReqDto.Create request, Member member, Store store) { + return Review.builder() + .member(member) + .store(store) + .content(request.content()) + .score(request.score()) + .build(); + } + + public static ReviewResDto.ReviewInfo toReviewInfo(Review review) { + return new ReviewResDto.ReviewInfo( + review.getId(), + review.getMember().getId(), + review.getStore().getId(), + review.getContent(), + review.getScore() + ); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/dto/ReviewReqDto.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/dto/ReviewReqDto.java new file mode 100644 index 0000000..d9b49b7 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/dto/ReviewReqDto.java @@ -0,0 +1,17 @@ +package com.example.umc10th.domain.review.dto; + +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; + +public class ReviewReqDto { + + public record Create( + @NotNull Long memberId, + @NotNull Long storeId, + @NotBlank String content, + @Min(0) @Max(5) float score + ) { + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/dto/ReviewResDto.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/dto/ReviewResDto.java new file mode 100644 index 0000000..5ca1e5d --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/dto/ReviewResDto.java @@ -0,0 +1,13 @@ +package com.example.umc10th.domain.review.dto; + +public class ReviewResDto { + + public record ReviewInfo( + Long reviewId, + Long memberId, + Long storeId, + String content, + float score + ) { + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/entity/Review.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/entity/Review.java new file mode 100644 index 0000000..fef38dd --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/entity/Review.java @@ -0,0 +1,52 @@ +package com.example.umc10th.domain.review.entity; + +import com.example.umc10th.domain.member.entity.Member; +import com.example.umc10th.domain.store.entity.Store; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.util.ArrayList; +import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "review") +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Review { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "review_id") + private Long id; + + @ManyToOne(optional = false) + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @ManyToOne(optional = false) + @JoinColumn(name = "store_id", nullable = false) + private Store store; + + @Column(name = "content", nullable = false, length = 255) + private String content; + + @Column(name = "score", nullable = false) + private Float score; + + @Builder.Default + @OneToMany(mappedBy = "review") + private List reviewImages = new ArrayList<>(); +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/entity/ReviewImage.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/entity/ReviewImage.java new file mode 100644 index 0000000..5fcca7a --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/entity/ReviewImage.java @@ -0,0 +1,36 @@ +package com.example.umc10th.domain.review.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "review_image") +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ReviewImage { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "review_image_id") + private Long id; + + @ManyToOne(optional = false) + @JoinColumn(name = "review_id", nullable = false) + private Review review; + + @Column(name = "image_url", nullable = false, length = 255) + private String imageUrl; +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/exception/ReviewException.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/exception/ReviewException.java new file mode 100644 index 0000000..10f3491 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/exception/ReviewException.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.review.exception; + +import com.example.umc10th.domain.review.exception.code.ReviewErrorCode; +import com.example.umc10th.global.apiPayload.exception.GeneralException; + +public class ReviewException extends GeneralException { + public ReviewException(ReviewErrorCode errorCode) { + super(errorCode); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/exception/code/ReviewErrorCode.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/exception/code/ReviewErrorCode.java new file mode 100644 index 0000000..b435640 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/exception/code/ReviewErrorCode.java @@ -0,0 +1,29 @@ +package com.example.umc10th.domain.review.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum ReviewErrorCode implements BaseErrorCode { + REVIEW_NOT_FOUND(HttpStatus.NOT_FOUND, "REVIEW404", "리뷰를 찾을 수 없습니다."), + MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "MEMBER404", "사용자를 찾을 수 없습니다."), + STORE_NOT_FOUND(HttpStatus.NOT_FOUND, "STORE404", "가게를 찾을 수 없습니다."); + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + @Override + public ReasonDto getReason() { + return new ReasonDto(httpStatus, false, code, message); + } + + @Override + public ReasonDto getReasonHttpStatus() { + return getReason(); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/repository/ReviewImageRepository.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/repository/ReviewImageRepository.java new file mode 100644 index 0000000..6324069 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/repository/ReviewImageRepository.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.review.repository; + +import com.example.umc10th.domain.review.entity.ReviewImage; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReviewImageRepository extends JpaRepository { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/repository/ReviewRepository.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/repository/ReviewRepository.java new file mode 100644 index 0000000..73627b1 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/repository/ReviewRepository.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.review.repository; + +import com.example.umc10th.domain.review.entity.Review; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReviewRepository extends JpaRepository { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/service/ReviewService.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/service/ReviewService.java new file mode 100644 index 0000000..0d29ce7 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/service/ReviewService.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.review.service; + +import com.example.umc10th.domain.review.dto.ReviewReqDto; +import com.example.umc10th.domain.review.dto.ReviewResDto; + +public interface ReviewService { + ReviewResDto.ReviewInfo getReview(Long reviewId); + + ReviewResDto.ReviewInfo createReview(ReviewReqDto.Create request); +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/review/service/ReviewServiceImpl.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/service/ReviewServiceImpl.java new file mode 100644 index 0000000..1cb21bb --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/review/service/ReviewServiceImpl.java @@ -0,0 +1,47 @@ +package com.example.umc10th.domain.review.service; + +import com.example.umc10th.domain.member.entity.Member; +import com.example.umc10th.domain.member.repository.MemberRepository; +import com.example.umc10th.domain.store.entity.Store; +import com.example.umc10th.domain.store.repository.StoreRepository; +import com.example.umc10th.domain.review.converter.ReviewConverter; +import com.example.umc10th.domain.review.dto.ReviewReqDto; +import com.example.umc10th.domain.review.dto.ReviewResDto; +import com.example.umc10th.domain.review.entity.Review; +import com.example.umc10th.domain.review.exception.ReviewException; +import com.example.umc10th.domain.review.exception.code.ReviewErrorCode; +import com.example.umc10th.domain.review.repository.ReviewRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class ReviewServiceImpl implements ReviewService { + + private final ReviewRepository reviewRepository; + private final MemberRepository memberRepository; + private final StoreRepository storeRepository; + + @Override + public ReviewResDto.ReviewInfo getReview(Long reviewId) { + Review review = reviewRepository.findById(reviewId) + .orElseThrow(() -> new ReviewException(ReviewErrorCode.REVIEW_NOT_FOUND)); + + return ReviewConverter.toReviewInfo(review); + } + + @Override + @Transactional + public ReviewResDto.ReviewInfo createReview(ReviewReqDto.Create request) { + Member member = memberRepository.findById(request.memberId()) + .orElseThrow(() -> new ReviewException(ReviewErrorCode.MEMBER_NOT_FOUND)); + + Store store = storeRepository.findById(request.storeId()) + .orElseThrow(() -> new ReviewException(ReviewErrorCode.STORE_NOT_FOUND)); + + Review savedReview = reviewRepository.save(ReviewConverter.toEntity(request, member, store)); + return ReviewConverter.toReviewInfo(savedReview); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/controller/StoreController.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/controller/StoreController.java new file mode 100644 index 0000000..ed3fdb5 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/controller/StoreController.java @@ -0,0 +1,24 @@ +package com.example.umc10th.domain.store.controller; + +import com.example.umc10th.domain.store.dto.StoreResDto; +import com.example.umc10th.domain.store.service.StoreService; +import com.example.umc10th.global.apiPayload.ApiResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/stores") +@RequiredArgsConstructor +public class StoreController { + + private final StoreService storeService; + + @GetMapping("/{storeId}") + public ResponseEntity> getStore(@PathVariable Long storeId) { + return ResponseEntity.ok(ApiResponse.onSuccess(storeService.getStore(storeId))); + } +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/converter/StoreConverter.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/converter/StoreConverter.java new file mode 100644 index 0000000..8e878df --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/converter/StoreConverter.java @@ -0,0 +1,21 @@ +package com.example.umc10th.domain.store.converter; + +import com.example.umc10th.domain.store.dto.StoreResDto; +import com.example.umc10th.domain.store.entity.Store; + +public final class StoreConverter { + + private StoreConverter() { + } + + public static StoreResDto.StoreInfo toStoreInfo(Store store) { + return new StoreResDto.StoreInfo( + store.getId(), + store.getName(), + store.getAddress(), + store.getScore(), + store.getRegion().getName(), + store.getCategory().getName() + ); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/dto/StoreReqDto.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/dto/StoreReqDto.java new file mode 100644 index 0000000..6c07c10 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/dto/StoreReqDto.java @@ -0,0 +1,6 @@ +package com.example.umc10th.domain.store.dto; + +public class StoreReqDto { + private StoreReqDto() { + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/dto/StoreResDto.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/dto/StoreResDto.java new file mode 100644 index 0000000..3bae539 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/dto/StoreResDto.java @@ -0,0 +1,14 @@ +package com.example.umc10th.domain.store.dto; + +public class StoreResDto { + + public record StoreInfo( + Long storeId, + String name, + String address, + Float score, + String regionName, + String categoryName + ) { + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/entity/FoodCategory.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/entity/FoodCategory.java new file mode 100644 index 0000000..5ee64f0 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/entity/FoodCategory.java @@ -0,0 +1,42 @@ +package com.example.umc10th.domain.store.entity; + +import com.example.umc10th.domain.member.entity.MemberPrefer; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.util.ArrayList; +import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "food_category") +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class FoodCategory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "catetory_id") + private Long id; + + @Column(name = "name", nullable = false, length = 20) + private String name; + + @Builder.Default + @OneToMany(mappedBy = "category") + private List stores = new ArrayList<>(); + + @Builder.Default + @OneToMany(mappedBy = "category") + private List memberPrefers = new ArrayList<>(); +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/entity/Region.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/entity/Region.java new file mode 100644 index 0000000..de01d2f --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/entity/Region.java @@ -0,0 +1,37 @@ +package com.example.umc10th.domain.store.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.util.ArrayList; +import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "region") +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Region { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "region_id") + private Long id; + + @Column(name = "name", nullable = false, length = 50) + private String name; + + @Builder.Default + @OneToMany(mappedBy = "region") + private List stores = new ArrayList<>(); +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/entity/Store.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/entity/Store.java new file mode 100644 index 0000000..9b1f949 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/entity/Store.java @@ -0,0 +1,59 @@ +package com.example.umc10th.domain.store.entity; + +import com.example.umc10th.domain.mission.entity.Mission; +import com.example.umc10th.domain.review.entity.Review; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.util.ArrayList; +import java.util.List; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "store") +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Store { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "store_id") + private Long id; + + @ManyToOne(optional = false) + @JoinColumn(name = "region_id", nullable = false) + private Region region; + + @ManyToOne(optional = false) + @JoinColumn(name = "category_id", nullable = false) + private FoodCategory category; + + @Column(name = "name", nullable = false, length = 50) + private String name; + + @Column(name = "address", nullable = false, length = 255) + private String address; + + @Column(name = "score", nullable = false) + private Float score; + + @Builder.Default + @OneToMany(mappedBy = "store") + private List missions = new ArrayList<>(); + + @Builder.Default + @OneToMany(mappedBy = "store") + private List reviews = new ArrayList<>(); +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/exception/StoreException.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/exception/StoreException.java new file mode 100644 index 0000000..6574d25 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/exception/StoreException.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.store.exception; + +import com.example.umc10th.domain.store.exception.code.StoreErrorCode; +import com.example.umc10th.global.apiPayload.exception.GeneralException; + +public class StoreException extends GeneralException { + public StoreException(StoreErrorCode errorCode) { + super(errorCode); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/exception/code/StoreErrorCode.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/exception/code/StoreErrorCode.java new file mode 100644 index 0000000..87e78c3 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/exception/code/StoreErrorCode.java @@ -0,0 +1,27 @@ +package com.example.umc10th.domain.store.exception.code; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum StoreErrorCode implements BaseErrorCode { + STORE_NOT_FOUND(HttpStatus.NOT_FOUND, "STORE404", "가게를 찾을 수 없습니다."); + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + @Override + public ReasonDto getReason() { + return new ReasonDto(httpStatus, false, code, message); + } + + @Override + public ReasonDto getReasonHttpStatus() { + return getReason(); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/repository/FoodCategoryRepository.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/repository/FoodCategoryRepository.java new file mode 100644 index 0000000..485584c --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/repository/FoodCategoryRepository.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.store.repository; + +import com.example.umc10th.domain.store.entity.FoodCategory; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FoodCategoryRepository extends JpaRepository { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/repository/RegionRepository.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/repository/RegionRepository.java new file mode 100644 index 0000000..c1eac74 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/repository/RegionRepository.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.store.repository; + +import com.example.umc10th.domain.store.entity.Region; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RegionRepository extends JpaRepository { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/repository/StoreRepository.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/repository/StoreRepository.java new file mode 100644 index 0000000..9a66926 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/repository/StoreRepository.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.store.repository; + +import com.example.umc10th.domain.store.entity.Store; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface StoreRepository extends JpaRepository { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/service/StoreService.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/service/StoreService.java new file mode 100644 index 0000000..5feb7e4 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/service/StoreService.java @@ -0,0 +1,7 @@ +package com.example.umc10th.domain.store.service; + +import com.example.umc10th.domain.store.dto.StoreResDto; + +public interface StoreService { + StoreResDto.StoreInfo getStore(Long storeId); +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/store/service/StoreServiceImpl.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/service/StoreServiceImpl.java new file mode 100644 index 0000000..835116b --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/store/service/StoreServiceImpl.java @@ -0,0 +1,27 @@ +package com.example.umc10th.domain.store.service; + +import com.example.umc10th.domain.store.converter.StoreConverter; +import com.example.umc10th.domain.store.dto.StoreResDto; +import com.example.umc10th.domain.store.entity.Store; +import com.example.umc10th.domain.store.exception.StoreException; +import com.example.umc10th.domain.store.exception.code.StoreErrorCode; +import com.example.umc10th.domain.store.repository.StoreRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class StoreServiceImpl implements StoreService { + + private final StoreRepository storeRepository; + + @Override + public StoreResDto.StoreInfo getStore(Long storeId) { + Store store = storeRepository.findById(storeId) + .orElseThrow(() -> new StoreException(StoreErrorCode.STORE_NOT_FOUND)); + + return StoreConverter.toStoreInfo(store); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/test/controller/TestController.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/test/controller/TestController.java new file mode 100644 index 0000000..7fcc448 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/test/controller/TestController.java @@ -0,0 +1,20 @@ +package com.example.umc10th.domain.test.controller; + +import com.example.umc10th.domain.test.dto.TestResDto; +import com.example.umc10th.global.apiPayload.ApiResponse; +import com.example.umc10th.global.apiPayload.code.status.SuccessStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1/test") +public class TestController { + + @GetMapping("/health") + public ResponseEntity> health() { + TestResDto.HealthResponse result = new TestResDto.HealthResponse("UP", "Test API is working."); + return ResponseEntity.ok(ApiResponse.of(SuccessStatus.OK, result)); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/domain/test/dto/TestResDto.java b/bean/umc10th/src/main/java/com/example/umc10th/domain/test/dto/TestResDto.java new file mode 100644 index 0000000..bd56486 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/domain/test/dto/TestResDto.java @@ -0,0 +1,10 @@ +package com.example.umc10th.domain.test.dto; + +public class TestResDto { + + public record HealthResponse( + String status, + String message + ) { + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/ApiResponse.java b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/ApiResponse.java new file mode 100644 index 0000000..7912d32 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/ApiResponse.java @@ -0,0 +1,50 @@ +package com.example.umc10th.global.apiPayload; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import com.example.umc10th.global.apiPayload.code.BaseSuccessCode; +import com.example.umc10th.global.apiPayload.code.status.SuccessStatus; +import com.fasterxml.jackson.annotation.JsonInclude; +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; + private final String code; + private final String message; + + @JsonInclude(JsonInclude.Include.NON_NULL) + private T result; + + public static ApiResponse onSuccess(T result) { + return of(SuccessStatus.OK, result); + } + + public static ApiResponse of(BaseSuccessCode code, T result) { + return new ApiResponse<>( + true, + code.getReason().code(), + code.getReason().message(), + result + ); + } + + public static ApiResponse onFailure(BaseErrorCode code, T result) { + return new ApiResponse<>( + false, + code.getReason().code(), + code.getReason().message(), + result + ); + } + + public static ApiResponse onFailure(String code, String message, T result) { + return new ApiResponse<>(false, code, message, result); + } +} diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/BaseCode.java b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/BaseCode.java new file mode 100644 index 0000000..07573cd --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/BaseCode.java @@ -0,0 +1,9 @@ +package com.example.umc10th.global.apiPayload.code; + +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; + +public interface BaseCode { + ReasonDto getReason(); + + ReasonDto getReasonHttpStatus(); +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/BaseErrorCode.java b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/BaseErrorCode.java new file mode 100644 index 0000000..da096a5 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/BaseErrorCode.java @@ -0,0 +1,4 @@ +package com.example.umc10th.global.apiPayload.code; + +public interface BaseErrorCode extends BaseCode { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/BaseSuccessCode.java b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/BaseSuccessCode.java new file mode 100644 index 0000000..35b18d3 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/BaseSuccessCode.java @@ -0,0 +1,4 @@ +package com.example.umc10th.global.apiPayload.code; + +public interface BaseSuccessCode extends BaseCode { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/dto/ReasonDto.java b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/dto/ReasonDto.java new file mode 100644 index 0000000..92b3568 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/dto/ReasonDto.java @@ -0,0 +1,11 @@ +package com.example.umc10th.global.apiPayload.code.dto; + +import org.springframework.http.HttpStatus; + +public record ReasonDto( + HttpStatus httpStatus, + boolean isSuccess, + String code, + String message +) { +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/status/ErrorStatus.java b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/status/ErrorStatus.java new file mode 100644 index 0000000..202e2eb --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/status/ErrorStatus.java @@ -0,0 +1,29 @@ +package com.example.umc10th.global.apiPayload.code.status; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum ErrorStatus implements BaseErrorCode { + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON500", "Server error."), + BAD_REQUEST(HttpStatus.BAD_REQUEST, "COMMON400", "Bad request."), + VALIDATION_ERROR(HttpStatus.BAD_REQUEST, "COMMON4001", "Validation failed."); + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + @Override + public ReasonDto getReason() { + return new ReasonDto(httpStatus, false, code, message); + } + + @Override + public ReasonDto getReasonHttpStatus() { + return getReason(); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/status/SuccessStatus.java b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/status/SuccessStatus.java new file mode 100644 index 0000000..75662f9 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/code/status/SuccessStatus.java @@ -0,0 +1,27 @@ +package com.example.umc10th.global.apiPayload.code.status; + +import com.example.umc10th.global.apiPayload.code.BaseSuccessCode; +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum SuccessStatus implements BaseSuccessCode { + OK(HttpStatus.OK, "COMMON200", "Success"); + + private final HttpStatus httpStatus; + private final String code; + private final String message; + + @Override + public ReasonDto getReason() { + return new ReasonDto(httpStatus, true, code, message); + } + + @Override + public ReasonDto getReasonHttpStatus() { + return getReason(); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/exception/GeneralException.java b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/exception/GeneralException.java new file mode 100644 index 0000000..2021214 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/exception/GeneralException.java @@ -0,0 +1,21 @@ +package com.example.umc10th.global.apiPayload.exception; + +import com.example.umc10th.global.apiPayload.code.BaseErrorCode; +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class GeneralException extends RuntimeException { + + private final BaseErrorCode code; + + public ReasonDto getErrorReason() { + return code.getReason(); + } + + public ReasonDto getErrorReasonHttpStatus() { + return code.getReasonHttpStatus(); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/exception/GeneralExceptionHandler.java b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/exception/GeneralExceptionHandler.java new file mode 100644 index 0000000..b997923 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/apiPayload/exception/GeneralExceptionHandler.java @@ -0,0 +1,46 @@ +package com.example.umc10th.global.apiPayload.exception; + +import com.example.umc10th.global.apiPayload.ApiResponse; +import com.example.umc10th.global.apiPayload.code.dto.ReasonDto; +import com.example.umc10th.global.apiPayload.code.status.ErrorStatus; +import java.util.LinkedHashMap; +import java.util.Map; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +public class GeneralExceptionHandler { + + @ExceptionHandler(GeneralException.class) + public ResponseEntity> handleGeneralException(GeneralException exception) { + ReasonDto reason = exception.getErrorReasonHttpStatus(); + return ResponseEntity + .status(reason.httpStatus()) + .body(ApiResponse.onFailure(reason.code(), reason.message(), null)); + } + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity> handleValidationException(MethodArgumentNotValidException exception) { + Map errors = new LinkedHashMap<>(); + + for (FieldError fieldError : exception.getBindingResult().getFieldErrors()) { + errors.put(fieldError.getField(), fieldError.getDefaultMessage()); + } + + ErrorStatus status = ErrorStatus.VALIDATION_ERROR; + return ResponseEntity + .status(status.getHttpStatus()) + .body(ApiResponse.onFailure(status.getCode(), status.getMessage(), errors)); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity> handleException(Exception exception) { + ErrorStatus status = ErrorStatus.INTERNAL_SERVER_ERROR; + return ResponseEntity + .status(status.getHttpStatus()) + .body(ApiResponse.onFailure(status.getCode(), status.getMessage(), exception.getMessage())); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/java/com/example/umc10th/global/config/SwaggerConfig.java b/bean/umc10th/src/main/java/com/example/umc10th/global/config/SwaggerConfig.java new file mode 100644 index 0000000..b0ab9b2 --- /dev/null +++ b/bean/umc10th/src/main/java/com/example/umc10th/global/config/SwaggerConfig.java @@ -0,0 +1,35 @@ +package com.example.umc10th.global.config; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import io.swagger.v3.oas.models.servers.Server; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + + @Bean + public OpenAPI swagger() { + Info info = new Info().title("UMC10th").description("10th Swagger").version("0.0.1"); + + 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); + } +} \ No newline at end of file diff --git a/bean/umc10th/src/main/resources/application.yml b/bean/umc10th/src/main/resources/application.yml new file mode 100644 index 0000000..d5eb749 --- /dev/null +++ b/bean/umc10th/src/main/resources/application.yml @@ -0,0 +1,19 @@ +spring: + application: + name: "umc10th" + + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: ${DB_URL} + username: ${DB_USER} + password: ${DB_PW} + + jpa: + database: mysql + database-platform: org.hibernate.dialect.MySQLDialect + show-sql: true + hibernate: + ddl-auto: update + properties: + hibernate: + format_sql: true \ No newline at end of file diff --git a/bean/umc10th/src/test/java/com/example/umc10th/Umc10thApplicationTests.java b/bean/umc10th/src/test/java/com/example/umc10th/Umc10thApplicationTests.java new file mode 100644 index 0000000..c1ec339 --- /dev/null +++ b/bean/umc10th/src/test/java/com/example/umc10th/Umc10thApplicationTests.java @@ -0,0 +1,11 @@ +package com.example.umc10th; + +import org.junit.jupiter.api.Test; + +class Umc10thApplicationTests { + + @Test + void smokeTest() { + } + +}