diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/README.md b/README.md index 5a6bd81..8d1c638 100644 --- a/README.md +++ b/README.md @@ -101,3 +101,4 @@ 빌드 결과물을 Executable jar 형태로 만들어 위 Branch에 함께 업로드 하시고, README에 다운로드 링크 정보를 넣어주시기 바랍니다. GitHub의 용량 문제로 업로드가 안되는 경우 다른 곳(개인 구글 드라이브 등)에 업로드 한 후 해당 다운로드 링크 정보를 README에 넣어주셔도 됩니다. 해당 파일을 다운로드 및 실행(e.g. java -jar project.jar)하여 요구 사항 기능 검증을 진행하게 됩니다. 해당 파일을 다운로드할 수 없거나 실행 시 에러가 발생하는 경우에는 기능 점검을 진행하지 않습니다. 온보딩 프로젝트 제출 전 해당 실행 파일 다운로드 및 정상 동작 여부를 체크해 주시기 바랍니다. + diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..041aedf --- /dev/null +++ b/build.gradle @@ -0,0 +1,50 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.3.2' + id 'io.spring.dependency-management' version '1.1.6' +} + +group = 'com.innercircle' +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-validation' + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.h2database:h2' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' + + // MapStruct + implementation 'org.mapstruct:mapstruct:1.4.2.Final' + annotationProcessor "org.mapstruct:mapstruct-processor:1.4.2.Final" + annotationProcessor( + 'org.projectlombok:lombok', + 'org.projectlombok:lombok-mapstruct-binding:0.1.0' + ) +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e644113 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 0000000..ac72c34 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..b740cf1 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/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/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 "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=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/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..25da30d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 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/settings.gradle b/settings.gradle new file mode 100644 index 0000000..229417f --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'servey' diff --git a/src/main/java/com/innercircle/survey/SurveyApplication.java b/src/main/java/com/innercircle/survey/SurveyApplication.java new file mode 100644 index 0000000..e946405 --- /dev/null +++ b/src/main/java/com/innercircle/survey/SurveyApplication.java @@ -0,0 +1,13 @@ +package com.innercircle.survey; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SurveyApplication { + + public static void main(String[] args) { + SpringApplication.run(SurveyApplication.class, args); + } + +} diff --git a/src/main/java/com/innercircle/survey/application/survey/SurveyAdminFacade.java b/src/main/java/com/innercircle/survey/application/survey/SurveyAdminFacade.java new file mode 100644 index 0000000..5919446 --- /dev/null +++ b/src/main/java/com/innercircle/survey/application/survey/SurveyAdminFacade.java @@ -0,0 +1,25 @@ +package com.innercircle.survey.application.survey; + +import com.innercircle.survey.domain.survey.Survey; +import com.innercircle.survey.domain.survey.SurveyAdminService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class SurveyAdminFacade { + + private final SurveyAdminService surveyAdminService; + + public String registerSurvey(Survey survey) { + var surveyToken = surveyAdminService.registerSurvey(survey); + // 알림메시지 + return surveyToken; + } + + public void updateSurvey(Survey updateSurvey) { + + } +} diff --git a/src/main/java/com/innercircle/survey/common/exception/BaseException.java b/src/main/java/com/innercircle/survey/common/exception/BaseException.java new file mode 100644 index 0000000..ca53bff --- /dev/null +++ b/src/main/java/com/innercircle/survey/common/exception/BaseException.java @@ -0,0 +1,26 @@ +package com.innercircle.survey.common.exception; + +import com.innercircle.survey.common.response.ErrorCode; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class BaseException extends RuntimeException{ + private ErrorCode errorCode; + + public BaseException(ErrorCode errorCode) { + super(errorCode.getErrorMsg()); + this.errorCode = errorCode; + } + + public BaseException(String message, ErrorCode errorCode) { + super(message); + this.errorCode = errorCode; + } + + public BaseException(String message, ErrorCode errorCode, Throwable cause) { + super(message, cause); + this.errorCode = errorCode; + } +} diff --git a/src/main/java/com/innercircle/survey/common/exception/EntityNotFoundException.java b/src/main/java/com/innercircle/survey/common/exception/EntityNotFoundException.java new file mode 100644 index 0000000..85e148c --- /dev/null +++ b/src/main/java/com/innercircle/survey/common/exception/EntityNotFoundException.java @@ -0,0 +1,14 @@ +package com.innercircle.survey.common.exception; + +import com.innercircle.survey.common.response.ErrorCode; + +public class EntityNotFoundException extends BaseException{ + + public EntityNotFoundException(ErrorCode errorCode) { + super(ErrorCode.COMMON_ENTITY_NOT_FOUND); + } + + public EntityNotFoundException(String message) { + super(message, ErrorCode.COMMON_ENTITY_NOT_FOUND); + } +} diff --git a/src/main/java/com/innercircle/survey/common/exception/IllegalStatusException.java b/src/main/java/com/innercircle/survey/common/exception/IllegalStatusException.java new file mode 100644 index 0000000..9eac655 --- /dev/null +++ b/src/main/java/com/innercircle/survey/common/exception/IllegalStatusException.java @@ -0,0 +1,15 @@ +package com.innercircle.survey.common.exception; + + +import com.innercircle.survey.common.response.ErrorCode; + +public class IllegalStatusException extends BaseException { + + public IllegalStatusException() { + super(ErrorCode.COMMON_ILLEGAL_STATUS); + } + + public IllegalStatusException(String message) { + super(message, ErrorCode.COMMON_ILLEGAL_STATUS); + } +} diff --git a/src/main/java/com/innercircle/survey/common/exception/InvalidParamException.java b/src/main/java/com/innercircle/survey/common/exception/InvalidParamException.java new file mode 100644 index 0000000..77687b6 --- /dev/null +++ b/src/main/java/com/innercircle/survey/common/exception/InvalidParamException.java @@ -0,0 +1,22 @@ +package com.innercircle.survey.common.exception; + +import com.innercircle.survey.common.response.ErrorCode; + +public class InvalidParamException extends BaseException { + + public InvalidParamException() { + super(ErrorCode.COMMON_INVALID_PARAMETER); + } + + public InvalidParamException(ErrorCode errorCode) { + super(errorCode); + } + + public InvalidParamException(String errorMsg) { + super(errorMsg, ErrorCode.COMMON_INVALID_PARAMETER); + } + + public InvalidParamException(String message, ErrorCode errorCode) { + super(message, errorCode); + } +} diff --git a/src/main/java/com/innercircle/survey/common/interceptor/CommonHttpRequestInterceptor.java b/src/main/java/com/innercircle/survey/common/interceptor/CommonHttpRequestInterceptor.java new file mode 100644 index 0000000..b4fb6fa --- /dev/null +++ b/src/main/java/com/innercircle/survey/common/interceptor/CommonHttpRequestInterceptor.java @@ -0,0 +1,29 @@ +package com.innercircle.survey.common.interceptor; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.MDC; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.servlet.HandlerInterceptor; + +import java.util.UUID; + +@Slf4j +@Component +public class CommonHttpRequestInterceptor implements HandlerInterceptor { + + public static final String HEADER_REQUEST_UUID_KEY = "x-request-id"; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + String requestEventId = request.getHeader(HEADER_REQUEST_UUID_KEY); + if (StringUtils.isEmpty(requestEventId)) { + requestEventId = UUID.randomUUID().toString(); + } + + MDC.put(HEADER_REQUEST_UUID_KEY, requestEventId); + return true; + } +} diff --git a/src/main/java/com/innercircle/survey/common/response/CommonControllerAdvice.java b/src/main/java/com/innercircle/survey/common/response/CommonControllerAdvice.java new file mode 100644 index 0000000..77d37c7 --- /dev/null +++ b/src/main/java/com/innercircle/survey/common/response/CommonControllerAdvice.java @@ -0,0 +1,75 @@ +package com.innercircle.survey.common.response; + +import com.innercircle.survey.common.exception.BaseException; +import com.innercircle.survey.common.interceptor.CommonHttpRequestInterceptor; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.MDC; +import org.springframework.core.NestedExceptionUtils; +import org.springframework.http.HttpStatus; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +@Slf4j +@ControllerAdvice +public class CommonControllerAdvice { + + /** + * http status: 500 AND result: FAIL + * 시스템 예외 상황. 집중 모니터링 대상 + * + * @param e + * @return + */ + @ResponseBody + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(value = Exception.class) + public CommonResponse onException(Exception e) { + String eventId = MDC.get(CommonHttpRequestInterceptor.HEADER_REQUEST_UUID_KEY); + log.error("eventId = {}", eventId, e); + return CommonResponse.fail(ErrorCode.COMMON_SYSTEM_ERROR); + } + + /** + * http status: 200 AND result: FAIL + * 시스템은 이슈 없고, 비즈니스 로직 처리에서 에러가 발생함 + * + * @param e + * @return + */ + @ResponseBody + @ResponseStatus(HttpStatus.OK) + @ExceptionHandler(value = BaseException.class) + public CommonResponse onBaseException(BaseException e) { + String eventId = MDC.get(CommonHttpRequestInterceptor.HEADER_REQUEST_UUID_KEY); + log.error("[BaseException] eventId = {}, errorCode = {}, errorMsg = {}", eventId, e.getErrorCode(), e.getMessage()); + return CommonResponse.fail(e.getMessage(), e.getErrorCode().name()); + } + + /** + * http status: 400 AND result: FAIL + * request parameter 에러 + * + * @param e + * @return + */ + @ResponseBody + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(value = {MethodArgumentNotValidException.class}) + public CommonResponse methodArgumentNotValidException(MethodArgumentNotValidException e) { + String eventId = MDC.get(CommonHttpRequestInterceptor.HEADER_REQUEST_UUID_KEY); + log.warn("[BaseException] eventId = {}, errorMsg = {}", eventId, NestedExceptionUtils.getMostSpecificCause(e).getMessage()); + BindingResult bindingResult = e.getBindingResult(); + FieldError fe = bindingResult.getFieldError(); + if (fe != null) { + String message = "Request Error" + " " + fe.getField() + "=" + fe.getRejectedValue() + "(" + fe.getDefaultMessage() + ")"; + return CommonResponse.fail(message, ErrorCode.COMMON_INVALID_PARAMETER.name()); + } else { + return CommonResponse.fail(ErrorCode.COMMON_INVALID_PARAMETER.getErrorMsg(), ErrorCode.COMMON_INVALID_PARAMETER.name()); + } + } +} diff --git a/src/main/java/com/innercircle/survey/common/response/CommonResponse.java b/src/main/java/com/innercircle/survey/common/response/CommonResponse.java new file mode 100644 index 0000000..0d024ca --- /dev/null +++ b/src/main/java/com/innercircle/survey/common/response/CommonResponse.java @@ -0,0 +1,53 @@ +package com.innercircle.survey.common.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CommonResponse { + private Result result; + private T data; + private String message; + private String errorCode; + + public static CommonResponse success(T data, String message) { + return (CommonResponse) CommonResponse.builder() + .result(Result.SUCCESS) + .data(data) + .message(message) + .build(); + } + + public static CommonResponse success(T data) { + return success(data, null); + } + + public static CommonResponse success() { + return success(null, null); + } + + public static CommonResponse fail(String message, String errorCode) { + return CommonResponse.builder() + .result(Result.FAIL) + .message(message) + .errorCode(errorCode) + .build(); + } + + public static CommonResponse fail(ErrorCode errorCode) { + return CommonResponse.builder() + .result(Result.FAIL) + .message(errorCode.getErrorMsg()) + .errorCode(errorCode.name()) + .build(); + } + + public enum Result { + SUCCESS, FAIL + } +} diff --git a/src/main/java/com/innercircle/survey/common/response/ErrorCode.java b/src/main/java/com/innercircle/survey/common/response/ErrorCode.java new file mode 100644 index 0000000..028742c --- /dev/null +++ b/src/main/java/com/innercircle/survey/common/response/ErrorCode.java @@ -0,0 +1,19 @@ +package com.innercircle.survey.common.response; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum ErrorCode { + COMMON_SYSTEM_ERROR("일시적인 오류가 발생하였습니다. 잠시 후 다시 시도해주세요"), + COMMON_INVALID_PARAMETER("요청한 값이 올바르지 않습니다."), + COMMON_ENTITY_NOT_FOUND("존재하지 않는 엔티티입니다."), + COMMON_ILLEGAL_STATUS("잘못된 상태값입니다."); + + private final String errorMsg; + + public String getErrorMsg(Object... arg) { + return String.format(errorMsg, arg); + } +} diff --git a/src/main/java/com/innercircle/survey/common/util/TokenGenerator.java b/src/main/java/com/innercircle/survey/common/util/TokenGenerator.java new file mode 100644 index 0000000..5402d42 --- /dev/null +++ b/src/main/java/com/innercircle/survey/common/util/TokenGenerator.java @@ -0,0 +1,15 @@ +package com.innercircle.survey.common.util; + +import org.apache.commons.lang3.RandomStringUtils; + +public class TokenGenerator { + private static final int TOKEN_LENGTH = 20; + + public static String randomCharacter(int length) { + return RandomStringUtils.randomAlphanumeric(length); + } + + public static String randomCharacterWithPrefix(String prefix) { + return prefix + RandomStringUtils.randomAlphanumeric(TOKEN_LENGTH - prefix.length()); + } +} diff --git a/src/main/java/com/innercircle/survey/config/JpaAuditingConfiguration.java b/src/main/java/com/innercircle/survey/config/JpaAuditingConfiguration.java new file mode 100644 index 0000000..f610fc2 --- /dev/null +++ b/src/main/java/com/innercircle/survey/config/JpaAuditingConfiguration.java @@ -0,0 +1,9 @@ +package com.innercircle.survey.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@EnableJpaAuditing +@Configuration +public class JpaAuditingConfiguration { +} diff --git a/src/main/java/com/innercircle/survey/config/SwaggerConfiguration.java b/src/main/java/com/innercircle/survey/config/SwaggerConfiguration.java new file mode 100644 index 0000000..ab9d71b --- /dev/null +++ b/src/main/java/com/innercircle/survey/config/SwaggerConfiguration.java @@ -0,0 +1,24 @@ +package com.innercircle.survey.config; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.servers.Server; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfiguration { + + @Bean + public OpenAPI openAPI(@Value("${springdoc.version}") String springdocVersion) { + Info info = new Info() + .title("Survey API Document") + .version(springdocVersion) + .description("Survey API 명세서"); + + return new OpenAPI() + .addServersItem(new Server().url("/")) + .info(info); + } +} diff --git a/src/main/java/com/innercircle/survey/domain/AbstractEntity.java b/src/main/java/com/innercircle/survey/domain/AbstractEntity.java new file mode 100644 index 0000000..70e0c8b --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/AbstractEntity.java @@ -0,0 +1,22 @@ +package com.innercircle.survey.domain; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.ZonedDateTime; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public class AbstractEntity { + + @CreationTimestamp + private ZonedDateTime createdAt; + + @UpdateTimestamp + private ZonedDateTime updatedAt; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/Survey.java b/src/main/java/com/innercircle/survey/domain/survey/Survey.java new file mode 100644 index 0000000..914e43a --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/Survey.java @@ -0,0 +1,33 @@ +package com.innercircle.survey.domain.survey; + +import com.innercircle.survey.common.util.TokenGenerator; +import com.innercircle.survey.domain.AbstractEntity; +import com.innercircle.survey.domain.survey.question.*; +import com.innercircle.survey.domain.survey.response.SurveyResponse; +import jakarta.persistence.*; +import lombok.Getter; + +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@Table(name = "surveys") +public class Survey extends AbstractEntity { + + private static final String SURVEY_PREFIX = "sv_"; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String surveyToken; + private Long version; + private ZonedDateTime surveyCreatedAt; + + @OneToMany(mappedBy = "survey") + private List surveyQuestions = new ArrayList<>(); + + @OneToMany(mappedBy = "survey") + private List surveyResponses = new ArrayList<>(); +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/SurveyAdminService.java b/src/main/java/com/innercircle/survey/domain/survey/SurveyAdminService.java new file mode 100644 index 0000000..3651d73 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/SurveyAdminService.java @@ -0,0 +1,5 @@ +package com.innercircle.survey.domain.survey; + +public interface SurveyAdminService { + String registerSurvey(Survey survey); +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/SurveyAdminServiceImpl.java b/src/main/java/com/innercircle/survey/domain/survey/SurveyAdminServiceImpl.java new file mode 100644 index 0000000..5eb5ba3 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/SurveyAdminServiceImpl.java @@ -0,0 +1,14 @@ +package com.innercircle.survey.domain.survey; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class SurveyAdminServiceImpl implements SurveyAdminService{ + + @Override + public String registerSurvey(Survey survey) { + return ""; + } +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/SurveyCommand.java b/src/main/java/com/innercircle/survey/domain/survey/SurveyCommand.java new file mode 100644 index 0000000..d13d0d7 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/SurveyCommand.java @@ -0,0 +1,8 @@ +package com.innercircle.survey.domain.survey; + +public class SurveyCommand { + + public static class RegisterSurveyRequest { + + } +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/SurveyReader.java b/src/main/java/com/innercircle/survey/domain/survey/SurveyReader.java new file mode 100644 index 0000000..1c7d5b4 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/SurveyReader.java @@ -0,0 +1,4 @@ +package com.innercircle.survey.domain.survey; + +public interface SurveyReader { +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/SurveyStore.java b/src/main/java/com/innercircle/survey/domain/survey/SurveyStore.java new file mode 100644 index 0000000..65b1e34 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/SurveyStore.java @@ -0,0 +1,5 @@ +package com.innercircle.survey.domain.survey; + +public interface SurveyStore { + Survey store(Survey survey); +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/question/MultipleSelectOption.java b/src/main/java/com/innercircle/survey/domain/survey/question/MultipleSelectOption.java new file mode 100644 index 0000000..573fb8a --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/question/MultipleSelectOption.java @@ -0,0 +1,23 @@ +package com.innercircle.survey.domain.survey.question; + +import com.innercircle.survey.domain.AbstractEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "multiple_select_options") +public class MultipleSelectOption extends AbstractEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "question_id") + private SurveyMultipleSelect question; + private Long sequence; + private String optionText; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/question/QuestionType.java b/src/main/java/com/innercircle/survey/domain/survey/question/QuestionType.java new file mode 100644 index 0000000..8149574 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/question/QuestionType.java @@ -0,0 +1,15 @@ +package com.innercircle.survey.domain.survey.question; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum QuestionType { + SHORT_ANSWER("단답형 질문"), + LONG_ANSWER("장문형 질문"), + SINGLE_SELECT("단일 선택형 질문"), + MULTIPLE_SELECT("다중 선택형 질문"); + + private final String desc; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/question/SingleSelectOption.java b/src/main/java/com/innercircle/survey/domain/survey/question/SingleSelectOption.java new file mode 100644 index 0000000..7864142 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/question/SingleSelectOption.java @@ -0,0 +1,24 @@ +package com.innercircle.survey.domain.survey.question; + +import com.innercircle.survey.domain.AbstractEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "single_select_options") +public class SingleSelectOption extends AbstractEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "question_id") + private SurveySingleSelect question; + + private Long sequence; + private String optionText; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/question/SurveyLongAnswer.java b/src/main/java/com/innercircle/survey/domain/survey/question/SurveyLongAnswer.java new file mode 100644 index 0000000..0beddf5 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/question/SurveyLongAnswer.java @@ -0,0 +1,20 @@ +package com.innercircle.survey.domain.survey.question; + +import com.innercircle.survey.domain.AbstractEntity; +import com.innercircle.survey.domain.survey.Survey; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "survey_long_answer") +public class SurveyLongAnswer extends SurveyQuestion { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/question/SurveyMultipleSelect.java b/src/main/java/com/innercircle/survey/domain/survey/question/SurveyMultipleSelect.java new file mode 100644 index 0000000..e3837ed --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/question/SurveyMultipleSelect.java @@ -0,0 +1,26 @@ +package com.innercircle.survey.domain.survey.question; + +import com.innercircle.survey.domain.AbstractEntity; +import com.innercircle.survey.domain.survey.Survey; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "survey_multi_select") +public class SurveyMultipleSelect extends SurveyQuestion { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToMany(mappedBy = "question") + private List options = new ArrayList<>(); +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/question/SurveyQuestion.java b/src/main/java/com/innercircle/survey/domain/survey/question/SurveyQuestion.java new file mode 100644 index 0000000..38b6f00 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/question/SurveyQuestion.java @@ -0,0 +1,29 @@ +package com.innercircle.survey.domain.survey.question; + + +import com.innercircle.survey.domain.AbstractEntity; +import com.innercircle.survey.domain.survey.Survey; +import jakarta.persistence.*; +import lombok.Getter; + +@Getter +@Entity +@Table(name = "survey_questions") +@Inheritance(strategy = InheritanceType.JOINED) +public class SurveyQuestion extends AbstractEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "survey_id") + private Survey survey; + + private String questionText; + private Long version; + private Long sequence; + + @Enumerated(EnumType.STRING) + private QuestionType questionType; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/question/SurveyShortAnswer.java b/src/main/java/com/innercircle/survey/domain/survey/question/SurveyShortAnswer.java new file mode 100644 index 0000000..50b2336 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/question/SurveyShortAnswer.java @@ -0,0 +1,21 @@ +package com.innercircle.survey.domain.survey.question; + + +import com.innercircle.survey.domain.AbstractEntity; +import com.innercircle.survey.domain.survey.Survey; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "survey_short_answer") +public class SurveyShortAnswer extends SurveyQuestion { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/question/SurveySingleSelect.java b/src/main/java/com/innercircle/survey/domain/survey/question/SurveySingleSelect.java new file mode 100644 index 0000000..54a7edc --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/question/SurveySingleSelect.java @@ -0,0 +1,25 @@ +package com.innercircle.survey.domain.survey.question; + +import com.innercircle.survey.domain.AbstractEntity; +import com.innercircle.survey.domain.survey.Survey; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Table(name = "survey_single_select") +public class SurveySingleSelect extends SurveyQuestion { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToMany(mappedBy = "question") + private List options = new ArrayList<>(); +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/response/LongAnswerResponse.java b/src/main/java/com/innercircle/survey/domain/survey/response/LongAnswerResponse.java new file mode 100644 index 0000000..f918738 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/response/LongAnswerResponse.java @@ -0,0 +1,12 @@ +package com.innercircle.survey.domain.survey.response; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; + +@Getter +@Entity +@Table(name = "long_answer_responses") +public class LongAnswerResponse extends QuestionResponse{ + private String answerText; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/response/MultipleSelectResponse.java b/src/main/java/com/innercircle/survey/domain/survey/response/MultipleSelectResponse.java new file mode 100644 index 0000000..58cbcea --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/response/MultipleSelectResponse.java @@ -0,0 +1,18 @@ +package com.innercircle.survey.domain.survey.response; + + +import com.innercircle.survey.domain.survey.question.MultipleSelectOption; +import jakarta.persistence.*; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@Table(name = "multiple_select_responses") +public class MultipleSelectResponse extends QuestionResponse{ + + @OneToMany(mappedBy = "response") + private List selectOptions = new ArrayList<>(); +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/response/MultipleSelectResponseOption.java b/src/main/java/com/innercircle/survey/domain/survey/response/MultipleSelectResponseOption.java new file mode 100644 index 0000000..f0f9cc7 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/response/MultipleSelectResponseOption.java @@ -0,0 +1,24 @@ +package com.innercircle.survey.domain.survey.response; + +import com.innercircle.survey.domain.AbstractEntity; +import com.innercircle.survey.domain.survey.question.MultipleSelectOption; +import jakarta.persistence.*; +import lombok.Getter; + +@Getter +@Entity +@Table(name = "multiple_select_response_options") +public class MultipleSelectResponseOption extends AbstractEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "response_id") + private MultipleSelectResponse response; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "option_id") + private MultipleSelectOption option; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/response/QuestionResponse.java b/src/main/java/com/innercircle/survey/domain/survey/response/QuestionResponse.java new file mode 100644 index 0000000..d74e714 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/response/QuestionResponse.java @@ -0,0 +1,25 @@ +package com.innercircle.survey.domain.survey.response; + +import com.innercircle.survey.domain.AbstractEntity; +import com.innercircle.survey.domain.survey.question.SurveyQuestion; +import jakarta.persistence.*; +import lombok.Getter; + +@Getter +@Entity +@Table(name = "question_responses") +@Inheritance(strategy = InheritanceType.JOINED) +public class QuestionResponse extends AbstractEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "response_id") + private SurveyResponse response; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "question_id") + private SurveyQuestion question; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/response/ShortAnswerResponse.java b/src/main/java/com/innercircle/survey/domain/survey/response/ShortAnswerResponse.java new file mode 100644 index 0000000..88f4843 --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/response/ShortAnswerResponse.java @@ -0,0 +1,12 @@ +package com.innercircle.survey.domain.survey.response; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; + +@Getter +@Entity +@Table(name = "short_answer_responses") +public class ShortAnswerResponse extends QuestionResponse{ + private String answerText; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/response/SingleSelectResponse.java b/src/main/java/com/innercircle/survey/domain/survey/response/SingleSelectResponse.java new file mode 100644 index 0000000..476e49d --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/response/SingleSelectResponse.java @@ -0,0 +1,15 @@ +package com.innercircle.survey.domain.survey.response; + +import com.innercircle.survey.domain.survey.question.SingleSelectOption; +import jakarta.persistence.*; +import lombok.Getter; + +@Getter +@Entity +@Table(name = "single_select_response") +public class SingleSelectResponse extends QuestionResponse{ + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "selected_option_id") + private SingleSelectOption selectOption; +} diff --git a/src/main/java/com/innercircle/survey/domain/survey/response/SurveyResponse.java b/src/main/java/com/innercircle/survey/domain/survey/response/SurveyResponse.java new file mode 100644 index 0000000..0a1ff6d --- /dev/null +++ b/src/main/java/com/innercircle/survey/domain/survey/response/SurveyResponse.java @@ -0,0 +1,26 @@ +package com.innercircle.survey.domain.survey.response; + +import com.innercircle.survey.domain.AbstractEntity; +import com.innercircle.survey.domain.survey.Survey; +import jakarta.persistence.*; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Entity +@Table(name = "survey_responses") +public class SurveyResponse extends AbstractEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "survey_id") + private Survey survey; + + @OneToMany(mappedBy = "response") + private List questionResponses = new ArrayList<>(); +} diff --git a/src/main/java/com/innercircle/survey/infrastructure/survey/SurveyRepository.java b/src/main/java/com/innercircle/survey/infrastructure/survey/SurveyRepository.java new file mode 100644 index 0000000..a58faa0 --- /dev/null +++ b/src/main/java/com/innercircle/survey/infrastructure/survey/SurveyRepository.java @@ -0,0 +1,7 @@ +package com.innercircle.survey.infrastructure.survey; + +import com.innercircle.survey.domain.survey.Survey; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface SurveyRepository extends JpaRepository { +} diff --git a/src/main/java/com/innercircle/survey/infrastructure/survey/SurveyStoreImpl.java b/src/main/java/com/innercircle/survey/infrastructure/survey/SurveyStoreImpl.java new file mode 100644 index 0000000..e42010b --- /dev/null +++ b/src/main/java/com/innercircle/survey/infrastructure/survey/SurveyStoreImpl.java @@ -0,0 +1,20 @@ +package com.innercircle.survey.infrastructure.survey; + +import com.innercircle.survey.domain.survey.Survey; +import com.innercircle.survey.domain.survey.SurveyStore; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class SurveyStoreImpl implements SurveyStore { + + private final SurveyRepository surveyRepository; + + @Override + public Survey store(Survey survey) { + return surveyRepository.save(survey); + } +} diff --git a/src/main/java/com/innercircle/survey/interfaces/doc/SurveyAdminControllerDoc.java b/src/main/java/com/innercircle/survey/interfaces/doc/SurveyAdminControllerDoc.java new file mode 100644 index 0000000..11a5670 --- /dev/null +++ b/src/main/java/com/innercircle/survey/interfaces/doc/SurveyAdminControllerDoc.java @@ -0,0 +1,19 @@ +package com.innercircle.survey.interfaces.doc; + +import com.innercircle.survey.common.response.CommonResponse; +import com.innercircle.survey.interfaces.survey.SurveyDto; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; + +@Tag(name = "Surveys Admin", description = "설문조사 도메인 API (Admin)") +public interface SurveyAdminControllerDoc { + + @Operation(summary = "설문조사 생성", description = "설문조사를 생성합니다.") + CommonResponse registerSurvey(SurveyDto.RegisterRequest request); + + @Operation(summary = "설문조사 수정", description = "설문조사를 수정합니다.") + CommonResponse updateSurvey(SurveyDto.UpdateRequest request); + + @Operation(summary = "설문조사 결과", description = "설문조사 결과를 확인합니다.") + CommonResponse surveyResponseResult(SurveyDto.ResponseResultRequest request); +} diff --git a/src/main/java/com/innercircle/survey/interfaces/doc/SurveyClientControllerDoc.java b/src/main/java/com/innercircle/survey/interfaces/doc/SurveyClientControllerDoc.java new file mode 100644 index 0000000..b2693ca --- /dev/null +++ b/src/main/java/com/innercircle/survey/interfaces/doc/SurveyClientControllerDoc.java @@ -0,0 +1,17 @@ +package com.innercircle.survey.interfaces.doc; + +import com.innercircle.survey.common.response.CommonResponse; +import com.innercircle.survey.interfaces.survey.SurveyDto; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; + +@Tag(name = "Survey Client", description = "설문조사 도메인 API (Client)") +public interface SurveyClientControllerDoc { + + @Operation(summary = "설문조사 데이터 가져오기", description = "설문조사 데이터를 가져옵니다.") + CommonResponse getSurvey(String surveyToken); + + @Operation(summary = "설문조사 데이터 제출", description = "설문조사를 제출합니다.") + CommonResponse submitSurvey(HttpServletRequest request, SurveyDto.SurveySubmitRequest surveySubmitRequest); +} diff --git a/src/main/java/com/innercircle/survey/interfaces/survey/SurveyAdminController.java b/src/main/java/com/innercircle/survey/interfaces/survey/SurveyAdminController.java new file mode 100644 index 0000000..1988c8b --- /dev/null +++ b/src/main/java/com/innercircle/survey/interfaces/survey/SurveyAdminController.java @@ -0,0 +1,40 @@ +package com.innercircle.survey.interfaces.survey; + +import com.innercircle.survey.application.survey.SurveyAdminFacade; +import com.innercircle.survey.common.response.CommonResponse; +import com.innercircle.survey.domain.survey.Survey; +import com.innercircle.survey.interfaces.doc.SurveyAdminControllerDoc; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +@Slf4j +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/surveys") +public class SurveyAdminController implements SurveyAdminControllerDoc { + + private final SurveyAdminFacade surveyAdminFacade; + + + @PostMapping + public CommonResponse registerSurvey(@RequestBody @Valid SurveyDto.RegisterRequest request) { + + var survey = request.toEntity(); + var surveyToken = surveyAdminFacade.registerSurvey(survey); + return CommonResponse.success(SurveyDto.RegisterResponse.of(surveyToken)); + } + + @PutMapping + public CommonResponse updateSurvey(@RequestBody @Valid SurveyDto.UpdateRequest request) { + var updateSurvey = request.toEntity(); + surveyAdminFacade.updateSurvey(updateSurvey); + return CommonResponse.success("OK"); + } + + public CommonResponse surveyResponseResult(SurveyDto.ResponseResultRequest request) { + + return null; + } +} diff --git a/src/main/java/com/innercircle/survey/interfaces/survey/SurveyClientController.java b/src/main/java/com/innercircle/survey/interfaces/survey/SurveyClientController.java new file mode 100644 index 0000000..2470811 --- /dev/null +++ b/src/main/java/com/innercircle/survey/interfaces/survey/SurveyClientController.java @@ -0,0 +1,24 @@ +package com.innercircle.survey.interfaces.survey; + +import com.innercircle.survey.common.response.CommonResponse; +import com.innercircle.survey.interfaces.doc.SurveyClientControllerDoc; +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/survey") +public class SurveyClientController implements SurveyClientControllerDoc { + + + @GetMapping("/{surveyToken}") + public CommonResponse getSurvey(@PathVariable("surveyToken") String surveyToken) { + return null; + } + + @PostMapping("/{surveyToken}") + public CommonResponse submitSurvey(HttpServletRequest request, SurveyDto.SurveySubmitRequest surveySubmitRequest) { + return null; + } +} diff --git a/src/main/java/com/innercircle/survey/interfaces/survey/SurveyDto.java b/src/main/java/com/innercircle/survey/interfaces/survey/SurveyDto.java new file mode 100644 index 0000000..3dbc56d --- /dev/null +++ b/src/main/java/com/innercircle/survey/interfaces/survey/SurveyDto.java @@ -0,0 +1,160 @@ +package com.innercircle.survey.interfaces.survey; + + +import com.innercircle.survey.domain.survey.Survey; +import com.innercircle.survey.domain.survey.question.SurveyLongAnswer; +import com.innercircle.survey.domain.survey.question.SurveyMultipleSelect; +import com.innercircle.survey.domain.survey.question.SurveyShortAnswer; +import com.innercircle.survey.domain.survey.question.SurveySingleSelect; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +public class SurveyDto { + + @Data + @Schema + public static class RegisterRequest { + private String surveyName; + private String surveyDesc; + private List shortAnswerTypeQuestions; + private List longAnswerTypeQuestions; + private List singleSelectListQuestions; + private List multipleSelectListQuestions; + + @Data + public static class ShortAnswerTypeQuestion extends QuestionBase { + + private String question; + +// public SurveyShortAnswer toEntity() { +// return SurveyShortAnswer.builder() +// .question(question) +// .build(); +// } + } + + @Data + public static class LongAnswerTypeQuestion extends QuestionBase { + private String question; + +// public SurveyLongAnswer toEntity() { +// return SurveyLongAnswer.builder() +// .question(question) +// .build(); +// } + } + + @Data + public static class SingleSelectListQuestion extends QuestionBase { + private String question; + private List questionOptions; + +// public SurveySingleSelect toEntity() { +// return SurveySingleSelect.builder() +// .question(question) +// .build(); +// } + } + + @Data + public static class MultipleSelectListQuestion extends QuestionBase { + private String question; + private List questionOptions; + +// public SurveyMultipleSelect toEntity() { +// return SurveyMultipleSelect.builder() +// .question(question) +// .build(); +// } + } + + @Data + public static class QuestionOption { + private Long sequence; + private String content; + } + + @Data + public static class QuestionBase { + private String question; + private Long sequence; + private boolean mustYN; + private QuestType questType; + } + + @Getter + @RequiredArgsConstructor + public enum QuestType { + SHORT("단답형"), + LONG("장문형"), + SINGLE_SELECT_LIST("단일 선택 리스트"), + MULTIPLE_SELECT_LIST("다중 선택 리스트"); + private final String desc; + } + + public Survey toEntity() { + Survey survey = new Survey(); +// if (shortAnswerTypeQuestions != null) { +// shortAnswerTypeQuestions.stream() +// .map(ShortAnswerTypeQuestion::toEntity) +// .forEach(survey::addShortAnswer); +// } +// if (longAnswerTypeQuestions != null) { +// longAnswerTypeQuestions.stream() +// .map(LongAnswerTypeQuestion::toEntity) +// .forEach(survey::addLongAnswer); +// } +// if (singleSelectListQuestions != null) { +// singleSelectListQuestions.stream() +// .map(SingleSelectListQuestion::toEntity) +// .forEach(survey::addSingleSelect); +// } +// if (multipleSelectListQuestions != null) { +// multipleSelectListQuestions.stream() +// .map(MultipleSelectListQuestion::toEntity) +// .forEach(survey::addMultipleSelect); +// } + return survey; + } + } + + @Data + public static class ResponseResultRequest { + + } + + @Data + public static class SurveyRequest { + } + + public class SurveySubmitRequest { + } + + /** + * Response DTO + * */ + + @Getter + @Builder + public static class RegisterResponse { + private final String surveyToken; + + public static RegisterResponse of(String surveyToken) { + return RegisterResponse.builder() + .surveyToken(surveyToken) + .build(); + } + } + + public class UpdateRequest { + + public Survey toEntity() { + return null; + } + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..b416111 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,32 @@ +spring: + datasource: + url: jdbc:h2:mem:testdb + driver-class-name: org.h2.Driver + username: sa + password: + hibernate: + ddl-auto: update + show-sql: true + properties: + hibernate: + format_sql: true + h2: + console: + enabled: true + path: /h2-console +springdoc: + version: v1 + packages-to-scan: com.innercircle.survey.interfaces + default-produces-media-type: application/json + swagger-ui: + path: /doc.html + tags-sorter: alpha + operations-sorter: alpha + doc-expansion: none + disable-swagger-default-url: true + api-docs: + path: /api-docs/json + groups: + enabled: true + cache: + disabled: true diff --git a/src/test/java/com/innercircle/survey/ServeyApplicationTests.java b/src/test/java/com/innercircle/survey/ServeyApplicationTests.java new file mode 100644 index 0000000..acf0d1a --- /dev/null +++ b/src/test/java/com/innercircle/survey/ServeyApplicationTests.java @@ -0,0 +1,13 @@ +package com.innercircle.survey; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ServeyApplicationTests { + + @Test + void contextLoads() { + } + +}