diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b63da455 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.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/.gradle/8.10/checksums/checksums.lock b/.gradle/8.10/checksums/checksums.lock new file mode 100644 index 00000000..d4598fdc Binary files /dev/null and b/.gradle/8.10/checksums/checksums.lock differ diff --git a/.gradle/8.10/checksums/md5-checksums.bin b/.gradle/8.10/checksums/md5-checksums.bin new file mode 100644 index 00000000..7f2ccadd Binary files /dev/null and b/.gradle/8.10/checksums/md5-checksums.bin differ diff --git a/.gradle/8.10/checksums/sha1-checksums.bin b/.gradle/8.10/checksums/sha1-checksums.bin new file mode 100644 index 00000000..b7c21899 Binary files /dev/null and b/.gradle/8.10/checksums/sha1-checksums.bin differ diff --git a/.gradle/8.10/dependencies-accessors/gc.properties b/.gradle/8.10/dependencies-accessors/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/.gradle/8.10/executionHistory/executionHistory.bin b/.gradle/8.10/executionHistory/executionHistory.bin new file mode 100644 index 00000000..a611ca2f Binary files /dev/null and b/.gradle/8.10/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.10/executionHistory/executionHistory.lock b/.gradle/8.10/executionHistory/executionHistory.lock new file mode 100644 index 00000000..60995b4c Binary files /dev/null and b/.gradle/8.10/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.10/fileChanges/last-build.bin b/.gradle/8.10/fileChanges/last-build.bin new file mode 100644 index 00000000..f76dd238 Binary files /dev/null and b/.gradle/8.10/fileChanges/last-build.bin differ diff --git a/.gradle/8.10/fileHashes/fileHashes.bin b/.gradle/8.10/fileHashes/fileHashes.bin new file mode 100644 index 00000000..072a2a34 Binary files /dev/null and b/.gradle/8.10/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.10/fileHashes/fileHashes.lock b/.gradle/8.10/fileHashes/fileHashes.lock new file mode 100644 index 00000000..ea7e6ee7 Binary files /dev/null and b/.gradle/8.10/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.10/gc.properties b/.gradle/8.10/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 00000000..53ae623d Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 00000000..abc1ff2a --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Mon Apr 14 18:05:38 KST 2025 +gradle.version=8.10 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 00000000..6b2ab068 Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe new file mode 100644 index 00000000..ec8534c8 Binary files /dev/null and b/.gradle/file-system.probe differ diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 00000000..e69de29b diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..77fd1730 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +3-sprint-mission \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..f9163b40 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..fe0b0dab --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..668101a2 --- /dev/null +++ b/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +group = 'com.sprint.mission' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.10.0') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +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 00000000..249e5832 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..af85458d --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Apr 14 18:05:24 KST 2025 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 00000000..1b6c7873 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# 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 00000000..107acd32 --- /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 00000000..79373e36 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = '3-sprint-mission' + 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 00000000..ac67e001 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/JavaApplication.java @@ -0,0 +1,98 @@ +package com.sprint.mission.discodeit; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.control.ChannelControl; +import com.sprint.mission.discodeit.control.MessageControl; +import com.sprint.mission.discodeit.control.UserControl; + +import java.util.InputMismatchException; +import java.util.Scanner; + +public class JavaApplication { + public static final Scanner scanner = new Scanner(System.in); + public static User currentUser; + public static Channel currentChannel; + + public static void main(String[] args) { + // 0. 초기 사용자 인증 + currentUser = UserControl.verifyUser(); + // 0_1. intro 메세지 + System.out.println(" ▶ discodeit 메세지 서비스에 연결되었습니다."); + // 1. mainmenu 호출 + menuMain(); + //// <<메뉴 트리>> + //// 메인메뉴 ┬ 1. 채널입장 (채널상 메세지 관리) || 메서드 : control.menuMessageMng() + //// │ ├ 1_1 메세지 작성 ok + //// │ ├ 1_2 전체 메세지 조회 ok + //// │ ├ 1_3 단건 메세지 조회 ok + //// │ ├ 1_4 메세지 수정 ok + //// │ ├ 1_5 메세지 삭제 ok + //// │ └ 1_6 다른 채널에 접속 ok + //// │ └ 1_7 현재 사용자 변경 ok + //// │ └ 1_8 상위메뉴로 ok + //// ├ 2. 채널 관리(신규,수정,삭제) || 메서드 : control.menuChannelMng() + //// │ ├ 2_1 신규 채널 개설 ok + //// │ ├ 2_2 개별 채널 정보 상세조회 ok + //// │ ├ 2_3 개별 채널 이름,설명 변경 ok + //// │ └ 2_4 개별 채널 삭제 ok + //// │ └ 2_5 전체 채널 정보 상세조회 ok + //// │ └ 2_6 상위메뉴로 ok + //// ├ 3. 사용자 관리(신규,수정,삭제) || 메서드 : control.menuUserMng() + //// │ ├ 3_1 신규 사용자 추가 ok + //// │ ├ 3_2 현재 사용자 변경 ok + //// │ ├ 3_3 사용자 삭제 ok + //// │ └ 3_4 단일 사용자 상세 조회 ok + //// │ └ 3_5 전체 사용자 목록 조회 ok + //// │ └ 3_6 현재 사용자 변경 ok + //// │ └ 3_7 상위메뉴로 ok + //// └ 4. 프로그램 종료 + } + + // ▽▽▽main메서드에서 사용되는 내부 메서드 + public static int scanInt(){ // 메뉴 선택시 int값 입력 필터링 메서드 + System.out.print(" >> "); + int inputNum = -1; + try { + inputNum = scanner.nextInt(); + scanner.nextLine(); // scanner 내부 개행문자 제거 + } catch (InputMismatchException e){ + System.out.println("숫자만 입력해 주세요"); + scanner.nextLine(); // scanner 내부 개행문자 제거 + } + return inputNum; +} + + + public static void menuMain(){ // 메인 메뉴 call 메서드. 각 세부 메뉴로 접근하기 위함. + while (true) { + System.out.println(" ▶ 원하는 메뉴를 선택해 주세요."); + System.out.println("**********************************************\n" + + "[1] 채널 입장 및 메세지 관리\n" + + "[2] 채널 관리 (신규, 수정, 삭제, 조회)\n" + + "[3] 사용자 관리 (신규, 수정, 삭제, 조회)\n" + + "[4] 종료\n" + + "**********************************************\n"); + int choice = scanInt(); // 숫자 입력 메서드 호출 + + switch (choice) { + case 1: // 채널 입장 : 메세지 관리 메서드 호출 + currentChannel = ChannelControl.verifyChannel(); + MessageControl.menuMessageMng(currentUser,currentChannel); + break; + case 2: + ChannelControl.menuChannelMng(currentUser); + break; + case 3: // 사용자 관리 : 사용자 관리 메서드 호출 + UserControl.menuUserMng(currentUser); + break; + case 4: + System.out.println(" ▶ 프로그램을 종료합니다."); + break; + default: + System.out.println(" ▶ 잘못된 접근입니다. 다시 입력해 주세요"); + } + if (choice == 4) {break;} + } + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/control/ChannelControl.java b/src/main/java/com/sprint/mission/discodeit/control/ChannelControl.java new file mode 100644 index 00000000..9a05b86c --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/control/ChannelControl.java @@ -0,0 +1,155 @@ +package com.sprint.mission.discodeit.control; + +import com.sprint.mission.discodeit.JavaApplication; +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.jcf.JCFChannelService; + +public class ChannelControl extends JavaApplication { + private static final JCFChannelService channelService = new JCFChannelService(); + + public static Channel verifyChannel(){ // 채널입장시 Channel 신규개설 판별 메서드. 있으면 있는 채널에 참가 / 없으면 없는채널 생성 + System.out.print(" ▶ 채널명을 입력해 주세요 : "); + String chanName = scanner.nextLine(); + Channel channel = channelService.findChannelByName(chanName); + if (channel != null) { + System.out.println("[" + channel.getChannelName() + "] 에 접속합니다." + ", 채널 ID: " + channel.getId()); + return channel; + } else { + System.out.println("\n ▶ 존재하지 않는 채널입니다. 새로운 채널을 개설합니다."); + System.out.println("\n ▶ 새로운 채널의 설명을 입력해주세요."); + String chanDesc = scanner.nextLine(); + Channel newChannel = channelService.addChannel(chanName,chanDesc,currentUser); + System.out.println(" ▶ [" + newChannel.getChannelName() + "] 채널에 접속합니다." + " 채널 ID: " + newChannel.getId()); + return newChannel; + } + } + public static void menuChannelMng(User currentUser){ // 2. 채널 관리 메서드 + while (true) { + System.out.println(" *******************************************************\n" + + " || 채널 관리 메뉴입니다. 원하는 기능을 선택하세요. ||\n" + + " || 1 > 신규 채널 생성 ||\n" + + " || 2 > 개별 채널 정보 상세조회 ||\n" + + " || 3 > 개별 채널 이름,설명 변경 ||\n" + + " || 4 > 개별 채널 삭제 ||\n" + + " || 5 > 전체 채널 정보 상세조회 ||\n" + + " || 6 > 상위 메뉴로 돌아가기 ||\n" + + " *******************************************************\n"); + int choice = scanInt(); // 숫자 입력 필터링 메서드 호출 + + switch (choice) { + case 1: // 2_1 신규 채널 생성, 채널설명 추가 + System.out.println(" ▶ 새로운 채널을 개설합니다."); + while(true) { + System.out.print(" ▶ 채널명을 입력해 주세요 : "); + String chanName = scanner.nextLine(); + Channel channel = channelService.findChannelByName(chanName); + if (channel == null) { + System.out.println("\n ▶ 새로운 채널의 설명을 입력해주세요."); + String chanDesc = scanner.nextLine(); + Channel newChan = channelService.addChannel(chanName, chanDesc, currentUser); + System.out.println("\n ▶ "+newChan.getChannelName()+" 채널 생성에 성공하였습니다."); + break; + } else {System.out.println("\n ▶ 이미 존재하는 채널입니다. 다른 이름을 입력해주세요.");} + } + break; + case 2: // 2_2 채널 이름으로 검색하여 개별 채널 조회 + System.out.println(" ▶ 조회할 채널의 이름을 입력해 주세요."); + System.out.print(" >> "); + String chnName = scanner.nextLine(); + Channel toPrintChannel = channelService.findChannelByName(chnName); + if (toPrintChannel != null) { + System.out.println(toPrintChannel); + break; + }else{System.out.println("존재하지 않는 채널명입니다. 다시 입력해 주세요"); + } + break; + case 3: // 2_3 채널 이름으로 검색하여 해당 채널 이름,설명 변경 + while (true){ + System.out.println("\n ▶ 채널 이름을 변경합니다. 현재 개설된 채널은 아래와 같습니다. \n"); + channelService.printAllChannels(); + while(true) { + String newName; + String newDesc; + System.out.println(" ▶ 변경할 채널의 이름을 선택해 주세요."); + System.out.print(" >> "); + String fndChnName = scanner.nextLine(); + Channel toRenameChannel = channelService.findChannelByName(fndChnName); + if (toRenameChannel != null) { + System.out.println(" ▶ 선택하신 채널은 ["+toRenameChannel.getChannelName()+"] 입니다"); + System.out.println(" ▶ 변경할 이름을 입력해 주세요."); + while(true) { + System.out.print(" >> "); + newName = scanner.nextLine(); + if(channelService.findChannelByName(newName) == null){ + if (newName.length() != 0) { + toRenameChannel.setChannelName(newName); + break; + } else { + System.out.println(" ▶ 잘못된 입력입니다. 다시 입력해 주세요."); + } + } else { + System.out.println(" ▶ 이미 존재하는 채널명입니다. 다시 입력해 주세요."); + } + } + + System.out.println(" ▶ 변경할 채널의 설명을 입력해 주세요."); + while(true){ + System.out.print(" >> "); + newDesc = scanner.nextLine(); + if (newDesc.length() == 0) { + channelService.UpdateChannel(toRenameChannel,newName,"-"); + System.out.println(" ▶ 채널 설명을 공백으로 설정했습니다."); + break; + }else{ + channelService.UpdateChannel(toRenameChannel,newName,newDesc); + System.out.println(" ▶ 채널정보 수정에 성공했습니다."); + break; + } + } + break; + }else{System.out.println("존재하지 않는 채널명입니다. 다시 입력해 주세요"); + } + }break; + } + break; + case 4: // 2_4 개별 채널 삭제 + System.out.println(" ▶ 현재 개설된 채널은 아래와 같습니다."); + channelService.printAllChannels(); + System.out.println(" ▶ 삭제할 채널의 이름을 입력해 주세요"); + + String fndChnName = scanner.nextLine(); + Channel toDeleteChannel = channelService.findChannelByName(fndChnName); + if (toDeleteChannel != null) { + System.out.println(" ▶ 정말로 삭제할까요? 삭제를 원하시면 [삭제]라고 입력해 주세요.\n >> "); + String deleteConfirm = scanner.nextLine(); + if (deleteConfirm.length() == 0) { + System.out.println(" ▶ 잘못된 입력입니다. 이전 메뉴로 돌아갑니다."); + break; + }else if(deleteConfirm.equals("삭제")) { + channelService.deleteChannel(toDeleteChannel); + System.out.println(" ▶ [" + fndChnName+ "]채널이 삭제되었습니다."); + }else{ + System.out.println(" ▶ 잘못된 입력입니다. 채널 삭제를 취소합니다."); + } + } else { + System.out.println(" ▶ 잘못된 입력입니다. 채널 삭제를 취소합니다."); + } + + + break; + case 5: // 2_5 개별 채널 정보 상세조회 + channelService.printAllChannels(); + break; + case 6: // 2_6 상위메뉴 복귀 + break; + default: // 세부메뉴 입력예외처리 + System.out.println(" ▶ 잘못된 접근입니다. 다시 입력해 주세요"); + } + if (choice == 6) {break;} + } + + + } // 2. 채널 관리 메서드 + +} diff --git a/src/main/java/com/sprint/mission/discodeit/control/MessageControl.java b/src/main/java/com/sprint/mission/discodeit/control/MessageControl.java new file mode 100644 index 00000000..5f56b2ae --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/control/MessageControl.java @@ -0,0 +1,132 @@ +package com.sprint.mission.discodeit.control; + +import com.sprint.mission.discodeit.JavaApplication; +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.jcf.JCFUserService; + +import java.util.List; + +public class MessageControl extends JavaApplication { + private static final JCFUserService userService = new JCFUserService(); + public static void menuMessageMng(User currentUser, Channel currentChannel){ // 1 메세지 관리 메서드 + while (true) { + System.out.println(" *******************************************************\n" + + " || ["+currentChannel.getChannelName()+"] 채널에 입장했습니다.\n" + + " || 원하는 기능을 선택하세요. ||\n" + + " || 1 > 신규 메세지 작성 ||\n" + + " || 2 > 전체 메세지 조회 ||\n" + + " || 3 > 단건 메세지 조회 ||\n" + + " || 4 > 메세지 수정 ||\n" + + " || 5 > 메세지 삭제 ||\n" + + " || 6 > 다른 채널에 접속 ||\n" + + " || 7 > 현재 사용자 변경 ||\n" + + " || 8 > 상위 메뉴로 돌아가기 ||\n" + + " *******************************************************\n"); + int choice = scanInt(); // 숫자 입력 필터링 메서드 호출 + int inputMsgNum; + Message currentMsg; + List messages = currentChannel.messageService().getMessagesList(); + switch (choice) { + case 1: // 1_1 메세지 작성 + System.out.print(" ▶ 새로운 대화를 시작합니다.\n"); + while (true){ + int goNum; + if((messages.size()) < 5){goNum=0;}else{goNum = messages.size() - 5;} + System.out.println("번호 | 사용자명 : 메세지(생성일/수정일)"); + for (int i = goNum ; i < messages.size(); i++) { + currentChannel.messageService().printOneMessage(i+1); + } + + System.out.print(" >> "); + String txtMsg = scanner.nextLine(); + if (txtMsg.length()!=0) { + currentChannel.messageService().uploadMsg(currentUser, txtMsg); + }else { + System.out.println(" ▶ 메세지 입력을 종료합니다"); + break; + } + } + break; + + case 2: //1_2 전체 메세지 조회 + System.out.println(" ▶ 채널에 등록된 모든 메세지를 조회합니다.\n "); + currentChannel.messageService().printAllMessages(); + break; + case 3: //1_3 단건 메세지 조회 + System.out.println(" ▶ 조회할 메세지의 번호를 입력해 주세요"); + inputMsgNum = scanInt(); // 숫자 입력 메서드 호출 + if(inputMsgNum <= messages.size()) { + System.out.println(" ▶ [" + inputMsgNum + "]번 메세지는 아래와 같습니다."); + System.out.println("번호 | 사용자 : 메세지 ( 생성시각 / 수정시각 )"); + currentChannel.messageService().printOneMessage(inputMsgNum); + break;} + System.out.println(" ▶ 잘못된 입력입니다. 상위메뉴로 돌아갑니다."); + + break; + case 4: // 1_4 메세지 수정 + System.out.println(" ▶ 현재 등록된 메세지는 아래와 같습니다."); + currentChannel.messageService().printAllMessages(); + System.out.println(" ▶ 수정할 메세지의 번호를 입력해 주세요"); + inputMsgNum = scanInt(); // 숫자 입력 메서드 호출 + if(inputMsgNum <= messages.size()) { + currentMsg = currentChannel.messageService().findMessageByNum(inputMsgNum); + System.out.println(" ▶ [" + inputMsgNum + "]번 메세지는 아래와 같습니다."); + System.out.println(currentMsg.getTextMsg()); + + System.out.print("수정할 새로운 메세지를 입력해 주세요.\n >> "); + String newMessage = scanner.nextLine(); + currentChannel.messageService().updateMsg(currentUser,currentMsg, newMessage); + System.out.println("기존 내용을 [" + currentMsg.getTextMsg() + "] 로 수정하였습니다."); + break;} + System.out.println(" ▶ 잘못된 입력입니다. 상위메뉴로 돌아갑니다."); + break; + case 5: // 1_5 메세지 삭제 + System.out.println(" ▶ 현재 등록된 메세지는 아래와 같습니다."); + currentChannel.messageService().printAllMessages(); + System.out.println(" ▶ 삭제할 메세지의 번호를 입력해 주세요"); + inputMsgNum = scanInt(); // 숫자 입력 메서드 호출 + currentMsg = currentChannel.messageService().findMessageByNum(inputMsgNum); + System.out.println(" ▶ [" + inputMsgNum + "]번 메세지는 아래와 같습니다."); + System.out.println(currentMsg.getTextMsg()); + + System.out.println(" ▶ 정말로 삭제할까요? 삭제를 원하시면 [삭제]라고 입력해 주세요.\n >> "); + String deleteConfirm = scanner.nextLine(); + if (deleteConfirm.length() == 0) { + System.out.println(" ▶ 잘못된 입력입니다. 이전 메뉴로 돌아갑니다."); + break; + }else if(deleteConfirm.equals("삭제")) { + currentChannel.messageService().deleteMessage(currentUser,currentMsg); + System.out.println("메세지가 삭제되었습니다."); + }else{ + System.out.println(" ▶ 잘못된 입력입니다. 사용자 삭제를 취소합니다."); + } + break; + case 6: // 1_6 현재 채널 변경 + currentChannel = ChannelControl.verifyChannel(); + break; + case 7: // 1_7 현재 사용자 변경 + System.out.print(" ▶ 어떤 사용자로 로그인할까요?"); + String username = scanner.nextLine(); + User user = userService.findUserByName(username); + if (user != null) { + System.out.println("[" + user.getName() + "] 사용자로 진행합니다." + ", ID: " + user.getId()); + currentUser = user; + } else { + System.out.println("\n ▶ 존재하지 않는 사용자입니다. 기존 사용자[" + currentUser.getName() + "]로 진행합니다.\n 현재 사용가능한 사용자는 아래와 같습니다."); + userService.getUserslist().forEach(u -> System.out.print(u.getName()+ " , ")); + System.out.println(); + } + break; + case 8: // 1_8 상위메뉴로 이동 + break; + default: // 세부메뉴 입력예외처리 + System.out.println(" ▶ 잘못된 접근입니다. 다시 입력해 주세요"); + } + if (choice == 8) {break;} + } + + + } // 1 메세지 관리 메서드 +} diff --git a/src/main/java/com/sprint/mission/discodeit/control/UserControl.java b/src/main/java/com/sprint/mission/discodeit/control/UserControl.java new file mode 100644 index 00000000..2bedad50 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/control/UserControl.java @@ -0,0 +1,164 @@ +package com.sprint.mission.discodeit.control; + +import com.sprint.mission.discodeit.JavaApplication; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.jcf.JCFUserService; + +import java.util.InputMismatchException; + +public class UserControl extends JavaApplication { + private static final JCFUserService userService = new JCFUserService(); + // 어플리케이션 최초 실행시 User 신규여부 판별 메서드. 있으면 있는 유저로 로그인 / 없으면 새 유저 생성 + public static User verifyUser(){ // 사용자명 입력 >> 없는 사용자 : 사용자 생성 / 있는 사용자 : 이름으로 확인, ID연결 + System.out.print(" ▶ 사용자명을 입력해 주세요 : "); + String username = scanner.nextLine(); + User user = userService.findUserByName(username); + if (user != null) { + System.out.println("[" + user.getName() + "] 님 환영합니다." + ", ID: " + user.getId()); + return user; + } else { + System.out.println("\n ▶ 존재하지 않는 사용자입니다. 신규 사용자로 등록합니다."); + User newUser = userService.createUser(username); + System.out.println("\n ▶ 환영합니다 [" + newUser.getName() + "] 님, 새로운 ID가 발급되였습니다.\n 신규 사용자 UUID : " + newUser.getId()); + return newUser; + } + } + // 1_3 사용자 관리 세부메뉴 메서드 + public static void menuUserMng(User currentUser){ // 1_4 사용자 관리 내부메뉴 메서드 + while (true) { + System.out.println(" *******************************************************\n" + + " || 사용자 관리 메뉴입니다. 원하는 기능을 선택하세요. ||\n" + + " || 1 > 신규 사용자 생성 ||\n" + + " || 2 > 현재 사용자 이름 변경 ||\n" + + " || 3 > 사용자 삭제 ||\n" + + " || 4 > 단일 사용자 상세조회 ||\n" + + " || 5 > 전체 사용자 상세조회 ||\n" + + " || 6 > 다른 사용자로 진행 ||\n" + + " || 7 > 상위 메뉴로 돌아가기 ||\n" + + " *******************************************************\n"); + System.out.print(" >> "); + int choice = -1; + try { + choice = scanner.nextInt(); + scanner.nextLine(); // scanner 내부 개행문자 제거 + } catch (InputMismatchException e){ + System.out.println("숫자만 입력해 주세요"); + scanner.nextLine(); // scanner 내부 개행문자 제거 + } + + switch (choice) { + case 1: // 1_4_1 신규 사용자 생성 메뉴 + System.out.println(" ▶ 새로운 사용자를 생성합니다."); + while (true) { + System.out.print(" ▶ 원하는 사용자명을 입력해 주세요 : "); + String username = scanner.nextLine(); + if (username.length() == 0) { // 입력값이 없는경우 상위 메뉴로 이동 + System.out.println(" ▶ 입력값이 없습니다. 사용자 생성을 취소합니다.\n"); + break;} + User user = userService.findUserByName(username); + if (user == null) { // 중복 유저명 체크하여 중복유저가 없는경우 사용자 생성 + User newUser = userService.createUser(username); + System.out.println(" ▶ 사용자 생성에 성공했습니다."); + System.out.println(" ▶ 사용자명 : " + newUser.getName() + " SSID : " + newUser.getId() + "\n"); + + // 새로 생성한 사용자로 currentUser 변경여부 체크 + System.out.println(" ▶ 새로운 사용자로 로그인하시겠습니까? Y/N"); + String newUserChange = scanner.nextLine(); + if (newUserChange.equals("y") || newUserChange.equals("Y")) { + currentUser = newUser; + System.out.println("\n ▶ [" + currentUser.getName() + "] 사용자로 로그인 했습니다."); + } + + System.out.println(" ▶ 기존 사용자 [" + currentUser.getName() + "]로 계속합니다."); + break; + } else { // user.name 중복값 확인시 while문 재시작 + System.out.println(" ▶ 이미 존재하는 사용자명입니다. 다른 이름을 입력해 주세요.\n"); + } + } + break; + + case 2: + while (true){ // 1_4_2 사용자 이름 변경 메뉴 + System.out.println("\n ▶ 사용자 이름을 변경합니다. * 현재 사용자 이름 : [" + currentUser.getName() + "]"); + System.out.println(" ▶ 변경할 사용자 이름을 입력해 주세요"); + System.out.print(" >> "); + String newName = scanner.nextLine(); + if(newName.length() ==0) {// 사용자 이름 입력값이 없는경우 상위메뉴로 이동 + System.out.println(" ▶ 새 이름을 입력하지 않았습니다. 사용자 이름 변경을 취소합니다."); + break;} + User user = userService.findUserByName(newName); + if(user != null){ // 중복값 존재시 재입력 + System.out.print(" ▶ 이미 존재하는 이름입니다. 다시 입력해 주세요.\n >>> "); + } else{ // 중복값 미확인시 유저명 변경 + userService.updateUserName(currentUser, newName); + break; + } + } + break; + case 3: // 1_4_3 사용자 삭제 메뉴 + System.out.println(" ▶ 삭제할 사용자의 이름을 입력해 주세요"); + System.out.println(" ▶ 현재 등록된 사용자는 아래와 같습니다."); + userService.printAllUsers(); + System.out.print(" >> "); + String deleteUser = scanner.nextLine(); + if ((deleteUser.length() == 0) || (userService.findUserByName(deleteUser) == null)) { + System.out.println(" ▶ 존재하지 않는 사용자이거나 잘못된 입력입니다. 이전 메뉴로 돌아갑니다."); + } else if (deleteUser.equals(currentUser.getName())){ + System.out.println(" ▶ 현재 로그인된 사용자는 삭제할 수 없습니다! 이전 메뉴로 돌아갑니다."); + break; + } else { + System.out.println(" ▶ 입력하신 사용자는 아래와 같습니다."); + User userToDel = userService.findUserByName(deleteUser); + System.out.println(userToDel); + System.out.println(" ▶ 정말로 삭제할까요? 삭제를 원하시면 [삭제]라고 입력해 주세요"); + System.out.print(" >> "); + String deleteConfirm = scanner.nextLine(); + if (deleteConfirm.length() == 0) { + System.out.println(" ▶ 잘못된 입력입니다. 이전 메뉴로 돌아갑니다."); + break; + }else if(deleteConfirm.equals("삭제")) { + userService.deleteUser(deleteUser); + System.out.println("[" + deleteUser + "] 사용자가 삭제되었습니다."); + }else{ + System.out.println(" ▶ 잘못된 입력입니다. 사용자 삭제를 취소합니다."); + } + } + break; + case 4: // 1_4_4 단일 사용자 정보 출력 메뉴 + System.out.print(" ▶ 조회할 사용자의 이름을 입력해 주세요.\n >> "); + String oneUser = scanner.nextLine(); + if ((oneUser.length() == 0) || (userService.findUserByName(oneUser) == null)) { + System.out.println(" ▶ 존재하지 않는 사용자이거나 잘못된 입력입니다. 이전 메뉴로 돌아갑니다."); + } else { + System.out.println(" ▶ 입력하신 사용자는 아래와 같습니다."); + User userToRead = userService.findUserByName(oneUser); + System.out.println(userToRead); + } + break; + case 5: // 1_4_5 모든 사용자 정보 출력 메뉴 + System.out.println(" ▶ 모든 사용자 정보를 출력합니다."); + userService.printAllUsers(); + break; + case 6: // 1_4_6 다른 사용자로 진행 + System.out.print(" ▶ 어떤 사용자로 로그인할까요?"); + String username = scanner.nextLine(); + User user = userService.findUserByName(username); + if (user != null) { + System.out.println("[" + user.getName() + "] 사용자로 진행합니다." + ", ID: " + user.getId()); + currentUser = user; + } else { + System.out.println("\n ▶ 존재하지 않는 사용자입니다. 기존 사용자[" + currentUser.getName() + "]로 진행합니다.\n 현재 사용가능한 사용자는 아래와 같습니다."); + userService.getUserslist().forEach(u -> System.out.print(u.getName()+ " , ")); + System.out.println(); + } + break; + case 7: // 1_4_7 상위메뉴 복귀 + break; + default: // 1_4 세부메뉴 입력예외처리 + System.out.println(" ▶ 잘못된 접근입니다. 다시 입력해 주세요"); + } + if (choice == 7) {break;} + } + } // 1_3 사용자 관리 세부메뉴 메서드 + +} 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 00000000..7bce68ed --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/Channel.java @@ -0,0 +1,59 @@ +package com.sprint.mission.discodeit.entity; + +import com.sprint.mission.discodeit.jcf.JCFMessageService; + +import java.text.SimpleDateFormat; +import java.util.UUID; + + +public class Channel { + private final UUID id = UUID.randomUUID(); + private long createdAt = System.currentTimeMillis(); + private long updatedAt; + private String channelName; + private String channelDescription; + private String channelCreater; + + private JCFMessageService messageService; + + + public Channel(String channelName, String channelDescription, String channelCreater, long createdAt, long updatedAt) { + this.channelName = channelName; + this.channelDescription = channelDescription; + this.channelCreater = channelCreater; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.messageService = new JCFMessageService(); + } + + public UUID getId() {return id;} + public String getCreatedAt() { + String formatedTime = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(createdAt); + return formatedTime;} + + public String getUpdatedAt() { + String formatedTime = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(updatedAt); + return formatedTime;} + public void setUpdatedAt(long updatedAt) {this.updatedAt = updatedAt;} + + public String getChannelName() {return channelName;} + public void setChannelName(String channelName) {this.channelName = channelName;} + + public String getChannelDescription() {return channelDescription;} + public void setChannelDescription(String channelDescription) {this.channelDescription = channelDescription;} + + public String getChannelCreater() {return channelCreater;} + + public JCFMessageService messageService() {return messageService;} + @Override + public String toString() { + String result; + if(getCreatedAt().equals(getUpdatedAt())){ + result = "채널명 : " + channelName + " 개설자 : " + channelCreater + " 채널설명 : " + channelDescription + " 개설일자 : " + getCreatedAt() + " UUID : " + getId(); + } else { + result = "채널명 : " + channelName + " 개설자 : " + channelCreater + " 채널설명 : " + channelDescription + " 개설일자 : " + getCreatedAt() + " 수정일자 : " + getUpdatedAt() + " UUID : " + getId(); + } + return result; + } +} + 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 00000000..6fc6e858 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/Message.java @@ -0,0 +1,50 @@ +package com.sprint.mission.discodeit.entity; + +import java.text.SimpleDateFormat; +import java.util.UUID; + +public class Message { + private final UUID id = UUID.randomUUID(); + private long createdAt = System.currentTimeMillis(); + private long updatedAt; + + private int msgNumber; + + private String author; + private String textMsg; + + + public Message(int msgNumber, String author, String textMsg,long createdAt, long updatedAt) { + this.msgNumber = msgNumber; + this.author = author; + this.textMsg = textMsg; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + public UUID getId() {return id;} + public int getMsgNumber() {return msgNumber;} + public String getAuthor() {return author;} + public void setAuthor(String newAuthor) {this.author = newAuthor;} + public void setTextMsg(String textMsg) {this.textMsg = textMsg;} + public String getTextMsg() {return textMsg;} + + public String getCreatedAt() { + String formatedTime = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(createdAt); + return formatedTime;} + public String getUpdatedAt() { + String formatedTime = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(updatedAt); + return formatedTime;} + public void setUpdatedAt(long updatedAt) { + this.updatedAt = updatedAt;} + @Override + public String toString() { + String result; + if(getCreatedAt().equals(getUpdatedAt())){ + result = msgNumber + " | " + author + " : " + textMsg + " (" + getCreatedAt() + ") : " + getId(); + } else { + result = msgNumber + " | " + author + " : " + textMsg + " (" + getCreatedAt() + " / " + getUpdatedAt() + ") : " + getId(); + } + return result; + } +} + 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 00000000..d6d6bcf8 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/entity/User.java @@ -0,0 +1,43 @@ +package com.sprint.mission.discodeit.entity; + +import java.text.SimpleDateFormat; +import java.util.UUID; + +public class User { + private final UUID id = UUID.randomUUID(); + private long createdAt = System.currentTimeMillis(); + private long updatedAt; + private String name; + + public User(String name, long createdAt, long updatedAt) { + this.name = name; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + public UUID getId() {return id;} + public String getName() {return name;} + public void setName(String name) {this.name = name;} + + public String getCreatedAt() { + String formatedTime = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(createdAt); + return formatedTime;} + public String getUpdatedAt() { + String aformatedTime = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(updatedAt); + return aformatedTime;} + public void setUpdatedAt(long updatedAt) {this.updatedAt = updatedAt;} + +@Override +public String toString() { + String result; + if(getCreatedAt().equals(getUpdatedAt())){ + result = "\n 사용자 이름 : " + name + "\n 생성일 : " + getCreatedAt() + "\n 사용자 UUID : " + id + "\n"; + } else { + result = "\n 사용자 이름 : " + name + "\n 생성일 : " + getCreatedAt() + "\n 수정일 : " + getUpdatedAt() + "\n 사용자 UUID : " + id + "\n"; + } + return result; + } + + + +} diff --git a/src/main/java/com/sprint/mission/discodeit/jcf/JCFChannelService.java b/src/main/java/com/sprint/mission/discodeit/jcf/JCFChannelService.java new file mode 100644 index 00000000..d731f9cc --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/jcf/JCFChannelService.java @@ -0,0 +1,65 @@ +package com.sprint.mission.discodeit.jcf; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.service.ChannelService; + +import java.util.ArrayList; +import java.util.List; + +public class JCFChannelService implements ChannelService { + // 초기 채널 입력 + private final List channels = new ArrayList<>(); + public JCFChannelService(){ + channels.add(new Channel("ch01","default Channel","관리자",1744036548250L,1744036548250L)); + + } + // 채널 생성 메서드 + @Override + public Channel addChannel(String channelName, String channelDesc, User user){ + long now = System.currentTimeMillis(); + Channel channel = new Channel(channelName,channelDesc,user.getName(),now,now); + channels.add(channel); + System.out.print("\n ▶ [새로운 채널 생성완료]"); + System.out.println(" ▶ 채널명 : " + channel.getChannelName() + " ▶ 생성시간 : " + channel.getCreatedAt()); + return channel; + }; + // 채널 수정 메서드 + @Override + public void UpdateChannel(Channel channel, String channelName, String channelDescription){ + long now = System.currentTimeMillis(); + channel.setChannelName(channelName); + channel.setChannelDescription(channelDescription); + channel.setUpdatedAt(now); + System.out.print("\n ▶ [채널 정보 수정 완료]"); + System.out.println(channel); + }; + // 채널 삭제 메서드 + @Override + public void deleteChannel(Channel channel){ + channels.remove(channel); + }; + // 전체채널목록 출력 메서드 + @Override + public void printAllChannels(){ + System.out.println("<< 생성된 전체 채널 >>"); + System.out.println("채널명 | 개설자 | 채널설명(개설시간)"); + channels.forEach(chan -> System.out.println(chan.getChannelName()+" | "+chan.getChannelCreater()+" | "+chan.getChannelDescription()+" ("+chan.getCreatedAt() + ")")); + System.out.println(""); + } + + @Override + public List getAllChannels() { + return List.of(); + } + + @Override // 이름으로 채널 검색 메서드. 채널객체를 return + public Channel findChannelByName(String name){ + for (Channel channel : channels) { + if (channel.getChannelName().equals(name)) { + return channel; // 일치하는 name 발견시 channel 객체를 리턴 + } + } + return null; // 없으면 null + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/jcf/JCFMessageService.java b/src/main/java/com/sprint/mission/discodeit/jcf/JCFMessageService.java new file mode 100644 index 00000000..c9013ad9 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/jcf/JCFMessageService.java @@ -0,0 +1,60 @@ +package com.sprint.mission.discodeit.jcf; + +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.service.MessageService; + +import java.util.ArrayList; +import java.util.List; + +public class JCFMessageService implements MessageService { + private final List messages = new ArrayList<>(); + // 테스트용 초기 더미 데이터 입력 + public JCFMessageService() { + messages.add(new Message(001,"희동이","더미 데이터 1 요리보고 조리봐도", 1744036548250L , 1744036548250L)); + messages.add(new Message(002,"희동이","더미 데이터 2 알수없는 둘리둘리", 1744036558250L , 1744036558250L)); + messages.add(new Message(003,"도우너","더미 데이터 3 빙하타고~내려와아", 1744036938250L , 1744036938250L)); + messages.add(new Message(004,"고길동","더미 데이터 4 치인구를 만났지만", 1744036938250L , 1744036938250L)); + } + @Override + public void uploadMsg(User user,String txtMsg){ + long now = System.currentTimeMillis(); + Message message = new Message(messages.size() + 1,user.getName(),txtMsg,now,now); + messages.add(message); + } + + @Override + public void updateMsg(User user, Message message,String newMsg) { + String resetColor = "\u001B[0m"; + String setColorYellow = "\u001B[33m"; + message.setTextMsg(newMsg + setColorYellow + " *** [" + user.getName() + "] 에 의해 수정됨" + resetColor); + message.setUpdatedAt(System.currentTimeMillis()); + } + + public void deleteMessage(User user, Message message){ + String resetColor = "\u001B[0m"; + String setColorRed = "\u001B[31m"; + message.setTextMsg(setColorRed + " - ////// " + user.getName() + " 사용자에 의해 삭제됨 ////// -" +message.getUpdatedAt() + resetColor); + message.setUpdatedAt(System.currentTimeMillis()); + } + public Message findMessageByNum(int num){ + for (Message message : messages) { + if (message.getMsgNumber() == num) { + return message; // 일치하는 메세지 번호 발견시 message 리턴 + } + }return null; + } + public void printAllMessages() { + System.out.println("<< 입력된 전체 메세지 >>"); + System.out.println("번호 | 사용자 : 메세지"); + messages.forEach(m -> System.out.printf("%4d | %-10s: %s \n 생성일 : %s 수정일 : %s UUID : %s\n",m.getMsgNumber(),m.getAuthor(),m.getTextMsg(),m.getCreatedAt(),m.getUpdatedAt(),m.getId())); + System.out.println(); + } + public void printOneMessage(int msgNum){ + Message message = findMessageByNum(msgNum); + System.out.printf("%4d | %-10s: %s \n 생성일 : %s 수정일 : %s UUID : %s\n", message.getMsgNumber(),message.getAuthor(),message.getTextMsg(),message.getCreatedAt(),message.getUpdatedAt(),message.getId() ); + } + public List getMessagesList() { + return messages; + } +} diff --git a/src/main/java/com/sprint/mission/discodeit/jcf/JCFUserService.java b/src/main/java/com/sprint/mission/discodeit/jcf/JCFUserService.java new file mode 100644 index 00000000..46b50eab --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/jcf/JCFUserService.java @@ -0,0 +1,74 @@ +package com.sprint.mission.discodeit.jcf; + +import com.sprint.mission.discodeit.entity.User; +import com.sprint.mission.discodeit.service.UserService; + +import java.util.*; + +public class JCFUserService implements UserService { + private final List users = new ArrayList<>(); + // 테스트용 초기 더미 데이터 입력 + public JCFUserService() { + users.add(new User("희동이" , 1744036538250L , 1744036538250L)); + users.add(new User("고길동" , 1744036738250L , 1744071238250L)); + users.add(new User("도우너" , 1744036938250L , 1744036538250L)); + } + + @Override // 유저 생성 메서드 createUser() + public User createUser(String name) { + long now = System.currentTimeMillis(); + User user = new User(name, now, now); + users.add(user); + System.out.println("사용자의 이름을 [" + user.getName() + "] 으로 생성하였습니다. | " + user.getCreatedAt()); + return user; + } + + @Override //유저 이름 변경 메서드 updateUserName() + public void updateUserName(User user, String newName) { + String oldName = user.getName(); + user.setName(newName); + user.setUpdatedAt(System.currentTimeMillis()); + System.out.println("[" + oldName + "] 사용자의 이름을 [" + user.getName() + "] 으로 변경하였습니다. | " + user.getUpdatedAt()); + } + + @Override + public boolean deleteUser(UUID id) { + return users.removeIf(user -> user.getId().equals(id)); + } + + @Override + public boolean deleteUser(String name) { + return users.removeIf(user -> user.getName().equals(name)); + } + + @Override + public User findUserById(UUID id) { + for (User user : users) { + if (user.getId().equals(id)) { + return user; // 일치하는 ID 발견시 user 리턴 + } + } + return null; // 없으면 null 리턴 + } + + @Override + public User findUserByName(String name) { + for (User user : users) { + if (user.getName().equals(name)) { + return user; // 일치하는 name 발견시 user 리턴 + } + } + return null; // 없으면 null 리턴 + } + + // 유틸 메서드: 모든 사용자 출력 + public void printAllUsers(){ + System.out.println(" □ □ □ 전체 사용자 목록 □ □ □ \n 사용자이름 | 사용자생성시간 | 사용자정보 수정시간 | 사용자UUID"); + users.forEach(u -> System.out.println(" " + u.getName() + " | " + u.getCreatedAt() + " | " + u.getUpdatedAt() + " | " + u.getId())); + System.out.println(); + } + public List getUserslist() { + return users; + } + +} \ No newline at end of file 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 00000000..2ac81252 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/ChannelService.java @@ -0,0 +1,17 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.entity.Channel; +import com.sprint.mission.discodeit.entity.User; + +import java.util.List; + +public interface ChannelService { + Channel addChannel(String channelName, String channelDesc, User user); + void UpdateChannel(Channel channel, String channelName, String channelDescription); + void deleteChannel(Channel channel); + + void printAllChannels(); + List getAllChannels(); + + Channel findChannelByName(String name); +} 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 00000000..9ef7819e --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/MessageService.java @@ -0,0 +1,19 @@ +package com.sprint.mission.discodeit.service; + + +import com.sprint.mission.discodeit.entity.Message; +import com.sprint.mission.discodeit.entity.User; + +import java.util.*; + +public interface MessageService{ + void uploadMsg(User user,String txtMsg); + void updateMsg(User user, Message message,String Msg); + Message findMessageByNum(int num); + + void deleteMessage(User user, Message message); + + void printAllMessages(); + void printOneMessage(int msgNum); + List getMessagesList(); // 사용자 전체 조회 +} 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 00000000..aca9a860 --- /dev/null +++ b/src/main/java/com/sprint/mission/discodeit/service/UserService.java @@ -0,0 +1,20 @@ +package com.sprint.mission.discodeit.service; + +import com.sprint.mission.discodeit.entity.User; + +import java.util.List; +import java.util.UUID; + +public interface UserService { + + User createUser(String name); // 새로운 유저 생성 + void updateUserName(User user,String name); // 기존 유저 수정 + void printAllUsers(); + List getUserslist(); // 유저 리스트 반환 + + User findUserById(UUID id); // ID로 단일유저 찾기 + User findUserByName(String name); // 이름으로 단일유저 찾기 + boolean deleteUser(UUID id); // ID로 유저 삭제 + boolean deleteUser(String name); // 이름으로 유저 삭제 + +}