From 39fa1fed44448ce98d4f919a7debca9b3d1495bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Fri, 28 Jul 2023 19:26:18 +0900 Subject: [PATCH 01/47] initial commit --- .gitignore | 37 +++ build.gradle | 44 ++++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 63375 bytes gradle/wrapper/gradle-wrapper.properties | 7 + gradlew | 248 ++++++++++++++++++ gradlew.bat | 92 +++++++ settings.gradle | 1 + .../dev/jpaboard/JpaBoardApplication.java | 13 + src/main/resources/application.yml | 1 + .../jpaboard/JpaBoardApplicationTests.java | 13 + 10 files changed, 456 insertions(+) create mode 100644 .gitignore create mode 100644 build.gradle create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100644 src/main/java/dev/jpaboard/JpaBoardApplication.java create mode 100644 src/main/resources/application.yml create mode 100644 src/test/java/dev/jpaboard/JpaBoardApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..c2065bc26 --- /dev/null +++ b/.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/build.gradle b/build.gradle new file mode 100644 index 000000000..17278acdb --- /dev/null +++ b/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.1.2' + id 'io.spring.dependency-management' version '1.1.2' +} + +group = 'dev' +version = '0.0.1-SNAPSHOT' + +java { + sourceCompatibility = '17' +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + // spring + 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' + + // test + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + + // lombok + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + + // database + runtimeOnly 'com.mysql:mysql-connector-j' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..033e24c4cdf41af1ab109bc7f253b2b887023340 GIT binary patch literal 63375 zcmb5VV{~QRw)Y#`wrv{~+qP{x72B%VwzFc}c2cp;N~)5ZbDrJayPv(!dGEd-##*zr z)#n-$y^sH|_dchh3@8{H5D*j;5D<{i*8l5IFJ|DjL!e)upfGNX(kojugZ3I`oH1PvW`wFW_ske0j@lB9bX zO;2)`y+|!@X(fZ1<2n!Qx*)_^Ai@Cv-dF&(vnudG?0CsddG_&Wtae(n|K59ew)6St z#dj7_(Cfwzh$H$5M!$UDd8=4>IQsD3xV=lXUq($;(h*$0^yd+b{qq63f0r_de#!o_ zXDngc>zy`uor)4A^2M#U*DC~i+dc<)Tb1Tv&~Ev@oM)5iJ4Sn#8iRw16XXuV50BS7 zdBL5Mefch(&^{luE{*5qtCZk$oFr3RH=H!c3wGR=HJ(yKc_re_X9pD` zJ;uxPzUfVpgU>DSq?J;I@a+10l0ONXPcDkiYcihREt5~T5Gb}sT0+6Q;AWHl`S5dV>lv%-p9l#xNNy7ZCr%cyqHY%TZ8Q4 zbp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>^LcqauG& zc$m3Z{!u8LvUrm^fT{qX5yD9{?r(CCiUdck%!T`KIZd2oQJz1joB&M(Teg_>;yS<2-5>BWfSPpG`Rt{!j6>kqMAvl^zk0JUEfy$HVJMkxP-GkwZuxL62me2#pj_5*ZIU zP~#C^OZLfl$HO)v;~~c&JHivn|1I9H5y_CDkt0JLLGKm(4*KLVhJ2jh2#vJuM6`b& zE==-lvME^Oj022xF&IV*? '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$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 + 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=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=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $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/gradlew.bat b/gradlew.bat new file mode 100644 index 000000000..93e3f59f1 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@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=. +@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. +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/settings.gradle b/settings.gradle new file mode 100644 index 000000000..4c167a26e --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'jpaBoard' diff --git a/src/main/java/dev/jpaboard/JpaBoardApplication.java b/src/main/java/dev/jpaboard/JpaBoardApplication.java new file mode 100644 index 000000000..e2a70e8ac --- /dev/null +++ b/src/main/java/dev/jpaboard/JpaBoardApplication.java @@ -0,0 +1,13 @@ +package dev.jpaboard; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class JpaBoardApplication { + + public static void main(String[] args) { + SpringApplication.run(JpaBoardApplication.class, args); + } + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1 @@ + diff --git a/src/test/java/dev/jpaboard/JpaBoardApplicationTests.java b/src/test/java/dev/jpaboard/JpaBoardApplicationTests.java new file mode 100644 index 000000000..bee6e2473 --- /dev/null +++ b/src/test/java/dev/jpaboard/JpaBoardApplicationTests.java @@ -0,0 +1,13 @@ +package dev.jpaboard; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class JpaBoardApplicationTests { + + @Test + void contextLoads() { + } + +} From b0db1058fe692fb70feddca2c86eb94389d5b870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Fri, 28 Jul 2023 19:32:55 +0900 Subject: [PATCH 02/47] =?UTF-8?q?feat:=20Post,=20User=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/jpaboard/post/domain/Post.java | 37 +++++++++++++++++++ .../java/dev/jpaboard/user/domain/User.java | 36 ++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/main/java/dev/jpaboard/post/domain/Post.java create mode 100644 src/main/java/dev/jpaboard/user/domain/User.java diff --git a/src/main/java/dev/jpaboard/post/domain/Post.java b/src/main/java/dev/jpaboard/post/domain/Post.java new file mode 100644 index 000000000..6753485b7 --- /dev/null +++ b/src/main/java/dev/jpaboard/post/domain/Post.java @@ -0,0 +1,37 @@ +package dev.jpaboard.post.domain; + +import dev.jpaboard.user.domain.User; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Post { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @ManyToOne + private User user; + + @Column(length = 25, nullable = false) + private String title; + + @Column(length = 5000, nullable = false) + private String content; + + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + @Builder + private Post(String title, String content) { + this.title = title; + this.content = content; + } + +} diff --git a/src/main/java/dev/jpaboard/user/domain/User.java b/src/main/java/dev/jpaboard/user/domain/User.java new file mode 100644 index 000000000..43a6071b9 --- /dev/null +++ b/src/main/java/dev/jpaboard/user/domain/User.java @@ -0,0 +1,36 @@ +package dev.jpaboard.user.domain; + +import jakarta.persistence.*; +import lombok.*; + +import java.time.LocalDateTime; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @Column(length = 5, nullable = false) + private String name; + + @Column(length = 3, nullable = false) + private int age; + + @Column(length = 20) + private String hobby; + + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + @Builder + private User(String name, int age, String hobby) { + this.name = name; + this.age = age; + this.hobby = hobby; + } + +} From 5997b1208203fa5da65eec30ad586cb931e843a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Fri, 28 Jul 2023 19:57:16 +0900 Subject: [PATCH 03/47] =?UTF-8?q?feat:=20=E2=9C=A8JpaAuditing=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=EC=9C=BC=EB=A1=9C=20=EC=83=9D=EC=84=B1=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=EA=B3=BC=20=EC=88=98=EC=A0=95=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/dev/jpaboard/BaseEntity.java | 23 +++++++++++++++++++ .../dev/jpaboard/common/config/JpaConfig.java | 11 +++++++++ .../java/dev/jpaboard/post/domain/Post.java | 6 ++--- .../java/dev/jpaboard/user/domain/User.java | 6 ++--- 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 src/main/java/dev/jpaboard/BaseEntity.java create mode 100644 src/main/java/dev/jpaboard/common/config/JpaConfig.java diff --git a/src/main/java/dev/jpaboard/BaseEntity.java b/src/main/java/dev/jpaboard/BaseEntity.java new file mode 100644 index 000000000..8b61923e0 --- /dev/null +++ b/src/main/java/dev/jpaboard/BaseEntity.java @@ -0,0 +1,23 @@ +package dev.jpaboard; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseEntity { + + @CreatedDate + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; + +} diff --git a/src/main/java/dev/jpaboard/common/config/JpaConfig.java b/src/main/java/dev/jpaboard/common/config/JpaConfig.java new file mode 100644 index 000000000..1532fcdf3 --- /dev/null +++ b/src/main/java/dev/jpaboard/common/config/JpaConfig.java @@ -0,0 +1,11 @@ +package dev.jpaboard.common.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@Configuration +@EnableJpaAuditing +public class JpaConfig { + + +} diff --git a/src/main/java/dev/jpaboard/post/domain/Post.java b/src/main/java/dev/jpaboard/post/domain/Post.java index 6753485b7..e7c6a946f 100644 --- a/src/main/java/dev/jpaboard/post/domain/Post.java +++ b/src/main/java/dev/jpaboard/post/domain/Post.java @@ -1,5 +1,6 @@ package dev.jpaboard.post.domain; +import dev.jpaboard.BaseEntity; import dev.jpaboard.user.domain.User; import jakarta.persistence.*; import lombok.AccessLevel; @@ -10,7 +11,7 @@ @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Post { +public class Post extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -25,9 +26,6 @@ public class Post { @Column(length = 5000, nullable = false) private String content; - private LocalDateTime createdAt; - private LocalDateTime updatedAt; - @Builder private Post(String title, String content) { this.title = title; diff --git a/src/main/java/dev/jpaboard/user/domain/User.java b/src/main/java/dev/jpaboard/user/domain/User.java index 43a6071b9..689b50395 100644 --- a/src/main/java/dev/jpaboard/user/domain/User.java +++ b/src/main/java/dev/jpaboard/user/domain/User.java @@ -1,5 +1,6 @@ package dev.jpaboard.user.domain; +import dev.jpaboard.BaseEntity; import jakarta.persistence.*; import lombok.*; @@ -8,7 +9,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class User { +public class User extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -23,9 +24,6 @@ public class User { @Column(length = 20) private String hobby; - private LocalDateTime createdAt; - private LocalDateTime updatedAt; - @Builder private User(String name, int age, String hobby) { this.name = name; From ff76a54da39ca4a1174924b5a9a582e87d1b3e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Fri, 28 Jul 2023 19:59:31 +0900 Subject: [PATCH 04/47] =?UTF-8?q?feat:=20=E2=9C=A8PostRepository,=20UserRe?= =?UTF-8?q?pository=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/jpaboard/post/repository/PostRepository.java | 7 +++++++ .../java/dev/jpaboard/user/repository/UserRepository.java | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 src/main/java/dev/jpaboard/post/repository/PostRepository.java create mode 100644 src/main/java/dev/jpaboard/user/repository/UserRepository.java diff --git a/src/main/java/dev/jpaboard/post/repository/PostRepository.java b/src/main/java/dev/jpaboard/post/repository/PostRepository.java new file mode 100644 index 000000000..f556d0a19 --- /dev/null +++ b/src/main/java/dev/jpaboard/post/repository/PostRepository.java @@ -0,0 +1,7 @@ +package dev.jpaboard.post.repository; + +import dev.jpaboard.post.domain.Post; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PostRepository extends JpaRepository { +} diff --git a/src/main/java/dev/jpaboard/user/repository/UserRepository.java b/src/main/java/dev/jpaboard/user/repository/UserRepository.java new file mode 100644 index 000000000..242ff27e5 --- /dev/null +++ b/src/main/java/dev/jpaboard/user/repository/UserRepository.java @@ -0,0 +1,7 @@ +package dev.jpaboard.user.repository; + +import org.apache.catalina.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { +} From 313a9c0148279919a632c25aaef2d532da8b1349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 30 Jul 2023 15:01:35 +0900 Subject: [PATCH 05/47] =?UTF-8?q?feat:=20PostController=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/post/api/PostController.java | 48 +++++++++++++++++++ .../java/dev/jpaboard/post/domain/Post.java | 9 +++- .../jpaboard/post/dto/PostCreateRequest.java | 14 ++++++ .../dev/jpaboard/post/dto/PostResponse.java | 16 +++++++ .../jpaboard/post/dto/PostUpdateRequest.java | 4 ++ .../user/dto/request/UserUpdateRequest.java | 5 ++ 6 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/main/java/dev/jpaboard/post/api/PostController.java create mode 100644 src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java create mode 100644 src/main/java/dev/jpaboard/post/dto/PostResponse.java create mode 100644 src/main/java/dev/jpaboard/post/dto/PostUpdateRequest.java create mode 100644 src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java new file mode 100644 index 000000000..6893068c7 --- /dev/null +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -0,0 +1,48 @@ +package dev.jpaboard.post.api; + +import dev.jpaboard.post.application.PostService; +import dev.jpaboard.post.dto.PostCreateRequest; +import dev.jpaboard.post.dto.PostResponse; +import dev.jpaboard.post.dto.PostUpdateRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api") +@RequiredArgsConstructor +public class PostController { + + private final PostService postService; + + @PostMapping("/posts") + @ResponseStatus(HttpStatus.CREATED) + public PostResponse create(PostCreateRequest request) { + return postService.create(request); + } + + @PatchMapping("/posts/{id}") + @ResponseStatus(HttpStatus.OK) + public PostResponse update(@PathVariable Long id, PostUpdateRequest request) { + return postService.update(request, id); + } + + @GetMapping("/posts/{id}") + @ResponseStatus(HttpStatus.OK) + public PostResponse findPost(@PathVariable Long id) { + return postService.findPost(id); + } + + @DeleteMapping("/posts/{id}") + @ResponseStatus(HttpStatus.OK) + public void delete(@PathVariable Long id) { + postService.delete(id); + } + + @DeleteMapping("/posts") + @ResponseStatus(HttpStatus.OK) + public void deleteAll() { + postService.deleteAll(); + } + +} diff --git a/src/main/java/dev/jpaboard/post/domain/Post.java b/src/main/java/dev/jpaboard/post/domain/Post.java index e7c6a946f..a49c7bc80 100644 --- a/src/main/java/dev/jpaboard/post/domain/Post.java +++ b/src/main/java/dev/jpaboard/post/domain/Post.java @@ -5,11 +5,11 @@ import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; - @Entity +@Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Post extends BaseEntity { @@ -32,4 +32,9 @@ private Post(String title, String content) { this.content = content; } + public void update(String title, String content) { + this.title = title; + this.content = content; + } + } diff --git a/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java b/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java new file mode 100644 index 000000000..0b9695edd --- /dev/null +++ b/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java @@ -0,0 +1,14 @@ +package dev.jpaboard.post.dto; + +import dev.jpaboard.post.domain.Post; + +public record PostCreateRequest(String title, String content) { + + public static Post toPost(PostCreateRequest request) { + return Post.builder() + .title(request.title) + .content(request.content()) + .build(); + } + +} diff --git a/src/main/java/dev/jpaboard/post/dto/PostResponse.java b/src/main/java/dev/jpaboard/post/dto/PostResponse.java new file mode 100644 index 000000000..332b33b7f --- /dev/null +++ b/src/main/java/dev/jpaboard/post/dto/PostResponse.java @@ -0,0 +1,16 @@ +package dev.jpaboard.post.dto; + +import dev.jpaboard.post.domain.Post; +import lombok.Builder; + +@Builder +public record PostResponse(String title, String content) { + + public static PostResponse toDto(Post post) { + return PostResponse.builder() + .title(post.getTitle()) + .content(post.getContent()) + .build(); + } + +} diff --git a/src/main/java/dev/jpaboard/post/dto/PostUpdateRequest.java b/src/main/java/dev/jpaboard/post/dto/PostUpdateRequest.java new file mode 100644 index 000000000..253ab21e4 --- /dev/null +++ b/src/main/java/dev/jpaboard/post/dto/PostUpdateRequest.java @@ -0,0 +1,4 @@ +package dev.jpaboard.post.dto; + +public record PostUpdateRequest(String title, String content) { +} diff --git a/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java b/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java new file mode 100644 index 000000000..8d68b4f16 --- /dev/null +++ b/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java @@ -0,0 +1,5 @@ +package dev.jpaboard.user.dto.request; + +public record UserUpdateRequest(String name, String hobby) { + +} From 62b604f71496fd48c921865084a0fd53c3269714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 30 Jul 2023 15:12:27 +0900 Subject: [PATCH 06/47] =?UTF-8?q?feat:=20PostService=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/application/PostService.java | 51 +++++++++++++++++++ .../post/exception/PostNotFoundException.java | 10 ++++ 2 files changed, 61 insertions(+) create mode 100644 src/main/java/dev/jpaboard/post/application/PostService.java create mode 100644 src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java diff --git a/src/main/java/dev/jpaboard/post/application/PostService.java b/src/main/java/dev/jpaboard/post/application/PostService.java new file mode 100644 index 000000000..789486e06 --- /dev/null +++ b/src/main/java/dev/jpaboard/post/application/PostService.java @@ -0,0 +1,51 @@ +package dev.jpaboard.post.application; + +import dev.jpaboard.post.domain.Post; +import dev.jpaboard.post.dto.PostCreateRequest; +import dev.jpaboard.post.dto.PostUpdateRequest; +import dev.jpaboard.post.exception.PostNotFoundException; +import dev.jpaboard.post.repository.PostRepository; +import dev.jpaboard.post.dto.PostResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class PostService { + + private final PostRepository postRepository; + + @Transactional + public PostResponse create(PostCreateRequest request) { + Post post = PostCreateRequest.toPost(request); + Post savedPost = postRepository.save(post); + return PostResponse.toDto(savedPost); + } + + @Transactional + public PostResponse update(PostUpdateRequest request, Long postId) { + Post post = postRepository.findById(postId) + .orElseThrow(PostNotFoundException::new); + post.update(request.title(), request.content()); + return PostResponse.toDto(post); + } + + public PostResponse findPost(Long id) { + Post post = postRepository.findById(id) + .orElseThrow(PostNotFoundException::new); + return PostResponse.toDto(post); + } + + @Transactional + public void delete(Long id) { + postRepository.deleteById(id); + } + + @Transactional + public void deleteAll() { + postRepository.deleteAll(); + } + +} diff --git a/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java b/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java new file mode 100644 index 000000000..697703865 --- /dev/null +++ b/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java @@ -0,0 +1,10 @@ +package dev.jpaboard.post.exception; + +public class PostNotFoundException extends RuntimeException { + private static final String MESSAGE = "게시글을 찾을 수 없습니다."; + + public PostNotFoundException() { + super(MESSAGE); + } + +} From 47d7a23f0cb3f62e3b70efa46df894a0a3ce3765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 30 Jul 2023 15:17:23 +0900 Subject: [PATCH 07/47] =?UTF-8?q?feat:=20UserController=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/user/api/UserController.java | 68 +++++++++++++++++++ .../java/dev/jpaboard/user/domain/User.java | 23 ++++++- .../user/dto/request/UserCreateRequest.java | 17 +++++ .../user/dto/request/UserLoginRequest.java | 5 ++ .../user/dto/response/UserResponse.java | 19 ++++++ 5 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 src/main/java/dev/jpaboard/user/api/UserController.java create mode 100644 src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java create mode 100644 src/main/java/dev/jpaboard/user/dto/request/UserLoginRequest.java create mode 100644 src/main/java/dev/jpaboard/user/dto/response/UserResponse.java diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java new file mode 100644 index 000000000..84640ff4b --- /dev/null +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -0,0 +1,68 @@ +package dev.jpaboard.user.api; + +import dev.jpaboard.user.dto.response.UserResponse; +import dev.jpaboard.user.application.UserService; +import dev.jpaboard.user.dto.request.UserCreateRequest; +import dev.jpaboard.user.dto.request.UserLoginRequest; +import dev.jpaboard.user.dto.request.UserUpdateRequest; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api") +@RequiredArgsConstructor +public class UserController { + + private final UserService userService; + + @PostMapping("/users") + @ResponseStatus(HttpStatus.CREATED) + public UserResponse signUp(UserCreateRequest request) { + return userService.signUp(request); + } + + @PostMapping("/users/login") + @ResponseStatus(HttpStatus.OK) + public String login(HttpServletRequest httpRequest, UserLoginRequest request) { + httpRequest.getSession().invalidate(); + HttpSession session = httpRequest.getSession(true); + + Long userId = userService.login(request); + session.setAttribute("userId", userId); + session.setMaxInactiveInterval(3600); + + return "redirect:api/users"; + } + + @GetMapping("/user/logout") + public String logout(HttpServletRequest request) { + HttpSession session = request.getSession(false); + if (session != null) { + session.invalidate(); + } + return "redirect:/api/users"; + } + + @PatchMapping("/users/update") + @ResponseStatus(HttpStatus.OK) + public UserResponse update(UserUpdateRequest userUpdateRequest, HttpServletRequest request) { + HttpSession session = request.getSession(false); + return userService.update(userUpdateRequest, (Long) session.getAttribute("userId")); + } + + @GetMapping("/users/me") + public UserResponse findUser(HttpServletRequest httpRequest) { + HttpSession session = httpRequest.getSession(false); + Long id = (Long) session.getAttribute("userId"); + return userService.findUser(id); + } + + @DeleteMapping("/users/{id}") + public void delete(@PathVariable Long id) { + userService.delete(id); + } + +} diff --git a/src/main/java/dev/jpaboard/user/domain/User.java b/src/main/java/dev/jpaboard/user/domain/User.java index 689b50395..bae6a9a42 100644 --- a/src/main/java/dev/jpaboard/user/domain/User.java +++ b/src/main/java/dev/jpaboard/user/domain/User.java @@ -2,19 +2,29 @@ import dev.jpaboard.BaseEntity; import jakarta.persistence.*; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.Pattern; import lombok.*; -import java.time.LocalDateTime; - @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class User extends BaseEntity { + private static final String EMAIL_REGEX = "^[_a-z0-9-]+(.[_a-z0-9-]+)*@(?:\\\\w+\\\\.)+\\\\w+$"; + private static final String PASSWORD_REGEX = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*\\W).{8,20}$"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; + @Column(length = 25, nullable = false) + @Email(regexp = EMAIL_REGEX) + private String email; + + @Column(length = 20, nullable = false) + @Pattern(regexp = PASSWORD_REGEX) + private String password; + @Column(length = 5, nullable = false) private String name; @@ -25,10 +35,17 @@ public class User extends BaseEntity { private String hobby; @Builder - private User(String name, int age, String hobby) { + private User(String email, String password, String name, int age, String hobby) { + this.email = email; + this.password = password; this.name = name; this.age = age; this.hobby = hobby; } + public void update(String name, String hobby) { + this.name = name; + this.hobby = hobby; + } + } diff --git a/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java b/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java new file mode 100644 index 000000000..713eb6d85 --- /dev/null +++ b/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java @@ -0,0 +1,17 @@ +package dev.jpaboard.user.dto.request; + +import dev.jpaboard.user.domain.User; + +public record UserCreateRequest(String email, String password, String name, int age, String hobby) { + + public static User toUser(UserCreateRequest request) { + return User.builder() + .email(request.email) + .password(request.password) + .name(request.name) + .age(request.age) + .hobby(request.hobby) + .build(); + } + +} diff --git a/src/main/java/dev/jpaboard/user/dto/request/UserLoginRequest.java b/src/main/java/dev/jpaboard/user/dto/request/UserLoginRequest.java new file mode 100644 index 000000000..939732924 --- /dev/null +++ b/src/main/java/dev/jpaboard/user/dto/request/UserLoginRequest.java @@ -0,0 +1,5 @@ +package dev.jpaboard.user.dto.request; + +public record UserLoginRequest(String email, String password) { + +} diff --git a/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java b/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java new file mode 100644 index 000000000..9463dcfe1 --- /dev/null +++ b/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java @@ -0,0 +1,19 @@ +package dev.jpaboard.user.dto.response; + +import dev.jpaboard.user.domain.User; +import lombok.Builder; + +@Builder +public record UserResponse(Long id, String email, String name, int age, String hobby) { + + public static UserResponse toDto(User user) { + return UserResponse.builder() + .id(user.getId()) + .email(user.getEmail()) + .name(user.getName()) + .age(user.getAge()) + .hobby(user.getHobby()) + .build(); + } + +} From 6e2e97811499975cc876de991a32f3ec65d34151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 30 Jul 2023 15:17:37 +0900 Subject: [PATCH 08/47] =?UTF-8?q?feat:=20UserService=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/application/UserService.java | 53 +++++++++++++++++++ .../user/exception/UserNotFoundException.java | 10 ++++ 2 files changed, 63 insertions(+) create mode 100644 src/main/java/dev/jpaboard/user/application/UserService.java create mode 100644 src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java diff --git a/src/main/java/dev/jpaboard/user/application/UserService.java b/src/main/java/dev/jpaboard/user/application/UserService.java new file mode 100644 index 000000000..0105b443e --- /dev/null +++ b/src/main/java/dev/jpaboard/user/application/UserService.java @@ -0,0 +1,53 @@ +package dev.jpaboard.user.application; + +import dev.jpaboard.user.dto.request.UserCreateRequest; +import dev.jpaboard.user.domain.User; +import dev.jpaboard.user.dto.request.UserLoginRequest; +import dev.jpaboard.user.dto.response.UserResponse; +import dev.jpaboard.user.dto.request.UserUpdateRequest; +import dev.jpaboard.user.exception.UserNotFoundException; +import dev.jpaboard.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class UserService { + + private final UserRepository userRepository; + + @Transactional + public UserResponse signUp(UserCreateRequest request) { + User user = UserCreateRequest.toUser(request); + User savedUser = userRepository.save(user); + return UserResponse.toDto(savedUser); + } + + public Long login(UserLoginRequest request) { + User user = userRepository.findByEmailAndPassword(request.email(), request.password()) + .orElseThrow(UserNotFoundException::new); + return user.getId(); + } + + @Transactional + public UserResponse update(UserUpdateRequest request, Long userId) { + User user = userRepository.findById(userId) + .orElseThrow(UserNotFoundException::new); + user.update(request.name(), request.hobby()); + return UserResponse.toDto(user); + } + + public UserResponse findUser(Long id) { + User user = userRepository.findById(id) + .orElseThrow(UserNotFoundException::new); + return UserResponse.toDto(user); + } + + @Transactional + public void delete(Long id) { + userRepository.deleteById(id); + } + +} diff --git a/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java b/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java new file mode 100644 index 000000000..ed42f4a4b --- /dev/null +++ b/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java @@ -0,0 +1,10 @@ +package dev.jpaboard.user.exception; + +public class UserNotFoundException extends RuntimeException { + private static final String MESSAGE = "유저를 찾을 수 없습니다."; + + public UserNotFoundException() { + super(MESSAGE); + } + +} From 732add59014cf27c73bfb3471f518898f7de7cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 30 Jul 2023 15:18:51 +0900 Subject: [PATCH 09/47] =?UTF-8?q?feat:=20email,=20password=EB=A1=9C=20User?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/jpaboard/user/repository/UserRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/dev/jpaboard/user/repository/UserRepository.java b/src/main/java/dev/jpaboard/user/repository/UserRepository.java index 242ff27e5..892da7492 100644 --- a/src/main/java/dev/jpaboard/user/repository/UserRepository.java +++ b/src/main/java/dev/jpaboard/user/repository/UserRepository.java @@ -1,7 +1,10 @@ package dev.jpaboard.user.repository; -import org.apache.catalina.User; +import dev.jpaboard.user.domain.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface UserRepository extends JpaRepository { + Optional findByEmailAndPassword(String email, String password); } From 078fa07375401930580060759482834ea116ffb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 30 Jul 2023 21:47:24 +0900 Subject: [PATCH 10/47] =?UTF-8?q?feat:=20Post=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=95=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/post/api/PostController.java | 17 +++++++++++++++++ .../post/application/PostService.java | 19 +++++++++++++++---- .../java/dev/jpaboard/post/domain/Post.java | 2 +- .../post/repository/PostRepository.java | 5 +++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java index 6893068c7..25ceb0608 100644 --- a/src/main/java/dev/jpaboard/post/api/PostController.java +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -4,7 +4,12 @@ import dev.jpaboard.post.dto.PostCreateRequest; import dev.jpaboard.post.dto.PostResponse; import dev.jpaboard.post.dto.PostUpdateRequest; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -33,6 +38,18 @@ public PostResponse findPost(@PathVariable Long id) { return postService.findPost(id); } + @GetMapping("/posts/{userId}") + @ResponseStatus(HttpStatus.OK) + public Page findPostByUser(@PathVariable Long userId, @PageableDefault(sort = "createdAt", direction = DESC) Pageable pageable) { + return postService.findPostByUser(userId, pageable); + } + + @GetMapping("/posts") + @ResponseStatus(HttpStatus.OK) + public Page findSlicePost(@PageableDefault(sort = "createdAt", direction = DESC) Pageable pageable) { + return postService.findAll(pageable); + } + @DeleteMapping("/posts/{id}") @ResponseStatus(HttpStatus.OK) public void delete(@PathVariable Long id) { diff --git a/src/main/java/dev/jpaboard/post/application/PostService.java b/src/main/java/dev/jpaboard/post/application/PostService.java index 789486e06..e400b64b4 100644 --- a/src/main/java/dev/jpaboard/post/application/PostService.java +++ b/src/main/java/dev/jpaboard/post/application/PostService.java @@ -6,7 +6,12 @@ import dev.jpaboard.post.exception.PostNotFoundException; import dev.jpaboard.post.repository.PostRepository; import dev.jpaboard.post.dto.PostResponse; +import dev.jpaboard.user.domain.User; +import dev.jpaboard.user.exception.UserNotFoundException; +import dev.jpaboard.user.repository.UserRepository; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -38,14 +43,20 @@ public PostResponse findPost(Long id) { return PostResponse.toDto(post); } + public Page findAll(Pageable pageable) { + Page postPage = postRepository.findAll(pageable); + return postPage.map(PostResponse::toDto); + } + + public Page findPostByUser(Long userId, Pageable pageable) { + Page postPage = postRepository.findPostByUserId(userId, pageable); + return postPage.map(PostResponse::toDto); + } + @Transactional public void delete(Long id) { postRepository.deleteById(id); } - @Transactional - public void deleteAll() { - postRepository.deleteAll(); - } } diff --git a/src/main/java/dev/jpaboard/post/domain/Post.java b/src/main/java/dev/jpaboard/post/domain/Post.java index a49c7bc80..ff3073554 100644 --- a/src/main/java/dev/jpaboard/post/domain/Post.java +++ b/src/main/java/dev/jpaboard/post/domain/Post.java @@ -1,6 +1,6 @@ package dev.jpaboard.post.domain; -import dev.jpaboard.BaseEntity; +import dev.jpaboard.common.entity.BaseEntity; import dev.jpaboard.user.domain.User; import jakarta.persistence.*; import lombok.AccessLevel; diff --git a/src/main/java/dev/jpaboard/post/repository/PostRepository.java b/src/main/java/dev/jpaboard/post/repository/PostRepository.java index f556d0a19..b3491281f 100644 --- a/src/main/java/dev/jpaboard/post/repository/PostRepository.java +++ b/src/main/java/dev/jpaboard/post/repository/PostRepository.java @@ -1,7 +1,12 @@ package dev.jpaboard.post.repository; import dev.jpaboard.post.domain.Post; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; public interface PostRepository extends JpaRepository { + + Page findPostByUserId(Long userId, Pageable pageable); + } From de64f1afdfb0ab254cb6c7ca64ed990fd144fb54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 30 Jul 2023 21:48:41 +0900 Subject: [PATCH 11/47] =?UTF-8?q?feat:=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EB=B0=8F=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/jpaboard/user/api/UserController.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index 84640ff4b..e88ebf27c 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -20,26 +20,26 @@ public class UserController { @PostMapping("/users") @ResponseStatus(HttpStatus.CREATED) - public UserResponse signUp(UserCreateRequest request) { + public UserResponse signUp(@RequestBody UserCreateRequest request) { return userService.signUp(request); } @PostMapping("/users/login") @ResponseStatus(HttpStatus.OK) - public String login(HttpServletRequest httpRequest, UserLoginRequest request) { + public Long login(@RequestBody UserLoginRequest request, HttpServletRequest httpRequest) { httpRequest.getSession().invalidate(); HttpSession session = httpRequest.getSession(true); Long userId = userService.login(request); session.setAttribute("userId", userId); session.setMaxInactiveInterval(3600); - - return "redirect:api/users"; + return userId; } @GetMapping("/user/logout") - public String logout(HttpServletRequest request) { - HttpSession session = request.getSession(false); + @ResponseStatus(HttpStatus.OK) + public String logout(HttpServletRequest httpRequest) { + HttpSession session = httpRequest.getSession(false); if (session != null) { session.invalidate(); } From ded55e569193d5d3808b7afae0d5ca1d048af567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 30 Jul 2023 21:49:24 +0900 Subject: [PATCH 12/47] =?UTF-8?q?feat:=20email=EA=B3=BC=20password?= =?UTF-8?q?=EC=97=90=20`@Valid`=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/jpaboard/{ => common/entity}/BaseEntity.java | 2 +- src/main/java/dev/jpaboard/user/domain/User.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) rename src/main/java/dev/jpaboard/{ => common/entity}/BaseEntity.java (93%) diff --git a/src/main/java/dev/jpaboard/BaseEntity.java b/src/main/java/dev/jpaboard/common/entity/BaseEntity.java similarity index 93% rename from src/main/java/dev/jpaboard/BaseEntity.java rename to src/main/java/dev/jpaboard/common/entity/BaseEntity.java index 8b61923e0..d24d24225 100644 --- a/src/main/java/dev/jpaboard/BaseEntity.java +++ b/src/main/java/dev/jpaboard/common/entity/BaseEntity.java @@ -1,4 +1,4 @@ -package dev.jpaboard; +package dev.jpaboard.common.entity; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; diff --git a/src/main/java/dev/jpaboard/user/domain/User.java b/src/main/java/dev/jpaboard/user/domain/User.java index bae6a9a42..74cd937d0 100644 --- a/src/main/java/dev/jpaboard/user/domain/User.java +++ b/src/main/java/dev/jpaboard/user/domain/User.java @@ -1,7 +1,8 @@ package dev.jpaboard.user.domain; -import dev.jpaboard.BaseEntity; +import dev.jpaboard.common.entity.BaseEntity; import jakarta.persistence.*; +import jakarta.validation.Valid; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Pattern; import lombok.*; @@ -11,7 +12,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class User extends BaseEntity { - private static final String EMAIL_REGEX = "^[_a-z0-9-]+(.[_a-z0-9-]+)*@(?:\\\\w+\\\\.)+\\\\w+$"; + private static final String EMAIL_REGEX = "^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$"; private static final String PASSWORD_REGEX = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*\\W).{8,20}$"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -35,7 +36,7 @@ public class User extends BaseEntity { private String hobby; @Builder - private User(String email, String password, String name, int age, String hobby) { + private User(@Valid String email, @Valid String password, String name, int age, String hobby) { this.email = email; this.password = password; this.name = name; From 5d88c1501bc2bea5e6fb4082112b3a0e1072a9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 30 Jul 2023 21:50:07 +0900 Subject: [PATCH 13/47] =?UTF-8?q?test:=20PostRepository=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/repository/PostRepositoryTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/test/java/dev/jpaboard/post/repository/PostRepositoryTest.java diff --git a/src/test/java/dev/jpaboard/post/repository/PostRepositoryTest.java b/src/test/java/dev/jpaboard/post/repository/PostRepositoryTest.java new file mode 100644 index 000000000..1aa92c6bc --- /dev/null +++ b/src/test/java/dev/jpaboard/post/repository/PostRepositoryTest.java @@ -0,0 +1,56 @@ +package dev.jpaboard.post.repository; + +import dev.jpaboard.post.domain.Post; +import dev.jpaboard.user.domain.User; +import dev.jpaboard.user.repository.UserRepository; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import java.util.List; + +@DataJpaTest +class PostRepositoryTest { + + @Autowired + private PostRepository postRepository; + + @Autowired + private UserRepository userRepository; + + @Test + void findPostByUserTest() { + //given + User user = User.builder() + .email("qkrdmswl123@naver.com") + .name("바보은지") + .password("Qkr123@234") + .hobby("박은지 바보") + .age(11) + .build(); + User 박은지 = userRepository.save(user); + Post 박 = createPost("제목1", "내용1", 박은지); + Post 은 = createPost("제목2", "내용2", 박은지); + Post 지 = createPost("제목3", "내용3", 박은지); + + //when + postRepository.saveAll(List.of(박, 은, 지)); + + //then + Page posts = postRepository.findPostByUserId(박은지.getId(), PageRequest.of(0, 1)); + + Assertions.assertThat(posts.getTotalPages()).isEqualTo(3); + } + + Post createPost(String 제목, String 내용, User 유저) { + return Post.builder() + .title(제목) + .content(내용) + .user(유저) + .build(); + } + +} From ad59f1308bcce70aba16f54a21b6c00fff672c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 16:06:04 +0900 Subject: [PATCH 14/47] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EC=8A=A4?= =?UTF-8?q?=ED=83=80=EC=9D=BC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/jpaboard/post/domain/Post.java | 26 +++++++++---------- .../dev/jpaboard/post/dto/PostResponse.java | 12 ++++----- .../post/exception/PostNotFoundException.java | 8 +++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/dev/jpaboard/post/domain/Post.java b/src/main/java/dev/jpaboard/post/domain/Post.java index ff3073554..e09823ec9 100644 --- a/src/main/java/dev/jpaboard/post/domain/Post.java +++ b/src/main/java/dev/jpaboard/post/domain/Post.java @@ -13,18 +13,18 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Post extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; - @ManyToOne - private User user; + @ManyToOne + private User user; - @Column(length = 25, nullable = false) - private String title; + @Column(length = 25, nullable = false) + private String title; - @Column(length = 5000, nullable = false) - private String content; + @Column(length = 5000, nullable = false) + private String content; @Builder private Post(String title, String content) { @@ -32,9 +32,9 @@ private Post(String title, String content) { this.content = content; } - public void update(String title, String content) { - this.title = title; - this.content = content; - } + public void update(String title, String content) { + this.title = title; + this.content = content; + } } diff --git a/src/main/java/dev/jpaboard/post/dto/PostResponse.java b/src/main/java/dev/jpaboard/post/dto/PostResponse.java index 332b33b7f..63e0e6dc2 100644 --- a/src/main/java/dev/jpaboard/post/dto/PostResponse.java +++ b/src/main/java/dev/jpaboard/post/dto/PostResponse.java @@ -6,11 +6,11 @@ @Builder public record PostResponse(String title, String content) { - public static PostResponse toDto(Post post) { - return PostResponse.builder() - .title(post.getTitle()) - .content(post.getContent()) - .build(); - } + public static PostResponse from(Post post) { + return PostResponse.builder() + .title(post.getTitle()) + .content(post.getContent()) + .build(); + } } diff --git a/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java b/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java index 697703865..ca4f4d200 100644 --- a/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java +++ b/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java @@ -1,10 +1,10 @@ package dev.jpaboard.post.exception; public class PostNotFoundException extends RuntimeException { - private static final String MESSAGE = "게시글을 찾을 수 없습니다."; + private static final String MESSAGE = "게시글을 찾을 수 없습니다."; - public PostNotFoundException() { - super(MESSAGE); - } + public PostNotFoundException() { + super(MESSAGE); + } } From c345ef0e27833b6ae9038cfc523bd2c2ef6e22f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 16:08:12 +0900 Subject: [PATCH 15/47] =?UTF-8?q?refactor:=20PostController=EC=99=80=20Pos?= =?UTF-8?q?tService=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/post/api/PostController.java | 73 +++++++++---------- .../post/application/PostService.java | 51 ++++++------- .../jpaboard/post/dto/PostCreateRequest.java | 3 +- .../dev/jpaboard/post/dto/PostsResponse.java | 15 ++++ .../post/repository/PostRepository.java | 4 - 5 files changed, 76 insertions(+), 70 deletions(-) create mode 100644 src/main/java/dev/jpaboard/post/dto/PostsResponse.java diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java index 25ceb0608..0e445ebc7 100644 --- a/src/main/java/dev/jpaboard/post/api/PostController.java +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -4,10 +4,8 @@ import dev.jpaboard.post.dto.PostCreateRequest; import dev.jpaboard.post.dto.PostResponse; import dev.jpaboard.post.dto.PostUpdateRequest; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpSession; +import dev.jpaboard.post.dto.PostsResponse; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.HttpStatus; @@ -18,43 +16,38 @@ @RequiredArgsConstructor public class PostController { - private final PostService postService; - - @PostMapping("/posts") - @ResponseStatus(HttpStatus.CREATED) - public PostResponse create(PostCreateRequest request) { - return postService.create(request); - } - - @PatchMapping("/posts/{id}") - @ResponseStatus(HttpStatus.OK) - public PostResponse update(@PathVariable Long id, PostUpdateRequest request) { - return postService.update(request, id); - } - - @GetMapping("/posts/{id}") - @ResponseStatus(HttpStatus.OK) - public PostResponse findPost(@PathVariable Long id) { - return postService.findPost(id); - } - - @GetMapping("/posts/{userId}") - @ResponseStatus(HttpStatus.OK) - public Page findPostByUser(@PathVariable Long userId, @PageableDefault(sort = "createdAt", direction = DESC) Pageable pageable) { - return postService.findPostByUser(userId, pageable); - } - - @GetMapping("/posts") - @ResponseStatus(HttpStatus.OK) - public Page findSlicePost(@PageableDefault(sort = "createdAt", direction = DESC) Pageable pageable) { - return postService.findAll(pageable); - } - - @DeleteMapping("/posts/{id}") - @ResponseStatus(HttpStatus.OK) - public void delete(@PathVariable Long id) { - postService.delete(id); - } + private final PostService postService; + + @PostMapping("/posts") + @ResponseStatus(CREATED) + public PostResponse create(@RequestBody PostCreateRequest request, + @SessionAttribute(name = "userId", required = false) Long userId) { + return postService.create(request, userId); + } + + @GetMapping("/posts/{id}") + public PostResponse findPost(@PathVariable Long id) { + return postService.findPost(id); + } + + @GetMapping("/posts") + public PostsResponse findSlicePosts(@PageableDefault(sort = "createdAt", direction = DESC) Pageable pageable) { + return postService.findAll(pageable); + } + + @PatchMapping("/posts/{id}") + @ResponseStatus(NO_CONTENT) + public void update(@PathVariable("id") Long postId, + @RequestBody PostUpdateRequest request, + @SessionAttribute(name = "userId", required = false) Long userId) { + postService.update(postId, request, userId); + } + + @DeleteMapping("/posts/{id}") + public void delete(@PathVariable("id") Long postId, + @SessionAttribute(name = "userId", required = false) Long userId) { + postService.delete(postId, userId); + } @DeleteMapping("/posts") @ResponseStatus(HttpStatus.OK) diff --git a/src/main/java/dev/jpaboard/post/application/PostService.java b/src/main/java/dev/jpaboard/post/application/PostService.java index e400b64b4..0dfbbb8f9 100644 --- a/src/main/java/dev/jpaboard/post/application/PostService.java +++ b/src/main/java/dev/jpaboard/post/application/PostService.java @@ -2,10 +2,10 @@ import dev.jpaboard.post.domain.Post; import dev.jpaboard.post.dto.PostCreateRequest; +import dev.jpaboard.post.dto.PostResponse; import dev.jpaboard.post.dto.PostUpdateRequest; import dev.jpaboard.post.exception.PostNotFoundException; import dev.jpaboard.post.repository.PostRepository; -import dev.jpaboard.post.dto.PostResponse; import dev.jpaboard.user.domain.User; import dev.jpaboard.user.exception.UserNotFoundException; import dev.jpaboard.user.repository.UserRepository; @@ -29,34 +29,35 @@ public PostResponse create(PostCreateRequest request) { return PostResponse.toDto(savedPost); } - @Transactional - public PostResponse update(PostUpdateRequest request, Long postId) { - Post post = postRepository.findById(postId) - .orElseThrow(PostNotFoundException::new); - post.update(request.title(), request.content()); - return PostResponse.toDto(post); - } + @Transactional + public void update(Long postId, PostUpdateRequest request, Long userId) { + Post post = findPostById(postId); + User user = findUserById(userId); - public PostResponse findPost(Long id) { - Post post = postRepository.findById(id) - .orElseThrow(PostNotFoundException::new); - return PostResponse.toDto(post); - } + post.checkAuthorize(user); + post.update(request.title(), request.content()); + } - public Page findAll(Pageable pageable) { - Page postPage = postRepository.findAll(pageable); - return postPage.map(PostResponse::toDto); - } + public PostResponse findPost(Long id) { + Post post = findPostById(id); - public Page findPostByUser(Long userId, Pageable pageable) { - Page postPage = postRepository.findPostByUserId(userId, pageable); - return postPage.map(PostResponse::toDto); - } + return PostResponse.from(post); + } - @Transactional - public void delete(Long id) { - postRepository.deleteById(id); - } + public PostsResponse findAll(Pageable pageable) { + Page postPage = postRepository.findAll(pageable); + + return PostsResponse.from(postPage); + } + + @Transactional + public void delete(Long postId, Long userId) { + Post post = findPostById(postId); + User user = findUserById(userId); + + post.checkAuthorize(user); + postRepository.deleteById(postId); + } } diff --git a/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java b/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java index 0b9695edd..3b1b939b0 100644 --- a/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java +++ b/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java @@ -4,8 +4,9 @@ public record PostCreateRequest(String title, String content) { - public static Post toPost(PostCreateRequest request) { + public static Post toPost(PostCreateRequest request, User user) { return Post.builder() + .user(user) .title(request.title) .content(request.content()) .build(); diff --git a/src/main/java/dev/jpaboard/post/dto/PostsResponse.java b/src/main/java/dev/jpaboard/post/dto/PostsResponse.java new file mode 100644 index 000000000..2804590d1 --- /dev/null +++ b/src/main/java/dev/jpaboard/post/dto/PostsResponse.java @@ -0,0 +1,15 @@ +package dev.jpaboard.post.dto; + +import dev.jpaboard.post.domain.Post; +import org.springframework.data.domain.Page; + +import java.util.List; + +public record PostsResponse(List postResponse, int totalPages, int currentPage) { + + public static PostsResponse from(Page postPage) { + return new PostsResponse(postPage.getContent().stream() + .map(PostResponse::from) + .toList(), postPage.getTotalPages(), postPage.getNumber()); + } +} diff --git a/src/main/java/dev/jpaboard/post/repository/PostRepository.java b/src/main/java/dev/jpaboard/post/repository/PostRepository.java index b3491281f..dde72d53c 100644 --- a/src/main/java/dev/jpaboard/post/repository/PostRepository.java +++ b/src/main/java/dev/jpaboard/post/repository/PostRepository.java @@ -1,12 +1,8 @@ package dev.jpaboard.post.repository; import dev.jpaboard.post.domain.Post; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; public interface PostRepository extends JpaRepository { - Page findPostByUserId(Long userId, Pageable pageable); - } From cb8b9887f7a670485f1ba8997f3d93a86627fc6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 16:43:57 +0900 Subject: [PATCH 16/47] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EC=8A=A4?= =?UTF-8?q?=ED=83=80=EC=9D=BC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpaboard/common/entity/BaseEntity.java | 4 +- .../user/application/UserService.java | 22 +++--- .../java/dev/jpaboard/user/domain/User.java | 76 +++++++++++-------- .../user/dto/response/UserResponse.java | 18 ++--- .../user/repository/UserRepository.java | 2 + 5 files changed, 70 insertions(+), 52 deletions(-) diff --git a/src/main/java/dev/jpaboard/common/entity/BaseEntity.java b/src/main/java/dev/jpaboard/common/entity/BaseEntity.java index d24d24225..ff5746f15 100644 --- a/src/main/java/dev/jpaboard/common/entity/BaseEntity.java +++ b/src/main/java/dev/jpaboard/common/entity/BaseEntity.java @@ -17,7 +17,7 @@ public abstract class BaseEntity { @CreatedDate private LocalDateTime createdAt; - @LastModifiedDate - private LocalDateTime updatedAt; + @LastModifiedDate + private LocalDateTime updatedAt; } diff --git a/src/main/java/dev/jpaboard/user/application/UserService.java b/src/main/java/dev/jpaboard/user/application/UserService.java index 0105b443e..071bff751 100644 --- a/src/main/java/dev/jpaboard/user/application/UserService.java +++ b/src/main/java/dev/jpaboard/user/application/UserService.java @@ -16,14 +16,14 @@ @RequiredArgsConstructor public class UserService { - private final UserRepository userRepository; + private final UserRepository userRepository; - @Transactional - public UserResponse signUp(UserCreateRequest request) { - User user = UserCreateRequest.toUser(request); - User savedUser = userRepository.save(user); - return UserResponse.toDto(savedUser); - } + @Transactional + public UserResponse signUp(UserCreateRequest request) { + User user = UserCreateRequest.toUser(request); + User savedUser = userRepository.save(user); + return UserResponse.toDto(savedUser); + } public Long login(UserLoginRequest request) { User user = userRepository.findByEmailAndPassword(request.email(), request.password()) @@ -45,9 +45,9 @@ public UserResponse findUser(Long id) { return UserResponse.toDto(user); } - @Transactional - public void delete(Long id) { - userRepository.deleteById(id); - } + @Transactional + public void delete(Long id) { + userRepository.deleteById(id); + } } diff --git a/src/main/java/dev/jpaboard/user/domain/User.java b/src/main/java/dev/jpaboard/user/domain/User.java index 74cd937d0..8c523b920 100644 --- a/src/main/java/dev/jpaboard/user/domain/User.java +++ b/src/main/java/dev/jpaboard/user/domain/User.java @@ -5,48 +5,64 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Pattern; -import lombok.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.Objects; @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class User extends BaseEntity { - private static final String EMAIL_REGEX = "^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$"; - private static final String PASSWORD_REGEX = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*\\W).{8,20}$"; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; + private static final String EMAIL_REGEX = "^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$"; + private static final String PASSWORD_REGEX = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*\\W).{8,20}$"; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @Column(length = 25, nullable = false) + @Email(regexp = EMAIL_REGEX) + private String email; - @Column(length = 25, nullable = false) - @Email(regexp = EMAIL_REGEX) - private String email; + @Column(length = 20, nullable = false) + @Pattern(regexp = PASSWORD_REGEX) + private String password; - @Column(length = 20, nullable = false) - @Pattern(regexp = PASSWORD_REGEX) - private String password; + @Column(length = 5, nullable = false) + private String name; - @Column(length = 5, nullable = false) - private String name; + @Column(length = 3, nullable = false) + private int age; - @Column(length = 3, nullable = false) - private int age; + @Column(length = 20) + private String hobby; - @Column(length = 20) - private String hobby; + @Builder + private User(@Valid String email, @Valid String password, String name, int age, String hobby) { + this.email = email; + this.password = password; + this.name = name; + this.age = age; + this.hobby = hobby; + } - @Builder - private User(@Valid String email, @Valid String password, String name, int age, String hobby) { - this.email = email; - this.password = password; - this.name = name; - this.age = age; - this.hobby = hobby; - } + public void update(String name, String hobby) { + this.name = name; + this.hobby = hobby; + } - public void update(String name, String hobby) { - this.name = name; - this.hobby = hobby; - } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof User user)) return false; + return id == user.id; + } + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java b/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java index 9463dcfe1..6f9a02c7f 100644 --- a/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java +++ b/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java @@ -6,14 +6,14 @@ @Builder public record UserResponse(Long id, String email, String name, int age, String hobby) { - public static UserResponse toDto(User user) { - return UserResponse.builder() - .id(user.getId()) - .email(user.getEmail()) - .name(user.getName()) - .age(user.getAge()) - .hobby(user.getHobby()) - .build(); - } + public static UserResponse toDto(User user) { + return UserResponse.builder() + .id(user.getId()) + .email(user.getEmail()) + .name(user.getName()) + .age(user.getAge()) + .hobby(user.getHobby()) + .build(); + } } diff --git a/src/main/java/dev/jpaboard/user/repository/UserRepository.java b/src/main/java/dev/jpaboard/user/repository/UserRepository.java index 892da7492..e1a609759 100644 --- a/src/main/java/dev/jpaboard/user/repository/UserRepository.java +++ b/src/main/java/dev/jpaboard/user/repository/UserRepository.java @@ -6,5 +6,7 @@ import java.util.Optional; public interface UserRepository extends JpaRepository { + Optional findByEmailAndPassword(String email, String password); + } From 68222646a0f34adef873d7f1878a20067d2c3851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 16:45:45 +0900 Subject: [PATCH 17/47] =?UTF-8?q?refactor:=20UserController=EC=99=80=20Use?= =?UTF-8?q?rService=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UnauthorizedAccessException.java | 11 ++++ .../dev/jpaboard/user/api/UserController.java | 62 +++++++++---------- .../user/application/UserService.java | 26 ++++---- 3 files changed, 53 insertions(+), 46 deletions(-) create mode 100644 src/main/java/dev/jpaboard/common/exception/UnauthorizedAccessException.java diff --git a/src/main/java/dev/jpaboard/common/exception/UnauthorizedAccessException.java b/src/main/java/dev/jpaboard/common/exception/UnauthorizedAccessException.java new file mode 100644 index 000000000..f89d22494 --- /dev/null +++ b/src/main/java/dev/jpaboard/common/exception/UnauthorizedAccessException.java @@ -0,0 +1,11 @@ +package dev.jpaboard.common.exception; + +public class UnauthorizedAccessException extends RuntimeException { + + private static final String MESSAGE = "권한이 없습니다."; + + public UnauthorizedAccessException() { + super(MESSAGE); + } + +} diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index e88ebf27c..540d4f487 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -1,14 +1,13 @@ package dev.jpaboard.user.api; -import dev.jpaboard.user.dto.response.UserResponse; import dev.jpaboard.user.application.UserService; import dev.jpaboard.user.dto.request.UserCreateRequest; import dev.jpaboard.user.dto.request.UserLoginRequest; import dev.jpaboard.user.dto.request.UserUpdateRequest; +import dev.jpaboard.user.dto.response.UserResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @RestController @@ -16,42 +15,41 @@ @RequiredArgsConstructor public class UserController { - private final UserService userService; + private final UserService userService; - @PostMapping("/users") - @ResponseStatus(HttpStatus.CREATED) - public UserResponse signUp(@RequestBody UserCreateRequest request) { - return userService.signUp(request); - } + @PostMapping("/users") + @ResponseStatus(OK) + public void signUp(@RequestBody UserCreateRequest request) { + userService.signUp(request); + } - @PostMapping("/users/login") - @ResponseStatus(HttpStatus.OK) - public Long login(@RequestBody UserLoginRequest request, HttpServletRequest httpRequest) { - httpRequest.getSession().invalidate(); - HttpSession session = httpRequest.getSession(true); + @PostMapping("/users/login") + @ResponseStatus(OK) + public Long login(@RequestBody UserLoginRequest request, HttpServletRequest httpRequest) { + httpRequest.getSession().invalidate(); + HttpSession session = httpRequest.getSession(true); - Long userId = userService.login(request); - session.setAttribute("userId", userId); - session.setMaxInactiveInterval(3600); - return userId; - } + Long userId = userService.login(request); + session.setAttribute("userId", userId); + session.setMaxInactiveInterval(3600); + return userId; + } - @GetMapping("/user/logout") - @ResponseStatus(HttpStatus.OK) - public String logout(HttpServletRequest httpRequest) { - HttpSession session = httpRequest.getSession(false); - if (session != null) { - session.invalidate(); + @GetMapping("/user/logout") + @ResponseStatus(NO_CONTENT) + public void logout(HttpServletRequest httpRequest) { + HttpSession session = httpRequest.getSession(false); + if (Objects.nonNull(session)) { + session.invalidate(); + } } - return "redirect:/api/users"; - } - @PatchMapping("/users/update") - @ResponseStatus(HttpStatus.OK) - public UserResponse update(UserUpdateRequest userUpdateRequest, HttpServletRequest request) { - HttpSession session = request.getSession(false); - return userService.update(userUpdateRequest, (Long) session.getAttribute("userId")); - } + @PatchMapping("/users/update") + @ResponseStatus(NO_CONTENT) + public void update(@RequestBody UserUpdateRequest request, + @SessionAttribute(name = "userId", required = false) Long userId) { + userService.update(request, userId); + } @GetMapping("/users/me") public UserResponse findUser(HttpServletRequest httpRequest) { diff --git a/src/main/java/dev/jpaboard/user/application/UserService.java b/src/main/java/dev/jpaboard/user/application/UserService.java index 071bff751..38fc76943 100644 --- a/src/main/java/dev/jpaboard/user/application/UserService.java +++ b/src/main/java/dev/jpaboard/user/application/UserService.java @@ -1,10 +1,10 @@ package dev.jpaboard.user.application; -import dev.jpaboard.user.dto.request.UserCreateRequest; import dev.jpaboard.user.domain.User; +import dev.jpaboard.user.dto.request.UserCreateRequest; import dev.jpaboard.user.dto.request.UserLoginRequest; -import dev.jpaboard.user.dto.response.UserResponse; import dev.jpaboard.user.dto.request.UserUpdateRequest; +import dev.jpaboard.user.dto.response.UserResponse; import dev.jpaboard.user.exception.UserNotFoundException; import dev.jpaboard.user.repository.UserRepository; import lombok.RequiredArgsConstructor; @@ -25,19 +25,17 @@ public UserResponse signUp(UserCreateRequest request) { return UserResponse.toDto(savedUser); } - public Long login(UserLoginRequest request) { - User user = userRepository.findByEmailAndPassword(request.email(), request.password()) - .orElseThrow(UserNotFoundException::new); - return user.getId(); - } + public Long login(UserLoginRequest request) { + User user = findByEmailAndPassword(request.email(), request.password()); + return user.getId(); + } - @Transactional - public UserResponse update(UserUpdateRequest request, Long userId) { - User user = userRepository.findById(userId) - .orElseThrow(UserNotFoundException::new); - user.update(request.name(), request.hobby()); - return UserResponse.toDto(user); - } + @Transactional + public UserResponse update(UserUpdateRequest request, Long userId) { + User user = findUserById(userId); + user.update(request.name(), request.hobby()); + return UserResponse.toDto(user); + } public UserResponse findUser(Long id) { User user = userRepository.findById(id) From 8e9843df13c0e9c00936c126d8213f9d3d16b88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 17:03:32 +0900 Subject: [PATCH 18/47] =?UTF-8?q?refactor:=20Post=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpaboard/common/entity/BaseEntity.java | 6 ++-- .../dev/jpaboard/post/api/PostController.java | 31 ++++++++--------- .../post/application/PostService.java | 28 ++++++++++++---- .../java/dev/jpaboard/post/domain/Post.java | 33 +++++++++++++++---- .../jpaboard/post/dto/PostCreateRequest.java | 1 + 5 files changed, 67 insertions(+), 32 deletions(-) diff --git a/src/main/java/dev/jpaboard/common/entity/BaseEntity.java b/src/main/java/dev/jpaboard/common/entity/BaseEntity.java index ff5746f15..d94778425 100644 --- a/src/main/java/dev/jpaboard/common/entity/BaseEntity.java +++ b/src/main/java/dev/jpaboard/common/entity/BaseEntity.java @@ -1,5 +1,6 @@ package dev.jpaboard.common.entity; +import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; import lombok.Getter; @@ -14,8 +15,9 @@ @EntityListeners(AuditingEntityListener.class) public abstract class BaseEntity { - @CreatedDate - private LocalDateTime createdAt; + @CreatedDate + @Column(updatable = false) + private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java index 0e445ebc7..8072717b7 100644 --- a/src/main/java/dev/jpaboard/post/api/PostController.java +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -8,34 +8,37 @@ import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; -import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import static org.springframework.data.domain.Sort.Direction.DESC; +import static org.springframework.http.HttpStatus.CREATED; +import static org.springframework.http.HttpStatus.NO_CONTENT; + @RestController -@RequestMapping("/api") +@RequestMapping("/api/posts") @RequiredArgsConstructor public class PostController { private final PostService postService; - @PostMapping("/posts") + @PostMapping() @ResponseStatus(CREATED) public PostResponse create(@RequestBody PostCreateRequest request, @SessionAttribute(name = "userId", required = false) Long userId) { return postService.create(request, userId); } - @GetMapping("/posts/{id}") - public PostResponse findPost(@PathVariable Long id) { - return postService.findPost(id); - } - - @GetMapping("/posts") + @GetMapping() public PostsResponse findSlicePosts(@PageableDefault(sort = "createdAt", direction = DESC) Pageable pageable) { return postService.findAll(pageable); } - @PatchMapping("/posts/{id}") + @GetMapping("/{id}") + public PostResponse findPost(@PathVariable Long id) { + return postService.findPost(id); + } + + @PatchMapping("/{id}") @ResponseStatus(NO_CONTENT) public void update(@PathVariable("id") Long postId, @RequestBody PostUpdateRequest request, @@ -43,16 +46,10 @@ public void update(@PathVariable("id") Long postId, postService.update(postId, request, userId); } - @DeleteMapping("/posts/{id}") + @DeleteMapping("/{id}") public void delete(@PathVariable("id") Long postId, @SessionAttribute(name = "userId", required = false) Long userId) { postService.delete(postId, userId); } - @DeleteMapping("/posts") - @ResponseStatus(HttpStatus.OK) - public void deleteAll() { - postService.deleteAll(); - } - } diff --git a/src/main/java/dev/jpaboard/post/application/PostService.java b/src/main/java/dev/jpaboard/post/application/PostService.java index 0dfbbb8f9..2bbc5e738 100644 --- a/src/main/java/dev/jpaboard/post/application/PostService.java +++ b/src/main/java/dev/jpaboard/post/application/PostService.java @@ -4,6 +4,7 @@ import dev.jpaboard.post.dto.PostCreateRequest; import dev.jpaboard.post.dto.PostResponse; import dev.jpaboard.post.dto.PostUpdateRequest; +import dev.jpaboard.post.dto.PostsResponse; import dev.jpaboard.post.exception.PostNotFoundException; import dev.jpaboard.post.repository.PostRepository; import dev.jpaboard.user.domain.User; @@ -15,19 +16,23 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + @Service @Transactional(readOnly = true) @RequiredArgsConstructor public class PostService { - private final PostRepository postRepository; + private final PostRepository postRepository; + private final UserRepository userRepository; + + @Transactional + public PostResponse create(PostCreateRequest request, Long userId) { + User user = findUserById(userId); - @Transactional - public PostResponse create(PostCreateRequest request) { - Post post = PostCreateRequest.toPost(request); - Post savedPost = postRepository.save(post); - return PostResponse.toDto(savedPost); - } + Post post = PostCreateRequest.toPost(request, user); + Post savedPost = postRepository.save(post); + return PostResponse.from(savedPost); + } @Transactional public void update(Long postId, PostUpdateRequest request, Long userId) { @@ -59,5 +64,14 @@ public void delete(Long postId, Long userId) { postRepository.deleteById(postId); } + private Post findPostById(Long postId) { + return postRepository.findById(postId) + .orElseThrow(PostNotFoundException::new); + } + + private User findUserById(Long userId) { + return userRepository.findById(userId) + .orElseThrow(UserNotFoundException::new); + } } diff --git a/src/main/java/dev/jpaboard/post/domain/Post.java b/src/main/java/dev/jpaboard/post/domain/Post.java index e09823ec9..7f804c808 100644 --- a/src/main/java/dev/jpaboard/post/domain/Post.java +++ b/src/main/java/dev/jpaboard/post/domain/Post.java @@ -1,6 +1,7 @@ package dev.jpaboard.post.domain; import dev.jpaboard.common.entity.BaseEntity; +import dev.jpaboard.common.exception.UnauthorizedAccessException; import dev.jpaboard.user.domain.User; import jakarta.persistence.*; import lombok.AccessLevel; @@ -8,6 +9,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.Objects; + @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -15,7 +18,7 @@ public class Post extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; + private Long id; @ManyToOne private User user; @@ -26,15 +29,33 @@ public class Post extends BaseEntity { @Column(length = 5000, nullable = false) private String content; - @Builder - private Post(String title, String content) { - this.title = title; - this.content = content; - } + @Builder + private Post(User user, String title, String content) { + this.user = user; + this.title = title; + this.content = content; + } + + public void checkAuthorize(User user) { + if (!this.user.equals(user)) { + throw new UnauthorizedAccessException(); + } + } public void update(String title, String content) { this.title = title; this.content = content; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Post post)) return false; + return id.equals(post.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java b/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java index 3b1b939b0..c683b6a05 100644 --- a/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java +++ b/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java @@ -1,6 +1,7 @@ package dev.jpaboard.post.dto; import dev.jpaboard.post.domain.Post; +import dev.jpaboard.user.domain.User; public record PostCreateRequest(String title, String content) { From 26607e8b86fc1ff2cca2ef3d2a851c288e45cc6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 17:04:18 +0900 Subject: [PATCH 19/47] =?UTF-8?q?refactor:=20User=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/user/api/UserController.java | 34 +++++++++++-------- .../user/application/UserService.java | 23 +++++++++---- .../java/dev/jpaboard/user/domain/User.java | 3 +- .../user/dto/response/UserResponse.java | 2 +- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index 540d4f487..4e4d472a7 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -10,20 +10,25 @@ import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import java.util.Objects; + +import static org.springframework.http.HttpStatus.NO_CONTENT; +import static org.springframework.http.HttpStatus.OK; + @RestController -@RequestMapping("/api") +@RequestMapping("/api/users") @RequiredArgsConstructor public class UserController { private final UserService userService; - @PostMapping("/users") + @PostMapping("/sing-up") @ResponseStatus(OK) public void signUp(@RequestBody UserCreateRequest request) { userService.signUp(request); } - @PostMapping("/users/login") + @PostMapping("/login") @ResponseStatus(OK) public Long login(@RequestBody UserLoginRequest request, HttpServletRequest httpRequest) { httpRequest.getSession().invalidate(); @@ -35,7 +40,7 @@ public Long login(@RequestBody UserLoginRequest request, HttpServletRequest http return userId; } - @GetMapping("/user/logout") + @GetMapping("/logout") @ResponseStatus(NO_CONTENT) public void logout(HttpServletRequest httpRequest) { HttpSession session = httpRequest.getSession(false); @@ -44,23 +49,22 @@ public void logout(HttpServletRequest httpRequest) { } } - @PatchMapping("/users/update") + @PatchMapping("/update") @ResponseStatus(NO_CONTENT) public void update(@RequestBody UserUpdateRequest request, @SessionAttribute(name = "userId", required = false) Long userId) { userService.update(request, userId); } - @GetMapping("/users/me") - public UserResponse findUser(HttpServletRequest httpRequest) { - HttpSession session = httpRequest.getSession(false); - Long id = (Long) session.getAttribute("userId"); - return userService.findUser(id); - } + @GetMapping("/me") + public UserResponse findUser(@SessionAttribute(name = "userId", required = false) Long userId) { - @DeleteMapping("/users/{id}") - public void delete(@PathVariable Long id) { - userService.delete(id); - } + return userService.findUser(userId); + } + + @DeleteMapping("/me") + public void delete(@SessionAttribute(name = "userId", required = false) Long userId) { + userService.delete(userId); + } } diff --git a/src/main/java/dev/jpaboard/user/application/UserService.java b/src/main/java/dev/jpaboard/user/application/UserService.java index 38fc76943..6db1a59d9 100644 --- a/src/main/java/dev/jpaboard/user/application/UserService.java +++ b/src/main/java/dev/jpaboard/user/application/UserService.java @@ -22,7 +22,7 @@ public class UserService { public UserResponse signUp(UserCreateRequest request) { User user = UserCreateRequest.toUser(request); User savedUser = userRepository.save(user); - return UserResponse.toDto(savedUser); + return UserResponse.from(savedUser); } public Long login(UserLoginRequest request) { @@ -34,18 +34,27 @@ public Long login(UserLoginRequest request) { public UserResponse update(UserUpdateRequest request, Long userId) { User user = findUserById(userId); user.update(request.name(), request.hobby()); - return UserResponse.toDto(user); + return UserResponse.from(user); } - public UserResponse findUser(Long id) { - User user = userRepository.findById(id) - .orElseThrow(UserNotFoundException::new); - return UserResponse.toDto(user); - } + public UserResponse findUser(Long userId) { + User user = findUserById(userId); + return UserResponse.from(user); + } @Transactional public void delete(Long id) { userRepository.deleteById(id); } + private User findUserById(Long userId) { + return userRepository.findById(userId) + .orElseThrow(UserNotFoundException::new); + } + + private User findByEmailAndPassword(String email, String password) { + return userRepository.findByEmailAndPassword(email, password) + .orElseThrow(UserNotFoundException::new); + } + } diff --git a/src/main/java/dev/jpaboard/user/domain/User.java b/src/main/java/dev/jpaboard/user/domain/User.java index 8c523b920..5318e300f 100644 --- a/src/main/java/dev/jpaboard/user/domain/User.java +++ b/src/main/java/dev/jpaboard/user/domain/User.java @@ -14,6 +14,7 @@ @Entity @Getter +@Table(name = "users") @NoArgsConstructor(access = AccessLevel.PROTECTED) public class User extends BaseEntity { @@ -21,7 +22,7 @@ public class User extends BaseEntity { private static final String PASSWORD_REGEX = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*\\W).{8,20}$"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; + private Long id; @Column(length = 25, nullable = false) @Email(regexp = EMAIL_REGEX) diff --git a/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java b/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java index 6f9a02c7f..2212f9b75 100644 --- a/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java +++ b/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java @@ -6,7 +6,7 @@ @Builder public record UserResponse(Long id, String email, String name, int age, String hobby) { - public static UserResponse toDto(User user) { + public static UserResponse from(User user) { return UserResponse.builder() .id(user.getId()) .email(user.getEmail()) From 459c3cd7bc5a82b00089083180fa01c8798abf5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 17:05:44 +0900 Subject: [PATCH 20/47] =?UTF-8?q?chore:=20=EB=A1=9C=EC=BB=AC=EA=B3=BC=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=EB=B2=A0=EC=9D=B4=EC=8A=A4=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 14 +++++++++++++- src/test/resources/application.yml | 13 +++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/application.yml diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8b1378917..187a59d6c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1 +1,13 @@ - +spring: + datasource: + url: jdbc:mysql://localhost:3307/jpa?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Seoul + username: jpa + password: 1234 + driver-class-name: com.mysql.cj.jdbc.Driver + jpa: + hibernate: + ddl-auto: none + properties: + hibernate: + format_sql: true + show-sql: true \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 000000000..3946202e7 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,13 @@ +spring: + datasource: + url: jdbc:h2:mem:testdb;MODE=MYSQL + username: sa + password: + driver-class-name: org.h2.Driver + jpa: + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true + show-sql: true \ No newline at end of file From 91cdd4e6e52dfa25bc69db6d9f7f93ef3c92ada6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 17:08:02 +0900 Subject: [PATCH 21/47] =?UTF-8?q?chore:=20rest-docs=EC=99=80=20swagger=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build.gradle b/build.gradle index 17278acdb..e4e100cc5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,9 @@ +buildscript { + ext { + restdocsApiSpecVersion = '0.18.2' + } +} + plugins { id 'java' id 'org.springframework.boot' version '3.1.2' @@ -21,6 +27,10 @@ repositories { mavenCentral() } +ext { + snippetsDir = file('build/generated-snippets') +} + dependencies { // spring implementation 'org.springframework.boot:spring-boot-starter-data-jpa' @@ -30,6 +40,8 @@ dependencies { // test testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' + testImplementation 'com.epages:restdocs-api-spec-mockmvc:' + restdocsApiSpecVersion + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' // lombok compileOnly 'org.projectlombok:lombok' From 737197c7aae27908f147a1564dc34a609a27c1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 17:58:54 +0900 Subject: [PATCH 22/47] =?UTF-8?q?refactor:=20ControllerAdvice=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/advice/ControllerAdvice.java | 41 +++++++++++++++++++ .../jpaboard/common/advice/ErrorResponse.java | 4 ++ ...xception.java => AuthorizedException.java} | 4 +- .../common/exception/ForbiddenException.java | 10 +++++ .../common/exception/NotFoundException.java | 8 ++++ .../post/exception/PostNotFoundException.java | 4 +- .../user/exception/UserNotFoundException.java | 4 +- 7 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 src/main/java/dev/jpaboard/common/advice/ControllerAdvice.java create mode 100644 src/main/java/dev/jpaboard/common/advice/ErrorResponse.java rename src/main/java/dev/jpaboard/common/exception/{UnauthorizedAccessException.java => AuthorizedException.java} (56%) create mode 100644 src/main/java/dev/jpaboard/common/exception/ForbiddenException.java create mode 100644 src/main/java/dev/jpaboard/common/exception/NotFoundException.java diff --git a/src/main/java/dev/jpaboard/common/advice/ControllerAdvice.java b/src/main/java/dev/jpaboard/common/advice/ControllerAdvice.java new file mode 100644 index 000000000..8c118292c --- /dev/null +++ b/src/main/java/dev/jpaboard/common/advice/ControllerAdvice.java @@ -0,0 +1,41 @@ +package dev.jpaboard.common.advice; + +import dev.jpaboard.common.exception.AuthorizedException; +import dev.jpaboard.common.exception.ForbiddenException; +import dev.jpaboard.common.exception.NotFoundException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import static org.springframework.http.HttpStatus.*; + +@RestControllerAdvice +public class ControllerAdvice { + + private static final String SERVER_ERROR_MESSAGE = "알 수 없는 문제가 발생했습니다."; + + @ExceptionHandler(NotFoundException.class) + @ResponseStatus(NOT_FOUND) + public ErrorResponse handleNotFoundException(NotFoundException e) { + return new ErrorResponse(e.getMessage()); + } + + @ExceptionHandler(AuthorizedException.class) + @ResponseStatus(UNAUTHORIZED) + public ErrorResponse handleAuthorizedException(AuthorizedException e) { + return new ErrorResponse(e.getMessage()); + } + + @ExceptionHandler(ForbiddenException.class) + @ResponseStatus(FORBIDDEN) + public ErrorResponse handleForbiddenException(ForbiddenException e) { + return new ErrorResponse(e.getMessage()); + } + + @ExceptionHandler(RuntimeException.class) + @ResponseStatus(INTERNAL_SERVER_ERROR) + public ErrorResponse handleRuntimeException() { + return new ErrorResponse(SERVER_ERROR_MESSAGE); + } + +} diff --git a/src/main/java/dev/jpaboard/common/advice/ErrorResponse.java b/src/main/java/dev/jpaboard/common/advice/ErrorResponse.java new file mode 100644 index 000000000..2661fc0d4 --- /dev/null +++ b/src/main/java/dev/jpaboard/common/advice/ErrorResponse.java @@ -0,0 +1,4 @@ +package dev.jpaboard.common.advice; + +public record ErrorResponse(String message) { +} diff --git a/src/main/java/dev/jpaboard/common/exception/UnauthorizedAccessException.java b/src/main/java/dev/jpaboard/common/exception/AuthorizedException.java similarity index 56% rename from src/main/java/dev/jpaboard/common/exception/UnauthorizedAccessException.java rename to src/main/java/dev/jpaboard/common/exception/AuthorizedException.java index f89d22494..3d17fa079 100644 --- a/src/main/java/dev/jpaboard/common/exception/UnauthorizedAccessException.java +++ b/src/main/java/dev/jpaboard/common/exception/AuthorizedException.java @@ -1,10 +1,10 @@ package dev.jpaboard.common.exception; -public class UnauthorizedAccessException extends RuntimeException { +public class AuthorizedException extends RuntimeException { private static final String MESSAGE = "권한이 없습니다."; - public UnauthorizedAccessException() { + public AuthorizedException() { super(MESSAGE); } diff --git a/src/main/java/dev/jpaboard/common/exception/ForbiddenException.java b/src/main/java/dev/jpaboard/common/exception/ForbiddenException.java new file mode 100644 index 000000000..299ec8dc4 --- /dev/null +++ b/src/main/java/dev/jpaboard/common/exception/ForbiddenException.java @@ -0,0 +1,10 @@ +package dev.jpaboard.common.exception; + +public class ForbiddenException extends RuntimeException { + private static final String MESSAGE = "권한이 없습니다."; + + public ForbiddenException() { + super(MESSAGE); + } + +} diff --git a/src/main/java/dev/jpaboard/common/exception/NotFoundException.java b/src/main/java/dev/jpaboard/common/exception/NotFoundException.java new file mode 100644 index 000000000..63b5fcba3 --- /dev/null +++ b/src/main/java/dev/jpaboard/common/exception/NotFoundException.java @@ -0,0 +1,8 @@ +package dev.jpaboard.common.exception; + +public class NotFoundException extends RuntimeException { + public NotFoundException(String message) { + super(message); + } + +} diff --git a/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java b/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java index ca4f4d200..171ce6819 100644 --- a/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java +++ b/src/main/java/dev/jpaboard/post/exception/PostNotFoundException.java @@ -1,6 +1,8 @@ package dev.jpaboard.post.exception; -public class PostNotFoundException extends RuntimeException { +import dev.jpaboard.common.exception.NotFoundException; + +public class PostNotFoundException extends NotFoundException { private static final String MESSAGE = "게시글을 찾을 수 없습니다."; public PostNotFoundException() { diff --git a/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java b/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java index ed42f4a4b..6aae35821 100644 --- a/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java +++ b/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java @@ -1,6 +1,8 @@ package dev.jpaboard.user.exception; -public class UserNotFoundException extends RuntimeException { +import dev.jpaboard.common.exception.NotFoundException; + +public class UserNotFoundException extends NotFoundException { private static final String MESSAGE = "유저를 찾을 수 없습니다."; public UserNotFoundException() { From 5b8b1d1335758c0f2c4ca27b3f17aa7519913c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Wed, 2 Aug 2023 18:01:12 +0900 Subject: [PATCH 23/47] =?UTF-8?q?refactor:=20Null=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/post/api/PostController.java | 12 ++++++++++++ src/main/java/dev/jpaboard/post/domain/Post.java | 4 ++-- .../dev/jpaboard/user/api/UserController.java | 15 ++++++++++++--- src/main/java/dev/jpaboard/user/domain/User.java | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java index 8072717b7..91c4c8707 100644 --- a/src/main/java/dev/jpaboard/post/api/PostController.java +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -1,5 +1,6 @@ package dev.jpaboard.post.api; +import dev.jpaboard.common.exception.AuthorizedException; import dev.jpaboard.post.application.PostService; import dev.jpaboard.post.dto.PostCreateRequest; import dev.jpaboard.post.dto.PostResponse; @@ -10,6 +11,8 @@ import org.springframework.data.web.PageableDefault; import org.springframework.web.bind.annotation.*; +import java.util.Objects; + import static org.springframework.data.domain.Sort.Direction.DESC; import static org.springframework.http.HttpStatus.CREATED; import static org.springframework.http.HttpStatus.NO_CONTENT; @@ -25,6 +28,7 @@ public class PostController { @ResponseStatus(CREATED) public PostResponse create(@RequestBody PostCreateRequest request, @SessionAttribute(name = "userId", required = false) Long userId) { + validateUserId(userId); return postService.create(request, userId); } @@ -43,13 +47,21 @@ public PostResponse findPost(@PathVariable Long id) { public void update(@PathVariable("id") Long postId, @RequestBody PostUpdateRequest request, @SessionAttribute(name = "userId", required = false) Long userId) { + validateUserId(userId); postService.update(postId, request, userId); } @DeleteMapping("/{id}") public void delete(@PathVariable("id") Long postId, @SessionAttribute(name = "userId", required = false) Long userId) { + validateUserId(userId); postService.delete(postId, userId); } + private void validateUserId(Long userId) { + if (Objects.isNull(userId)) { + throw new AuthorizedException(); + } + } + } diff --git a/src/main/java/dev/jpaboard/post/domain/Post.java b/src/main/java/dev/jpaboard/post/domain/Post.java index 7f804c808..05fe9f705 100644 --- a/src/main/java/dev/jpaboard/post/domain/Post.java +++ b/src/main/java/dev/jpaboard/post/domain/Post.java @@ -1,7 +1,7 @@ package dev.jpaboard.post.domain; import dev.jpaboard.common.entity.BaseEntity; -import dev.jpaboard.common.exception.UnauthorizedAccessException; +import dev.jpaboard.common.exception.ForbiddenException; import dev.jpaboard.user.domain.User; import jakarta.persistence.*; import lombok.AccessLevel; @@ -38,7 +38,7 @@ private Post(User user, String title, String content) { public void checkAuthorize(User user) { if (!this.user.equals(user)) { - throw new UnauthorizedAccessException(); + throw new ForbiddenException(); } } diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index 4e4d472a7..77c3c4a21 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -1,5 +1,6 @@ package dev.jpaboard.user.api; +import dev.jpaboard.common.exception.AuthorizedException; import dev.jpaboard.user.application.UserService; import dev.jpaboard.user.dto.request.UserCreateRequest; import dev.jpaboard.user.dto.request.UserLoginRequest; @@ -44,9 +45,10 @@ public Long login(@RequestBody UserLoginRequest request, HttpServletRequest http @ResponseStatus(NO_CONTENT) public void logout(HttpServletRequest httpRequest) { HttpSession session = httpRequest.getSession(false); - if (Objects.nonNull(session)) { - session.invalidate(); + if (Objects.isNull(session)) { + throw new AuthorizedException(); } + session.invalidate(); } @PatchMapping("/update") @@ -58,13 +60,20 @@ public void update(@RequestBody UserUpdateRequest request, @GetMapping("/me") public UserResponse findUser(@SessionAttribute(name = "userId", required = false) Long userId) { - + validateUserId(userId); return userService.findUser(userId); } + @DeleteMapping("/me") public void delete(@SessionAttribute(name = "userId", required = false) Long userId) { userService.delete(userId); } + private void validateUserId(Long userId) { + if (Objects.isNull(userId)) { + throw new AuthorizedException(); + } + } + } diff --git a/src/main/java/dev/jpaboard/user/domain/User.java b/src/main/java/dev/jpaboard/user/domain/User.java index 5318e300f..37c9202eb 100644 --- a/src/main/java/dev/jpaboard/user/domain/User.java +++ b/src/main/java/dev/jpaboard/user/domain/User.java @@ -59,7 +59,7 @@ public void update(String name, String hobby) { public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof User user)) return false; - return id == user.id; + return id.equals(user.id); } @Override From fcee36fed17277e27330c6f66b4cf608acaa4c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Thu, 3 Aug 2023 00:53:23 +0900 Subject: [PATCH 24/47] =?UTF-8?q?test:=20PostController=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/user/api/UserController.java | 2 +- .../java/dev/jpaboard/ControllerTest.java | 36 +++++ .../dev/jpaboard/post/PostControllerTest.java | 152 ++++++++++++++++++ .../post/repository/PostRepositoryTest.java | 56 ------- 4 files changed, 189 insertions(+), 57 deletions(-) create mode 100644 src/test/java/dev/jpaboard/ControllerTest.java create mode 100644 src/test/java/dev/jpaboard/post/PostControllerTest.java delete mode 100644 src/test/java/dev/jpaboard/post/repository/PostRepositoryTest.java diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index 77c3c4a21..169e8fbbc 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -23,7 +23,7 @@ public class UserController { private final UserService userService; - @PostMapping("/sing-up") + @PostMapping("/sign-up") @ResponseStatus(OK) public void signUp(@RequestBody UserCreateRequest request) { userService.signUp(request); diff --git a/src/test/java/dev/jpaboard/ControllerTest.java b/src/test/java/dev/jpaboard/ControllerTest.java new file mode 100644 index 000000000..9856d6e41 --- /dev/null +++ b/src/test/java/dev/jpaboard/ControllerTest.java @@ -0,0 +1,36 @@ +package dev.jpaboard; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.restdocs.RestDocumentationContextProvider; +import org.springframework.restdocs.RestDocumentationExtension; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.filter.CharacterEncodingFilter; + +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; + +@AutoConfigureMockMvc +@AutoConfigureRestDocs +@ExtendWith({RestDocumentationExtension.class}) +public abstract class ControllerTest { + + protected ObjectMapper objectMapper = new ObjectMapper(); + + protected MockMvc mockMvc; + + @BeforeEach + void setUp(WebApplicationContext ctx, RestDocumentationContextProvider restDocumentation) { + mockMvc = MockMvcBuilders.webAppContextSetup(ctx) + .apply(documentationConfiguration(restDocumentation)) + .addFilters(new CharacterEncodingFilter("UTF-8", true)) + .alwaysDo(print()) + .build(); + } + +} diff --git a/src/test/java/dev/jpaboard/post/PostControllerTest.java b/src/test/java/dev/jpaboard/post/PostControllerTest.java new file mode 100644 index 000000000..eca1f6467 --- /dev/null +++ b/src/test/java/dev/jpaboard/post/PostControllerTest.java @@ -0,0 +1,152 @@ +package dev.jpaboard.post; + +import dev.jpaboard.ControllerTest; +import dev.jpaboard.post.api.PostController; +import dev.jpaboard.post.application.PostService; +import dev.jpaboard.post.dto.PostCreateRequest; +import dev.jpaboard.post.dto.PostResponse; +import dev.jpaboard.post.dto.PostUpdateRequest; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockHttpSession; +import org.springframework.restdocs.payload.JsonFieldType; +import org.springframework.test.context.ActiveProfiles; + +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.resourceDetails; +import static com.epages.restdocs.apispec.ResourceDocumentation.headerWithName; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doNothing; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; +import static org.springframework.restdocs.payload.PayloadDocumentation.*; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(PostController.class) +@ActiveProfiles("test") +public class PostControllerTest extends ControllerTest { + + @MockBean + PostService postService; + + @Test + void create() throws Exception { + PostCreateRequest request = new PostCreateRequest("제목", "내용"); + given(postService.create(any(), any())).willReturn(new PostResponse("제목", "내용")); + + MockHttpSession session = new MockHttpSession(); + session.setAttribute("userId", 1L); + + mockMvc.perform(post("/api/posts") + .session(session) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ) + .andDo(print()) + .andDo(document("post-create", + resourceDetails().description("게시물 생성"), + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestHeaders( + headerWithName("JsessionID").description("세션").getAttributes()), + requestFields( + fieldWithPath("title").type(JsonFieldType.STRING) + .description("제목"), + fieldWithPath("content").type(JsonFieldType.STRING) + .description("내용") + ), + responseFields( + fieldWithPath("title").type(JsonFieldType.STRING) + .description("제목"), + fieldWithPath("content").type(JsonFieldType.STRING) + .description("내용") + ) + ) + ).andExpect(status().isCreated()); + } + + @Test + void update() throws Exception { + + PostUpdateRequest request = new PostUpdateRequest("제목", "내용"); + doNothing().when(postService).update(any(), any(), any()); + + MockHttpSession session = new MockHttpSession(); + session.setAttribute("userId", 1L); + + mockMvc.perform(patch("/api/posts/{id}", 1L) + .session(session) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ) + .andDo(print()) + .andDo(document("post-update", + resourceDetails().description("게시물 업데이트"), + pathParameters(parameterWithName("id").description("Post ID")), + requestHeaders( + headerWithName("JsessionID").description("세션").getAttributes() + ), + requestFields( + fieldWithPath("title").type(JsonFieldType.STRING).description("수정할 제목"), + fieldWithPath("content").type(JsonFieldType.STRING).description("수정할 내용") + ) + ) + ).andExpect(status().isNoContent()); + } + + @Test + void deletePost() throws Exception { + doNothing().when(postService).delete(any(), any()); + + MockHttpSession session = new MockHttpSession(); + session.setAttribute("userId", 1L); + + mockMvc.perform(delete("/api/posts/{id}", 1L) + .session(session) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + ) + .andDo(print()) + .andDo(document("post-delete", + resourceDetails().description("게시물 삭제"), + pathParameters(parameterWithName("id").description("Post ID")), + requestHeaders( + headerWithName("JsessionID").description("세션").getAttributes() + ) + ) + ).andExpect(status().isOk()); + + } + + @Test + void findPost() throws Exception { + given(postService.findPost(any())).willReturn(new PostResponse("제목", "내용")); + + mockMvc.perform(get("/api/posts/{id}", 1L) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + ) + .andDo(print()) + .andDo(document("post-find", + resourceDetails().description("게시물 조회"), + pathParameters(parameterWithName("id").description("Post ID")), + responseFields( + fieldWithPath("title").type(JsonFieldType.STRING) + .description("제목"), + fieldWithPath("content").type(JsonFieldType.STRING) + .description("내용") + ) + ) + ).andExpect(status().isOk()); + } + +} diff --git a/src/test/java/dev/jpaboard/post/repository/PostRepositoryTest.java b/src/test/java/dev/jpaboard/post/repository/PostRepositoryTest.java deleted file mode 100644 index 1aa92c6bc..000000000 --- a/src/test/java/dev/jpaboard/post/repository/PostRepositoryTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package dev.jpaboard.post.repository; - -import dev.jpaboard.post.domain.Post; -import dev.jpaboard.user.domain.User; -import dev.jpaboard.user.repository.UserRepository; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; - -import java.util.List; - -@DataJpaTest -class PostRepositoryTest { - - @Autowired - private PostRepository postRepository; - - @Autowired - private UserRepository userRepository; - - @Test - void findPostByUserTest() { - //given - User user = User.builder() - .email("qkrdmswl123@naver.com") - .name("바보은지") - .password("Qkr123@234") - .hobby("박은지 바보") - .age(11) - .build(); - User 박은지 = userRepository.save(user); - Post 박 = createPost("제목1", "내용1", 박은지); - Post 은 = createPost("제목2", "내용2", 박은지); - Post 지 = createPost("제목3", "내용3", 박은지); - - //when - postRepository.saveAll(List.of(박, 은, 지)); - - //then - Page posts = postRepository.findPostByUserId(박은지.getId(), PageRequest.of(0, 1)); - - Assertions.assertThat(posts.getTotalPages()).isEqualTo(3); - } - - Post createPost(String 제목, String 내용, User 유저) { - return Post.builder() - .title(제목) - .content(내용) - .user(유저) - .build(); - } - -} From 4636fa53cf1004c3151f72d44b4e7ffa5dd26807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Thu, 3 Aug 2023 00:54:43 +0900 Subject: [PATCH 25/47] =?UTF-8?q?chore:=20restdocs=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e4e100cc5..79529f3f0 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,9 @@ buildscript { plugins { id 'java' id 'org.springframework.boot' version '3.1.2' - id 'io.spring.dependency-management' version '1.1.2' + id 'io.spring.dependency-management' version '1.1.0' + id 'com.epages.restdocs-api-spec' version "${restdocsApiSpecVersion}" + id 'org.hidetake.swagger.generator' version '2.18.2' } group = 'dev' @@ -49,8 +51,34 @@ dependencies { // database runtimeOnly 'com.mysql:mysql-connector-j' + runtimeOnly 'com.h2database:h2' } tasks.named('test') { useJUnitPlatform() } + +tasks.withType(GenerateSwaggerUI) { + dependsOn 'openapi3' + + delete file('src/main/resources/static/docs/') + copy { + from "build/resources/main/static/docs" + into "src/main/resources/static/docs/" + } +} + +openapi3 { + server = "http://localhost:8080" + title = "JPA Board" + description = "Spring REST Docs with SwaggerUI." + version = "0.0.1" + outputFileNamePrefix = 'jpa-board' + format = 'json' + + outputDirectory = 'build/resources/main/static/docs' +} + +bootJar { + dependsOn(':openapi3') +} \ No newline at end of file From c927d74a44df87cbd729ba5e7d56479b07fe1d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Fri, 4 Aug 2023 16:26:26 +0900 Subject: [PATCH 26/47] =?UTF-8?q?chore:=20build.gradle=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 79529f3f0..c2fc8257f 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ dependencies { // test testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc' - testImplementation 'com.epages:restdocs-api-spec-mockmvc:' + restdocsApiSpecVersion + testImplementation "com.epages:restdocs-api-spec-mockmvc:${restdocsApiSpecVersion}" implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' // lombok From dabc8c40dd4461db9cb4a5d0bd021dd379ec2f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Fri, 4 Aug 2023 16:28:23 +0900 Subject: [PATCH 27/47] =?UTF-8?q?refactor:=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ControllerAdvice.java => ControllerExceptionAdvice.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/dev/jpaboard/common/advice/{ControllerAdvice.java => ControllerExceptionAdvice.java} (97%) diff --git a/src/main/java/dev/jpaboard/common/advice/ControllerAdvice.java b/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java similarity index 97% rename from src/main/java/dev/jpaboard/common/advice/ControllerAdvice.java rename to src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java index 8c118292c..1c6c80a1e 100644 --- a/src/main/java/dev/jpaboard/common/advice/ControllerAdvice.java +++ b/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java @@ -10,7 +10,7 @@ import static org.springframework.http.HttpStatus.*; @RestControllerAdvice -public class ControllerAdvice { +public class ControllerExceptionAdvice { private static final String SERVER_ERROR_MESSAGE = "알 수 없는 문제가 발생했습니다."; From 5ddedbc988282bf1f6ef980319ca79d48bc9cab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Fri, 4 Aug 2023 16:29:58 +0900 Subject: [PATCH 28/47] =?UTF-8?q?refactor:=20PostController=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EA=B4=84=ED=98=B8=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/dev/jpaboard/post/api/PostController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java index 91c4c8707..7d90ef25b 100644 --- a/src/main/java/dev/jpaboard/post/api/PostController.java +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -24,7 +24,7 @@ public class PostController { private final PostService postService; - @PostMapping() + @PostMapping @ResponseStatus(CREATED) public PostResponse create(@RequestBody PostCreateRequest request, @SessionAttribute(name = "userId", required = false) Long userId) { @@ -32,7 +32,7 @@ public PostResponse create(@RequestBody PostCreateRequest request, return postService.create(request, userId); } - @GetMapping() + @GetMapping public PostsResponse findSlicePosts(@PageableDefault(sort = "createdAt", direction = DESC) Pageable pageable) { return postService.findAll(pageable); } From 0f360e12afa915891084813b0471a833cd0861f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Fri, 4 Aug 2023 17:05:20 +0900 Subject: [PATCH 29/47] =?UTF-8?q?refactor:=20Session=EC=9D=98=20userId=20N?= =?UTF-8?q?ull=20=EA=B2=80=EC=A6=9D=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../advice/ControllerExceptionAdvice.java | 10 ++++--- .../dev/jpaboard/post/api/PostController.java | 26 +++++++++---------- .../dev/jpaboard/user/api/UserController.java | 13 +++------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java b/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java index 1c6c80a1e..69f305a03 100644 --- a/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java +++ b/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java @@ -3,11 +3,15 @@ import dev.jpaboard.common.exception.AuthorizedException; import dev.jpaboard.common.exception.ForbiddenException; import dev.jpaboard.common.exception.NotFoundException; +import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; -import static org.springframework.http.HttpStatus.*; +import static org.springframework.http.HttpStatus.FORBIDDEN; +import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import static org.springframework.http.HttpStatus.NOT_FOUND; +import static org.springframework.http.HttpStatus.UNAUTHORIZED; @RestControllerAdvice public class ControllerExceptionAdvice { @@ -20,9 +24,9 @@ public ErrorResponse handleNotFoundException(NotFoundException e) { return new ErrorResponse(e.getMessage()); } - @ExceptionHandler(AuthorizedException.class) + @ExceptionHandler({AuthorizedException.class, ServletRequestBindingException.class}) @ResponseStatus(UNAUTHORIZED) - public ErrorResponse handleAuthorizedException(AuthorizedException e) { + public ErrorResponse handleAuthorizedException(Exception e) { return new ErrorResponse(e.getMessage()); } diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java index 7d90ef25b..d9a5fc6f3 100644 --- a/src/main/java/dev/jpaboard/post/api/PostController.java +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -1,6 +1,5 @@ package dev.jpaboard.post.api; -import dev.jpaboard.common.exception.AuthorizedException; import dev.jpaboard.post.application.PostService; import dev.jpaboard.post.dto.PostCreateRequest; import dev.jpaboard.post.dto.PostResponse; @@ -9,9 +8,16 @@ import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; -import org.springframework.web.bind.annotation.*; - -import java.util.Objects; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +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.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.SessionAttribute; import static org.springframework.data.domain.Sort.Direction.DESC; import static org.springframework.http.HttpStatus.CREATED; @@ -46,22 +52,14 @@ public PostResponse findPost(@PathVariable Long id) { @ResponseStatus(NO_CONTENT) public void update(@PathVariable("id") Long postId, @RequestBody PostUpdateRequest request, - @SessionAttribute(name = "userId", required = false) Long userId) { - validateUserId(userId); + @SessionAttribute(name = "userId") Long userId) { postService.update(postId, request, userId); } @DeleteMapping("/{id}") public void delete(@PathVariable("id") Long postId, - @SessionAttribute(name = "userId", required = false) Long userId) { - validateUserId(userId); + @SessionAttribute(name = "userId") Long userId) { postService.delete(postId, userId); } - private void validateUserId(Long userId) { - if (Objects.isNull(userId)) { - throw new AuthorizedException(); - } - } - } diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index 169e8fbbc..8f63d03e0 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -54,26 +54,19 @@ public void logout(HttpServletRequest httpRequest) { @PatchMapping("/update") @ResponseStatus(NO_CONTENT) public void update(@RequestBody UserUpdateRequest request, - @SessionAttribute(name = "userId", required = false) Long userId) { + @SessionAttribute(name = "userId") Long userId) { userService.update(request, userId); } @GetMapping("/me") - public UserResponse findUser(@SessionAttribute(name = "userId", required = false) Long userId) { - validateUserId(userId); + public UserResponse findUser(@SessionAttribute(name = "userId") Long userId) { return userService.findUser(userId); } @DeleteMapping("/me") - public void delete(@SessionAttribute(name = "userId", required = false) Long userId) { + public void delete(@SessionAttribute(name = "userId") Long userId) { userService.delete(userId); } - private void validateUserId(Long userId) { - if (Objects.isNull(userId)) { - throw new AuthorizedException(); - } - } - } From d5b5ade3e7caf90cd429c4d70b7a0ecf564e12a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Fri, 4 Aug 2023 18:21:06 +0900 Subject: [PATCH 30/47] =?UTF-8?q?refactor:=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/post/application/PostService.java | 6 ++---- src/main/java/dev/jpaboard/post/domain/Post.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/dev/jpaboard/post/application/PostService.java b/src/main/java/dev/jpaboard/post/application/PostService.java index 2bbc5e738..3d8d0b593 100644 --- a/src/main/java/dev/jpaboard/post/application/PostService.java +++ b/src/main/java/dev/jpaboard/post/application/PostService.java @@ -37,9 +37,8 @@ public PostResponse create(PostCreateRequest request, Long userId) { @Transactional public void update(Long postId, PostUpdateRequest request, Long userId) { Post post = findPostById(postId); - User user = findUserById(userId); - post.checkAuthorize(user); + post.checkAuthorize(userId); post.update(request.title(), request.content()); } @@ -58,9 +57,8 @@ public PostsResponse findAll(Pageable pageable) { @Transactional public void delete(Long postId, Long userId) { Post post = findPostById(postId); - User user = findUserById(userId); - post.checkAuthorize(user); + post.checkAuthorize(userId); postRepository.deleteById(postId); } diff --git a/src/main/java/dev/jpaboard/post/domain/Post.java b/src/main/java/dev/jpaboard/post/domain/Post.java index 05fe9f705..2c3843eea 100644 --- a/src/main/java/dev/jpaboard/post/domain/Post.java +++ b/src/main/java/dev/jpaboard/post/domain/Post.java @@ -3,7 +3,12 @@ import dev.jpaboard.common.entity.BaseEntity; import dev.jpaboard.common.exception.ForbiddenException; import dev.jpaboard.user.domain.User; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -36,8 +41,8 @@ private Post(User user, String title, String content) { this.content = content; } - public void checkAuthorize(User user) { - if (!this.user.equals(user)) { + public void checkAuthorize(Long userId) { + if (!Objects.equals(user.getId(), userId)) { throw new ForbiddenException(); } } From d885391c41fff5623a8b154964db4c4b01898abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 00:01:56 +0900 Subject: [PATCH 31/47] =?UTF-8?q?refactor:=20Email,=20Password,=20User=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../advice/ControllerExceptionAdvice.java | 8 +++++ .../common/exception/BadRequestException.java | 9 +++++ .../dev/jpaboard/post/api/PostController.java | 3 +- .../jpaboard/post/dto/PostCreateRequest.java | 20 ++++++----- .../jpaboard/post/dto/PostUpdateRequest.java | 7 +++- .../java/dev/jpaboard/user/domain/Email.java | 32 +++++++++++++++++ .../dev/jpaboard/user/domain/Password.java | 31 +++++++++++++++++ .../java/dev/jpaboard/user/domain/User.java | 34 +++++++++++-------- .../user/dto/request/UserUpdateRequest.java | 5 ++- .../user/dto/response/UserResponse.java | 3 +- .../user/exception/InvalidEmailException.java | 12 +++++++ .../exception/InvalidPasswordException.java | 12 +++++++ .../user/repository/UserRepository.java | 4 ++- 13 files changed, 151 insertions(+), 29 deletions(-) create mode 100644 src/main/java/dev/jpaboard/common/exception/BadRequestException.java create mode 100644 src/main/java/dev/jpaboard/user/domain/Email.java create mode 100644 src/main/java/dev/jpaboard/user/domain/Password.java create mode 100644 src/main/java/dev/jpaboard/user/exception/InvalidEmailException.java create mode 100644 src/main/java/dev/jpaboard/user/exception/InvalidPasswordException.java diff --git a/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java b/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java index 69f305a03..919a13aa5 100644 --- a/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java +++ b/src/main/java/dev/jpaboard/common/advice/ControllerExceptionAdvice.java @@ -1,6 +1,7 @@ package dev.jpaboard.common.advice; import dev.jpaboard.common.exception.AuthorizedException; +import dev.jpaboard.common.exception.BadRequestException; import dev.jpaboard.common.exception.ForbiddenException; import dev.jpaboard.common.exception.NotFoundException; import org.springframework.web.bind.ServletRequestBindingException; @@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; +import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.springframework.http.HttpStatus.NOT_FOUND; @@ -42,4 +44,10 @@ public ErrorResponse handleRuntimeException() { return new ErrorResponse(SERVER_ERROR_MESSAGE); } + @ExceptionHandler(BadRequestException.class) + @ResponseStatus(BAD_REQUEST) + public ErrorResponse handleBadRequestException(BadRequestException e) { + return new ErrorResponse(e.getMessage()); + } + } diff --git a/src/main/java/dev/jpaboard/common/exception/BadRequestException.java b/src/main/java/dev/jpaboard/common/exception/BadRequestException.java new file mode 100644 index 000000000..b3e1801dd --- /dev/null +++ b/src/main/java/dev/jpaboard/common/exception/BadRequestException.java @@ -0,0 +1,9 @@ +package dev.jpaboard.common.exception; + +public class BadRequestException extends RuntimeException { + + public BadRequestException(String message) { + super(message); + } + +} diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java index d9a5fc6f3..9d2528f79 100644 --- a/src/main/java/dev/jpaboard/post/api/PostController.java +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -5,6 +5,7 @@ import dev.jpaboard.post.dto.PostResponse; import dev.jpaboard.post.dto.PostUpdateRequest; import dev.jpaboard.post.dto.PostsResponse; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; @@ -51,7 +52,7 @@ public PostResponse findPost(@PathVariable Long id) { @PatchMapping("/{id}") @ResponseStatus(NO_CONTENT) public void update(@PathVariable("id") Long postId, - @RequestBody PostUpdateRequest request, + @Valid @RequestBody PostUpdateRequest request, @SessionAttribute(name = "userId") Long userId) { postService.update(postId, request, userId); } diff --git a/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java b/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java index c683b6a05..9ff309664 100644 --- a/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java +++ b/src/main/java/dev/jpaboard/post/dto/PostCreateRequest.java @@ -2,15 +2,19 @@ import dev.jpaboard.post.domain.Post; import dev.jpaboard.user.domain.User; +import jakarta.validation.constraints.Size; -public record PostCreateRequest(String title, String content) { +public record PostCreateRequest( + @Size(max = 25) String title, + @Size(max = 5000) String content +) { - public static Post toPost(PostCreateRequest request, User user) { - return Post.builder() - .user(user) - .title(request.title) - .content(request.content()) - .build(); - } + public static Post toPost(PostCreateRequest request, User user) { + return Post.builder() + .user(user) + .title(request.title) + .content(request.content()) + .build(); + } } diff --git a/src/main/java/dev/jpaboard/post/dto/PostUpdateRequest.java b/src/main/java/dev/jpaboard/post/dto/PostUpdateRequest.java index 253ab21e4..cfac4838c 100644 --- a/src/main/java/dev/jpaboard/post/dto/PostUpdateRequest.java +++ b/src/main/java/dev/jpaboard/post/dto/PostUpdateRequest.java @@ -1,4 +1,9 @@ package dev.jpaboard.post.dto; -public record PostUpdateRequest(String title, String content) { +import jakarta.validation.constraints.Size; + +public record PostUpdateRequest( + @Size(max = 25) String title, + @Size(max = 5000) String content +) { } diff --git a/src/main/java/dev/jpaboard/user/domain/Email.java b/src/main/java/dev/jpaboard/user/domain/Email.java new file mode 100644 index 000000000..1bcec9591 --- /dev/null +++ b/src/main/java/dev/jpaboard/user/domain/Email.java @@ -0,0 +1,32 @@ +package dev.jpaboard.user.domain; + +import dev.jpaboard.user.exception.InvalidEmailException; +import jakarta.persistence.Embeddable; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.regex.Pattern; + +@Embeddable +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Email { + + private static final Pattern EMAIL_PATTERN = Pattern.compile("^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$"); + + private String email; + + public Email(String email) { + validateEmail(email); + this.email = email; + } + + private void validateEmail(String userEmail) throws InvalidEmailException { + if (!EMAIL_PATTERN.matcher(userEmail).matches()) { + throw new InvalidEmailException(); + } + } + +} + diff --git a/src/main/java/dev/jpaboard/user/domain/Password.java b/src/main/java/dev/jpaboard/user/domain/Password.java new file mode 100644 index 000000000..f21f5007b --- /dev/null +++ b/src/main/java/dev/jpaboard/user/domain/Password.java @@ -0,0 +1,31 @@ +package dev.jpaboard.user.domain; + +import dev.jpaboard.user.exception.InvalidPasswordException; +import jakarta.persistence.Embeddable; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.regex.Pattern; + +@Embeddable +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Password { + + private static final Pattern PASSWORD_REGEX = Pattern.compile("^(?=.*[a-zA-Z])(?=.*\\d)(?=.*\\W).{8,20}$"); + + private String password; + + public Password(String password) throws InvalidPasswordException { + validatePassword(password); + this.password = password; + } + + private void validatePassword(String userPassword) throws InvalidPasswordException { + if (!PASSWORD_REGEX.matcher(userPassword).matches()) { + throw new InvalidPasswordException(); + } + } + +} diff --git a/src/main/java/dev/jpaboard/user/domain/User.java b/src/main/java/dev/jpaboard/user/domain/User.java index 37c9202eb..57598b763 100644 --- a/src/main/java/dev/jpaboard/user/domain/User.java +++ b/src/main/java/dev/jpaboard/user/domain/User.java @@ -1,10 +1,13 @@ package dev.jpaboard.user.domain; import dev.jpaboard.common.entity.BaseEntity; -import jakarta.persistence.*; -import jakarta.validation.Valid; -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.Pattern; +import jakarta.persistence.Column; +import jakarta.persistence.Embedded; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -18,19 +21,15 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class User extends BaseEntity { - private static final String EMAIL_REGEX = "^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*.[a-zA-Z]{2,3}$"; - private static final String PASSWORD_REGEX = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*\\W).{8,20}$"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(length = 25, nullable = false) - @Email(regexp = EMAIL_REGEX) - private String email; + @Embedded + private Email email; - @Column(length = 20, nullable = false) - @Pattern(regexp = PASSWORD_REGEX) - private String password; + @Embedded + private Password password; @Column(length = 5, nullable = false) private String name; @@ -42,9 +41,9 @@ public class User extends BaseEntity { private String hobby; @Builder - private User(@Valid String email, @Valid String password, String name, int age, String hobby) { - this.email = email; - this.password = password; + private User(String email, String password, String name, int age, String hobby) { + this.email = new Email(email); + this.password = new Password(password); this.name = name; this.age = age; this.hobby = hobby; @@ -66,4 +65,9 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(id); } + + public String getEmail() { + return email.getEmail(); + } + } diff --git a/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java b/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java index 8d68b4f16..fd05e5bcf 100644 --- a/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java +++ b/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java @@ -1,5 +1,8 @@ package dev.jpaboard.user.dto.request; -public record UserUpdateRequest(String name, String hobby) { +import jakarta.validation.constraints.Size; +public record UserUpdateRequest( + @Size(max = 5) String name, + @Size(min = 20) String hobby) { } diff --git a/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java b/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java index 2212f9b75..d65334089 100644 --- a/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java +++ b/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java @@ -4,11 +4,10 @@ import lombok.Builder; @Builder -public record UserResponse(Long id, String email, String name, int age, String hobby) { +public record UserResponse(String email, String name, int age, String hobby) { public static UserResponse from(User user) { return UserResponse.builder() - .id(user.getId()) .email(user.getEmail()) .name(user.getName()) .age(user.getAge()) diff --git a/src/main/java/dev/jpaboard/user/exception/InvalidEmailException.java b/src/main/java/dev/jpaboard/user/exception/InvalidEmailException.java new file mode 100644 index 000000000..1c32fd829 --- /dev/null +++ b/src/main/java/dev/jpaboard/user/exception/InvalidEmailException.java @@ -0,0 +1,12 @@ +package dev.jpaboard.user.exception; + +import dev.jpaboard.common.exception.BadRequestException; + +public class InvalidEmailException extends BadRequestException { + private static final String MESSAGE = "적절하지 않은 이메일입니다."; + + public InvalidEmailException() { + super(MESSAGE); + } + +} diff --git a/src/main/java/dev/jpaboard/user/exception/InvalidPasswordException.java b/src/main/java/dev/jpaboard/user/exception/InvalidPasswordException.java new file mode 100644 index 000000000..3f742ea51 --- /dev/null +++ b/src/main/java/dev/jpaboard/user/exception/InvalidPasswordException.java @@ -0,0 +1,12 @@ +package dev.jpaboard.user.exception; + +import dev.jpaboard.common.exception.BadRequestException; + +public class InvalidPasswordException extends BadRequestException { + private static final String MESSAGE = "적절하지 않은 비밀번호입니다."; + + public InvalidPasswordException() { + super(MESSAGE); + } + +} diff --git a/src/main/java/dev/jpaboard/user/repository/UserRepository.java b/src/main/java/dev/jpaboard/user/repository/UserRepository.java index e1a609759..c4fd654c6 100644 --- a/src/main/java/dev/jpaboard/user/repository/UserRepository.java +++ b/src/main/java/dev/jpaboard/user/repository/UserRepository.java @@ -1,5 +1,7 @@ package dev.jpaboard.user.repository; +import dev.jpaboard.user.domain.Email; +import dev.jpaboard.user.domain.Password; import dev.jpaboard.user.domain.User; import org.springframework.data.jpa.repository.JpaRepository; @@ -7,6 +9,6 @@ public interface UserRepository extends JpaRepository { - Optional findByEmailAndPassword(String email, String password); + Optional findByEmailAndPassword(Email email, Password password); } From f11274339661d3527567eb0f5da737cbffb92167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 00:22:15 +0900 Subject: [PATCH 32/47] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EC=8A=A4?= =?UTF-8?q?=ED=83=80=EC=9D=BC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/AuthorizedException.java | 1 - .../dev/jpaboard/post/dto/PostsResponse.java | 1 + .../dev/jpaboard/user/api/UserController.java | 1 - .../user/dto/request/UserCreateRequest.java | 18 +++++++++--------- .../user/dto/request/UserLoginRequest.java | 1 - .../user/exception/UserNotFoundException.java | 8 ++++---- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/java/dev/jpaboard/common/exception/AuthorizedException.java b/src/main/java/dev/jpaboard/common/exception/AuthorizedException.java index 3d17fa079..28e2ca02b 100644 --- a/src/main/java/dev/jpaboard/common/exception/AuthorizedException.java +++ b/src/main/java/dev/jpaboard/common/exception/AuthorizedException.java @@ -1,7 +1,6 @@ package dev.jpaboard.common.exception; public class AuthorizedException extends RuntimeException { - private static final String MESSAGE = "권한이 없습니다."; public AuthorizedException() { diff --git a/src/main/java/dev/jpaboard/post/dto/PostsResponse.java b/src/main/java/dev/jpaboard/post/dto/PostsResponse.java index 2804590d1..cb942d837 100644 --- a/src/main/java/dev/jpaboard/post/dto/PostsResponse.java +++ b/src/main/java/dev/jpaboard/post/dto/PostsResponse.java @@ -12,4 +12,5 @@ public static PostsResponse from(Page postPage) { .map(PostResponse::from) .toList(), postPage.getTotalPages(), postPage.getNumber()); } + } diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index 8f63d03e0..ce6809bfc 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -63,7 +63,6 @@ public UserResponse findUser(@SessionAttribute(name = "userId") Long userId) { return userService.findUser(userId); } - @DeleteMapping("/me") public void delete(@SessionAttribute(name = "userId") Long userId) { userService.delete(userId); diff --git a/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java b/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java index 713eb6d85..da899a79b 100644 --- a/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java +++ b/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java @@ -4,14 +4,14 @@ public record UserCreateRequest(String email, String password, String name, int age, String hobby) { - public static User toUser(UserCreateRequest request) { - return User.builder() - .email(request.email) - .password(request.password) - .name(request.name) - .age(request.age) - .hobby(request.hobby) - .build(); - } + public static User toUser(UserCreateRequest request) { + return User.builder() + .email(request.email) + .password(request.password) + .name(request.name) + .age(request.age) + .hobby(request.hobby) + .build(); + } } diff --git a/src/main/java/dev/jpaboard/user/dto/request/UserLoginRequest.java b/src/main/java/dev/jpaboard/user/dto/request/UserLoginRequest.java index 939732924..9af883fbd 100644 --- a/src/main/java/dev/jpaboard/user/dto/request/UserLoginRequest.java +++ b/src/main/java/dev/jpaboard/user/dto/request/UserLoginRequest.java @@ -1,5 +1,4 @@ package dev.jpaboard.user.dto.request; public record UserLoginRequest(String email, String password) { - } diff --git a/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java b/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java index 6aae35821..1e235a1cf 100644 --- a/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java +++ b/src/main/java/dev/jpaboard/user/exception/UserNotFoundException.java @@ -3,10 +3,10 @@ import dev.jpaboard.common.exception.NotFoundException; public class UserNotFoundException extends NotFoundException { - private static final String MESSAGE = "유저를 찾을 수 없습니다."; + private static final String MESSAGE = "유저를 찾을 수 없습니다."; - public UserNotFoundException() { - super(MESSAGE); - } + public UserNotFoundException() { + super(MESSAGE); + } } From 8eb1637977dc4bebcd7d5251533f19da69943d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 00:23:09 +0900 Subject: [PATCH 33/47] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/jpaboard/JpaBoardApplicationTests.java | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/test/java/dev/jpaboard/JpaBoardApplicationTests.java diff --git a/src/test/java/dev/jpaboard/JpaBoardApplicationTests.java b/src/test/java/dev/jpaboard/JpaBoardApplicationTests.java deleted file mode 100644 index bee6e2473..000000000 --- a/src/test/java/dev/jpaboard/JpaBoardApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.jpaboard; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class JpaBoardApplicationTests { - - @Test - void contextLoads() { - } - -} From 2fd7292c7eaee9e3bd2170517d7de3b4fff1ced7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 00:25:51 +0900 Subject: [PATCH 34/47] =?UTF-8?q?refactor:=20=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EC=B6=9C=EB=A1=9C=20=EB=A1=9C=EC=A7=81=20=EA=B0=80?= =?UTF-8?q?=EB=8F=85=EC=84=B1=20=ED=96=A5=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/dev/jpaboard/post/dto/PostsResponse.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/jpaboard/post/dto/PostsResponse.java b/src/main/java/dev/jpaboard/post/dto/PostsResponse.java index cb942d837..105ab4974 100644 --- a/src/main/java/dev/jpaboard/post/dto/PostsResponse.java +++ b/src/main/java/dev/jpaboard/post/dto/PostsResponse.java @@ -8,9 +8,10 @@ public record PostsResponse(List postResponse, int totalPages, int currentPage) { public static PostsResponse from(Page postPage) { - return new PostsResponse(postPage.getContent().stream() + List posts = postPage.getContent().stream() .map(PostResponse::from) - .toList(), postPage.getTotalPages(), postPage.getNumber()); + .toList(); + return new PostsResponse(posts, postPage.getTotalPages(), postPage.getNumber()); } } From cfc15455663c8b851644043eee8d5f88094edbe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 00:27:43 +0900 Subject: [PATCH 35/47] =?UTF-8?q?refactor:=20logout=EC=97=90=EC=84=9C=20Ge?= =?UTF-8?q?t=EC=9D=84=20Post=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/jpaboard/user/api/UserController.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index ce6809bfc..72402a640 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -9,7 +9,15 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +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.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.SessionAttribute; import java.util.Objects; @@ -41,7 +49,7 @@ public Long login(@RequestBody UserLoginRequest request, HttpServletRequest http return userId; } - @GetMapping("/logout") + @PostMapping("/logout") @ResponseStatus(NO_CONTENT) public void logout(HttpServletRequest httpRequest) { HttpSession session = httpRequest.getSession(false); From 6fe58201ec4186061ac248f357989f2e9aea0067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 02:17:53 +0900 Subject: [PATCH 36/47] =?UTF-8?q?refactor:=20=EC=9D=B8=EC=A6=9D,=20?= =?UTF-8?q?=EC=9D=B8=EA=B0=80=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/auth/api/AuthController.java | 56 +++++++++++++++++++ .../auth/application/AuthService.java | 37 ++++++++++++ .../dev/jpaboard/user/api/UserController.java | 39 +------------ .../user/application/UserService.java | 19 ------- .../user/dto/request/UserCreateRequest.java | 12 ++-- 5 files changed, 100 insertions(+), 63 deletions(-) create mode 100644 src/main/java/dev/jpaboard/auth/api/AuthController.java create mode 100644 src/main/java/dev/jpaboard/auth/application/AuthService.java diff --git a/src/main/java/dev/jpaboard/auth/api/AuthController.java b/src/main/java/dev/jpaboard/auth/api/AuthController.java new file mode 100644 index 000000000..3a75bf56f --- /dev/null +++ b/src/main/java/dev/jpaboard/auth/api/AuthController.java @@ -0,0 +1,56 @@ +package dev.jpaboard.auth.api; + +import dev.jpaboard.auth.application.AuthService; +import dev.jpaboard.common.exception.AuthorizedException; +import dev.jpaboard.user.dto.request.UserCreateRequest; +import dev.jpaboard.user.dto.request.UserLoginRequest; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; +import lombok.RequiredArgsConstructor; +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.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Objects; + +import static org.springframework.http.HttpStatus.NO_CONTENT; +import static org.springframework.http.HttpStatus.OK; + +@RestController +@RequestMapping("/api/auth") +@RequiredArgsConstructor +public class AuthController { + + private final AuthService authService; + + @PostMapping("/sign-up") + @ResponseStatus(OK) + public void signUp(@RequestBody UserCreateRequest request) { + authService.signUp(request); + } + + @PostMapping("/login") + @ResponseStatus(OK) + public Long login(@RequestBody UserLoginRequest request, HttpServletRequest httpRequest) { + httpRequest.getSession().invalidate(); + HttpSession session = httpRequest.getSession(true); + + Long userId = authService.login(request); + session.setAttribute("userId", userId); + session.setMaxInactiveInterval(3600); + return userId; + } + + @PostMapping("/logout") + @ResponseStatus(NO_CONTENT) + public void logout(HttpServletRequest httpRequest) { + HttpSession session = httpRequest.getSession(false); + if (Objects.isNull(session)) { + throw new AuthorizedException(); + } + session.invalidate(); + } + +} diff --git a/src/main/java/dev/jpaboard/auth/application/AuthService.java b/src/main/java/dev/jpaboard/auth/application/AuthService.java new file mode 100644 index 000000000..0156b4846 --- /dev/null +++ b/src/main/java/dev/jpaboard/auth/application/AuthService.java @@ -0,0 +1,37 @@ +package dev.jpaboard.auth.application; + +import dev.jpaboard.user.domain.Email; +import dev.jpaboard.user.domain.Password; +import dev.jpaboard.user.domain.User; +import dev.jpaboard.user.dto.request.UserCreateRequest; +import dev.jpaboard.user.dto.request.UserLoginRequest; +import dev.jpaboard.user.exception.UserNotFoundException; +import dev.jpaboard.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class AuthService { + + private final UserRepository userRepository; + + @Transactional + public void signUp(UserCreateRequest request) { + User user = request.toUser(); + userRepository.save(user); + } + + public Long login(UserLoginRequest request) { + User user = findByEmailAndPassword(request.email(), request.password()); + return user.getId(); + } + + private User findByEmailAndPassword(String email, String password) { + return userRepository.findByEmailAndPassword(new Email(email), new Password(password)) + .orElseThrow(UserNotFoundException::new); + } + +} diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index 72402a640..af99fe6b1 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -1,28 +1,19 @@ package dev.jpaboard.user.api; -import dev.jpaboard.common.exception.AuthorizedException; import dev.jpaboard.user.application.UserService; -import dev.jpaboard.user.dto.request.UserCreateRequest; -import dev.jpaboard.user.dto.request.UserLoginRequest; import dev.jpaboard.user.dto.request.UserUpdateRequest; import dev.jpaboard.user.dto.response.UserResponse; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpSession; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; -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.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.SessionAttribute; -import java.util.Objects; - import static org.springframework.http.HttpStatus.NO_CONTENT; -import static org.springframework.http.HttpStatus.OK; @RestController @RequestMapping("/api/users") @@ -31,35 +22,7 @@ public class UserController { private final UserService userService; - @PostMapping("/sign-up") - @ResponseStatus(OK) - public void signUp(@RequestBody UserCreateRequest request) { - userService.signUp(request); - } - - @PostMapping("/login") - @ResponseStatus(OK) - public Long login(@RequestBody UserLoginRequest request, HttpServletRequest httpRequest) { - httpRequest.getSession().invalidate(); - HttpSession session = httpRequest.getSession(true); - - Long userId = userService.login(request); - session.setAttribute("userId", userId); - session.setMaxInactiveInterval(3600); - return userId; - } - - @PostMapping("/logout") - @ResponseStatus(NO_CONTENT) - public void logout(HttpServletRequest httpRequest) { - HttpSession session = httpRequest.getSession(false); - if (Objects.isNull(session)) { - throw new AuthorizedException(); - } - session.invalidate(); - } - - @PatchMapping("/update") + @PatchMapping @ResponseStatus(NO_CONTENT) public void update(@RequestBody UserUpdateRequest request, @SessionAttribute(name = "userId") Long userId) { diff --git a/src/main/java/dev/jpaboard/user/application/UserService.java b/src/main/java/dev/jpaboard/user/application/UserService.java index 6db1a59d9..ea4d597e5 100644 --- a/src/main/java/dev/jpaboard/user/application/UserService.java +++ b/src/main/java/dev/jpaboard/user/application/UserService.java @@ -1,8 +1,6 @@ package dev.jpaboard.user.application; import dev.jpaboard.user.domain.User; -import dev.jpaboard.user.dto.request.UserCreateRequest; -import dev.jpaboard.user.dto.request.UserLoginRequest; import dev.jpaboard.user.dto.request.UserUpdateRequest; import dev.jpaboard.user.dto.response.UserResponse; import dev.jpaboard.user.exception.UserNotFoundException; @@ -18,18 +16,6 @@ public class UserService { private final UserRepository userRepository; - @Transactional - public UserResponse signUp(UserCreateRequest request) { - User user = UserCreateRequest.toUser(request); - User savedUser = userRepository.save(user); - return UserResponse.from(savedUser); - } - - public Long login(UserLoginRequest request) { - User user = findByEmailAndPassword(request.email(), request.password()); - return user.getId(); - } - @Transactional public UserResponse update(UserUpdateRequest request, Long userId) { User user = findUserById(userId); @@ -52,9 +38,4 @@ private User findUserById(Long userId) { .orElseThrow(UserNotFoundException::new); } - private User findByEmailAndPassword(String email, String password) { - return userRepository.findByEmailAndPassword(email, password) - .orElseThrow(UserNotFoundException::new); - } - } diff --git a/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java b/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java index da899a79b..f90bfce5f 100644 --- a/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java +++ b/src/main/java/dev/jpaboard/user/dto/request/UserCreateRequest.java @@ -4,13 +4,13 @@ public record UserCreateRequest(String email, String password, String name, int age, String hobby) { - public static User toUser(UserCreateRequest request) { + public User toUser() { return User.builder() - .email(request.email) - .password(request.password) - .name(request.name) - .age(request.age) - .hobby(request.hobby) + .email(this.email) + .password(this.password) + .name(this.name) + .age(this.age) + .hobby(this.hobby) .build(); } From 62100aac77346c996d8aca3c72b17d6a80b66a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 02:18:37 +0900 Subject: [PATCH 37/47] =?UTF-8?q?test:=20=ED=8E=98=EC=96=B4=20=EC=BD=94?= =?UTF-8?q?=EB=94=A9=20=EC=A0=80=EC=9E=A5=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/jpaboard/UserControllerTest.java | 150 ++++++++++++++++++ src/test/java/dev/jpaboard/user/UserTest.java | 24 +++ .../user/repository/UserRepositoryTest.java | 35 ++++ 3 files changed, 209 insertions(+) create mode 100644 src/test/java/dev/jpaboard/UserControllerTest.java create mode 100644 src/test/java/dev/jpaboard/user/UserTest.java create mode 100644 src/test/java/dev/jpaboard/user/repository/UserRepositoryTest.java diff --git a/src/test/java/dev/jpaboard/UserControllerTest.java b/src/test/java/dev/jpaboard/UserControllerTest.java new file mode 100644 index 000000000..702e948e1 --- /dev/null +++ b/src/test/java/dev/jpaboard/UserControllerTest.java @@ -0,0 +1,150 @@ +package dev.jpaboard; + +import dev.jpaboard.auth.api.AuthController; +import dev.jpaboard.auth.application.AuthService; +import dev.jpaboard.user.application.UserService; +import dev.jpaboard.user.dto.request.UserCreateRequest; +import dev.jpaboard.user.dto.request.UserLoginRequest; +import dev.jpaboard.user.dto.request.UserUpdateRequest; +import dev.jpaboard.user.dto.response.UserResponse; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockHttpSession; +import org.springframework.restdocs.payload.JsonFieldType; + +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; +import static com.epages.restdocs.apispec.ResourceDocumentation.headerWithName; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doNothing; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; +import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(AuthController.class) +public class UserControllerTest extends ControllerTest { + + @MockBean + UserService userService; + + @MockBean + AuthService authService; + + @Test + void signUp() throws Exception { + UserCreateRequest request = new UserCreateRequest("qkrdmswl1018@naver.com", "Qwer1234?", "이름", 10, "취이름"); + doNothing().when(authService).signUp(any()); + + mockMvc.perform(post("/api/auth/sign-up") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ) + .andDo(document("signup", + preprocessRequest(prettyPrint()), + requestFields( + fieldWithPath("email").type(JsonFieldType.STRING) + .description("이메일"), + fieldWithPath("password").type(JsonFieldType.STRING) + .description("비밀번호"), + fieldWithPath("name").type(JsonFieldType.STRING) + .description("이름"), + fieldWithPath("age").type(JsonFieldType.NUMBER) + .description("나이"), + fieldWithPath("hobby").type(JsonFieldType.STRING) + .description("취미") + ) + ) + ) +// .andExpect() + .andExpect(status().isOk()); + } + + @Test + void login() throws Exception { + UserLoginRequest request = new UserLoginRequest("qkrdmswl1018@naver.com", "Qwer1234?"); + given(authService.login(any())).willReturn(1L); + + mockMvc.perform(post("/api/auth/login") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ) + .andDo(document("login", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestFields( + fieldWithPath("email").type(JsonFieldType.STRING) + .description("이메일"), + fieldWithPath("password").type(JsonFieldType.STRING) + .description("비밀번호") + ) + ) + ).andExpect(status().isOk()); + } + + @Test + void update() throws Exception { + UserUpdateRequest request = new UserUpdateRequest("이름", "취미"); + doNothing().when(userService).update(any(), any()); + + MockHttpSession session = new MockHttpSession(); + session.setAttribute("userId", 1L); + + mockMvc.perform(patch("/api/users/update") + .session(session) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ) + .andDo(document("user-update", + requestHeaders( + headerWithName("JsessionID").description("세션").getAttributes() + ), + requestFields( + fieldWithPath("name").type(JsonFieldType.STRING).description("수정할 이름"), + fieldWithPath("hobby").type(JsonFieldType.STRING).description("수정할 취미") + ) + ) + ).andExpect(status().isNoContent()); + } + + @Test + void findUser() throws Exception { + given(userService.findUser(any())).willReturn(new UserResponse("qwer123@naver.com", "데브코스", 4, "코딩")); + + mockMvc.perform(get("/api/posts/me") + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + ) + .andDo(document("user-find", + pathParameters(parameterWithName("id").description("User ID")), + responseFields( + fieldWithPath("email").type(JsonFieldType.STRING) + .description("이메일"), + fieldWithPath("name").type(JsonFieldType.STRING) + .description("이름"), + fieldWithPath("age").type(JsonFieldType.NUMBER) + .description("나이"), + fieldWithPath("hobby").type(JsonFieldType.STRING) + .description("취미") + ) + ) + ).andExpect(status().isOk()); + } + +} diff --git a/src/test/java/dev/jpaboard/user/UserTest.java b/src/test/java/dev/jpaboard/user/UserTest.java new file mode 100644 index 000000000..88fa53652 --- /dev/null +++ b/src/test/java/dev/jpaboard/user/UserTest.java @@ -0,0 +1,24 @@ +package dev.jpaboard.user; + +import dev.jpaboard.user.domain.User; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class UserTest { + + @ParameterizedTest + @CsvSource(value = {"qkrdmswl1018@naver.com|Qwe12|박은지|21|공부", "qwer2345gmail.com|Dfg23456?|고범준|25|놀기", "oiue345345|2345|원건희|25|산책"}, delimiter = '|') + void user_Create_Fail(String email, String password, String name, int age, String hobby) { + User user = User.builder() + .email(email) + .password(password) + .name(name) + .age(age) + .hobby(hobby) + .build(); + + } + +} diff --git a/src/test/java/dev/jpaboard/user/repository/UserRepositoryTest.java b/src/test/java/dev/jpaboard/user/repository/UserRepositoryTest.java new file mode 100644 index 000000000..c6877d1ea --- /dev/null +++ b/src/test/java/dev/jpaboard/user/repository/UserRepositoryTest.java @@ -0,0 +1,35 @@ +package dev.jpaboard.user.repository; + +import dev.jpaboard.user.domain.Email; +import dev.jpaboard.user.domain.Password; +import dev.jpaboard.user.domain.User; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +import java.util.Optional; + +@DataJpaTest +class UserRepositoryTest { + + @Autowired + private UserRepository userRepository; + + @Test + void test() { + User user = User.builder() + .email("qkrdmswl1018@naner.com") + .password("Qwqer123?") + .name("박은지") + .age(23) + .hobby("산책") + .build(); + userRepository.save(user); + + User findUser = userRepository.findByEmailAndPassword(new Email("qkrdmswl1018@naner.com"), new Password("Qwqer123?")).get(); + System.out.println(String.format("Email: %s, Password: %s", findUser.getEmail(), findUser.getPassword())); + } + +} \ No newline at end of file From 25e0c81e60cab1dc8298a114ed4d1f0b51435782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 21:40:20 +0900 Subject: [PATCH 38/47] =?UTF-8?q?test:=20UserControllerTest=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/user/api/UserController.java | 12 +- .../user/application/UserService.java | 9 +- ...serResponse.java => UserInfoResponse.java} | 6 +- src/test/java/dev/jpaboard/user/UserTest.java | 24 ---- .../jpaboard/user/api/UserControllerTest.java | 110 ++++++++++++++++++ 5 files changed, 122 insertions(+), 39 deletions(-) rename src/main/java/dev/jpaboard/user/dto/response/{UserResponse.java => UserInfoResponse.java} (62%) delete mode 100644 src/test/java/dev/jpaboard/user/UserTest.java create mode 100644 src/test/java/dev/jpaboard/user/api/UserControllerTest.java diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index af99fe6b1..ed8eb8529 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -2,7 +2,7 @@ import dev.jpaboard.user.application.UserService; import dev.jpaboard.user.dto.request.UserUpdateRequest; -import dev.jpaboard.user.dto.response.UserResponse; +import dev.jpaboard.user.dto.response.UserInfoResponse; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -22,11 +22,9 @@ public class UserController { private final UserService userService; - @PatchMapping - @ResponseStatus(NO_CONTENT) - public void update(@RequestBody UserUpdateRequest request, - @SessionAttribute(name = "userId") Long userId) { - userService.update(request, userId); + @GetMapping("/me") + public UserInfoResponse findUser(@SessionAttribute(name = "userId") Long userId) { + return userService.findUser(userId); } @GetMapping("/me") @@ -35,7 +33,7 @@ public UserResponse findUser(@SessionAttribute(name = "userId") Long userId) { } @DeleteMapping("/me") - public void delete(@SessionAttribute(name = "userId") Long userId) { + public void deleteUser(@SessionAttribute(name = "userId") Long userId) { userService.delete(userId); } diff --git a/src/main/java/dev/jpaboard/user/application/UserService.java b/src/main/java/dev/jpaboard/user/application/UserService.java index ea4d597e5..654ecc465 100644 --- a/src/main/java/dev/jpaboard/user/application/UserService.java +++ b/src/main/java/dev/jpaboard/user/application/UserService.java @@ -2,7 +2,7 @@ import dev.jpaboard.user.domain.User; import dev.jpaboard.user.dto.request.UserUpdateRequest; -import dev.jpaboard.user.dto.response.UserResponse; +import dev.jpaboard.user.dto.response.UserInfoResponse; import dev.jpaboard.user.exception.UserNotFoundException; import dev.jpaboard.user.repository.UserRepository; import lombok.RequiredArgsConstructor; @@ -17,15 +17,14 @@ public class UserService { private final UserRepository userRepository; @Transactional - public UserResponse update(UserUpdateRequest request, Long userId) { + public void update(UserUpdateRequest request, Long userId) { User user = findUserById(userId); user.update(request.name(), request.hobby()); - return UserResponse.from(user); } - public UserResponse findUser(Long userId) { + public UserInfoResponse findUser(Long userId) { User user = findUserById(userId); - return UserResponse.from(user); + return UserInfoResponse.from(user); } @Transactional diff --git a/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java b/src/main/java/dev/jpaboard/user/dto/response/UserInfoResponse.java similarity index 62% rename from src/main/java/dev/jpaboard/user/dto/response/UserResponse.java rename to src/main/java/dev/jpaboard/user/dto/response/UserInfoResponse.java index d65334089..7f19887d9 100644 --- a/src/main/java/dev/jpaboard/user/dto/response/UserResponse.java +++ b/src/main/java/dev/jpaboard/user/dto/response/UserInfoResponse.java @@ -4,10 +4,10 @@ import lombok.Builder; @Builder -public record UserResponse(String email, String name, int age, String hobby) { +public record UserInfoResponse(String email, String name, int age, String hobby) { - public static UserResponse from(User user) { - return UserResponse.builder() + public static UserInfoResponse from(User user) { + return UserInfoResponse.builder() .email(user.getEmail()) .name(user.getName()) .age(user.getAge()) diff --git a/src/test/java/dev/jpaboard/user/UserTest.java b/src/test/java/dev/jpaboard/user/UserTest.java deleted file mode 100644 index 88fa53652..000000000 --- a/src/test/java/dev/jpaboard/user/UserTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package dev.jpaboard.user; - -import dev.jpaboard.user.domain.User; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -public class UserTest { - - @ParameterizedTest - @CsvSource(value = {"qkrdmswl1018@naver.com|Qwe12|박은지|21|공부", "qwer2345gmail.com|Dfg23456?|고범준|25|놀기", "oiue345345|2345|원건희|25|산책"}, delimiter = '|') - void user_Create_Fail(String email, String password, String name, int age, String hobby) { - User user = User.builder() - .email(email) - .password(password) - .name(name) - .age(age) - .hobby(hobby) - .build(); - - } - -} diff --git a/src/test/java/dev/jpaboard/user/api/UserControllerTest.java b/src/test/java/dev/jpaboard/user/api/UserControllerTest.java new file mode 100644 index 000000000..b977d22c0 --- /dev/null +++ b/src/test/java/dev/jpaboard/user/api/UserControllerTest.java @@ -0,0 +1,110 @@ +package dev.jpaboard.user.api; + +import com.epages.restdocs.apispec.Schema; +import dev.jpaboard.ControllerTest; +import dev.jpaboard.user.application.UserService; +import dev.jpaboard.user.dto.request.UserUpdateRequest; +import dev.jpaboard.user.dto.response.UserInfoResponse; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.restdocs.payload.JsonFieldType; + +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.resourceDetails; +import static com.epages.restdocs.apispec.ResourceDocumentation.headerWithName; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doNothing; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(UserController.class) +public class UserControllerTest extends ControllerTest { + + @MockBean + UserService userService; + + @DisplayName("로그인한 유저는 본인의 정보를 조회할 수 있다.") + @Test + void findUserTest() throws Exception { + UserInfoResponse response = new UserInfoResponse("qwer123@naver.com", "데브코스", 4, "코딩"); + given(userService.findUser(SESSION_USERID_VALUE)).willReturn(response); + + mockMvc.perform(get("/api/users/me") + .session(session) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + ) + .andDo(document("user-me", + resourceDetails().tags("User").description("본인 정보 조회") + .responseSchema(Schema.schema("UserInfoResponse")), + responseFields( + fieldWithPath("email").type(JsonFieldType.STRING) + .description("이메일"), + fieldWithPath("name").type(JsonFieldType.STRING) + .description("이름"), + fieldWithPath("age").type(JsonFieldType.NUMBER) + .description("나이"), + fieldWithPath("hobby").type(JsonFieldType.STRING) + .description("취미") + ) + ) + ).andExpect(status().isOk()); + } + + @DisplayName("로그인한 유저는 본인의 정보를 수정할 수 있다.") + @Test + void updateUserTest() throws Exception { + UserUpdateRequest request = new UserUpdateRequest("이름", "취미"); + doNothing().when(userService).update(request, SESSION_USERID_VALUE); + + mockMvc.perform(patch("/api/users") + .session(session) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(request)) + ) + .andDo(document("user-update", + resourceDetails().tags("User") + .description("유저 업데이트") + .requestSchema(Schema.schema("UserUpdateRequest")), + requestHeaders( + headerWithName("JsessionID").description("세션").getAttributes() + ), + requestFields( + fieldWithPath("name").type(JsonFieldType.STRING).description("수정할 이름"), + fieldWithPath("hobby").type(JsonFieldType.STRING).description("수정할 취미") + ) + ) + ).andExpect(status().isNoContent()); + } + + @DisplayName("로그인한 유저는 회원탈퇴를 할 수 있다.") + @Test + void deleteUserTest() throws Exception { + doNothing().when(userService).delete(SESSION_USERID_VALUE); + + mockMvc.perform(delete("/api/users/me") + .session(session) + .accept(MediaType.APPLICATION_JSON) + .contentType(MediaType.APPLICATION_JSON) + ) + .andDo(document("user-delete", + resourceDetails().tags("User").description("회원탈퇴"), + requestHeaders( + headerWithName("JsessionID").description("세션").getAttributes() + ) + ) + ) + .andExpect(status().isOk()); + } + +} From 0a79c4a8fecbb863ab9b49e65411db26a3f81089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 21:40:40 +0900 Subject: [PATCH 39/47] =?UTF-8?q?test:=20PostControllerTest=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/post/api/PostController.java | 10 ++--- .../dev/jpaboard/post/PostControllerTest.java | 40 +++++++++++++------ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java index 9d2528f79..dbdbad9a6 100644 --- a/src/main/java/dev/jpaboard/post/api/PostController.java +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -51,15 +51,15 @@ public PostResponse findPost(@PathVariable Long id) { @PatchMapping("/{id}") @ResponseStatus(NO_CONTENT) - public void update(@PathVariable("id") Long postId, - @Valid @RequestBody PostUpdateRequest request, - @SessionAttribute(name = "userId") Long userId) { + public void updatePost(@PathVariable("id") Long postId, + @Valid @RequestBody PostUpdateRequest request, + @SessionAttribute(name = "userId") Long userId) { postService.update(postId, request, userId); } @DeleteMapping("/{id}") - public void delete(@PathVariable("id") Long postId, - @SessionAttribute(name = "userId") Long userId) { + public void deletePost(@PathVariable("id") Long postId, + @SessionAttribute(name = "userId") Long userId) { postService.delete(postId, userId); } diff --git a/src/test/java/dev/jpaboard/post/PostControllerTest.java b/src/test/java/dev/jpaboard/post/PostControllerTest.java index eca1f6467..8a587ab66 100644 --- a/src/test/java/dev/jpaboard/post/PostControllerTest.java +++ b/src/test/java/dev/jpaboard/post/PostControllerTest.java @@ -1,11 +1,13 @@ package dev.jpaboard.post; +import com.epages.restdocs.apispec.Schema; import dev.jpaboard.ControllerTest; import dev.jpaboard.post.api.PostController; import dev.jpaboard.post.application.PostService; import dev.jpaboard.post.dto.PostCreateRequest; import dev.jpaboard.post.dto.PostResponse; import dev.jpaboard.post.dto.PostUpdateRequest; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -21,9 +23,16 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; -import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; -import static org.springframework.restdocs.payload.PayloadDocumentation.*; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -36,8 +45,9 @@ public class PostControllerTest extends ControllerTest { @MockBean PostService postService; + @DisplayName("로그인한 유저는 게시물을 생성할 수 있다.") @Test - void create() throws Exception { + void createPostTest() throws Exception { PostCreateRequest request = new PostCreateRequest("제목", "내용"); given(postService.create(any(), any())).willReturn(new PostResponse("제목", "내용")); @@ -52,7 +62,9 @@ void create() throws Exception { ) .andDo(print()) .andDo(document("post-create", - resourceDetails().description("게시물 생성"), + resourceDetails().tag("Post").description("게시물 생성") + .requestSchema(Schema.schema("CreatePostRequest")) + .responseSchema(Schema.schema("CreatePostResponse")), preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), requestHeaders( @@ -73,8 +85,9 @@ void create() throws Exception { ).andExpect(status().isCreated()); } + @DisplayName("로그인한 유저는 자신의 게시물을 수정할 수 있다.") @Test - void update() throws Exception { + void updatePostTest() throws Exception { PostUpdateRequest request = new PostUpdateRequest("제목", "내용"); doNothing().when(postService).update(any(), any(), any()); @@ -90,7 +103,8 @@ void update() throws Exception { ) .andDo(print()) .andDo(document("post-update", - resourceDetails().description("게시물 업데이트"), + resourceDetails().tag("Post").description("게시물 업데이트") + .requestSchema(Schema.schema("UpdatePostRequest")), pathParameters(parameterWithName("id").description("Post ID")), requestHeaders( headerWithName("JsessionID").description("세션").getAttributes() @@ -103,8 +117,9 @@ void update() throws Exception { ).andExpect(status().isNoContent()); } + @DisplayName("로그인한 유저는 자신의 게시물을 삭제할 수 있다.") @Test - void deletePost() throws Exception { + void deletePostTest() throws Exception { doNothing().when(postService).delete(any(), any()); MockHttpSession session = new MockHttpSession(); @@ -117,18 +132,18 @@ void deletePost() throws Exception { ) .andDo(print()) .andDo(document("post-delete", - resourceDetails().description("게시물 삭제"), + resourceDetails().tag("Post").description("게시물 삭제"), pathParameters(parameterWithName("id").description("Post ID")), requestHeaders( headerWithName("JsessionID").description("세션").getAttributes() ) ) ).andExpect(status().isOk()); - } + @DisplayName("게시물 아이디로 게시물을 조회할 수 있다.") @Test - void findPost() throws Exception { + void findPostTest() throws Exception { given(postService.findPost(any())).willReturn(new PostResponse("제목", "내용")); mockMvc.perform(get("/api/posts/{id}", 1L) @@ -137,7 +152,8 @@ void findPost() throws Exception { ) .andDo(print()) .andDo(document("post-find", - resourceDetails().description("게시물 조회"), + resourceDetails().tag("Post").description("게시물 조회") + .responseSchema(Schema.schema("FindPostResponse")), pathParameters(parameterWithName("id").description("Post ID")), responseFields( fieldWithPath("title").type(JsonFieldType.STRING) From 8a16922af27b93672050e1fa12c7710b05f031eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sat, 5 Aug 2023 21:40:53 +0900 Subject: [PATCH 40/47] =?UTF-8?q?test:=20AuthControllerTest=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthControllerTest.java} | 86 ++++--------------- 1 file changed, 16 insertions(+), 70 deletions(-) rename src/test/java/dev/jpaboard/{UserControllerTest.java => auth/AuthControllerTest.java} (52%) diff --git a/src/test/java/dev/jpaboard/UserControllerTest.java b/src/test/java/dev/jpaboard/auth/AuthControllerTest.java similarity index 52% rename from src/test/java/dev/jpaboard/UserControllerTest.java rename to src/test/java/dev/jpaboard/auth/AuthControllerTest.java index 702e948e1..a02f7725d 100644 --- a/src/test/java/dev/jpaboard/UserControllerTest.java +++ b/src/test/java/dev/jpaboard/auth/AuthControllerTest.java @@ -1,53 +1,43 @@ -package dev.jpaboard; +package dev.jpaboard.auth; +import com.epages.restdocs.apispec.Schema; +import dev.jpaboard.ControllerTest; import dev.jpaboard.auth.api.AuthController; import dev.jpaboard.auth.application.AuthService; -import dev.jpaboard.user.application.UserService; import dev.jpaboard.user.dto.request.UserCreateRequest; import dev.jpaboard.user.dto.request.UserLoginRequest; -import dev.jpaboard.user.dto.request.UserUpdateRequest; -import dev.jpaboard.user.dto.response.UserResponse; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; -import org.springframework.mock.web.MockHttpSession; import org.springframework.restdocs.payload.JsonFieldType; import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; -import static com.epages.restdocs.apispec.ResourceDocumentation.headerWithName; +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.resourceDetails; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doNothing; -import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; -import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; -import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; -import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; -import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @WebMvcTest(AuthController.class) -public class UserControllerTest extends ControllerTest { +public class AuthControllerTest extends ControllerTest { @MockBean - UserService userService; - - @MockBean - AuthService authService; + private AuthService authService; + @DisplayName("자신의 정보를 입력하여 회원가입할 수 있다.") @Test void signUp() throws Exception { UserCreateRequest request = new UserCreateRequest("qkrdmswl1018@naver.com", "Qwer1234?", "이름", 10, "취이름"); - doNothing().when(authService).signUp(any()); + doNothing().when(authService).signUp(request); mockMvc.perform(post("/api/auth/sign-up") .accept(MediaType.APPLICATION_JSON) @@ -55,6 +45,8 @@ void signUp() throws Exception { .content(objectMapper.writeValueAsString(request)) ) .andDo(document("signup", + resourceDetails().tag("Auth").description("회원가입") + .requestSchema(Schema.schema("SignUpRequest")), preprocessRequest(prettyPrint()), requestFields( fieldWithPath("email").type(JsonFieldType.STRING) @@ -70,10 +62,10 @@ void signUp() throws Exception { ) ) ) -// .andExpect() .andExpect(status().isOk()); } + @DisplayName("회원가입된 유저는 이메일과 비밀번호로 로그인할 수 있다.") @Test void login() throws Exception { UserLoginRequest request = new UserLoginRequest("qkrdmswl1018@naver.com", "Qwer1234?"); @@ -85,6 +77,8 @@ void login() throws Exception { .content(objectMapper.writeValueAsString(request)) ) .andDo(document("login", + resourceDetails().tag("Auth").description("로그인") + .requestSchema(Schema.schema("LoginRequest")), preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), requestFields( @@ -94,57 +88,9 @@ void login() throws Exception { .description("비밀번호") ) ) - ).andExpect(status().isOk()); - } - - @Test - void update() throws Exception { - UserUpdateRequest request = new UserUpdateRequest("이름", "취미"); - doNothing().when(userService).update(any(), any()); - - MockHttpSession session = new MockHttpSession(); - session.setAttribute("userId", 1L); - - mockMvc.perform(patch("/api/users/update") - .session(session) - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) ) - .andDo(document("user-update", - requestHeaders( - headerWithName("JsessionID").description("세션").getAttributes() - ), - requestFields( - fieldWithPath("name").type(JsonFieldType.STRING).description("수정할 이름"), - fieldWithPath("hobby").type(JsonFieldType.STRING).description("수정할 취미") - ) - ) - ).andExpect(status().isNoContent()); - } - - @Test - void findUser() throws Exception { - given(userService.findUser(any())).willReturn(new UserResponse("qwer123@naver.com", "데브코스", 4, "코딩")); - - mockMvc.perform(get("/api/posts/me") - .accept(MediaType.APPLICATION_JSON) - .contentType(MediaType.APPLICATION_JSON) - ) - .andDo(document("user-find", - pathParameters(parameterWithName("id").description("User ID")), - responseFields( - fieldWithPath("email").type(JsonFieldType.STRING) - .description("이메일"), - fieldWithPath("name").type(JsonFieldType.STRING) - .description("이름"), - fieldWithPath("age").type(JsonFieldType.NUMBER) - .description("나이"), - fieldWithPath("hobby").type(JsonFieldType.STRING) - .description("취미") - ) - ) - ).andExpect(status().isOk()); + .andExpect(content().string("1")) + .andExpect(status().isOk()); } } From 9bc6cdc209c7927a42c0fa1825f7cb39ef8c58b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 6 Aug 2023 01:52:06 +0900 Subject: [PATCH 41/47] =?UTF-8?q?test:=20UserTest=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/user/domain/UserTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/test/java/dev/jpaboard/user/domain/UserTest.java diff --git a/src/test/java/dev/jpaboard/user/domain/UserTest.java b/src/test/java/dev/jpaboard/user/domain/UserTest.java new file mode 100644 index 000000000..db8f4412d --- /dev/null +++ b/src/test/java/dev/jpaboard/user/domain/UserTest.java @@ -0,0 +1,32 @@ +package dev.jpaboard.user.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +class UserTest { + + @DisplayName("유저의 이름과 취미를 수정할 수 있다.") + @Test + void updateTest() { + String 이름 = "이름"; + String 취미 = "취미"; + + User user = User.builder() + .email("qkrdmswl1018@naver.com") + .password("QWert123?") + .name("name") + .age(23) + .hobby("hobby") + .build(); + + user.update(이름, 취미); + + assertAll( + () -> assertThat(user.getName()).isEqualTo(이름), + () -> assertThat(user.getHobby()).isEqualTo(취미)); + } + +} From 37a495c027dcb605179c23a5a11d1508001282d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 6 Aug 2023 01:52:21 +0900 Subject: [PATCH 42/47] =?UTF-8?q?test:=20UserServiceTest=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/dto/request/UserUpdateRequest.java | 2 +- .../user/application/UserServiceTest.java | 116 ++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/test/java/dev/jpaboard/user/application/UserServiceTest.java diff --git a/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java b/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java index fd05e5bcf..6256f8aec 100644 --- a/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java +++ b/src/main/java/dev/jpaboard/user/dto/request/UserUpdateRequest.java @@ -4,5 +4,5 @@ public record UserUpdateRequest( @Size(max = 5) String name, - @Size(min = 20) String hobby) { + @Size(max = 20) String hobby) { } diff --git a/src/test/java/dev/jpaboard/user/application/UserServiceTest.java b/src/test/java/dev/jpaboard/user/application/UserServiceTest.java new file mode 100644 index 000000000..311fb3765 --- /dev/null +++ b/src/test/java/dev/jpaboard/user/application/UserServiceTest.java @@ -0,0 +1,116 @@ +package dev.jpaboard.user.application; + +import dev.jpaboard.user.domain.User; +import dev.jpaboard.user.dto.request.UserUpdateRequest; +import dev.jpaboard.user.dto.response.UserInfoResponse; +import dev.jpaboard.user.exception.UserNotFoundException; +import dev.jpaboard.user.repository.UserRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertFalse; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) +class UserServiceTest { + + private static final String 이메일 = "qkrdmswl1018@naver.com"; + private static final String 비밀번호 = "QWert123?"; + private static final String 이름 = "name"; + private static final int 나이 = 23; + private static final String 취미 = "hobby"; + + @Autowired + private UserService userService; + + @Autowired + private UserRepository userRepository; + + private User user; + + @BeforeEach + void setUp() { + userRepository.deleteAllInBatch(); + user = savedUser(); + } + + private User savedUser() { + User user = User.builder() + .email(이메일) + .password(비밀번호) + .name(이름) + .age(나이) + .hobby(취미) + .build(); + + return userRepository.save(user); + } + + @DisplayName("존재하는 유저 아이디를 입력할 경우 유저를 수정할 수 있다.") + @Test + void updateUserTest() { + String 수정된_이름 = "원건희"; + String 수정된_취미 = "수정된 취미"; + + Long id = user.getId(); + + userService.update(new UserUpdateRequest(수정된_이름, 수정된_취미), id); + + User findUser = userRepository.findById(id).get(); + assertAll( + () -> assertThat(findUser.getName()).isEqualTo(수정된_이름), + () -> assertThat(findUser.getHobby()).isEqualTo(수정된_취미) + ); + } + + @DisplayName("존재하는 유저 아이디를 입력할 경우 유저를 조회할 수 있다.") + @Test + void findUserTest() { + Long id = user.getId(); + + UserInfoResponse findUser = userService.findUser(id); + + assertAll( + () -> assertThat(findUser.email()).isEqualTo(이메일), + () -> assertThat(findUser.name()).isEqualTo(이름), + () -> assertThat(findUser.age()).isEqualTo(나이), + () -> assertThat(findUser.hobby()).isEqualTo(취미) + ); + } + + @DisplayName("존재하는 유저 아이디를 입력할 경우 유저를 삭제할 수 있다.") + @Test + void deleteUserTest() { + Long id = user.getId(); + userService.delete(id); + + Optional findUser = userRepository.findById(id); + + assertFalse(findUser.isPresent()); + } + + @DisplayName("존재하지 않는 유저 아이디를 입력할 경우 유저를 수정할 수 없다.") + @Test + void updateFailTest() { + String 수정된_이름 = "원건희"; + String 수정된_취미 = "수정된 취미"; + + assertThatThrownBy(() -> userService.update(new UserUpdateRequest(수정된_이름, 수정된_취미), 102938475L)) + .isInstanceOf(UserNotFoundException.class); + } + + @DisplayName("존재하지 않는 유저 아이디를 입력할 경우 유저를 조회할 수 없다.") + @Test + void findUserFailTest() { + assertThatThrownBy(() -> userService.findUser(1029384756L)) + .isInstanceOf(UserNotFoundException.class); + } + +} From 3962dab44a35f060b324718dd73a6aa993a90c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 6 Aug 2023 01:52:30 +0900 Subject: [PATCH 43/47] =?UTF-8?q?test:=20PostTest=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/post/domain/PostTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/java/dev/jpaboard/post/domain/PostTest.java diff --git a/src/test/java/dev/jpaboard/post/domain/PostTest.java b/src/test/java/dev/jpaboard/post/domain/PostTest.java new file mode 100644 index 000000000..72161384d --- /dev/null +++ b/src/test/java/dev/jpaboard/post/domain/PostTest.java @@ -0,0 +1,40 @@ +package dev.jpaboard.post.domain; + +import dev.jpaboard.user.domain.User; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +class PostTest { + + private static final String 제목 = "제목"; + private static final String 내용 = "내용"; + + @DisplayName("") + @Test + void updateTest() { + User user = User.builder() + .email("qkrdmswl1018@naver.com") + .password("QWert123?") + .name("name") + .age(23) + .hobby("hobby") + .build(); + + Post post = Post.builder() + .title("title") + .content("content") + .user(user) + .build(); + + post.update(제목, 내용); + + assertAll( + () -> assertThat(post.getTitle()).isEqualTo(제목), + () -> assertThat(post.getContent()).isEqualTo(내용) + ); + } + +} From 802973450b7890e74351928557f72c3f32d3ec58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Sun, 6 Aug 2023 01:52:38 +0900 Subject: [PATCH 44/47] =?UTF-8?q?test:=20PostServiceTest=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/application/PostServiceTest.java | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 src/test/java/dev/jpaboard/post/application/PostServiceTest.java diff --git a/src/test/java/dev/jpaboard/post/application/PostServiceTest.java b/src/test/java/dev/jpaboard/post/application/PostServiceTest.java new file mode 100644 index 000000000..60c9c2632 --- /dev/null +++ b/src/test/java/dev/jpaboard/post/application/PostServiceTest.java @@ -0,0 +1,164 @@ +package dev.jpaboard.post.application; + +import dev.jpaboard.common.exception.ForbiddenException; +import dev.jpaboard.post.domain.Post; +import dev.jpaboard.post.dto.PostCreateRequest; +import dev.jpaboard.post.dto.PostResponse; +import dev.jpaboard.post.dto.PostUpdateRequest; +import dev.jpaboard.post.dto.PostsResponse; +import dev.jpaboard.post.exception.PostNotFoundException; +import dev.jpaboard.post.repository.PostRepository; +import dev.jpaboard.user.domain.User; +import dev.jpaboard.user.repository.UserRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.PageRequest; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertFalse; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) +class PostServiceTest { + + private static final String 제목 = "제목"; + private static final String 내용 = "내용"; + + @Autowired + private UserRepository userRepository; + + @Autowired + private PostService postService; + + @Autowired + private PostRepository postRepository; + + private User user; + private Post post; + + @BeforeEach + void setUp() { + postRepository.deleteAllInBatch(); + userRepository.deleteAllInBatch(); + user = savedUser(); + post = savedPost(user); + } + + @DisplayName("유저가 존재할 경우 게시물을 생성할 수 있다.") + @Test + void createPostTest() { + Long userId = user.getId(); + + PostCreateRequest request = new PostCreateRequest(제목, 내용); + + PostResponse response = postService.create(request, userId); + + assertAll( + () -> assertThat(response.title()).isEqualTo(제목), + () -> assertThat(response.content()).isEqualTo(내용) + ); + } + + @DisplayName("게시물을 생성한 유저 아이디와 수정할 유저 아이디가 같을 경우 게시물을 수정할 수 있다.") + @Test + void updatePostTest() { + Long userId = user.getId(); + Long postId = post.getId(); + + postService.update(postId, new PostUpdateRequest(제목, 내용), userId); + + Post findPost = postRepository.findById(postId).get(); + assertAll( + () -> assertThat(findPost.getTitle()).isEqualTo(제목), + () -> assertThat(findPost.getContent()).isEqualTo(내용) + ); + } + + @DisplayName("존재하는 게시물 아이디를 입력할 경우 게시물을 조회할 수 있다.") + @Test + void findPostTest() { + Long postId = post.getId(); + + PostResponse findPost = postService.findPost(postId); + + assertAll( + () -> assertThat(findPost.title()).isEqualTo(제목), + () -> assertThat(findPost.content()).isEqualTo(내용) + ); + } + + @DisplayName("모든 게시물을 페이징으로 조회할 수 있다.") + @Test + void findAllTest() { + Long userId = user.getId(); + + PostCreateRequest request1 = new PostCreateRequest("제목", "내용"); + PostCreateRequest request2 = new PostCreateRequest("제목2", "내용2"); + PostCreateRequest request3 = new PostCreateRequest("제목3", "내용3"); + postService.create(request1, userId); + postService.create(request2, userId); + postService.create(request3, userId); + + PostsResponse allPosts = postService.findAll(PageRequest.of(0, 2)); + + assertThat(allPosts.totalPages()).isEqualTo(2); + } + + @DisplayName("존재하는 게시물 아이디와 해당 게시물을 생성한 유저 아이디를 입력할 경우 게시물을 삭제할 수 있다.") + @Test + void deletePostTest() { + Long userId = user.getId(); + Long postId = post.getId(); + postService.delete(postId, userId); + + Optional findPost = postRepository.findById(postId); + + assertFalse(findPost.isPresent()); + } + + @DisplayName("해당 게시물을 생성한 유저 아이디와 다른 유저 아이디를 입력할 경우 게시물을 수정할 수 없다.") + @Test + void updateFailByUserIdTest() { + Long postId = post.getId(); + + assertThatThrownBy(() -> postService.update(postId, new PostUpdateRequest("title", "content"), 102938297928461204L)) + .isInstanceOf(ForbiddenException.class); + } + + @DisplayName("존재하지 않는 게시물 아이디를 입력할 경우 게시물을 수정할 수 없다.") + @Test + void updateFailByPostIdTest() { + Long userId = user.getId(); + + assertThatThrownBy(() -> postService.update(1230984576L, new PostUpdateRequest("title", "content"), userId)) + .isInstanceOf(PostNotFoundException.class); + } + + private User savedUser() { + User user = User.builder() + .email("qkrdmswl1018@naver.com") + .password("QWert123?") + .name("name") + .age(23) + .hobby("hobby") + .build(); + + return userRepository.save(user); + } + + private Post savedPost(User user) { + Post post = Post.builder() + .title(제목) + .content(내용) + .user(user) + .build(); + return postRepository.save(post); + } + +} From 0be4727a5f93b448e0fb708cf32ec407d872ae4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Mon, 7 Aug 2023 16:45:51 +0900 Subject: [PATCH 45/47] =?UTF-8?q?refactor:=20=EB=B0=98=EC=98=81=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EC=BB=A4=EB=B0=8B=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++- .../java/dev/jpaboard/common/config/JpaConfig.java | 1 - .../java/dev/jpaboard/post/api/PostController.java | 5 ++--- src/main/java/dev/jpaboard/post/domain/Post.java | 1 + src/main/java/dev/jpaboard/post/dto/PostResponse.java | 7 +------ .../java/dev/jpaboard/user/api/UserController.java | 8 +++++--- src/main/resources/application.yml | 10 +++++++++- src/test/java/dev/jpaboard/ControllerTest.java | 7 +++++++ .../java/dev/jpaboard/post/PostControllerTest.java | 2 +- 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index c2fc8257f..5af4099e1 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,7 @@ tasks.withType(GenerateSwaggerUI) { dependsOn 'openapi3' delete file('src/main/resources/static/docs/') + delete file('build/generated-snippets') copy { from "build/resources/main/static/docs" into "src/main/resources/static/docs/" @@ -80,5 +81,5 @@ openapi3 { } bootJar { - dependsOn(':openapi3') + dependsOn 'openapi3' } \ No newline at end of file diff --git a/src/main/java/dev/jpaboard/common/config/JpaConfig.java b/src/main/java/dev/jpaboard/common/config/JpaConfig.java index 1532fcdf3..b1b7fcd62 100644 --- a/src/main/java/dev/jpaboard/common/config/JpaConfig.java +++ b/src/main/java/dev/jpaboard/common/config/JpaConfig.java @@ -7,5 +7,4 @@ @EnableJpaAuditing public class JpaConfig { - } diff --git a/src/main/java/dev/jpaboard/post/api/PostController.java b/src/main/java/dev/jpaboard/post/api/PostController.java index dbdbad9a6..dd32638f4 100644 --- a/src/main/java/dev/jpaboard/post/api/PostController.java +++ b/src/main/java/dev/jpaboard/post/api/PostController.java @@ -33,9 +33,8 @@ public class PostController { @PostMapping @ResponseStatus(CREATED) - public PostResponse create(@RequestBody PostCreateRequest request, - @SessionAttribute(name = "userId", required = false) Long userId) { - validateUserId(userId); + public PostResponse createPost(@Valid @RequestBody PostCreateRequest request, + @SessionAttribute(name = "userId") Long userId) { return postService.create(request, userId); } diff --git a/src/main/java/dev/jpaboard/post/domain/Post.java b/src/main/java/dev/jpaboard/post/domain/Post.java index 2c3843eea..3ac933894 100644 --- a/src/main/java/dev/jpaboard/post/domain/Post.java +++ b/src/main/java/dev/jpaboard/post/domain/Post.java @@ -63,4 +63,5 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(id); } + } diff --git a/src/main/java/dev/jpaboard/post/dto/PostResponse.java b/src/main/java/dev/jpaboard/post/dto/PostResponse.java index 63e0e6dc2..f8e7c74fb 100644 --- a/src/main/java/dev/jpaboard/post/dto/PostResponse.java +++ b/src/main/java/dev/jpaboard/post/dto/PostResponse.java @@ -1,16 +1,11 @@ package dev.jpaboard.post.dto; import dev.jpaboard.post.domain.Post; -import lombok.Builder; -@Builder public record PostResponse(String title, String content) { public static PostResponse from(Post post) { - return PostResponse.builder() - .title(post.getTitle()) - .content(post.getContent()) - .build(); + return new PostResponse(post.getTitle(), post.getContent()); } } diff --git a/src/main/java/dev/jpaboard/user/api/UserController.java b/src/main/java/dev/jpaboard/user/api/UserController.java index ed8eb8529..6e0e69787 100644 --- a/src/main/java/dev/jpaboard/user/api/UserController.java +++ b/src/main/java/dev/jpaboard/user/api/UserController.java @@ -27,9 +27,11 @@ public UserInfoResponse findUser(@SessionAttribute(name = "userId") Long userId) return userService.findUser(userId); } - @GetMapping("/me") - public UserResponse findUser(@SessionAttribute(name = "userId") Long userId) { - return userService.findUser(userId); + @PatchMapping + @ResponseStatus(NO_CONTENT) + public void updateUser(@RequestBody UserUpdateRequest request, + @SessionAttribute(name = "userId") Long userId) { + userService.update(request, userId); } @DeleteMapping("/me") diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 187a59d6c..0d4c8aba7 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,4 +10,12 @@ spring: properties: hibernate: format_sql: true - show-sql: true \ No newline at end of file + show-sql: true + +--- +springdoc: + default-consumes-media-type: application/json;charset=UTF-8 + default-produces-media-type: application/json;charset=UTF-8 + swagger-ui: + url: /docs/jpa-board.json + path: /docs/swagger \ No newline at end of file diff --git a/src/test/java/dev/jpaboard/ControllerTest.java b/src/test/java/dev/jpaboard/ControllerTest.java index 9856d6e41..34442afcc 100644 --- a/src/test/java/dev/jpaboard/ControllerTest.java +++ b/src/test/java/dev/jpaboard/ControllerTest.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.mock.web.MockHttpSession; import org.springframework.restdocs.RestDocumentationContextProvider; import org.springframework.restdocs.RestDocumentationExtension; import org.springframework.test.web.servlet.MockMvc; @@ -20,8 +21,12 @@ @ExtendWith({RestDocumentationExtension.class}) public abstract class ControllerTest { + protected static final String SESSION_KEY_VALUE = "userId"; + protected static final long SESSION_USERID_VALUE = 1L; protected ObjectMapper objectMapper = new ObjectMapper(); + protected MockHttpSession session = new MockHttpSession(); + protected MockMvc mockMvc; @BeforeEach @@ -31,6 +36,8 @@ void setUp(WebApplicationContext ctx, RestDocumentationContextProvider restDocum .addFilters(new CharacterEncodingFilter("UTF-8", true)) .alwaysDo(print()) .build(); + + session.setAttribute(SESSION_KEY_VALUE, SESSION_USERID_VALUE); } } diff --git a/src/test/java/dev/jpaboard/post/PostControllerTest.java b/src/test/java/dev/jpaboard/post/PostControllerTest.java index 8a587ab66..bb2d6426d 100644 --- a/src/test/java/dev/jpaboard/post/PostControllerTest.java +++ b/src/test/java/dev/jpaboard/post/PostControllerTest.java @@ -43,7 +43,7 @@ public class PostControllerTest extends ControllerTest { @MockBean - PostService postService; + private PostService postService; @DisplayName("로그인한 유저는 게시물을 생성할 수 있다.") @Test From fec17f45aeac352f770cdbd7823bd3819128212d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Mon, 7 Aug 2023 17:06:15 +0900 Subject: [PATCH 46/47] =?UTF-8?q?refactor:=20equals()=EC=99=80=20hashCode(?= =?UTF-8?q?)=20=EC=9E=AC=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/dev/jpaboard/user/domain/Email.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/dev/jpaboard/user/domain/Email.java b/src/main/java/dev/jpaboard/user/domain/Email.java index 1bcec9591..5ec9b3580 100644 --- a/src/main/java/dev/jpaboard/user/domain/Email.java +++ b/src/main/java/dev/jpaboard/user/domain/Email.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.Objects; import java.util.regex.Pattern; @Embeddable @@ -28,5 +29,16 @@ private void validateEmail(String userEmail) throws InvalidEmailException { } } -} + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Email email1)) return false; + return Objects.equals(email, email1.email); + } + @Override + public int hashCode() { + return Objects.hash(email); + } + +} From d84a00ae0b89ddeebbffb0baa25394d46253b5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=8B=E1=85=B3=E1=86=AB?= =?UTF-8?q?=E1=84=8C=E1=85=B5?= Date: Mon, 7 Aug 2023 17:13:21 +0900 Subject: [PATCH 47/47] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/jpaboard/post/PostControllerTest.java | 2 -- .../post/application/PostServiceTest.java | 4 +-- .../user/application/UserServiceTest.java | 9 +++-- .../user/repository/UserRepositoryTest.java | 35 ------------------- 4 files changed, 9 insertions(+), 41 deletions(-) delete mode 100644 src/test/java/dev/jpaboard/user/repository/UserRepositoryTest.java diff --git a/src/test/java/dev/jpaboard/post/PostControllerTest.java b/src/test/java/dev/jpaboard/post/PostControllerTest.java index bb2d6426d..bc8aa6249 100644 --- a/src/test/java/dev/jpaboard/post/PostControllerTest.java +++ b/src/test/java/dev/jpaboard/post/PostControllerTest.java @@ -14,7 +14,6 @@ import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpSession; import org.springframework.restdocs.payload.JsonFieldType; -import org.springframework.test.context.ActiveProfiles; import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.resourceDetails; @@ -39,7 +38,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @WebMvcTest(PostController.class) -@ActiveProfiles("test") public class PostControllerTest extends ControllerTest { @MockBean diff --git a/src/test/java/dev/jpaboard/post/application/PostServiceTest.java b/src/test/java/dev/jpaboard/post/application/PostServiceTest.java index 60c9c2632..ec1344124 100644 --- a/src/test/java/dev/jpaboard/post/application/PostServiceTest.java +++ b/src/test/java/dev/jpaboard/post/application/PostServiceTest.java @@ -44,8 +44,8 @@ class PostServiceTest { @BeforeEach void setUp() { - postRepository.deleteAllInBatch(); - userRepository.deleteAllInBatch(); + postRepository.deleteAll(); + userRepository.deleteAll(); user = savedUser(); post = savedPost(user); } diff --git a/src/test/java/dev/jpaboard/user/application/UserServiceTest.java b/src/test/java/dev/jpaboard/user/application/UserServiceTest.java index 311fb3765..57e87c7a0 100644 --- a/src/test/java/dev/jpaboard/user/application/UserServiceTest.java +++ b/src/test/java/dev/jpaboard/user/application/UserServiceTest.java @@ -1,5 +1,6 @@ package dev.jpaboard.user.application; +import dev.jpaboard.post.repository.PostRepository; import dev.jpaboard.user.domain.User; import dev.jpaboard.user.dto.request.UserUpdateRequest; import dev.jpaboard.user.dto.response.UserInfoResponse; @@ -18,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertFalse; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) +@SpringBootTest class UserServiceTest { private static final String 이메일 = "qkrdmswl1018@naver.com"; @@ -33,11 +34,15 @@ class UserServiceTest { @Autowired private UserRepository userRepository; + @Autowired + private PostRepository postRepository; + private User user; @BeforeEach void setUp() { - userRepository.deleteAllInBatch(); + postRepository.deleteAll(); + userRepository.deleteAll(); user = savedUser(); } diff --git a/src/test/java/dev/jpaboard/user/repository/UserRepositoryTest.java b/src/test/java/dev/jpaboard/user/repository/UserRepositoryTest.java deleted file mode 100644 index c6877d1ea..000000000 --- a/src/test/java/dev/jpaboard/user/repository/UserRepositoryTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.jpaboard.user.repository; - -import dev.jpaboard.user.domain.Email; -import dev.jpaboard.user.domain.Password; -import dev.jpaboard.user.domain.User; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; - -import java.util.Optional; - -@DataJpaTest -class UserRepositoryTest { - - @Autowired - private UserRepository userRepository; - - @Test - void test() { - User user = User.builder() - .email("qkrdmswl1018@naner.com") - .password("Qwqer123?") - .name("박은지") - .age(23) - .hobby("산책") - .build(); - userRepository.save(user); - - User findUser = userRepository.findByEmailAndPassword(new Email("qkrdmswl1018@naner.com"), new Password("Qwqer123?")).get(); - System.out.println(String.format("Email: %s, Password: %s", findUser.getEmail(), findUser.getPassword())); - } - -} \ No newline at end of file