diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..8af972cde --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/.gitignore b/.gitignore index 7cb6b1c91..c2065bc26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,11 @@ +HELP.md .gradle build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -.idea -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### +### STS ### .apt_generated .classpath .factorypath @@ -29,6 +17,15 @@ bin/ !**/src/main/**/bin/ !**/src/test/**/bin/ +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + ### NetBeans ### /nbproject/private/ /nbbuild/ @@ -38,6 +35,3 @@ bin/ ### VS Code ### .vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 000000000..815bede54 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# 0-spring-mission +스프린트 미션 모범 답안 리포지토리입니다. diff --git a/build.gradle b/build.gradle index 668101a29..c192c557d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,46 @@ plugins { - id 'java' + id 'java' + id 'org.springframework.boot' version '3.4.4' + id 'io.spring.dependency-management' version '1.1.7' } group = 'com.sprint.mission' -version = '1.0-SNAPSHOT' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} repositories { - mavenCentral() + mavenCentral() } dependencies { - testImplementation platform('org.junit:junit-bom:5.10.0') - testImplementation 'org.junit.jupiter:junit-jupiter' + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + // JUnit 의존성 (JUnit 5) + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.0' + + // Mockito 의존성 + testImplementation 'org.mockito:mockito-core:3.9.0' + + // Spring Boot Test 의존성 + testImplementation 'org.springframework.boot:spring-boot-starter-test' } -test { - useJUnitPlatform() -} \ No newline at end of file +tasks.named('test') { + useJUnitPlatform() +} diff --git a/dfsad b/dfsad new file mode 100644 index 000000000..414e138bd --- /dev/null +++ b/dfsad @@ -0,0 +1,31 @@ + origin/임정현 + origin/임정현-sprint1 + upstream/HEAD -> upstream/main + upstream/main + upstream/revert-34-이채원 + upstream/강문구 + upstream/강우진 + upstream/강호 + upstream/고희준 + upstream/김동욱 + upstream/김민준 + upstream/김유빈 + upstream/김하연 + upstream/김현기 + upstream/박인규 + upstream/박진솔 + upstream/박현준 + upstream/백은호 + upstream/안여경 + upstream/이건민 + upstream/이승진 + upstream/이주용 + upstream/이지현 + upstream/이채원 + upstream/임정현 + upstream/정윤지 + upstream/조백선 + upstream/조재구 + upstream/조현아 + upstream/한동우 + upstream/황지인 diff --git a/discodeit/.gitattributes b/discodeit/.gitattributes new file mode 100644 index 000000000..8af972cde --- /dev/null +++ b/discodeit/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/discodeit/.gitignore b/discodeit/.gitignore new file mode 100644 index 000000000..c2065bc26 --- /dev/null +++ b/discodeit/.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/discodeit/build.gradle b/discodeit/build.gradle new file mode 100644 index 000000000..1c8b5c58f --- /dev/null +++ b/discodeit/build.gradle @@ -0,0 +1,36 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.4.4' + id 'io.spring.dependency-management' version '1.1.7' +} + +group = 'com.sprint.mission' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/discodeit/gradle/wrapper/gradle-wrapper.jar b/discodeit/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..9bbc975c7 Binary files /dev/null and b/discodeit/gradle/wrapper/gradle-wrapper.jar differ diff --git a/discodeit/gradle/wrapper/gradle-wrapper.properties b/discodeit/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..37f853b1c --- /dev/null +++ b/discodeit/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/discodeit/gradlew b/discodeit/gradlew new file mode 100644 index 000000000..faf93008b --- /dev/null +++ b/discodeit/gradlew @@ -0,0 +1,251 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$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=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + 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/discodeit/gradlew.bat b/discodeit/gradlew.bat new file mode 100644 index 000000000..9d21a2183 --- /dev/null +++ b/discodeit/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%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/discodeit/settings.gradle b/discodeit/settings.gradle new file mode 100644 index 000000000..2437dfb29 --- /dev/null +++ b/discodeit/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'discodeit' diff --git a/discodeit/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java b/discodeit/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java new file mode 100644 index 000000000..360245c48 --- /dev/null +++ b/discodeit/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java @@ -0,0 +1,13 @@ +package com.sprint.mission.discodeit; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DiscodeitApplication { + + public static void main(String[] args) { + SpringApplication.run(DiscodeitApplication.class, args); + } + +} diff --git a/discodeit/src/main/resources/application.properties b/discodeit/src/main/resources/application.properties new file mode 100644 index 000000000..545cf9f09 --- /dev/null +++ b/discodeit/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=discodeit diff --git a/discodeit/src/test/java/com/sprint/mission/discodeit/DiscodeitApplicationTests.java b/discodeit/src/test/java/com/sprint/mission/discodeit/DiscodeitApplicationTests.java new file mode 100644 index 000000000..3a987a214 --- /dev/null +++ b/discodeit/src/test/java/com/sprint/mission/discodeit/DiscodeitApplicationTests.java @@ -0,0 +1,13 @@ +package com.sprint.mission.discodeit; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DiscodeitApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/file-data-map/Channel/4ca4422b-51d4-47ed-b774-dce4d5ee91db.ser b/file-data-map/Channel/4ca4422b-51d4-47ed-b774-dce4d5ee91db.ser new file mode 100644 index 000000000..a2c074fd8 Binary files /dev/null and b/file-data-map/Channel/4ca4422b-51d4-47ed-b774-dce4d5ee91db.ser differ diff --git a/file-data-map/Channel/7fe05d90-a1e3-4212-8c78-3097817310a1.ser b/file-data-map/Channel/7fe05d90-a1e3-4212-8c78-3097817310a1.ser new file mode 100644 index 000000000..2f787ca17 Binary files /dev/null and b/file-data-map/Channel/7fe05d90-a1e3-4212-8c78-3097817310a1.ser differ diff --git a/file-data-map/Channel/b72bb445-2b1c-40c0-af25-da60c7ecb26c.ser b/file-data-map/Channel/b72bb445-2b1c-40c0-af25-da60c7ecb26c.ser new file mode 100644 index 000000000..1925d5581 Binary files /dev/null and b/file-data-map/Channel/b72bb445-2b1c-40c0-af25-da60c7ecb26c.ser differ diff --git a/file-data-map/Channel/b8eae8a7-7210-4c0c-81ac-bbca581f350d.ser b/file-data-map/Channel/b8eae8a7-7210-4c0c-81ac-bbca581f350d.ser new file mode 100644 index 000000000..28390f8cc Binary files /dev/null and b/file-data-map/Channel/b8eae8a7-7210-4c0c-81ac-bbca581f350d.ser differ diff --git a/file-data-map/Channel/c2dd8093-e891-4976-946e-307f6675e87b.ser b/file-data-map/Channel/c2dd8093-e891-4976-946e-307f6675e87b.ser new file mode 100644 index 000000000..de7fb9b6f Binary files /dev/null and b/file-data-map/Channel/c2dd8093-e891-4976-946e-307f6675e87b.ser differ diff --git a/file-data-map/Channel/d8467d13-df0b-4a78-acd1-d7ae24158f43.ser b/file-data-map/Channel/d8467d13-df0b-4a78-acd1-d7ae24158f43.ser new file mode 100644 index 000000000..5bda281cf Binary files /dev/null and b/file-data-map/Channel/d8467d13-df0b-4a78-acd1-d7ae24158f43.ser differ diff --git a/file-data-map/Channel/f3f88d0b-e423-41bc-ac91-5990407183cc.ser b/file-data-map/Channel/f3f88d0b-e423-41bc-ac91-5990407183cc.ser new file mode 100644 index 000000000..3d2aaec16 Binary files /dev/null and b/file-data-map/Channel/f3f88d0b-e423-41bc-ac91-5990407183cc.ser differ diff --git a/file-data-map/Message/1d3e6587-5e90-41d8-a496-3eacf74ff748.ser b/file-data-map/Message/1d3e6587-5e90-41d8-a496-3eacf74ff748.ser new file mode 100644 index 000000000..af192f2d4 Binary files /dev/null and b/file-data-map/Message/1d3e6587-5e90-41d8-a496-3eacf74ff748.ser differ diff --git a/file-data-map/Message/2cabd690-34eb-485b-b3a6-16e44e65220f.ser b/file-data-map/Message/2cabd690-34eb-485b-b3a6-16e44e65220f.ser new file mode 100644 index 000000000..d7dafbaf8 Binary files /dev/null and b/file-data-map/Message/2cabd690-34eb-485b-b3a6-16e44e65220f.ser differ diff --git a/file-data-map/Message/89a6aba5-3322-4623-89bd-5d6be9e55672.ser b/file-data-map/Message/89a6aba5-3322-4623-89bd-5d6be9e55672.ser new file mode 100644 index 000000000..bd33b40d1 Binary files /dev/null and b/file-data-map/Message/89a6aba5-3322-4623-89bd-5d6be9e55672.ser differ diff --git a/file-data-map/Message/a0c90d4f-20af-4ca9-81cf-dd11c10fdd47.ser b/file-data-map/Message/a0c90d4f-20af-4ca9-81cf-dd11c10fdd47.ser new file mode 100644 index 000000000..5e9849469 Binary files /dev/null and b/file-data-map/Message/a0c90d4f-20af-4ca9-81cf-dd11c10fdd47.ser differ diff --git a/file-data-map/Message/eebc2575-62bc-4651-b4d8-fa6af3feca78.ser b/file-data-map/Message/eebc2575-62bc-4651-b4d8-fa6af3feca78.ser new file mode 100644 index 000000000..c0eddf49e Binary files /dev/null and b/file-data-map/Message/eebc2575-62bc-4651-b4d8-fa6af3feca78.ser differ diff --git a/file-data-map/Message/f96f31b5-ec61-4862-a0eb-3bd8647e4b93.ser b/file-data-map/Message/f96f31b5-ec61-4862-a0eb-3bd8647e4b93.ser new file mode 100644 index 000000000..1be7ea7c4 Binary files /dev/null and b/file-data-map/Message/f96f31b5-ec61-4862-a0eb-3bd8647e4b93.ser differ diff --git a/file-data-map/Message/fde0b2ed-c0a2-47d8-8d8d-6844e1b73460.ser b/file-data-map/Message/fde0b2ed-c0a2-47d8-8d8d-6844e1b73460.ser new file mode 100644 index 000000000..0014df33b Binary files /dev/null and b/file-data-map/Message/fde0b2ed-c0a2-47d8-8d8d-6844e1b73460.ser differ diff --git a/file-data-map/User/0cfcbd0d-cea9-4ee4-aa79-2948b75ec2a9.ser b/file-data-map/User/0cfcbd0d-cea9-4ee4-aa79-2948b75ec2a9.ser new file mode 100644 index 000000000..bea9b9ef4 Binary files /dev/null and b/file-data-map/User/0cfcbd0d-cea9-4ee4-aa79-2948b75ec2a9.ser differ diff --git a/file-data-map/User/0eeacc64-b05a-444b-adc1-d59adb39f3d7.ser b/file-data-map/User/0eeacc64-b05a-444b-adc1-d59adb39f3d7.ser new file mode 100644 index 000000000..ae61e9ebf Binary files /dev/null and b/file-data-map/User/0eeacc64-b05a-444b-adc1-d59adb39f3d7.ser differ diff --git a/file-data-map/User/1e432f56-783c-4f92-9fe4-7c473a66bca5.ser b/file-data-map/User/1e432f56-783c-4f92-9fe4-7c473a66bca5.ser new file mode 100644 index 000000000..563991818 Binary files /dev/null and b/file-data-map/User/1e432f56-783c-4f92-9fe4-7c473a66bca5.ser differ diff --git a/file-data-map/User/552b16ea-3adb-47d3-949b-ffdd1273a483.ser b/file-data-map/User/552b16ea-3adb-47d3-949b-ffdd1273a483.ser new file mode 100644 index 000000000..469ea5c7e Binary files /dev/null and b/file-data-map/User/552b16ea-3adb-47d3-949b-ffdd1273a483.ser differ diff --git a/file-data-map/User/5fe1cf6c-2722-4367-b7e3-632e08462029.ser b/file-data-map/User/5fe1cf6c-2722-4367-b7e3-632e08462029.ser new file mode 100644 index 000000000..639580197 Binary files /dev/null and b/file-data-map/User/5fe1cf6c-2722-4367-b7e3-632e08462029.ser differ diff --git a/file-data-map/User/645179ee-c4ce-4175-b845-f13a08ddc8b6.ser b/file-data-map/User/645179ee-c4ce-4175-b845-f13a08ddc8b6.ser new file mode 100644 index 000000000..b35a2cd31 Binary files /dev/null and b/file-data-map/User/645179ee-c4ce-4175-b845-f13a08ddc8b6.ser differ diff --git a/file-data-map/User/7cb19da7-e036-4381-91e3-b353b0d1fae1.ser b/file-data-map/User/7cb19da7-e036-4381-91e3-b353b0d1fae1.ser new file mode 100644 index 000000000..9ec9c6637 Binary files /dev/null and b/file-data-map/User/7cb19da7-e036-4381-91e3-b353b0d1fae1.ser differ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e5832f..9bbc975c7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f3afae7b7..37f853b1c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Thu Apr 10 09:38:34 KST 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c78733..faf93008b 100644 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +133,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +200,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +216,12 @@ set -- \ 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. diff --git a/gradlew.bat b/gradlew.bat index 107acd32c..9d21a2183 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +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. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +59,11 @@ 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. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +78,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +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! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +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 diff --git a/settings.gradle b/settings.gradle index 79373e364..2437dfb29 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1 @@ -rootProject.name = '3-sprint-mission' - +rootProject.name = 'discodeit' diff --git a/src/main/java/com/sprint/mission/discodeit/AppConfig.java b/src/main/java/com/sprint/mission/discodeit/AppConfig.java new file mode 100644 index 000000000..d50e5e695 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/AppConfig.java @@ -0,0 +1,52 @@ +package com.sprint.mission.discodeit; + +import com.sprint.mission.discodeit.repository.ChannelRepository; +import com.sprint.mission.discodeit.repository.MessageRepository; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.repository.file.FileChannelRepository; +import com.sprint.mission.discodeit.repository.file.FileMessageRepository; +import com.sprint.mission.discodeit.repository.file.FileUserRepository; +import com.sprint.mission.discodeit.service.basic.BasicChannelService; +import com.sprint.mission.discodeit.service.basic.BasicMessageService; +import com.sprint.mission.discodeit.service.basic.BasicUserService; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +//@Configuration +//@ComponentScan(basePackages = "com.example") // ComponentScan 예시 +//public class AutoAppConfig { +//} + +@Configuration +public class AppConfig { + + @Bean + public UserRepository userRepository() { + return new FileUserRepository(); + } + + @Bean + public BasicUserService basicUserService() { + return new BasicUserService(userRepository()); + } + + @Bean + public ChannelRepository channelRepository() { + return new FileChannelRepository(); + } + + @Bean + public BasicChannelService basicChannelService() { + return new BasicChannelService(channelRepository()); + } + + @Bean + public MessageRepository messageRepository() { + return new FileMessageRepository(); + } + + @Bean + public BasicMessageService basicMessageService() { + return new BasicMessageService(messageRepository(), channelRepository(), userRepository()); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java b/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java new file mode 100644 index 000000000..e5ab6ee69 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java @@ -0,0 +1,50 @@ +package com.sprint.mission.discodeit; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.service.ChannelService; +import com.sprint.mission.discodeit.service.MessageService; +import com.sprint.mission.discodeit.service.UserService; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +@SpringBootApplication +public class DiscodeitApplication { + +// static User setupUser(UserService userService) { +// User user = userService.create("woody", "woody@codeit.com", "woody1234"); +// return user; +// } + + static Channel setupChannel(ChannelService channelService) { + Channel channel = channelService.create(ChannelType.PUBLIC, "공지", "공지 채널입니다."); + return channel; + } + + static void messageCreateTest(MessageService messageService, Channel channel, User author) { + Message message = messageService.create("안녕하세요.", channel.getId(), author.getId()); + System.out.println("메시지 생성: " + message.getId()); + } + + + public static void main(String[] args) { + SpringApplication.run(DiscodeitApplication.class, args); + + // 서비스 초기화 + ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); + ChannelService channelService = (ChannelService) context.getBean("basicChannelService"); + UserService userService = (UserService) context.getBean("basicUserService"); + MessageService messageService = (MessageService) context.getBean("basicMessageService"); + + // 셋업 + User user = setupUser(userService); + Channel channel = setupChannel(channelService); + // 테스트 + messageCreateTest(messageService, channel, user); + } + +} diff --git a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java index 4a2b3086b..0212c409f 100644 --- a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -1,182 +1,59 @@ package com.sprint.mission.discodeit; -import com.sprint.mission.discodeit.entity.Message; import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; +import com.sprint.mission.discodeit.entity.Message; import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import com.sprint.mission.discodeit.repository.MessageRepository; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.repository.file.FileChannelRepository; +import com.sprint.mission.discodeit.repository.file.FileMessageRepository; +import com.sprint.mission.discodeit.repository.file.FileUserRepository; import com.sprint.mission.discodeit.service.ChannelService; import com.sprint.mission.discodeit.service.MessageService; import com.sprint.mission.discodeit.service.UserService; -import com.sprint.mission.discodeit.service.jcf.JCFChannelService; -import com.sprint.mission.discodeit.service.jcf.JCFMessageService; -import com.sprint.mission.discodeit.service.jcf.JCFUserService; - -import java.util.*; +import com.sprint.mission.discodeit.service.basic.BasicChannelService; +import com.sprint.mission.discodeit.service.basic.BasicMessageService; +import com.sprint.mission.discodeit.service.basic.BasicUserService; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class JavaApplication { - static void userCRUDTest(UserService UserService) { // UserService 객체를 파라미터로 받음 - // User 생성 - User user1 = UserService.createUser("111111-2222222", "Alice", 20, "alice@gmail.com"); - System.out.println("user1 생성: " + user1.getId()); - User user2 = UserService.createUser("111111-2223333", "John", 25, "john@gmail.com"); - System.out.println("user2 생성: " + user2.getId()); - User user3 = UserService.createUser("111111-2224444", "Steve", 30, "steve@gmail.com"); - System.out.println("user3 생성: " + user3.getId()); - - // User 조회 - User readingUser1 = UserService.foundUser(user1.getId()); - System.out.println("user1 조회: " + readingUser1.getId()); - User readingUser2 = UserService.foundUser(user2.getId()); - System.out.println("user2 조회: " + readingUser2.getId()); - User readingUser3 = UserService.foundUser(user3.getId()); - System.out.println("user3 조회: " + readingUser3.getId()); - - // 모든 User 조회 - List readAllUsers = UserService.readAllUsers(); - System.out.println("\n전체 유저 조회: " + readAllUsers.size()); - - // User 수정 - User updatingUser1 = UserService.updateUser(user1.getId(), null, "alice@naver.com"); - System.out.println("user1 email 수정: " + String.join(",", updatingUser1.getEmail())); - User updatingUser2 = UserService.updateUser(user2.getId(), "Johnny", null); - System.out.println("user2 name, email 수정: " + String.join(",", updatingUser2.getName())); - User updatingUser3 = UserService.updateUser(user3.getId(), "Wonder", "steve@yahoo.co.kr"); - System.out.println("user3 name, email 수정: " + String.join(",", updatingUser2.getName(), updatingUser2.getEmail())); - - // 수정 후 User 조회 - List readUpdatedAllUsers = UserService.readAllUsers(); - System.out.println("\n수정 후 유저 조회: " + readUpdatedAllUsers.size()); - - // User 삭제 - UserService.deleteUser(user1.getId()); - List readUsersAfterDelete = UserService.readAllUsers(); - System.out.println("\nuser1 삭제: " + readUsersAfterDelete.size()); -// userService.deleteUser(user2.getId()); -// System.out.println("user2 삭제: " + readUsersAfterDelete.size()); -// userService.deleteUser(user3.getId()); -// System.out.println("user3 삭제: " + readUsersAfterDelete.size()); - - // 삭제 후 User 조회 - List readAfterDeletedAllUsers = UserService.readAllUsers(); - System.out.println("\n삭제 후 유저 조회: " + readAfterDeletedAllUsers.size()); - - - System.out.println("User CRUD Test Completed"); - } - - - static void channelCRUDTest(ChannelService channelService) { // ChannelService 객체를 파라미터로 받음 - // Channel 생성 - Channel channel1 = channelService.createChannel("여자친구", "사랑방"); - System.out.println("channel1 생성: " + channel1.getId()); - Channel channel2 = channelService.createChannel("엄마", "안부방" ); - System.out.println("channel2 생성: " + channel2.getId()); - Channel channel3 = channelService.createChannel("아빠", "위로방" ); - System.out.println("channel3 생성: " + channel3.getId()); - - // Channel 조회 - Channel readingChannel1 = channelService.readChannel(channel1.getId()); - System.out.println("channel1 조회: " + readingChannel1.getId()); - Channel readingChannel2 = channelService.readChannel(channel2.getId()); - System.out.println("channel2 조회: " + readingChannel2.getId()); - Channel readingChannel3 = channelService.readChannel(channel3.getId()); - System.out.println("channel3 조회: " + readingChannel3.getId()); - - // 모든 Channel 조회 - List readAllChannels = channelService.readAllChannels(); - System.out.println("채널 조회: " + readAllChannels.size()); - - // Channel 수정 - Channel updatingChannel1 = channelService.updateChannel(channel1.getId(), null, "찐사랑방"); - System.out.println("channel1 description 수정: " + String.join(",", updatingChannel1.getDescription())); - Channel updatingChannel2 = channelService.updateChannel(channel2.getId(), "아버지", null); - System.out.println("channel2 name 수정: " + String.join(",", updatingChannel2.getChannelName())); - Channel updatingChannel3 = channelService.updateChannel(channel3.getId(), "어머니", "위로방"); - System.out.println("channel3 name, description 수정: " + String.join(",", updatingChannel3.getChannelName(), updatingChannel3.getDescription())); - - // User 삭제 - channelService.deleteChannel(channel1.getId()); - List readChannelsAfterDelete = channelService.readAllChannels(); - System.out.println("channel1 삭제: " + readChannelsAfterDelete.size()); -// channelService.deleteChannel(channel2.getId()); -// System.out.println("channel2 삭제: " + readChannelsAfterDelete.size()); -// channelService.deleteChannel(channel3.getId()); -// System.out.println("channel3 삭제: " + readChannelsAfterDelete.size()); - - System.out.println("Channel CRUD Test Completed"); - } - - static void messageCRUDTest(MessageService messageService) { // MessageService 객체를 파라미터로 받음 - // 단독 테스트를 하려면 channelId와 authorId가 필요함 - UUID channelId = UUID.randomUUID(); - UUID authorId = UUID.randomUUID(); - // Message 생성 - Message message1 = messageService.createMessage("나는 너를 정말 사랑해", channelId, authorId); - System.out.println("message1 생성: " + message1.getId()); - Message message2 = messageService.createMessage("나는 너를 정말 애정해", channelId, authorId); - System.out.println("message2 생성: " + message2.getId()); - Message message3 = messageService.createMessage("나는 너를 정말 연모해", channelId, authorId); - System.out.println("message3 생성: " + message3.getId()); - - // Message 조회 - Message readingMessage = messageService.readMessage(message1.getId()); - System.out.println("message1 조회: " + readingMessage.getId()); - Message readingMessage2 = messageService.readMessage(message2.getId()); - System.out.println("message2 조회: " + readingMessage2.getId()); - Message readingMessage3 = messageService.readMessage(message3.getId()); - System.out.println("message3 조회: " + readingMessage3.getId()); - - // 모든 Message 조회 - List readAllMessages = messageService.readAllMessages(); - System.out.println("채널 조회: " + readAllMessages.size()); - - // Message 수정 - Message updatingMessage1 = messageService.updateMessage(message1.getId(), "나는 너의 모든 것이 좋아"); - System.out.println("message content 수정: " + String.join(",", updatingMessage1.getContent())); - Message updatingMessage2 = messageService.updateMessage(message2.getId(), "나는 너의 모든 것을 사랑해"); - System.out.println("message content 수정: " + String.join(",", updatingMessage2.getContent())); - Message updatingMessage3 = messageService.updateMessage(message3.getId(), "나는 너의 모든 면을 사랑해"); - System.out.println("message content 수정: " + String.join(",", updatingMessage3.getContent())); - - // Message 삭제 - messageService.deleteMessage(message1.getId()); - List readMessagesAfterDelete = messageService.readAllMessages(); - System.out.println("message1 삭제: " + readMessagesAfterDelete.size()); -// messageService.deleteMessage(message2.getId()); -// System.out.println("message2 삭제: " + readMessagesAfterDelete.size()); -// messageService.deleteMessage(message3.getId()); -// System.out.println("message3 삭제: " + readMessagesAfterDelete.size()); - - System.out.println("Message CRUD Test Completed"); - } - - static User setupUser(UserService userService) { - User user = userService.createUser("123456-5678910", "임정현", 25, "1234wjdgusdl@gmail.com"); - return user; - } +// static User setupUser(UserService userService) { +// User user = userService.create("woody", "woody@codeit.com", "woody1234"); +// return user; +// } static Channel setupChannel(ChannelService channelService) { - Channel channel = channelService.createChannel("스프링 백엔드 3기", "이곳은 코드잇 스프린트 스프링 백엔드 3기 채널입니다."); + Channel channel = channelService.create(ChannelType.PUBLIC, "공지", "공지 채널입니다."); return channel; } - static Message setupMessage(MessageService messageService, Channel channel, User author) { - Message message = messageService.createMessage("다들 좋은 아침입니다.", channel.getId(), author.getId()); - return message; + static void messageCreateTest(MessageService messageService, Channel channel, User author) { + Message message = messageService.create("안녕하세요.", channel.getId(), author.getId()); + System.out.println("메시지 생성: " + message.getId()); } + public static void main(String[] args) { - // 서비스 초기화 - UserService userService = new JCFUserService(); - ChannelService channelService = new JCFChannelService(); - MessageService messageService = new JCFMessageService(channelService, userService); + // 레포지토리 초기화 + UserRepository userRepository = new FileUserRepository(); + ChannelRepository channelRepository = new FileChannelRepository(); + MessageRepository messageRepository = new FileMessageRepository(); - // 테스트 - userCRUDTest(userService); - channelCRUDTest(channelService); - messageCRUDTest(messageService); + // 서비스 초기화 +// UserService userService = new BasicUserService(userRepository); +// ChannelService channelService = new BasicChannelService(channelRepository); +// MessageService messageService = new BasicMessageService(messageRepository, channelRepository, userRepository); + ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); + ChannelService channelService = (ChannelService) context.getBean("basicChannelService"); + UserService userService = (UserService) context.getBean("basicUserService"); + MessageService messageService = (MessageService) context.getBean("basicMessageService"); // 셋업 - User user = setupUser(userService); +// User user = setupUser(userService); Channel channel = setupChannel(channelService); - setupMessage(messageService, channel, user); + // 테스트 + messageCreateTest(messageService, channel, user); } } diff --git a/src/main/java/com/sprint/mission/discodeit/JavaApplication2.java b/src/main/java/com/sprint/mission/discodeit/JavaApplication2.java index af97567dd..f1261816c 100644 --- a/src/main/java/com/sprint/mission/discodeit/JavaApplication2.java +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication2.java @@ -1,60 +1,56 @@ package com.sprint.mission.discodeit; -import com.sprint.mission.discodeit.entity.Message; -import com.sprint.mission.discodeit.entity.Channel; + import com.sprint.mission.discodeit.entity.User; import com.sprint.mission.discodeit.repository.UserRepository; import com.sprint.mission.discodeit.repository.file.FileUserRepository; -import com.sprint.mission.discodeit.service.ChannelService; -import com.sprint.mission.discodeit.service.MessageService; +import com.sprint.mission.discodeit.repository.jcf.JCFUserRepository; import com.sprint.mission.discodeit.service.UserService; import com.sprint.mission.discodeit.service.basic.BasicUserService; -import com.sprint.mission.discodeit.service.file.FileMessageService; -import com.sprint.mission.discodeit.service.file.FileUserService; -import com.sprint.mission.discodeit.service.file.FileChannelService; -import java.util.*; +import java.sql.SQLOutput; +import java.util.ArrayList; +import java.util.List; public class JavaApplication2 { + + static User setupUser(BasicUserService basicUserService) { + UserRepository userRepository; + // 테스트용 유저 객체 생성 + List userList = new ArrayList<>(); + User user1 = basicUserService.createUser("111111-1234567", "김첨지", 49, "cheomji@gmail.com"); + userList.add(user1); + User user2 = basicUserService.createUser("222222-2234567", "김복순", 49, "luckysoon@gmail.com"); + userList.add(user2); + + return user1; + } + public static void main(String[] args) { + + // 저장 로직 호출 + UserRepository userRepository = new FileUserRepository(); +// UserRepository userRepository2 = new JCFUserRepository(); + // 서비스 초기화 - // TODO Basic*Service 구현체를 초기화하세요. - UserRepository userRepository; - UserService userService; - BasicUserService basicUserService; -// ChannelService channelService; -// MessageService messageService; + + BasicUserService basicUserService = new BasicUserService(userRepository); // 셋업 User user = setupUser(basicUserService); -// Channel channel = setupChannel(channelService); - // 테스트 -// messageCreateTest(messageService, channel, user); - } - static User setupUser(UserService userService) { - User user = userService.createUser("woody", "woody1234", 25, "woody@codeit.com"); - return user; - } -// static Channel setupChannel(ChannelService channelService) { -// Channel channel = channelService.createChannel("공지", "공지 채널입니다."); -// return channel; -// } -// -// static void messageCreateTest(MessageService messageService, Channel channel, User author) { -// Message message = messageService.createMessage("안녕하세요. 저는 우디입니다", channel.getId(), author.getId()); -// System.out.println("메시지 생성: " + message.getId()); -// } - public void FileCRUDTest() { - System.out.println("-----------------FileCRUDTest-----------------"); + // 유저 조회(단건) + System.out.println("-----------------(유저 조회)-----------------"); - // 등록 + basicUserService.findById((user.getId())); - User user1 = setupUser(userService); + // 유저 조회(다건) + System.out.println("-----------------(전체 유저 조회)-----------------"); - // 조회(단건) - System.out.println("-----------------조회(단건)Test-----------------"); - System.out.println("User: " + userService.foundUser(user1.getId())); + // 유저 정보 수정 + System.out.println("-----------------(유저 정보 수정)-----------------"); + // 유저 삭제 + System.out.println("-----------------(유저 삭제)-----------------"); } } diff --git a/src/main/java/com/sprint/mission/discodeit/entity/BinaryContent.java b/src/main/java/com/sprint/mission/discodeit/entity/BinaryContent.java new file mode 100644 index 000000000..3a09b6631 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/BinaryContent.java @@ -0,0 +1,30 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.UUID; + +//이미지, 파일 등 바이너리 데이터를 표현하는 도메인 모델입니다. 사용자의 프로필 이미지, 메시지에 첨부된 파일을 저장하기 위해 활용합니다. +@Getter +public class BinaryContent { + + private final UUID id; + private final Instant createdAt; +// Instant updatedAt; // Immutable 도메인이라 updatedAt 정의x + // + private final String fileName; + private final FileType fileType; // image or attachment + private final byte[] content; + + + public BinaryContent(String fileName, FileType fileType, byte[] content) { + this.id = UUID.randomUUID(); + this.createdAt = Instant.now().truncatedTo(ChronoUnit.SECONDS); + // + this.fileName = fileName; + this.fileType = fileType; + this.content = content; + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/Channel.java b/src/main/java/com/sprint/mission/discodeit/entity/Channel.java index 55b66dfe4..ee32a7250 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/Channel.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/Channel.java @@ -1,58 +1,75 @@ package com.sprint.mission.discodeit.entity; +import lombok.Getter; + +import java.io.Serial; +import java.io.Serializable; import java.time.Instant; -import java.util.*; import java.util.UUID; -public class Channel extends Base { - private String channelName; - private String description; +@Getter +public class Channel implements Serializable { - public Channel() {} + @Serial + private static final long serialVersionUID = 1L; + private UUID id; + private Instant createdAt; + private Instant updatedAt; + // + private ChannelType type; + private String name; + private String description; + // + private ReadStatus readStatus; - public Channel(String channelName, String description) { - super(); + public Channel(ChannelType type, String name, String description) { + this.id = UUID.randomUUID(); + this.createdAt = Instant.ofEpochSecond(Instant.now().getEpochSecond()); // - this.channelName = channelName; + this.type = type; + this.name = name; this.description = description; + // + this.readStatus = null; // 채널을 읽은 유저들의 상태 } +// public UUID getId() { +// return id; +// } +// +// public Long getCreatedAt() { +// return createdAt; +// } +// +// public Long getUpdatedAt() { +// return updatedAt; +// } +// +// public ChannelType getType() { +// return type; +// } +// +// public String getName() { +// return name; +// } +// +// public String getDescription() { +// return description; +// } - // Gettter Method - - public String getChannelName() { - return this.channelName; - } - - public String getDescription() { return this.description; } - - - // Update Method - - public void updateChannel(String newChannelName, String newDescription) { + public void update(String newName, String newDescription) { boolean anyValueUpdated = false; - if (newChannelName != null && !newChannelName.equals(this.channelName)) { - this.channelName = newChannelName; + if (newName != null && !newName.equals(this.name)) { + this.name = newName; anyValueUpdated = true; } - - if (newDescription != null && newDescription.equals(this.description)) { + if (newDescription != null && !newDescription.equals(this.description)) { this.description = newDescription; anyValueUpdated = true; } if (anyValueUpdated) { - super.updateUpdatedAt(Instant.now().getEpochSecond()); + this.updatedAt = Instant.ofEpochSecond(Instant.now().getEpochSecond()); } } - - @Override - public String toString() { - return "Channel{" + - "name='" + getChannelName() + '\'' + - ", channelId='" + getId() + '\'' + - ", createdAt='" + getCreatedAt() + '\'' + - ", updatedAt='" + getUpdatedAt() + '\'' + - '}'; - } -} \ No newline at end of file +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/ChannelType.java b/src/main/java/com/sprint/mission/discodeit/entity/ChannelType.java new file mode 100644 index 000000000..9a2ff3f0f --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/ChannelType.java @@ -0,0 +1,6 @@ +package com.sprint.mission.discodeit.entity; + +public enum ChannelType { + PUBLIC, + PRIVATE, +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/FileType.java b/src/main/java/com/sprint/mission/discodeit/entity/FileType.java new file mode 100644 index 000000000..7deeced43 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/FileType.java @@ -0,0 +1,6 @@ +package com.sprint.mission.discodeit.entity; + +public enum FileType { + IMAGE, + ATTACHMENT +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/Message.java b/src/main/java/com/sprint/mission/discodeit/entity/Message.java index af7b845f5..86490b39f 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/Message.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/Message.java @@ -1,41 +1,43 @@ package com.sprint.mission.discodeit.entity; +import lombok.Getter; +import java.io.Serial; +import java.io.Serializable; import java.time.Instant; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; -public class Message extends Base { +@Getter +public class Message implements Serializable { - private UUID authorId; - private UUID channelId; // 이걸 Channel 클래스와 어떻게 연결시키지 - private String content; // message는 결국 HashSet이야 + @Serial + private static final long serialVersionUID = 1L; + private UUID id; + private Instant createdAt; + private Instant updatedAt; + // + private String content; + // + private UUID channelId; + private UUID authorId; + // + private List attachmentIds; public Message(String content, UUID channelId, UUID authorId) { - super(); + this.id = UUID.randomUUID(); + this.createdAt = Instant.ofEpochSecond(Instant.now().getEpochSecond()); + // this.content = content; this.channelId = channelId; this.authorId = authorId; + // + this.attachmentIds = new ArrayList<>(); // 하나가 아닐 수도 있음. 여러개를 받아야 함 } - - // Getter Methods - public String getContent() { - return content; - } - - public UUID getChannelId() { - return channelId; - } - - public UUID getAuthorId() { - return authorId; - } - - - // Update Method - - public void updateMessage(String newContent) { + public void update(String newContent) { boolean anyValueUpdated = false; if (newContent != null && !newContent.equals(this.content)) { this.content = newContent; @@ -43,19 +45,19 @@ public void updateMessage(String newContent) { } if (anyValueUpdated) { - super.updateUpdatedAt(Instant.now().getEpochSecond()); + this.updatedAt = Instant.ofEpochSecond(Instant.now().getEpochSecond()); } } - @Override - public String toString() { - return "Message{" + - "message='" + getContent() + '\'' + - ", id='" + getId() + '\'' + - ", channelId='" + getChannelId() + '\'' + - ", authorId='" + getAuthorId() + '\'' + - ", createdAt='" + getCreatedAt() + '\'' + - ", updatedAt='" + getUpdatedAt() + '\'' + - '}'; + public void update(UUID attachmentId) { + boolean anyValueUpdated = false; + if (attachmentId != null && !attachmentId.equals(this.attachmentIds)) { + this.attachmentIds.add(attachmentId); + anyValueUpdated = true; + } + + if (anyValueUpdated) { + this.updatedAt = Instant.ofEpochSecond(Instant.now().getEpochSecond()); + } } } diff --git a/src/main/java/com/sprint/mission/discodeit/entity/ReadStatus.java b/src/main/java/com/sprint/mission/discodeit/entity/ReadStatus.java new file mode 100644 index 000000000..115e87d8c --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/ReadStatus.java @@ -0,0 +1,44 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.Optional; +import java.util.UUID; + +/*사용자가 채널 별 마지막으로 메시지를 읽은 시간을 표현하는 도메인 모델입니다. +사용자별 각 채널에 읽지 않은 메시지를 확인하기 위해 활용합니다.*/ +@Getter +public class ReadStatus { + + private UUID id; + private Instant createdAt; + private Instant updatedAt; + // + private UUID userId; + private UUID channelId; + private Instant lastReadAt; + + public ReadStatus(User user, Channel channel) { + this.id = UUID.randomUUID(); + this.userId = user.getId(); + this.channelId = channel.getId(); + this.createdAt = Instant.now().truncatedTo(ChronoUnit.SECONDS); + this.updatedAt = this.createdAt; + this.lastReadAt = this.updatedAt; + } + + //TODO lastReadAt에 메시지가 생성된 시점 대입 + public void update(User user, Channel channel, Instant lastReadAt) { + this.userId = user.getId(); + this.channelId = channel.getId(); + this.lastReadAt = Instant.now().truncatedTo(ChronoUnit.SECONDS); + } + + // 채널에 읽지 않은 메시지가 있는지 + //TODO 채널이 업데이트 된 시간이 lastReadAt보다 이후인지 + public boolean hasUnreadMessages(Channel channel) { // true면 ReadStatus는 안읽음, false면 읽음 + return channel.getUpdatedAt().isAfter(lastReadAt); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/User.java b/src/main/java/com/sprint/mission/discodeit/entity/User.java index 182b69a6a..a501499bd 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/User.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/User.java @@ -1,69 +1,69 @@ package com.sprint.mission.discodeit.entity; -import java.time.Instant; -import java.util.*; +import com.sprint.mission.discodeit.entity.dto.CreateUserRequest; +import lombok.Getter; +import lombok.Setter; + import java.io.Serial; import java.io.Serializable; +import java.time.Instant; +import java.util.Optional; +import java.util.UUID; -public class User extends Base implements Serializable { - private transient String RRN; +@Getter +public class User implements Serializable { - // @Serial - private static final long serialVersionUID = 1L; // private, final 필수x 권장사항 - private int age; - private String name; - private String email; + private static final long serialVersionUID = 1L; + private UUID id; + private Instant createdAt; + private Instant updatedAt; + // + private String username; + private String email; + private String password; + // + private UserStatus userStatus; + private ReadStatus readStatus; - public User(String RRN, String name, int age, String email) { - super(); + @Setter + private UUID profileId; - this.RRN = RRN; - this.age = age; - this.name = name; + public User(String username, String email, String password, UUID profileId) { + this.id = UUID.randomUUID(); + this.createdAt = Instant.ofEpochSecond(Instant.now().getEpochSecond()); + // + this.username = username; this.email = email; + this.password = password; + // + this.profileId = profileId; + this.userStatus = null; + this.readStatus = null; } - - // Getter Method - public String getRRN() { return RRN; } - - public int getAge() { return age; } - - public String getName() { return name; } - - public String getEmail() { return email; } - - - // Update Method - public void updateUser(String newName, String newEmail) { + public void update(String newUsername, String newEmail, String newPassword /*,UUID newProfileId*/) { boolean anyValueUpdated = false; - if (newName != null && !newName.equals(this.name)) { - this.name = newName; + if (newUsername != null && !newUsername.equals(this.username)) { + this.username = newUsername; anyValueUpdated = true; } - if (newEmail != null && !newEmail.equals(this.email)) { this.email = newEmail; anyValueUpdated = true; } + if (newPassword != null && !newPassword.equals(this.password)) { + this.password = newPassword; + anyValueUpdated = true; + } +// if (newProfileId != null && !newProfileId.equals(this.profileId)) { +// this.profileId = newProfileId; +// anyValueUpdated = true; +// } if (anyValueUpdated) { - super.updateUpdatedAt(Instant.now().getEpochSecond()); + this.updatedAt = Instant.ofEpochSecond(Instant.now().getEpochSecond()); } } - - @Override - public String toString() { - return "User{" + - "id=" + getId() + - ", RRN='" + getRRN() + '\'' + - ", name='" + getName() + '\'' + - ", age=" + getAge() + - ", email='" + getEmail() + '\'' + - ", createdAt='" + getCreatedAt() + '\'' + - ", updatedAt='" + getUpdatedAt() + '\'' + - '}'; - } } diff --git a/src/main/java/com/sprint/mission/discodeit/entity/UserStatus.java b/src/main/java/com/sprint/mission/discodeit/entity/UserStatus.java new file mode 100644 index 000000000..33a34085d --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/UserStatus.java @@ -0,0 +1,53 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.io.Serial; +import java.io.Serializable; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.UUID; + +@Getter +public class UserStatus { + + @Serial + private static final long serialVersionUID = 1L; + + private UUID id; + private Instant createdAt; + private Instant updatedAt; + // + private UUID userId; + private Instant lastLoginAt; + + public UserStatus(User user) { + + this.id = UUID.randomUUID(); +// this.createdAt = Instant.ofEpochSecond(Instant.now().getEpochSecond()); + this.createdAt = Instant.now().truncatedTo(ChronoUnit.SECONDS); + this.updatedAt = this.createdAt; + // + this.userId = user.getId(); + + this.lastLoginAt = this.createdAt; + + } + + public boolean isCurrenlyLoggedIn() { + return lastLoginAt.plusSeconds(300).isAfter(Instant.now()); // true: 로그인 + } + + public void update() { + boolean anyValueUpdated = false; + if (this.isCurrenlyLoggedIn()) { + this.lastLoginAt = Instant.now().truncatedTo(ChronoUnit.SECONDS); + anyValueUpdated = true; + } + + if (anyValueUpdated) { + this.updatedAt = Instant.ofEpochSecond(Instant.now().getEpochSecond()); + } + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/ChannelDTO.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/ChannelDTO.java new file mode 100644 index 000000000..b9561f3f7 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/ChannelDTO.java @@ -0,0 +1,14 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.Channel; + +import java.time.Instant; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public record ChannelDTO( + Channel channel, + Instant lastReadAt, + Optional> userIds +) { } diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateBinaryContentRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateBinaryContentRequest.java new file mode 100644 index 000000000..e5c38157a --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateBinaryContentRequest.java @@ -0,0 +1,12 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.FileType; + +import java.util.UUID; + +public record CreateBinaryContentRequest ( + UUID id, + String fileName, + FileType fileType, + byte[] content +) { } diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateMessageRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateMessageRequest.java new file mode 100644 index 000000000..c63510f3b --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateMessageRequest.java @@ -0,0 +1,11 @@ +package com.sprint.mission.discodeit.entity.dto; + +import java.util.List; +import java.util.UUID; + +public record CreateMessageRequest( + String content, + UUID channelId, + UUID authorId, + List attachments // 첨부파일 리스트 +) { } diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/CreatePrivateChannelRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreatePrivateChannelRequest.java new file mode 100644 index 000000000..a0266bfe9 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreatePrivateChannelRequest.java @@ -0,0 +1,11 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.User; + +import java.util.List; +import java.util.UUID; + +public record CreatePrivateChannelRequest( + List userList, + UUID channelId +) {} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/CreatePublicChannelRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreatePublicChannelRequest.java new file mode 100644 index 000000000..920e8263b --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreatePublicChannelRequest.java @@ -0,0 +1,12 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.ChannelType; + +import java.util.UUID; + +public record CreatePublicChannelRequest( +// ChannelType PUBLIC, + UUID channelId, + String name, + String description +) {} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateReadStatusRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateReadStatusRequest.java new file mode 100644 index 000000000..7b51d66d8 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateReadStatusRequest.java @@ -0,0 +1,14 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.User; + +import java.time.Instant; +import java.util.UUID; + +public record CreateReadStatusRequest( + User user, + Channel channel, + Instant lastReadAt +) { +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateUserRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateUserRequest.java new file mode 100644 index 000000000..10f9e528b --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateUserRequest.java @@ -0,0 +1,11 @@ +package com.sprint.mission.discodeit.entity.dto; + +import org.springframework.web.multipart.MultipartFile; + +import java.util.UUID; + +public record CreateUserRequest( + UUID id, + String username, + String email, + String password) {} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateUserStatusRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateUserStatusRequest.java new file mode 100644 index 000000000..ae3c4a5f4 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/CreateUserStatusRequest.java @@ -0,0 +1,13 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.User; + +import java.time.Instant; +import java.util.UUID; + +public record CreateUserStatusRequest( + UUID id, + User user, + Instant lastLoginAt +) { +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/FindUserReqeust.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/FindUserReqeust.java new file mode 100644 index 000000000..ab933585b --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/FindUserReqeust.java @@ -0,0 +1,8 @@ +package com.sprint.mission.discodeit.entity.dto; + +import java.util.UUID; + +public record FindUserReqeust( + UUID id +) { +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/LoginRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/LoginRequest.java new file mode 100644 index 000000000..2b4ed3c2f --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/LoginRequest.java @@ -0,0 +1,4 @@ +package com.sprint.mission.discodeit.entity.dto; + +public record LoginRequest(String username, String password) { +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateChannelRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateChannelRequest.java new file mode 100644 index 000000000..29ba6460b --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateChannelRequest.java @@ -0,0 +1,10 @@ +package com.sprint.mission.discodeit.entity.dto; + +import java.util.UUID; + +public record UpdateChannelRequest( + UUID channelId, + String newName, + String newDescription +) { +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateMessageRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateMessageRequest.java new file mode 100644 index 000000000..765827090 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateMessageRequest.java @@ -0,0 +1,9 @@ +package com.sprint.mission.discodeit.entity.dto; + +import java.util.UUID; + +public record UpdateMessageRequest( + UUID messageId, + String content +) { +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateReadStatusRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateReadStatusRequest.java new file mode 100644 index 000000000..1e9b42ec0 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateReadStatusRequest.java @@ -0,0 +1,15 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.User; + +import java.time.Instant; +import java.util.UUID; + +public record UpdateReadStatusRequest( + UUID id, + User user, + Channel channel, + Instant lastReadAt +) { +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateUserRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateUserRequest.java new file mode 100644 index 000000000..2bae44634 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateUserRequest.java @@ -0,0 +1,13 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.BinaryContent; + +import java.util.Optional; +import java.util.UUID; + +public record UpdateUserRequest( + String username, // 사용자가 수정할 수 있는 필드들만 포함 + String email, + String password, + Optional binaryContent) { +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateUserStatusRequest.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateUserStatusRequest.java new file mode 100644 index 000000000..c9b8bd172 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/UpdateUserStatusRequest.java @@ -0,0 +1,13 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.entity.UserStatus; + +import java.time.Instant; + +public record UpdateUserStatusRequest( + User user, + UserStatus userStatus, + Instant lastLoginAt +) { +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/dto/UserDTO.java b/src/main/java/com/sprint/mission/discodeit/entity/dto/UserDTO.java new file mode 100644 index 000000000..07a75ca9a --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/dto/UserDTO.java @@ -0,0 +1,13 @@ +package com.sprint.mission.discodeit.entity.dto; + +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.entity.UserStatus; + +import java.util.List; +import java.util.Optional; + +public record UserDTO ( + Optional user, + UserStatus userStatus +) { } + diff --git a/src/main/java/com/sprint/mission/discodeit/entity/exception/CannotUpdateException.java b/src/main/java/com/sprint/mission/discodeit/entity/exception/CannotUpdateException.java new file mode 100644 index 000000000..f98e72404 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/exception/CannotUpdateException.java @@ -0,0 +1,7 @@ +package com.sprint.mission.discodeit.entity.exception; + +public class CannotUpdateException extends RuntimeException { + public CannotUpdateException(String message) { + super(message); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/exception/DuplicateReadStatusException.java b/src/main/java/com/sprint/mission/discodeit/entity/exception/DuplicateReadStatusException.java new file mode 100644 index 000000000..71d5e6b9a --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/exception/DuplicateReadStatusException.java @@ -0,0 +1,7 @@ +package com.sprint.mission.discodeit.entity.exception; + +public class DuplicateReadStatusException extends RuntimeException { + public DuplicateReadStatusException(String message) { + super(message); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/exception/DuplicateUserStatusException.java b/src/main/java/com/sprint/mission/discodeit/entity/exception/DuplicateUserStatusException.java new file mode 100644 index 000000000..e0d5a2601 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/exception/DuplicateUserStatusException.java @@ -0,0 +1,7 @@ +package com.sprint.mission.discodeit.entity.exception; + +public class DuplicateUserStatusException extends RuntimeException { + public DuplicateUserStatusException(String message) { + super(message); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/BinaryContentRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/BinaryContentRepository.java new file mode 100644 index 000000000..8adf32440 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/BinaryContentRepository.java @@ -0,0 +1,18 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.entity.ReadStatus; +import jakarta.websocket.Decoder; + +import java.util.List; +import java.util.UUID; + +public interface BinaryContentRepository { + + BinaryContent save(BinaryContent binaryContent); + BinaryContent findById(UUID id); + List findAllByIdIn(List ids); + List findAll(); + boolean existsById(UUID id); + void delete(UUID id); +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java index dd5e7cebe..326a84f4b 100644 --- a/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java +++ b/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java @@ -3,18 +3,13 @@ import com.sprint.mission.discodeit.entity.Channel; import java.util.List; +import java.util.Optional; import java.util.UUID; public interface ChannelRepository { - - void create(Channel channel); - - Channel findById(UUID id); - + Channel save(Channel channel); + Optional findById(UUID id); List findAll(); - - void update(UUID id, String newName, String newDescription); - - void delete(UUID id); - + boolean existsById(UUID id); + void deleteById(UUID id); } diff --git a/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java index ad1fb490d..ad7c1d588 100644 --- a/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java +++ b/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java @@ -1,19 +1,16 @@ package com.sprint.mission.discodeit.repository; -import com.sprint.mission.discodeit.entity.Channel; import com.sprint.mission.discodeit.entity.Message; import java.util.List; +import java.util.Optional; import java.util.UUID; public interface MessageRepository { - void create(Message message); - - Message findById(UUID id); - + Message save(Message message); + Optional findById(UUID id); + List findAllByChannelId(UUID channelId); List findAll(); - - void updateMessage(UUID id, String newContent); - - void delete(UUID id); + boolean existsById(UUID id); + void deleteById(UUID id); } diff --git a/src/main/java/com/sprint/mission/discodeit/repository/ReadStatusRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/ReadStatusRepository.java new file mode 100644 index 000000000..006fe3b2c --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/ReadStatusRepository.java @@ -0,0 +1,19 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.ReadStatus; + +import java.util.List; +import java.util.UUID; + +public interface ReadStatusRepository { + + ReadStatus save(ReadStatus readStatus); + ReadStatus findById(UUID id); + List findByChannelId(UUID channelId); + List findAll(); + ReadStatus findByUserIdAndChannelId(UUID userId, UUID channelId); + List findByUserId(UUID userId); // UserId에 해당하는 채널별 ReadStatus 불러오기 + void delete(UUID id); + boolean existByChannelIdAndUserId(UUID userId, UUID channelId); + ReadStatus update(ReadStatus readStatus); +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/RepositoryConfig.java b/src/main/java/com/sprint/mission/discodeit/repository/RepositoryConfig.java new file mode 100644 index 000000000..0f8441bcb --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/RepositoryConfig.java @@ -0,0 +1,46 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.repository.file.FileBinaryContentRepository; +import com.sprint.mission.discodeit.repository.file.FileReadStatusRepository; +import com.sprint.mission.discodeit.repository.file.FileUserStatusRepository; +import com.sprint.mission.discodeit.repository.jcf.JCFBinaryContentRepository; +import com.sprint.mission.discodeit.repository.jcf.JCFReadStatusRepository; +import com.sprint.mission.discodeit.repository.jcf.JCFUserStatusRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RepositoryConfig { + + @Value("${discodeit.repository.type") + private String repositoryType; + + @Value("${discodeit.repository.file-directory") + private String fileDirectory; + + @Bean + public UserStatusRepository userStatusRepository() { + if ("file".equalsIgnoreCase(repositoryType)) { + return new FileUserStatusRepository(fileDirectory); + } else { + return new JCFUserStatusRepository(); + } + } + @Bean + public ReadStatusRepository readStatusRepository() { + if ("file".equalsIgnoreCase(repositoryType)) { + return new FileReadStatusRepository(fileDirectory); + } else { + return new JCFReadStatusRepository(); + } + } + @Bean + public BinaryContentRepository binaryContentRepository() { + if ("file".equalsIgnoreCase(repositoryType)) { + return new FileBinaryContentRepository(fileDirectory); + } else { + return new JCFBinaryContentRepository(); + } + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java index ddc5e8d0b..ebdbcb9e4 100644 --- a/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java +++ b/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java @@ -1,32 +1,15 @@ package com.sprint.mission.discodeit.repository; -//레포지토리 설계 및 구현 -// -//[ ] "저장 로직"과 관련된 기능을 도메인 모델 별 인터페이스로 선언하세요. -//[ ] 인터페이스 패키지명: com.sprint.mission.discodeit.repository -//[ ] 인터페이스 네이밍 규칙: [도메인 모델 이름]Repository - import com.sprint.mission.discodeit.entity.User; -import java.nio.file.*; -import java.util.*; - -public interface UserRepository { // 저장소에 저장해주는 것 - - void create(User user); // User user 말고 Object o로도 가능한가? - - User findById(UUID id); +import java.util.List; +import java.util.Optional; +import java.util.UUID; +public interface UserRepository { + User save(User user); + Optional findById(UUID id); List findAll(); - - void update(UUID id, String newName, String newEmail); - - void delete(UUID id); - -// // TODO 호출 메소드 -// // Instance의 정보가 저장된 파일의 주소를 불러온다. -// // // 1. save와 read 메소드가 반환한 List를 파라미터로 받는다. -// // // 2. save와 read 메소드로 저장(호출)된 파일의 경로를 불러온다 -// // // 3. String 타입으로 경로를 리턴한다. -// String loadPath(List list); + boolean existsById(UUID id); + void deleteById(UUID id); } diff --git a/src/main/java/com/sprint/mission/discodeit/repository/UserStatusRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/UserStatusRepository.java new file mode 100644 index 000000000..7df16abb3 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/UserStatusRepository.java @@ -0,0 +1,17 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.UserStatus; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface UserStatusRepository { + + UserStatus save(UserStatus userStatus); + Optional findByUserId(UUID userId); + Optional find(UUID id); + List findAll(); + boolean existsByUserId(UUID userId); + void delete(UUID userId); +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/file/FileBinaryContentRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/file/FileBinaryContentRepository.java new file mode 100644 index 000000000..e5b67fedd --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileBinaryContentRepository.java @@ -0,0 +1,102 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; + +import java.io.*; +import java.nio.file.*; +import java.util.*; +import java.util.stream.Collectors; + +public class FileBinaryContentRepository implements BinaryContentRepository { + + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; // 파일 확장자 + + public FileBinaryContentRepository() { + this.DIRECTORY = Paths.get(System.getProperty("user.dir"), "file-data-map", BinaryContent.class.getSimpleName()); + if (Files.notExists(DIRECTORY)) { + try { + Files.createDirectories(DIRECTORY); // 디렉토리가 없으면 생성 + } catch (IOException e) { + throw new RuntimeException("Error creating directory", e); + } + } + } + + private Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); // UUID를 기반으로 파일 경로 생성 + } + + @Override + public BinaryContent save(BinaryContent binaryContent) { + Path path = resolvePath(binaryContent.getId()); + try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path.toFile()))) { + oos.writeObject(binaryContent); // BinaryContent 객체를 파일에 저장 + } catch (IOException e) { + throw new RuntimeException("Error writing BinaryContent to file", e); + } + return binaryContent; + } + + @Override + public BinaryContent findById(UUID id) { + Path path = resolvePath(id); + if (Files.exists(path)) { + try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile()))) { + return (BinaryContent) ois.readObject(); // 파일에서 BinaryContent 객체 읽기 + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException("Error reading BinaryContent from file", e); + } + } + return null; // 해당 파일이 없으면 null 반환 + } + + @Override + public List findAllByIdIn(List ids) { + List binaryContents = new ArrayList<>(); + for (UUID id : ids) { + BinaryContent binaryContent = findById(id); + if (binaryContent != null) { + binaryContents.add(binaryContent); + } + } + return binaryContents; + } + + @Override + public List findAll() { + List binaryContents = new ArrayList<>(); + try { + Files.list(DIRECTORY) // 디렉토리 내 모든 파일 탐색 + .filter(path -> path.toString().endsWith(EXTENSION)) // 확장자가 ".ser"인 파일만 필터링 + .forEach(path -> { + try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile()))) { + binaryContents.add((BinaryContent) ois.readObject()); // 파일에서 BinaryContent 객체 읽기 + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); // 예외 처리 + } + }); + } catch (IOException e) { + throw new RuntimeException("Error listing files", e); + } + return binaryContents; // 모든 BinaryContent 객체를 반환 + } + + @Override + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); // 해당 id의 파일이 존재하는지 확인 + } + + @Override + public void delete(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); // 해당 id의 파일을 삭제 + } catch (IOException e) { + throw new RuntimeException("Error deleting BinaryContent", e); + } + } +} + diff --git a/src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java index 82c2e7360..48b7de342 100644 --- a/src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java @@ -1,127 +1,102 @@ package com.sprint.mission.discodeit.repository.file; import com.sprint.mission.discodeit.entity.Channel; -import com.sprint.mission.discodeit.entity.User; import com.sprint.mission.discodeit.repository.ChannelRepository; +import org.springframework.stereotype.Repository; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.UUID; +@Repository public class FileChannelRepository implements ChannelRepository { - - private final File file = new File("/data/channels.txt"); - - public void save(Channel channel) { // entity를 받고 return 없음 - - // 부모 디렉토리 없으면 생성 - File parentDir = file.getParentFile(); - if (!parentDir.exists()) { - parentDir.mkdirs(); // data/ 폴더 생성 - } - - try (ObjectOutputStream objectOOS = new ObjectOutputStream(new FileOutputStream(file)) // FOS는 Path를 직접 파라미터로 받지 못함 - ) { - - objectOOS.writeObject(channel); - - } catch (IOException e) { - throw new RuntimeException(e); + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileChannelRepository() { + this.DIRECTORY = Paths.get(System.getProperty("user.dir"), "file-data-map", Channel.class.getSimpleName()); + if (Files.notExists(DIRECTORY)) { + try { + Files.createDirectories(DIRECTORY); + } catch (IOException e) { + throw new RuntimeException(e); + } } } - private void save(List channelList) { - // 부모 디렉토리 없으면 생성 - File parentDir = file.getParentFile(); - if (!parentDir.exists()) { - parentDir.mkdirs(); // data/ 폴더 생성 - } - try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) { - - oos.writeObject(channelList); - } catch (IOException e) { - throw new RuntimeException(e); - } + private Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); } - public List load() { // List 출력 - List objectList = new ArrayList(); - - Path path = Paths.get("/data/channels.txt"); - try (ObjectInputStream objectOIS = new ObjectInputStream(new FileInputStream(path.toFile())) + @Override + public Channel save(Channel channel) { + Path path = resolvePath(channel.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) ) { - if (!Files.exists(path)) { - return new ArrayList<>(); - } - for (Channel object :(List) objectOIS.readObject()) { - - objectList.add(object); - } - } catch (FileNotFoundException e) { - System.out.println("파일을 찾을 수 없습니다."); // 비즈니스 로직 - throw new RuntimeException(e); - } catch (IOException | ClassNotFoundException e) { - System.out.println("파일에 아무 것도 없습니다."); // 비즈니스 로직 + oos.writeObject(channel); + } catch (IOException e) { throw new RuntimeException(e); } - return objectList; - } - - @Override - public void create(Channel channel) { - - save(channel); + return channel; } @Override - public Channel findById(UUID id) { - // 1. id를 입력하면, id에 해당하는 유저를 역직렬화하여 불러온다. - List objectList = load(); - for (Channel object : objectList) { - if (object instanceof Channel) { - Channel channel = (Channel) object; - if (channel.getId().equals(id)) { - return channel; - } + public Optional findById(UUID id) { + Channel channelNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + channelNullable = (Channel) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); } } - return null; + return Optional.ofNullable(channelNullable); } @Override public List findAll() { - - List channel = load(); - return channel; + try { + return Files.list(DIRECTORY) + .filter(path -> path.toString().endsWith(EXTENSION)) + .map(path -> { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + return (Channel) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override - public void update(UUID id, String newName, String newDescription) { - List channelList = load(); // 기존 채널 리스트 로드 - - for (Channel channel : channelList) { - if (channel.getId().equals(id)) { - channel.updateChannel(newName, newDescription); // 채널 정보 수정 - break; - } - } - - save(channelList); // 전체 리스트를 다시 저장 + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); } @Override - public void delete(UUID id) { - List objectList = load(); - for (Channel object : objectList) { - if (object.getId().equals(id)) { - objectList.remove(object); - save(objectList); - break; - } + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); } } } diff --git a/src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java index 5f7583a55..bf71910fb 100644 --- a/src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java @@ -2,115 +2,101 @@ import com.sprint.mission.discodeit.entity.Message; import com.sprint.mission.discodeit.repository.MessageRepository; +import org.springframework.stereotype.Repository; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.UUID; +@Repository public class FileMessageRepository implements MessageRepository { - - private final File file = new File("/data/messages.txt"); - - - public void save(Message message) { // entity를 받고 return 없음 - - // 부모 디렉토리 없으면 생성 - File parentDir = file.getParentFile(); - if (!parentDir.exists()) { - parentDir.mkdirs(); // data/ 폴더 생성 - } - - try (ObjectOutputStream objectOOS = new ObjectOutputStream(new FileOutputStream(file)) // FOS는 Path를 직접 파라미터로 받지 못함 - ) { - objectOOS.writeObject(message); - - } catch (IOException e) { - throw new RuntimeException(e); + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileMessageRepository() { + this.DIRECTORY = Paths.get(System.getProperty("user.dir"), "file-data-map", Message.class.getSimpleName()); + if (Files.notExists(DIRECTORY)) { + try { + Files.createDirectories(DIRECTORY); + } catch (IOException e) { + throw new RuntimeException(e); + } } } - private void save(List messageList) { - - try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) { - - oos.writeObject(messageList); - - } catch (IOException e) { - throw new RuntimeException(e); - } + private Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); } - public List load() { // List 출력 - List objectList = new ArrayList(); - - Path path = Paths.get("/data/messages.txt"); - try (ObjectInputStream objectOIS = new ObjectInputStream(new FileInputStream(path.toFile())) + @Override + public Message save(Message message) { + Path path = resolvePath(message.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) ) { - if (!Files.exists(path)) { // 비즈니스 로직 - return new ArrayList<>(); - } - for (Message object :(List) objectOIS.readObject()) { - - objectList.add(object); - } - } catch (FileNotFoundException e) { - System.out.println("메시지 파일을 찾을 수 없습니다."); // 비즈니스 로직 - throw new RuntimeException(e); - } catch (IOException | ClassNotFoundException e) { - System.out.println("파일에 메시지가 없습니다."); // 비즈니스 로직 + oos.writeObject(message); + } catch (IOException e) { throw new RuntimeException(e); } - return objectList; - } - - - @Override - public void create(Message message) { - save(message); + return message; } @Override - public Message findById(UUID id) { - List objectList = load(); - for (Message object : objectList) { - if (object.getId().equals(id)) { - return object; + public Optional findById(UUID id) { + Message messageNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + messageNullable = (Message) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); } } - return null; + return Optional.ofNullable(messageNullable); } @Override public List findAll() { - List objectList = load(); - return objectList; + try { + return Files.list(DIRECTORY) + .filter(path -> path.toString().endsWith(EXTENSION)) + .map(path -> { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + return (Message) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override - public void updateMessage(UUID id, String newContent) { - List objectList = load(); - for (Message object : objectList) { - if (object.getId().equals(id)) { - object.updateMessage(newContent); - save(objectList); - break; - } - } + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); } @Override - public void delete(UUID id) { - List objectList = load(); - for (Message object : objectList) { - if (object.getId().equals(id)) { - objectList.remove(object); - save(objectList); - break; - } + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); } } } diff --git a/src/main/java/com/sprint/mission/discodeit/repository/file/FileReadStatusRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/file/FileReadStatusRepository.java new file mode 100644 index 000000000..9ff166093 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileReadStatusRepository.java @@ -0,0 +1,233 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; + +public class FileReadStatusRepository implements ReadStatusRepository { + + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileReadStatusRepository() { // 생성자에서 File의 이름과 Path를 생성하고 Directory 없으면 생성 + this.DIRECTORY = Paths.get(System.getProperty("readStatus.dir"), "file-data-map", ReadStatus.class.getSimpleName()); + if (Files.notExists(DIRECTORY)) { + try { + Files.createDirectories(DIRECTORY); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + private Path resolvePath(UUID id) {return DIRECTORY.resolve(id + EXTENSION);} // id만 있으면 EXTENSION을 합쳐 Path를 반환 + + @Override + public ReadStatus save(ReadStatus readStatus) { + Path path = resolvePath(readStatus.getId()); + try ( + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path.toFile())); + ) { + oos.writeObject(readStatus); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return readStatus; + } + + @Override + public ReadStatus findById(UUID id) { + ReadStatus readStatusNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile())); + ) + { + readStatusNullable = (ReadStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + + return readStatusNullable; + } + + @Override + public List findByChannelId(UUID channelId) { + // 1. 반환 리스트 초기화 + List readStatusList = new ArrayList<>(); + + // 2. channelId에 해당하는 파일 경로 계산 + Path path = resolvePath(channelId); + + // 3. 파일이 존재하면 파일에서 데이터 읽기 + if (Files.exists(path)) { + try ( + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile())); + ) + { + Object o = ois.readObject(); +// readStatusList = (List) ois.readObject(); + // 5. readObject가 List라면, 데이터를 읽어 리스트에 저장 + if (o instanceof List) { + List tempList = (List) o; + // 리스트가 ReadStatus 객체들로 구성되어 있으면 + if (!tempList.isEmpty() && tempList.get(0) instanceof ReadStatus) { + readStatusList = (List) tempList; + } + } + + } catch (IOException | ClassNotFoundException e) { + // 예외 발생 시 예외 메시지 출력 (optional: 로깅 추가) + e.printStackTrace(); + // 실패 시 빈 리스트 반환 + return readStatusList; + } + } + + // 6. load한 ReadStatus 리스트 반환 + return readStatusList; + } + + @Override + public List findAll() { + try { + return Files.list(DIRECTORY) + .filter(path -> path.toString().endsWith(EXTENSION)) + .map(path -> { + try ( + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile())); + ) { + return (ReadStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public ReadStatus findByUserIdAndChannelId(UUID userId, UUID channelId) { + // 해당 채널 ID와 관련된 파일 경로 + Path path = resolvePath(channelId); + + // 파일 존재 유무 확인 + if (Files.exists(path)) { + try ( + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile())); + ) { + List readStatusList = (List) ois.readObject(); + // userId와 channelId가 일치하는 ReadStatus 찾기 + return readStatusList.stream() + .filter(readStatus -> readStatus.getUserId().equals(userId) && readStatus.getChannelId().equals(channelId)) + .findFirst() + .orElse(null); // 없으면 null 반환 + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException("Error reading from file", e); + } + } + return null; // 파일이 없으면 null 반환 + } + + @Override + public List findByUserId(UUID userId) { + // 1. 반환 리스트 초기화 + List readStatusList = new ArrayList<>(); + + // 2. userId에 해당하는 파일 경로 계산 + Path path = resolvePath(userId); + + // 3. 파일이 존재하면 파일에서 데이터 읽기 + if (Files.exists(path)) { + try ( + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile())); + ) + { + Object o = ois.readObject(); +// readStatusList = (List) ois.readObject(); + // 5. readObject가 List라면, 데이터를 읽어 리스트에 저장 + if (o instanceof List) { + List tempList = (List) o; + // 리스트가 ReadStatus 객체들로 구성되어 있으면 + if (!tempList.isEmpty() && tempList.get(0) instanceof ReadStatus) { + readStatusList = (List) tempList; + } + } + + } catch (IOException | ClassNotFoundException e) { + // 예외 발생 시 예외 메시지 출력 (optional: 로깅 추가) + e.printStackTrace(); + // 실패 시 빈 리스트 반환 + return readStatusList; + } + } + + // 6. load한 ReadStatus 리스트 반환 + return readStatusList; + } + + @Override + public void delete(UUID id) { + Path path = resolvePath(id); + if (Files.exists(path)) { + try { + Files.delete(path); // 해당 파일 삭제 + } catch (IOException e) { + throw new RuntimeException("Error deleting file", e); + } + } else { + throw new NoSuchElementException("ReadStatus with id " + id + " not found"); + } + + } + + @Override + public boolean existByChannelIdAndUserId(UUID userId, UUID channelId) { + // 해당 채널에 대한 파일을 찾ㄱ ㅗ존재 여부 확인 + return findByUserIdAndChannelId(userId, channelId) != null; + } + + @Override + public ReadStatus update(ReadStatus readStatus) { + Path path = resolvePath(readStatus.getId()); + + List readStatusList = new ArrayList<>(); + + // 기존 파일 읽기 + if (Files.exists(path)) { + try ( + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile()))) { + readStatusList = (List) ois.readObject(); + } catch (ClassNotFoundException | IOException e) { + throw new RuntimeException("Error reading from file", e); + } + } + + // 업덷이트할 ReadStatus가 리스트에 있는지 확인 + Optional existing = readStatusList.stream() + .filter(readStatus1 -> readStatus1.getId().equals(readStatus.getId())) + .findFirst(); + + if (existing.isPresent()) { + // 기존 값 수정 + readStatusList.remove(existing.get()); + readStatusList.add(readStatus); + // 파일로 다시 저장 + this.save(readStatus); + return readStatus; + } else { + throw new NoSuchElementException("ReadStatus with id " + readStatus.getId() + " not found"); + } + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java index 69c45c3b1..b02e2df38 100644 --- a/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java @@ -1,143 +1,102 @@ package com.sprint.mission.discodeit.repository.file; -//[ ] 다음의 조건을 만족하는 레포지토리 인터페이스의 구현체를 작성하세요. -//[ ] 클래스 패키지명: com.sprint.mission.discodeit.repository.file -//[ ] 클래스 네이밍 규칙: File[인터페이스 이름] -// [ ] 기존에 구현한 File*Service 구현체의 "저장 로직"과 관련된 코드를 참고하여 구현하세요. - import com.sprint.mission.discodeit.entity.User; import com.sprint.mission.discodeit.repository.UserRepository; +import org.springframework.stereotype.Repository; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.UUID; +@Repository public class FileUserRepository implements UserRepository { - - private final File file = new File("/data/users.txt"); - - // TODO 저장 메소드 (Serialization) - // 1. Instance 정보를 받는다. - // // 1-1. 파라미터로 객체를 받는다. or 객체 리스트를 받는다 - // // 1-2. 저장 목록을 리턴? - // 2. Instance 정보를 파일(경로)에 저장한다. - // 3. 저장된 Instance의 정보가 담긴 리스트를 리턴한다. <- 굳이 할 필요가 있나? - - public void save(User user) { - // 부모 디렉토리 없으면 생성 - File parentDir = file.getParentFile(); - if (!parentDir.exists()) { - parentDir.mkdirs(); // data/ 폴더 생성 - } - - try (ObjectOutputStream objectOOS = new ObjectOutputStream(new FileOutputStream(file)) // FOS는 Path를 직접 파라미터로 받지 못함 - ) { - objectOOS.writeObject(user); - - } catch (IOException e) { - throw new RuntimeException(e); + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileUserRepository() { + this.DIRECTORY = Paths.get(System.getProperty("user.dir"), "file-data-map", User.class.getSimpleName()); + if (Files.notExists(DIRECTORY)) { + try { + Files.createDirectories(DIRECTORY); + } catch (IOException e) { + throw new RuntimeException(e); + } } } - private void save(List userList) { - - // 부모 디렉토리 없으면 생성 - File parentDir = file.getParentFile(); - if (!parentDir.exists()) { - parentDir.mkdirs(); // data/ 폴더 생성 - } - try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file))) { - - oos.writeObject(userList); - } catch (IOException e) { - throw new RuntimeException(e); - } + private Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); } - public List load() { - List objectList = new ArrayList(); - Path path = Paths.get("/data/users.txt"); - - try (ObjectInputStream objectOIS = new ObjectInputStream(new FileInputStream(path.toFile())) + @Override + public User save(User user) { // user의 id를 받아 와서 resolvePath에다 넣고, 디렉토리에 user.getId().ser 파일을 만든다 + Path path = resolvePath(user.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) ) { - if (!Files.exists(path)) { - return new ArrayList<>(); - } - for (User object :(List) objectOIS.readObject()) { - - objectList.add(object); - } - } catch (FileNotFoundException e) { - System.out.println("파일을 찾을 수 없습니다."); - throw new RuntimeException(e); - } catch (IOException | ClassNotFoundException e) { - System.out.println("파일에 아무 것도 없습니다."); + oos.writeObject(user); + } catch (IOException e) { throw new RuntimeException(e); } - return objectList; + return user; } - - public void create(User user) { // Controller에서 만들어진 User 타입을 파라미터로 씀 - save(user); - } - - - // TODO 읽기 메소드 (Deserialization) - // // 1. 파일의 경로를 파라미터로 받는다. - // // 2. 불러온 Instance의 정보가 담긴 리스트를 리턴한다. - @Override - public User findById(UUID id) { - // 1. id를 입력하면, id에 해당하는 유저를 역직렬화하여 불러온다. - List objectList = load(); - for (User object : objectList) { - if (object instanceof User) { - User user = (User) object; - if (user.getId().equals(id)) { - return user; - } + public Optional findById(UUID id) { + User userNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + userNullable = (User) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); } } - return null; + return Optional.ofNullable(userNullable); } @Override public List findAll() { - return load(); + try { + return Files.list(DIRECTORY) + .filter(path -> path.toString().endsWith(EXTENSION)) + .map(path -> { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + return (User) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } catch (IOException e) { + throw new RuntimeException(e); + } } @Override - public void update(UUID id, String newName, String newEmail) { - List objectList = load(); - for (User object : objectList) { - if (object.getId().equals(id)) { - object.updateUser(newName, newEmail); - save(objectList); - break; - } - } + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); } @Override - public void delete(UUID id) { - List objectList = load(); - for (User object : objectList) { - if (object.getId().equals(id)) { - objectList.remove(object); - save(objectList); - break; - } + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); } } - // TODO 호출 메소드 - // Instance의 정보가 저장된 파일의 주소를 불러온다. - // // 1. save와 read 메소드가 반환한 List를 파라미터로 받는다. - // // 2. save와 read 메소드로 저장(호출)된 파일의 경로를 불러온다 - // // 3. String 타입으로 경로를 리턴한다. -// String loadPath(List list); } diff --git a/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserStatusRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserStatusRepository.java new file mode 100644 index 000000000..39f604e08 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserStatusRepository.java @@ -0,0 +1,120 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.repository.UserStatusRepository; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public class FileUserStatusRepository implements UserStatusRepository { + + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileUserStatusRepository() { // 생성자에서 File의 이름과 Path를 생성하고 Directory 없으면 생성 + this.DIRECTORY = Paths.get(System.getProperty("userStatus.dir"), "file-data-map", UserStatus.class.getSimpleName()); + if (Files.notExists(DIRECTORY)) { + try { + Files.createDirectories(DIRECTORY); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + private Path resolvePath(UUID id) {return DIRECTORY.resolve(id + EXTENSION);} // id만 있으면 EXTENSION을 합쳐 Path를 반환 + + @Override + public UserStatus save(UserStatus userStatus) { + Path path = resolvePath(userStatus.getId()); + try ( + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path.toFile())); + ) { + oos.writeObject(userStatus); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return userStatus; + } + + @Override + public Optional findByUserId(UUID userId) { + UserStatus userStatusNullable = null; // 초기화 + Path path = resolvePath(userId); // 경로 계산 + + if (Files.exists(path)) { // 파일 존재유무 + try ( + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile())); + ) + { + userStatusNullable = (UserStatus) ois.readObject(); // 파일에서 UserStatus 객체 read + return Optional.ofNullable(userStatusNullable); // Optional 처리 + } catch (ClassNotFoundException | IOException e) { + e.printStackTrace(); + return Optional.empty(); + } + } + + return Optional.empty(); + } + + @Override + public Optional find(UUID id) { + UserStatus userStatusNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile())); + ) + { + userStatusNullable = (UserStatus) ois.readObject(); + } catch (ClassNotFoundException | IOException e) { + throw new RuntimeException(e); + } + } + + return Optional.ofNullable(userStatusNullable); + } + + @Override + public List findAll() { + try { + return Files.list(DIRECTORY) + .filter(path -> path.toString().endsWith(EXTENSION)) + .map(path -> { + try ( + ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path.toFile())); + ) { + return (UserStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean existsByUserId(UUID userId) { + Path path = resolvePath(userId); + return Files.exists(path); + } + + @Override + public void delete(UUID userId) { + Path path = resolvePath(userId); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java new file mode 100644 index 000000000..e35217b42 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java @@ -0,0 +1,51 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; + +import java.util.*; +import java.util.stream.Collectors; + +public class JCFBinaryContentRepository implements BinaryContentRepository { + + Map binaryContentMap; + + public JCFBinaryContentRepository() { + this.binaryContentMap = new HashMap<>(); + } + + @Override + public BinaryContent save(BinaryContent binaryContent) { + // 1. BinaryContent를 Map에 저장 + binaryContentMap.put(binaryContent.getId(), binaryContent); + return binaryContent; + } + + @Override + public BinaryContent findById(UUID id) { + return binaryContentMap.get(id); + } + + @Override + public List findAllByIdIn(List ids) { + return ids.stream() // ids 리스트에 대해 Stream 생성 + .map(binaryContentMap::get) // 각 UUID에 대해 binaryContentMap에서 해당하는 BinaryContent 가져옴 + .filter(Objects::nonNull) // null 아닌 값만 filter + .collect(Collectors.toList()); // 리스트로 collect + } + + @Override + public List findAll() { + return new ArrayList<>(binaryContentMap.values()); + } + + @Override + public boolean existsById(UUID id) { + return binaryContentMap.containsKey(id); + } + + @Override + public void delete(UUID id) { + binaryContentMap.remove(id); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java index 0b7f0a9dd..e11c92da5 100644 --- a/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java @@ -5,45 +5,36 @@ import java.util.*; -// TODO 나중에 Repository객체를 연결해야함 public class JCFChannelRepository implements ChannelRepository { - Map channelMap; + private final Map data; public JCFChannelRepository() { - this.channelMap = new HashMap(); + this.data = new HashMap<>(); } @Override - public void create(Channel channel) { // Channel channel1 = new Channel(id, name, description)을 받아서 파라미터로 쓰면 됨 - this.channelMap.put(channel.getId(), channel); + public Channel save(Channel channel) { + this.data.put(channel.getId(), channel); + return channel; } @Override - public Channel findById(UUID id) { - - return this.channelMap.get(id); + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); } @Override public List findAll() { - List channels = new ArrayList<>(channelMap.values()); - - return channels; + return this.data.values().stream().toList(); } @Override - public void update(UUID id, String newName, String newDescription) { - Channel channel = this.channelMap.get(id); - if (channel != null) { - channel.updateChannel(newName, newDescription); - } + public boolean existsById(UUID id) { + return this.data.containsKey(id); } - public void delete(UUID id) { -// if (!this.channelMap.containsKey(id)) { -// throw new NoSuchElementException(id + "ID를 가진 채널을 찾을 수 없습니다."); // 비즈니스 로직 -// } - this.channelMap.remove(id); + @Override + public void deleteById(UUID id) { + this.data.remove(id); } - } diff --git a/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java index c9224a62a..5ad8b3556 100644 --- a/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java @@ -1,67 +1,40 @@ package com.sprint.mission.discodeit.repository.jcf; import com.sprint.mission.discodeit.entity.Message; -import com.sprint.mission.discodeit.repository.ChannelRepository; import com.sprint.mission.discodeit.repository.MessageRepository; -import com.sprint.mission.discodeit.repository.UserRepository; -import com.sprint.mission.discodeit.service.ChannelService; -import com.sprint.mission.discodeit.service.UserService; import java.util.*; -import java.util.stream.Collectors; public class JCFMessageRepository implements MessageRepository { - private final Map data; // messageId + private final Map data; - private final ChannelRepository channelRepository; - private final UserRepository userRepository; - - public JCFMessageRepository(ChannelRepository channelRepository, UserRepository userRepository) { - this.data = new HashMap(); - this.channelRepository = channelRepository; - this.userRepository = userRepository; + public JCFMessageRepository() { + this.data = new HashMap<>(); } - @Override - public void create(Message message) { // content, channelId, authorId가 담긴 Message 타입을 받아옴 - try { - channelRepository.findById(message.getChannelId()); // 비즈니스 로직 - userRepository.findById(message.getAuthorId()); // 비즈니스 로직 - } catch (Exception e) { - throw new RuntimeException(e); - } - - this.data.put(message.getId(), message); // 저장 로직 - + public Message save(Message message) { + this.data.put(message.getId(), message); + return message; } @Override - public Message findById(UUID id) { - Message message = data.get(id); -// if (message == null) { 비즈니스 로직 -// return null; -// } - return message; + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); } @Override public List findAll() { - return this.data.values().stream().collect(Collectors.toList()); + return this.data.values().stream().toList(); } @Override - public void updateMessage(UUID id, String newContent) { - Message message = this.findById(id); - - message.updateMessage(newContent); - + public boolean existsById(UUID id) { + return this.data.containsKey(id); } @Override - public void delete(UUID id) { - - Message message = this.findById(id); + public void deleteById(UUID id) { this.data.remove(id); } } diff --git a/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFReadStatusRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFReadStatusRepository.java new file mode 100644 index 000000000..8fefa6638 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFReadStatusRepository.java @@ -0,0 +1,103 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; + +import java.util.*; +import java.util.stream.Collectors; + +public class JCFReadStatusRepository implements ReadStatusRepository { + + Map readStatusMap; + Map> readStatusMapWithChannelId; + Map> readStatusMapWithUserId; + + public JCFReadStatusRepository() { + this.readStatusMap = new HashMap<>(); // 이게 얼마나 비효율적일까 + this.readStatusMapWithChannelId = new HashMap<>(); + this.readStatusMapWithUserId = new HashMap<>(); + } + + @Override + public ReadStatus save(ReadStatus readStatus) { + // 1. id를 key로 저장 + readStatusMap.put(readStatus.getId(), readStatus); + + // 2. channelId에 해당하는 ReadStatus 리스트를 가져와서 없으면 새로 생성 후 추가 + List readStatusListWithChannelId = readStatusMapWithChannelId + .getOrDefault(readStatus.getChannelId(), new ArrayList<>()); + readStatusListWithChannelId.add(readStatus); + readStatusMapWithChannelId.put(readStatus.getChannelId(), readStatusListWithChannelId); + + // 3. userId에 해당하는 ReadStatus 리스트를 가져와서 없으면 새로 생성 후 추가 + List readStatusListWithUserId = readStatusMapWithUserId + .getOrDefault(readStatus.getUserId(), new ArrayList<>()); + readStatusListWithUserId.add(readStatus); + readStatusMapWithUserId.put(readStatus.getUserId(), readStatusListWithUserId); + + ReadStatus result = readStatusMap.get(readStatus.getId()); + + return result; + } + + @Override + public ReadStatus findById(UUID id) { + ReadStatus result = readStatusMap.get(id); + return result; + } + + @Override + public List findByChannelId(UUID channelId) { + List result = readStatusMapWithChannelId.get(channelId); + return result; + } + + @Override + public List findAll() { + List result = new ArrayList<>(); + result.addAll(readStatusMap.values()); + return result; + } + + @Override + public boolean existByChannelIdAndUserId(UUID userId, UUID channelId) { + // 1. channelId에 해당하는 ReadStatus 리스트 가져오기 + List readStatusListWithChannelId = readStatusMapWithChannelId.getOrDefault(channelId, new ArrayList<>()); + + // 2. userId와 일치하는 ReadStatus 존재 유무 확인 + return readStatusListWithChannelId.stream() + .anyMatch(readStatus -> readStatus.getUserId().equals(userId)); + } + + @Override + public ReadStatus findByUserIdAndChannelId(UUID userId, UUID channelId) { + // 1. channelId에 해댕하는 ReadStatus 리스트 가져오기 + List readStatusListWithChannelId = readStatusMapWithChannelId.getOrDefault(channelId, new ArrayList<>()); + + // 2. userIdd와 일치하는 ReadStatus filter 하여 반환 + return (ReadStatus) readStatusListWithChannelId.stream() + .filter(readStatus -> readStatus.getUserId().equals(userId)); // userId와 일치하는 ReadStatus만 필터링 + } + + @Override + public ReadStatus update(ReadStatus readStatus) { + + return readStatusMap.put(readStatus.getId(), readStatus); + } + + @Override + public List findByUserId(UUID userId) { + if (readStatusMapWithUserId.containsKey(userId)) { + List result = readStatusMapWithUserId.getOrDefault(userId, new ArrayList<>()); + + return result; + } else { + throw new NoSuchElementException("ReadStatus not found"); + } + } + + @Override + public void delete(UUID id) { + readStatusMap.remove(id); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java index 5f8c998c4..a60363a37 100644 --- a/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java @@ -1,54 +1,40 @@ package com.sprint.mission.discodeit.repository.jcf; -//[ ] 다음의 조건을 만족하는 레포지토리 인터페이스의 구현체를 작성하세요. -//[ ] 클래스 패키지명: com.sprint.mission.discodeit.repository.jcf -//[ ] 클래스 네이밍 규칙: JCF[인터페이스 이름] -// [ ] 기존에 구현한 JCF*Service 구현체의 "저장 로직"과 관련된 코드를 참고하여 구현하세요. - -import com.sprint.mission.discodeit.entity.Channel; import com.sprint.mission.discodeit.entity.User; import com.sprint.mission.discodeit.repository.UserRepository; -import java.io.*; -import java.nio.file.Path; -import java.security.Key; import java.util.*; -public class JCFUserRepository implements UserRepository { // JCF를 활용한 저장로직 - - private final Map userMap; +public class JCFUserRepository implements UserRepository { + private final Map data; public JCFUserRepository() { - this.userMap = new HashMap(); // 주소와 파일을 받는 HashMap // Q. 이럴 때는 objectMap 대신 userMap이라고 해야 하는가? Map을 쓴 건 옳았나? + this.data = new HashMap<>(); } - public void create(User user) { - userMap.put(user.getId(), user); + @Override + public User save(User user) { + this.data.put(user.getId(), user); + return user; } @Override - public User findById(UUID id) { - return userMap.get(id); + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); } @Override public List findAll() { - return new ArrayList(userMap.values()); + return this.data.values().stream().toList(); } @Override - public void update(UUID id, String newName, String newEmail) { - User user = this.userMap.get(id); - if (user != null) { - user.updateUser(newName, newEmail); - } + public boolean existsById(UUID id) { + return this.data.containsKey(id); } @Override - public void delete(UUID id) { -// if (!this.userMap.containsKey(id)) { -// throw new NoSuchElementException(id + "ID를 가진 채널을 찾을 수 없습니다."); // 비즈니스 로직 -// } - this.userMap.remove(id); + public void deleteById(UUID id) { + this.data.remove(id); } } diff --git a/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserStatusRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserStatusRepository.java new file mode 100644 index 000000000..33ea2da93 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserStatusRepository.java @@ -0,0 +1,81 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.repository.UserStatusRepository; + +import java.util.*; + +public class JCFUserStatusRepository implements UserStatusRepository { + + Map userStatusMap = new HashMap<>(); // userId와 UserStatus를 entry로 가지는 JCF 생성 + + UserRepository userRepository; + UserStatusRepository userStatusRepository; + + public JCFUserStatusRepository(UserRepository userRepository, UserStatusRepository userStatusRepository) { + this.userStatusMap = new HashMap<>(); + // + this.userRepository = userRepository; + this.userStatusRepository = userStatusRepository; + } + + @Override + public UserStatus save(UserStatus userStatus) { + + // 1. User 찾기 + UUID userId = userStatus.getUserId(); + + // 2. 를 JCF에 저장 + userStatusMap.put(userId, userStatus); + + return userStatus; + } + + @Override + public Optional findByUserId(UUID userId) { + + return Optional.ofNullable(userStatusMap.get(userId)); + } + + @Override + public Optional find(UUID id) { + + // TODO Map에 저장되어 있는 UserStatus의 id로 UserStatus를 불러와야함 + // 1. userStatusMap의 values를 List로 변환 + UserStatus userStatus = userStatusMap.values() + .stream() + .filter(status -> status.getId().equals(id)) + .findFirst() + .orElseThrow(() -> new NoSuchElementException("UserStatus with that id not found")); + + return Optional.ofNullable(userStatus); + } + + @Override + public List findAll() { + + List userStatusList = userStatusMap.values() + .stream() + .toList(); + + return userStatusList; + } + + @Override + public boolean existsByUserId(UUID userId) { + + // 1. userStatusMap에서 userId에 해당하는 UserStatus가 존재하는지 확인 + boolean exists = userStatusMap.values() + .stream() + .anyMatch(status -> status.getUserId().equals(userId)); + + return exists; + } + + @Override + public void delete(UUID userId) { + + userStatusMap.remove(userId); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/AuthService.java b/src/main/java/com/sprint/mission/discodeit/service/AuthService.java new file mode 100644 index 000000000..0f06f20ab --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/AuthService.java @@ -0,0 +1,27 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.entity.dto.LoginRequest; +import com.sprint.mission.discodeit.repository.UserRepository; + +import java.util.List; + +public class AuthService { + + UserRepository userRepository; + + public User login(LoginRequest loginRequest) { + + List userList = userRepository.findAll() + .stream() + .toList(); + + for (User user : userList) { // O(n) 시간 복잡도 + if (user.getUsername().equals(loginRequest.username()) || user.getPassword().equals(loginRequest.password())) { + return user; + } + } + + throw new IllegalArgumentException("로그인에 실패했습니다. 사용자 이름 또는 비밀번호가 올바르지 않거나 정보가 없습니다."); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java index 11f43bc9d..410542221 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -1,14 +1,21 @@ package com.sprint.mission.discodeit.service; import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.dto.ChannelDTO; +import com.sprint.mission.discodeit.entity.dto.CreatePrivateChannelRequest; +import com.sprint.mission.discodeit.entity.dto.CreatePublicChannelRequest; +import com.sprint.mission.discodeit.entity.dto.UpdateChannelRequest; +import java.time.Instant; import java.util.List; +import java.util.Map; import java.util.UUID; public interface ChannelService { - Channel createChannel(String channelName, String description); // C - Channel readChannel(UUID id); // R - List readAllChannels(); - Channel updateChannel(UUID id, String newName, String newDescription); // U - void deleteChannel(UUID id); // D + Channel create(CreatePrivateChannelRequest request); + Channel create(CreatePublicChannelRequest request); + ChannelDTO find(UUID id); + List findAllByUserId(UUID userId); + Channel update(UpdateChannelRequest request); + void delete(UUID channelId); } diff --git a/src/main/java/com/sprint/mission/discodeit/service/MessageService.java b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java index da51bb461..f458aa316 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/MessageService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -1,15 +1,18 @@ package com.sprint.mission.discodeit.service; import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.entity.dto.CreateBinaryContentRequest; +import com.sprint.mission.discodeit.entity.dto.CreateMessageRequest; +import com.sprint.mission.discodeit.entity.dto.UpdateMessageRequest; import java.util.List; +import java.util.Optional; import java.util.UUID; public interface MessageService { - Message createMessage(String content, UUID channelId, UUID authorId); // C - Message readMessage(UUID id); // R - List readAllMessages(); -// List readMessagesByChannelId(UUID channelId); - Message updateMessage(UUID id, String newContent); // U - void deleteMessage(UUID id); // D + Message create(CreateMessageRequest request); + Message find(UUID messageId); + List findAllByChannelId(UUID channelId); + Message update(UpdateMessageRequest request); + void delete(UUID messageId); } diff --git a/src/main/java/com/sprint/mission/discodeit/service/UserService.java b/src/main/java/com/sprint/mission/discodeit/service/UserService.java index 3f1c37ad6..360354c31 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/UserService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/UserService.java @@ -1,15 +1,21 @@ package com.sprint.mission.discodeit.service; - +import com.sprint.mission.discodeit.entity.BinaryContent; import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.entity.dto.*; import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.UUID; public interface UserService { - User createUser(String RRN, String name, int age, String email); // C - User foundUser(UUID id); // R - List readAllUsers(); - User updateUser(UUID id, String newName, String newEmail); // U - void deleteUser(UUID id); // D + + User create(CreateUserRequest request, Optional binaryContentRequest); + boolean hasDuplicate(String username, String email); + UserDTO find(UUID id); + UserDTO findAll(); + User update(UUID userId, UpdateUserRequest request, Optional binaryContentRequest); + void delete(UUID userId); } diff --git a/src/main/java/com/sprint/mission/discodeit/service/basic/BasicBinaryContentService.java b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicBinaryContentService.java new file mode 100644 index 000000000..4157bac7e --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicBinaryContentService.java @@ -0,0 +1,71 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.entity.dto.CreateBinaryContentRequest; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; + +import java.util.*; + +public class BasicBinaryContentService { + + BinaryContentRepository binaryContentRepository; + + public BinaryContent create(CreateBinaryContentRequest request) { + + // 1. request에서 파라미터를 받아와 BinaryContent 생성 + if (request.fileName() == null || request.fileType() == null || request.content() == null) { + throw new NoSuchElementException("BinaryContent parameters are invalid."); + } + + // 2. BinaryContent 객체 생성 + BinaryContent binaryContent = new BinaryContent(request.fileName(), request.fileType(), request.content()); + + // 3. Repository에 저장 + return binaryContentRepository.save(binaryContent); + } + + + public BinaryContent find(UUID id) { + + // 1. repository에서 find(UUID id)로 BinaryContent 찾아서 반환 + + BinaryContent binaryContent = binaryContentRepository.findById(id); + + if (binaryContent == null) { + throw new NoSuchElementException("BinaryContent not found."); + } + + return binaryContent; + } + + public List findAllByIdIn(List ids) { + + if (ids == null || ids.isEmpty()) { + throw new NoSuchElementException("ids is empty."); + } + return binaryContentRepository.findAllByIdIn(ids); +// List binaryContentList = binaryContentRepository.findAll(); +// List result = new ArrayList<>(); +// if (!binaryContentList.isEmpty()) { +// for (BinaryContent binaryContent : binaryContentList) { +// for (UUID id : ids) { +// if (binaryContent.getId().equals(id)) { +// result.add(binaryContent); +// } +// } +// } +// } +// +// return result; + } + + public void delete(UUID id) { + + BinaryContent binaryContent = binaryContentRepository.findById(id); + if (binaryContent == null) { + throw new NoSuchElementException("BinaryContent not found."); + } + binaryContentRepository.delete(id); + } + +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/basic/BasicChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicChannelService.java new file mode 100644 index 000000000..7d31fefa8 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicChannelService.java @@ -0,0 +1,160 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.entity.*; +import com.sprint.mission.discodeit.entity.dto.ChannelDTO; +import com.sprint.mission.discodeit.entity.dto.CreatePublicChannelRequest; +import com.sprint.mission.discodeit.entity.dto.CreatePrivateChannelRequest; +import com.sprint.mission.discodeit.entity.dto.UpdateChannelRequest; +import com.sprint.mission.discodeit.entity.exception.CannotUpdateException; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import com.sprint.mission.discodeit.repository.MessageRepository; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.service.ChannelService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import javax.swing.text.html.Option; +import java.time.Instant; +import java.util.*; +import java.util.stream.Collectors; + + +@RequiredArgsConstructor +@Service +public class BasicChannelService implements ChannelService { + private final ChannelRepository channelRepository; + private final UserRepository userRepository; + ReadStatusRepository readStatusRepository; + MessageRepository messageRepository; + + @Override + public Channel create(CreatePrivateChannelRequest request) { + Channel channel = new Channel(ChannelType.PRIVATE, null, null); + channelRepository.save(channel); + + List userList = request.userList(); // userList를 넣는게 중요해짐 + for (User user : userList) { // 일단 userList의 값들이 User 객체인지 유효성 검사는 안했음 + ReadStatus readStatus = new ReadStatus(user, channel); + readStatusRepository.save(readStatus); + } + + return channel; + } + + @Override + public Channel create(CreatePublicChannelRequest request) { + Channel channel = new Channel(ChannelType.PUBLIC, request.name(), request.description()); + + return channelRepository.save(channel); + } + + // TODO + // - DTO를 활용하여: + // - [ ] 해당 채널의 가장 최근 메시지의 시간 정보를 포함합니다. + @Override + public ChannelDTO find(UUID channelId) { // 애는 ChannelId임 + + // 1. 채널 조회 + Channel channel = this.channelRepository + .findById(channelId) + .orElseThrow(() -> new NoSuchElementException("Channel with channelId " + channelId + " not found")); + + // 2. 가장 최근 메시지 읽은 시간 조회 + Instant lastReadAt = readStatusRepository + .findById(channelId) + .getLastReadAt(); + + // 3. PRIVATE 채널일 경우, 참여한 사용자 ID 정보 포함 + List userIds = new ArrayList<>(); + + // FIXME : userIds는 List를 가져야함 + if (channel.getType() == ChannelType.PRIVATE) { + // 3-1. ReadStatus에서 UserId를 여러 개 가져옴 + List readStatuses = readStatusRepository.findByChannelId(channelId); + + // 참여한 모든 사용자 ID를 userIds에 추가 + for (ReadStatus readStatus : readStatuses) { + userIds.add(readStatus.getUserId()); // 여러 개의 userId 추가 + } + Optional> optionalUserIds = Optional.ofNullable(userIds); + ChannelDTO channelDTO = new ChannelDTO(channel, lastReadAt, optionalUserIds); + + return channelDTO; + } else { // PUBLIC + ChannelDTO channelDTO = new ChannelDTO(channel, lastReadAt, Optional.empty()); + + return channelDTO; + } + + } + + // FIXME : List를 return하도록 수정 + @Override + public List findAllByUserId(UUID userId) { + + // 1. return 기본값 설정 + List privateChannelDTOList = new ArrayList<>(); + List publicChannelDTOList = new ArrayList<>(); + + // 2. userId를 통해 channelId에 해당하는 DTO를 찾는다. + List readStatuses = readStatusRepository.findByUserId(userId); + + // 3. 각 Channel에 대해 처리 + for (ReadStatus readStatus : readStatuses) { + UUID channelId = readStatus.getChannelId(); + ChannelDTO channelDTO = this.find(channelId); + // 4. 채널 타입이 PRIVATE인 경우 + if (channelDTO.channel().getType() == ChannelType.PRIVATE) { + // PRIVATE 채널에 해당하는 userId를 포함시켜서 목록에 추가 + List userIds = new ArrayList<>(); + userIds.add(userId); // 현재 userId를 userIds 리스트에 추가 + + // PRIVATE 채널일 경우 User ID를 포함하여 ChannelDTO 생성 + ChannelDTO privateChannelDTO = new ChannelDTO(channelDTO.channel(), channelDTO.lastReadAt(), Optional.of(userIds)); + privateChannelDTOList.add(privateChannelDTO); + + } else { // PUBLIC 채널인 경우 + publicChannelDTOList.add(channelDTO); + } + } + // 5. 최종적으로 PUBLIC과 PRIVATE 채널 리스트를 합쳐서 반환 + privateChannelDTOList.addAll(publicChannelDTOList); + return privateChannelDTOList; // PRIVATE 채널 목록을 먼저 반환 (혹은 publicChannelDTOList를 반환할 수도 있음) + } + + @Override + public Channel update(UpdateChannelRequest request) { + Channel channel = channelRepository.findById(request.channelId()) + .orElseThrow(() -> new NoSuchElementException("Channel with id " + request.channelId() + " not found")); + + if (channel.getType() == ChannelType.PUBLIC) { + channel.update(request.newName(), request.newDescription()); + + return channelRepository.save(channel); + } else { + throw new CannotUpdateException("PRIVATE 채널은 수정할 수 없습니다."); + } + } + + @Override + public void delete(UUID channelId) { + // 1. Channel 도메인 삭제 + if (!channelRepository.existsById(channelId)) { + throw new NoSuchElementException("Channel with id " + channelId + " not found"); + } + channelRepository.deleteById(channelId); + + // 2. ReadStatus 도메인 삭제 + List readStatuses = readStatusRepository.findByChannelId(channelId); + for (ReadStatus readStatus : readStatuses) { + readStatusRepository.delete(readStatus.getUserId()); + } + + // 3. Message 도메인 삭제 + List messages = messageRepository.findAllByChannelId(channelId); + for (Message message : messages) { + messageRepository.deleteById(message.getId()); + } + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/basic/BasicMessageService.java b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicMessageService.java new file mode 100644 index 000000000..f3e6d8be1 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicMessageService.java @@ -0,0 +1,94 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.entity.dto.CreateBinaryContentRequest; +import com.sprint.mission.discodeit.entity.dto.CreateMessageRequest; +import com.sprint.mission.discodeit.entity.dto.UpdateMessageRequest; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import com.sprint.mission.discodeit.repository.MessageRepository; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.service.MessageService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.*; + +@RequiredArgsConstructor +@Service +public class BasicMessageService implements MessageService { + private final MessageRepository messageRepository; + // + private final ChannelRepository channelRepository; + private final UserRepository userRepository; + BinaryContentRepository binaryContentRepository; + + @Override + public Message create(CreateMessageRequest request) { + // 1. Channel 유효성 검사 + if (!channelRepository.existsById(request.channelId())) { + throw new NoSuchElementException("Channel not found with id " + request.channelId()); + } + + // 2. User 유효성 검사 + if (!userRepository.existsById(request.authorId())) { + throw new NoSuchElementException("Author not found with id " + request.authorId()); + } + + // 3. Message 생성 + Message message = new Message(request.content(), request.channelId(), request.authorId()); + + // 4. 첨부파일 처리 + if (request.attachments() != null && !request.attachments().isEmpty()) { + for (CreateBinaryContentRequest attachment : request.attachments()) { + BinaryContent binaryContent = new BinaryContent(attachment.id(), attachment.fileName(), attachment.fileType(), attachment.content()); + // 첨부파일을 서버에 저장, 파일 ID 얻어옴 + binaryContentRepository.save(binaryContent); + message.update(binaryContent.getId()); + } + } + + // 5. 메시지 저장 + return messageRepository.save(message); + } + + @Override + public Message find(UUID messageId) { + + return messageRepository.findById(messageId) + .orElseThrow(() -> new NoSuchElementException("Message with id " + messageId + " not found")); + } + + @Override + public List findAllByChannelId(UUID channelId) { + + List messages = messageRepository.findAllByChannelId(channelId); + + return messages; + } + + @Override + public Message update(UpdateMessageRequest request) { + Message message = messageRepository.findById(request.messageId()) + .orElseThrow(() -> new NoSuchElementException("Message with id " + request.messageId() + " not found")); + message.update(request.content()); + return messageRepository.save(message); + } + + @Override + public void delete(UUID messageId) { + if (!messageRepository.existsById(messageId)) { + throw new NoSuchElementException("Message with id " + messageId + " not found"); + } + + Message message = messageRepository.findById(messageId).get(); + List ids = message.getAttachmentIds(); + for (UUID id : ids) { + if (binaryContentRepository.existsById(id)) { + binaryContentRepository.delete(id); + } + } + messageRepository.deleteById(messageId); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/basic/BasicReadStatusService.java b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicReadStatusService.java new file mode 100644 index 000000000..922c0275f --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicReadStatusService.java @@ -0,0 +1,69 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.entity.dto.CreateReadStatusRequest; +import com.sprint.mission.discodeit.entity.dto.UpdateReadStatusRequest; +import com.sprint.mission.discodeit.entity.exception.DuplicateReadStatusException; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; +import com.sprint.mission.discodeit.repository.UserRepository; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.UUID; + +public class BasicReadStatusService { + + ChannelRepository channelRepository; + UserRepository userRepository; + ReadStatusRepository readStatusRepository; + + public ReadStatus create(CreateReadStatusRequest request) { + + // 1. User 존재 여부 확인 + User user = userRepository.findById(request.user().getId()) + .orElseThrow(() -> new NoSuchElementException("User not found")); + + // 2. Channel 존재 여부 확인 + Channel channel = channelRepository.findById(request.channel().getId()) + .orElseThrow(() -> new NoSuchElementException("Channel not found")); + + // 3. 이미 같은 Channel과 User에 대한 ReadStatus 존재 여부 확인 + boolean exists = readStatusRepository.existByChannelIdAndUserId(request.user().getId(), request.channel().getId()); + if (exists) { + throw new DuplicateReadStatusException("ReadStatus already exists for this channel and user "); + } + + // 4. ReadStatus 객체 생성 + ReadStatus readStatus = new ReadStatus(user, channel); + + // 5. 저장 + return readStatusRepository.save(readStatus); + } + + public Optional find(UUID id) { + + return Optional.ofNullable(readStatusRepository.findById(id)); + } + + public List findAllByUserId(UUID userId) { + + return readStatusRepository.findByUserId(userId); + } + + public ReadStatus update(UpdateReadStatusRequest request) { + if (!readStatusRepository.existByChannelIdAndUserId(request.channel().getId(), request.user().getId())) { + throw new NoSuchElementException("ReadStatus not found for this channel and user"); + } + ReadStatus readStatus = readStatusRepository.findByUserIdAndChannelId(request.user().getId(), request.channel().getId()); + + return readStatusRepository.update(readStatus); + } + + public void delete(UUID id) { + readStatusRepository.delete(id); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java index 2932a9803..10d24605b 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java @@ -1,54 +1,161 @@ package com.sprint.mission.discodeit.service.basic; +import com.sprint.mission.discodeit.entity.BinaryContent; import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.entity.dto.*; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.repository.UserStatusRepository; import com.sprint.mission.discodeit.service.UserService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Optional; -import java.util.UUID; +import java.util.*; +import java.util.stream.Collectors; +import static java.util.Arrays.stream; + +@RequiredArgsConstructor +@Service public class BasicUserService implements UserService { - UserRepository userRepository; + private final UserRepository userRepository; + UserStatusRepository userStatusRepository; + BinaryContentRepository binaryContentRepository; + + @Override + public boolean hasDuplicate(String username, String email) { - public BasicUserService(UserRepository userRepository) { - this.userRepository = userRepository; + // TODO + /* 1. 파라미터와 비교할 UserRepository의 username과 email 데이터를 불러온다. + * 1-1. findAll()에 있는 UserDTO(List, List> + 1-2. List을 userList에 할당한다. + * 1-3. username과 email을 추출해서 각각 중복검사 하여 결과를 return 한다. + * */ + List userList = findAll().userList(); + + for (User user : userList) { + if(user.getUsername().equals(username) && user.getEmail().equals(email)) { + return true; + } + } + return false; } @Override - public User createUser(String RRN, String name, int age, String email) { - User user = new User(RRN, name, age, email); + public User create(CreateUserRequest request, Optional binaryContentRequest) { + + /* 중복검사 선행 */ + if (hasDuplicate(request.username(), request.email())) { + throw new IllegalArgumentException("사용자 이름 또는 이메일 주소가 중복됩니다."); + } + + // User 객체 생성 + User user = new User(request.username(), request.email(), request.password(), null); // profileId는 어떻게 설정해주냐 + + // UserStatus 객체 생성만 하고 상태정보를 가져오진 않음 + UserStatus userStatus = new UserStatus(user); + + // FIXME 선택적으로를 아직 구현 안함 + // BinaryContent 객체 생성 및 저장 후 User 객체의 profileId과 연결 + binaryContentRequest.ifPresent(binaryContent -> { + BinaryContent newBinaryContent = new BinaryContent(UUID.randomUUID(), binaryContent.fileName(), + binaryContent.fileType(), binaryContent.content()); + + binaryContentRepository.save(newBinaryContent); + + user.setProfileId(newBinaryContent.getId()); + }); - userRepository.create(user); + // 트랜잭션 시작 + try { + // 데이터베이스에 UserStatus와 BinaryContent 저장 + userStatusRepository.save(userStatus); +// binaryContentRepository.save(binaryContent); - return userRepository.findById(user.getId()); + return userRepository.save(user); + } catch (Exception e) { + throw new RuntimeException("사용자 생성에 실패했습니다.", e); + } } @Override - public User foundUser(UUID id) { + public UserDTO find(UUID id) { - return userRepository.findById(id); + Optional user = userRepository.findById(id); + + if (user.isPresent()) { + UserStatus userStatus = userStatusRepository.findByUserId(id); + UserDTO userDTO = new UserDTO(user, userStatus); + return userDTO; + } else { + throw new IllegalArgumentException("해당 User의 UserStatus가 존재하지 않습니다."); + } } + // FIXME : List를 return하도록 수정 @Override - public List readAllUsers() { + public UserDTO findAll() { + // 1. User 목록 조회 + List userList = userRepository.findAll(); + + // 2. 각 User에 대해 UserStatus 조회 후 Optional 래퍼 클래스로 감싸기 + List userStatuses = new ArrayList<>(); + + // 3. User와 UserStatus 연결 + for (User user : userList) { + // 3-1. password 제외 + user.update(user.getUsername(), user.getEmail(), null); + // 3-2. 연결 + UserStatus userStatus = Optional.ofNullable(userStatusRepository.findByUserId(user.getId())) + .orElseThrow(() -> new IllegalArgumentException("해당 유저의 UserStatus가 존재하지 않습니다.")); - return userRepository.findAll(); + userStatuses.add(userStatus); + } + + return new UserDTO(userList, userStatuses); } @Override - public User updateUser(UUID id, String newName, String newEmail) { - User user = userRepository.findById(id); - userRepository.update(user.getId(), newName, newEmail); + public User update(UUID userId, UpdateUserRequest request, Optional binaryContentRequest) { + // 1. User를 userId로 찾아오기 + User user = userRepository.findById(userId) + .orElseThrow(() -> new NoSuchElementException("User with id " + userId + " not found")); + + // 2. User 객채의 필드 update + user.update(request.username(), request.email(), request.password()); + + // 3. BinaryContent 업데이트 (profileId가 조ㅓㄴ재하는 경우) + request.binaryContent().ifPresent(binaryContent -> { + // 3.1 기존 BinaryContent 삭제 (profileId가 일치하는 BinaryContent 삭제) + BinaryContent existingBinaryContent = Optional.ofNullable(binaryContentRepository.findById(user.getProfileId())) + .orElseThrow(() -> new NoSuchElementException("BinaryContent with profileId " + binaryContent.getId() + " not found" )); + + + binaryContentRepository.delete(existingBinaryContent.getId()); + + // 3.2 새로운 BinaryContent 저장 (새로운 프로필 이미지) + BinaryContent newBinaryContent = new BinaryContent(binaryContent.getId(), binaryContent.getFileName(), binaryContent.getFileType(), binaryContent.getContent()); + binaryContentRepository.save(newBinaryContent); + }); - return userRepository.findById(id); + return userRepository.save(user); } @Override - public void deleteUser(UUID id) { - User user = userRepository.findById(id); - userRepository.delete(id); + public void delete(UUID userId) { + if (!userRepository.existsById(userId)) { + throw new NoSuchElementException("User with id " + userId + " not found"); + } + userRepository.deleteById(userId); + if (!binaryContentRepository.existsById(userId)) { + throw new NoSuchElementException("BinaryContent with profileId " + userId + " not found"); + } + binaryContentRepository.delete(userId); + if (!userStatusRepository.existsByUserId(userId)) { + throw new NoSuchElementException("UserStatus with profileId " + userId + " not found"); + } + userStatusRepository.delete(userId); } } diff --git a/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserStatusService.java b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserStatusService.java new file mode 100644 index 000000000..3c674d4a4 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserStatusService.java @@ -0,0 +1,111 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.entity.dto.CreateUserStatusRequest; +import com.sprint.mission.discodeit.entity.dto.UpdateUserStatusRequest; +import com.sprint.mission.discodeit.entity.exception.DuplicateUserStatusException; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.repository.UserStatusRepository; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.UUID; + +public class BasicUserStatusService { + + UserRepository userRepository; + UserStatusRepository userStatusRepository; + + UserStatus create(CreateUserStatusRequest request) { + + // 1. User 존재 확인 + if (!userRepository.existsById(request.user().getId())) { + throw new NoSuchElementException("User not found"); + } + + // 2. User의 UserStatus 존재 확인 + if (!userStatusRepository.existsByUserId(request.user().getId())) { + throw new DuplicateUserStatusException("UserStatus with userId already exists"); + } + + // 3. UserStatus 생성 및 저장 + UserStatus userStatus = new UserStatus(request.user()); + + return userStatusRepository.save(userStatus); + } + + public Optional find(UUID id) { + if (!userRepository.existsById(id)) { + throw new NoSuchElementException("User not found"); + } + + if (!userStatusRepository.existsByUserId(id)) { + throw new DuplicateUserStatusException("UserStatus with userId not found"); + } + + return userStatusRepository.find(id); + } + + List findAll() { + + return userStatusRepository.findAll(); + } + + Optional update(UpdateUserStatusRequest request) { + + if (!userRepository.existsById(request.user().getId())) { + throw new NoSuchElementException("User not found"); + } + + if (!userStatusRepository.existsByUserId(request.user().getId())) { + throw new DuplicateUserStatusException("UserStatus with userId not found"); + } + + // 1. 수정할 UserStatus 찾기 + Optional userStatus = userStatusRepository.find(request.userStatus().getId()); + + // 2. 수정 + userStatus.get().update(); + + // 3. 저장 + userStatusRepository.save(userStatus.get()); + + return userStatus; + } + + Optional updateByUserId(UpdateUserStatusRequest request) { + + if (!userRepository.existsById(request.user().getId())) { + throw new NoSuchElementException("User not found"); + } + + if (!userStatusRepository.existsByUserId(request.user().getId())) { + throw new DuplicateUserStatusException("UserStatus with userId not found"); + } + + // 1. 수정할 UserStatus 찾기 + Optional optionalUserStatus = userStatusRepository.find(request.user().getId()); + + // 2. 수정 + optionalUserStatus.get().update(); + + // 3. 저장 + userStatusRepository.save(optionalUserStatus.get()); + + return optionalUserStatus; + } + + void delete(UUID id) { + + if (!userRepository.existsById(id)) { + throw new NoSuchElementException("User not found"); + } + + if (!userStatusRepository.existsByUserId(id)) { + throw new DuplicateUserStatusException("UserStatus with userId not found"); + } + + userStatusRepository.delete(id); + } +} \ No newline at end of file diff --git a/src/main/java/com/sprint/mission/discodeit/service/file/FileUserService.java b/src/main/java/com/sprint/mission/discodeit/service/file/FileUserService.java index 2be915097..7e2e84479 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/file/FileUserService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/file/FileUserService.java @@ -69,7 +69,7 @@ public User createUser(String RRN, String name, int age, String email) { } @Override - public User foundUser(UUID id) { // R + public User findById(UUID id) { // R List users = loadUsers(path); // 유저 리스트 역직렬화 // 객체 하나하나 역직렬화 아님 for (User user : users) { diff --git a/src/main/java/com/sprint/mission/discodeit/service/file/data/channel.txt b/src/main/java/com/sprint/mission/discodeit/service/file/data/channel.txt deleted file mode 100644 index 4f742106b..000000000 Binary files a/src/main/java/com/sprint/mission/discodeit/service/file/data/channel.txt and /dev/null differ diff --git a/src/main/java/com/sprint/mission/discodeit/service/file/data/message.txt b/src/main/java/com/sprint/mission/discodeit/service/file/data/message.txt deleted file mode 100644 index 1b6193d1f..000000000 Binary files a/src/main/java/com/sprint/mission/discodeit/service/file/data/message.txt and /dev/null differ diff --git a/src/main/java/com/sprint/mission/discodeit/service/file/data/user.txt b/src/main/java/com/sprint/mission/discodeit/service/file/data/user.txt deleted file mode 100644 index 625ce47f1..000000000 Binary files a/src/main/java/com/sprint/mission/discodeit/service/file/data/user.txt and /dev/null differ diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFMessageService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFMessageService.java index f9b02da4e..938103ab6 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFMessageService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFMessageService.java @@ -29,7 +29,7 @@ public Message createMessage(String content, UUID channelId, UUID authorId) { // return message; try { channelService.readChannel(channelId); - userService.foundUser(authorId); + userService.findById(authorId); } catch (Exception e) { throw e; } diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFUserService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFUserService.java index db1eb79a6..cb9ecac24 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFUserService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFUserService.java @@ -22,7 +22,7 @@ public User createUser(String RRN, String name, int age, String email) { // C } @Override - public User foundUser(UUID id) { // R + public User findById(UUID id) { // R User userNullable = this.data.get(id); return Optional.ofNullable(userNullable) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 000000000..545cf9f09 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=discodeit diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 000000000..e84ddd7f9 --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,4 @@ +discodeit: + repository: + type: jcf + file-directory: .discodeit \ No newline at end of file diff --git a/src/test/java/com/sprint/mission/discodeit/DiscodeitApplicationTests.java b/src/test/java/com/sprint/mission/discodeit/DiscodeitApplicationTests.java new file mode 100644 index 000000000..3a987a214 --- /dev/null +++ b/src/test/java/com/sprint/mission/discodeit/DiscodeitApplicationTests.java @@ -0,0 +1,13 @@ +package com.sprint.mission.discodeit; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DiscodeitApplicationTests { + + @Test + void contextLoads() { + } + +}