From d9c5ce89895ce215327d6a3022f3a3763f8db51c Mon Sep 17 00:00:00 2001 From: hayoun Date: Sat, 22 Apr 2023 16:19:20 +0900 Subject: [PATCH 01/16] =?UTF-8?q?[init]=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 6148 bytes ThirdSeminar/.gitignore | 37 +++ ThirdSeminar/build.gradle | 33 +++ .../gradle/wrapper/gradle-wrapper.properties | 5 + ThirdSeminar/gradlew | 240 ++++++++++++++++++ ThirdSeminar/gradlew.bat | 91 +++++++ ThirdSeminar/settings.gradle | 1 + .../ThirdSeminar/ThirdSeminarApplication.java | 13 + .../ThirdSeminarApplicationTests.java | 13 + 9 files changed, 433 insertions(+) create mode 100644 .DS_Store create mode 100644 ThirdSeminar/.gitignore create mode 100644 ThirdSeminar/build.gradle create mode 100644 ThirdSeminar/gradle/wrapper/gradle-wrapper.properties create mode 100755 ThirdSeminar/gradlew create mode 100644 ThirdSeminar/gradlew.bat create mode 100644 ThirdSeminar/settings.gradle create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/ThirdSeminarApplication.java create mode 100644 ThirdSeminar/src/test/java/sopt/org/ThirdSeminar/ThirdSeminarApplicationTests.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d5b20d82098ba1469016650a15e03b038e605758 GIT binary patch literal 6148 zcmeHKOG*Pl5Pco9h!`PDmwkeOH<*OUB7z&^0W=vwVUmG>`?--v9AAADM+a9TB2`fJ zDqU6GJrB~|1t2Y-t4m-8U_up4;tYrk4~9mbd_qh*$2C@%V~=WG4@~qIhh*=kxZ%DR zDDh$c&2C#aTSkSN1$Ex3&;!n~!2@<^a6qO09#8b|aa`BE%9l@-Q{3W_xySG8Mh)w( zY{jmVB}0ONU?3O>27-YfVt{wH$mGm0Y%mZE1Ox93$oY_|f`wyis7D8lwgAL2hgImy zgIQ{_W8v5uGD1mKO0?4CEk?3(j%Uv+99u&xNAl()`O0t2OVZUjf7W!Q!Z2(w5DfGg zklvRvllyK#=?@>+2y^m~s0{*ZIz eLW361;xn&sYz<`=8P{@RJOq@GFu}ktFz^a94LJ1x literal 0 HcmV?d00001 diff --git a/ThirdSeminar/.gitignore b/ThirdSeminar/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/ThirdSeminar/.gitignore @@ -0,0 +1,37 @@ +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/ diff --git a/ThirdSeminar/build.gradle b/ThirdSeminar/build.gradle new file mode 100644 index 0000000..4ff82f2 --- /dev/null +++ b/ThirdSeminar/build.gradle @@ -0,0 +1,33 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '2.7.11' + id 'io.spring.dependency-management' version '1.0.15.RELEASE' +} + +group = 'sopt.org' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '11' + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'mysql:mysql-connector-java:8.0.32' + implementation 'org.springframework.boot:spring-boot-starter-validation' + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/ThirdSeminar/gradle/wrapper/gradle-wrapper.properties b/ThirdSeminar/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..774fae8 --- /dev/null +++ b/ThirdSeminar/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/ThirdSeminar/gradlew b/ThirdSeminar/gradlew new file mode 100755 index 0000000..a69d9cb --- /dev/null +++ b/ThirdSeminar/gradlew @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/ThirdSeminar/gradlew.bat b/ThirdSeminar/gradlew.bat new file mode 100644 index 0000000..53a6b23 --- /dev/null +++ b/ThirdSeminar/gradlew.bat @@ -0,0 +1,91 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/ThirdSeminar/settings.gradle b/ThirdSeminar/settings.gradle new file mode 100644 index 0000000..397b799 --- /dev/null +++ b/ThirdSeminar/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'ThirdSeminar' diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/ThirdSeminarApplication.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/ThirdSeminarApplication.java new file mode 100644 index 0000000..e152738 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/ThirdSeminarApplication.java @@ -0,0 +1,13 @@ +package sopt.org.ThirdSeminar; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ThirdSeminarApplication { + + public static void main(String[] args) { + SpringApplication.run(ThirdSeminarApplication.class, args); + } + +} diff --git a/ThirdSeminar/src/test/java/sopt/org/ThirdSeminar/ThirdSeminarApplicationTests.java b/ThirdSeminar/src/test/java/sopt/org/ThirdSeminar/ThirdSeminarApplicationTests.java new file mode 100644 index 0000000..c6d451e --- /dev/null +++ b/ThirdSeminar/src/test/java/sopt/org/ThirdSeminar/ThirdSeminarApplicationTests.java @@ -0,0 +1,13 @@ +package sopt.org.ThirdSeminar; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ThirdSeminarApplicationTests { + + @Test + void contextLoads() { + } + +} From b79c7583d849daefb4e711b6678090c69721d5d1 Mon Sep 17 00:00:00 2001 From: hayoun Date: Sat, 22 Apr 2023 16:38:05 +0900 Subject: [PATCH 02/16] [feat] User Entity --- .../sopt/org/ThirdSeminar/domain/User.java | 36 +++++++++++++++++++ .../src/main/resources/application.yaml | 14 ++++++++ 2 files changed, 50 insertions(+) create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java create mode 100644 ThirdSeminar/src/main/resources/application.yaml diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java new file mode 100644 index 0000000..5623534 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java @@ -0,0 +1,36 @@ +package sopt.org.ThirdSeminar.domain; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class User{ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + public Long id; + + @Column(nullable = false) + private String nickname; + + @Column(nullable = false) + private String email; + + + @Column(nullable = false) + private String password; + + @Builder + public User(String nickname,String email,String password){ + this.nickname=nickname; + this.email=email; + this.password=password; + } + + +} diff --git a/ThirdSeminar/src/main/resources/application.yaml b/ThirdSeminar/src/main/resources/application.yaml new file mode 100644 index 0000000..5399297 --- /dev/null +++ b/ThirdSeminar/src/main/resources/application.yaml @@ -0,0 +1,14 @@ +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/sopt_32?useSSL=true&useUnicode=true&serverTimezone=Asia/Seoul + username: sopt_server + password: 1124 + + jpa: + show-sql: true + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true \ No newline at end of file From 78d6ef7339ea986c192515c039ac3865a6cf53b8 Mon Sep 17 00:00:00 2001 From: hayoun Date: Sat, 22 Apr 2023 16:50:20 +0900 Subject: [PATCH 03/16] [feat] UserRequest DTO --- .../dto/request/UserRequestDto.java | 30 +++++++++++++++++++ .../sopt/org/ThirdSeminar/domain/User.java | 4 +-- .../infrastructure/UserRepository.java | 8 +++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/UserRequestDto.java create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/UserRepository.java diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/UserRequestDto.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/UserRequestDto.java new file mode 100644 index 0000000..d117852 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/UserRequestDto.java @@ -0,0 +1,30 @@ +package sopt.org.ThirdSeminar.controller.dto.request; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class UserRequestDto { + @Email(message = "이메일 형식이 맞지 않습니다.") + @NotNull + private final String email; + + @NotBlank + @Pattern(regexp = "^[가-힣a-zA-Z]{2,10}$", message = "닉네임 형식에 맞지 않습니다.") + private final String nickname; + + @NotBlank + @Pattern(regexp="(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\\W)(?=\\S+$).{8,20}", + message = "비밀번호는 영문 대,소문자와 숫자, 특수기호가 적어도 1개 이상씩 포함된 8자 ~ 20자의 비밀번호여야 합니다." + ) + private final String password; + + +} diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java index 5623534..7561ac0 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java @@ -9,8 +9,8 @@ @Entity @Getter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class User{ +@NoArgsConstructor +public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long id; diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/UserRepository.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/UserRepository.java new file mode 100644 index 0000000..757619a --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/UserRepository.java @@ -0,0 +1,8 @@ +package sopt.org.ThirdSeminar.infrastructure; + +import org.springframework.data.repository.Repository; +import sopt.org.ThirdSeminar.domain.User; + +public interface UserRepository extends Repository { + void save(User user) ; +} From 91e1612243764a17e4b5e0645f562a379b8433a2 Mon Sep 17 00:00:00 2001 From: hayoun Date: Sat, 22 Apr 2023 17:55:06 +0900 Subject: [PATCH 04/16] =?UTF-8?q?[feat]=20=EA=B8=B0=EB=B3=B8=20=EA=B3=BC?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../advice/ControllerExceptionAdvice.java | 19 ++++++++++ .../common/dto/ApiResponseDto.java | 29 +++++++++++++++ .../controller/UserController.java | 27 ++++++++++++++ .../dto/request/UserRequestDto.java | 6 ++-- .../dto/response/UserResponseDto.java | 17 +++++++++ .../ThirdSeminar/exception/ErrorStatus.java | 35 +++++++++++++++++++ .../ThirdSeminar/exception/SuccessStatus.java | 18 ++++++++++ .../org/ThirdSeminar/service/UserService.java | 29 +++++++++++++++ .../src/main/resources/application.yaml | 9 ++++- 9 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/dto/ApiResponseDto.java create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/UserController.java create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/UserResponseDto.java create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/UserService.java diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java new file mode 100644 index 0000000..4821ae8 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java @@ -0,0 +1,19 @@ +package sopt.org.ThirdSeminar.common.advice; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import sopt.org.ThirdSeminar.exception.ErrorStatus; +import sopt.org.thirdSeminar.common.dto.ApiResponseDto; +@RestControllerAdvice +public class ControllerExceptionAdvice { + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(MethodArgumentNotValidException.class) + protected ApiResponseDto handleMethodArgumentNotValidException(final MethodArgumentNotValidException e){ + return ApiResponseDto.error(ErrorStatus.VALIDATION_REQUEST_MISSING_EXCEPTION); + } + +} diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/dto/ApiResponseDto.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/dto/ApiResponseDto.java new file mode 100644 index 0000000..c3b45c1 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/dto/ApiResponseDto.java @@ -0,0 +1,29 @@ +package sopt.org.thirdSeminar.common.dto; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import sopt.org.ThirdSeminar.exception.ErrorStatus; +import sopt.org.ThirdSeminar.exception.SuccessStatus; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class ApiResponseDto { + + private final int code; + private final String message; + private T data; + + public static ApiResponseDto success(SuccessStatus successStatus){ + return new ApiResponseDto<>(successStatus.getHttpStatus().value(),successStatus.getMessage()); + } + public static ApiResponseDto success(SuccessStatus successStatus,T data){ + return new ApiResponseDto<>(successStatus.getHttpStatus().value(),successStatus.getMessage(),data); + } + public static ApiResponseDto error(ErrorStatus errorStatus) { + return new ApiResponseDto<>(errorStatus.getHttpStatus().value(), errorStatus.getMessage()); + } +} \ No newline at end of file diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/UserController.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/UserController.java new file mode 100644 index 0000000..cab2d6b --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/UserController.java @@ -0,0 +1,27 @@ +package sopt.org.ThirdSeminar.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import sopt.org.ThirdSeminar.controller.dto.request.UserRequestDto; +import sopt.org.ThirdSeminar.controller.dto.response.UserResponseDto; +import sopt.org.ThirdSeminar.exception.SuccessStatus; +import sopt.org.ThirdSeminar.service.UserService; +import sopt.org.thirdSeminar.common.dto.ApiResponseDto; +import javax.validation.Valid; + +@RestController +@RequiredArgsConstructor +public class UserController { + + private final UserService userService; + + @PostMapping("/user/signup") + @ResponseStatus(HttpStatus.CREATED) + public ApiResponseDto create(@RequestBody @Valid final UserRequestDto request){ + return ApiResponseDto.success(SuccessStatus.SIGNUP_SUCCESS,userService.create(request)); + } +} diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/UserRequestDto.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/UserRequestDto.java index d117852..75f5a8c 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/UserRequestDto.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/UserRequestDto.java @@ -14,17 +14,17 @@ public class UserRequestDto { @Email(message = "이메일 형식이 맞지 않습니다.") @NotNull - private final String email; + private String email; @NotBlank @Pattern(regexp = "^[가-힣a-zA-Z]{2,10}$", message = "닉네임 형식에 맞지 않습니다.") - private final String nickname; + private String nickname; @NotBlank @Pattern(regexp="(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\\W)(?=\\S+$).{8,20}", message = "비밀번호는 영문 대,소문자와 숫자, 특수기호가 적어도 1개 이상씩 포함된 8자 ~ 20자의 비밀번호여야 합니다." ) - private final String password; + private String password; } diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/UserResponseDto.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/UserResponseDto.java new file mode 100644 index 0000000..591b7d6 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/UserResponseDto.java @@ -0,0 +1,17 @@ +package sopt.org.ThirdSeminar.controller.dto.response; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class UserResponseDto { + + private Long userId; + private String nickname; + + public static UserResponseDto of(Long userId, String nickname) { + return new UserResponseDto(userId, nickname); + } +} diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java new file mode 100644 index 0000000..13a3d05 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java @@ -0,0 +1,35 @@ +package sopt.org.ThirdSeminar.exception; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum ErrorStatus { + + /* +BAD_REQUEST + */ + VALIDATION_EXCEPTION(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), + VALIDATION_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST, "요청값이 입력되지 않았습니다."), + + + /* + CONFLICT + */ + CONFLICT_EMAIL_EXCEPTION(HttpStatus.CONFLICT, "이미 등록된 이메일입니다."), + CONFLICT_NICKNAME_EXCEPTION(HttpStatus.CONFLICT, "이미 등록된 닉네임입니다."), + + /* + SERVER_ERROR + */ + INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "예상치 못한 서버 에러가 발생했습니다."), + BAD_GATEWAY_EXCEPTION(HttpStatus.BAD_GATEWAY, "일시적인 에러가 발생하였습니다.\n잠시 후 다시 시도해주세요!"), + SERVICE_UNAVAILABLE_EXCEPTION(HttpStatus.SERVICE_UNAVAILABLE, "현재 점검 중입니다.\n잠시 후 다시 시도해주세요!"), + ; + + private final HttpStatus httpStatus; + private final String message; +} diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java new file mode 100644 index 0000000..926df85 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java @@ -0,0 +1,18 @@ +package sopt.org.ThirdSeminar.exception; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum SuccessStatus { + + + SIGNUP_SUCCESS(HttpStatus.CREATED,"회원가입이 완료되었습니다"); + + + private final HttpStatus httpStatus; + private final String message; +} diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/UserService.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/UserService.java new file mode 100644 index 0000000..e02439a --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/UserService.java @@ -0,0 +1,29 @@ +package sopt.org.ThirdSeminar.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import sopt.org.ThirdSeminar.controller.dto.request.UserRequestDto; +import sopt.org.ThirdSeminar.controller.dto.response.UserResponseDto; +import sopt.org.ThirdSeminar.domain.User; +import sopt.org.ThirdSeminar.infrastructure.UserRepository; + +@Service +@RequiredArgsConstructor +public class UserService { + + private final UserRepository userRepository; + + @Transactional + public UserResponseDto create(UserRequestDto request){ + User user= User.builder() + .email(request.getEmail()) + .nickname(request.getNickname()) + .password(request.getPassword()) + .build(); + + userRepository.save(user); + + return UserResponseDto.of(user.getId(), user.getNickname()); + } +} diff --git a/ThirdSeminar/src/main/resources/application.yaml b/ThirdSeminar/src/main/resources/application.yaml index 5399297..c56a508 100644 --- a/ThirdSeminar/src/main/resources/application.yaml +++ b/ThirdSeminar/src/main/resources/application.yaml @@ -11,4 +11,11 @@ spring: ddl-auto: create properties: hibernate: - format_sql: true \ No newline at end of file + format_sql: true + logging: + level: + org: + hibernate: + type: + descriptor: + sql: trace \ No newline at end of file From d87d35b7a240ab7c21390f01cb940acb8d23c4a4 Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 20:17:37 +0900 Subject: [PATCH 05/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20Status=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sopt/org/ThirdSeminar/exception/SuccessStatus.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java index 926df85..5205516 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java @@ -10,8 +10,8 @@ public enum SuccessStatus { - SIGNUP_SUCCESS(HttpStatus.CREATED,"회원가입이 완료되었습니다"); - + SIGNUP_SUCCESS(HttpStatus.CREATED,"회원가입이 완료되었습니다"), + SEARCH_SUCCESS(HttpStatus.OK,"유저 검색에 성공했습니다."); private final HttpStatus httpStatus; private final String message; From 665fc19ce07d9ea01cfe2431495fdae7fd0d0621 Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 20:26:20 +0900 Subject: [PATCH 06/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20=EA=B2=80=EC=83=89=20=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0?= =?UTF-8?q?=EB=A6=AC,=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ThirdSeminar/infrastructure/UserRepository.java | 3 +++ .../java/sopt/org/ThirdSeminar/service/UserService.java | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/UserRepository.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/UserRepository.java index 757619a..4e0f14e 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/UserRepository.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/UserRepository.java @@ -5,4 +5,7 @@ public interface UserRepository extends Repository { void save(User user) ; + + User getOne(Long id); + } diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/UserService.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/UserService.java index e02439a..74aa319 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/UserService.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/UserService.java @@ -26,4 +26,10 @@ public UserResponseDto create(UserRequestDto request){ return UserResponseDto.of(user.getId(), user.getNickname()); } + + public UserResponseDto search(Long userId){ + User user=userRepository.getOne(userId); + + return UserResponseDto.of(user.getId(),user.getNickname()); + } } From 954136a3ca0b51739b336db2fdc83f6f40719c52 Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 20:26:28 +0900 Subject: [PATCH 07/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=20id=20=EA=B2=80=EC=83=89=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/ThirdSeminar/controller/UserController.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/UserController.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/UserController.java index cab2d6b..0760451 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/UserController.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/UserController.java @@ -2,10 +2,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import sopt.org.ThirdSeminar.controller.dto.request.UserRequestDto; import sopt.org.ThirdSeminar.controller.dto.response.UserResponseDto; import sopt.org.ThirdSeminar.exception.SuccessStatus; @@ -24,4 +21,10 @@ public class UserController { public ApiResponseDto create(@RequestBody @Valid final UserRequestDto request){ return ApiResponseDto.success(SuccessStatus.SIGNUP_SUCCESS,userService.create(request)); } + + @GetMapping("/user/{id}") + @ResponseStatus(HttpStatus.OK) + public ApiResponseDto search(@PathVariable @Valid final Long id){ + return ApiResponseDto.success(SuccessStatus.SEARCH_SUCCESS,userService.search(id)); + } } From b4a44249da35207663ee3b8158579e57d331a97c Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 20:34:34 +0900 Subject: [PATCH 08/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20=EB=93=B1=EB=A1=9D?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/advice/ControllerExceptionAdvice.java | 9 +++++++++ .../sopt/org/ThirdSeminar/exception/ErrorStatus.java | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java index 4821ae8..867ed70 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java @@ -7,6 +7,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import sopt.org.ThirdSeminar.exception.ErrorStatus; import sopt.org.thirdSeminar.common.dto.ApiResponseDto; + +import javax.persistence.EntityNotFoundException; + @RestControllerAdvice public class ControllerExceptionAdvice { @@ -16,4 +19,10 @@ protected ApiResponseDto handleMethodArgumentNotValidException(final MethodArgum return ApiResponseDto.error(ErrorStatus.VALIDATION_REQUEST_MISSING_EXCEPTION); } + @ResponseStatus(HttpStatus.NOT_FOUND) + @ExceptionHandler(EntityNotFoundException.class) + protected ApiResponseDto handleEntityNotFoundException(final EntityNotFoundException e){ + return ApiResponseDto.error(ErrorStatus.NOT_FOUND_USER); + } + } diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java index 13a3d05..6b9de2d 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java @@ -15,7 +15,7 @@ public enum ErrorStatus { VALIDATION_EXCEPTION(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), VALIDATION_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST, "요청값이 입력되지 않았습니다."), - + NOT_FOUND_USER(HttpStatus.BAD_REQUEST, "등록된 유저가 존재하지 않습니다."), /* CONFLICT */ From 0790d63ccbfd4684111b585fd78842e44b99bd35 Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 22:15:58 +0900 Subject: [PATCH 09/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EB=AC=BC=20=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=84=A0=EC=96=B8,?= =?UTF-8?q?=201:N=20=EC=97=B0=EA=B4=80=EA=B4=80=EA=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/org/ThirdSeminar/domain/Post.java | 28 +++++++++++++++++++ .../sopt/org/ThirdSeminar/domain/User.java | 5 ++++ .../infrastructure/PostRepository.java | 2 ++ 3 files changed, 35 insertions(+) create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/Post.java create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/Post.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/Post.java new file mode 100644 index 0000000..e096aeb --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/Post.java @@ -0,0 +1,28 @@ +package sopt.org.ThirdSeminar.domain; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Entity +@Getter +@NoArgsConstructor +public class Post { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String title; + @Column(nullable = false) + private String content; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="created_userId") + private User created_user; + + + +} diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java index 7561ac0..36be36a 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/User.java @@ -6,6 +6,8 @@ import lombok.NoArgsConstructor; import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; @Entity @Getter @@ -25,11 +27,14 @@ public class User { @Column(nullable = false) private String password; + @OneToMany(mappedBy = "created_user") + private List posts=new ArrayList(); @Builder public User(String nickname,String email,String password){ this.nickname=nickname; this.email=email; this.password=password; + this.posts=new ArrayList(); } diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java new file mode 100644 index 0000000..1cacee3 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java @@ -0,0 +1,2 @@ +package sopt.org.ThirdSeminar.infrastructure;public class PostRepository { +} From 07d874ce5a133bc34493092aca8928c5b4f9ee42 Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 22:24:39 +0900 Subject: [PATCH 10/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]Post=20DTO=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/PostRequestDto.java | 19 +++++++++++++++++++ .../dto/response/PostResponseDto.java | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/PostRequestDto.java create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/PostResponseDto.java diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/PostRequestDto.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/PostRequestDto.java new file mode 100644 index 0000000..093879c --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/request/PostRequestDto.java @@ -0,0 +1,19 @@ +package sopt.org.ThirdSeminar.controller.dto.request; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import javax.validation.constraints.NotNull; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class PostRequestDto { + + @NotNull + private String title; + @NotNull + private String content; + @NotNull + private Long created_userId; +} diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/PostResponseDto.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/PostResponseDto.java new file mode 100644 index 0000000..712bdd8 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/PostResponseDto.java @@ -0,0 +1,19 @@ +package sopt.org.ThirdSeminar.controller.dto.response; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor(access = AccessLevel.PRIVATE) +public class PostResponseDto { + + private String title; + private String content; + private String created_user; + + public static PostResponseDto of(String title,String content,String created_user){ + return new PostResponseDto(title,content,created_user); + } +} From 7e0f1a045cee238296c3e8dc33a7a293634b804e Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 22:24:52 +0900 Subject: [PATCH 11/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20PostRepository=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/PostRepository.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java index 1cacee3..e4cb257 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java @@ -1,2 +1,17 @@ -package sopt.org.ThirdSeminar.infrastructure;public class PostRepository { +package sopt.org.ThirdSeminar.infrastructure; + + +import org.springframework.data.repository.Repository; +import sopt.org.ThirdSeminar.domain.Post; + +import java.util.List; + +public interface PostRepository extends Repository { + + void save(Post post); + + List findAllByPostTitle(String title); + + List findAllById(Long id); + } From a6e2d257128ccb415b292013cb39c868c1869e21 Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 22:37:34 +0900 Subject: [PATCH 12/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20Post=20Builder=20?= =?UTF-8?q?=ED=8C=A8=ED=84=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/sopt/org/ThirdSeminar/domain/Post.java | 4 ++++ .../sopt/org/ThirdSeminar/infrastructure/PostRepository.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/Post.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/Post.java index e096aeb..c752f36 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/Post.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/domain/Post.java @@ -1,5 +1,7 @@ package sopt.org.ThirdSeminar.domain; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -7,7 +9,9 @@ @Entity @Getter +@Builder @NoArgsConstructor +@AllArgsConstructor public class Post { @Id diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java index e4cb257..50fe104 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java @@ -12,6 +12,6 @@ public interface PostRepository extends Repository { List findAllByPostTitle(String title); - List findAllById(Long id); + Post findAllById(Long id); } From 22c0afc69a9d2ebed9ba352a8e4e34404d0252df Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 22:55:23 +0900 Subject: [PATCH 13/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20PostService=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/PostRepository.java | 2 +- .../org/ThirdSeminar/service/PostService.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java index 50fe104..bda562a 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java @@ -10,7 +10,7 @@ public interface PostRepository extends Repository { void save(Post post); - List findAllByPostTitle(String title); + List findAllByTitle(String title); Post findAllById(Long id); diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java new file mode 100644 index 0000000..f77c595 --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java @@ -0,0 +1,41 @@ +package sopt.org.ThirdSeminar.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import sopt.org.ThirdSeminar.controller.dto.request.PostRequestDto; +import sopt.org.ThirdSeminar.controller.dto.response.PostResponseDto; +import sopt.org.ThirdSeminar.domain.Post; +import sopt.org.ThirdSeminar.domain.User; +import sopt.org.ThirdSeminar.infrastructure.PostRepository; +import sopt.org.ThirdSeminar.infrastructure.UserRepository; + +@Service +@RequiredArgsConstructor +public class PostService { + + private final PostRepository postRepository; + private final UserRepository userRepository; + @Transactional + public PostResponseDto create(PostRequestDto postRequestDto){ + + User user=userRepository.getOne(postRequestDto.getCreated_userId()); + Post post= Post.builder() + .title(postRequestDto.getTitle()) + .content(postRequestDto.getContent()) + .created_user(user) + .build(); + + return PostResponseDto.of(post.getTitle(),post.getContent(),user.getNickname()); + } + + @Transactional + public PostResponseDto search(Long postId){ + + Post post= postRepository.findAllById(postId); + User user=post.getCreated_user(); + PostResponseDto postResponseDto=PostResponseDto.of(post.getTitle(),post.getContent(),user.getNickname()); + + return postResponseDto; + } +} From de65d6115723288cb245146433e42de15bdb0ccf Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 22:55:39 +0900 Subject: [PATCH 14/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]PostController=20?= =?UTF-8?q?=EB=B0=8F=20Status=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PostController.java | 26 +++++++++++++++++++ .../ThirdSeminar/exception/SuccessStatus.java | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/PostController.java diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/PostController.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/PostController.java new file mode 100644 index 0000000..5f5e93c --- /dev/null +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/PostController.java @@ -0,0 +1,26 @@ +package sopt.org.ThirdSeminar.controller; + +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import sopt.org.ThirdSeminar.controller.dto.request.PostRequestDto; +import sopt.org.ThirdSeminar.controller.dto.response.PostResponseDto; +import sopt.org.ThirdSeminar.exception.SuccessStatus; +import sopt.org.ThirdSeminar.service.PostService; +import sopt.org.thirdSeminar.common.dto.ApiResponseDto; + +import javax.validation.Valid; + +@RestController +@RequiredArgsConstructor +public class PostController { + + private final PostService postService; + + @PostMapping("/post/create") + public ApiResponseDto crate(@RequestBody @Valid final PostRequestDto postRequestDto){ + return ApiResponseDto.success(SuccessStatus.CREATE_SUCCESS, postService.create(postRequestDto)); + } + +} diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java index 5205516..73e02fd 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/SuccessStatus.java @@ -11,8 +11,9 @@ public enum SuccessStatus { SIGNUP_SUCCESS(HttpStatus.CREATED,"회원가입이 완료되었습니다"), - SEARCH_SUCCESS(HttpStatus.OK,"유저 검색에 성공했습니다."); + SEARCH_SUCCESS(HttpStatus.OK,"유저 검색에 성공했습니다."), + CREATE_SUCCESS(HttpStatus.CREATED,"글 작성에 성공했습니다"); private final HttpStatus httpStatus; private final String message; } From 1bf935b356518bf2af25ca3bb5688577fef09415 Mon Sep 17 00:00:00 2001 From: hayoun Date: Fri, 5 May 2023 23:13:14 +0900 Subject: [PATCH 15/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EB=AC=BC=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PostController.java | 19 +++++++++++----- .../infrastructure/PostRepository.java | 2 +- .../org/ThirdSeminar/service/PostService.java | 22 ++++++++++++++++++- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/PostController.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/PostController.java index 5f5e93c..143c9b0 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/PostController.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/PostController.java @@ -1,9 +1,7 @@ package sopt.org.ThirdSeminar.controller; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import sopt.org.ThirdSeminar.controller.dto.request.PostRequestDto; import sopt.org.ThirdSeminar.controller.dto.response.PostResponseDto; import sopt.org.ThirdSeminar.exception.SuccessStatus; @@ -11,6 +9,7 @@ import sopt.org.thirdSeminar.common.dto.ApiResponseDto; import javax.validation.Valid; +import java.util.List; @RestController @RequiredArgsConstructor @@ -19,8 +18,16 @@ public class PostController { private final PostService postService; @PostMapping("/post/create") - public ApiResponseDto crate(@RequestBody @Valid final PostRequestDto postRequestDto){ - return ApiResponseDto.success(SuccessStatus.CREATE_SUCCESS, postService.create(postRequestDto)); - } + public ApiResponseDto crate(@RequestBody @Valid final PostRequestDto postRequestDto){ + return ApiResponseDto.success(SuccessStatus.CREATE_SUCCESS, postService.create(postRequestDto)); + } + @GetMapping("/post/{id}") + public ApiResponseDto search(@PathVariable final Long id){ + return ApiResponseDto.success(SuccessStatus.SEARCH_SUCCESS,postService.search(id)); + } + @GetMapping("/post/search") + public ApiResponseDto> searchByTitle(@RequestParam final String title){ + return ApiResponseDto.success(SuccessStatus.SEARCH_SUCCESS,postService.searchByTitle(title)); + } } diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java index bda562a..57cad92 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/infrastructure/PostRepository.java @@ -12,6 +12,6 @@ public interface PostRepository extends Repository { List findAllByTitle(String title); - Post findAllById(Long id); + Post getOne(Long id); } diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java index f77c595..810a904 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java @@ -10,6 +10,9 @@ import sopt.org.ThirdSeminar.infrastructure.PostRepository; import sopt.org.ThirdSeminar.infrastructure.UserRepository; +import java.util.ArrayList; +import java.util.List; + @Service @RequiredArgsConstructor public class PostService { @@ -32,10 +35,27 @@ public PostResponseDto create(PostRequestDto postRequestDto){ @Transactional public PostResponseDto search(Long postId){ - Post post= postRepository.findAllById(postId); + Post post= postRepository.getOne(postId); User user=post.getCreated_user(); + System.out.println(user); PostResponseDto postResponseDto=PostResponseDto.of(post.getTitle(),post.getContent(),user.getNickname()); return postResponseDto; } + + @Transactional + public List searchByTitle(String title){ + List postList=postRepository.findAllByTitle(title); + + List responseList=new ArrayList(); + + for (Post post:postList + ) { + User user=post.getCreated_user(); + responseList.add(PostResponseDto.of(post.getTitle(),post.getContent(),user.getNickname())); + + } + + return responseList; + } } From b3f831277ceb644dbc6ebede1d0431a8650039be Mon Sep 17 00:00:00 2001 From: hayoun Date: Sat, 6 May 2023 01:29:46 +0900 Subject: [PATCH 16/16] =?UTF-8?q?[=EC=8B=AC=ED=99=94]=20=EA=B8=B0=ED=83=80?= =?UTF-8?q?=20=EC=98=A4=EB=A5=98=20=ED=94=BD=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/advice/ControllerExceptionAdvice.java | 5 ++--- .../controller/dto/response/PostResponseDto.java | 6 +++--- .../java/sopt/org/ThirdSeminar/exception/ErrorStatus.java | 2 +- .../java/sopt/org/ThirdSeminar/service/PostService.java | 8 ++++---- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java index 867ed70..440ca10 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/common/advice/ControllerExceptionAdvice.java @@ -15,14 +15,13 @@ public class ControllerExceptionAdvice { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MethodArgumentNotValidException.class) - protected ApiResponseDto handleMethodArgumentNotValidException(final MethodArgumentNotValidException e){ + protected ApiResponseDto handleMethodArgumentNotValidException(final MethodArgumentNotValidException e) { return ApiResponseDto.error(ErrorStatus.VALIDATION_REQUEST_MISSING_EXCEPTION); } @ResponseStatus(HttpStatus.NOT_FOUND) @ExceptionHandler(EntityNotFoundException.class) - protected ApiResponseDto handleEntityNotFoundException(final EntityNotFoundException e){ + protected ApiResponseDto handleEntityNotFoundException(final EntityNotFoundException e) { return ApiResponseDto.error(ErrorStatus.NOT_FOUND_USER); } - } diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/PostResponseDto.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/PostResponseDto.java index 712bdd8..3bce587 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/PostResponseDto.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/controller/dto/response/PostResponseDto.java @@ -8,12 +8,12 @@ @Getter @AllArgsConstructor(access = AccessLevel.PRIVATE) public class PostResponseDto { - + private Long id; private String title; private String content; private String created_user; - public static PostResponseDto of(String title,String content,String created_user){ - return new PostResponseDto(title,content,created_user); + public static PostResponseDto of(Long id,String title,String content,String created_user){ + return new PostResponseDto(id,title,content,created_user); } } diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java index 6b9de2d..0cdf79b 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/exception/ErrorStatus.java @@ -15,7 +15,7 @@ public enum ErrorStatus { VALIDATION_EXCEPTION(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), VALIDATION_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST, "요청값이 입력되지 않았습니다."), - NOT_FOUND_USER(HttpStatus.BAD_REQUEST, "등록된 유저가 존재하지 않습니다."), + NOT_FOUND_USER(HttpStatus.BAD_REQUEST, "검색 결과가 없습니다."), /* CONFLICT */ diff --git a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java index 810a904..0cbc885 100644 --- a/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java +++ b/ThirdSeminar/src/main/java/sopt/org/ThirdSeminar/service/PostService.java @@ -28,8 +28,8 @@ public PostResponseDto create(PostRequestDto postRequestDto){ .content(postRequestDto.getContent()) .created_user(user) .build(); - - return PostResponseDto.of(post.getTitle(),post.getContent(),user.getNickname()); + postRepository.save(post); + return PostResponseDto.of(post.getId(),post.getTitle(),post.getContent(),user.getNickname()); } @Transactional @@ -38,7 +38,7 @@ public PostResponseDto search(Long postId){ Post post= postRepository.getOne(postId); User user=post.getCreated_user(); System.out.println(user); - PostResponseDto postResponseDto=PostResponseDto.of(post.getTitle(),post.getContent(),user.getNickname()); + PostResponseDto postResponseDto=PostResponseDto.of(post.getId(),post.getTitle(),post.getContent(),user.getNickname()); return postResponseDto; } @@ -52,7 +52,7 @@ public List searchByTitle(String title){ for (Post post:postList ) { User user=post.getCreated_user(); - responseList.add(PostResponseDto.of(post.getTitle(),post.getContent(),user.getNickname())); + responseList.add(PostResponseDto.of(post.getId(),post.getTitle(),post.getContent(),user.getNickname())); }