diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..fcd416fa Binary files /dev/null and b/.DS_Store differ diff --git a/.github/.DS_Store b/.github/.DS_Store new file mode 100644 index 00000000..f91bab92 Binary files /dev/null and b/.github/.DS_Store differ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..90e30d95 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI Pipeline for Jutalkpia + +on: + push: + branches: + - dev + pull_request: + branches: + - dev + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + # 1. 코드 체크아웃 + - name: Checkout code + uses: actions/checkout@v3 + + # 2. Java 17 환경 설정 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + # 3. Gradle 빌드 + # 3.1. chat-service 빌드 + - name: Build chat-service + working-directory: src/backend/chat-service + run: ./gradlew clean build -x test + + # 4. Docker 이미지 빌드 및 푸시 + # 4.1. chat-service 이미지 빌드 및 푸시 + - name: Build and push Docker image for chat-service + working-directory: src/backend/chat-service + run: | + docker build -t mirlee/chat-service:latest . + docker push mirlee/chat-service:latest diff --git a/src/.idea/.gitignore b/src/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/src/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/src/.idea/misc.xml b/src/.idea/misc.xml new file mode 100644 index 00000000..6f29fee2 --- /dev/null +++ b/src/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/.idea/modules.xml b/src/.idea/modules.xml new file mode 100644 index 00000000..f669a0e5 --- /dev/null +++ b/src/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/.idea/src.iml b/src/.idea/src.iml new file mode 100644 index 00000000..d6ebd480 --- /dev/null +++ b/src/.idea/src.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/.idea/vcs.xml b/src/.idea/vcs.xml new file mode 100644 index 00000000..6c0b8635 --- /dev/null +++ b/src/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/backend/chat-service/Dockerfile b/src/backend/chat-service/Dockerfile new file mode 100644 index 00000000..1655604d --- /dev/null +++ b/src/backend/chat-service/Dockerfile @@ -0,0 +1,16 @@ +# JDK 17 기반 이미지 사용 +FROM eclipse-temurin:17-jdk-jammy + +# 작업 디렉토리 설정 +WORKDIR /app + +# 빌드된 JAR 파일 복사 +ARG JAR_FILE=build/libs/chat-service-0.0.1-SNAPSHOT.jar +COPY ${JAR_FILE} app.jar + +# 포트 노출 +EXPOSE 8080 + +# 애플리케이션 실행 +ENTRYPOINT ["java", "-jar", "app.jar"] + diff --git a/src/backend/workspace_server/.gitattributes b/src/backend/workspace_server/.gitattributes new file mode 100644 index 00000000..8af972cd --- /dev/null +++ b/src/backend/workspace_server/.gitattributes @@ -0,0 +1,3 @@ +/gradlew text eol=lf +*.bat text eol=crlf +*.jar binary diff --git a/src/backend/workspace_server/.gitignore b/src/backend/workspace_server/.gitignore new file mode 100644 index 00000000..95b1c6cf --- /dev/null +++ b/src/backend/workspace_server/.gitignore @@ -0,0 +1,38 @@ +HELP.md +local.env +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/src/backend/workspace_server/Dockerfile b/src/backend/workspace_server/Dockerfile new file mode 100644 index 00000000..5d97c43f --- /dev/null +++ b/src/backend/workspace_server/Dockerfile @@ -0,0 +1,15 @@ +# Azul Zulu OpenJDK 17 기반 이미지 +FROM azul/zulu-openjdk:17 + +# 작업 디렉토리 설정 +WORKDIR /app + +# 빌드된 JAR 파일 복사 +ARG JAR_FILE=build/libs/workspace-server-0.0.1-SNAPSHOT.jar +COPY ${JAR_FILE} app.jar + +# 포트 노출 +EXPOSE 8080 + +# 애플리케이션 실행 +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/src/backend/workspace_server/build.gradle b/src/backend/workspace_server/build.gradle new file mode 100644 index 00000000..a9cff14a --- /dev/null +++ b/src/backend/workspace_server/build.gradle @@ -0,0 +1,40 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.3.7' + id 'io.spring.dependency-management' version '1.1.7' +} + +group = 'com.jootalkpia' +version = '0.0.1-SNAPSHOT' + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.kafka:spring-kafka' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'org.postgresql:postgresql:42.7.4' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.kafka:spring-kafka-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/src/backend/workspace_server/docker-compose.yml b/src/backend/workspace_server/docker-compose.yml new file mode 100644 index 00000000..d7ddfa37 --- /dev/null +++ b/src/backend/workspace_server/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3.8' + +services: + workspace-server: + image: mirlee/workspace_server + container_name: workspace_server + ports: + - "8080:8080" + environment: + DB_USER: ${DB_USER} # PostgreSQL 사용자 + DB_PASSWORD: ${DB_PASSWORD} # PostgreSQL 비밀번호 + DB_NAME: ${DB_NAME} # 공통 데이터베이스 이름 + DB_HOST: db # PostgreSQL 컨테이너 이름 (서비스 이름과 동일) + DB_PORT: ${DB_PORT} # PostgreSQL 기본 포트 + depends_on: + - db +# +# db: +# image: mirlee/postgresql-db:latest +# container_name: jootalkpia-db +# environment: +# POSTGRES_USER: ${DB_USER} # PostgreSQL 사용자 +# POSTGRES_PASSWORD: ${DB_PASSWORD} # PostgreSQL 비밀번호 +# POSTGRES_DB: ${DB_NAME} # 공통 데이터베이스 이름 +# volumes: +# - postgres_data:/var/lib/postgresql/data +# ports: +# - "5432:5432" # 로컬 포트 5432 -> 컨테이너 포트 5432 +# +#volumes: +# postgres_data: diff --git a/src/backend/workspace_server/gradle/wrapper/gradle-wrapper.jar b/src/backend/workspace_server/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..a4b76b95 Binary files /dev/null and b/src/backend/workspace_server/gradle/wrapper/gradle-wrapper.jar differ diff --git a/src/backend/workspace_server/gradle/wrapper/gradle-wrapper.properties b/src/backend/workspace_server/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..e2847c82 --- /dev/null +++ b/src/backend/workspace_server/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/src/backend/workspace_server/gradlew b/src/backend/workspace_server/gradlew new file mode 100755 index 00000000..f5feea6d --- /dev/null +++ b/src/backend/workspace_server/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/src/backend/workspace_server/gradlew.bat b/src/backend/workspace_server/gradlew.bat new file mode 100644 index 00000000..9d21a218 --- /dev/null +++ b/src/backend/workspace_server/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/backend/workspace_server/local.env b/src/backend/workspace_server/local.env new file mode 100644 index 00000000..8396a86f --- /dev/null +++ b/src/backend/workspace_server/local.env @@ -0,0 +1,6 @@ +# PostgreSQL +DB_HOST=localhost +DB_PORT=5432 +DB_NAME=jootalkpia +DB_USER=admin +DB_PASSWORD=1234 diff --git a/src/backend/workspace_server/settings.gradle b/src/backend/workspace_server/settings.gradle new file mode 100644 index 00000000..462aba0f --- /dev/null +++ b/src/backend/workspace_server/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'workspace_server' diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/WorkspaceServerApplication.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/WorkspaceServerApplication.java new file mode 100644 index 00000000..aba1f394 --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/WorkspaceServerApplication.java @@ -0,0 +1,13 @@ +package com.jootalkpia.workspace_server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WorkspaceServerApplication { + + public static void main(String[] args) { + SpringApplication.run(WorkspaceServerApplication.class, args); + } + +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/controller/WorkSpaceController.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/controller/WorkSpaceController.java new file mode 100644 index 00000000..e0bf6027 --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/controller/WorkSpaceController.java @@ -0,0 +1,34 @@ +package com.jootalkpia.workspace_server.controller; + + +import com.jootalkpia.aop.JootalkpiaAuthenticationContext; +import com.jootalkpia.workspace_server.dto.ChannelListDTO; +import com.jootalkpia.workspace_server.service.WorkSpaceService; +import com.jootalkpia.workspace_server.util.ValidationUtils; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Slf4j +@RequestMapping("/api/v1/workspace") +@RequiredArgsConstructor +public class WorkSpaceController { + + private final WorkSpaceService workSpaceService; + private final Long userId = JootalkpiaAuthenticationContext.getUserInfo().userId(); + + @GetMapping("/{workspaceId}/channels") + public ResponseEntity getChannels(@PathVariable Long workspaceId) { + // 유효성 검증 + ValidationUtils.validateWorkSpaceId(workspaceId); + log.info("Getting channels for workspace with id: {}", workspaceId); + + ChannelListDTO channelListDTO = workSpaceService.getChannels(userId, workspaceId); + return ResponseEntity.ok().body(channelListDTO); + } +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/dto/ChannelListDTO.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/dto/ChannelListDTO.java new file mode 100644 index 00000000..c3487fe4 --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/dto/ChannelListDTO.java @@ -0,0 +1,12 @@ +package com.jootalkpia.workspace_server.dto; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ChannelListDTO { + private List joinedChannels; + private List unjoinedChannels; +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/dto/SimpleChannel.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/dto/SimpleChannel.java new file mode 100644 index 00000000..9a7fbd1a --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/dto/SimpleChannel.java @@ -0,0 +1,13 @@ +package com.jootalkpia.workspace_server.dto; + +import java.time.LocalDateTime; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class SimpleChannel { + private Long channelId; + private String channelName; + private LocalDateTime createdAt; +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/Channels.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/Channels.java new file mode 100644 index 00000000..aa95040a --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/Channels.java @@ -0,0 +1,46 @@ +package com.jootalkpia.workspace_server.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +@Entity +@Table(name = "channels") +@Getter +public class Channels { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "channel_id", nullable = false) + private Long channelId; + + @ManyToOne + @JoinColumn(name = "workspace_id", nullable = false) + private WorkSpace workSpace; + + @OneToMany(mappedBy = "channels", cascade = CascadeType.ALL, orphanRemoval = true) + private List userChannel = new ArrayList<>(); + + @Column(name = "name", length = 100, nullable = false) + private String name; + + @CreationTimestamp + @Column(name = "created_at", updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updated_at") + private LocalDateTime updatedAt; +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/Mention.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/Mention.java new file mode 100644 index 00000000..2d9bcc7c --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/Mention.java @@ -0,0 +1,42 @@ +package com.jootalkpia.workspace_server.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import java.time.LocalDateTime; +import lombok.Getter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +@Entity +@Table(name = "mention") +@Getter +public class Mention { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "mention_id", nullable = false) + private Long mentionId; + + @ManyToOne + @JoinColumn(name = "user_channel_id", nullable = false) + private UserChannel userChannel; + + @Column(name = "message_id", nullable = false) + private Long messageId; + + @Column(name = "is_unread", nullable = false) + private Boolean isUnread; + + @CreationTimestamp + @Column(name = "created_at", updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updated_at") + private LocalDateTime updatedAt; +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/UserChannel.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/UserChannel.java new file mode 100644 index 00000000..6d8d4e5a --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/UserChannel.java @@ -0,0 +1,50 @@ +package com.jootalkpia.workspace_server.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +@Entity +@Table(name = "user_channel") +@Getter +public class UserChannel { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_channel_id", nullable = false) + private Long userChannelId; + + @ManyToOne + @JoinColumn(name = "user_id", nullable = false) + private Users users; + + @ManyToOne + @JoinColumn(name = "channel_id", nullable = false) + private Channels channels; + + @OneToMany(mappedBy = "userChannel", cascade = CascadeType.ALL, orphanRemoval = true) + private List mentions = new ArrayList<>(); + + @Column(name = "mute", nullable = false) + private Boolean mute; + + @CreationTimestamp + @Column(name = "createdAt", updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updatedAt") + private LocalDateTime updatedAt; +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/Users.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/Users.java new file mode 100644 index 00000000..ebf205a6 --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/Users.java @@ -0,0 +1,48 @@ +package com.jootalkpia.workspace_server.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import java.time.LocalDateTime; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +@Entity +@Table(name = "users") +@Getter +@Setter +public class Users { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "user_id", nullable = false) + private Long userId; + + @Column(name = "platform", nullable = false, length = 50) + private String platform; + + @Column(name = "social_id", nullable = false, length = 50, unique = true) + private String socialId; + + @Column(name = "nickname", nullable = false, length = 100) + private String nickname; + + @Column(name = "email", nullable = false, length = 320, unique = true) + private String email; + + @Column(name = "profile_image", length = 100) + private String profileImage; + + @CreationTimestamp + @Column(name = "created_at", nullable = false, updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updated_at", nullable = false) + private LocalDateTime updatedAt; +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/WorkSpace.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/WorkSpace.java new file mode 100644 index 00000000..12636225 --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/entity/WorkSpace.java @@ -0,0 +1,43 @@ +package com.jootalkpia.workspace_server.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +@Entity +@Table(name = "work_space") +@Getter +public class WorkSpace { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "workspace_id", nullable = false) + private Long workspaceId; + + @Column(name = "name", length = 100, nullable = false) + private String name; + + @Column(name = "stock_name", length = 100, nullable = false) + private String stockName; + + @OneToMany(mappedBy = "workSpace", cascade = CascadeType.ALL, orphanRemoval = true) + private List channels = new ArrayList<>(); + + @CreationTimestamp + @Column(name = "createdAt", updatable = false) + private LocalDateTime createdAt; + + @UpdateTimestamp + @Column(name = "updatedAt") + private LocalDateTime updatedAt; +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/exception/common/CustomException.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/exception/common/CustomException.java new file mode 100644 index 00000000..3227ca9c --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/exception/common/CustomException.java @@ -0,0 +1,13 @@ +package com.jootalkpia.workspace_server.exception.common; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class CustomException extends RuntimeException { + + private final String code; + private final String message; + +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/exception/common/ErrorCode.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/exception/common/ErrorCode.java new file mode 100644 index 00000000..248502f4 --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/exception/common/ErrorCode.java @@ -0,0 +1,31 @@ +package com.jootalkpia.workspace_server.exception.common; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum ErrorCode { + + // 400 Bad Request + UNKNOWN("W00001", "알 수 없는 에러가 발생했습니다."), + BAD_REQUEST("W40001", "잘못된 요청입니다."), + VALIDATION_FAILED("W40002", "유효성 검증에 실패했습니다."), + MISSING_PARAMETER("W40003", "필수 파라미터가 누락되었습니다."), + INVALID_PARAMETER("W40004", "잘못된 파라미터가 포함되었습니다."), + + // 404 Not Found + _NOT_FOUND("W40401", "등록되지 않은 ~~입니다."), + + + // 500 Internal Server Error + INTERNAL_SERVER_ERROR("W50001", "서버 내부 오류가 발생했습니다."), + DATABASE_ERROR("W50002", "데이터베이스 처리 중 오류가 발생했습니다."), + IMAGE_UPLOAD_FAILED("W50003", "파일 업로드에 실패했습니다."), + IMAGE_DOWNLOAD_FAILED("W50004", "파일 다운로드 중 오류가 발생했습니다."), + FILE_PROCESSING_FAILED("W50005", "파일 처리 중 오류가 발생했습니다."), + UNEXPECTED_ERROR("W50006", "예상치 못한 오류가 발생했습니다."); + + private final String code; + private final String msg; +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/repository/ChannelRepository.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/repository/ChannelRepository.java new file mode 100644 index 00000000..9e754ba8 --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/repository/ChannelRepository.java @@ -0,0 +1,11 @@ +package com.jootalkpia.workspace_server.repository; + +import com.jootalkpia.workspace_server.entity.Channels; +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ChannelRepository extends JpaRepository { + List findByWorkSpaceWorkspaceId(Long workspaceId); +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/repository/UserChannelRepository.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/repository/UserChannelRepository.java new file mode 100644 index 00000000..1578e611 --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/repository/UserChannelRepository.java @@ -0,0 +1,9 @@ +package com.jootalkpia.workspace_server.repository; + +import com.jootalkpia.workspace_server.entity.UserChannel; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserChannelRepository extends JpaRepository { + Optional findByUsersUserIdAndChannelsChannelId(Long userId, Long channelId); +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/repository/WorkSpaceRepository.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/repository/WorkSpaceRepository.java new file mode 100644 index 00000000..55dd0aca --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/repository/WorkSpaceRepository.java @@ -0,0 +1,10 @@ +package com.jootalkpia.workspace_server.repository; + +import com.jootalkpia.workspace_server.entity.WorkSpace; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface WorkSpaceRepository extends JpaRepository { +} + diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/service/WorkSpaceService.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/service/WorkSpaceService.java new file mode 100644 index 00000000..4d9ab08f --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/service/WorkSpaceService.java @@ -0,0 +1,59 @@ +package com.jootalkpia.workspace_server.service; + + +import com.jootalkpia.workspace_server.dto.ChannelListDTO; +import com.jootalkpia.workspace_server.dto.SimpleChannel; +import com.jootalkpia.workspace_server.entity.Channels; +import com.jootalkpia.workspace_server.exception.common.CustomException; +import com.jootalkpia.workspace_server.exception.common.ErrorCode; +import com.jootalkpia.workspace_server.repository.ChannelRepository; +import com.jootalkpia.workspace_server.repository.UserChannelRepository; +import java.util.ArrayList; +import java.util.List; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +@RequiredArgsConstructor +public class WorkSpaceService { + + private final ChannelRepository channelRepository; + private final UserChannelRepository userChannelRepository; + + public ChannelListDTO getChannels(Long userId, Long workspaceId) { + // workspaceId로 모든 채널 조회 + List channelList = channelRepository.findByWorkSpaceWorkspaceId(workspaceId); + if (channelList.isEmpty()) { + throw new CustomException(ErrorCode.DATABASE_ERROR.getCode(), ErrorCode.DATABASE_ERROR.getMsg()); + } + + // 가입된 채널과 가입되지 않은 채널을 분류 + List joinedChannels = new ArrayList<>(); + List unjoinedChannels = new ArrayList<>(); + + for (Channels channels : channelList) { + SimpleChannel simpleChannel = new SimpleChannel(); + simpleChannel.setChannelId(channels.getChannelId()); + simpleChannel.setChannelName(channels.getName()); + simpleChannel.setCreatedAt(channels.getCreatedAt()); + + if (isJoinedChannel(userId, channels)) { + joinedChannels.add(simpleChannel); + } else { + unjoinedChannels.add(simpleChannel); + } + } + + ChannelListDTO channelListDTO = new ChannelListDTO(); + channelListDTO.setJoinedChannels(joinedChannels); + channelListDTO.setUnjoinedChannels(unjoinedChannels); + + return channelListDTO; + } + + private boolean isJoinedChannel(Long userId, Channels channels) { + return userChannelRepository.findByUsersUserIdAndChannelsChannelId(userId, channels.getChannelId()).isPresent(); + } +} diff --git a/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/util/ValidationUtils.java b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/util/ValidationUtils.java new file mode 100644 index 00000000..cae8970b --- /dev/null +++ b/src/backend/workspace_server/src/main/java/com/jootalkpia/workspace_server/util/ValidationUtils.java @@ -0,0 +1,17 @@ +package com.jootalkpia.workspace_server.util; + +import com.jootalkpia.workspace_server.exception.common.CustomException; +import com.jootalkpia.workspace_server.exception.common.ErrorCode; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@AllArgsConstructor +public class ValidationUtils { + + public static void validateWorkSpaceId(Long workSpaceId) { + if (workSpaceId == null || workSpaceId <= 0) { + throw new CustomException(ErrorCode.INVALID_PARAMETER.getCode(), ErrorCode.INVALID_PARAMETER.getMsg()); + } + } +} \ No newline at end of file diff --git a/src/backend/workspace_server/src/main/resources/application.yml b/src/backend/workspace_server/src/main/resources/application.yml new file mode 100644 index 00000000..36bfdeea --- /dev/null +++ b/src/backend/workspace_server/src/main/resources/application.yml @@ -0,0 +1,29 @@ +server: + port: 8080 # 애플리케이션 실행 포트 + +spring: + application: + name: workspace_server # 애플리케이션 이름 + datasource: + url: jdbc:postgresql://${DB_HOST:localhost}:${DB_PORT:5432}/${DB_NAME:jootalkpia} + username: ${DB_USER} # 데이터베이스 사용자 + password: ${DB_PASSWORD} # 데이터베이스 비밀번호 + driver-class-name: org.postgresql.Driver + jpa: + hibernate: + ddl-auto: update + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQLDialect + logging: + level: + org.hibernate.SQL: DEBUG # Hibernate SQL 로그 출력 + org.hibernate.type.descriptor.sql: TRACE # SQL 매개변수 출력 +management: + endpoints: + web: + exposure: + include: "*" # 모든 관리 엔드포인트 노출 + endpoint: + health: + show-details: always # /actuator/health에 세부 정보 표시 diff --git a/src/backend/workspace_server/src/test/java/com/jootalkpia/workspace_server/WorkspaceServerApplicationTests.java b/src/backend/workspace_server/src/test/java/com/jootalkpia/workspace_server/WorkspaceServerApplicationTests.java new file mode 100644 index 00000000..8d8d9f01 --- /dev/null +++ b/src/backend/workspace_server/src/test/java/com/jootalkpia/workspace_server/WorkspaceServerApplicationTests.java @@ -0,0 +1,13 @@ +package com.jootalkpia.workspace_server; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class WorkspaceServerApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/src/infra/docker-compose.yml b/src/infra/docker-compose.yml new file mode 100644 index 00000000..697211f1 --- /dev/null +++ b/src/infra/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.8' + +services: + chat-service: + image: mirlee/chat-service:latest + container_name: chat-service + ports: + - "8080:8080" + environment: + DB_USER: ${DB_USER} # PostgreSQL 사용자 + DB_PASSWORD: ${DB_PASSWORD} # PostgreSQL 비밀번호 + DB_NAME: ${DB_NAME} # 공통 데이터베이스 이름 + DB_HOST: db # PostgreSQL 컨테이너 이름 (서비스 이름과 동일) + DB_PORT: ${DB_PORT} # PostgreSQL 기본 포트 + depends_on: + - db + + db: + image: postgres:15 + container_name: jutalkpia-db + environment: + POSTGRES_USER: ${DB_USER} # PostgreSQL 사용자 + POSTGRES_PASSWORD: ${DB_PASSWORD} # PostgreSQL 비밀번호 + POSTGRES_DB: ${DB_NAME} # 공통 데이터베이스 이름 + ports: + - "5432:5432" # 로컬 포트 5432 -> 컨테이너 포트 5432 + volumes: + - postgres_data:/var/lib/postgresql/data # PostgreSQL 데이터 영구 저장소 + +volumes: + postgres_data: +