From f3ebe8d3698eb35d80d87402ff1e3253593ef5fc Mon Sep 17 00:00:00 2001 From: jiho0420 Date: Fri, 9 Jan 2026 11:11:51 +0900 Subject: [PATCH 01/10] init sprint2 --- .gitignore | 43 +++++ .idea/.gitignore | 10 + .idea/misc.xml | 6 + build.gradle | 20 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 60756 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 234 +++++++++++++++++++++++ gradlew.bat | 89 +++++++++ settings.gradle | 1 + src/main/java/org/example/Main.java | 17 ++ 10 files changed, 426 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 build.gradle create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100644 src/main/java/org/example/Main.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1fac4d56a --- /dev/null +++ b/.gitignore @@ -0,0 +1,43 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ +.kotlin + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..987919843 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# 디폴트 무시된 파일 +/shelf/ +/workspace.xml +# 쿼리 파일을 포함한 무시된 디폴트 폴더 +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# 에디터 기반 HTTP 클라이언트 요청 +/httpRequests/ diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..4b151abfd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000..973cc4853 --- /dev/null +++ b/build.gradle @@ -0,0 +1,20 @@ +plugins { + id 'java' +} + +group = 'org.example' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.10.0') + testImplementation 'org.junit.jupiter:junit-jupiter' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..249e5832f090a2944b7473328c07c9755baa3196 GIT binary patch literal 60756 zcmb5WV{~QRw(p$^Dz@00IL3?^hro$gg*4VI_WAaTyVM5Foj~O|-84 z$;06hMwt*rV;^8iB z1~&0XWpYJmG?Ts^K9PC62H*`G}xom%S%yq|xvG~FIfP=9*f zZoDRJBm*Y0aId=qJ?7dyb)6)JGWGwe)MHeNSzhi)Ko6J<-m@v=a%NsP537lHe0R* z`If4$aaBA#S=w!2z&m>{lpTy^Lm^mg*3?M&7HFv}7K6x*cukLIGX;bQG|QWdn{%_6 zHnwBKr84#B7Z+AnBXa16a?or^R?+>$4`}{*a_>IhbjvyTtWkHw)|ay)ahWUd-qq$~ zMbh6roVsj;_qnC-R{G+Cy6bApVOinSU-;(DxUEl!i2)1EeQ9`hrfqj(nKI7?Z>Xur zoJz-a`PxkYit1HEbv|jy%~DO^13J-ut986EEG=66S}D3!L}Efp;Bez~7tNq{QsUMm zh9~(HYg1pA*=37C0}n4g&bFbQ+?-h-W}onYeE{q;cIy%eZK9wZjSwG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0z_$mZ4rbQ0o=^curCs3bJK6sq z9fu-aW-l#>z~ca(B;4yv;2RZ?tGYAU)^)Kz{L|4oPj zdOf_?de|#yS)p2v8-N||+XL=O*%3+y)oI(HbM)Ds?q8~HPzIP(vs*G`iddbWq}! z(2!VjP&{Z1w+%eUq^ '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="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 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 000000000..2b0b99ee7 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = '10-sprint-mission' \ No newline at end of file diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java new file mode 100644 index 000000000..876719ad3 --- /dev/null +++ b/src/main/java/org/example/Main.java @@ -0,0 +1,17 @@ +package org.example; + +//TIP 코드를 실행하려면 을(를) 누르거나 +// 에디터 여백에 있는 아이콘을 클릭하세요. +public class Main { + public static void main(String[] args) { + //TIP 캐럿을 강조 표시된 텍스트에 놓고 을(를) 누르면 + // IntelliJ IDEA이(가) 수정을 제안하는 것을 확인할 수 있습니다. + System.out.printf("Hello and welcome!"); + + for (int i = 1; i <= 5; i++) { + //TIP 을(를) 눌러 코드 디버그를 시작하세요. 1개의 중단점을 설정해 드렸습니다 + // 언제든 을(를) 눌러 중단점을 더 추가할 수 있습니다. + System.out.println("i = " + i); + } + } +} \ No newline at end of file From 7b5ec65d2a1463a291cb48a818a3e5ba3e263dfa Mon Sep 17 00:00:00 2001 From: jiho0420 Date: Mon, 12 Jan 2026 13:26:51 +0900 Subject: [PATCH 02/10] Basic Requirements --- .idea/gradle.xml | 17 +++ .idea/misc.xml | 6 +- .idea/vcs.xml | 7 + .../mission/discodeit/JavaApplication.java | 130 ++++++++++++++++++ .../mission/discodeit/entity/BaseEntity.java | 32 +++++ .../mission/discodeit/entity/Channel.java | 17 +++ .../mission/discodeit/entity/Message.java | 34 +++++ .../sprint/mission/discodeit/entity/User.java | 36 +++++ .../discodeit/service/ChannelService.java | 18 +++ .../discodeit/service/MessageService.java | 15 ++ .../discodeit/service/UserService.java | 21 +++ .../service/jcf/JCFChannelService.java | 50 +++++++ .../service/jcf/JCFMessageService.java | 54 ++++++++ .../discodeit/service/jcf/JCFUserService.java | 59 ++++++++ src/main/java/org/example/Main.java | 17 --- 15 files changed, 495 insertions(+), 18 deletions(-) create mode 100644 .idea/gradle.xml create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/com/sprint/mission/discodeit/JavaApplication.java create mode 100644 src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java create mode 100644 src/main/java/com/sprint/mission/discodeit/entity/Channel.java create mode 100644 src/main/java/com/sprint/mission/discodeit/entity/Message.java create mode 100644 src/main/java/com/sprint/mission/discodeit/entity/User.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/ChannelService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/MessageService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/UserService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/jcf/JCFMessageService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/jcf/JCFUserService.java delete mode 100644 src/main/java/org/example/Main.java diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 000000000..2a65317ef --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 4b151abfd..913a8d6a7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,10 @@ - + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..288b36b1e --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java new file mode 100644 index 000000000..92eca9934 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -0,0 +1,130 @@ +package com.sprint.mission.discodeit; + +import com.sprint.mission.discodeit.entity.Channel; +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 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.List; +import java.util.UUID; + +public class JavaApplication { + public static void main(String[] args) { + System.out.println("========== 디스코드 서비스 테스트 시작 ==========\n"); + + UserService userService = new JCFUserService(); + ChannelService channelService = new JCFChannelService(); + + // User 테스트 + System.out.println("유저 기능 테스트"); + + // 등록 + User newUser = new User("jiho0420","1234" , "jiho@codeit.kr"); + userService.createUser(newUser); + UUID createdUserId = newUser.getId(); + + // 단건 조회 + System.out.println("단건 조회 시도:"); + User foundUser = userService.findUserById(createdUserId); + System.out.println("조회된 유저: " + foundUser.getUsername()); + + // 다건 조회 + System.out.println("전체 조회 시도:"); + List allUsers = userService.findAllUsers(); + System.out.println("총 유저 수: " + allUsers.size() + "명"); + + // 수정 + System.out.println(">> 유저 정보 수정 시도:"); + + User updateData = new User("SuperJiho", null, "super@codeit.kr"); + userService.updateUser(createdUserId, updateData); + + // 수정된 데이터 조회 + User updatedUser = userService.findUserById(createdUserId); + System.out.println("수정된 이름: " + updatedUser.getUsername()); + System.out.println("수정된 이메일: " + updatedUser.getEmail()); + + // 비밀번호 변경 테스트 + userService.changePassword(createdUserId, "5678"); + System.out.println("비밀번호 변경 완료"); + + // 삭제 + System.out.println(">> 유저 삭제 시도:"); + userService.deleteUser(createdUserId); + + // 삭제 확인 + System.out.println(">> 삭제 확인:"); + try { + userService.findUserById(createdUserId); + } catch (IllegalArgumentException e) { + System.out.println("에러 발생: " + e.getMessage()); + } + + System.out.println("\n------------------------------------------\n"); + + // Channel 테스트 + System.out.println("채널 기능 테스트"); + + // 등록 + Channel newChannel = new Channel("본방"); + channelService.createChannel(newChannel); + UUID createdChannelId = newChannel.getId(); + + // 조회 + Channel foundChannel = channelService.findChannelById(createdChannelId); + System.out.println("생성된 채널명: " + foundChannel.getChannelName()); + + // 수정 + Channel updateChannelData = new Channel("공지사항"); + channelService.updateChannel(createdChannelId, updateChannelData); + + // 수정 확인 + Channel updatedChannel = channelService.findChannelById(createdChannelId); + System.out.println("변경된 채널명: " + updatedChannel.getChannelName()); + + // 삭제 + channelService.deleteChannel(createdChannelId); + + // 삭제 확인 + try { + channelService.findChannelById(createdChannelId); + } catch (IllegalArgumentException e) { + System.out.println("에러 발생: " + e.getMessage()); + } + + System.out.println("\n------------------------------------------\n"); + + // 메시지 기능 테스트 + System.out.println("\n[3] 메시지 기능 테스트"); + MessageService messageService = new JCFMessageService(); + + // 생성된 유저가 채널에 글 작성 + Message msg1 = new Message("안녕하세요", createdChannelId, createdUserId); + messageService.createMessage(msg1); + + Message msg2 = new Message("반갑습니다", createdChannelId, createdUserId); + messageService.createMessage(msg2); + + // 특정 채널의 메시지 목록 조회 + System.out.println(">> [" + foundChannel.getChannelName() + "] 채널의 메시지 목록:"); + List channelMessages = messageService.findMessagesByChannelId(createdChannelId); + + for (Message msg : channelMessages) { + System.out.println("- 내용: " + msg.getContent()); + } + + // 메시지 수정 + messageService.updateMessage(msg1.getId(), "안녕하세요! (수정됨)"); + System.out.println("수정 후 내용: " + messageService.findMessageById(msg1.getId()).getContent()); + + // 메시지 삭제 + messageService.deleteMessage(msg2.getId()); + + System.out.println("\n========== 테스트 종료 =========="); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java b/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java new file mode 100644 index 000000000..023c5f085 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java @@ -0,0 +1,32 @@ +package com.sprint.mission.discodeit.entity; + +import java.util.UUID; + +public class BaseEntity { + private UUID id; + private Long createdAt; + private Long updatedAt; + + public BaseEntity() { + this.id = UUID.randomUUID(); + this.createdAt = System.currentTimeMillis(); + this.updatedAt = System.currentTimeMillis(); + } + + public Long getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Long updatedAt) { + this.updatedAt = updatedAt; + } + + public Long getCreatedAt() { + return createdAt; + } + + public UUID getId() { + return id; + } + +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/Channel.java b/src/main/java/com/sprint/mission/discodeit/entity/Channel.java new file mode 100644 index 000000000..48f4a3e66 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/Channel.java @@ -0,0 +1,17 @@ +package com.sprint.mission.discodeit.entity; + +public class Channel extends BaseEntity{ + private String channelName; + + public String getChannelName() { + return channelName; + } + + public void updateChannelInfo(String newChannelName){ + this.channelName = newChannelName; + } + + public Channel(String channelName) { + this.channelName = channelName; + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/Message.java b/src/main/java/com/sprint/mission/discodeit/entity/Message.java new file mode 100644 index 000000000..cb4d7774d --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/Message.java @@ -0,0 +1,34 @@ +package com.sprint.mission.discodeit.entity; + +import java.util.UUID; + +public class Message extends BaseEntity{ + private String content; + private UUID channelId; + private UUID userId; + + public String getContent() { + return content; + } + + public UUID getChannelId() { + return channelId; + } + + public UUID getUserId() { + return userId; + } + + public void updateContent(String newContent){ + this.content = newContent; + super.setUpdatedAt(System.currentTimeMillis()); + } + + public Message(String content, UUID channelId, UUID userId) { + this.content = content; + this.channelId = channelId; + this.userId = userId; + } + + +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/User.java b/src/main/java/com/sprint/mission/discodeit/entity/User.java new file mode 100644 index 000000000..e061be56d --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/User.java @@ -0,0 +1,36 @@ +package com.sprint.mission.discodeit.entity; + +public class User extends BaseEntity { + private String username; + private String password; + private String email; + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getEmail() { + return email; + } + + public void updateUserInfo(String newUsername, String newEmail){ + this.username = newUsername; + this.email = newEmail; + this.setUpdatedAt(System.currentTimeMillis()); + } + + public void updatePassword(String newPassword){ + this.password = newPassword; + this.setUpdatedAt(System.currentTimeMillis()); + } + + public User(String username, String password, String email) { + this.username = username; + this.password = password; + this.email = email; + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java new file mode 100644 index 000000000..826a1e00a --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -0,0 +1,18 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.entity.Channel; +import java.util.List; +import java.util.UUID; + +public interface ChannelService { + void createChannel(Channel channelName); + + void deleteChannel(UUID id); + + Channel findChannelById(UUID id); + List findAllChannels(); + + void updateChannel(UUID id, Channel channelName); + + +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/MessageService.java b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java new file mode 100644 index 000000000..76c220ab9 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -0,0 +1,15 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.entity.Message; + +import java.util.List; +import java.util.UUID; + +public interface MessageService { + void createMessage(Message message); + void deleteMessage(UUID id); + Message findMessageById(UUID id); + void updateMessage(UUID id, String newContent); + List findAllMessages(); + List findMessagesByChannelId(UUID channelId); +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/UserService.java b/src/main/java/com/sprint/mission/discodeit/service/UserService.java new file mode 100644 index 000000000..1ac0af077 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/UserService.java @@ -0,0 +1,21 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.entity.User; + +import java.util.List; +import java.util.UUID; + +public interface UserService { + void createUser(User user); + + User findUserById(UUID id); + + List findAllUsers(); + + void updateUser(UUID id, User user); + + void changePassword(UUID id, String newPassword); + + void deleteUser(UUID id); + +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java new file mode 100644 index 000000000..bfb370bd7 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java @@ -0,0 +1,50 @@ +package com.sprint.mission.discodeit.service.jcf; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.service.ChannelService; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class JCFChannelService implements ChannelService { + private final List channelList; + + public JCFChannelService(){ + this.channelList = new ArrayList<>(); + } + @Override + public void createChannel(Channel channel) { + channelList.add(channel); + System.out.println(channel.getChannelName() + "채널 생성이 완료되었습니다."); + } + + @Override + public Channel findChannelById(UUID id){ + return channelList.stream() + .filter(channel -> channel.getId().equals(id)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + } + + @Override + public List findAllChannels(){ + return channelList; + } + + @Override + public void deleteChannel(UUID id){ + channelList.removeIf(channel -> channel.getId().equals(id)); + } + + public void updateChannel(UUID id, Channel channelName){ + Channel targetChannel = findChannelById(id); + + if(targetChannel != null){ + targetChannel.updateChannelInfo(channelName.getChannelName()); + } else { + System.out.println("수정할 채널을 찾을 수 없습니다."); + } + } + +} 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 new file mode 100644 index 000000000..466a9b9b9 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFMessageService.java @@ -0,0 +1,54 @@ +package com.sprint.mission.discodeit.service.jcf; + +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.service.MessageService; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +public class JCFMessageService implements MessageService { + private final List messageList; + public JCFMessageService(){ + this.messageList = new ArrayList<>(); + } + + public void createMessage(Message message){ + messageList.add(message); + System.out.println("메시지가 전송되었습니다. " + message.getContent()); + } + + public List findMessagesByChannelId(UUID channelId){ + return messageList.stream() + .filter(message -> message.getChannelId().equals(channelId)) + .collect(Collectors.toList()); + } + + public List findAllMessages(){ + return messageList; + } + + public Message findMessageById(UUID id){ + return messageList.stream() + .filter(msg -> msg.getId().equals(id)) + .findFirst() + .orElse(null); + } + + public void updateMessage(UUID id, String newContent){ + Message targetMessage = findMessageById(id); + if(targetMessage != null){ + targetMessage.updateContent(newContent); + System.out.println("메시지가 수정되었습니다"); + }else{ + System.out.println("수정할 메시지가 없습니다"); + } + } + + public void deleteMessage(UUID id){ + messageList.removeIf(msg -> msg.getId().equals(id)); + System.out.println("메시지가 삭제되었습니다"); + } + +} 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 new file mode 100644 index 000000000..c6d90c5a0 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFUserService.java @@ -0,0 +1,59 @@ +package com.sprint.mission.discodeit.service.jcf; + +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.service.UserService; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class JCFUserService implements UserService { + private final List userList; + public JCFUserService(){ + this.userList = new ArrayList<>(); + } + + @Override + public void createUser(User user) { + userList.add(user); + System.out.println(user.getUsername() + "님 회원가입 완료되었습니다."); + } + + @Override + public User findUserById(UUID id){ + return userList.stream() + .filter(user -> user.getId().equals(id)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + } + + @Override + public List findAllUsers(){ + return userList; + } + + @Override + public void updateUser(UUID id, User user){ + User targetUser = findUserById(id); + + if(targetUser != null){ + targetUser.updateUserInfo(user.getUsername(), user.getEmail()); + } else { + System.out.println("수정할 유저를 찾을 수 없습니다"); + } + } + + public void deleteUser(UUID id){ + userList.removeIf(user -> user.getId().equals(id)); + } + + @Override + public void changePassword(UUID id, String newPassword) { + User targetUser = findUserById(id); + if (targetUser != null) { + targetUser.updatePassword(newPassword); + } else { + System.out.println("해당 유저를 찾을 수 없습니다."); + } + } +} diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java deleted file mode 100644 index 876719ad3..000000000 --- a/src/main/java/org/example/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.example; - -//TIP 코드를 실행하려면 을(를) 누르거나 -// 에디터 여백에 있는 아이콘을 클릭하세요. -public class Main { - public static void main(String[] args) { - //TIP 캐럿을 강조 표시된 텍스트에 놓고 을(를) 누르면 - // IntelliJ IDEA이(가) 수정을 제안하는 것을 확인할 수 있습니다. - System.out.printf("Hello and welcome!"); - - for (int i = 1; i <= 5; i++) { - //TIP 을(를) 눌러 코드 디버그를 시작하세요. 1개의 중단점을 설정해 드렸습니다 - // 언제든 을(를) 눌러 중단점을 더 추가할 수 있습니다. - System.out.println("i = " + i); - } - } -} \ No newline at end of file From 57f73e4c5444433a50efe244d7db90274bbd7c2a Mon Sep 17 00:00:00 2001 From: jiho0420 Date: Tue, 13 Jan 2026 01:47:21 +0900 Subject: [PATCH 03/10] =?UTF-8?q?ChannelService=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20Message?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/discodeit/JavaApplication.java | 58 ++++++++++--------- .../mission/discodeit/entity/Message.java | 22 +++---- .../discodeit/service/ChannelService.java | 2 +- .../discodeit/service/MessageService.java | 2 +- .../service/jcf/JCFChannelService.java | 16 +++-- .../service/jcf/JCFMessageService.java | 25 ++++++-- 6 files changed, 70 insertions(+), 55 deletions(-) diff --git a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java index 92eca9934..42b052922 100644 --- a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -19,11 +19,12 @@ public static void main(String[] args) { UserService userService = new JCFUserService(); ChannelService channelService = new JCFChannelService(); + MessageService messageService = new JCFMessageService(userService, channelService); // User 테스트 System.out.println("유저 기능 테스트"); - // 등록 + // 유저 등록 User newUser = new User("jiho0420","1234" , "jiho@codeit.kr"); userService.createUser(newUser); UUID createdUserId = newUser.getId(); @@ -53,24 +54,13 @@ public static void main(String[] args) { userService.changePassword(createdUserId, "5678"); System.out.println("비밀번호 변경 완료"); - // 삭제 - System.out.println(">> 유저 삭제 시도:"); - userService.deleteUser(createdUserId); - - // 삭제 확인 - System.out.println(">> 삭제 확인:"); - try { - userService.findUserById(createdUserId); - } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); - } System.out.println("\n------------------------------------------\n"); // Channel 테스트 System.out.println("채널 기능 테스트"); - // 등록 + // 채널 등록 Channel newChannel = new Channel("본방"); channelService.createChannel(newChannel); UUID createdChannelId = newChannel.getId(); @@ -87,28 +77,15 @@ public static void main(String[] args) { Channel updatedChannel = channelService.findChannelById(createdChannelId); System.out.println("변경된 채널명: " + updatedChannel.getChannelName()); - // 삭제 - channelService.deleteChannel(createdChannelId); - - // 삭제 확인 - try { - channelService.findChannelById(createdChannelId); - } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); - } System.out.println("\n------------------------------------------\n"); // 메시지 기능 테스트 System.out.println("\n[3] 메시지 기능 테스트"); - MessageService messageService = new JCFMessageService(); // 생성된 유저가 채널에 글 작성 - Message msg1 = new Message("안녕하세요", createdChannelId, createdUserId); - messageService.createMessage(msg1); - - Message msg2 = new Message("반갑습니다", createdChannelId, createdUserId); - messageService.createMessage(msg2); + Message msg1 = messageService.createMessage("안녕하세요", createdChannelId, createdUserId); + Message msg2 = messageService.createMessage("반갑습니다", createdChannelId, createdUserId); // 특정 채널의 메시지 목록 조회 System.out.println(">> [" + foundChannel.getChannelName() + "] 채널의 메시지 목록:"); @@ -122,7 +99,32 @@ public static void main(String[] args) { messageService.updateMessage(msg1.getId(), "안녕하세요! (수정됨)"); System.out.println("수정 후 내용: " + messageService.findMessageById(msg1.getId()).getContent()); + // 유저 삭제 + System.out.println(">> 유저 삭제 시도:"); + userService.deleteUser(createdUserId); + + // 유저 삭제 확인 + System.out.println(">> 유저 삭제 확인:"); + try { + userService.findUserById(createdUserId); + } catch (IllegalArgumentException e) { + System.out.println("에러 발생: " + e.getMessage()); + } + + // 채널 삭제 + System.out.println(">> 채널 삭제 시도:"); + channelService.deleteChannel(createdChannelId); + + // 채널 삭제 확인 + System.out.println(">> 채널 삭제 확인:"); + try { + channelService.findChannelById(createdChannelId); + } catch (IllegalArgumentException e) { + System.out.println("에러 발생: " + e.getMessage()); + } + // 메시지 삭제 + System.out.println(">> 메시지 삭제 시도:"); messageService.deleteMessage(msg2.getId()); System.out.println("\n========== 테스트 종료 =========="); 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 cb4d7774d..f5d234d41 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/Message.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/Message.java @@ -4,19 +4,19 @@ public class Message extends BaseEntity{ private String content; - private UUID channelId; - private UUID userId; + private Channel channel; + private User user; - public String getContent() { - return content; + public User getUser() { + return user; } - public UUID getChannelId() { - return channelId; + public Channel getChannel() { + return channel; } - public UUID getUserId() { - return userId; + public String getContent() { + return content; } public void updateContent(String newContent){ @@ -24,10 +24,10 @@ public void updateContent(String newContent){ super.setUpdatedAt(System.currentTimeMillis()); } - public Message(String content, UUID channelId, UUID userId) { + public Message(String content, Channel channel, User user) { this.content = content; - this.channelId = channelId; - this.userId = userId; + this.channel = channel; + this.user = user; } 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 826a1e00a..24053ae70 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -12,7 +12,7 @@ public interface ChannelService { Channel findChannelById(UUID id); List findAllChannels(); - void updateChannel(UUID id, Channel channelName); + Channel updateChannel(UUID id, Channel channelName); } 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 76c220ab9..6030bab87 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/MessageService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -6,7 +6,7 @@ import java.util.UUID; public interface MessageService { - void createMessage(Message message); + Message createMessage(String content, UUID channelId, UUID userId); void deleteMessage(UUID id); Message findMessageById(UUID id); void updateMessage(UUID id, String newContent); diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java index bfb370bd7..fc0090316 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java @@ -33,18 +33,16 @@ public List findAllChannels(){ } @Override - public void deleteChannel(UUID id){ - channelList.removeIf(channel -> channel.getId().equals(id)); + public void deleteChannel(UUID id){ // 예외 처리가 구현되어있는 findChannelById(id) 사용 + Channel targetChannel = findChannelById(id); + channelList.remove(targetChannel); } - public void updateChannel(UUID id, Channel channelName){ - Channel targetChannel = findChannelById(id); + public Channel updateChannel(UUID id, Channel channelName){ + Channel targetChannel = findChannelById(id); // 예외 처리가 구현되어있는 findChannelById(id) 사용 - if(targetChannel != null){ - targetChannel.updateChannelInfo(channelName.getChannelName()); - } else { - System.out.println("수정할 채널을 찾을 수 없습니다."); - } + targetChannel.updateChannelInfo(channelName.getChannelName()); + return targetChannel; } } 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 466a9b9b9..f6e5c2310 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 @@ -1,7 +1,11 @@ package com.sprint.mission.discodeit.service.jcf; +import com.sprint.mission.discodeit.entity.Channel; 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 java.util.ArrayList; import java.util.List; @@ -10,18 +14,29 @@ public class JCFMessageService implements MessageService { private final List messageList; - public JCFMessageService(){ + private final UserService userService; + private final ChannelService channelService; + + public JCFMessageService(UserService userService, ChannelService channelService){ this.messageList = new ArrayList<>(); + this.userService = userService; + this.channelService = channelService; } - public void createMessage(Message message){ - messageList.add(message); - System.out.println("메시지가 전송되었습니다. " + message.getContent()); + public Message createMessage(String content, UUID channelId, UUID userId){ + Channel channel = channelService.findChannelById(channelId); + User user = userService.findUserById(userId); + + Message newMessage = new Message(content, channel, user); + + messageList.add(newMessage); + + return newMessage; } public List findMessagesByChannelId(UUID channelId){ return messageList.stream() - .filter(message -> message.getChannelId().equals(channelId)) + .filter(message -> message.getChannel().getId().equals(channelId)) .collect(Collectors.toList()); } From c9d2bee1cf8a2af7b6df5eb9d1a077b824de44f0 Mon Sep 17 00:00:00 2001 From: jiho0420 Date: Tue, 13 Jan 2026 14:35:42 +0900 Subject: [PATCH 04/10] =?UTF-8?q?email,=20username=EC=9D=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=EC=9E=91=EC=97=85=20=EB=B0=8F=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC=20=EA=B0=95=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/discodeit/JavaApplication.java | 76 +++++++++++-------- .../mission/discodeit/entity/Channel.java | 1 + .../sprint/mission/discodeit/entity/User.java | 6 +- .../discodeit/service/ChannelService.java | 4 +- .../discodeit/service/MessageService.java | 2 +- .../discodeit/service/UserService.java | 8 +- .../service/jcf/JCFChannelService.java | 11 +-- .../service/jcf/JCFMessageService.java | 21 +++-- .../discodeit/service/jcf/JCFUserService.java | 37 +++++---- 9 files changed, 94 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java index 42b052922..f35b0e3fb 100644 --- a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -25,34 +25,46 @@ public static void main(String[] args) { System.out.println("유저 기능 테스트"); // 유저 등록 - User newUser = new User("jiho0420","1234" , "jiho@codeit.kr"); - userService.createUser(newUser); - UUID createdUserId = newUser.getId(); + User createdUser = userService.createUser("임지호", "1234", "jiho@codeit.kr"); + UUID createdUserId = createdUser.getId(); // 단건 조회 - System.out.println("단건 조회 시도:"); + System.out.println("\n단건 조회 시도:"); User foundUser = userService.findUserById(createdUserId); System.out.println("조회된 유저: " + foundUser.getUsername()); // 다건 조회 - System.out.println("전체 조회 시도:"); + System.out.println("\n전체 조회 시도:"); List allUsers = userService.findAllUsers(); System.out.println("총 유저 수: " + allUsers.size() + "명"); // 수정 - System.out.println(">> 유저 정보 수정 시도:"); + System.out.println("\n>> 유저 정보 수정 시도:"); - User updateData = new User("SuperJiho", null, "super@codeit.kr"); - userService.updateUser(createdUserId, updateData); + User updatedUser = userService.updateUsername(createdUserId, "아임지호"); + System.out.println("이름 변경 확인: " + updatedUser.getUsername()); + + updatedUser = userService.updateEmail(createdUserId, "newjiho@codeit.kr"); + System.out.println("이메일 변경 확인: " + updatedUser.getEmail()); + + updatedUser = userService.changePassword(createdUserId, "234234"); + System.out.println("비밀번호 변경 확인: " + updatedUser.getPassword()); + + System.out.println("최종 상태: " + updatedUser.toString()); + +// userService.updateUsername(createdUserId, "아임지호"); +// userService.updateEmail(createdUserId, "newjiho@codeit.kr"); +// userService.changePassword(createdUserId, "234234"); // 수정된 데이터 조회 - User updatedUser = userService.findUserById(createdUserId); - System.out.println("수정된 이름: " + updatedUser.getUsername()); - System.out.println("수정된 이메일: " + updatedUser.getEmail()); +// User updatedUser = userService.findUserById(createdUserId); +// System.out.println("수정된 이름: " + updatedUser.getUsername()); +// System.out.println("수정된 이메일: " + updatedUser.getEmail()); +// System.out.println("수정된 비밀번호: " + updatedUser.getPassword()); // 비밀번호 변경 테스트 - userService.changePassword(createdUserId, "5678"); - System.out.println("비밀번호 변경 완료"); +// userService.changePassword(createdUserId, "5678"); +// System.out.println("비밀번호 변경 완료: " + userService.findUserById(createdUserId).getPassword()); System.out.println("\n------------------------------------------\n"); @@ -61,8 +73,7 @@ public static void main(String[] args) { System.out.println("채널 기능 테스트"); // 채널 등록 - Channel newChannel = new Channel("본방"); - channelService.createChannel(newChannel); + Channel newChannel = channelService.createChannel("본방"); UUID createdChannelId = newChannel.getId(); // 조회 @@ -70,22 +81,25 @@ public static void main(String[] args) { System.out.println("생성된 채널명: " + foundChannel.getChannelName()); // 수정 - Channel updateChannelData = new Channel("공지사항"); - channelService.updateChannel(createdChannelId, updateChannelData); + Channel updatedChannel = channelService.updateChannel(createdChannelId, "공지방"); +// Channel updateChannelData = new Channel("공지사항"); +// channelService.updateChannel(createdChannelId, updateChannelData.getChannelName()); // 수정 확인 - Channel updatedChannel = channelService.findChannelById(createdChannelId); +// Channel updatedChannel = channelService.findChannelById(createdChannelId); System.out.println("변경된 채널명: " + updatedChannel.getChannelName()); System.out.println("\n------------------------------------------\n"); // 메시지 기능 테스트 - System.out.println("\n[3] 메시지 기능 테스트"); + System.out.println("\n메시지 기능 테스트"); // 생성된 유저가 채널에 글 작성 Message msg1 = messageService.createMessage("안녕하세요", createdChannelId, createdUserId); Message msg2 = messageService.createMessage("반갑습니다", createdChannelId, createdUserId); + UUID msg1Id = msg1.getId(); + UUID msg2Id = msg2.getId(); // 특정 채널의 메시지 목록 조회 System.out.println(">> [" + foundChannel.getChannelName() + "] 채널의 메시지 목록:"); @@ -96,15 +110,18 @@ public static void main(String[] args) { } // 메시지 수정 - messageService.updateMessage(msg1.getId(), "안녕하세요! (수정됨)"); - System.out.println("수정 후 내용: " + messageService.findMessageById(msg1.getId()).getContent()); + System.out.println("\n"); + msg1 = messageService.updateMessage(msg1Id, "자바 실습 중"); +// messageService.updateMessage(msg1.getId(), "안녕하세요! (수정됨)"); + System.out.println("수정 후 내용: " + msg1.getContent()); + + // 메시지 삭제 + System.out.println("\n>> 메시지 삭제 시도:"); + messageService.deleteMessage(msg2.getId()); // 유저 삭제 - System.out.println(">> 유저 삭제 시도:"); userService.deleteUser(createdUserId); - - // 유저 삭제 확인 - System.out.println(">> 유저 삭제 확인:"); + System.out.println("\n>> 유저 삭제 확인:"); try { userService.findUserById(createdUserId); } catch (IllegalArgumentException e) { @@ -112,21 +129,14 @@ public static void main(String[] args) { } // 채널 삭제 - System.out.println(">> 채널 삭제 시도:"); channelService.deleteChannel(createdChannelId); - - // 채널 삭제 확인 - System.out.println(">> 채널 삭제 확인:"); + System.out.println("\n>> 채널 삭제 확인:"); try { channelService.findChannelById(createdChannelId); } catch (IllegalArgumentException e) { System.out.println("에러 발생: " + e.getMessage()); } - // 메시지 삭제 - System.out.println(">> 메시지 삭제 시도:"); - messageService.deleteMessage(msg2.getId()); - System.out.println("\n========== 테스트 종료 =========="); } } 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 48f4a3e66..6c3d96d99 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/Channel.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/Channel.java @@ -9,6 +9,7 @@ public String getChannelName() { public void updateChannelInfo(String newChannelName){ this.channelName = newChannelName; + super.setUpdatedAt(System.currentTimeMillis()); } public Channel(String channelName) { 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 e061be56d..4bac396f2 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/User.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/User.java @@ -17,8 +17,12 @@ public String getEmail() { return email; } - public void updateUserInfo(String newUsername, String newEmail){ + public void updateUsername(String newUsername){ this.username = newUsername; + this.setUpdatedAt(System.currentTimeMillis()); + } + + public void updateEmail(String newEmail){ this.email = newEmail; this.setUpdatedAt(System.currentTimeMillis()); } 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 24053ae70..108ac05cf 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -5,14 +5,14 @@ import java.util.UUID; public interface ChannelService { - void createChannel(Channel channelName); + Channel createChannel(String channelName); void deleteChannel(UUID id); Channel findChannelById(UUID id); List findAllChannels(); - Channel updateChannel(UUID id, Channel channelName); + Channel updateChannel(UUID id, String channelName); } 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 6030bab87..4560a9e6e 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/MessageService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -9,7 +9,7 @@ public interface MessageService { Message createMessage(String content, UUID channelId, UUID userId); void deleteMessage(UUID id); Message findMessageById(UUID id); - void updateMessage(UUID id, String newContent); + Message updateMessage(UUID id, String newContent); List findAllMessages(); List findMessagesByChannelId(UUID channelId); } 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 1ac0af077..ea95d93a4 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/UserService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/UserService.java @@ -6,15 +6,17 @@ import java.util.UUID; public interface UserService { - void createUser(User user); + User createUser(String username, String password, String email); User findUserById(UUID id); List findAllUsers(); - void updateUser(UUID id, User user); + User updateUsername(UUID id, String newUsername); - void changePassword(UUID id, String newPassword); + User updateEmail(UUID id, String newEmail); + + User changePassword(UUID id, String newPassword); void deleteUser(UUID id); diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java index fc0090316..73f0da0cd 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java @@ -13,10 +13,13 @@ public class JCFChannelService implements ChannelService { public JCFChannelService(){ this.channelList = new ArrayList<>(); } + @Override - public void createChannel(Channel channel) { + public Channel createChannel(String channelName) { + Channel channel = new Channel(channelName); channelList.add(channel); System.out.println(channel.getChannelName() + "채널 생성이 완료되었습니다."); + return channel; } @Override @@ -38,11 +41,9 @@ public void deleteChannel(UUID id){ // 예외 처리가 구현되어있는 findC channelList.remove(targetChannel); } - public Channel updateChannel(UUID id, Channel channelName){ + public Channel updateChannel(UUID id, String channelName){ Channel targetChannel = findChannelById(id); // 예외 처리가 구현되어있는 findChannelById(id) 사용 - - targetChannel.updateChannelInfo(channelName.getChannelName()); + targetChannel.updateChannelInfo(channelName); return targetChannel; } - } 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 f6e5c2310..8991497f9 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 @@ -28,7 +28,6 @@ public Message createMessage(String content, UUID channelId, UUID userId){ User user = userService.findUserById(userId); Message newMessage = new Message(content, channel, user); - messageList.add(newMessage); return newMessage; @@ -48,22 +47,22 @@ public Message findMessageById(UUID id){ return messageList.stream() .filter(msg -> msg.getId().equals(id)) .findFirst() - .orElse(null); + .orElseThrow(() -> new IllegalArgumentException("해당 메시지 없음")); } - public void updateMessage(UUID id, String newContent){ + public Message updateMessage(UUID id, String newContent){ Message targetMessage = findMessageById(id); - if(targetMessage != null){ - targetMessage.updateContent(newContent); - System.out.println("메시지가 수정되었습니다"); - }else{ - System.out.println("수정할 메시지가 없습니다"); - } + + targetMessage.updateContent(newContent); + System.out.println("메시지가 수정되었습니다"); + + return targetMessage; } public void deleteMessage(UUID id){ - messageList.removeIf(msg -> msg.getId().equals(id)); - System.out.println("메시지가 삭제되었습니다"); + Message targetMessage = findMessageById(id); + messageList.remove(targetMessage); + System.out.println("메시지 삭제 완료: " + targetMessage.getContent()); } } 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 c6d90c5a0..ec76f228e 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 @@ -14,9 +14,11 @@ public JCFUserService(){ } @Override - public void createUser(User user) { - userList.add(user); - System.out.println(user.getUsername() + "님 회원가입 완료되었습니다."); + public User createUser(String username, String password, String email) { + User newUser = new User(username, password, email); + userList.add(newUser); + System.out.println(username + "님 회원가입 완료되었습니다."); + return newUser; } @Override @@ -33,27 +35,30 @@ public List findAllUsers(){ } @Override - public void updateUser(UUID id, User user){ + public User updateUsername(UUID id, String newUsername){ User targetUser = findUserById(id); + targetUser.updateUsername(newUsername); + return targetUser; + } - if(targetUser != null){ - targetUser.updateUserInfo(user.getUsername(), user.getEmail()); - } else { - System.out.println("수정할 유저를 찾을 수 없습니다"); - } + @Override + public User updateEmail(UUID id, String newEmail){ + User targetUser = findUserById(id); + targetUser.updateEmail(newEmail); + return targetUser; } + @Override public void deleteUser(UUID id){ - userList.removeIf(user -> user.getId().equals(id)); + User targetUser = findUserById(id); + userList.remove(targetUser); + System.out.println(targetUser.getUsername() + "님 삭제 완료되었습니다"); } @Override - public void changePassword(UUID id, String newPassword) { + public User changePassword(UUID id, String newPassword) { User targetUser = findUserById(id); - if (targetUser != null) { - targetUser.updatePassword(newPassword); - } else { - System.out.println("해당 유저를 찾을 수 없습니다."); - } + targetUser.updatePassword(newPassword); + return targetUser; } } From 4c2ea0fa2cd7da0bb09596b2034d2f19b87705cb Mon Sep 17 00:00:00 2001 From: jiho0420 Date: Tue, 13 Jan 2026 17:08:13 +0900 Subject: [PATCH 05/10] =?UTF-8?q?feat:=20=EC=9D=B4=EB=A6=84=EA=B3=BC=20?= =?UTF-8?q?=EC=9D=B4=EB=A9=94=EC=9D=BC=20=EC=84=A0=ED=83=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EA=B0=80=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test: userInfo 수정 로직 테스트 케이스 추가 --- .../mission/discodeit/JavaApplication.java | 40 ++++++++----------- .../sprint/mission/discodeit/entity/User.java | 5 +++ .../discodeit/service/UserService.java | 4 +- .../discodeit/service/jcf/JCFUserService.java | 36 +++++++++++++---- 4 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java index f35b0e3fb..62b31e44b 100644 --- a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -25,9 +25,12 @@ public static void main(String[] args) { System.out.println("유저 기능 테스트"); // 유저 등록 - User createdUser = userService.createUser("임지호", "1234", "jiho@codeit.kr"); + User createdUser = userService.createUser("임지호", "1234", "jiho@codeit.com"); UUID createdUserId = createdUser.getId(); + User createdUser2 = userService.createUser("홍길동", "gildong", "gildong@codeit.com"); + UUID createdUserId2 = createdUser2.getId(); + // 단건 조회 System.out.println("\n단건 조회 시도:"); User foundUser = userService.findUserById(createdUserId); @@ -41,31 +44,23 @@ public static void main(String[] args) { // 수정 System.out.println("\n>> 유저 정보 수정 시도:"); - User updatedUser = userService.updateUsername(createdUserId, "아임지호"); + User updatedUser = userService.updateUserInfo(createdUserId, "아임지호", "newjiho@codeit.com"); System.out.println("이름 변경 확인: " + updatedUser.getUsername()); - - updatedUser = userService.updateEmail(createdUserId, "newjiho@codeit.kr"); - System.out.println("이메일 변경 확인: " + updatedUser.getEmail()); - updatedUser = userService.changePassword(createdUserId, "234234"); System.out.println("비밀번호 변경 확인: " + updatedUser.getPassword()); - System.out.println("최종 상태: " + updatedUser.toString()); - -// userService.updateUsername(createdUserId, "아임지호"); -// userService.updateEmail(createdUserId, "newjiho@codeit.kr"); -// userService.changePassword(createdUserId, "234234"); - - // 수정된 데이터 조회 -// User updatedUser = userService.findUserById(createdUserId); -// System.out.println("수정된 이름: " + updatedUser.getUsername()); -// System.out.println("수정된 이메일: " + updatedUser.getEmail()); -// System.out.println("수정된 비밀번호: " + updatedUser.getPassword()); + System.out.println("\n------------------------------------------\n"); - // 비밀번호 변경 테스트 -// userService.changePassword(createdUserId, "5678"); -// System.out.println("비밀번호 변경 완료: " + userService.findUserById(createdUserId).getPassword()); + User updatedUser2 = userService.updateUserInfo(createdUserId2, null, "newgildong@naver.com"); + System.out.println(updatedUser2); + updatedUser2 = userService.updateUserInfo(createdUserId2, "홍 길동", "new@codeit.kr"); + System.out.println(updatedUser2); + updatedUser2 = userService.updateUserInfo(createdUserId2, null, null); + System.out.println(updatedUser2); + updatedUser2 = userService.updateUserInfo(createdUserId2, "뉴길동", null); + System.out.println(updatedUser2); + System.out.println("최종 상태: " + updatedUser); System.out.println("\n------------------------------------------\n"); @@ -82,11 +77,8 @@ public static void main(String[] args) { // 수정 Channel updatedChannel = channelService.updateChannel(createdChannelId, "공지방"); -// Channel updateChannelData = new Channel("공지사항"); -// channelService.updateChannel(createdChannelId, updateChannelData.getChannelName()); // 수정 확인 -// Channel updatedChannel = channelService.findChannelById(createdChannelId); System.out.println("변경된 채널명: " + updatedChannel.getChannelName()); @@ -120,8 +112,8 @@ public static void main(String[] args) { messageService.deleteMessage(msg2.getId()); // 유저 삭제 - userService.deleteUser(createdUserId); System.out.println("\n>> 유저 삭제 확인:"); + userService.deleteUser(createdUserId); try { userService.findUserById(createdUserId); } catch (IllegalArgumentException e) { 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 4bac396f2..9db1f4405 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/User.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/User.java @@ -37,4 +37,9 @@ public User(String username, String password, String email) { this.password = password; this.email = email; } + + @Override + public String toString() { + return "이름: " + username + ", 이메일: " + email + ", 비밀번호: " + password; + } } 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 ea95d93a4..5982c2b91 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/UserService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/UserService.java @@ -12,9 +12,7 @@ public interface UserService { List findAllUsers(); - User updateUsername(UUID id, String newUsername); - - User updateEmail(UUID id, String newEmail); + User updateUserInfo(UUID id, String newUsername, String newEmail); User changePassword(UUID id, String newPassword); 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 ec76f228e..b038f1d60 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 @@ -35,17 +35,39 @@ public List findAllUsers(){ } @Override - public User updateUsername(UUID id, String newUsername){ + public User updateUserInfo(UUID id, String newUsername, String newEmail){ User targetUser = findUserById(id); - targetUser.updateUsername(newUsername); + try{ + validateUpdateInfo(newUsername, newEmail); + } catch (IllegalArgumentException e){ + System.out.println(e.getMessage()); + return targetUser; + } + + if (newUsername != null){ + targetUser.updateUsername(newUsername); + System.out.println("이름이 변경되었습니다: " + targetUser.getUsername()); + } + if (newEmail != null){ + targetUser.updateEmail(newEmail); + System.out.println("이메일이 변경되었습니다: " + targetUser.getEmail()); + } return targetUser; } - @Override - public User updateEmail(UUID id, String newEmail){ - User targetUser = findUserById(id); - targetUser.updateEmail(newEmail); - return targetUser; + public void validateUpdateInfo(String name, String email){ + if (name == null && email == null){ + throw new IllegalArgumentException("둘 중 하나는 입력해야 합니다."); + } + if (name != null && name.contains(" ")){ + throw new IllegalArgumentException("띄어쓰기는 포함할 수 없습니다."); + } + if (email != null && !email.contains("@")){ + throw new IllegalArgumentException("이메일 형식이 잘못되었습니다."); + } + if (email != null && email.contains(" ")){ + throw new IllegalArgumentException("띄어쓰기는 포함할 수 없습니다."); + } } @Override From ba0a077d07909432e60ddc8254c686d7513ebd61 Mon Sep 17 00:00:00 2001 From: jiho0420 Date: Wed, 14 Jan 2026 11:01:28 +0900 Subject: [PATCH 06/10] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=9D=98=20=EC=B1=84=EB=84=90=20=EC=9E=85=EC=9E=A5=20=EB=B0=8F?= =?UTF-8?q?=20=ED=8A=B9=EC=A0=95=20=EC=B1=84=EB=84=90=EC=9D=98=20=EC=B0=B8?= =?UTF-8?q?=EA=B0=80=EC=9E=90=20=EC=A1=B0=ED=9A=8C,=20=ED=8A=B9=EC=A0=95?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9=EC=9E=90=EC=9D=98=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/discodeit/JavaApplication.java | 239 +++++++++++------- .../mission/discodeit/entity/Channel.java | 12 + .../discodeit/service/ChannelService.java | 5 + .../discodeit/service/MessageService.java | 1 + .../service/jcf/JCFChannelService.java | 29 ++- .../service/jcf/JCFMessageService.java | 6 + .../discodeit/service/jcf/JCFUserService.java | 1 + 7 files changed, 205 insertions(+), 88 deletions(-) diff --git a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java index 62b31e44b..823917959 100644 --- a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -18,117 +18,182 @@ public static void main(String[] args) { System.out.println("========== 디스코드 서비스 테스트 시작 ==========\n"); UserService userService = new JCFUserService(); - ChannelService channelService = new JCFChannelService(); + ChannelService channelService = new JCFChannelService(userService); MessageService messageService = new JCFMessageService(userService, channelService); - // User 테스트 - System.out.println("유저 기능 테스트"); +// // User 테스트 +// System.out.println("유저 기능 테스트"); +// +// // 유저 등록 +// User createdUser = userService.createUser("임지호", "1234", "jiho@codeit.com"); +// UUID createdUserId = createdUser.getId(); +// +// User createdUser2 = userService.createUser("홍길동", "gildong", "gildong@codeit.com"); +// UUID createdUserId2 = createdUser2.getId(); +// +// // 단건 조회 +// System.out.println("\n단건 조회 시도:"); +// User foundUser = userService.findUserById(createdUserId); +// System.out.println("조회된 유저: " + foundUser.getUsername()); +// +// // 다건 조회 +// System.out.println("\n전체 조회 시도:"); +// List allUsers = userService.findAllUsers(); +// System.out.println("총 유저 수: " + allUsers.size() + "명"); +// +// // 수정 +// System.out.println("\n>> 유저 정보 수정 시도:"); +// +// User updatedUser = userService.updateUserInfo(createdUserId, "아임지호", "newjiho@codeit.com"); +// System.out.println("이름 변경 확인: " + updatedUser.getUsername()); +// updatedUser = userService.changePassword(createdUserId, "234234"); +// System.out.println("비밀번호 변경 확인: " + updatedUser.getPassword()); +// +// System.out.println("\n------------------------------------------\n"); +// +// User updatedUser2 = userService.updateUserInfo(createdUserId2, null, "newgildong@naver.com"); +// System.out.println(updatedUser2); +// updatedUser2 = userService.updateUserInfo(createdUserId2, "홍 길동", "new@codeit.kr"); +// System.out.println(updatedUser2); +// updatedUser2 = userService.updateUserInfo(createdUserId2, null, null); +// System.out.println(updatedUser2); +// updatedUser2 = userService.updateUserInfo(createdUserId2, "뉴길동", null); +// System.out.println(updatedUser2); +// +// System.out.println("최종 상태: " + updatedUser); +// +// System.out.println("\n------------------------------------------\n"); +// +// // Channel 테스트 +// System.out.println("채널 기능 테스트"); +// +// // 채널 등록 +// Channel newChannel = channelService.createChannel("본방"); +// UUID createdChannelId = newChannel.getId(); +// +// // 조회 +// Channel foundChannel = channelService.findChannelById(createdChannelId); +// System.out.println("생성된 채널명: " + foundChannel.getChannelName()); +// +// // 수정 +// Channel updatedChannel = channelService.updateChannel(createdChannelId, "공지방"); +// +// // 수정 확인 +// System.out.println("변경된 채널명: " + updatedChannel.getChannelName()); +// +// +// System.out.println("\n------------------------------------------\n"); +// +// // 메시지 기능 테스트 +// System.out.println("\n메시지 기능 테스트"); +// +// // 생성된 유저가 채널에 글 작성 +// Message msg1 = messageService.createMessage("안녕하세요", createdChannelId, createdUserId); +// Message msg2 = messageService.createMessage("반갑습니다", createdChannelId, createdUserId); +// UUID msg1Id = msg1.getId(); +// UUID msg2Id = msg2.getId(); +// +// // 특정 채널의 메시지 목록 조회 +// System.out.println(">> [" + foundChannel.getChannelName() + "] 채널의 메시지 목록:"); +// List channelMessages = messageService.findMessagesByChannelId(createdChannelId); +// +// for (Message msg : channelMessages) { +// System.out.println("- 내용: " + msg.getContent()); +// } +// +// // 메시지 수정 +// System.out.println("\n"); +// msg1 = messageService.updateMessage(msg1Id, "자바 실습 중"); +//// messageService.updateMessage(msg1.getId(), "안녕하세요! (수정됨)"); +// System.out.println("수정 후 내용: " + msg1.getContent()); +// +// // 메시지 삭제 +// System.out.println("\n>> 메시지 삭제 시도:"); +// messageService.deleteMessage(msg2.getId()); +// +// // 유저 삭제 +// System.out.println("\n>> 유저 삭제 확인:"); +// userService.deleteUser(createdUserId); +// try { +// userService.findUserById(createdUserId); +// } catch (IllegalArgumentException e) { +// System.out.println("에러 발생: " + e.getMessage()); +// } +// +// // 채널 삭제 +// channelService.deleteChannel(createdChannelId); +// System.out.println("\n>> 채널 삭제 확인:"); +// try { +// channelService.findChannelById(createdChannelId); +// } catch (IllegalArgumentException e) { +// System.out.println("에러 발생: " + e.getMessage()); +// } +// +// System.out.println("\n========== 테스트 종료 =========="); + + // 데이터 준비 (유저 2명, 채널 1개) + System.out.println(">> 유저 및 채널 생성 중"); + User user1 = userService.createUser("임지호", "1234", "jiho@codeit.com"); + User user2 = userService.createUser("홍길동", "5678", "hong@codeit.com"); + Channel channel = channelService.createChannel("수다방"); + + UUID user1Id = user1.getId(); + UUID user2Id = user2.getId(); + UUID channelId = channel.getId(); - // 유저 등록 - User createdUser = userService.createUser("임지호", "1234", "jiho@codeit.com"); - UUID createdUserId = createdUser.getId(); - - User createdUser2 = userService.createUser("홍길동", "gildong", "gildong@codeit.com"); - UUID createdUserId2 = createdUser2.getId(); - - // 단건 조회 - System.out.println("\n단건 조회 시도:"); - User foundUser = userService.findUserById(createdUserId); - System.out.println("조회된 유저: " + foundUser.getUsername()); - - // 다건 조회 - System.out.println("\n전체 조회 시도:"); - List allUsers = userService.findAllUsers(); - System.out.println("총 유저 수: " + allUsers.size() + "명"); - - // 수정 - System.out.println("\n>> 유저 정보 수정 시도:"); - - User updatedUser = userService.updateUserInfo(createdUserId, "아임지호", "newjiho@codeit.com"); - System.out.println("이름 변경 확인: " + updatedUser.getUsername()); - updatedUser = userService.changePassword(createdUserId, "234234"); - System.out.println("비밀번호 변경 확인: " + updatedUser.getPassword()); System.out.println("\n------------------------------------------\n"); - User updatedUser2 = userService.updateUserInfo(createdUserId2, null, "newgildong@naver.com"); - System.out.println(updatedUser2); - updatedUser2 = userService.updateUserInfo(createdUserId2, "홍 길동", "new@codeit.kr"); - System.out.println(updatedUser2); - updatedUser2 = userService.updateUserInfo(createdUserId2, null, null); - System.out.println(updatedUser2); - updatedUser2 = userService.updateUserInfo(createdUserId2, "뉴길동", null); - System.out.println(updatedUser2); - System.out.println("최종 상태: " + updatedUser); + // 채널 입장 테스트 (joinChannel) + System.out.println(">> [테스트 1] 채널 입장 (joinChannel)"); + try { + channelService.joinChannel(user1Id, channelId); + channelService.joinChannel(user2Id, channelId); - System.out.println("\n------------------------------------------\n"); + // 중복 입장 테스트 + System.out.println("\n(중복 입장 시도 -> 에러 예상)"); + channelService.joinChannel(user1Id, channelId); + } catch (IllegalArgumentException e) { + System.out.println("중복 방지 성공: " + e.getMessage()); + } - // Channel 테스트 - System.out.println("채널 기능 테스트"); - // 채널 등록 - Channel newChannel = channelService.createChannel("본방"); - UUID createdChannelId = newChannel.getId(); + System.out.println("\n------------------------------------------\n"); - // 조회 - Channel foundChannel = channelService.findChannelById(createdChannelId); - System.out.println("생성된 채널명: " + foundChannel.getChannelName()); - // 수정 - Channel updatedChannel = channelService.updateChannel(createdChannelId, "공지방"); + // 채널 참가자 조회(findParticipantsByChannelId) + System.out.println(">>채널 참가자 리스트 조회"); + List participants = channelService.findParticipants(channelId); - // 수정 확인 - System.out.println("변경된 채널명: " + updatedChannel.getChannelName()); + System.out.println("[" + channel.getChannelName() + "] 현재 참가자 수: " + participants.size() + "명"); + for (User p : participants) { + System.out.println("- 참가자: " + p.getUsername() + " (" + p.getEmail() + ")"); + } System.out.println("\n------------------------------------------\n"); - // 메시지 기능 테스트 - System.out.println("\n메시지 기능 테스트"); - // 생성된 유저가 채널에 글 작성 - Message msg1 = messageService.createMessage("안녕하세요", createdChannelId, createdUserId); - Message msg2 = messageService.createMessage("반갑습니다", createdChannelId, createdUserId); - UUID msg1Id = msg1.getId(); - UUID msg2Id = msg2.getId(); + // 메시지 작성 (데이터 쌓기) + System.out.println(">> 메시지 작성 중"); + messageService.createMessage("안녕하세요! 지호입니다.", channelId, user1Id); + messageService.createMessage("반갑습니다~ 길동이에요.", channelId, user2Id); + messageService.createMessage("오늘 점심 뭐 드실래요?", channelId, user2Id); - // 특정 채널의 메시지 목록 조회 - System.out.println(">> [" + foundChannel.getChannelName() + "] 채널의 메시지 목록:"); - List channelMessages = messageService.findMessagesByChannelId(createdChannelId); - for (Message msg : channelMessages) { - System.out.println("- 내용: " + msg.getContent()); - } + // 특정 유저의 메시지 조회 (findMessagesByUserId) + System.out.println("\n>> [테스트 3] '홍길동'이 작성한 메시지 내역 조회"); - // 메시지 수정 - System.out.println("\n"); - msg1 = messageService.updateMessage(msg1Id, "자바 실습 중"); -// messageService.updateMessage(msg1.getId(), "안녕하세요! (수정됨)"); - System.out.println("수정 후 내용: " + msg1.getContent()); + // 홍길동(user2)이 쓴 글만 가져오기 + List gildongMessages = messageService.findMessagesByUserId(user2Id); - // 메시지 삭제 - System.out.println("\n>> 메시지 삭제 시도:"); - messageService.deleteMessage(msg2.getId()); - - // 유저 삭제 - System.out.println("\n>> 유저 삭제 확인:"); - userService.deleteUser(createdUserId); - try { - userService.findUserById(createdUserId); - } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); + System.out.println("홍길동 작성글 개수: " + gildongMessages.size() + "개"); + for (Message msg : gildongMessages) { + System.out.println("📝 내용: " + msg.getContent() + " | 채널: " + msg.getChannel().getChannelName()); } - // 채널 삭제 - channelService.deleteChannel(createdChannelId); - System.out.println("\n>> 채널 삭제 확인:"); - try { - channelService.findChannelById(createdChannelId); - } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); - } - System.out.println("\n========== 테스트 종료 =========="); + System.out.println("\n========== 모든 테스트 종료 =========="); } } 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 6c3d96d99..3c46d88ea 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/Channel.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/Channel.java @@ -1,7 +1,11 @@ package com.sprint.mission.discodeit.entity; +import java.util.ArrayList; +import java.util.List; + public class Channel extends BaseEntity{ private String channelName; + private List participants = new ArrayList<>(); public String getChannelName() { return channelName; @@ -12,6 +16,14 @@ public void updateChannelInfo(String newChannelName){ super.setUpdatedAt(System.currentTimeMillis()); } + public List getParticipants() { + return participants; + } + + public void addParticipant(User user){ + this.participants.add(user); + } + public Channel(String channelName) { this.channelName = channelName; } 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 108ac05cf..a7d641bf7 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -1,6 +1,8 @@ package com.sprint.mission.discodeit.service; import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.User; + import java.util.List; import java.util.UUID; @@ -14,5 +16,8 @@ public interface ChannelService { Channel updateChannel(UUID id, String channelName); + void joinChannel(UUID userID, UUID channelID); + + List findParticipants(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 4560a9e6e..ab01cdf5b 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/MessageService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -12,4 +12,5 @@ public interface MessageService { Message updateMessage(UUID id, String newContent); List findAllMessages(); List findMessagesByChannelId(UUID channelId); + List findMessagesByUserId(UUID userId); } diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java index 73f0da0cd..fed4d3dd2 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java @@ -1,7 +1,9 @@ package com.sprint.mission.discodeit.service.jcf; import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.User; import com.sprint.mission.discodeit.service.ChannelService; +import com.sprint.mission.discodeit.service.UserService; import java.util.ArrayList; import java.util.List; @@ -9,9 +11,11 @@ public class JCFChannelService implements ChannelService { private final List channelList; + private final UserService userService; - public JCFChannelService(){ + public JCFChannelService(UserService userService){ this.channelList = new ArrayList<>(); + this.userService = userService; } @Override @@ -46,4 +50,27 @@ public Channel updateChannel(UUID id, String channelName){ targetChannel.updateChannelInfo(channelName); return targetChannel; } + + @Override + public void joinChannel(UUID userID, UUID channelID) { + Channel targetChannel = findChannelById(channelID); + User targetUser = userService.findUserById(userID); + + boolean isAlreadyExist = targetChannel.getParticipants().stream() + .anyMatch(participant -> participant.getId().equals(targetUser.getId())); + + if(isAlreadyExist) { + throw new IllegalArgumentException("이미 채널에 참여중인 사용자입니다."); + } + + targetChannel.getParticipants().add(targetUser); + System.out.println(targetUser.getUsername() + "님이 " + + targetChannel.getChannelName() + " 채널에 입장했습니다."); + } + + @Override + public List findParticipants(UUID channelID){ + Channel targetChannel = findChannelById(channelID); + return targetChannel.getParticipants(); + } } 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 8991497f9..2c2480df6 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 @@ -39,6 +39,12 @@ public List findMessagesByChannelId(UUID channelId){ .collect(Collectors.toList()); } + public List findMessagesByUserId(UUID userId){ + return messageList.stream() + .filter(message -> message.getUser().getId().equals(userId)) + .collect(Collectors.toList()); + } + public List findAllMessages(){ return messageList; } 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 b038f1d60..29098c4be 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 @@ -83,4 +83,5 @@ public User changePassword(UUID id, String newPassword) { targetUser.updatePassword(newPassword); return targetUser; } + } From bfe153825a9cd85730f7dcb45777971a298ccf80 Mon Sep 17 00:00:00 2001 From: jiho0420 Date: Wed, 14 Jan 2026 15:52:26 +0900 Subject: [PATCH 07/10] =?UTF-8?q?refactor:=20-=EC=9D=B4=EB=A9=94=EC=9D=BC?= =?UTF-8?q?=20=EC=A0=95=EA=B7=9C=ED=91=9C=ED=98=84=EC=8B=9D=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B0=95=ED=99=94=20-=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5=EC=86=8C=20Map=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20Optional=20=EB=8F=84=EC=9E=85?= =?UTF-8?q?=20-=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/discodeit/JavaApplication.java | 417 ++++++++++++------ .../mission/discodeit/entity/Channel.java | 9 + .../sprint/mission/discodeit/entity/User.java | 17 + .../discodeit/service/ChannelService.java | 3 +- .../discodeit/service/MessageService.java | 3 +- .../discodeit/service/UserService.java | 3 +- .../service/jcf/JCFChannelService.java | 45 +- .../service/jcf/JCFMessageService.java | 62 ++- .../discodeit/service/jcf/JCFUserService.java | 48 +- 9 files changed, 399 insertions(+), 208 deletions(-) diff --git a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java index 823917959..734c03e0b 100644 --- a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -11,189 +11,320 @@ import com.sprint.mission.discodeit.service.jcf.JCFUserService; import java.util.List; +import java.util.Optional; import java.util.UUID; public class JavaApplication { public static void main(String[] args) { - System.out.println("========== 디스코드 서비스 테스트 시작 ==========\n"); + System.out.println("========== 디스코드잇 서비스 테스트 시작 ==========\n"); UserService userService = new JCFUserService(); ChannelService channelService = new JCFChannelService(userService); MessageService messageService = new JCFMessageService(userService, channelService); -// // User 테스트 -// System.out.println("유저 기능 테스트"); -// -// // 유저 등록 -// User createdUser = userService.createUser("임지호", "1234", "jiho@codeit.com"); -// UUID createdUserId = createdUser.getId(); -// -// User createdUser2 = userService.createUser("홍길동", "gildong", "gildong@codeit.com"); -// UUID createdUserId2 = createdUser2.getId(); -// -// // 단건 조회 -// System.out.println("\n단건 조회 시도:"); -// User foundUser = userService.findUserById(createdUserId); -// System.out.println("조회된 유저: " + foundUser.getUsername()); -// -// // 다건 조회 -// System.out.println("\n전체 조회 시도:"); -// List allUsers = userService.findAllUsers(); -// System.out.println("총 유저 수: " + allUsers.size() + "명"); -// -// // 수정 -// System.out.println("\n>> 유저 정보 수정 시도:"); -// -// User updatedUser = userService.updateUserInfo(createdUserId, "아임지호", "newjiho@codeit.com"); -// System.out.println("이름 변경 확인: " + updatedUser.getUsername()); -// updatedUser = userService.changePassword(createdUserId, "234234"); -// System.out.println("비밀번호 변경 확인: " + updatedUser.getPassword()); -// -// System.out.println("\n------------------------------------------\n"); -// -// User updatedUser2 = userService.updateUserInfo(createdUserId2, null, "newgildong@naver.com"); -// System.out.println(updatedUser2); -// updatedUser2 = userService.updateUserInfo(createdUserId2, "홍 길동", "new@codeit.kr"); -// System.out.println(updatedUser2); -// updatedUser2 = userService.updateUserInfo(createdUserId2, null, null); -// System.out.println(updatedUser2); -// updatedUser2 = userService.updateUserInfo(createdUserId2, "뉴길동", null); -// System.out.println(updatedUser2); -// -// System.out.println("최종 상태: " + updatedUser); -// -// System.out.println("\n------------------------------------------\n"); -// -// // Channel 테스트 -// System.out.println("채널 기능 테스트"); -// -// // 채널 등록 -// Channel newChannel = channelService.createChannel("본방"); -// UUID createdChannelId = newChannel.getId(); -// -// // 조회 -// Channel foundChannel = channelService.findChannelById(createdChannelId); -// System.out.println("생성된 채널명: " + foundChannel.getChannelName()); -// -// // 수정 -// Channel updatedChannel = channelService.updateChannel(createdChannelId, "공지방"); -// -// // 수정 확인 -// System.out.println("변경된 채널명: " + updatedChannel.getChannelName()); -// -// -// System.out.println("\n------------------------------------------\n"); -// -// // 메시지 기능 테스트 -// System.out.println("\n메시지 기능 테스트"); -// -// // 생성된 유저가 채널에 글 작성 -// Message msg1 = messageService.createMessage("안녕하세요", createdChannelId, createdUserId); -// Message msg2 = messageService.createMessage("반갑습니다", createdChannelId, createdUserId); -// UUID msg1Id = msg1.getId(); -// UUID msg2Id = msg2.getId(); -// -// // 특정 채널의 메시지 목록 조회 -// System.out.println(">> [" + foundChannel.getChannelName() + "] 채널의 메시지 목록:"); -// List channelMessages = messageService.findMessagesByChannelId(createdChannelId); -// -// for (Message msg : channelMessages) { -// System.out.println("- 내용: " + msg.getContent()); -// } -// -// // 메시지 수정 -// System.out.println("\n"); -// msg1 = messageService.updateMessage(msg1Id, "자바 실습 중"); -//// messageService.updateMessage(msg1.getId(), "안녕하세요! (수정됨)"); -// System.out.println("수정 후 내용: " + msg1.getContent()); -// -// // 메시지 삭제 -// System.out.println("\n>> 메시지 삭제 시도:"); -// messageService.deleteMessage(msg2.getId()); -// -// // 유저 삭제 -// System.out.println("\n>> 유저 삭제 확인:"); -// userService.deleteUser(createdUserId); -// try { -// userService.findUserById(createdUserId); -// } catch (IllegalArgumentException e) { -// System.out.println("에러 발생: " + e.getMessage()); -// } -// -// // 채널 삭제 -// channelService.deleteChannel(createdChannelId); -// System.out.println("\n>> 채널 삭제 확인:"); -// try { -// channelService.findChannelById(createdChannelId); -// } catch (IllegalArgumentException e) { -// System.out.println("에러 발생: " + e.getMessage()); -// } -// -// System.out.println("\n========== 테스트 종료 =========="); - - // 데이터 준비 (유저 2명, 채널 1개) - System.out.println(">> 유저 및 채널 생성 중"); + // ========== User 기능 테스트 ========== + System.out.println("========== User 기능 테스트 ==========\n"); + + // 유저 생성 + System.out.println(">> 유저 생성 테스트"); User user1 = userService.createUser("임지호", "1234", "jiho@codeit.com"); User user2 = userService.createUser("홍길동", "5678", "hong@codeit.com"); - Channel channel = channelService.createChannel("수다방"); - + User user3 = userService.createUser("김철수", "abcd", "kim@codeit.com"); UUID user1Id = user1.getId(); UUID user2Id = user2.getId(); - UUID channelId = channel.getId(); + UUID user3Id = user3.getId(); + + System.out.println("\n------------------------------------------\n"); + // 유저 단건 조회 + System.out.println(">> 유저 단건 조회 테스트"); + Optional foundUser1 = userService.findUserById(user1Id); + foundUser1.ifPresent(user -> System.out.println("조회된 유저: " + user.getUsername())); + Optional foundUser2 = userService.findUserById(user2Id); + foundUser2.ifPresent(user -> System.out.println("조회된 유저: " + user.getUsername())); + Optional foundUser3 = userService.findUserById(user3Id); + foundUser3.ifPresent(user -> System.out.println("조회된 유저: " + user.getUsername())); System.out.println("\n------------------------------------------\n"); + // 유저 전체 조회 + System.out.println(">> 유저 전체 조회 테스트"); + List allUsers = userService.findAllUsers(); + System.out.println("총 유저 수: " + allUsers.size() + "명"); + for (User u : allUsers) { + System.out.println("- " + u.getUsername() + " (" + u.getEmail() + ")"); + } - // 채널 입장 테스트 (joinChannel) - System.out.println(">> [테스트 1] 채널 입장 (joinChannel)"); - try { - channelService.joinChannel(user1Id, channelId); - channelService.joinChannel(user2Id, channelId); + System.out.println("\n------------------------------------------\n"); + + // 유저 정보 수정 + System.out.println(">> 유저 정보 수정 테스트"); + User updatedUser = userService.updateUserInfo(user1Id, "아임지호", "newjiho@codeit.com"); + System.out.println("수정된 유저: " + updatedUser); + + System.out.println("\n------------------------------------------\n"); + + // 유저 비밀번호 변경 + System.out.println(">> 유저 비밀번호 변경 테스트"); + updatedUser = userService.changePassword(user1Id, "newpass1234"); + System.out.println("비밀번호 변경 완료: " + updatedUser.getPassword()); + + System.out.println("\n------------------------------------------\n"); + + // 유저 정보 수정 검증 테스트 + System.out.println(">> 유저 정보 수정 검증 테스트"); + System.out.println("둘 다 null인 경우:"); + userService.updateUserInfo(user2Id, null, null); + + System.out.println("\n이름에 공백 포함:"); + userService.updateUserInfo(user2Id, "홍 길동", "test@test.com"); + + System.out.println("\n이메일 형식 오류:"); + userService.updateUserInfo(user2Id, "홍길동", "invalidemail"); + + System.out.println("\n정상 수정:"); + userService.updateUserInfo(user2Id, "뉴홍길동", "newhong@codeit.com"); + + + System.out.println("\n========== Channel 기능 테스트 ==========\n"); + + // 채널 생성 + System.out.println(">>채널 생성 테스트"); + Channel channel1 = channelService.createChannel("본방"); + Channel channel2 = channelService.createChannel("공지방"); + Channel channel3 = channelService.createChannel("수다방"); + UUID channel1Id = channel1.getId(); + UUID channel2Id = channel2.getId(); + UUID channel3Id = channel3.getId(); + + System.out.println("\n------------------------------------------\n"); - // 중복 입장 테스트 - System.out.println("\n(중복 입장 시도 -> 에러 예상)"); - channelService.joinChannel(user1Id, channelId); + // 채널 단건 조회 + System.out.println(">>채널 단건 조회 테스트"); + Optional foundChannel = channelService.findChannelById(channel1Id); + foundChannel.ifPresent(channel -> + System.out.println("조회된 채널: " + channel.getChannelName())); + + System.out.println("\n------------------------------------------\n"); + + // 채널 전체 조회 + System.out.println(">>채널 전체 조회 테스트"); + List allChannels = channelService.findAllChannels(); + System.out.println("총 채널 수: " + allChannels.size() + "개"); + for (Channel c : allChannels) { + System.out.println("- " + c.getChannelName()); + } + + System.out.println("\n------------------------------------------\n"); + + // 채널 수정 + System.out.println(">>채널 수정 테스트"); + Channel updatedChannel = channelService.updateChannel(channel1Id, "메인방"); + System.out.println("변경된 채널명: " + updatedChannel.getChannelName()); + + System.out.println("\n------------------------------------------\n"); + + // 채널 입장 + System.out.println(">>채널 입장 테스트"); + channelService.joinChannel(user1Id, channel1Id); + channelService.joinChannel(user2Id, channel1Id); + channelService.joinChannel(user3Id, channel1Id); + + channelService.joinChannel(user1Id, channel2Id); + channelService.joinChannel(user2Id, channel2Id); + + System.out.println("\n------------------------------------------\n"); + + // 중복 입장 테스트 + System.out.println(">>중복 입장 방지 테스트"); + try { + channelService.joinChannel(user1Id, channel1Id); } catch (IllegalArgumentException e) { - System.out.println("중복 방지 성공: " + e.getMessage()); + System.out.println("에러 발생: " + e.getMessage()); } + System.out.println("\n------------------------------------------\n"); + + // 채널 참가자 조회 + System.out.println(">>채널 참가자 조회 테스트"); + List participants = channelService.findParticipants(channel1Id); + System.out.println("[" + updatedChannel.getChannelName() + "] 참가자 수: " + participants.size() + "명"); + for (User p : participants) { + System.out.println("- " + p.getUsername() + " (" + p.getEmail() + ")"); + } System.out.println("\n------------------------------------------\n"); + // 특정 유저가 속해있는 채널 + Optional testUser = userService.findUserById(user1Id); + if (testUser.isPresent()) { + System.out.println(testUser.get().getUsername() + "님이 참여 중인 채널:"); + for (Channel c : testUser.get().getMyChannels()) { + System.out.println("- " + c.getChannelName()); + } + } + + + System.out.println("\n========== Message 기능 테스트 ==========\n"); - // 채널 참가자 조회(findParticipantsByChannelId) - System.out.println(">>채널 참가자 리스트 조회"); - List participants = channelService.findParticipants(channelId); + // 메시지 생성 + System.out.println(">> 메시지 생성"); + Message msg1 = messageService.createMessage("안녕하세요! 지호입니다.", channel1Id, user1Id); + Message msg2 = messageService.createMessage("반갑습니다~ 길동이에요.", channel1Id, user2Id); + Message msg3 = messageService.createMessage("오늘 점심 뭐 드실래요?", channel1Id, user2Id); + Message msg4 = messageService.createMessage("저는 김철수입니다.", channel1Id, user3Id); - System.out.println("[" + channel.getChannelName() + "] 현재 참가자 수: " + participants.size() + "명"); + Message msg5 = messageService.createMessage("공지사항입니다.", channel2Id, user1Id); + Message msg6 = messageService.createMessage("확인했습니다.", channel2Id, user2Id); + + UUID msg1Id = msg1.getId(); + UUID msg2Id = msg2.getId(); + UUID msg5Id = msg5.getId(); + + System.out.println("\n------------------------------------------\n"); + + // 메시지 단건 조회 + System.out.println(">>메시지 단건 조회 테스트"); + Optional foundMessage = messageService.findMessageById(msg1Id); + foundMessage.ifPresent(message -> + System.out.println("조회된 메시지: " + message.getContent())); + + System.out.println("\n------------------------------------------\n"); + + // 메시지 전체 조회 + System.out.println(">>메시지 전체 조회 테스트"); + List allMessages = messageService.findAllMessages(); + System.out.println("전체 메시지 수: " + allMessages.size() + "개"); + + System.out.println("\n------------------------------------------\n"); + + // 특정 채널의 메시지 조회 + System.out.println(">>특정 채널의 메시지 조회 테스트"); + List channelMessages = messageService.findMessagesByChannelId(channel1Id); + System.out.println("[" + updatedChannel.getChannelName() + "] 메시지 수: " + channelMessages.size() + "개"); + for (Message m : channelMessages) { + System.out.println("- " + m.getUser().getUsername() + ": " + m.getContent()); + } + + System.out.println("\n------------------------------------------\n"); + + // 특정 유저의 메시지 조회 + System.out.println(">>특정 유저의 메시지 조회 테스트"); + List userMessages = messageService.findMessagesByUserId(user2Id); + Optional msgUser = userService.findUserById(user2Id); + if (msgUser.isPresent()) { + System.out.println(msgUser.get().getUsername() + "님의 메시지 수: " + userMessages.size() + "개"); + for (Message m : userMessages) { + System.out.println("📝 내용: " + m.getContent() + " | 채널: " + m.getChannel().getChannelName()); + } + } + + System.out.println("\n------------------------------------------\n"); + + // 메시지 수정 + System.out.println(">>메시지 수정 테스트"); + Message updatedMessage = messageService.updateMessage(msg1Id, "메시지를 잘못 보내서 수정했어요"); + System.out.println("수정된 메시지: " + updatedMessage.getContent()); + + System.out.println("\n------------------------------------------\n"); + + // 메시지 삭제 + System.out.println(">>메시지 삭제 테스트"); + messageService.deleteMessage(msg2Id); + + System.out.println("\n삭제 후 채널 메시지 확인:"); + channelMessages = messageService.findMessagesByChannelId(channel1Id); + System.out.println("현재 메시지 수: " + channelMessages.size() + "개"); + + System.out.println("\n------------------------------------------\n"); + + //특정 유저가 작성한 메시지 열람 + Optional testUser2 = userService.findUserById(user1Id); + if (testUser2.isPresent()) { + System.out.println(testUser2.get().getUsername() + "님이 작성한 메시지:"); + for (Message m : testUser2.get().getMyMessages()) { + System.out.println("- " + m.getContent()); + } + } + + System.out.println("\n====================\n"); + + // 유저 삭제 (연관된 채널의 participants에서도 제거되는지 확인) + System.out.println("삭제 전 [" + updatedChannel.getChannelName() + "] 참가자 수: " + + channelService.findParticipants(channel1Id).size() + "명"); + + userService.deleteUser(user3Id); + + System.out.println("삭제 후 [" + updatedChannel.getChannelName() + "] 참가자 수: " + + channelService.findParticipants(channel1Id).size() + "명"); + + participants = channelService.findParticipants(channel1Id); + System.out.println("현재 참가자:"); for (User p : participants) { - System.out.println("- 참가자: " + p.getUsername() + " (" + p.getEmail() + ")"); + System.out.println("- " + p.getUsername()); } + System.out.println("\n------------------------------------------\n"); + + // 채널 삭제 (연관된 유저의 myChannels에서도 제거되는지 확인) + Optional testUser3 = userService.findUserById(user1Id); + testUser3.ifPresent(user -> + System.out.println("삭제 전 " + user.getUsername() + "님의 참여 채널 수: " + + user.getMyChannels().size() + "개")); + + channelService.deleteChannel(channel2Id); + + testUser3 = userService.findUserById(user1Id); + if (testUser3.isPresent()) { + System.out.println("삭제 후 " + testUser3.get().getUsername() + "님의 참여 채널 수: " + + testUser3.get().getMyChannels().size() + "개"); + System.out.println("현재 참여 채널:"); + for (Channel c : testUser3.get().getMyChannels()) { + System.out.println("- " + c.getChannelName()); + } + } System.out.println("\n------------------------------------------\n"); + // 존재하지 않는 데이터 조회 시 에러 처리 + System.out.println(">> 존재하지 않는 데이터 조회 테스트"); + try { + userService.findUserById(user3Id) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + } catch (IllegalArgumentException e) { + System.out.println("에러 발생: " + e.getMessage()); + } - // 메시지 작성 (데이터 쌓기) - System.out.println(">> 메시지 작성 중"); - messageService.createMessage("안녕하세요! 지호입니다.", channelId, user1Id); - messageService.createMessage("반갑습니다~ 길동이에요.", channelId, user2Id); - messageService.createMessage("오늘 점심 뭐 드실래요?", channelId, user2Id); + try { + channelService.findChannelById(channel2Id) + .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + } catch (IllegalArgumentException e) { + System.out.println("에러 발생: " + e.getMessage()); + } - // 특정 유저의 메시지 조회 (findMessagesByUserId) - System.out.println("\n>> [테스트 3] '홍길동'이 작성한 메시지 내역 조회"); + // 최종 상태 + System.out.println("\n========== 최종 상태 확인 ==========\n"); - // 홍길동(user2)이 쓴 글만 가져오기 - List gildongMessages = messageService.findMessagesByUserId(user2Id); + System.out.println(">> 남아있는 유저:"); + allUsers = userService.findAllUsers(); + for (User u : allUsers) { + System.out.println("- " + u.getUsername() + " (채널 " + u.getMyChannels().size() + + "개 참여, 메시지 " + u.getMyMessages().size() + "개 작성)"); + } - System.out.println("홍길동 작성글 개수: " + gildongMessages.size() + "개"); - for (Message msg : gildongMessages) { - System.out.println("📝 내용: " + msg.getContent() + " | 채널: " + msg.getChannel().getChannelName()); + System.out.println("\n>> 남아있는 채널:"); + allChannels = channelService.findAllChannels(); + for (Channel c : allChannels) { + System.out.println("- " + c.getChannelName() + " (참가자 " + + c.getParticipants().size() + "명, 메시지 " + + c.getChannelMessages().size() + "개)"); } + System.out.println("\n>> 남아있는 메시지:"); + allMessages = messageService.findAllMessages(); + System.out.println("총 메시지 수: " + allMessages.size() + "개"); System.out.println("\n========== 모든 테스트 종료 =========="); } -} +} \ No newline at end of file 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 3c46d88ea..b9c914606 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/Channel.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/Channel.java @@ -6,6 +6,7 @@ public class Channel extends BaseEntity{ private String channelName; private List participants = new ArrayList<>(); + private List channelMessages = new ArrayList<>(); public String getChannelName() { return channelName; @@ -24,6 +25,14 @@ public void addParticipant(User user){ this.participants.add(user); } + public List getChannelMessages() { + return channelMessages; + } + + public void addMessage(Message message){ + this.channelMessages.add(message); + } + public Channel(String channelName) { this.channelName = channelName; } 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 9db1f4405..c81b4df01 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/User.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/User.java @@ -1,9 +1,14 @@ package com.sprint.mission.discodeit.entity; +import java.util.ArrayList; +import java.util.List; + public class User extends BaseEntity { private String username; private String password; private String email; + private List myChannels = new ArrayList<>(); + private List myMessages = new ArrayList<>(); public String getUsername() { return username; @@ -32,6 +37,18 @@ public void updatePassword(String newPassword){ this.setUpdatedAt(System.currentTimeMillis()); } + public List getMyMessages() { + return myMessages; + } + + public List getMyChannels() { + return myChannels; + } + + public void addMessage(Message message){ + this.myMessages.add(message); + } + public User(String username, String password, String email) { this.username = username; this.password = password; 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 a7d641bf7..bfdf6420e 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -4,6 +4,7 @@ import com.sprint.mission.discodeit.entity.User; import java.util.List; +import java.util.Optional; import java.util.UUID; public interface ChannelService { @@ -11,7 +12,7 @@ public interface ChannelService { void deleteChannel(UUID id); - Channel findChannelById(UUID id); + Optional findChannelById(UUID id); List findAllChannels(); Channel updateChannel(UUID id, String channelName); 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 ab01cdf5b..7bb5d1d3b 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/MessageService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -3,12 +3,13 @@ import com.sprint.mission.discodeit.entity.Message; import java.util.List; +import java.util.Optional; import java.util.UUID; public interface MessageService { Message createMessage(String content, UUID channelId, UUID userId); void deleteMessage(UUID id); - Message findMessageById(UUID id); + Optional findMessageById(UUID id); Message updateMessage(UUID id, String newContent); List findAllMessages(); List findMessagesByChannelId(UUID channelId); 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 5982c2b91..504a59abf 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/UserService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/UserService.java @@ -3,12 +3,13 @@ import com.sprint.mission.discodeit.entity.User; import java.util.List; +import java.util.Optional; import java.util.UUID; public interface UserService { User createUser(String username, String password, String email); - User findUserById(UUID id); + Optional findUserById(UUID id); List findAllUsers(); diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java index fed4d3dd2..aaf8b8fc1 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java @@ -5,56 +5,60 @@ import com.sprint.mission.discodeit.service.ChannelService; import com.sprint.mission.discodeit.service.UserService; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; public class JCFChannelService implements ChannelService { - private final List channelList; + private final Map channelMap; private final UserService userService; public JCFChannelService(UserService userService){ - this.channelList = new ArrayList<>(); + this.channelMap = new HashMap<>(); this.userService = userService; } @Override public Channel createChannel(String channelName) { Channel channel = new Channel(channelName); - channelList.add(channel); + channelMap.put(channel.getId(), channel); System.out.println(channel.getChannelName() + "채널 생성이 완료되었습니다."); return channel; } @Override - public Channel findChannelById(UUID id){ - return channelList.stream() - .filter(channel -> channel.getId().equals(id)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + public Optional findChannelById(UUID id){ + return Optional.ofNullable(channelMap.get(id)); } @Override public List findAllChannels(){ - return channelList; + return new ArrayList<>(channelMap.values()); } @Override - public void deleteChannel(UUID id){ // 예외 처리가 구현되어있는 findChannelById(id) 사용 - Channel targetChannel = findChannelById(id); - channelList.remove(targetChannel); + public void deleteChannel(UUID id){ + Channel targetChannel = findChannelById(id) + .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + + for (User participant : targetChannel.getParticipants()) { + participant.getMyChannels().remove(targetChannel); + } + + channelMap.remove(id); } public Channel updateChannel(UUID id, String channelName){ - Channel targetChannel = findChannelById(id); // 예외 처리가 구현되어있는 findChannelById(id) 사용 + Channel targetChannel = findChannelById(id) + .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); targetChannel.updateChannelInfo(channelName); return targetChannel; } @Override public void joinChannel(UUID userID, UUID channelID) { - Channel targetChannel = findChannelById(channelID); - User targetUser = userService.findUserById(userID); + Channel targetChannel = findChannelById(channelID) + .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + User targetUser = userService.findUserById(userID) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); boolean isAlreadyExist = targetChannel.getParticipants().stream() .anyMatch(participant -> participant.getId().equals(targetUser.getId())); @@ -64,13 +68,16 @@ public void joinChannel(UUID userID, UUID channelID) { } targetChannel.getParticipants().add(targetUser); + targetUser.getMyChannels().add(targetChannel); + System.out.println(targetUser.getUsername() + "님이 " + targetChannel.getChannelName() + " 채널에 입장했습니다."); } @Override public List findParticipants(UUID channelID){ - Channel targetChannel = findChannelById(channelID); + Channel targetChannel = findChannelById(channelID) + .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); return targetChannel.getParticipants(); } } 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 2c2480df6..aa2742173 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 @@ -7,57 +7,60 @@ import com.sprint.mission.discodeit.service.MessageService; import com.sprint.mission.discodeit.service.UserService; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; +import java.util.*; + public class JCFMessageService implements MessageService { - private final List messageList; + private final Map messageMap; private final UserService userService; private final ChannelService channelService; public JCFMessageService(UserService userService, ChannelService channelService){ - this.messageList = new ArrayList<>(); + this.messageMap = new HashMap<>(); this.userService = userService; this.channelService = channelService; } public Message createMessage(String content, UUID channelId, UUID userId){ - Channel channel = channelService.findChannelById(channelId); - User user = userService.findUserById(userId); + Channel channel = channelService.findChannelById(channelId) + .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + User user = userService.findUserById(userId) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); Message newMessage = new Message(content, channel, user); - messageList.add(newMessage); + messageMap.put(newMessage.getId(), newMessage); + + user.addMessage(newMessage); + channel.addMessage(newMessage); return newMessage; } public List findMessagesByChannelId(UUID channelId){ - return messageList.stream() - .filter(message -> message.getChannel().getId().equals(channelId)) - .collect(Collectors.toList()); + Channel channel = channelService.findChannelById(channelId) + .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + + return channel.getChannelMessages(); } public List findMessagesByUserId(UUID userId){ - return messageList.stream() - .filter(message -> message.getUser().getId().equals(userId)) - .collect(Collectors.toList()); + User user = userService.findUserById(userId) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + + return user.getMyMessages(); } public List findAllMessages(){ - return messageList; + return new ArrayList<>(messageMap.values()); } - public Message findMessageById(UUID id){ - return messageList.stream() - .filter(msg -> msg.getId().equals(id)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("해당 메시지 없음")); + public Optional findMessageById(UUID id){ + return Optional.ofNullable(messageMap.get(id)); } public Message updateMessage(UUID id, String newContent){ - Message targetMessage = findMessageById(id); + Message targetMessage = findMessageById(id) + .orElseThrow(() -> new IllegalArgumentException("해당 메시지 없음")); targetMessage.updateContent(newContent); System.out.println("메시지가 수정되었습니다"); @@ -66,8 +69,19 @@ public Message updateMessage(UUID id, String newContent){ } public void deleteMessage(UUID id){ - Message targetMessage = findMessageById(id); - messageList.remove(targetMessage); + Message targetMessage = findMessageById(id) + .orElseThrow(() -> new IllegalArgumentException("해당 메시지 없음")); + + // 유저 쪽 리스트에서 삭제 + if (targetMessage.getUser() != null) { + targetMessage.getUser().getMyMessages().remove(targetMessage); + } + // 채널 쪽 리스트에서 삭제 + if (targetMessage.getChannel() != null) { + targetMessage.getChannel().getChannelMessages().remove(targetMessage); + } + + messageMap.remove(id); System.out.println("메시지 삭제 완료: " + targetMessage.getContent()); } 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 29098c4be..ef5b4e6d3 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 @@ -1,42 +1,39 @@ package com.sprint.mission.discodeit.service.jcf; +import com.sprint.mission.discodeit.entity.Channel; import com.sprint.mission.discodeit.entity.User; import com.sprint.mission.discodeit.service.UserService; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; public class JCFUserService implements UserService { - private final List userList; + private final Map userMap; public JCFUserService(){ - this.userList = new ArrayList<>(); + this.userMap = new HashMap<>(); } @Override public User createUser(String username, String password, String email) { User newUser = new User(username, password, email); - userList.add(newUser); + userMap.put(newUser.getId(), newUser); System.out.println(username + "님 회원가입 완료되었습니다."); return newUser; } @Override - public User findUserById(UUID id){ - return userList.stream() - .filter(user -> user.getId().equals(id)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + public Optional findUserById(UUID id){ + return Optional.ofNullable(userMap.get(id)); } @Override public List findAllUsers(){ - return userList; + return new ArrayList<>(userMap.values()); } @Override public User updateUserInfo(UUID id, String newUsername, String newEmail){ - User targetUser = findUserById(id); + User targetUser = findUserById(id) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); try{ validateUpdateInfo(newUsername, newEmail); } catch (IllegalArgumentException e){ @@ -62,24 +59,37 @@ public void validateUpdateInfo(String name, String email){ if (name != null && name.contains(" ")){ throw new IllegalArgumentException("띄어쓰기는 포함할 수 없습니다."); } - if (email != null && !email.contains("@")){ + if (email != null && !isValidEmail(email)){ throw new IllegalArgumentException("이메일 형식이 잘못되었습니다."); } - if (email != null && email.contains(" ")){ - throw new IllegalArgumentException("띄어쓰기는 포함할 수 없습니다."); + } + + private boolean isValidEmail(String email){ + if (email == null || email.trim().isEmpty()){ + return false; } + // 이메일 정규표현식 + String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; + return email.matches(emailRegex); } @Override public void deleteUser(UUID id){ - User targetUser = findUserById(id); - userList.remove(targetUser); + User targetUser = findUserById(id) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + + for (Channel channel : targetUser.getMyChannels()) { + channel.getParticipants().remove(targetUser); + } + + userMap.remove(id); System.out.println(targetUser.getUsername() + "님 삭제 완료되었습니다"); } @Override public User changePassword(UUID id, String newPassword) { - User targetUser = findUserById(id); + User targetUser = findUserById(id) + .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); targetUser.updatePassword(newPassword); return targetUser; } From db700a02c3ccf1d4267c4eb2b6bedb065a5eacd0 Mon Sep 17 00:00:00 2001 From: jiho0420 Date: Thu, 15 Jan 2026 12:12:33 +0900 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20=EC=B1=84=EB=84=90=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?refactor:=20findById=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD=20(Optional?= =?UTF-8?q?=20->=20Object)=20=EB=B0=8F=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20=EB=82=B4=EB=B6=80=ED=99=94=20?= =?UTF-8?q?-=20=EC=B1=84=EB=84=90=20=EC=B0=B8=EA=B0=80=EC=9E=90=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C(findParticipants)=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=9D=B4=EA=B4=80=20(ChannelService=20->=20UserService)=20-=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95(up?= =?UTF-8?q?dateUserInfo)=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0=20(if?= =?UTF-8?q?=EB=AC=B8=20->=20Optional=20=EC=B2=B4=EC=9D=B4=EB=8B=9D)=20-=20?= =?UTF-8?q?=ED=8A=B9=EC=A0=95=20=EC=9C=A0=EC=A0=80=EC=9D=98=20=EC=B0=B8?= =?UTF-8?q?=EC=97=AC=20=EC=B1=84=EB=84=90=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/discodeit/JavaApplication.java | 158 +++++++++++------- .../discodeit/service/ChannelService.java | 9 +- .../discodeit/service/MessageService.java | 3 +- .../discodeit/service/UserService.java | 5 +- .../service/jcf/JCFChannelService.java | 40 +++-- .../service/jcf/JCFMessageService.java | 27 ++- .../discodeit/service/jcf/JCFUserService.java | 77 +++++---- 7 files changed, 188 insertions(+), 131 deletions(-) diff --git a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java index 734c03e0b..e1acae4f5 100644 --- a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -11,7 +11,6 @@ import com.sprint.mission.discodeit.service.jcf.JCFUserService; import java.util.List; -import java.util.Optional; import java.util.UUID; public class JavaApplication { @@ -38,12 +37,14 @@ public static void main(String[] args) { // 유저 단건 조회 System.out.println(">> 유저 단건 조회 테스트"); - Optional foundUser1 = userService.findUserById(user1Id); - foundUser1.ifPresent(user -> System.out.println("조회된 유저: " + user.getUsername())); - Optional foundUser2 = userService.findUserById(user2Id); - foundUser2.ifPresent(user -> System.out.println("조회된 유저: " + user.getUsername())); - Optional foundUser3 = userService.findUserById(user3Id); - foundUser3.ifPresent(user -> System.out.println("조회된 유저: " + user.getUsername())); + User foundUser1 = userService.findUserById(user1Id); + System.out.println("조회된 유저: " + foundUser1.getUsername()); + + User foundUser2 = userService.findUserById(user2Id); + System.out.println("조회된 유저: " + foundUser2.getUsername()); + + User foundUser3 = userService.findUserById(user3Id); + System.out.println("조회된 유저: " + foundUser3.getUsername()); System.out.println("\n------------------------------------------\n"); @@ -74,13 +75,25 @@ public static void main(String[] args) { // 유저 정보 수정 검증 테스트 System.out.println(">> 유저 정보 수정 검증 테스트"); System.out.println("둘 다 null인 경우:"); - userService.updateUserInfo(user2Id, null, null); + try { + userService.updateUserInfo(user2Id, null, null); + } catch (IllegalArgumentException e) { + System.out.println("에러 발생: " + e.getMessage()); + } System.out.println("\n이름에 공백 포함:"); - userService.updateUserInfo(user2Id, "홍 길동", "test@test.com"); + try { + userService.updateUserInfo(user2Id, "홍 길동", "test@test.com"); + } catch (IllegalArgumentException e) { + System.out.println("에러 발생: " + e.getMessage()); + } System.out.println("\n이메일 형식 오류:"); - userService.updateUserInfo(user2Id, "홍길동", "invalidemail"); + try { + userService.updateUserInfo(user2Id, "홍길동", "invalidemail"); + } catch (IllegalArgumentException e) { + System.out.println("에러 발생: " + e.getMessage()); + } System.out.println("\n정상 수정:"); userService.updateUserInfo(user2Id, "뉴홍길동", "newhong@codeit.com"); @@ -101,9 +114,8 @@ public static void main(String[] args) { // 채널 단건 조회 System.out.println(">>채널 단건 조회 테스트"); - Optional foundChannel = channelService.findChannelById(channel1Id); - foundChannel.ifPresent(channel -> - System.out.println("조회된 채널: " + channel.getChannelName())); + Channel foundChannel = channelService.findChannelByChannelId(channel1Id); + System.out.println("조회된 채널: " + foundChannel.getChannelName()); System.out.println("\n------------------------------------------\n"); @@ -145,9 +157,33 @@ public static void main(String[] args) { System.out.println("\n------------------------------------------\n"); + // 채널 퇴장 + System.out.println(">> 채널 퇴장 테스트"); + + channelService.leaveChannel(user1Id, channel1Id); + + // 채널의 참가자 리스트에서 빠졌는지 확인 + List participantsAfterLeave = userService.findParticipants(channel1Id); + System.out.println("퇴장 후 [" + updatedChannel.getChannelName() + "] 참가자 수: " + + participantsAfterLeave.size() + "명"); + + // 유저의 채널 리스트에서 빠졌는지 확인 + System.out.println(user1.getUsername() + "님의 현재 참여 채널 수: " + + user1.getMyChannels().size() + "개"); + + // 참여하지 않은 방에서 또 나가려고 할 때 + System.out.println("\n>> 참여하지 않은 채널 퇴장 시도"); + try { + channelService.leaveChannel(user1Id, channel1Id); + } catch (IllegalArgumentException e) { + System.out.println("✅에러 캐치 성공: " + e.getMessage()); + } + + System.out.println("\n------------------------------------------\n"); + // 채널 참가자 조회 System.out.println(">>채널 참가자 조회 테스트"); - List participants = channelService.findParticipants(channel1Id); + List participants = userService.findParticipants(channel1Id); System.out.println("[" + updatedChannel.getChannelName() + "] 참가자 수: " + participants.size() + "명"); for (User p : participants) { System.out.println("- " + p.getUsername() + " (" + p.getEmail() + ")"); @@ -156,12 +192,13 @@ public static void main(String[] args) { System.out.println("\n------------------------------------------\n"); // 특정 유저가 속해있는 채널 - Optional testUser = userService.findUserById(user1Id); - if (testUser.isPresent()) { - System.out.println(testUser.get().getUsername() + "님이 참여 중인 채널:"); - for (Channel c : testUser.get().getMyChannels()) { - System.out.println("- " + c.getChannelName()); - } + System.out.println(">>특정 유저가 속해있는 채널 조회"); + List userChannels = channelService.findChannelByUserId(user1Id); + User testUser = userService.findUserById(user1Id); + + System.out.println(testUser.getUsername() + "님이 참여 중인 채널:"); + for (Channel c : userChannels) { + System.out.println("- " + c.getChannelName()); } @@ -179,15 +216,13 @@ public static void main(String[] args) { UUID msg1Id = msg1.getId(); UUID msg2Id = msg2.getId(); - UUID msg5Id = msg5.getId(); System.out.println("\n------------------------------------------\n"); // 메시지 단건 조회 System.out.println(">>메시지 단건 조회 테스트"); - Optional foundMessage = messageService.findMessageById(msg1Id); - foundMessage.ifPresent(message -> - System.out.println("조회된 메시지: " + message.getContent())); + Message foundMessage = messageService.findMessageById(msg1Id); + System.out.println("조회된 메시지: " + foundMessage.getContent()); System.out.println("\n------------------------------------------\n"); @@ -211,14 +246,14 @@ public static void main(String[] args) { // 특정 유저의 메시지 조회 System.out.println(">>특정 유저의 메시지 조회 테스트"); List userMessages = messageService.findMessagesByUserId(user2Id); - Optional msgUser = userService.findUserById(user2Id); - if (msgUser.isPresent()) { - System.out.println(msgUser.get().getUsername() + "님의 메시지 수: " + userMessages.size() + "개"); - for (Message m : userMessages) { - System.out.println("📝 내용: " + m.getContent() + " | 채널: " + m.getChannel().getChannelName()); - } + User msgUser = userService.findUserById(user2Id); + + System.out.println(msgUser.getUsername() + "님의 메시지 수: " + userMessages.size() + "개"); + for (Message m : userMessages) { + System.out.println("📝 내용: " + m.getContent() + " | 채널: " + m.getChannel().getChannelName()); } + System.out.println("\n------------------------------------------\n"); // 메시지 수정 @@ -238,27 +273,28 @@ public static void main(String[] args) { System.out.println("\n------------------------------------------\n"); - //특정 유저가 작성한 메시지 열람 - Optional testUser2 = userService.findUserById(user1Id); - if (testUser2.isPresent()) { - System.out.println(testUser2.get().getUsername() + "님이 작성한 메시지:"); - for (Message m : testUser2.get().getMyMessages()) { - System.out.println("- " + m.getContent()); - } + // 특정 유저가 작성한 메시지 열람 + System.out.println(">>작성한 메시지 열람"); + User testUser2 = userService.findUserById(user1Id); + System.out.println(testUser2.getUsername() + "님이 작성한 메시지:"); + for (Message m : testUser2.getMyMessages()) { + System.out.println("- " + m.getContent()); } + System.out.println("\n====================\n"); - // 유저 삭제 (연관된 채널의 participants에서도 제거되는지 확인) + // 유저 삭제 + System.out.println(">>유저 삭제 테스트"); System.out.println("삭제 전 [" + updatedChannel.getChannelName() + "] 참가자 수: " - + channelService.findParticipants(channel1Id).size() + "명"); + + userService.findParticipants(channel1Id).size() + "명"); userService.deleteUser(user3Id); System.out.println("삭제 후 [" + updatedChannel.getChannelName() + "] 참가자 수: " - + channelService.findParticipants(channel1Id).size() + "명"); + + userService.findParticipants(channel1Id).size() + "명"); - participants = channelService.findParticipants(channel1Id); + participants = userService.findParticipants(channel1Id); System.out.println("현재 참가자:"); for (User p : participants) { System.out.println("- " + p.getUsername()); @@ -266,40 +302,40 @@ public static void main(String[] args) { System.out.println("\n------------------------------------------\n"); - // 채널 삭제 (연관된 유저의 myChannels에서도 제거되는지 확인) - Optional testUser3 = userService.findUserById(user1Id); - testUser3.ifPresent(user -> - System.out.println("삭제 전 " + user.getUsername() + "님의 참여 채널 수: " - + user.getMyChannels().size() + "개")); + // 채널 삭제 + System.out.println(">>채널 삭제 테스트"); + List channelsBeforeDelete = channelService.findChannelByUserId(user1Id); + User testUser3 = userService.findUserById(user1Id); + System.out.println("삭제 전 " + testUser3.getUsername() + "님의 참여 채널 수: " + + channelsBeforeDelete.size() + "개"); channelService.deleteChannel(channel2Id); + // 삭제 후 유저 다시 조회 (채널 리스트 갱신 확인) + List channelsAfterDelete = channelService.findChannelByUserId(user1Id); testUser3 = userService.findUserById(user1Id); - if (testUser3.isPresent()) { - System.out.println("삭제 후 " + testUser3.get().getUsername() + "님의 참여 채널 수: " - + testUser3.get().getMyChannels().size() + "개"); - System.out.println("현재 참여 채널:"); - for (Channel c : testUser3.get().getMyChannels()) { - System.out.println("- " + c.getChannelName()); - } + System.out.println("삭제 후 " + testUser3.getUsername() + "님의 참여 채널 수: " + + channelsAfterDelete.size() + "개"); + System.out.println("현재 참여 채널:"); + for (Channel c : channelsAfterDelete) { + System.out.println("- " + c.getChannelName()); } + System.out.println("\n------------------------------------------\n"); - // 존재하지 않는 데이터 조회 시 에러 처리 + // 존재하지 않는 데이터 조회 시 에러 처리 (Service가 예외를 던지는지 확인) System.out.println(">> 존재하지 않는 데이터 조회 테스트"); try { - userService.findUserById(user3Id) - .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + userService.findUserById(user3Id); // 이미 삭제된 유저 } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); + System.out.println("✅ 에러 캐치 성공: " + e.getMessage()); } try { - channelService.findChannelById(channel2Id) - .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + channelService.findChannelByChannelId(channel2Id); // 이미 삭제된 채널 } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); + System.out.println("✅ 에러 캐치 성공: " + e.getMessage()); } @@ -317,7 +353,7 @@ public static void main(String[] args) { allChannels = channelService.findAllChannels(); for (Channel c : allChannels) { System.out.println("- " + c.getChannelName() + " (참가자 " - + c.getParticipants().size() + "명, 메시지 " + + userService.findParticipants(c.getId()).size() + "명, 메시지 " + c.getChannelMessages().size() + "개)"); } 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 bfdf6420e..08f176dbd 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -1,10 +1,8 @@ package com.sprint.mission.discodeit.service; import com.sprint.mission.discodeit.entity.Channel; -import com.sprint.mission.discodeit.entity.User; import java.util.List; -import java.util.Optional; import java.util.UUID; public interface ChannelService { @@ -12,13 +10,14 @@ public interface ChannelService { void deleteChannel(UUID id); - Optional findChannelById(UUID id); + Channel findChannelByChannelId(UUID id); + List findAllChannels(); + List findChannelByUserId(UUID userID); Channel updateChannel(UUID id, String channelName); void joinChannel(UUID userID, UUID channelID); - List findParticipants(UUID channelID); - + void leaveChannel(UUID userID, 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 7bb5d1d3b..ab01cdf5b 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/MessageService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -3,13 +3,12 @@ import com.sprint.mission.discodeit.entity.Message; import java.util.List; -import java.util.Optional; import java.util.UUID; public interface MessageService { Message createMessage(String content, UUID channelId, UUID userId); void deleteMessage(UUID id); - Optional findMessageById(UUID id); + Message findMessageById(UUID id); Message updateMessage(UUID id, String newContent); List findAllMessages(); List findMessagesByChannelId(UUID channelId); 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 504a59abf..b307e6546 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/UserService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/UserService.java @@ -3,13 +3,12 @@ import com.sprint.mission.discodeit.entity.User; import java.util.List; -import java.util.Optional; import java.util.UUID; public interface UserService { User createUser(String username, String password, String email); - Optional findUserById(UUID id); + User findUserById(UUID id); List findAllUsers(); @@ -19,4 +18,6 @@ public interface UserService { void deleteUser(UUID id); + List findParticipants(UUID channelID); + } diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java index aaf8b8fc1..de84440d1 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java @@ -25,8 +25,18 @@ public Channel createChannel(String channelName) { } @Override - public Optional findChannelById(UUID id){ - return Optional.ofNullable(channelMap.get(id)); + public Channel findChannelByChannelId(UUID id){ + Channel channel = channelMap.get(id); + if (channel == null) { + throw new IllegalArgumentException("해당 채널이 없습니다."); + } + return channel; + } + + @Override + public List findChannelByUserId(UUID userID){ + User user = userService.findUserById(userID); + return new ArrayList<>(user.getMyChannels()); } @Override @@ -36,8 +46,7 @@ public List findAllChannels(){ @Override public void deleteChannel(UUID id){ - Channel targetChannel = findChannelById(id) - .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + Channel targetChannel = findChannelByChannelId(id); for (User participant : targetChannel.getParticipants()) { participant.getMyChannels().remove(targetChannel); @@ -47,18 +56,15 @@ public void deleteChannel(UUID id){ } public Channel updateChannel(UUID id, String channelName){ - Channel targetChannel = findChannelById(id) - .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); + Channel targetChannel = findChannelByChannelId(id); targetChannel.updateChannelInfo(channelName); return targetChannel; } @Override public void joinChannel(UUID userID, UUID channelID) { - Channel targetChannel = findChannelById(channelID) - .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); - User targetUser = userService.findUserById(userID) - .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + Channel targetChannel = findChannelByChannelId(channelID); + User targetUser = userService.findUserById(userID); boolean isAlreadyExist = targetChannel.getParticipants().stream() .anyMatch(participant -> participant.getId().equals(targetUser.getId())); @@ -75,9 +81,15 @@ public void joinChannel(UUID userID, UUID channelID) { } @Override - public List findParticipants(UUID channelID){ - Channel targetChannel = findChannelById(channelID) - .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); - return targetChannel.getParticipants(); + public void leaveChannel(UUID userID, UUID channelID) { + Channel targetChannel = findChannelByChannelId(channelID); + User targetUser = userService.findUserById(userID); + + if (!targetChannel.getParticipants().contains(targetUser)) { + throw new IllegalArgumentException("채널에 참여중이지 않습니다."); + } + + targetChannel.getParticipants().remove(targetUser); + targetUser.getMyChannels().remove(targetChannel); } } 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 aa2742173..861f4f6b1 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 @@ -22,10 +22,8 @@ public JCFMessageService(UserService userService, ChannelService channelService) } public Message createMessage(String content, UUID channelId, UUID userId){ - Channel channel = channelService.findChannelById(channelId) - .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); - User user = userService.findUserById(userId) - .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + Channel channel = channelService.findChannelByChannelId(channelId); + User user = userService.findUserById(userId); Message newMessage = new Message(content, channel, user); messageMap.put(newMessage.getId(), newMessage); @@ -37,15 +35,12 @@ public Message createMessage(String content, UUID channelId, UUID userId){ } public List findMessagesByChannelId(UUID channelId){ - Channel channel = channelService.findChannelById(channelId) - .orElseThrow(() -> new IllegalArgumentException("해당 채널 없음")); - + Channel channel = channelService.findChannelByChannelId(channelId); return channel.getChannelMessages(); } public List findMessagesByUserId(UUID userId){ - User user = userService.findUserById(userId) - .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + User user = userService.findUserById(userId); return user.getMyMessages(); } @@ -54,13 +49,16 @@ public List findAllMessages(){ return new ArrayList<>(messageMap.values()); } - public Optional findMessageById(UUID id){ - return Optional.ofNullable(messageMap.get(id)); + public Message findMessageById(UUID id){ + Message message = messageMap.get(id); + if (message == null) { + throw new IllegalArgumentException("해당 메시지가 없습니다."); + } + return message; } public Message updateMessage(UUID id, String newContent){ - Message targetMessage = findMessageById(id) - .orElseThrow(() -> new IllegalArgumentException("해당 메시지 없음")); + Message targetMessage = findMessageById(id); targetMessage.updateContent(newContent); System.out.println("메시지가 수정되었습니다"); @@ -69,8 +67,7 @@ public Message updateMessage(UUID id, String newContent){ } public void deleteMessage(UUID id){ - Message targetMessage = findMessageById(id) - .orElseThrow(() -> new IllegalArgumentException("해당 메시지 없음")); + Message targetMessage = findMessageById(id); // 유저 쪽 리스트에서 삭제 if (targetMessage.getUser() != null) { 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 ef5b4e6d3..fb1add3a9 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 @@ -21,8 +21,12 @@ public User createUser(String username, String password, String email) { } @Override - public Optional findUserById(UUID id){ - return Optional.ofNullable(userMap.get(id)); + public User findUserById(UUID id) { + User user = userMap.get(id); + if (user == null) { + throw new IllegalArgumentException("해당 유저가 없습니다."); + } + return user; } @Override @@ -31,37 +35,40 @@ public List findAllUsers(){ } @Override - public User updateUserInfo(UUID id, String newUsername, String newEmail){ - User targetUser = findUserById(id) - .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); - try{ - validateUpdateInfo(newUsername, newEmail); - } catch (IllegalArgumentException e){ - System.out.println(e.getMessage()); - return targetUser; + public User updateUserInfo(UUID id, String newUsername, String newEmail) { + User targetUser = findUserById(id); + + // username, email 검증 + if (newUsername == null && newEmail == null) { + throw new IllegalArgumentException("둘 중 하나는 입력해야 합니다."); } - if (newUsername != null){ - targetUser.updateUsername(newUsername); + // Username 검증 + Optional.ofNullable(newUsername) + .filter(name -> name.contains(" ")) + .ifPresent(name -> { + throw new IllegalArgumentException("띄어쓰기는 포함할 수 없습니다."); + }); + + // Email 검증 + Optional.ofNullable(newEmail) + .filter(email -> !isValidEmail(email)) + .ifPresent(email -> { + throw new IllegalArgumentException("이메일 형식이 잘못되었습니다."); + }); + + // 실제 수정 로직 + Optional.ofNullable(newUsername).ifPresent(name -> { + targetUser.updateUsername(name); System.out.println("이름이 변경되었습니다: " + targetUser.getUsername()); - } - if (newEmail != null){ - targetUser.updateEmail(newEmail); + }); + + Optional.ofNullable(newEmail).ifPresent(email -> { + targetUser.updateEmail(email); System.out.println("이메일이 변경되었습니다: " + targetUser.getEmail()); - } - return targetUser; - } + }); - public void validateUpdateInfo(String name, String email){ - if (name == null && email == null){ - throw new IllegalArgumentException("둘 중 하나는 입력해야 합니다."); - } - if (name != null && name.contains(" ")){ - throw new IllegalArgumentException("띄어쓰기는 포함할 수 없습니다."); - } - if (email != null && !isValidEmail(email)){ - throw new IllegalArgumentException("이메일 형식이 잘못되었습니다."); - } + return targetUser; } private boolean isValidEmail(String email){ @@ -75,8 +82,7 @@ private boolean isValidEmail(String email){ @Override public void deleteUser(UUID id){ - User targetUser = findUserById(id) - .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + User targetUser = findUserById(id); for (Channel channel : targetUser.getMyChannels()) { channel.getParticipants().remove(targetUser); @@ -88,10 +94,17 @@ public void deleteUser(UUID id){ @Override public User changePassword(UUID id, String newPassword) { - User targetUser = findUserById(id) - .orElseThrow(() -> new IllegalArgumentException("해당 사용자 없음")); + User targetUser = findUserById(id); targetUser.updatePassword(newPassword); return targetUser; } + @Override + public List findParticipants(UUID channelID){ + return userMap.values().stream() + .filter(user -> user.getMyChannels().stream() + .anyMatch(channel -> channel.getId().equals(channelID))) + .toList(); + } + } From 0d052bc341dd95a71d26a9cbc854a0e41dc654f8 Mon Sep 17 00:00:00 2001 From: jiho0420 Date: Thu, 15 Jan 2026 14:36:52 +0900 Subject: [PATCH 09/10] =?UTF-8?q?refactor:=20=EC=B1=84=EB=84=90=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=B0=98=EB=B3=B5=EB=AC=B8=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0(for->stream)=20=EB=B0=8F=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/codeStyles/codeStyleConfig.xml | 5 +++++ .../service/jcf/JCFChannelService.java | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 000000000..a55e7a179 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java index de84440d1..86ebc999a 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java @@ -48,10 +48,8 @@ public List findAllChannels(){ public void deleteChannel(UUID id){ Channel targetChannel = findChannelByChannelId(id); - for (User participant : targetChannel.getParticipants()) { - participant.getMyChannels().remove(targetChannel); - } - + targetChannel.getParticipants() + .forEach(user -> user.getMyChannels().remove(targetChannel)); channelMap.remove(id); } @@ -66,12 +64,15 @@ public void joinChannel(UUID userID, UUID channelID) { Channel targetChannel = findChannelByChannelId(channelID); User targetUser = userService.findUserById(userID); - boolean isAlreadyExist = targetChannel.getParticipants().stream() - .anyMatch(participant -> participant.getId().equals(targetUser.getId())); + targetChannel.getParticipants().stream() + .filter(participant -> participant.getId().equals(targetUser.getId())) + .findAny() + .ifPresent(participant -> { + throw new IllegalArgumentException("이미 채널에 참여중인 사용자입니다."); + }); - if(isAlreadyExist) { - throw new IllegalArgumentException("이미 채널에 참여중인 사용자입니다."); - } + targetChannel.getParticipants().add(targetUser); + targetUser.getMyChannels().add(targetChannel); targetChannel.getParticipants().add(targetUser); targetUser.getMyChannels().add(targetChannel); From 1153edb208e0e5c5842d1788e263c4ca43141b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EB=A6=B0?= Date: Wed, 4 Feb 2026 16:23:31 +0900 Subject: [PATCH 10/10] Apply sprint3 changes --- .../discodeit/DiscodeitApplication.java | 51 +++ .../mission/discodeit/JavaApplication.java | 38 ++ .../sprint/mission/discodeit/dto/AuthDto.java | 8 + .../discodeit/dto/BinaryContentDto.java | 19 + .../mission/discodeit/dto/ChannelDto.java | 34 ++ .../mission/discodeit/dto/MessageDto.java | 37 ++ .../mission/discodeit/dto/ReadStatusDto.java | 25 ++ .../sprint/mission/discodeit/dto/UserDto.java | 37 ++ .../mission/discodeit/dto/UserStatusDto.java | 22 + .../mission/discodeit/entity/BaseEntity.java | 26 ++ .../discodeit/entity/BinaryContent.java | 20 + .../mission/discodeit/entity/Channel.java | 40 ++ .../mission/discodeit/entity/ChannelType.java | 6 + .../mission/discodeit/entity/Message.java | 56 +++ .../mission/discodeit/entity/ReadStatus.java | 29 ++ .../sprint/mission/discodeit/entity/User.java | 35 ++ .../mission/discodeit/entity/UserStatus.java | 27 ++ .../repository/BinaryContentRepository.java | 21 + .../repository/ChannelRepository.java | 17 + .../repository/MessageRepository.java | 22 + .../repository/ReadStatusRepository.java | 27 ++ .../discodeit/repository/UserRepository.java | 20 + .../repository/UserStatusRepository.java | 22 + .../file/FileBinaryContentRepository.java | 117 +++++ .../file/FileChannelRepository.java | 116 +++++ .../file/FileMessageRepository.java | 165 +++++++ .../file/FileReadStatusRepository.java | 162 +++++++ .../repository/file/FileUserRepository.java | 127 ++++++ .../file/FileUserStatusRepository.java | 133 ++++++ .../jcf/JCFBinaryContentRepository.java | 55 +++ .../repository/jcf/JCFChannelRepository.java | 55 +++ .../repository/jcf/JCFMessageRepository.java | 67 +++ .../jcf/JCFReadStatusRepository.java | 82 ++++ .../repository/jcf/JCFUserRepository.java | 66 +++ .../jcf/JCFUserStatusRepository.java | 61 +++ .../discodeit/service/AuthService.java | 8 + .../service/BinaryContentService.java | 15 + .../discodeit/service/ChannelService.java | 16 + .../discodeit/service/MessageService.java | 15 + .../discodeit/service/ReadStatusService.java | 18 + .../discodeit/service/UserService.java | 15 + .../discodeit/service/UserStatusService.java | 16 + .../service/basic/BasicAuthService.java | 39 ++ .../basic/BasicBinaryContentService.java | 59 +++ .../service/basic/BasicChannelService.java | 124 ++++++ .../service/basic/BasicMessageService.java | 111 +++++ .../service/basic/BasicReadStatusService.java | 87 ++++ .../service/basic/BasicUserService.java | 137 ++++++ .../service/basic/BasicUserStatusService.java | 93 ++++ .github/src/main/resources/application.yaml | 4 + .idea/.name | 1 + HELP.md | 25 ++ .../discodeit/DiscodeitApplication.java | 51 +++ .../mission/discodeit/JavaApplication.java | 404 ++---------------- .../sprint/mission/discodeit/dto/AuthDto.java | 8 + .../discodeit/dto/BinaryContentDto.java | 19 + .../mission/discodeit/dto/ChannelDto.java | 34 ++ .../mission/discodeit/dto/MessageDto.java | 37 ++ .../mission/discodeit/dto/ReadStatusDto.java | 25 ++ .../sprint/mission/discodeit/dto/UserDto.java | 37 ++ .../mission/discodeit/dto/UserStatusDto.java | 22 + .../mission/discodeit/entity/BaseEntity.java | 36 +- .../discodeit/entity/BinaryContent.java | 20 + .../mission/discodeit/entity/Channel.java | 67 +-- .../mission/discodeit/entity/ChannelType.java | 6 + .../mission/discodeit/entity/Message.java | 70 +-- .../mission/discodeit/entity/ReadStatus.java | 29 ++ .../sprint/mission/discodeit/entity/User.java | 69 +-- .../mission/discodeit/entity/UserStatus.java | 27 ++ .../repository/BinaryContentRepository.java | 21 + .../repository/ChannelRepository.java | 17 + .../repository/MessageRepository.java | 22 + .../repository/ReadStatusRepository.java | 27 ++ .../discodeit/repository/UserRepository.java | 20 + .../repository/UserStatusRepository.java | 22 + .../file/FileBinaryContentRepository.java | 117 +++++ .../file/FileChannelRepository.java | 116 +++++ .../file/FileMessageRepository.java | 165 +++++++ .../file/FileReadStatusRepository.java | 162 +++++++ .../repository/file/FileUserRepository.java | 127 ++++++ .../file/FileUserStatusRepository.java | 133 ++++++ .../jcf/JCFBinaryContentRepository.java | 55 +++ .../repository/jcf/JCFChannelRepository.java | 55 +++ .../repository/jcf/JCFMessageRepository.java | 67 +++ .../jcf/JCFReadStatusRepository.java | 82 ++++ .../repository/jcf/JCFUserRepository.java | 66 +++ .../jcf/JCFUserStatusRepository.java | 61 +++ .../discodeit/service/AuthService.java | 8 + .../service/BinaryContentService.java | 15 + .../discodeit/service/ChannelService.java | 21 +- .../discodeit/service/MessageService.java | 13 +- .../discodeit/service/ReadStatusService.java | 18 + .../discodeit/service/UserService.java | 20 +- .../discodeit/service/UserStatusService.java | 16 + .../service/basic/BasicAuthService.java | 39 ++ .../basic/BasicBinaryContentService.java | 59 +++ .../service/basic/BasicChannelService.java | 124 ++++++ .../service/basic/BasicMessageService.java | 111 +++++ .../service/basic/BasicReadStatusService.java | 87 ++++ .../service/basic/BasicUserService.java | 137 ++++++ .../service/basic/BasicUserStatusService.java | 93 ++++ .../service/jcf/JCFChannelService.java | 96 ----- .../service/jcf/JCFMessageService.java | 85 ---- .../discodeit/service/jcf/JCFUserService.java | 110 ----- src/main/resources/application.yaml | 4 + 105 files changed, 5162 insertions(+), 818 deletions(-) create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/JavaApplication.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/dto/AuthDto.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/dto/BinaryContentDto.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/dto/ChannelDto.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/dto/MessageDto.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/dto/ReadStatusDto.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/dto/UserDto.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/dto/UserStatusDto.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/entity/BinaryContent.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/entity/Channel.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/entity/ChannelType.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/entity/Message.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/entity/ReadStatus.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/entity/User.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/entity/UserStatus.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/BinaryContentRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/ReadStatusRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/UserStatusRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/file/FileBinaryContentRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/file/FileReadStatusRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserStatusRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFReadStatusRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserStatusRepository.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/AuthService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/BinaryContentService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/MessageService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/ReadStatusService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/UserService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/UserStatusService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicAuthService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicBinaryContentService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicChannelService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicMessageService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicReadStatusService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java create mode 100644 .github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserStatusService.java create mode 100644 .github/src/main/resources/application.yaml create mode 100644 .idea/.name create mode 100644 HELP.md create mode 100644 src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java create mode 100644 src/main/java/com/sprint/mission/discodeit/dto/AuthDto.java create mode 100644 src/main/java/com/sprint/mission/discodeit/dto/BinaryContentDto.java create mode 100644 src/main/java/com/sprint/mission/discodeit/dto/ChannelDto.java create mode 100644 src/main/java/com/sprint/mission/discodeit/dto/MessageDto.java create mode 100644 src/main/java/com/sprint/mission/discodeit/dto/ReadStatusDto.java create mode 100644 src/main/java/com/sprint/mission/discodeit/dto/UserDto.java create mode 100644 src/main/java/com/sprint/mission/discodeit/dto/UserStatusDto.java create mode 100644 src/main/java/com/sprint/mission/discodeit/entity/BinaryContent.java create mode 100644 src/main/java/com/sprint/mission/discodeit/entity/ChannelType.java create mode 100644 src/main/java/com/sprint/mission/discodeit/entity/ReadStatus.java create mode 100644 src/main/java/com/sprint/mission/discodeit/entity/UserStatus.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/BinaryContentRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/ReadStatusRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/UserStatusRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/file/FileBinaryContentRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/file/FileReadStatusRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/file/FileUserStatusRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFReadStatusRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserStatusRepository.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/AuthService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/BinaryContentService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/ReadStatusService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/UserStatusService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/basic/BasicAuthService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/basic/BasicBinaryContentService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/basic/BasicChannelService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/basic/BasicMessageService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/basic/BasicReadStatusService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java create mode 100644 src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserStatusService.java delete mode 100644 src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java delete mode 100644 src/main/java/com/sprint/mission/discodeit/service/jcf/JCFMessageService.java delete mode 100644 src/main/java/com/sprint/mission/discodeit/service/jcf/JCFUserService.java create mode 100644 src/main/resources/application.yaml diff --git a/.github/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java b/.github/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java new file mode 100644 index 000000000..4315d3f06 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java @@ -0,0 +1,51 @@ +//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 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.boot.SpringApplication; +//import org.springframework.boot.autoconfigure.SpringBootApplication; +//import org.springframework.context.ConfigurableApplicationContext; +// +//@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("메시지 생성: [" + author.getUsername() + "] " + message.getContent()); +// } +// +// public static void main(String[] args) { +// ConfigurableApplicationContext context = SpringApplication.run(DiscodeitApplication.class, args); +// +// // 서비스 초기화 +// UserService userService = context.getBean(UserService.class); +// ChannelService channelService = context.getBean(ChannelService.class); +// MessageService messageService = context.getBean(MessageService.class); +// +// // 셋업 +// User user = setupUser(userService); +// Channel channel = setupChannel(channelService); +// +// // 테스트 +// messageCreateTest(messageService, channel, user); +// } +// +//} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/JavaApplication.java b/.github/src/main/java/com/sprint/mission/discodeit/JavaApplication.java new file mode 100644 index 000000000..c8eb112d5 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -0,0 +1,38 @@ +//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.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.basic.BasicChannelService; +//import com.sprint.mission.discodeit.service.basic.BasicMessageService; +//import com.sprint.mission.discodeit.service.basic.BasicUserService; +// +//public class JavaApplication { +// public static void main(String[] args) { +// // 레포지토리 초기화 +// UserRepository userRepository = new FileUserRepository(); +// ChannelRepository channelRepository = new FileChannelRepository(); +// MessageRepository messageRepository = new FileMessageRepository(); +// +// // 서비스 초기화 +// UserService userService = new BasicUserService(userRepository); +// ChannelService channelService = new BasicChannelService(channelRepository); +// MessageService messageService = new BasicMessageService(messageRepository, channelRepository, userRepository); +// +// // 셋업 +// User user = setupUser(userService); +// Channel channel = setupChannel(channelService); +// // 테스트 +// messageCreateTest(messageService, channel, user); +// } +//} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/dto/AuthDto.java b/.github/src/main/java/com/sprint/mission/discodeit/dto/AuthDto.java new file mode 100644 index 000000000..2cc77bd3f --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/dto/AuthDto.java @@ -0,0 +1,8 @@ +package com.sprint.mission.discodeit.dto; + +public class AuthDto { + public record LoginRequest( + String username, + String password + ) {} +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/dto/BinaryContentDto.java b/.github/src/main/java/com/sprint/mission/discodeit/dto/BinaryContentDto.java new file mode 100644 index 000000000..a4e0808f6 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/dto/BinaryContentDto.java @@ -0,0 +1,19 @@ +package com.sprint.mission.discodeit.dto; + +import java.util.UUID; + +public class BinaryContentDto { + public record CreateRequest( + byte[] bytes, + String contentType, + String fileName + ){} + + public record Response( + UUID id, + byte[] bytes, + String contentType, + String fileName + ){} + +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/dto/ChannelDto.java b/.github/src/main/java/com/sprint/mission/discodeit/dto/ChannelDto.java new file mode 100644 index 000000000..3bee70451 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/dto/ChannelDto.java @@ -0,0 +1,34 @@ +package com.sprint.mission.discodeit.dto; + +import com.sprint.mission.discodeit.entity.ChannelType; +import lombok.Builder; + +import java.time.Instant; +import java.util.List; +import java.util.UUID; + +public class ChannelDto { + public record CreateRequest( + ChannelType type, + String name, + String description + ) {} + + + @Builder + public record Response( + UUID id, + ChannelType type, + String name, + String description, + Instant lastMessageAt, + List memberIdList + + ) {} + + public record UpdateRequest ( + UUID channelId, + String newName, + String newDescription + ) {} +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/dto/MessageDto.java b/.github/src/main/java/com/sprint/mission/discodeit/dto/MessageDto.java new file mode 100644 index 000000000..7f9e9b132 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/dto/MessageDto.java @@ -0,0 +1,37 @@ +package com.sprint.mission.discodeit.dto; + +import lombok.Builder; + +import java.util.List; +import java.util.UUID; + +public class MessageDto { + public record CreateRequest( + String content, + UUID channelId, + UUID authorId, + List attachments // 첨부파일(선택) + ) {} + + public record BinaryContentDto ( + byte[] data, + String fileType, + String fileName + ) {} + + + @Builder + public record Response( + UUID id, + UUID channelId, + UUID authorId, + String content, + List attachmentId + ) {} + + public record UpdateRequest ( + UUID id, + String content, + List attachments + ) {} +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/dto/ReadStatusDto.java b/.github/src/main/java/com/sprint/mission/discodeit/dto/ReadStatusDto.java new file mode 100644 index 000000000..4f27dd7b8 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/dto/ReadStatusDto.java @@ -0,0 +1,25 @@ +package com.sprint.mission.discodeit.dto; + +import java.time.Instant; +import java.util.UUID; + +public class ReadStatusDto { + public record CreateRequest( + UUID userId, + UUID channelId + ){} + + public record Response( + UUID id, + UUID userId, + UUID channelId, + UUID lastMessageReadId, + Instant updatedAt + + ){} + + public record UpdateRequest( + UUID id, + UUID lastReadMessageId + ){} +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/dto/UserDto.java b/.github/src/main/java/com/sprint/mission/discodeit/dto/UserDto.java new file mode 100644 index 000000000..4d751b2d4 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/dto/UserDto.java @@ -0,0 +1,37 @@ +package com.sprint.mission.discodeit.dto; + +import lombok.Builder; + +import java.util.UUID; + +public class UserDto { + public record CreateRequest( + String username, + String email, + String password, + BinaryContentDto profileImage + ) {} + + public record BinaryContentDto ( + byte[] data, + String fileType, + String fileName + ) {} + + @Builder + public record Response( + UUID id, + String username, + String email, + boolean isOnline, + UUID profileImageId + ) {} + + public record UpdateRequest ( + UUID id, + String username, + String email, + String password, + BinaryContentDto profileImage + ) {} +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/dto/UserStatusDto.java b/.github/src/main/java/com/sprint/mission/discodeit/dto/UserStatusDto.java new file mode 100644 index 000000000..c7a160b39 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/dto/UserStatusDto.java @@ -0,0 +1,22 @@ +package com.sprint.mission.discodeit.dto; + +import java.time.Instant; +import java.util.UUID; + +public class UserStatusDto { + public record CreateRequest( + UUID userId + ){} + + public record Response( + UUID id, + UUID userId, + Instant updatedAt, + boolean isOnline + ){} + + public record UpdateRequest( + UUID id, + UUID userId + ){} +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java b/.github/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java new file mode 100644 index 000000000..ac38adefc --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java @@ -0,0 +1,26 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.AllArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.io.Serializable; +import java.time.Instant; +import java.util.UUID; + +@SuperBuilder +@AllArgsConstructor +public abstract class BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + protected final UUID id; + protected final Instant createdAt; + + public BaseEntity() { + this.id = UUID.randomUUID(); + this.createdAt = Instant.now(); + } + + // 공통 Getter + public UUID getId() { return id; } + public Instant getCreatedAt() { return createdAt; } + +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/entity/BinaryContent.java b/.github/src/main/java/com/sprint/mission/discodeit/entity/BinaryContent.java new file mode 100644 index 000000000..5989e3fb3 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/entity/BinaryContent.java @@ -0,0 +1,20 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; + +import java.time.Instant; +import java.util.UUID; + +@Getter +public class BinaryContent extends BaseEntity{ + private final byte[] bytes; + private final String contentType; // 예: image/png, application/pdf + private final String fileName; + + public BinaryContent(byte[] bytes, String contentType, String fileName) { + super(); + this.bytes = bytes; + this.contentType = contentType; + this.fileName = fileName; + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/entity/Channel.java b/.github/src/main/java/com/sprint/mission/discodeit/entity/Channel.java new file mode 100644 index 000000000..ea4ac80a7 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/entity/Channel.java @@ -0,0 +1,40 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.time.Instant; +import java.util.UUID; + +@Getter +@Setter +public class Channel extends BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + private Instant updatedAt; + private ChannelType type; + private String name; + private String description; + + public Channel(ChannelType type, String name, String description) { + this.type = type; + this.name = name; + this.description = description; + } + + public void update(String newName, String newDescription) { + boolean anyValueUpdated = false; + if (newName != null && !newName.equals(this.name)) { + this.name = newName; + anyValueUpdated = true; + } + if (newDescription != null && !newDescription.equals(this.description)) { + this.description = newDescription; + anyValueUpdated = true; + } + + if (anyValueUpdated) { + this.updatedAt = Instant.now(); + } + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/entity/ChannelType.java b/.github/src/main/java/com/sprint/mission/discodeit/entity/ChannelType.java new file mode 100644 index 000000000..9a2ff3f0f --- /dev/null +++ b/.github/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/.github/src/main/java/com/sprint/mission/discodeit/entity/Message.java b/.github/src/main/java/com/sprint/mission/discodeit/entity/Message.java new file mode 100644 index 000000000..61ce1d783 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/entity/Message.java @@ -0,0 +1,56 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.io.Serializable; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Getter +@Builder +@AllArgsConstructor +public class Message extends BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + private Instant updatedAt; + // + private String content; + // + private UUID channelId; + private UUID authorId; + private List attachmentIds; + + public Message(String content, UUID channelId, UUID authorId, List attachmentId) { + this.content = content; + this.channelId = channelId; + this.authorId = authorId; + this.attachmentIds = (attachmentId!= null) ? attachmentId: new ArrayList<>(); // 내용을 받지 않았을 때에는 빈 리스트로 초기화 + } + + public void update(String newContent, List newAttachmentIds) { + boolean[] isUpdated = {false}; + + Optional.ofNullable(newContent) + .filter(c -> !c.equals(this.content)) + .ifPresent(c -> { + this.content = c; + isUpdated[0] = true; + }); + + Optional.ofNullable(newAttachmentIds) + .filter(ids -> !ids.equals(this.attachmentIds)) + .ifPresent(ids -> { + this.attachmentIds = ids; + isUpdated[0] = true; + }); + + // 하나라도 바뀌었으면 시간 갱신 + if (isUpdated[0]) { + this.updatedAt = Instant.now(); + } + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/entity/ReadStatus.java b/.github/src/main/java/com/sprint/mission/discodeit/entity/ReadStatus.java new file mode 100644 index 000000000..eb84ecea4 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/entity/ReadStatus.java @@ -0,0 +1,29 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; + +import java.time.Instant; +import java.util.Optional; +import java.util.UUID; + +@Getter +public class ReadStatus extends BaseEntity { + private final UUID userId; + private final UUID channelId; + private Instant updatedAt; + private UUID lastReadMessageId; + + public ReadStatus(UUID userId, UUID channelId) { + this.userId = userId; + this.channelId = channelId; + } + + public void updateLastReadMessage(UUID lastReadMessageId) { + Optional.ofNullable(lastReadMessageId) + .filter(id -> !id.equals(this.lastReadMessageId)) + .ifPresent(id -> { + this.lastReadMessageId = id; + this.updatedAt = Instant.now(); + }); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/entity/User.java b/.github/src/main/java/com/sprint/mission/discodeit/entity/User.java new file mode 100644 index 000000000..d64313e2c --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/entity/User.java @@ -0,0 +1,35 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.time.Instant; +import java.util.Optional; +import java.util.UUID; + +@Getter +@Setter +public class User extends BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + + private Instant updatedAt; + + private String username; + private String email; + private String password; + + private UUID profileImageId; + + public User(String username, String email, String password) { + this.username = username; + this.email = email; + this.password = password; + } + + public void update(String newUsername, String newEmail, String newPassword) { + Optional.ofNullable(newUsername).filter(s -> !s.isBlank()).ifPresent(this::setUsername); + Optional.ofNullable(newEmail).filter(s -> !s.isBlank()).ifPresent(this::setEmail); + Optional.ofNullable(newPassword).filter(s -> !s.isBlank()).ifPresent(this::setPassword); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/entity/UserStatus.java b/.github/src/main/java/com/sprint/mission/discodeit/entity/UserStatus.java new file mode 100644 index 000000000..4991751c7 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/entity/UserStatus.java @@ -0,0 +1,27 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; + +import java.time.Instant; +import java.util.UUID; + +@Getter +public class UserStatus extends BaseEntity { + private final UUID userId; + private Instant updatedAt; + + public UserStatus(UUID userId) { + this.userId = userId; + } + + // 5분 이내 접속 여부 판단 메소드 + public boolean isOnline() { + // 현재 시간 - 5분(300초) 이후 접속했다면 true + return updatedAt.isAfter(Instant.now().minusSeconds(300)); + } + + public void updateActiveTime() { + this.updatedAt = Instant.now(); + } + +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/BinaryContentRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/BinaryContentRepository.java new file mode 100644 index 000000000..03c42f422 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/BinaryContentRepository.java @@ -0,0 +1,21 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface BinaryContentRepository { + BinaryContent save(BinaryContent binaryContent); + + Optional findById(UUID id); + List findAllById(List idList); + + boolean existsById(UUID id); + + void deleteById(UUID id); + void deleteAllById(List idList); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java new file mode 100644 index 000000000..c8b9faa77 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java @@ -0,0 +1,17 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface ChannelRepository { + Channel save(Channel channel); + Optional findById(UUID id); + List findAll(); + boolean existsById(UUID id); + void deleteById(UUID id); + List findAllByType(ChannelType channelType); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java new file mode 100644 index 000000000..a34ce4f0c --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java @@ -0,0 +1,22 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.Message; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface MessageRepository { + Message save(Message message); + + Optional findById(UUID id); + Optional findLastMessageOfChannel(UUID channelId); + + List findAll(); + List findAllByChannelId(UUID channelId); + + boolean existsById(UUID id); + + void deleteById(UUID id); + void deleteAllByChannelId(UUID channelId); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/ReadStatusRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/ReadStatusRepository.java new file mode 100644 index 000000000..29b6bb9f1 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/ReadStatusRepository.java @@ -0,0 +1,27 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.entity.UserStatus; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface ReadStatusRepository { + ReadStatus save(ReadStatus readStatus); + Optional findById(UUID id); + + Optional findByUserAndChannelId(UUID userId, UUID channelId); + + void deleteById(UUID id); + void deleteAllByChannelId(UUID channelId); + public List findAll(); + + List findAllByChannelId(UUID channelId); + List findAllByUserId(UUID userId); + + boolean existsByChannelIdAndUserId(UUID channelId, UUID userId); + boolean existsById(UUID id); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java new file mode 100644 index 000000000..867ab1bf5 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java @@ -0,0 +1,20 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.User; + +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(); + boolean existsById(UUID id); + void deleteById(UUID id); + + boolean usernameExistence(String username); + boolean emailExistence(String email); + + Optional findByUsername(String username); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/UserStatusRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/UserStatusRepository.java new file mode 100644 index 000000000..cae485b96 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/UserStatusRepository.java @@ -0,0 +1,22 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.UserStatus; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface UserStatusRepository { + UserStatus save(UserStatus userStatus); + + boolean existsByUserId(UUID userId); + boolean existsById(UUID id); + + Optional findById(UUID id); + Optional findByUserId(UUID userId); + List findAll(); + + void deleteById(UUID id); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileBinaryContentRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileBinaryContentRepository.java new file mode 100644 index 000000000..eb01deaa9 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileBinaryContentRepository.java @@ -0,0 +1,117 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileBinaryContentRepository implements BinaryContentRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileBinaryContentRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + 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(e); + } + } + } + + private Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); + } + + @Override + public BinaryContent save(BinaryContent binaryContent) { + Path path = resolvePath(binaryContent.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(binaryContent); + } catch (IOException e) { + throw new RuntimeException(e); + } + return binaryContent; + } + + @Override + public Optional findById(UUID id) { + BinaryContent binaryContentNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + binaryContentNullable = (BinaryContent) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + return Optional.ofNullable(binaryContentNullable); + } + + @Override + public List findAllById(List idList) { + return idList.stream() + .map(this::resolvePath) + .filter(Files::exists) + .map(path -> { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + return (BinaryContent) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } + + @Override + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deleteAllById(List idList) { + idList.forEach(id -> { + Path path = resolvePath(id); + try { + Files.deleteIfExists(path); + } catch (IOException e) { + throw new RuntimeException("파일 삭제 실패: " + id, e); + } + }); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java new file mode 100644 index 000000000..90ef855e9 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java @@ -0,0 +1,116 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileChannelRepository implements ChannelRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileChannelRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + 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 Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); + } + + @Override + public Channel save(Channel channel) { + Path path = resolvePath(channel.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(channel); + } catch (IOException e) { + throw new RuntimeException(e); + } + return channel; + } + + @Override + 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 Optional.ofNullable(channelNullable); + } + + @Override + public List findAll() { + 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 boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public List findAllByType(ChannelType channelType) { + return findAll().stream() + .filter(channel -> channel.getType().equals(channelType)) + .toList(); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java new file mode 100644 index 000000000..9c2c40342 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java @@ -0,0 +1,165 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.repository.MessageRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileMessageRepository implements MessageRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileMessageRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + 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 Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); + } + + @Override + public Message save(Message message) { + Path path = resolvePath(message.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(message); + } catch (IOException e) { + throw new RuntimeException(e); + } + return message; + } + + @Override + 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 Optional.ofNullable(messageNullable); + } + + @Override + public Optional findLastMessageOfChannel(UUID channelId) { + 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); + } + }) + .filter(message -> message.getChannelId().equals(channelId)) + .sorted(Comparator.comparing(Message::getCreatedAt).reversed()) + .findFirst(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public List findAll() { + 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 List findAllByChannelId(UUID channelId) { + return findAll().stream() + .filter(message -> message.getChannelId().equals(channelId)) + .toList(); + } + + @Override + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deleteAllByChannelId(UUID channelId) { + try { + Files.list(DIRECTORY) + .filter(path -> path.toString().endsWith(EXTENSION)) + .forEach(path -> { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + Message message = (Message) ois.readObject(); + if (message.getChannelId().equals(channelId)) { + ois.close(); + fis.close(); + Files.delete(path); + } + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException("파일 삭제 중 오류 발생: " + path, e); + } + }); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileReadStatusRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileReadStatusRepository.java new file mode 100644 index 000000000..b1860eac9 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileReadStatusRepository.java @@ -0,0 +1,162 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileReadStatusRepository implements ReadStatusRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileReadStatusRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + this.DIRECTORY = Paths.get(System.getProperty("user.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); + } + + @Override + public ReadStatus save(ReadStatus readStatus) { + Path path = resolvePath(readStatus.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(readStatus); + } catch (IOException e) { + throw new RuntimeException(e); + } + return readStatus; + } + + @Override + public Optional findById(UUID id) { + ReadStatus readStatusNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + readStatusNullable = (ReadStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + return Optional.ofNullable(readStatusNullable); + } + + @Override + public Optional findByUserAndChannelId(UUID userId, UUID channelId) { + return findAll().stream() + .filter(readStatus -> readStatus.getUserId().equals(userId) && readStatus.getChannelId().equals(channelId)) + .findFirst(); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deleteAllByChannelId(UUID channelId) { + try { + Files.list(DIRECTORY) + .filter(path -> path.toString().endsWith(EXTENSION)) + .forEach(path -> { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + Message message = (Message) ois.readObject(); + if (message.getChannelId().equals(channelId)) { + ois.close(); + fis.close(); + Files.delete(path); + } + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException("파일 삭제 중 오류 발생: " + path, e); + } + }); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + + @Override + public List findAll() { + 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 (ReadStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public List findAllByChannelId(UUID channelId) { + return findAll().stream() + .filter(readStatus -> readStatus.getChannelId().equals(channelId)) + .toList(); + } + + @Override + public List findAllByUserId(UUID userId) { + return findAll().stream() + .filter(readStatus -> readStatus.getChannelId().equals(userId)) + .toList(); + } + + @Override + public boolean existsByChannelIdAndUserId(UUID channelId, UUID userId) { + return findByUserAndChannelId(userId, channelId).isPresent(); + } + + @Override + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + +} \ No newline at end of file diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java new file mode 100644 index 000000000..42618daa0 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java @@ -0,0 +1,127 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.repository.UserRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileUserRepository implements UserRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileUserRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + 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 Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); + } + + @Override + public User save(User user) { + Path path = resolvePath(user.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(user); + } catch (IOException e) { + throw new RuntimeException(e); + } + return user; + } + + @Override + 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 Optional.ofNullable(userNullable); + } + + @Override + public List findAll() { + 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 boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean usernameExistence(String username) { + return findAll().stream() + .anyMatch(user -> user.getUsername().equals(username)); + } + + @Override + public boolean emailExistence(String email) { + return findAll().stream() + .anyMatch(user -> user.getEmail().equals(email)); + } + + @Override + public Optional findByUsername(String username) { + return findAll().stream() + .filter(user -> user.getUsername().equals(username)) + .findFirst(); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserStatusRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserStatusRepository.java new file mode 100644 index 000000000..5762b2e68 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserStatusRepository.java @@ -0,0 +1,133 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.repository.UserStatusRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileUserStatusRepository implements UserStatusRepository { + + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileUserStatusRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + this.DIRECTORY = Paths.get(System.getProperty("user.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); + } + + @Override + public UserStatus save(UserStatus userStatus) { + Path path = resolvePath(userStatus.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(userStatus); + } catch (IOException e) { + throw new RuntimeException(e); + } + return userStatus; + } + + @Override + public boolean existsByUserId(UUID userId) { + Path path = resolvePath(userId); + return Files.exists(path); + } + + @Override + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public Optional findById(UUID id) { + UserStatus userStatusNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + userStatusNullable = (UserStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + return Optional.ofNullable(userStatusNullable); + } + + @Override + public Optional findByUserId(UUID userId) { + UserStatus userStatusNullable = null; + Path path = resolvePath(userId); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + userStatusNullable = (UserStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException 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 ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + return (UserStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java new file mode 100644 index 000000000..d6e5b4a2a --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java @@ -0,0 +1,55 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFBinaryContentRepository implements BinaryContentRepository { + private final Map data; + + public JCFBinaryContentRepository() { + this.data = new HashMap<>(); + } + + @Override + public BinaryContent save(BinaryContent binaryContent) { + this.data.put(binaryContent.getId(), binaryContent); + return binaryContent; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public List findAllById(List idList) { + return data.values().stream() + .filter(binaryContent -> idList.contains(binaryContent.getId())) + .toList(); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public void deleteAllById(List idList) { + data.values().removeIf(binaryContent -> idList.contains(binaryContent.getId())); + + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java new file mode 100644 index 000000000..785fac572 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java @@ -0,0 +1,55 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFChannelRepository implements ChannelRepository { + private final Map data; + + public JCFChannelRepository() { + this.data = new HashMap<>(); + } + + @Override + public Channel save(Channel channel) { + this.data.put(channel.getId(), channel); + return channel; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public List findAllByType(ChannelType channelType) { + return data.values().stream() + .filter(channel -> channel.getType().equals(channelType)) + .toList(); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java new file mode 100644 index 000000000..8f28c548f --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java @@ -0,0 +1,67 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.repository.MessageRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFMessageRepository implements MessageRepository { + private final Map data; + + public JCFMessageRepository() { + this.data = new HashMap<>(); + } + + @Override + public Message save(Message message) { + this.data.put(message.getId(), message); + return message; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public Optional findLastMessageOfChannel(UUID channelId) { + return data.values().stream() + .filter(message -> message.getChannelId().equals(channelId)) + .sorted(Comparator.comparing(Message::getCreatedAt).reversed()) + .findFirst(); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public List findAllByChannelId(UUID channelId) { + return data.values().stream() + .filter(message -> message.getChannelId().equals(channelId)) + .toList(); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public void deleteAllByChannelId(UUID channelId) { + data.values().removeIf(message -> message.getChannelId().equals(channelId)); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFReadStatusRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFReadStatusRepository.java new file mode 100644 index 000000000..03db7eaec --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFReadStatusRepository.java @@ -0,0 +1,82 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFReadStatusRepository implements ReadStatusRepository { + + private final Map data; + public JCFReadStatusRepository() { + this.data = new HashMap<>(); + } + + @Override + public ReadStatus save(ReadStatus readStatus) { + this.data.put(readStatus.getId(), readStatus); + return readStatus; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public Optional findByUserAndChannelId(UUID userId, UUID channelId) { + return data.values().stream() + .filter(readStatus -> readStatus.getUserId().equals(userId)) + .filter(readStatus -> readStatus.getChannelId().equals(channelId)) + .findFirst(); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public void deleteAllByChannelId(UUID channelId) { + data.values().removeIf(readStatus -> readStatus.getChannelId().equals(channelId)); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public List findAllByChannelId(UUID channelId) { + return data.values().stream() + .filter(readStatus -> readStatus.getChannelId().equals(channelId)) + .toList(); + } + + @Override + public List findAllByUserId(UUID userId) { + return data.values().stream() + .filter(readStatus -> readStatus.getUserId().equals(userId)) + .toList(); + } + + @Override + public boolean existsByChannelIdAndUserId(UUID channelId, UUID userId) { + return data.values().stream() + .anyMatch(readStatus -> + readStatus.getUserId().equals(userId) && readStatus.getChannelId().equals(channelId) + ); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java new file mode 100644 index 000000000..3264d1e9d --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java @@ -0,0 +1,66 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.repository.UserRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFUserRepository implements UserRepository { + private final Map data; + + public JCFUserRepository() { + this.data = new HashMap<>(); + } + + @Override + public User save(User user) { + this.data.put(user.getId(), user); + return user; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public boolean usernameExistence(String username) { + return data.values().stream() + .anyMatch(user -> user.getUsername().equals(username)); + } + + @Override + public boolean emailExistence(String email) { + return data.values().stream() + .anyMatch(user -> user.getEmail().equals(email)); + } + + @Override + public Optional findByUsername(String username) { + return data.values().stream() + .filter(user -> user.getUsername().equals(username)) + .findFirst(); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserStatusRepository.java b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserStatusRepository.java new file mode 100644 index 000000000..cfc8df1ef --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserStatusRepository.java @@ -0,0 +1,61 @@ +package com.sprint.mission.discodeit.repository.jcf; + + +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.repository.UserStatusRepository; +import com.sprint.mission.discodeit.service.UserStatusService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFUserStatusRepository implements UserStatusRepository { + private final Map data; + + public JCFUserStatusRepository() { + this.data = new HashMap<>(); + } + + + @Override + public UserStatus save(UserStatus userStatus) { + this.data.put(userStatus.getId(), userStatus); + return userStatus; + } + + @Override + public boolean existsByUserId(UUID userId) { + return this.data.containsKey(userId); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public Optional findByUserId(UUID userId) { + return Optional.ofNullable(this.data.get(userId)); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/AuthService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/AuthService.java new file mode 100644 index 000000000..d68baee7f --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/AuthService.java @@ -0,0 +1,8 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.AuthDto; +import com.sprint.mission.discodeit.dto.UserDto; + +public interface AuthService { + UserDto.Response login(AuthDto.LoginRequest request); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/BinaryContentService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/BinaryContentService.java new file mode 100644 index 000000000..6a1341f0f --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/BinaryContentService.java @@ -0,0 +1,15 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.BinaryContentDto; +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.dto.UserStatusDto; + +import java.util.List; +import java.util.UUID; + +public interface BinaryContentService { + BinaryContentDto.Response create(BinaryContentDto.CreateRequest request); + BinaryContentDto.Response find(UUID userId); + List findAllByIdIn(List idList); + void delete(UUID id); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java new file mode 100644 index 000000000..af357ecd5 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -0,0 +1,16 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.ChannelDto; +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; + +import java.util.List; +import java.util.UUID; + +public interface ChannelService { + ChannelDto.Response create(ChannelDto.CreateRequest request); + ChannelDto.Response find(UUID channelId); + List findAllByUserId(UUID userId); + ChannelDto.Response update(ChannelDto.UpdateRequest request); + void delete(UUID channelId); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/MessageService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/MessageService.java new file mode 100644 index 000000000..723f49053 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -0,0 +1,15 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.MessageDto; +import com.sprint.mission.discodeit.entity.Message; + +import java.util.List; +import java.util.UUID; + +public interface MessageService { + MessageDto.Response create(MessageDto.CreateRequest request); + List findAllByChannelId(UUID channelId); +// List findAll(); + MessageDto.Response update(MessageDto.UpdateRequest request); + void delete(UUID messageId); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/ReadStatusService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/ReadStatusService.java new file mode 100644 index 000000000..a02957986 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/ReadStatusService.java @@ -0,0 +1,18 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.entity.User; +import lombok.Locked; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface ReadStatusService { + ReadStatusDto.Response create(ReadStatusDto.CreateRequest request); + ReadStatusDto.Response find(UUID id); + List findAllByUserId(UUID userId); + ReadStatusDto.Response update(ReadStatusDto.UpdateRequest request); + void delete(UUID id); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/UserService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/UserService.java new file mode 100644 index 000000000..3186f3ffb --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/UserService.java @@ -0,0 +1,15 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.UserDto; +import com.sprint.mission.discodeit.entity.User; + +import java.util.List; +import java.util.UUID; + +public interface UserService { + UserDto.Response create(UserDto.CreateRequest request); + UserDto.Response find(UUID userId); + List findAll(); + UserDto.Response update(UserDto.UpdateRequest request); + void delete(UUID userId); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/UserStatusService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/UserStatusService.java new file mode 100644 index 000000000..ff497c9a0 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/UserStatusService.java @@ -0,0 +1,16 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.dto.UserStatusDto; + +import java.util.List; +import java.util.UUID; + +public interface UserStatusService { + UserStatusDto.Response create(UserStatusDto.CreateRequest request); + UserStatusDto.Response find(UUID id); + List findAll(); + UserStatusDto.Response update(UserStatusDto.UpdateRequest request); + UserStatusDto.Response updateByUserId(UserStatusDto.UpdateRequest request); + void delete(UUID id); +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicAuthService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicAuthService.java new file mode 100644 index 000000000..0c9010a4d --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicAuthService.java @@ -0,0 +1,39 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.AuthDto; +import com.sprint.mission.discodeit.dto.UserDto; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.service.AuthService; +import org.springframework.stereotype.Service; + +import java.util.NoSuchElementException; + +@Service +public class BasicAuthService implements AuthService { + + private final UserRepository userRepository; + + public BasicAuthService(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Override + public UserDto.Response login(AuthDto.LoginRequest request) { + // username: 유저 존재 확인 + User user = userRepository.findByUsername(request.username()) + .orElseThrow(() -> new NoSuchElementException("존재하지 않는 유저입니다.")); + + // password: 비밀번호 일치 여부 확인 + if (!user.getPassword().equals(request.password())) { + throw new IllegalArgumentException("비밀번호가 일치하지 않습니다."); + } + + return UserDto.Response.builder() + .id(user.getId()) + .username(user.getUsername()) + .email(user.getEmail()) + .profileImageId(user.getProfileImageId()) + .build(); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicBinaryContentService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicBinaryContentService.java new file mode 100644 index 000000000..7997973d9 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicBinaryContentService.java @@ -0,0 +1,59 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.BinaryContentDto; +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; +import com.sprint.mission.discodeit.service.BinaryContentService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class BasicBinaryContentService implements BinaryContentService { + private final BinaryContentRepository binaryContentRepository; + + @Override + public BinaryContentDto.Response create(BinaryContentDto.CreateRequest request) { + BinaryContent content = new BinaryContent( + request.bytes(), + request.contentType(), + request.fileName() + ); + return convertToResponse(binaryContentRepository.save(content)); + } + + @Override + public BinaryContentDto.Response find(UUID userId) { + return binaryContentRepository.findById(userId) + .map(this::convertToResponse) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 파일이 존재하지 않습니다.")); + } + + @Override + public List findAllByIdIn(List idList) { + return binaryContentRepository.findAllById(idList).stream() + .map(this::convertToResponse) + .toList(); + } + + @Override + public void delete(UUID id) { + if (!binaryContentRepository.existsById(id)) { + throw new NoSuchElementException("해당 ID의 파일이 존재하지 않습니다."); + } + binaryContentRepository.deleteById(id); + } + + private BinaryContentDto.Response convertToResponse(BinaryContent content) { + return new BinaryContentDto.Response( + content.getId(), + content.getBytes(), + content.getContentType(), + content.getFileName() + ); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicChannelService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicChannelService.java new file mode 100644 index 000000000..d650f962e --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicChannelService.java @@ -0,0 +1,124 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.ChannelDto; +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.ReadStatus; +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.service.ChannelService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.validation.MessageCodesResolver; + +import java.time.Instant; +import java.util.*; + +@Service +@RequiredArgsConstructor +public class BasicChannelService implements ChannelService { + private final ChannelRepository channelRepository; + private final ReadStatusRepository readStatusRepository; + private final MessageRepository messageRepository; + + + @Override + public ChannelDto.Response create(ChannelDto.CreateRequest request) { + // PUBLIC 채널 생성 시 기존 로직 유지, PRIVATE 채널 생성 시 생략 + String name = (request.type() == ChannelType.PUBLIC) ? request.name() : null; + String description = (request.type() == ChannelType.PUBLIC) ? request.description() : null; + + Channel channel = new Channel(request.type(), name, description); + channelRepository.save(channel); + + return convertToResponse(channel, null, null); // 초기 생성 시 최근 메시지, 유저 목록 없음 + } + + + @Override + public ChannelDto.Response find(UUID channelId) { + Channel channel = channelRepository.findById(channelId) + .orElseThrow(() -> new NoSuchElementException("Channel with id " + channelId + " not found")); + + // 해당 채널의 가장 최근 메시지의 시간 정보 + Instant lastTime = messageRepository.findLastMessageOfChannel(channelId) + .map(Message::getCreatedAt).orElse(null); + + // PRIVATE 채널의 경우 참여한 유저의 id 포함 + List memberList = null; + if (channel.getType() == ChannelType.PRIVATE) { + memberList = readStatusRepository.findAllByChannelId(channelId).stream() + .map(ReadStatus::getUserId) + .toList(); + } + + return convertToResponse(channel, lastTime, memberList); + + } + + @Override + public List findAllByUserId (UUID userId){ + // PUBLIC 채널: 전체 조회 + List publicChannels = channelRepository.findAllByType(ChannelType.PUBLIC); + + // PRIVATE: 유저가 참여한 채널만 조회 + List myPrivateChannels = readStatusRepository.findAllByUserId(userId).stream() + .map(readStatus -> channelRepository.findById(readStatus.getChannelId()).orElse(null)) + .filter(Objects::nonNull) + .filter(channel -> channel.getType() == ChannelType.PRIVATE) + .toList(); + + // 참여한 PUBLIC과 PRIVATE 채널 합치기: 특정 유저가 볼 수 있는 채널 목록 조회 가능 + List myAvailableChannelList = new ArrayList<>(); + myAvailableChannelList.addAll(publicChannels); + myAvailableChannelList.addAll(myPrivateChannels); + + // find() 재사용: 최근 메시지 시간 정보, PRIVATE 채널의 유저 Id 정보 포함 + return myAvailableChannelList.stream() + .map(channel -> find(channel.getId())) + .toList(); + } + + @Override + public ChannelDto.Response update (ChannelDto.UpdateRequest request) { + Channel channel = channelRepository.findById(request.channelId()) + .orElseThrow(() -> new NoSuchElementException("Channel with id " + request.channelId() + " not found")); + + // PRIVATE 채널은 수정 불가 + if (channel.getType() == ChannelType.PRIVATE) { + throw new IllegalStateException("PRIVATE 채널은 수정할 수 없습니다."); + } + + channel.setName(request.newName()); + channel.setDescription(request.newDescription()); + + channelRepository.save(channel); + return convertToResponse(channel, null, null); + } + + @Override + public void delete (UUID channelId) { + Channel channel = channelRepository.findById(channelId).orElseThrow(); + + // 관련 도메인(Message, ReadStatus) 삭제 + messageRepository.deleteAllByChannelId(channelId); + readStatusRepository.deleteAllByChannelId(channelId); + + channelRepository.deleteById(channelId); + } + + private ChannelDto.Response convertToResponse (Channel channel, Instant lastMessageTime, List memberId) { + return ChannelDto.Response.builder() + .id(channel.getId()) + .name(channel.getName()) + .lastMessageAt(lastMessageTime) + .memberIdList(memberId) + .build(); + } + } + + + + diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicMessageService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicMessageService.java new file mode 100644 index 000000000..87985e10d --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicMessageService.java @@ -0,0 +1,111 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.MessageDto; +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.entity.Message; +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.*; + +@Service +@RequiredArgsConstructor +public class BasicMessageService implements MessageService { + private final MessageRepository messageRepository; + private final ChannelRepository channelRepository; + private final UserRepository userRepository; + private final BinaryContentRepository binaryContentRepository; + + @Override + public MessageDto.Response create(MessageDto.CreateRequest request) { + + List attachmentIds = new ArrayList<>(); + + if (request.attachments() != null && !request.attachments().isEmpty()) { + attachmentIds = request.attachments().stream() + .map(fileRequest -> { + BinaryContent content = new BinaryContent( + fileRequest.data(), + fileRequest.fileType(), + fileRequest.fileName() + ); + return binaryContentRepository.save(content).getId(); + }) + .toList(); + } + + Message message = new Message( + request.content(), + request.channelId(), + request.authorId(), + attachmentIds + ); + + messageRepository.save(message); + + return convertToResponse(message); + + } + + @Override + public List findAllByChannelId(UUID channelId) { + return messageRepository.findAllByChannelId(channelId).stream() + .map(this::convertToResponse) + .toList(); + } + + @Override + public MessageDto.Response update(MessageDto.UpdateRequest request) { + Message message = messageRepository.findById(request.id()) + .orElseThrow(() -> new NoSuchElementException("Message with id " + request.id() + " not found")); + + List newIds = Optional.ofNullable(request.attachments()) + .filter(attachments -> !attachments.isEmpty()) + .map(attachments -> attachments.stream() + .map(dto -> { + BinaryContent content = new BinaryContent( + dto.data(), + dto.fileType(), + dto.fileName() + ); + return binaryContentRepository.save(content).getId(); + }) + .toList() + ) + .orElse(null); + message.update(request.content(), newIds); + + return convertToResponse(messageRepository.save(message)); + + } + + + @Override + public void delete(UUID id) { + Message message = messageRepository.findById(id) + .orElseThrow(() -> new NoSuchElementException("Message with id " + id + " not found")); + + // 첨부파일 삭제 + if (message.getAttachmentIds() != null && !message.getAttachmentIds().isEmpty()) { + binaryContentRepository.deleteAllById(message.getAttachmentIds()); + } + + messageRepository.deleteById(id); + + } + + private MessageDto.Response convertToResponse(Message message) { + return MessageDto.Response.builder() + .id(message.getId()) + .channelId(message.getChannelId()) + .authorId(message.getAuthorId()) + .content(message.getContent()) + .attachmentId(message.getAttachmentIds()) + .build(); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicReadStatusService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicReadStatusService.java new file mode 100644 index 000000000..cc82371e1 --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicReadStatusService.java @@ -0,0 +1,87 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.service.ReadStatusService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class BasicReadStatusService implements ReadStatusService { + private final ReadStatusRepository readStatusRepository; + private final UserRepository userRepository; + private final ChannelRepository channelRepository; + + @Override + public ReadStatusDto.Response create(ReadStatusDto.CreateRequest request) { + // 관련된 채널이나 유저가 존재하지 않을 때 예외 발생 + channelRepository.findById(request.channelId()) + .orElseThrow(() -> new NoSuchElementException("채널이 존재하지 않습니다.")); + + userRepository.findById(request.userId()) + .orElseThrow(() -> new NoSuchElementException("유저가 존재하지 않습니다.")); + + // 같은 채널과 유저와 관련된 객체가 이미 존재하면 예외 발생 + if(readStatusRepository.existsByChannelIdAndUserId(request.channelId(), request.userId())) { + throw new IllegalStateException("이미 채널과 유저의 상태가 존재합니다."); + } + + ReadStatus readStatus = new ReadStatus(request.channelId(), request.userId()); + return convertToResponse(readStatusRepository.save(readStatus)); + + } + + @Override + public ReadStatusDto.Response find(UUID id) { + return readStatusRepository.findById(id) + .map(this::convertToResponse) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다.")); + } + + @Override + public List findAllByUserId(UUID userId) { + return readStatusRepository.findAllByUserId(userId).stream() + .map(this::convertToResponse) + .toList(); + } + + @Override + public ReadStatusDto.Response update(ReadStatusDto.UpdateRequest request) { + ReadStatus readStatus = readStatusRepository.findById(request.id()) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다.")); + + Optional.ofNullable(request.lastReadMessageId()) + .ifPresent(readStatus::updateLastReadMessage); + + return convertToResponse(readStatusRepository.save(readStatus)); + } + + @Override + public void delete(UUID id) { + if(!readStatusRepository.existsById(id)) { + throw new NoSuchElementException("존재하지 않는 Id 입니다."); + } + readStatusRepository.deleteById(id); + + } + private ReadStatusDto.Response convertToResponse(ReadStatus readStatus) { + return new ReadStatusDto.Response( + readStatus.getId(), + readStatus.getUserId(), + readStatus.getChannelId(), + readStatus.getLastReadMessageId(), + readStatus.getUpdatedAt() + ); + } + +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java new file mode 100644 index 000000000..ee70a6eaa --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java @@ -0,0 +1,137 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.UserDto; +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.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; + +@Service +@RequiredArgsConstructor +public class BasicUserService implements UserService { + private final UserRepository userRepository; + private final BinaryContentRepository binaryContentRepository; + private final UserStatusRepository userStatusRepository; + + @Override + public UserDto.Response create(UserDto.CreateRequest request) { + // 프로필 이미지 처리(선택적) + UUID imageId = null; + if (request.profileImage() != null) { + BinaryContent image = new BinaryContent( + request.profileImage().data(), + request.profileImage().fileType(), + request.profileImage().fileName()); + imageId = binaryContentRepository.save(image).getId(); + } + + // 중복 검증 + if (userRepository.usernameExistence(request.username())) throw new RuntimeException("이미 존재하는 이름입니다."); + if (userRepository.emailExistence(request.email())) throw new RuntimeException("이미 존재하는 이메일입니다."); + + // 유저 등록 + User user = new User(request.username(), request.email(), request.password()); + if (imageId != null) { + user.setProfileImageId(imageId); + } + User savedUser = userRepository.save(user); + userStatusRepository.save(new UserStatus(savedUser.getId())); + + return UserDto.Response.builder() + .id(savedUser.getId()) + .username(savedUser.getUsername()) + .email(savedUser.getEmail()) + .isOnline(true) + .profileImageId(savedUser.getProfileImageId()) + .build(); + + + } + + @Override + public UserDto.Response find(UUID userId) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new NoSuchElementException("User with id " + userId + " not found")); + + // 유저 온라인 상태 정보 포함(패스워드 제외) + boolean isOnline = userStatusRepository.findByUserId(userId) + .map(UserStatus::isOnline) + .orElse(false); + + return UserDto.Response.builder() + .id(user.getId()) + .username(user.getUsername()) + .email(user.getEmail()) + .profileImageId(user.getProfileImageId()) + .isOnline(isOnline) + .build(); + } + + @Override + public List findAll() { + return userRepository.findAll().stream() + .map(user -> { + boolean isOnline = userStatusRepository.findByUserId(user.getId()) + .map(UserStatus::isOnline) + .orElse(false); + + return UserDto.Response.builder() + .id(user.getId()) + .username(user.getUsername()) + .email(user.getEmail()) + .profileImageId(user.getProfileImageId()) + .isOnline(isOnline) + .build(); + }) + .toList(); + } + + @Override + public UserDto.Response update(UserDto.UpdateRequest updateRequest) { + User user = userRepository.findById(updateRequest.id()) + .orElseThrow(() -> new NoSuchElementException("User with id " + updateRequest.id()+ " not found")); + + // 프로필 이미지 대체 (선택) + Optional.ofNullable(updateRequest.profileImage()) + .ifPresent(imageDto -> { + if (user.getProfileImageId() != null) { + binaryContentRepository.deleteById(user.getProfileImageId()); + } + BinaryContent newImage = new BinaryContent( + imageDto.data(), imageDto.fileType(), imageDto.fileName() + ); + user.setProfileImageId(binaryContentRepository.save(newImage).getId()); + }); + + user.update(updateRequest.username(), updateRequest.email(), updateRequest.password()); + userRepository.save(user); + return find(user.getId()); + } + + @Override + public void delete(UUID userId) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new NoSuchElementException("User not found with id: " + userId)); + + // BinaryContent 삭제 + if (user.getProfileImageId() != null) { + binaryContentRepository.deleteById(user.getProfileImageId()); + } + + // UserStatus 삭제 + userStatusRepository.deleteById(userId); + + // 유저 삭제 + userRepository.deleteById(userId); + } +} diff --git a/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserStatusService.java b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserStatusService.java new file mode 100644 index 000000000..eda29109c --- /dev/null +++ b/.github/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserStatusService.java @@ -0,0 +1,93 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.dto.UserStatusDto; +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.repository.UserStatusRepository; +import com.sprint.mission.discodeit.service.UserStatusService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class BasicUserStatusService implements UserStatusService { + + private final UserStatusRepository userStatusRepository; + private final UserRepository userRepository; + + + @Override + public UserStatusDto.Response create(UserStatusDto.CreateRequest request) { + // 관련된 유저 존재 X + userRepository.findById(request.userId()) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 유저가 존재하지 않습니다.")); + + // 같은 유저와 관련된 객체가 이미 존재 + if (userStatusRepository.existsByUserId(request.userId())) { + throw new IllegalStateException("해당 ID의 상태가 이미 존재합니다."); + } + + UserStatus userStatus = new UserStatus( + request.userId() + ); + + return convertToResponse(userStatusRepository.save(userStatus)); + } + + @Override + public UserStatusDto.Response find(UUID id) { + return userStatusRepository.findById(id) + .map(this::convertToResponse) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다.")); + } + + @Override + public List findAll() { + return userStatusRepository.findAll().stream() + .map(this::convertToResponse) + .toList(); + } + + @Override + public UserStatusDto.Response update(UserStatusDto.UpdateRequest request) { + UserStatus userStatus = userStatusRepository.findById(request.id()) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다.")); + + userStatus.updateActiveTime(); + + return convertToResponse(userStatusRepository.save(userStatus)); + } + + @Override + public UserStatusDto.Response updateByUserId(UserStatusDto.UpdateRequest request) { + UserStatus userStatus = userStatusRepository.findByUserId(request.userId()) + .orElseThrow(() -> new NoSuchElementException("해당 유저의 상태 정보가 존재하지 않습니다.")); + + userStatus.updateActiveTime(); + + return convertToResponse(userStatusRepository.save(userStatus)); + } + + @Override + public void delete(UUID id) { + if (!userStatusRepository.existsById(id)) { + throw new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다."); + } + userStatusRepository.deleteById(id); + + } + + private UserStatusDto.Response convertToResponse(UserStatus userStatus) { + return new UserStatusDto.Response( + userStatus.getId(), + userStatus.getUserId(), + userStatus.getUpdatedAt(), + userStatus.isOnline() + ); + } +} diff --git a/.github/src/main/resources/application.yaml b/.github/src/main/resources/application.yaml new file mode 100644 index 000000000..4fe0afb2e --- /dev/null +++ b/.github/src/main/resources/application.yaml @@ -0,0 +1,4 @@ +discodeit: + repository: + type: jcf + file-directory: .discodeit diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 000000000..e07238326 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +0-sprint-mission \ No newline at end of file diff --git a/HELP.md b/HELP.md new file mode 100644 index 000000000..1337c63bd --- /dev/null +++ b/HELP.md @@ -0,0 +1,25 @@ +# Getting Started + +### Reference Documentation + +For further reference, please consider the following sections: + +* [Official Gradle documentation](https://docs.gradle.org) +* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/3.5.10/gradle-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/3.5.10/gradle-plugin/packaging-oci-image.html) +* [Spring Web](https://docs.spring.io/spring-boot/3.5.10/reference/web/servlet.html) + +### Guides + +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) + +### Additional Links + +These additional references should also help you: + +* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) + 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..5cb5983c1 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/DiscodeitApplication.java @@ -0,0 +1,51 @@ +package com.sprint.mission.discodeit;//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 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.boot.SpringApplication; +//import org.springframework.boot.autoconfigure.SpringBootApplication; +//import org.springframework.context.ConfigurableApplicationContext; +// +//@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("메시지 생성: [" + author.getUsername() + "] " + message.getContent()); +// } +// +// public static void main(String[] args) { +// ConfigurableApplicationContext context = SpringApplication.run(DiscodeitApplication.class, args); +// +// // 서비스 초기화 +// UserService userService = context.getBean(UserService.class); +// ChannelService channelService = context.getBean(ChannelService.class); +// MessageService messageService = context.getBean(MessageService.class); +// +// // 셋업 +// 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 e1acae4f5..2392c9167 100644 --- a/src/main/java/com/sprint/mission/discodeit/JavaApplication.java +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -1,366 +1,38 @@ -package com.sprint.mission.discodeit; - -import com.sprint.mission.discodeit.entity.Channel; -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 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.List; -import java.util.UUID; - -public class JavaApplication { - public static void main(String[] args) { - System.out.println("========== 디스코드잇 서비스 테스트 시작 ==========\n"); - - UserService userService = new JCFUserService(); - ChannelService channelService = new JCFChannelService(userService); - MessageService messageService = new JCFMessageService(userService, channelService); - - // ========== User 기능 테스트 ========== - System.out.println("========== User 기능 테스트 ==========\n"); - - // 유저 생성 - System.out.println(">> 유저 생성 테스트"); - User user1 = userService.createUser("임지호", "1234", "jiho@codeit.com"); - User user2 = userService.createUser("홍길동", "5678", "hong@codeit.com"); - User user3 = userService.createUser("김철수", "abcd", "kim@codeit.com"); - UUID user1Id = user1.getId(); - UUID user2Id = user2.getId(); - UUID user3Id = user3.getId(); - - System.out.println("\n------------------------------------------\n"); - - // 유저 단건 조회 - System.out.println(">> 유저 단건 조회 테스트"); - User foundUser1 = userService.findUserById(user1Id); - System.out.println("조회된 유저: " + foundUser1.getUsername()); - - User foundUser2 = userService.findUserById(user2Id); - System.out.println("조회된 유저: " + foundUser2.getUsername()); - - User foundUser3 = userService.findUserById(user3Id); - System.out.println("조회된 유저: " + foundUser3.getUsername()); - - System.out.println("\n------------------------------------------\n"); - - // 유저 전체 조회 - System.out.println(">> 유저 전체 조회 테스트"); - List allUsers = userService.findAllUsers(); - System.out.println("총 유저 수: " + allUsers.size() + "명"); - for (User u : allUsers) { - System.out.println("- " + u.getUsername() + " (" + u.getEmail() + ")"); - } - - System.out.println("\n------------------------------------------\n"); - - // 유저 정보 수정 - System.out.println(">> 유저 정보 수정 테스트"); - User updatedUser = userService.updateUserInfo(user1Id, "아임지호", "newjiho@codeit.com"); - System.out.println("수정된 유저: " + updatedUser); - - System.out.println("\n------------------------------------------\n"); - - // 유저 비밀번호 변경 - System.out.println(">> 유저 비밀번호 변경 테스트"); - updatedUser = userService.changePassword(user1Id, "newpass1234"); - System.out.println("비밀번호 변경 완료: " + updatedUser.getPassword()); - - System.out.println("\n------------------------------------------\n"); - - // 유저 정보 수정 검증 테스트 - System.out.println(">> 유저 정보 수정 검증 테스트"); - System.out.println("둘 다 null인 경우:"); - try { - userService.updateUserInfo(user2Id, null, null); - } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); - } - - System.out.println("\n이름에 공백 포함:"); - try { - userService.updateUserInfo(user2Id, "홍 길동", "test@test.com"); - } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); - } - - System.out.println("\n이메일 형식 오류:"); - try { - userService.updateUserInfo(user2Id, "홍길동", "invalidemail"); - } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); - } - - System.out.println("\n정상 수정:"); - userService.updateUserInfo(user2Id, "뉴홍길동", "newhong@codeit.com"); - - - System.out.println("\n========== Channel 기능 테스트 ==========\n"); - - // 채널 생성 - System.out.println(">>채널 생성 테스트"); - Channel channel1 = channelService.createChannel("본방"); - Channel channel2 = channelService.createChannel("공지방"); - Channel channel3 = channelService.createChannel("수다방"); - UUID channel1Id = channel1.getId(); - UUID channel2Id = channel2.getId(); - UUID channel3Id = channel3.getId(); - - System.out.println("\n------------------------------------------\n"); - - // 채널 단건 조회 - System.out.println(">>채널 단건 조회 테스트"); - Channel foundChannel = channelService.findChannelByChannelId(channel1Id); - System.out.println("조회된 채널: " + foundChannel.getChannelName()); - - System.out.println("\n------------------------------------------\n"); - - // 채널 전체 조회 - System.out.println(">>채널 전체 조회 테스트"); - List allChannels = channelService.findAllChannels(); - System.out.println("총 채널 수: " + allChannels.size() + "개"); - for (Channel c : allChannels) { - System.out.println("- " + c.getChannelName()); - } - - System.out.println("\n------------------------------------------\n"); - - // 채널 수정 - System.out.println(">>채널 수정 테스트"); - Channel updatedChannel = channelService.updateChannel(channel1Id, "메인방"); - System.out.println("변경된 채널명: " + updatedChannel.getChannelName()); - - System.out.println("\n------------------------------------------\n"); - - // 채널 입장 - System.out.println(">>채널 입장 테스트"); - channelService.joinChannel(user1Id, channel1Id); - channelService.joinChannel(user2Id, channel1Id); - channelService.joinChannel(user3Id, channel1Id); - - channelService.joinChannel(user1Id, channel2Id); - channelService.joinChannel(user2Id, channel2Id); - - System.out.println("\n------------------------------------------\n"); - - // 중복 입장 테스트 - System.out.println(">>중복 입장 방지 테스트"); - try { - channelService.joinChannel(user1Id, channel1Id); - } catch (IllegalArgumentException e) { - System.out.println("에러 발생: " + e.getMessage()); - } - - System.out.println("\n------------------------------------------\n"); - - // 채널 퇴장 - System.out.println(">> 채널 퇴장 테스트"); - - channelService.leaveChannel(user1Id, channel1Id); - - // 채널의 참가자 리스트에서 빠졌는지 확인 - List participantsAfterLeave = userService.findParticipants(channel1Id); - System.out.println("퇴장 후 [" + updatedChannel.getChannelName() + "] 참가자 수: " - + participantsAfterLeave.size() + "명"); - - // 유저의 채널 리스트에서 빠졌는지 확인 - System.out.println(user1.getUsername() + "님의 현재 참여 채널 수: " - + user1.getMyChannels().size() + "개"); - - // 참여하지 않은 방에서 또 나가려고 할 때 - System.out.println("\n>> 참여하지 않은 채널 퇴장 시도"); - try { - channelService.leaveChannel(user1Id, channel1Id); - } catch (IllegalArgumentException e) { - System.out.println("✅에러 캐치 성공: " + e.getMessage()); - } - - System.out.println("\n------------------------------------------\n"); - - // 채널 참가자 조회 - System.out.println(">>채널 참가자 조회 테스트"); - List participants = userService.findParticipants(channel1Id); - System.out.println("[" + updatedChannel.getChannelName() + "] 참가자 수: " + participants.size() + "명"); - for (User p : participants) { - System.out.println("- " + p.getUsername() + " (" + p.getEmail() + ")"); - } - - System.out.println("\n------------------------------------------\n"); - - // 특정 유저가 속해있는 채널 - System.out.println(">>특정 유저가 속해있는 채널 조회"); - List userChannels = channelService.findChannelByUserId(user1Id); - User testUser = userService.findUserById(user1Id); - - System.out.println(testUser.getUsername() + "님이 참여 중인 채널:"); - for (Channel c : userChannels) { - System.out.println("- " + c.getChannelName()); - } - - - System.out.println("\n========== Message 기능 테스트 ==========\n"); - - // 메시지 생성 - System.out.println(">> 메시지 생성"); - Message msg1 = messageService.createMessage("안녕하세요! 지호입니다.", channel1Id, user1Id); - Message msg2 = messageService.createMessage("반갑습니다~ 길동이에요.", channel1Id, user2Id); - Message msg3 = messageService.createMessage("오늘 점심 뭐 드실래요?", channel1Id, user2Id); - Message msg4 = messageService.createMessage("저는 김철수입니다.", channel1Id, user3Id); - - Message msg5 = messageService.createMessage("공지사항입니다.", channel2Id, user1Id); - Message msg6 = messageService.createMessage("확인했습니다.", channel2Id, user2Id); - - UUID msg1Id = msg1.getId(); - UUID msg2Id = msg2.getId(); - - System.out.println("\n------------------------------------------\n"); - - // 메시지 단건 조회 - System.out.println(">>메시지 단건 조회 테스트"); - Message foundMessage = messageService.findMessageById(msg1Id); - System.out.println("조회된 메시지: " + foundMessage.getContent()); - - System.out.println("\n------------------------------------------\n"); - - // 메시지 전체 조회 - System.out.println(">>메시지 전체 조회 테스트"); - List allMessages = messageService.findAllMessages(); - System.out.println("전체 메시지 수: " + allMessages.size() + "개"); - - System.out.println("\n------------------------------------------\n"); - - // 특정 채널의 메시지 조회 - System.out.println(">>특정 채널의 메시지 조회 테스트"); - List channelMessages = messageService.findMessagesByChannelId(channel1Id); - System.out.println("[" + updatedChannel.getChannelName() + "] 메시지 수: " + channelMessages.size() + "개"); - for (Message m : channelMessages) { - System.out.println("- " + m.getUser().getUsername() + ": " + m.getContent()); - } - - System.out.println("\n------------------------------------------\n"); - - // 특정 유저의 메시지 조회 - System.out.println(">>특정 유저의 메시지 조회 테스트"); - List userMessages = messageService.findMessagesByUserId(user2Id); - User msgUser = userService.findUserById(user2Id); - - System.out.println(msgUser.getUsername() + "님의 메시지 수: " + userMessages.size() + "개"); - for (Message m : userMessages) { - System.out.println("📝 내용: " + m.getContent() + " | 채널: " + m.getChannel().getChannelName()); - } - - - System.out.println("\n------------------------------------------\n"); - - // 메시지 수정 - System.out.println(">>메시지 수정 테스트"); - Message updatedMessage = messageService.updateMessage(msg1Id, "메시지를 잘못 보내서 수정했어요"); - System.out.println("수정된 메시지: " + updatedMessage.getContent()); - - System.out.println("\n------------------------------------------\n"); - - // 메시지 삭제 - System.out.println(">>메시지 삭제 테스트"); - messageService.deleteMessage(msg2Id); - - System.out.println("\n삭제 후 채널 메시지 확인:"); - channelMessages = messageService.findMessagesByChannelId(channel1Id); - System.out.println("현재 메시지 수: " + channelMessages.size() + "개"); - - System.out.println("\n------------------------------------------\n"); - - // 특정 유저가 작성한 메시지 열람 - System.out.println(">>작성한 메시지 열람"); - User testUser2 = userService.findUserById(user1Id); - System.out.println(testUser2.getUsername() + "님이 작성한 메시지:"); - for (Message m : testUser2.getMyMessages()) { - System.out.println("- " + m.getContent()); - } - - - System.out.println("\n====================\n"); - - // 유저 삭제 - System.out.println(">>유저 삭제 테스트"); - System.out.println("삭제 전 [" + updatedChannel.getChannelName() + "] 참가자 수: " - + userService.findParticipants(channel1Id).size() + "명"); - - userService.deleteUser(user3Id); - - System.out.println("삭제 후 [" + updatedChannel.getChannelName() + "] 참가자 수: " - + userService.findParticipants(channel1Id).size() + "명"); - - participants = userService.findParticipants(channel1Id); - System.out.println("현재 참가자:"); - for (User p : participants) { - System.out.println("- " + p.getUsername()); - } - - System.out.println("\n------------------------------------------\n"); - - // 채널 삭제 - System.out.println(">>채널 삭제 테스트"); - List channelsBeforeDelete = channelService.findChannelByUserId(user1Id); - User testUser3 = userService.findUserById(user1Id); - System.out.println("삭제 전 " + testUser3.getUsername() + "님의 참여 채널 수: " - + channelsBeforeDelete.size() + "개"); - - channelService.deleteChannel(channel2Id); - - // 삭제 후 유저 다시 조회 (채널 리스트 갱신 확인) - List channelsAfterDelete = channelService.findChannelByUserId(user1Id); - testUser3 = userService.findUserById(user1Id); - System.out.println("삭제 후 " + testUser3.getUsername() + "님의 참여 채널 수: " - + channelsAfterDelete.size() + "개"); - System.out.println("현재 참여 채널:"); - for (Channel c : channelsAfterDelete) { - System.out.println("- " + c.getChannelName()); - } - - - System.out.println("\n------------------------------------------\n"); - - // 존재하지 않는 데이터 조회 시 에러 처리 (Service가 예외를 던지는지 확인) - System.out.println(">> 존재하지 않는 데이터 조회 테스트"); - try { - userService.findUserById(user3Id); // 이미 삭제된 유저 - } catch (IllegalArgumentException e) { - System.out.println("✅ 에러 캐치 성공: " + e.getMessage()); - } - - try { - channelService.findChannelByChannelId(channel2Id); // 이미 삭제된 채널 - } catch (IllegalArgumentException e) { - System.out.println("✅ 에러 캐치 성공: " + e.getMessage()); - } - - - // 최종 상태 - System.out.println("\n========== 최종 상태 확인 ==========\n"); - - System.out.println(">> 남아있는 유저:"); - allUsers = userService.findAllUsers(); - for (User u : allUsers) { - System.out.println("- " + u.getUsername() + " (채널 " + u.getMyChannels().size() - + "개 참여, 메시지 " + u.getMyMessages().size() + "개 작성)"); - } - - System.out.println("\n>> 남아있는 채널:"); - allChannels = channelService.findAllChannels(); - for (Channel c : allChannels) { - System.out.println("- " + c.getChannelName() + " (참가자 " - + userService.findParticipants(c.getId()).size() + "명, 메시지 " - + c.getChannelMessages().size() + "개)"); - } - - System.out.println("\n>> 남아있는 메시지:"); - allMessages = messageService.findAllMessages(); - System.out.println("총 메시지 수: " + allMessages.size() + "개"); - - System.out.println("\n========== 모든 테스트 종료 =========="); - } -} \ No newline at end of file +package com.sprint.mission.discodeit;//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.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.basic.BasicChannelService; +//import com.sprint.mission.discodeit.service.basic.BasicMessageService; +//import com.sprint.mission.discodeit.service.basic.BasicUserService; +// +//public class JavaApplication { +// public static void main(String[] args) { +// // 레포지토리 초기화 +// UserRepository userRepository = new FileUserRepository(); +// ChannelRepository channelRepository = new FileChannelRepository(); +// MessageRepository messageRepository = new FileMessageRepository(); +// +// // 서비스 초기화 +// UserService userService = new BasicUserService(userRepository); +// ChannelService channelService = new BasicChannelService(channelRepository); +// MessageService messageService = new BasicMessageService(messageRepository, channelRepository, userRepository); +// +// // 셋업 +// User user = setupUser(userService); +// Channel channel = setupChannel(channelService); +// // 테스트 +// messageCreateTest(messageService, channel, user); +// } +//} diff --git a/src/main/java/com/sprint/mission/discodeit/dto/AuthDto.java b/src/main/java/com/sprint/mission/discodeit/dto/AuthDto.java new file mode 100644 index 000000000..2cc77bd3f --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/dto/AuthDto.java @@ -0,0 +1,8 @@ +package com.sprint.mission.discodeit.dto; + +public class AuthDto { + public record LoginRequest( + String username, + String password + ) {} +} diff --git a/src/main/java/com/sprint/mission/discodeit/dto/BinaryContentDto.java b/src/main/java/com/sprint/mission/discodeit/dto/BinaryContentDto.java new file mode 100644 index 000000000..a4e0808f6 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/dto/BinaryContentDto.java @@ -0,0 +1,19 @@ +package com.sprint.mission.discodeit.dto; + +import java.util.UUID; + +public class BinaryContentDto { + public record CreateRequest( + byte[] bytes, + String contentType, + String fileName + ){} + + public record Response( + UUID id, + byte[] bytes, + String contentType, + String fileName + ){} + +} diff --git a/src/main/java/com/sprint/mission/discodeit/dto/ChannelDto.java b/src/main/java/com/sprint/mission/discodeit/dto/ChannelDto.java new file mode 100644 index 000000000..3bee70451 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/dto/ChannelDto.java @@ -0,0 +1,34 @@ +package com.sprint.mission.discodeit.dto; + +import com.sprint.mission.discodeit.entity.ChannelType; +import lombok.Builder; + +import java.time.Instant; +import java.util.List; +import java.util.UUID; + +public class ChannelDto { + public record CreateRequest( + ChannelType type, + String name, + String description + ) {} + + + @Builder + public record Response( + UUID id, + ChannelType type, + String name, + String description, + Instant lastMessageAt, + List memberIdList + + ) {} + + public record UpdateRequest ( + UUID channelId, + String newName, + String newDescription + ) {} +} diff --git a/src/main/java/com/sprint/mission/discodeit/dto/MessageDto.java b/src/main/java/com/sprint/mission/discodeit/dto/MessageDto.java new file mode 100644 index 000000000..7f9e9b132 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/dto/MessageDto.java @@ -0,0 +1,37 @@ +package com.sprint.mission.discodeit.dto; + +import lombok.Builder; + +import java.util.List; +import java.util.UUID; + +public class MessageDto { + public record CreateRequest( + String content, + UUID channelId, + UUID authorId, + List attachments // 첨부파일(선택) + ) {} + + public record BinaryContentDto ( + byte[] data, + String fileType, + String fileName + ) {} + + + @Builder + public record Response( + UUID id, + UUID channelId, + UUID authorId, + String content, + List attachmentId + ) {} + + public record UpdateRequest ( + UUID id, + String content, + List attachments + ) {} +} diff --git a/src/main/java/com/sprint/mission/discodeit/dto/ReadStatusDto.java b/src/main/java/com/sprint/mission/discodeit/dto/ReadStatusDto.java new file mode 100644 index 000000000..4f27dd7b8 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/dto/ReadStatusDto.java @@ -0,0 +1,25 @@ +package com.sprint.mission.discodeit.dto; + +import java.time.Instant; +import java.util.UUID; + +public class ReadStatusDto { + public record CreateRequest( + UUID userId, + UUID channelId + ){} + + public record Response( + UUID id, + UUID userId, + UUID channelId, + UUID lastMessageReadId, + Instant updatedAt + + ){} + + public record UpdateRequest( + UUID id, + UUID lastReadMessageId + ){} +} diff --git a/src/main/java/com/sprint/mission/discodeit/dto/UserDto.java b/src/main/java/com/sprint/mission/discodeit/dto/UserDto.java new file mode 100644 index 000000000..4d751b2d4 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/dto/UserDto.java @@ -0,0 +1,37 @@ +package com.sprint.mission.discodeit.dto; + +import lombok.Builder; + +import java.util.UUID; + +public class UserDto { + public record CreateRequest( + String username, + String email, + String password, + BinaryContentDto profileImage + ) {} + + public record BinaryContentDto ( + byte[] data, + String fileType, + String fileName + ) {} + + @Builder + public record Response( + UUID id, + String username, + String email, + boolean isOnline, + UUID profileImageId + ) {} + + public record UpdateRequest ( + UUID id, + String username, + String email, + String password, + BinaryContentDto profileImage + ) {} +} diff --git a/src/main/java/com/sprint/mission/discodeit/dto/UserStatusDto.java b/src/main/java/com/sprint/mission/discodeit/dto/UserStatusDto.java new file mode 100644 index 000000000..c7a160b39 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/dto/UserStatusDto.java @@ -0,0 +1,22 @@ +package com.sprint.mission.discodeit.dto; + +import java.time.Instant; +import java.util.UUID; + +public class UserStatusDto { + public record CreateRequest( + UUID userId + ){} + + public record Response( + UUID id, + UUID userId, + Instant updatedAt, + boolean isOnline + ){} + + public record UpdateRequest( + UUID id, + UUID userId + ){} +} diff --git a/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java b/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java index 023c5f085..ac38adefc 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/BaseEntity.java @@ -1,32 +1,26 @@ package com.sprint.mission.discodeit.entity; +import lombok.AllArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.io.Serializable; +import java.time.Instant; import java.util.UUID; -public class BaseEntity { - private UUID id; - private Long createdAt; - private Long updatedAt; +@SuperBuilder +@AllArgsConstructor +public abstract class BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + protected final UUID id; + protected final Instant createdAt; public BaseEntity() { this.id = UUID.randomUUID(); - this.createdAt = System.currentTimeMillis(); - this.updatedAt = System.currentTimeMillis(); - } - - public Long getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Long updatedAt) { - this.updatedAt = updatedAt; - } - - public Long getCreatedAt() { - return createdAt; + this.createdAt = Instant.now(); } - public UUID getId() { - return id; - } + // 공통 Getter + public UUID getId() { return id; } + public Instant getCreatedAt() { return createdAt; } } 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..5989e3fb3 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/BinaryContent.java @@ -0,0 +1,20 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; + +import java.time.Instant; +import java.util.UUID; + +@Getter +public class BinaryContent extends BaseEntity{ + private final byte[] bytes; + private final String contentType; // 예: image/png, application/pdf + private final String fileName; + + public BinaryContent(byte[] bytes, String contentType, String fileName) { + super(); + this.bytes = bytes; + this.contentType = contentType; + this.fileName = fileName; + } +} 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 b9c914606..ea4ac80a7 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/Channel.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/Channel.java @@ -1,39 +1,40 @@ package com.sprint.mission.discodeit.entity; -import java.util.ArrayList; -import java.util.List; - -public class Channel extends BaseEntity{ - private String channelName; - private List participants = new ArrayList<>(); - private List channelMessages = new ArrayList<>(); - - public String getChannelName() { - return channelName; - } - - public void updateChannelInfo(String newChannelName){ - this.channelName = newChannelName; - super.setUpdatedAt(System.currentTimeMillis()); - } - - public List getParticipants() { - return participants; - } - - public void addParticipant(User user){ - this.participants.add(user); - } - - public List getChannelMessages() { - return channelMessages; - } - - public void addMessage(Message message){ - this.channelMessages.add(message); +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.time.Instant; +import java.util.UUID; + +@Getter +@Setter +public class Channel extends BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + private Instant updatedAt; + private ChannelType type; + private String name; + private String description; + + public Channel(ChannelType type, String name, String description) { + this.type = type; + this.name = name; + this.description = description; } - public Channel(String channelName) { - this.channelName = channelName; + public void update(String newName, String newDescription) { + boolean anyValueUpdated = false; + if (newName != null && !newName.equals(this.name)) { + this.name = newName; + anyValueUpdated = true; + } + if (newDescription != null && !newDescription.equals(this.description)) { + this.description = newDescription; + anyValueUpdated = true; + } + + if (anyValueUpdated) { + this.updatedAt = Instant.now(); + } } } 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/Message.java b/src/main/java/com/sprint/mission/discodeit/entity/Message.java index f5d234d41..61ce1d783 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/Message.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/Message.java @@ -1,34 +1,56 @@ package com.sprint.mission.discodeit.entity; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.io.Serializable; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import java.util.UUID; -public class Message extends BaseEntity{ +@Getter +@Builder +@AllArgsConstructor +public class Message extends BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; + private Instant updatedAt; + // private String content; - private Channel channel; - private User user; + // + private UUID channelId; + private UUID authorId; + private List attachmentIds; - public User getUser() { - return user; - } - - public Channel getChannel() { - return channel; - } - - public String getContent() { - return content; - } - - public void updateContent(String newContent){ - this.content = newContent; - super.setUpdatedAt(System.currentTimeMillis()); - } - - public Message(String content, Channel channel, User user) { + public Message(String content, UUID channelId, UUID authorId, List attachmentId) { this.content = content; - this.channel = channel; - this.user = user; + this.channelId = channelId; + this.authorId = authorId; + this.attachmentIds = (attachmentId!= null) ? attachmentId: new ArrayList<>(); // 내용을 받지 않았을 때에는 빈 리스트로 초기화 } - + public void update(String newContent, List newAttachmentIds) { + boolean[] isUpdated = {false}; + + Optional.ofNullable(newContent) + .filter(c -> !c.equals(this.content)) + .ifPresent(c -> { + this.content = c; + isUpdated[0] = true; + }); + + Optional.ofNullable(newAttachmentIds) + .filter(ids -> !ids.equals(this.attachmentIds)) + .ifPresent(ids -> { + this.attachmentIds = ids; + isUpdated[0] = true; + }); + + // 하나라도 바뀌었으면 시간 갱신 + if (isUpdated[0]) { + this.updatedAt = Instant.now(); + } + } } 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..eb84ecea4 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/ReadStatus.java @@ -0,0 +1,29 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; + +import java.time.Instant; +import java.util.Optional; +import java.util.UUID; + +@Getter +public class ReadStatus extends BaseEntity { + private final UUID userId; + private final UUID channelId; + private Instant updatedAt; + private UUID lastReadMessageId; + + public ReadStatus(UUID userId, UUID channelId) { + this.userId = userId; + this.channelId = channelId; + } + + public void updateLastReadMessage(UUID lastReadMessageId) { + Optional.ofNullable(lastReadMessageId) + .filter(id -> !id.equals(this.lastReadMessageId)) + .ifPresent(id -> { + this.lastReadMessageId = id; + this.updatedAt = Instant.now(); + }); + } +} 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 c81b4df01..d64313e2c 100644 --- a/src/main/java/com/sprint/mission/discodeit/entity/User.java +++ b/src/main/java/com/sprint/mission/discodeit/entity/User.java @@ -1,62 +1,35 @@ package com.sprint.mission.discodeit.entity; -import java.util.ArrayList; -import java.util.List; +import lombok.Getter; +import lombok.Setter; -public class User extends BaseEntity { - private String username; - private String password; - private String email; - private List myChannels = new ArrayList<>(); - private List myMessages = new ArrayList<>(); - - public String getUsername() { - return username; - } - - public String getPassword() { - return password; - } - - public String getEmail() { - return email; - } - - public void updateUsername(String newUsername){ - this.username = newUsername; - this.setUpdatedAt(System.currentTimeMillis()); - } +import java.io.Serializable; +import java.time.Instant; +import java.util.Optional; +import java.util.UUID; - public void updateEmail(String newEmail){ - this.email = newEmail; - this.setUpdatedAt(System.currentTimeMillis()); - } - - public void updatePassword(String newPassword){ - this.password = newPassword; - this.setUpdatedAt(System.currentTimeMillis()); - } +@Getter +@Setter +public class User extends BaseEntity implements Serializable { + private static final long serialVersionUID = 1L; - public List getMyMessages() { - return myMessages; - } + private Instant updatedAt; - public List getMyChannels() { - return myChannels; - } + private String username; + private String email; + private String password; - public void addMessage(Message message){ - this.myMessages.add(message); - } + private UUID profileImageId; - public User(String username, String password, String email) { + public User(String username, String email, String password) { this.username = username; - this.password = password; this.email = email; + this.password = password; } - @Override - public String toString() { - return "이름: " + username + ", 이메일: " + email + ", 비밀번호: " + password; + public void update(String newUsername, String newEmail, String newPassword) { + Optional.ofNullable(newUsername).filter(s -> !s.isBlank()).ifPresent(this::setUsername); + Optional.ofNullable(newEmail).filter(s -> !s.isBlank()).ifPresent(this::setEmail); + Optional.ofNullable(newPassword).filter(s -> !s.isBlank()).ifPresent(this::setPassword); } } 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..4991751c7 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/UserStatus.java @@ -0,0 +1,27 @@ +package com.sprint.mission.discodeit.entity; + +import lombok.Getter; + +import java.time.Instant; +import java.util.UUID; + +@Getter +public class UserStatus extends BaseEntity { + private final UUID userId; + private Instant updatedAt; + + public UserStatus(UUID userId) { + this.userId = userId; + } + + // 5분 이내 접속 여부 판단 메소드 + public boolean isOnline() { + // 현재 시간 - 5분(300초) 이후 접속했다면 true + return updatedAt.isAfter(Instant.now().minusSeconds(300)); + } + + public void updateActiveTime() { + this.updatedAt = Instant.now(); + } + +} 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..03c42f422 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/BinaryContentRepository.java @@ -0,0 +1,21 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface BinaryContentRepository { + BinaryContent save(BinaryContent binaryContent); + + Optional findById(UUID id); + List findAllById(List idList); + + boolean existsById(UUID id); + + void deleteById(UUID id); + void deleteAllById(List idList); +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java new file mode 100644 index 000000000..c8b9faa77 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/ChannelRepository.java @@ -0,0 +1,17 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface ChannelRepository { + Channel save(Channel channel); + Optional findById(UUID id); + List findAll(); + boolean existsById(UUID id); + void deleteById(UUID id); + List findAllByType(ChannelType channelType); +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java new file mode 100644 index 000000000..a34ce4f0c --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/MessageRepository.java @@ -0,0 +1,22 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.Message; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface MessageRepository { + Message save(Message message); + + Optional findById(UUID id); + Optional findLastMessageOfChannel(UUID channelId); + + List findAll(); + List findAllByChannelId(UUID channelId); + + boolean existsById(UUID id); + + void deleteById(UUID id); + void deleteAllByChannelId(UUID channelId); +} 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..29b6bb9f1 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/ReadStatusRepository.java @@ -0,0 +1,27 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.entity.UserStatus; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface ReadStatusRepository { + ReadStatus save(ReadStatus readStatus); + Optional findById(UUID id); + + Optional findByUserAndChannelId(UUID userId, UUID channelId); + + void deleteById(UUID id); + void deleteAllByChannelId(UUID channelId); + public List findAll(); + + List findAllByChannelId(UUID channelId); + List findAllByUserId(UUID userId); + + boolean existsByChannelIdAndUserId(UUID channelId, UUID userId); + boolean existsById(UUID id); +} diff --git a/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java new file mode 100644 index 000000000..867ab1bf5 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/UserRepository.java @@ -0,0 +1,20 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.User; + +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(); + boolean existsById(UUID id); + void deleteById(UUID id); + + boolean usernameExistence(String username); + boolean emailExistence(String email); + + Optional findByUsername(String username); +} 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..cae485b96 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/UserStatusRepository.java @@ -0,0 +1,22 @@ +package com.sprint.mission.discodeit.repository; + +import com.sprint.mission.discodeit.entity.UserStatus; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface UserStatusRepository { + UserStatus save(UserStatus userStatus); + + boolean existsByUserId(UUID userId); + boolean existsById(UUID id); + + Optional findById(UUID id); + Optional findByUserId(UUID userId); + List findAll(); + + void deleteById(UUID id); +} 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..eb01deaa9 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileBinaryContentRepository.java @@ -0,0 +1,117 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileBinaryContentRepository implements BinaryContentRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileBinaryContentRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + 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(e); + } + } + } + + private Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); + } + + @Override + public BinaryContent save(BinaryContent binaryContent) { + Path path = resolvePath(binaryContent.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(binaryContent); + } catch (IOException e) { + throw new RuntimeException(e); + } + return binaryContent; + } + + @Override + public Optional findById(UUID id) { + BinaryContent binaryContentNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + binaryContentNullable = (BinaryContent) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + return Optional.ofNullable(binaryContentNullable); + } + + @Override + public List findAllById(List idList) { + return idList.stream() + .map(this::resolvePath) + .filter(Files::exists) + .map(path -> { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + return (BinaryContent) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } + + @Override + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deleteAllById(List idList) { + idList.forEach(id -> { + Path path = resolvePath(id); + try { + Files.deleteIfExists(path); + } catch (IOException e) { + throw new RuntimeException("파일 삭제 실패: " + id, 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 new file mode 100644 index 000000000..90ef855e9 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileChannelRepository.java @@ -0,0 +1,116 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileChannelRepository implements ChannelRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileChannelRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + 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 Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); + } + + @Override + public Channel save(Channel channel) { + Path path = resolvePath(channel.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(channel); + } catch (IOException e) { + throw new RuntimeException(e); + } + return channel; + } + + @Override + 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 Optional.ofNullable(channelNullable); + } + + @Override + public List findAll() { + 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 boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public List findAllByType(ChannelType channelType) { + return findAll().stream() + .filter(channel -> channel.getType().equals(channelType)) + .toList(); + } +} 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 new file mode 100644 index 000000000..9c2c40342 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileMessageRepository.java @@ -0,0 +1,165 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.repository.MessageRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileMessageRepository implements MessageRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileMessageRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + 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 Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); + } + + @Override + public Message save(Message message) { + Path path = resolvePath(message.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(message); + } catch (IOException e) { + throw new RuntimeException(e); + } + return message; + } + + @Override + 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 Optional.ofNullable(messageNullable); + } + + @Override + public Optional findLastMessageOfChannel(UUID channelId) { + 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); + } + }) + .filter(message -> message.getChannelId().equals(channelId)) + .sorted(Comparator.comparing(Message::getCreatedAt).reversed()) + .findFirst(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public List findAll() { + 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 List findAllByChannelId(UUID channelId) { + return findAll().stream() + .filter(message -> message.getChannelId().equals(channelId)) + .toList(); + } + + @Override + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deleteAllByChannelId(UUID channelId) { + try { + Files.list(DIRECTORY) + .filter(path -> path.toString().endsWith(EXTENSION)) + .forEach(path -> { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + Message message = (Message) ois.readObject(); + if (message.getChannelId().equals(channelId)) { + ois.close(); + fis.close(); + Files.delete(path); + } + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException("파일 삭제 중 오류 발생: " + path, e); + } + }); + } 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..b1860eac9 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileReadStatusRepository.java @@ -0,0 +1,162 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileReadStatusRepository implements ReadStatusRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileReadStatusRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + this.DIRECTORY = Paths.get(System.getProperty("user.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); + } + + @Override + public ReadStatus save(ReadStatus readStatus) { + Path path = resolvePath(readStatus.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(readStatus); + } catch (IOException e) { + throw new RuntimeException(e); + } + return readStatus; + } + + @Override + public Optional findById(UUID id) { + ReadStatus readStatusNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + readStatusNullable = (ReadStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + return Optional.ofNullable(readStatusNullable); + } + + @Override + public Optional findByUserAndChannelId(UUID userId, UUID channelId) { + return findAll().stream() + .filter(readStatus -> readStatus.getUserId().equals(userId) && readStatus.getChannelId().equals(channelId)) + .findFirst(); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void deleteAllByChannelId(UUID channelId) { + try { + Files.list(DIRECTORY) + .filter(path -> path.toString().endsWith(EXTENSION)) + .forEach(path -> { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + Message message = (Message) ois.readObject(); + if (message.getChannelId().equals(channelId)) { + ois.close(); + fis.close(); + Files.delete(path); + } + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException("파일 삭제 중 오류 발생: " + path, e); + } + }); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + + @Override + public List findAll() { + 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 (ReadStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public List findAllByChannelId(UUID channelId) { + return findAll().stream() + .filter(readStatus -> readStatus.getChannelId().equals(channelId)) + .toList(); + } + + @Override + public List findAllByUserId(UUID userId) { + return findAll().stream() + .filter(readStatus -> readStatus.getChannelId().equals(userId)) + .toList(); + } + + @Override + public boolean existsByChannelIdAndUserId(UUID channelId, UUID userId) { + return findByUserAndChannelId(userId, channelId).isPresent(); + } + + @Override + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..42618daa0 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserRepository.java @@ -0,0 +1,127 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.repository.UserRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileUserRepository implements UserRepository { + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileUserRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + 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 Path resolvePath(UUID id) { + return DIRECTORY.resolve(id + EXTENSION); + } + + @Override + public User save(User user) { + Path path = resolvePath(user.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(user); + } catch (IOException e) { + throw new RuntimeException(e); + } + return user; + } + + @Override + 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 Optional.ofNullable(userNullable); + } + + @Override + public List findAll() { + 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 boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public void deleteById(UUID id) { + Path path = resolvePath(id); + try { + Files.delete(path); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean usernameExistence(String username) { + return findAll().stream() + .anyMatch(user -> user.getUsername().equals(username)); + } + + @Override + public boolean emailExistence(String email) { + return findAll().stream() + .anyMatch(user -> user.getEmail().equals(email)); + } + + @Override + public Optional findByUsername(String username) { + return findAll().stream() + .filter(user -> user.getUsername().equals(username)) + .findFirst(); + } +} 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..5762b2e68 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/file/FileUserStatusRepository.java @@ -0,0 +1,133 @@ +package com.sprint.mission.discodeit.repository.file; + +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.repository.UserStatusRepository; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +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.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "file" +) +public class FileUserStatusRepository implements UserStatusRepository { + + private final Path DIRECTORY; + private final String EXTENSION = ".ser"; + + public FileUserStatusRepository(@Value("${discodeit.repository.file-directory:file-data-map}") String baseDirectory) { + this.DIRECTORY = Paths.get(System.getProperty("user.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); + } + + @Override + public UserStatus save(UserStatus userStatus) { + Path path = resolvePath(userStatus.getId()); + try ( + FileOutputStream fos = new FileOutputStream(path.toFile()); + ObjectOutputStream oos = new ObjectOutputStream(fos) + ) { + oos.writeObject(userStatus); + } catch (IOException e) { + throw new RuntimeException(e); + } + return userStatus; + } + + @Override + public boolean existsByUserId(UUID userId) { + Path path = resolvePath(userId); + return Files.exists(path); + } + + @Override + public boolean existsById(UUID id) { + Path path = resolvePath(id); + return Files.exists(path); + } + + @Override + public Optional findById(UUID id) { + UserStatus userStatusNullable = null; + Path path = resolvePath(id); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + userStatusNullable = (UserStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + return Optional.ofNullable(userStatusNullable); + } + + @Override + public Optional findByUserId(UUID userId) { + UserStatus userStatusNullable = null; + Path path = resolvePath(userId); + if (Files.exists(path)) { + try ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + userStatusNullable = (UserStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException 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 ( + FileInputStream fis = new FileInputStream(path.toFile()); + ObjectInputStream ois = new ObjectInputStream(fis) + ) { + return (UserStatus) ois.readObject(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + }) + .toList(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + 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/jcf/JCFBinaryContentRepository.java b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java new file mode 100644 index 000000000..d6e5b4a2a --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFBinaryContentRepository.java @@ -0,0 +1,55 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFBinaryContentRepository implements BinaryContentRepository { + private final Map data; + + public JCFBinaryContentRepository() { + this.data = new HashMap<>(); + } + + @Override + public BinaryContent save(BinaryContent binaryContent) { + this.data.put(binaryContent.getId(), binaryContent); + return binaryContent; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public List findAllById(List idList) { + return data.values().stream() + .filter(binaryContent -> idList.contains(binaryContent.getId())) + .toList(); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public void deleteAllById(List idList) { + data.values().removeIf(binaryContent -> idList.contains(binaryContent.getId())); + + } +} 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 new file mode 100644 index 000000000..785fac572 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFChannelRepository.java @@ -0,0 +1,55 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFChannelRepository implements ChannelRepository { + private final Map data; + + public JCFChannelRepository() { + this.data = new HashMap<>(); + } + + @Override + public Channel save(Channel channel) { + this.data.put(channel.getId(), channel); + return channel; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public List findAllByType(ChannelType channelType) { + return data.values().stream() + .filter(channel -> channel.getType().equals(channelType)) + .toList(); + } +} 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 new file mode 100644 index 000000000..8f28c548f --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFMessageRepository.java @@ -0,0 +1,67 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.repository.MessageRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFMessageRepository implements MessageRepository { + private final Map data; + + public JCFMessageRepository() { + this.data = new HashMap<>(); + } + + @Override + public Message save(Message message) { + this.data.put(message.getId(), message); + return message; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public Optional findLastMessageOfChannel(UUID channelId) { + return data.values().stream() + .filter(message -> message.getChannelId().equals(channelId)) + .sorted(Comparator.comparing(Message::getCreatedAt).reversed()) + .findFirst(); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public List findAllByChannelId(UUID channelId) { + return data.values().stream() + .filter(message -> message.getChannelId().equals(channelId)) + .toList(); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public void deleteAllByChannelId(UUID channelId) { + data.values().removeIf(message -> message.getChannelId().equals(channelId)); + } +} 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..03db7eaec --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFReadStatusRepository.java @@ -0,0 +1,82 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFReadStatusRepository implements ReadStatusRepository { + + private final Map data; + public JCFReadStatusRepository() { + this.data = new HashMap<>(); + } + + @Override + public ReadStatus save(ReadStatus readStatus) { + this.data.put(readStatus.getId(), readStatus); + return readStatus; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public Optional findByUserAndChannelId(UUID userId, UUID channelId) { + return data.values().stream() + .filter(readStatus -> readStatus.getUserId().equals(userId)) + .filter(readStatus -> readStatus.getChannelId().equals(channelId)) + .findFirst(); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public void deleteAllByChannelId(UUID channelId) { + data.values().removeIf(readStatus -> readStatus.getChannelId().equals(channelId)); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public List findAllByChannelId(UUID channelId) { + return data.values().stream() + .filter(readStatus -> readStatus.getChannelId().equals(channelId)) + .toList(); + } + + @Override + public List findAllByUserId(UUID userId) { + return data.values().stream() + .filter(readStatus -> readStatus.getUserId().equals(userId)) + .toList(); + } + + @Override + public boolean existsByChannelIdAndUserId(UUID channelId, UUID userId) { + return data.values().stream() + .anyMatch(readStatus -> + readStatus.getUserId().equals(userId) && readStatus.getChannelId().equals(channelId) + ); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(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 new file mode 100644 index 000000000..3264d1e9d --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserRepository.java @@ -0,0 +1,66 @@ +package com.sprint.mission.discodeit.repository.jcf; + +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.repository.UserRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFUserRepository implements UserRepository { + private final Map data; + + public JCFUserRepository() { + this.data = new HashMap<>(); + } + + @Override + public User save(User user) { + this.data.put(user.getId(), user); + return user; + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } + + @Override + public boolean usernameExistence(String username) { + return data.values().stream() + .anyMatch(user -> user.getUsername().equals(username)); + } + + @Override + public boolean emailExistence(String email) { + return data.values().stream() + .anyMatch(user -> user.getEmail().equals(email)); + } + + @Override + public Optional findByUsername(String username) { + return data.values().stream() + .filter(user -> user.getUsername().equals(username)) + .findFirst(); + } +} 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..cfc8df1ef --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/repository/jcf/JCFUserStatusRepository.java @@ -0,0 +1,61 @@ +package com.sprint.mission.discodeit.repository.jcf; + + +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.repository.UserStatusRepository; +import com.sprint.mission.discodeit.service.UserStatusService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Repository; + +import java.util.*; + +@Repository +@ConditionalOnProperty( + name = "discodeit.repository.type", + havingValue = "jcf", + matchIfMissing = true +) +public class JCFUserStatusRepository implements UserStatusRepository { + private final Map data; + + public JCFUserStatusRepository() { + this.data = new HashMap<>(); + } + + + @Override + public UserStatus save(UserStatus userStatus) { + this.data.put(userStatus.getId(), userStatus); + return userStatus; + } + + @Override + public boolean existsByUserId(UUID userId) { + return this.data.containsKey(userId); + } + + @Override + public boolean existsById(UUID id) { + return this.data.containsKey(id); + } + + @Override + public Optional findById(UUID id) { + return Optional.ofNullable(this.data.get(id)); + } + + @Override + public Optional findByUserId(UUID userId) { + return Optional.ofNullable(this.data.get(userId)); + } + + @Override + public List findAll() { + return this.data.values().stream().toList(); + } + + @Override + public void deleteById(UUID id) { + this.data.remove(id); + } +} 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..d68baee7f --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/AuthService.java @@ -0,0 +1,8 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.AuthDto; +import com.sprint.mission.discodeit.dto.UserDto; + +public interface AuthService { + UserDto.Response login(AuthDto.LoginRequest request); +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/BinaryContentService.java b/src/main/java/com/sprint/mission/discodeit/service/BinaryContentService.java new file mode 100644 index 000000000..6a1341f0f --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/BinaryContentService.java @@ -0,0 +1,15 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.BinaryContentDto; +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.dto.UserStatusDto; + +import java.util.List; +import java.util.UUID; + +public interface BinaryContentService { + BinaryContentDto.Response create(BinaryContentDto.CreateRequest request); + BinaryContentDto.Response find(UUID userId); + List findAllByIdIn(List idList); + void delete(UUID id); +} 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 08f176dbd..af357ecd5 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -1,23 +1,16 @@ package com.sprint.mission.discodeit.service; +import com.sprint.mission.discodeit.dto.ChannelDto; import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.ChannelType; import java.util.List; import java.util.UUID; public interface ChannelService { - Channel createChannel(String channelName); - - void deleteChannel(UUID id); - - Channel findChannelByChannelId(UUID id); - - List findAllChannels(); - List findChannelByUserId(UUID userID); - - Channel updateChannel(UUID id, String channelName); - - void joinChannel(UUID userID, UUID channelID); - - void leaveChannel(UUID userID, UUID channelID); + ChannelDto.Response create(ChannelDto.CreateRequest request); + ChannelDto.Response find(UUID channelId); + List findAllByUserId(UUID userId); + ChannelDto.Response update(ChannelDto.UpdateRequest 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 ab01cdf5b..723f49053 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/MessageService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -1,16 +1,15 @@ package com.sprint.mission.discodeit.service; +import com.sprint.mission.discodeit.dto.MessageDto; import com.sprint.mission.discodeit.entity.Message; import java.util.List; import java.util.UUID; public interface MessageService { - Message createMessage(String content, UUID channelId, UUID userId); - void deleteMessage(UUID id); - Message findMessageById(UUID id); - Message updateMessage(UUID id, String newContent); - List findAllMessages(); - List findMessagesByChannelId(UUID channelId); - List findMessagesByUserId(UUID userId); + MessageDto.Response create(MessageDto.CreateRequest request); + List findAllByChannelId(UUID channelId); +// List findAll(); + MessageDto.Response update(MessageDto.UpdateRequest request); + void delete(UUID messageId); } diff --git a/src/main/java/com/sprint/mission/discodeit/service/ReadStatusService.java b/src/main/java/com/sprint/mission/discodeit/service/ReadStatusService.java new file mode 100644 index 000000000..a02957986 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/ReadStatusService.java @@ -0,0 +1,18 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.entity.User; +import lombok.Locked; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface ReadStatusService { + ReadStatusDto.Response create(ReadStatusDto.CreateRequest request); + ReadStatusDto.Response find(UUID id); + List findAllByUserId(UUID userId); + ReadStatusDto.Response update(ReadStatusDto.UpdateRequest request); + void delete(UUID id); +} 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 b307e6546..3186f3ffb 100644 --- a/src/main/java/com/sprint/mission/discodeit/service/UserService.java +++ b/src/main/java/com/sprint/mission/discodeit/service/UserService.java @@ -1,23 +1,15 @@ package com.sprint.mission.discodeit.service; +import com.sprint.mission.discodeit.dto.UserDto; import com.sprint.mission.discodeit.entity.User; import java.util.List; import java.util.UUID; public interface UserService { - User createUser(String username, String password, String email); - - User findUserById(UUID id); - - List findAllUsers(); - - User updateUserInfo(UUID id, String newUsername, String newEmail); - - User changePassword(UUID id, String newPassword); - - void deleteUser(UUID id); - - List findParticipants(UUID channelID); - + UserDto.Response create(UserDto.CreateRequest request); + UserDto.Response find(UUID userId); + List findAll(); + UserDto.Response update(UserDto.UpdateRequest request); + void delete(UUID userId); } diff --git a/src/main/java/com/sprint/mission/discodeit/service/UserStatusService.java b/src/main/java/com/sprint/mission/discodeit/service/UserStatusService.java new file mode 100644 index 000000000..ff497c9a0 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/UserStatusService.java @@ -0,0 +1,16 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.dto.UserStatusDto; + +import java.util.List; +import java.util.UUID; + +public interface UserStatusService { + UserStatusDto.Response create(UserStatusDto.CreateRequest request); + UserStatusDto.Response find(UUID id); + List findAll(); + UserStatusDto.Response update(UserStatusDto.UpdateRequest request); + UserStatusDto.Response updateByUserId(UserStatusDto.UpdateRequest request); + void delete(UUID id); +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/basic/BasicAuthService.java b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicAuthService.java new file mode 100644 index 000000000..0c9010a4d --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicAuthService.java @@ -0,0 +1,39 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.AuthDto; +import com.sprint.mission.discodeit.dto.UserDto; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.service.AuthService; +import org.springframework.stereotype.Service; + +import java.util.NoSuchElementException; + +@Service +public class BasicAuthService implements AuthService { + + private final UserRepository userRepository; + + public BasicAuthService(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Override + public UserDto.Response login(AuthDto.LoginRequest request) { + // username: 유저 존재 확인 + User user = userRepository.findByUsername(request.username()) + .orElseThrow(() -> new NoSuchElementException("존재하지 않는 유저입니다.")); + + // password: 비밀번호 일치 여부 확인 + if (!user.getPassword().equals(request.password())) { + throw new IllegalArgumentException("비밀번호가 일치하지 않습니다."); + } + + return UserDto.Response.builder() + .id(user.getId()) + .username(user.getUsername()) + .email(user.getEmail()) + .profileImageId(user.getProfileImageId()) + .build(); + } +} 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..7997973d9 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicBinaryContentService.java @@ -0,0 +1,59 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.BinaryContentDto; +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.repository.BinaryContentRepository; +import com.sprint.mission.discodeit.service.BinaryContentService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class BasicBinaryContentService implements BinaryContentService { + private final BinaryContentRepository binaryContentRepository; + + @Override + public BinaryContentDto.Response create(BinaryContentDto.CreateRequest request) { + BinaryContent content = new BinaryContent( + request.bytes(), + request.contentType(), + request.fileName() + ); + return convertToResponse(binaryContentRepository.save(content)); + } + + @Override + public BinaryContentDto.Response find(UUID userId) { + return binaryContentRepository.findById(userId) + .map(this::convertToResponse) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 파일이 존재하지 않습니다.")); + } + + @Override + public List findAllByIdIn(List idList) { + return binaryContentRepository.findAllById(idList).stream() + .map(this::convertToResponse) + .toList(); + } + + @Override + public void delete(UUID id) { + if (!binaryContentRepository.existsById(id)) { + throw new NoSuchElementException("해당 ID의 파일이 존재하지 않습니다."); + } + binaryContentRepository.deleteById(id); + } + + private BinaryContentDto.Response convertToResponse(BinaryContent content) { + return new BinaryContentDto.Response( + content.getId(), + content.getBytes(), + content.getContentType(), + content.getFileName() + ); + } +} 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..d650f962e --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicChannelService.java @@ -0,0 +1,124 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.ChannelDto; +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.ReadStatus; +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.service.ChannelService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.validation.MessageCodesResolver; + +import java.time.Instant; +import java.util.*; + +@Service +@RequiredArgsConstructor +public class BasicChannelService implements ChannelService { + private final ChannelRepository channelRepository; + private final ReadStatusRepository readStatusRepository; + private final MessageRepository messageRepository; + + + @Override + public ChannelDto.Response create(ChannelDto.CreateRequest request) { + // PUBLIC 채널 생성 시 기존 로직 유지, PRIVATE 채널 생성 시 생략 + String name = (request.type() == ChannelType.PUBLIC) ? request.name() : null; + String description = (request.type() == ChannelType.PUBLIC) ? request.description() : null; + + Channel channel = new Channel(request.type(), name, description); + channelRepository.save(channel); + + return convertToResponse(channel, null, null); // 초기 생성 시 최근 메시지, 유저 목록 없음 + } + + + @Override + public ChannelDto.Response find(UUID channelId) { + Channel channel = channelRepository.findById(channelId) + .orElseThrow(() -> new NoSuchElementException("Channel with id " + channelId + " not found")); + + // 해당 채널의 가장 최근 메시지의 시간 정보 + Instant lastTime = messageRepository.findLastMessageOfChannel(channelId) + .map(Message::getCreatedAt).orElse(null); + + // PRIVATE 채널의 경우 참여한 유저의 id 포함 + List memberList = null; + if (channel.getType() == ChannelType.PRIVATE) { + memberList = readStatusRepository.findAllByChannelId(channelId).stream() + .map(ReadStatus::getUserId) + .toList(); + } + + return convertToResponse(channel, lastTime, memberList); + + } + + @Override + public List findAllByUserId (UUID userId){ + // PUBLIC 채널: 전체 조회 + List publicChannels = channelRepository.findAllByType(ChannelType.PUBLIC); + + // PRIVATE: 유저가 참여한 채널만 조회 + List myPrivateChannels = readStatusRepository.findAllByUserId(userId).stream() + .map(readStatus -> channelRepository.findById(readStatus.getChannelId()).orElse(null)) + .filter(Objects::nonNull) + .filter(channel -> channel.getType() == ChannelType.PRIVATE) + .toList(); + + // 참여한 PUBLIC과 PRIVATE 채널 합치기: 특정 유저가 볼 수 있는 채널 목록 조회 가능 + List myAvailableChannelList = new ArrayList<>(); + myAvailableChannelList.addAll(publicChannels); + myAvailableChannelList.addAll(myPrivateChannels); + + // find() 재사용: 최근 메시지 시간 정보, PRIVATE 채널의 유저 Id 정보 포함 + return myAvailableChannelList.stream() + .map(channel -> find(channel.getId())) + .toList(); + } + + @Override + public ChannelDto.Response update (ChannelDto.UpdateRequest request) { + Channel channel = channelRepository.findById(request.channelId()) + .orElseThrow(() -> new NoSuchElementException("Channel with id " + request.channelId() + " not found")); + + // PRIVATE 채널은 수정 불가 + if (channel.getType() == ChannelType.PRIVATE) { + throw new IllegalStateException("PRIVATE 채널은 수정할 수 없습니다."); + } + + channel.setName(request.newName()); + channel.setDescription(request.newDescription()); + + channelRepository.save(channel); + return convertToResponse(channel, null, null); + } + + @Override + public void delete (UUID channelId) { + Channel channel = channelRepository.findById(channelId).orElseThrow(); + + // 관련 도메인(Message, ReadStatus) 삭제 + messageRepository.deleteAllByChannelId(channelId); + readStatusRepository.deleteAllByChannelId(channelId); + + channelRepository.deleteById(channelId); + } + + private ChannelDto.Response convertToResponse (Channel channel, Instant lastMessageTime, List memberId) { + return ChannelDto.Response.builder() + .id(channel.getId()) + .name(channel.getName()) + .lastMessageAt(lastMessageTime) + .memberIdList(memberId) + .build(); + } + } + + + + 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..87985e10d --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicMessageService.java @@ -0,0 +1,111 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.MessageDto; +import com.sprint.mission.discodeit.entity.BinaryContent; +import com.sprint.mission.discodeit.entity.Message; +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.*; + +@Service +@RequiredArgsConstructor +public class BasicMessageService implements MessageService { + private final MessageRepository messageRepository; + private final ChannelRepository channelRepository; + private final UserRepository userRepository; + private final BinaryContentRepository binaryContentRepository; + + @Override + public MessageDto.Response create(MessageDto.CreateRequest request) { + + List attachmentIds = new ArrayList<>(); + + if (request.attachments() != null && !request.attachments().isEmpty()) { + attachmentIds = request.attachments().stream() + .map(fileRequest -> { + BinaryContent content = new BinaryContent( + fileRequest.data(), + fileRequest.fileType(), + fileRequest.fileName() + ); + return binaryContentRepository.save(content).getId(); + }) + .toList(); + } + + Message message = new Message( + request.content(), + request.channelId(), + request.authorId(), + attachmentIds + ); + + messageRepository.save(message); + + return convertToResponse(message); + + } + + @Override + public List findAllByChannelId(UUID channelId) { + return messageRepository.findAllByChannelId(channelId).stream() + .map(this::convertToResponse) + .toList(); + } + + @Override + public MessageDto.Response update(MessageDto.UpdateRequest request) { + Message message = messageRepository.findById(request.id()) + .orElseThrow(() -> new NoSuchElementException("Message with id " + request.id() + " not found")); + + List newIds = Optional.ofNullable(request.attachments()) + .filter(attachments -> !attachments.isEmpty()) + .map(attachments -> attachments.stream() + .map(dto -> { + BinaryContent content = new BinaryContent( + dto.data(), + dto.fileType(), + dto.fileName() + ); + return binaryContentRepository.save(content).getId(); + }) + .toList() + ) + .orElse(null); + message.update(request.content(), newIds); + + return convertToResponse(messageRepository.save(message)); + + } + + + @Override + public void delete(UUID id) { + Message message = messageRepository.findById(id) + .orElseThrow(() -> new NoSuchElementException("Message with id " + id + " not found")); + + // 첨부파일 삭제 + if (message.getAttachmentIds() != null && !message.getAttachmentIds().isEmpty()) { + binaryContentRepository.deleteAllById(message.getAttachmentIds()); + } + + messageRepository.deleteById(id); + + } + + private MessageDto.Response convertToResponse(Message message) { + return MessageDto.Response.builder() + .id(message.getId()) + .channelId(message.getChannelId()) + .authorId(message.getAuthorId()) + .content(message.getContent()) + .attachmentId(message.getAttachmentIds()) + .build(); + } +} 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..cc82371e1 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicReadStatusService.java @@ -0,0 +1,87 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.entity.ReadStatus; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.repository.ChannelRepository; +import com.sprint.mission.discodeit.repository.ReadStatusRepository; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.service.ReadStatusService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class BasicReadStatusService implements ReadStatusService { + private final ReadStatusRepository readStatusRepository; + private final UserRepository userRepository; + private final ChannelRepository channelRepository; + + @Override + public ReadStatusDto.Response create(ReadStatusDto.CreateRequest request) { + // 관련된 채널이나 유저가 존재하지 않을 때 예외 발생 + channelRepository.findById(request.channelId()) + .orElseThrow(() -> new NoSuchElementException("채널이 존재하지 않습니다.")); + + userRepository.findById(request.userId()) + .orElseThrow(() -> new NoSuchElementException("유저가 존재하지 않습니다.")); + + // 같은 채널과 유저와 관련된 객체가 이미 존재하면 예외 발생 + if(readStatusRepository.existsByChannelIdAndUserId(request.channelId(), request.userId())) { + throw new IllegalStateException("이미 채널과 유저의 상태가 존재합니다."); + } + + ReadStatus readStatus = new ReadStatus(request.channelId(), request.userId()); + return convertToResponse(readStatusRepository.save(readStatus)); + + } + + @Override + public ReadStatusDto.Response find(UUID id) { + return readStatusRepository.findById(id) + .map(this::convertToResponse) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다.")); + } + + @Override + public List findAllByUserId(UUID userId) { + return readStatusRepository.findAllByUserId(userId).stream() + .map(this::convertToResponse) + .toList(); + } + + @Override + public ReadStatusDto.Response update(ReadStatusDto.UpdateRequest request) { + ReadStatus readStatus = readStatusRepository.findById(request.id()) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다.")); + + Optional.ofNullable(request.lastReadMessageId()) + .ifPresent(readStatus::updateLastReadMessage); + + return convertToResponse(readStatusRepository.save(readStatus)); + } + + @Override + public void delete(UUID id) { + if(!readStatusRepository.existsById(id)) { + throw new NoSuchElementException("존재하지 않는 Id 입니다."); + } + readStatusRepository.deleteById(id); + + } + private ReadStatusDto.Response convertToResponse(ReadStatus readStatus) { + return new ReadStatusDto.Response( + readStatus.getId(), + readStatus.getUserId(), + readStatus.getChannelId(), + readStatus.getLastReadMessageId(), + readStatus.getUpdatedAt() + ); + } + +} 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 new file mode 100644 index 000000000..ee70a6eaa --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserService.java @@ -0,0 +1,137 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.UserDto; +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.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; + +@Service +@RequiredArgsConstructor +public class BasicUserService implements UserService { + private final UserRepository userRepository; + private final BinaryContentRepository binaryContentRepository; + private final UserStatusRepository userStatusRepository; + + @Override + public UserDto.Response create(UserDto.CreateRequest request) { + // 프로필 이미지 처리(선택적) + UUID imageId = null; + if (request.profileImage() != null) { + BinaryContent image = new BinaryContent( + request.profileImage().data(), + request.profileImage().fileType(), + request.profileImage().fileName()); + imageId = binaryContentRepository.save(image).getId(); + } + + // 중복 검증 + if (userRepository.usernameExistence(request.username())) throw new RuntimeException("이미 존재하는 이름입니다."); + if (userRepository.emailExistence(request.email())) throw new RuntimeException("이미 존재하는 이메일입니다."); + + // 유저 등록 + User user = new User(request.username(), request.email(), request.password()); + if (imageId != null) { + user.setProfileImageId(imageId); + } + User savedUser = userRepository.save(user); + userStatusRepository.save(new UserStatus(savedUser.getId())); + + return UserDto.Response.builder() + .id(savedUser.getId()) + .username(savedUser.getUsername()) + .email(savedUser.getEmail()) + .isOnline(true) + .profileImageId(savedUser.getProfileImageId()) + .build(); + + + } + + @Override + public UserDto.Response find(UUID userId) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new NoSuchElementException("User with id " + userId + " not found")); + + // 유저 온라인 상태 정보 포함(패스워드 제외) + boolean isOnline = userStatusRepository.findByUserId(userId) + .map(UserStatus::isOnline) + .orElse(false); + + return UserDto.Response.builder() + .id(user.getId()) + .username(user.getUsername()) + .email(user.getEmail()) + .profileImageId(user.getProfileImageId()) + .isOnline(isOnline) + .build(); + } + + @Override + public List findAll() { + return userRepository.findAll().stream() + .map(user -> { + boolean isOnline = userStatusRepository.findByUserId(user.getId()) + .map(UserStatus::isOnline) + .orElse(false); + + return UserDto.Response.builder() + .id(user.getId()) + .username(user.getUsername()) + .email(user.getEmail()) + .profileImageId(user.getProfileImageId()) + .isOnline(isOnline) + .build(); + }) + .toList(); + } + + @Override + public UserDto.Response update(UserDto.UpdateRequest updateRequest) { + User user = userRepository.findById(updateRequest.id()) + .orElseThrow(() -> new NoSuchElementException("User with id " + updateRequest.id()+ " not found")); + + // 프로필 이미지 대체 (선택) + Optional.ofNullable(updateRequest.profileImage()) + .ifPresent(imageDto -> { + if (user.getProfileImageId() != null) { + binaryContentRepository.deleteById(user.getProfileImageId()); + } + BinaryContent newImage = new BinaryContent( + imageDto.data(), imageDto.fileType(), imageDto.fileName() + ); + user.setProfileImageId(binaryContentRepository.save(newImage).getId()); + }); + + user.update(updateRequest.username(), updateRequest.email(), updateRequest.password()); + userRepository.save(user); + return find(user.getId()); + } + + @Override + public void delete(UUID userId) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new NoSuchElementException("User not found with id: " + userId)); + + // BinaryContent 삭제 + if (user.getProfileImageId() != null) { + binaryContentRepository.deleteById(user.getProfileImageId()); + } + + // UserStatus 삭제 + userStatusRepository.deleteById(userId); + + // 유저 삭제 + userRepository.deleteById(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..eda29109c --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/basic/BasicUserStatusService.java @@ -0,0 +1,93 @@ +package com.sprint.mission.discodeit.service.basic; + +import com.sprint.mission.discodeit.dto.ReadStatusDto; +import com.sprint.mission.discodeit.dto.UserStatusDto; +import com.sprint.mission.discodeit.entity.UserStatus; +import com.sprint.mission.discodeit.repository.UserRepository; +import com.sprint.mission.discodeit.repository.UserStatusRepository; +import com.sprint.mission.discodeit.service.UserStatusService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class BasicUserStatusService implements UserStatusService { + + private final UserStatusRepository userStatusRepository; + private final UserRepository userRepository; + + + @Override + public UserStatusDto.Response create(UserStatusDto.CreateRequest request) { + // 관련된 유저 존재 X + userRepository.findById(request.userId()) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 유저가 존재하지 않습니다.")); + + // 같은 유저와 관련된 객체가 이미 존재 + if (userStatusRepository.existsByUserId(request.userId())) { + throw new IllegalStateException("해당 ID의 상태가 이미 존재합니다."); + } + + UserStatus userStatus = new UserStatus( + request.userId() + ); + + return convertToResponse(userStatusRepository.save(userStatus)); + } + + @Override + public UserStatusDto.Response find(UUID id) { + return userStatusRepository.findById(id) + .map(this::convertToResponse) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다.")); + } + + @Override + public List findAll() { + return userStatusRepository.findAll().stream() + .map(this::convertToResponse) + .toList(); + } + + @Override + public UserStatusDto.Response update(UserStatusDto.UpdateRequest request) { + UserStatus userStatus = userStatusRepository.findById(request.id()) + .orElseThrow(() -> new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다.")); + + userStatus.updateActiveTime(); + + return convertToResponse(userStatusRepository.save(userStatus)); + } + + @Override + public UserStatusDto.Response updateByUserId(UserStatusDto.UpdateRequest request) { + UserStatus userStatus = userStatusRepository.findByUserId(request.userId()) + .orElseThrow(() -> new NoSuchElementException("해당 유저의 상태 정보가 존재하지 않습니다.")); + + userStatus.updateActiveTime(); + + return convertToResponse(userStatusRepository.save(userStatus)); + } + + @Override + public void delete(UUID id) { + if (!userStatusRepository.existsById(id)) { + throw new NoSuchElementException("해당 ID의 상태가 존재하지 않습니다."); + } + userStatusRepository.deleteById(id); + + } + + private UserStatusDto.Response convertToResponse(UserStatus userStatus) { + return new UserStatusDto.Response( + userStatus.getId(), + userStatus.getUserId(), + userStatus.getUpdatedAt(), + userStatus.isOnline() + ); + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java b/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java deleted file mode 100644 index 86ebc999a..000000000 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFChannelService.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.sprint.mission.discodeit.service.jcf; - -import com.sprint.mission.discodeit.entity.Channel; -import com.sprint.mission.discodeit.entity.User; -import com.sprint.mission.discodeit.service.ChannelService; -import com.sprint.mission.discodeit.service.UserService; - -import java.util.*; - -public class JCFChannelService implements ChannelService { - private final Map channelMap; - private final UserService userService; - - public JCFChannelService(UserService userService){ - this.channelMap = new HashMap<>(); - this.userService = userService; - } - - @Override - public Channel createChannel(String channelName) { - Channel channel = new Channel(channelName); - channelMap.put(channel.getId(), channel); - System.out.println(channel.getChannelName() + "채널 생성이 완료되었습니다."); - return channel; - } - - @Override - public Channel findChannelByChannelId(UUID id){ - Channel channel = channelMap.get(id); - if (channel == null) { - throw new IllegalArgumentException("해당 채널이 없습니다."); - } - return channel; - } - - @Override - public List findChannelByUserId(UUID userID){ - User user = userService.findUserById(userID); - return new ArrayList<>(user.getMyChannels()); - } - - @Override - public List findAllChannels(){ - return new ArrayList<>(channelMap.values()); - } - - @Override - public void deleteChannel(UUID id){ - Channel targetChannel = findChannelByChannelId(id); - - targetChannel.getParticipants() - .forEach(user -> user.getMyChannels().remove(targetChannel)); - channelMap.remove(id); - } - - public Channel updateChannel(UUID id, String channelName){ - Channel targetChannel = findChannelByChannelId(id); - targetChannel.updateChannelInfo(channelName); - return targetChannel; - } - - @Override - public void joinChannel(UUID userID, UUID channelID) { - Channel targetChannel = findChannelByChannelId(channelID); - User targetUser = userService.findUserById(userID); - - targetChannel.getParticipants().stream() - .filter(participant -> participant.getId().equals(targetUser.getId())) - .findAny() - .ifPresent(participant -> { - throw new IllegalArgumentException("이미 채널에 참여중인 사용자입니다."); - }); - - targetChannel.getParticipants().add(targetUser); - targetUser.getMyChannels().add(targetChannel); - - targetChannel.getParticipants().add(targetUser); - targetUser.getMyChannels().add(targetChannel); - - System.out.println(targetUser.getUsername() + "님이 " - + targetChannel.getChannelName() + " 채널에 입장했습니다."); - } - - @Override - public void leaveChannel(UUID userID, UUID channelID) { - Channel targetChannel = findChannelByChannelId(channelID); - User targetUser = userService.findUserById(userID); - - if (!targetChannel.getParticipants().contains(targetUser)) { - throw new IllegalArgumentException("채널에 참여중이지 않습니다."); - } - - targetChannel.getParticipants().remove(targetUser); - targetUser.getMyChannels().remove(targetChannel); - } -} 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 deleted file mode 100644 index 861f4f6b1..000000000 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFMessageService.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.sprint.mission.discodeit.service.jcf; - -import com.sprint.mission.discodeit.entity.Channel; -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 java.util.*; - - -public class JCFMessageService implements MessageService { - private final Map messageMap; - private final UserService userService; - private final ChannelService channelService; - - public JCFMessageService(UserService userService, ChannelService channelService){ - this.messageMap = new HashMap<>(); - this.userService = userService; - this.channelService = channelService; - } - - public Message createMessage(String content, UUID channelId, UUID userId){ - Channel channel = channelService.findChannelByChannelId(channelId); - User user = userService.findUserById(userId); - - Message newMessage = new Message(content, channel, user); - messageMap.put(newMessage.getId(), newMessage); - - user.addMessage(newMessage); - channel.addMessage(newMessage); - - return newMessage; - } - - public List findMessagesByChannelId(UUID channelId){ - Channel channel = channelService.findChannelByChannelId(channelId); - return channel.getChannelMessages(); - } - - public List findMessagesByUserId(UUID userId){ - User user = userService.findUserById(userId); - - return user.getMyMessages(); - } - - public List findAllMessages(){ - return new ArrayList<>(messageMap.values()); - } - - public Message findMessageById(UUID id){ - Message message = messageMap.get(id); - if (message == null) { - throw new IllegalArgumentException("해당 메시지가 없습니다."); - } - return message; - } - - public Message updateMessage(UUID id, String newContent){ - Message targetMessage = findMessageById(id); - - targetMessage.updateContent(newContent); - System.out.println("메시지가 수정되었습니다"); - - return targetMessage; - } - - public void deleteMessage(UUID id){ - Message targetMessage = findMessageById(id); - - // 유저 쪽 리스트에서 삭제 - if (targetMessage.getUser() != null) { - targetMessage.getUser().getMyMessages().remove(targetMessage); - } - // 채널 쪽 리스트에서 삭제 - if (targetMessage.getChannel() != null) { - targetMessage.getChannel().getChannelMessages().remove(targetMessage); - } - - messageMap.remove(id); - System.out.println("메시지 삭제 완료: " + targetMessage.getContent()); - } - -} 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 deleted file mode 100644 index fb1add3a9..000000000 --- a/src/main/java/com/sprint/mission/discodeit/service/jcf/JCFUserService.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.sprint.mission.discodeit.service.jcf; - -import com.sprint.mission.discodeit.entity.Channel; -import com.sprint.mission.discodeit.entity.User; -import com.sprint.mission.discodeit.service.UserService; - -import java.util.*; - -public class JCFUserService implements UserService { - private final Map userMap; - public JCFUserService(){ - this.userMap = new HashMap<>(); - } - - @Override - public User createUser(String username, String password, String email) { - User newUser = new User(username, password, email); - userMap.put(newUser.getId(), newUser); - System.out.println(username + "님 회원가입 완료되었습니다."); - return newUser; - } - - @Override - public User findUserById(UUID id) { - User user = userMap.get(id); - if (user == null) { - throw new IllegalArgumentException("해당 유저가 없습니다."); - } - return user; - } - - @Override - public List findAllUsers(){ - return new ArrayList<>(userMap.values()); - } - - @Override - public User updateUserInfo(UUID id, String newUsername, String newEmail) { - User targetUser = findUserById(id); - - // username, email 검증 - if (newUsername == null && newEmail == null) { - throw new IllegalArgumentException("둘 중 하나는 입력해야 합니다."); - } - - // Username 검증 - Optional.ofNullable(newUsername) - .filter(name -> name.contains(" ")) - .ifPresent(name -> { - throw new IllegalArgumentException("띄어쓰기는 포함할 수 없습니다."); - }); - - // Email 검증 - Optional.ofNullable(newEmail) - .filter(email -> !isValidEmail(email)) - .ifPresent(email -> { - throw new IllegalArgumentException("이메일 형식이 잘못되었습니다."); - }); - - // 실제 수정 로직 - Optional.ofNullable(newUsername).ifPresent(name -> { - targetUser.updateUsername(name); - System.out.println("이름이 변경되었습니다: " + targetUser.getUsername()); - }); - - Optional.ofNullable(newEmail).ifPresent(email -> { - targetUser.updateEmail(email); - System.out.println("이메일이 변경되었습니다: " + targetUser.getEmail()); - }); - - return targetUser; - } - - private boolean isValidEmail(String email){ - if (email == null || email.trim().isEmpty()){ - return false; - } - // 이메일 정규표현식 - String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; - return email.matches(emailRegex); - } - - @Override - public void deleteUser(UUID id){ - User targetUser = findUserById(id); - - for (Channel channel : targetUser.getMyChannels()) { - channel.getParticipants().remove(targetUser); - } - - userMap.remove(id); - System.out.println(targetUser.getUsername() + "님 삭제 완료되었습니다"); - } - - @Override - public User changePassword(UUID id, String newPassword) { - User targetUser = findUserById(id); - targetUser.updatePassword(newPassword); - return targetUser; - } - - @Override - public List findParticipants(UUID channelID){ - return userMap.values().stream() - .filter(user -> user.getMyChannels().stream() - .anyMatch(channel -> channel.getId().equals(channelID))) - .toList(); - } - -} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml new file mode 100644 index 000000000..4fe0afb2e --- /dev/null +++ b/src/main/resources/application.yaml @@ -0,0 +1,4 @@ +discodeit: + repository: + type: jcf + file-directory: .discodeit