diff --git a/hyjii_springboot/ShoppingmallApi/HELP.md b/hyjii_springboot/ShoppingmallApi/HELP.md new file mode 100644 index 0000000..96e6a27 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/HELP.md @@ -0,0 +1,14 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Gradle documentation](https://docs.gradle.org) +* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.7.17-SNAPSHOT/gradle-plugin/reference/html/) +* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.7.17-SNAPSHOT/gradle-plugin/reference/html/#build-image) + +### Additional Links +These additional references should also help you: + +* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) + diff --git a/hyjii_springboot/ShoppingmallApi/build.gradle b/hyjii_springboot/ShoppingmallApi/build.gradle new file mode 100644 index 0000000..8dcf83d --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/build.gradle @@ -0,0 +1,41 @@ +buildscript { + ext { + springBootVersion = '2.1.9.RELEASE' + } + repositories { + mavenCentral() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + } +} + +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'org.springframework.boot' +apply plugin: 'io.spring.dependency-management' + +group 'org.example' +version '1.0.4-SNAPSHOT' +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + compile('org.springframework.boot:spring-boot-starter-web') + compile('org.projectlombok:lombok') + compile('org.springframework.boot:spring-boot-starter-data-jpa') + compile('org.springframework.boot:spring-boot-starter-mustache') + compile('com.h2database:h2') + + //compile('org.springframework.boot:spring-boot-starter-oauth2-client') + compile('org.springframework.session:spring-session-jdbc') + + compile("org.mariadb.jdbc:mariadb-java-client") + + testCompile('org.springframework.boot:spring-boot-starter-test') + //testCompile('org.springframework.boot:spring-boot-starter-mustache') + //testCompile("org.springframework.security:spring-security-test") +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/gradle/wrapper/gradle-wrapper.jar b/hyjii_springboot/ShoppingmallApi/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..033e24c Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/gradle/wrapper/gradle-wrapper.jar differ diff --git a/hyjii_springboot/ShoppingmallApi/gradle/wrapper/gradle-wrapper.properties b/hyjii_springboot/ShoppingmallApi/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..ce17e26 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/gradlew b/hyjii_springboot/ShoppingmallApi/gradlew new file mode 100644 index 0000000..fcb6fca --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/gradlew @@ -0,0 +1,248 @@ +#!/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/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && 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=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=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# 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/hyjii_springboot/ShoppingmallApi/gradlew.bat b/hyjii_springboot/ShoppingmallApi/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/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. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% 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/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/ShoppingmallApiApplication.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/ShoppingmallApiApplication.class new file mode 100644 index 0000000..b1a8df0 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/ShoppingmallApiApplication.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/BaseTimeEntity.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/BaseTimeEntity.class new file mode 100644 index 0000000..0ee91b7 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/BaseTimeEntity.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/posts/Posts$PostsBuilder.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/posts/Posts$PostsBuilder.class new file mode 100644 index 0000000..c53174d Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/posts/Posts$PostsBuilder.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/posts/Posts.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/posts/Posts.class new file mode 100644 index 0000000..65b0173 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/posts/Posts.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/posts/PostsRepository.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/posts/PostsRepository.class new file mode 100644 index 0000000..3c1bd4e Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/domain/posts/PostsRepository.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/service/posts/PostsService.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/service/posts/PostsService.class new file mode 100644 index 0000000..cddd750 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/service/posts/PostsService.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/IndexController.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/IndexController.class new file mode 100644 index 0000000..fc927b4 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/IndexController.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/PostsApiController.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/PostsApiController.class new file mode 100644 index 0000000..466554d Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/PostsApiController.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsCreateDto$PostsCreateDtoBuilder.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsCreateDto$PostsCreateDtoBuilder.class new file mode 100644 index 0000000..f2936b8 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsCreateDto$PostsCreateDtoBuilder.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsCreateDto.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsCreateDto.class new file mode 100644 index 0000000..b8b47a4 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsCreateDto.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsListReadDto.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsListReadDto.class new file mode 100644 index 0000000..3695042 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsListReadDto.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsReadDto.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsReadDto.class new file mode 100644 index 0000000..59d0440 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsReadDto.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsUpdateDto$PostsUpdateDtoBuilder.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsUpdateDto$PostsUpdateDtoBuilder.class new file mode 100644 index 0000000..df4449d Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsUpdateDto$PostsUpdateDtoBuilder.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsUpdateDto.class b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsUpdateDto.class new file mode 100644 index 0000000..5ea0be1 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/production/classes/com/example/ShoppingmallApi/web/dto/PostsUpdateDto.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/production/resources/application.properties b/hyjii_springboot/ShoppingmallApi/out/production/resources/application.properties new file mode 100644 index 0000000..706c288 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/out/production/resources/application.properties @@ -0,0 +1,3 @@ +spring.jpa.show_sql=true +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect +spring.h2.console.enabled=true \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/out/production/resources/static/js/app/index.js b/hyjii_springboot/ShoppingmallApi/out/production/resources/static/js/app/index.js new file mode 100644 index 0000000..a87bb2d --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/out/production/resources/static/js/app/index.js @@ -0,0 +1,80 @@ +var main = { + init : function () { + var _this = this; + $('#btn-save').on('click', function () { + _this.save(); + }); + + $('#btn-update').on('click', function () { + _this.update(); + }); + + $('#btn-delete').on('click', function () { + _this.delete(); + }); + }, + save : function () { + var data = { + product_name: $('#product_name').val(), + price: $('#price').val(), + product_number: $('#product_number').val(), + stock: $('#stock').val(), + category: $('#category').val() + }; + + $.ajax({ + type: 'POST', + url: '/api/v1/posts', + dataType: 'json', + contentType:'application/json; charset=utf-8', + data: JSON.stringify(data) + }).done(function() { + alert('글이 등록되었습니다.'); + window.location.href = '/'; + }).fail(function (error) { + alert(JSON.stringify(error)); + }); + }, + update : function () { + var data = { + product_name: $('#product_name').val(), + price: $('#price').val(), + product_number: $('#product_number').val(), + stock: $('#stock').val(), + category: $('#category').val() + }; + + var id = $('#id').val(); + + $.ajax({ + type: 'PUT', + url: '/api/v1/posts/'+id, + dataType: 'json', + contentType:'application/json; charset=utf-8', + data: JSON.stringify(data) + }).done(function() { + alert('글이 수정되었습니다.'); + window.location.href = '/'; + }).fail(function (error) { + alert(JSON.stringify(error)); + }); + }, + delete : function () { + var id = $('#id').val(); + + $.ajax({ + type: 'DELETE', + url: '/api/v1/posts/'+id, + dataType: 'json', + contentType:'application/json; charset=utf-8' + }).done(function() { + alert('글이 삭제되었습니다.'); + window.location.href = '/'; + }).fail(function (error) { + alert(JSON.stringify(error)); + }); + } + +}; + +main.init(); \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/index.mustache b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/index.mustache new file mode 100644 index 0000000..5cfaf18 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/index.mustache @@ -0,0 +1,38 @@ +{{>layout/header}} + +

쇼핑몰 웹서비스

+
+
+ +
+
+ + + + + + + + + + + + + + {{#posts}} + + + + + + + + + {{/posts}} + +
게시글번호제품이름가격제품번호재고카테고리
{{id}}{{product_name}}{{price}}{{product_number}}{{stock}}{{category}}
+
+ +{{>layout/footer}} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/layout/footer.mustache b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/layout/footer.mustache new file mode 100644 index 0000000..0a1faaa --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/layout/footer.mustache @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/layout/header.mustache b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/layout/header.mustache new file mode 100644 index 0000000..c29d4a7 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/layout/header.mustache @@ -0,0 +1,9 @@ + + + + 쇼핑몰 웹서비스 + + + + + \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/posts-save.mustache b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/posts-save.mustache new file mode 100644 index 0000000..c0dc09e --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/posts-save.mustache @@ -0,0 +1,34 @@ +{{>layout/header}} + +

게시글 등록

+ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ 취소 + +
+
+ +{{>layout/footer}} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/posts-update.mustache b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/posts-update.mustache new file mode 100644 index 0000000..d9a6f04 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/out/production/resources/templates/posts-update.mustache @@ -0,0 +1,40 @@ +{{>layout/header}} + +

게시글 수정

+ +
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ 취소 + + +
+
+ +{{>layout/footer}} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/out/test/classes/com/example/ShoppingmallApi/domain/posts/PostsRepositoryTest.class b/hyjii_springboot/ShoppingmallApi/out/test/classes/com/example/ShoppingmallApi/domain/posts/PostsRepositoryTest.class new file mode 100644 index 0000000..5ee3968 Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/test/classes/com/example/ShoppingmallApi/domain/posts/PostsRepositoryTest.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/test/classes/com/example/ShoppingmallApi/web/IndexControllerTest.class b/hyjii_springboot/ShoppingmallApi/out/test/classes/com/example/ShoppingmallApi/web/IndexControllerTest.class new file mode 100644 index 0000000..17f9c8e Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/test/classes/com/example/ShoppingmallApi/web/IndexControllerTest.class differ diff --git a/hyjii_springboot/ShoppingmallApi/out/test/classes/com/example/ShoppingmallApi/web/PostsApiControllerTest.class b/hyjii_springboot/ShoppingmallApi/out/test/classes/com/example/ShoppingmallApi/web/PostsApiControllerTest.class new file mode 100644 index 0000000..554054c Binary files /dev/null and b/hyjii_springboot/ShoppingmallApi/out/test/classes/com/example/ShoppingmallApi/web/PostsApiControllerTest.class differ diff --git a/hyjii_springboot/ShoppingmallApi/settings.gradle b/hyjii_springboot/ShoppingmallApi/settings.gradle new file mode 100644 index 0000000..e6f6f64 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/settings.gradle @@ -0,0 +1,8 @@ +pluginManagement { + repositories { + maven { url 'https://repo.spring.io/milestone' } + maven { url 'https://repo.spring.io/snapshot' } + gradlePluginPortal() + } +} +rootProject.name = 'ShoppingmallApi' diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/ShoppingmallApiApplication.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/ShoppingmallApiApplication.java new file mode 100644 index 0000000..2cbbd14 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/ShoppingmallApiApplication.java @@ -0,0 +1,15 @@ +package com.example.ShoppingmallApi; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@EnableJpaAuditing +@SpringBootApplication +public class ShoppingmallApiApplication { + + public static void main(String[] args) { + + SpringApplication.run(ShoppingmallApiApplication.class, args); + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/domain/BaseTimeEntity.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/domain/BaseTimeEntity.java new file mode 100644 index 0000000..4e0e24d --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/domain/BaseTimeEntity.java @@ -0,0 +1,22 @@ +package com.example.ShoppingmallApi.domain; + +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; +import java.time.LocalDateTime; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public class BaseTimeEntity { + + @CreatedDate + private LocalDateTime createdDate; + + @LastModifiedDate + private LocalDateTime modifiedDate; +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/domain/posts/Posts.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/domain/posts/Posts.java new file mode 100644 index 0000000..34510b9 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/domain/posts/Posts.java @@ -0,0 +1,49 @@ +package com.example.ShoppingmallApi.domain.posts; + +import com.example.ShoppingmallApi.domain.BaseTimeEntity; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +@Getter +@NoArgsConstructor +@Entity +public class Posts extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column + private String product_name; + + @Column + private int price; + + @Column + private String product_number; + + @Column + private int stock; + + @Column + private String category; + + @Builder + public Posts(String product_name, int price, String product_number, int stock, String category){ + this.product_name = product_name; + this.price = price; + this.product_number = product_number; + this.stock = stock; + this.category = category; + } + + public void update(String product_name, int price, String product_number, int stock, String category){ + this.product_name = product_name; + this.price = price; + this.product_number = product_number; + this.stock = stock; + this.category = category; + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/domain/posts/PostsRepository.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/domain/posts/PostsRepository.java new file mode 100644 index 0000000..5c23082 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/domain/posts/PostsRepository.java @@ -0,0 +1,11 @@ +package com.example.ShoppingmallApi.domain.posts; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; + +public interface PostsRepository extends JpaRepository { + @Query("SELECT p FROM Posts p ORDER BY p.id DESC") + List findAllDesc(); +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/service/posts/PostsService.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/service/posts/PostsService.java new file mode 100644 index 0000000..2c08eec --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/service/posts/PostsService.java @@ -0,0 +1,49 @@ +package com.example.ShoppingmallApi.service.posts; + +import com.example.ShoppingmallApi.domain.posts.Posts; +import com.example.ShoppingmallApi.domain.posts.PostsRepository; +import com.example.ShoppingmallApi.web.dto.PostsCreateDto; +import com.example.ShoppingmallApi.web.dto.PostsListReadDto; +import com.example.ShoppingmallApi.web.dto.PostsReadDto; +import com.example.ShoppingmallApi.web.dto.PostsUpdateDto; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +import java.util.List; +import java.util.stream.Collectors; + +@RequiredArgsConstructor +@Service +public class PostsService { + private final PostsRepository postsRepository; + + @Transactional + public Long save(PostsCreateDto requestDto) { //Create + return postsRepository.save(requestDto.toEntity()).getId(); + } + + @Transactional + public Long update(Long id, PostsUpdateDto requestDto){ //Update + Posts posts = postsRepository.findById(id).orElseThrow(()->new IllegalArgumentException("해당 상품이 없습니다. id=" + id)); + posts.update(requestDto.getProduct_name(), requestDto.getPrice(), requestDto.getProduct_number(), requestDto.getStock(), requestDto.getCategory()); + return id; + } + + @Transactional + public PostsReadDto findById(Long id){ //Read + Posts entity = postsRepository.findById(id).orElseThrow(()->new IllegalArgumentException("해당 게시글이 없습니다. id=" + id)); + return new PostsReadDto(entity); + } + + @Transactional + public void delete(Long id){ //Delete + Posts posts = postsRepository.findById(id).orElseThrow(()->new IllegalArgumentException("해당 게시글이 없습니다. id=" + id)); + postsRepository.delete(posts); + } + @Transactional(readOnly = true) + public List findAllDesc() { + return postsRepository.findAllDesc().stream().map(PostsListReadDto::new).collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/IndexController.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/IndexController.java new file mode 100644 index 0000000..74294dc --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/IndexController.java @@ -0,0 +1,33 @@ +package com.example.ShoppingmallApi.web; + +import com.example.ShoppingmallApi.service.posts.PostsService; +import com.example.ShoppingmallApi.web.dto.PostsReadDto; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@RequiredArgsConstructor +@Controller +public class IndexController { + + private final PostsService postsService; + + @GetMapping("/") + public String index(Model model){ + model.addAttribute("posts",postsService.findAllDesc()); + return "index"; + } + @GetMapping("/posts/save") + public String postsSave(){ + return "posts-save"; + } + @GetMapping("/posts/update/{id}") + public String postsUpdate(@PathVariable Long id, Model model) { + PostsReadDto dto = postsService.findById(id); + model.addAttribute("post", dto); + + return "posts-update"; + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/PostsApiController.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/PostsApiController.java new file mode 100644 index 0000000..5c4dd0b --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/PostsApiController.java @@ -0,0 +1,36 @@ +package com.example.ShoppingmallApi.web; + +import com.example.ShoppingmallApi.service.posts.PostsService; +import com.example.ShoppingmallApi.web.dto.PostsCreateDto; +import com.example.ShoppingmallApi.web.dto.PostsReadDto; +import com.example.ShoppingmallApi.web.dto.PostsUpdateDto; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RequiredArgsConstructor +@RestController +public class PostsApiController { + + private final PostsService postsService; + + @PostMapping("/api/v1/posts") //Create + public Long save(@RequestBody PostsCreateDto requestDto) { + return postsService.save(requestDto); + } + + @PutMapping("/api/v1/posts/{id}") //Update + public Long update(@PathVariable Long id, @RequestBody PostsUpdateDto requestDto){ + return postsService.update(id, requestDto); + } + + @GetMapping("/api/v1/posts/{id}") //Read + public PostsReadDto findById (@PathVariable Long id) { + return postsService.findById(id); + } + + @DeleteMapping("/api/v1/posts/{id}") //Delete + public Long delete(@PathVariable long id){ + postsService.delete(id); + return id; + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsCreateDto.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsCreateDto.java new file mode 100644 index 0000000..b58fe71 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsCreateDto.java @@ -0,0 +1,28 @@ +package com.example.ShoppingmallApi.web.dto; + +import com.example.ShoppingmallApi.domain.posts.Posts; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class PostsCreateDto { + private String product_name; + private int price; + private String product_number; + private int stock; + private String category; + @Builder + public PostsCreateDto(String product_name, int price, String product_number, int stock, String category){ + this.product_name = product_name; + this.price = price; + this.product_number = product_number; + this.stock = stock; + this.category = category; + } + public Posts toEntity(){ + return Posts.builder().product_name(product_name).price(price).product_number(product_number).stock(stock) + .category(category).build(); + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsListReadDto.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsListReadDto.java new file mode 100644 index 0000000..bd1f166 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsListReadDto.java @@ -0,0 +1,27 @@ +package com.example.ShoppingmallApi.web.dto; + +import com.example.ShoppingmallApi.domain.posts.Posts; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +public class PostsListReadDto { + private Long id; + private String product_name; + private int price; + private String product_number; + private int stock; + private String category; + private LocalDateTime modifiedDate; + + public PostsListReadDto(Posts entity){ + this.id = entity.getId(); + this.product_name = entity.getProduct_name(); + this.price = entity.getPrice(); + this.product_number = entity.getProduct_number(); + this.stock = entity.getStock(); + this.category = entity.getCategory(); + this.modifiedDate = entity.getModifiedDate(); + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsReadDto.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsReadDto.java new file mode 100644 index 0000000..c140e5d --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsReadDto.java @@ -0,0 +1,23 @@ +package com.example.ShoppingmallApi.web.dto; + +import com.example.ShoppingmallApi.domain.posts.Posts; +import lombok.Getter; + +@Getter +public class PostsReadDto { + private Long id; + private String product_name; + private int price; + private String product_number; + private int stock; + private String category; + + public PostsReadDto(Posts entity){ + this.id = entity.getId(); + this.product_name = entity.getProduct_name(); + this.price = entity.getPrice(); + this.product_number = entity.getProduct_number(); + this.stock = entity.getStock(); + this.category = entity.getCategory(); + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsUpdateDto.java b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsUpdateDto.java new file mode 100644 index 0000000..6af6805 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/java/com/example/ShoppingmallApi/web/dto/PostsUpdateDto.java @@ -0,0 +1,24 @@ +package com.example.ShoppingmallApi.web.dto; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class PostsUpdateDto { + private String product_name; + private int price; + private String product_number; + private int stock; + private String category; + + @Builder + public PostsUpdateDto(String product_name, int price, String product_number, int stock, String category){ + this.product_name = product_name; + this.price = price; + this.product_number = product_number; + this.stock = stock; + this.category = category; + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/resources/application.properties b/hyjii_springboot/ShoppingmallApi/src/main/resources/application.properties new file mode 100644 index 0000000..706c288 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.jpa.show_sql=true +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect +spring.h2.console.enabled=true \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/resources/static/js/app/index.js b/hyjii_springboot/ShoppingmallApi/src/main/resources/static/js/app/index.js new file mode 100644 index 0000000..a87bb2d --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/resources/static/js/app/index.js @@ -0,0 +1,80 @@ +var main = { + init : function () { + var _this = this; + $('#btn-save').on('click', function () { + _this.save(); + }); + + $('#btn-update').on('click', function () { + _this.update(); + }); + + $('#btn-delete').on('click', function () { + _this.delete(); + }); + }, + save : function () { + var data = { + product_name: $('#product_name').val(), + price: $('#price').val(), + product_number: $('#product_number').val(), + stock: $('#stock').val(), + category: $('#category').val() + }; + + $.ajax({ + type: 'POST', + url: '/api/v1/posts', + dataType: 'json', + contentType:'application/json; charset=utf-8', + data: JSON.stringify(data) + }).done(function() { + alert('글이 등록되었습니다.'); + window.location.href = '/'; + }).fail(function (error) { + alert(JSON.stringify(error)); + }); + }, + update : function () { + var data = { + product_name: $('#product_name').val(), + price: $('#price').val(), + product_number: $('#product_number').val(), + stock: $('#stock').val(), + category: $('#category').val() + }; + + var id = $('#id').val(); + + $.ajax({ + type: 'PUT', + url: '/api/v1/posts/'+id, + dataType: 'json', + contentType:'application/json; charset=utf-8', + data: JSON.stringify(data) + }).done(function() { + alert('글이 수정되었습니다.'); + window.location.href = '/'; + }).fail(function (error) { + alert(JSON.stringify(error)); + }); + }, + delete : function () { + var id = $('#id').val(); + + $.ajax({ + type: 'DELETE', + url: '/api/v1/posts/'+id, + dataType: 'json', + contentType:'application/json; charset=utf-8' + }).done(function() { + alert('글이 삭제되었습니다.'); + window.location.href = '/'; + }).fail(function (error) { + alert(JSON.stringify(error)); + }); + } + +}; + +main.init(); \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/index.mustache b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/index.mustache new file mode 100644 index 0000000..5cfaf18 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/index.mustache @@ -0,0 +1,38 @@ +{{>layout/header}} + +

쇼핑몰 웹서비스

+
+
+ +
+
+ + + + + + + + + + + + + + {{#posts}} + + + + + + + + + {{/posts}} + +
게시글번호제품이름가격제품번호재고카테고리
{{id}}{{product_name}}{{price}}{{product_number}}{{stock}}{{category}}
+
+ +{{>layout/footer}} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/layout/footer.mustache b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/layout/footer.mustache new file mode 100644 index 0000000..0a1faaa --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/layout/footer.mustache @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/layout/header.mustache b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/layout/header.mustache new file mode 100644 index 0000000..c29d4a7 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/layout/header.mustache @@ -0,0 +1,9 @@ + + + + 쇼핑몰 웹서비스 + + + + + \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/posts-save.mustache b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/posts-save.mustache new file mode 100644 index 0000000..c0dc09e --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/posts-save.mustache @@ -0,0 +1,34 @@ +{{>layout/header}} + +

게시글 등록

+ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ 취소 + +
+
+ +{{>layout/footer}} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/posts-update.mustache b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/posts-update.mustache new file mode 100644 index 0000000..d9a6f04 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/main/resources/templates/posts-update.mustache @@ -0,0 +1,40 @@ +{{>layout/header}} + +

게시글 수정

+ +
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ 취소 + + +
+
+ +{{>layout/footer}} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/test/java/com/example/ShoppingmallApi/domain/posts/PostsRepositoryTest.java b/hyjii_springboot/ShoppingmallApi/src/test/java/com/example/ShoppingmallApi/domain/posts/PostsRepositoryTest.java new file mode 100644 index 0000000..cf6f069 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/test/java/com/example/ShoppingmallApi/domain/posts/PostsRepositoryTest.java @@ -0,0 +1,65 @@ +package com.example.ShoppingmallApi.domain.posts; + +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class PostsRepositoryTest { + @Autowired + PostsRepository postsRepository; + + @After + public void cleanup(){ + postsRepository.deleteAll(); + } + + @Test + public void 상품_불러오기(){ + //given + String product_name = "코트"; + int price = 50000; + String product_number = "E98Y512"; + int stock = 100; + String category = "Outer"; + + postsRepository.save(Posts.builder().product_name(product_name).price(price).product_number(product_number) + .stock(stock).category(category).build()); + + //when + List postsList = postsRepository.findAll(); + + //then + Posts posts = postsList.get(0); + assertThat(posts.getProduct_name()).isEqualTo(product_name); + assertThat(posts.getPrice()).isEqualTo(price); + assertThat(posts.getProduct_number()).isEqualTo(product_number); + assertThat(posts.getStock()).isEqualTo(stock); + assertThat(posts.getCategory()).isEqualTo(category); + } + @Test + public void BaseTimeEntity_등록(){ + //given + LocalDateTime now = LocalDateTime.of(2023,10,7,0,0,0); + Posts savedPosts = postsRepository.save(Posts.builder().product_name("product_name").price(50000).product_number("product_number") + .stock(100).category("category").build()); + //when + List postsList = postsRepository.findAll(); + //then + Posts posts = postsList.get(0); + + System.out.println(">>>>>>>>> createDate="+posts.getCreatedDate()+", modifiedDate="+posts.getModifiedDate()); + assertThat(posts.getCreatedDate()).isAfter(now); + assertThat(posts.getModifiedDate()).isAfter(now); + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/test/java/com/example/ShoppingmallApi/web/IndexControllerTest.java b/hyjii_springboot/ShoppingmallApi/src/test/java/com/example/ShoppingmallApi/web/IndexControllerTest.java new file mode 100644 index 0000000..7a3da2e --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/test/java/com/example/ShoppingmallApi/web/IndexControllerTest.java @@ -0,0 +1,33 @@ +package com.example.ShoppingmallApi.web; + +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.bind.annotation.GetMapping; + +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = RANDOM_PORT) +public class IndexControllerTest { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void 메인페이지_로딩(){ + //when + String body = this.restTemplate.getForObject("/", String.class); + + //then + assertThat(body).contains("쇼핑몰 웹서비스"); + } + @GetMapping("/posts/save") + public String postsSave(){ + return "posts-save"; + } +} \ No newline at end of file diff --git a/hyjii_springboot/ShoppingmallApi/src/test/java/com/example/ShoppingmallApi/web/PostsApiControllerTest.java b/hyjii_springboot/ShoppingmallApi/src/test/java/com/example/ShoppingmallApi/web/PostsApiControllerTest.java new file mode 100644 index 0000000..f6f6086 --- /dev/null +++ b/hyjii_springboot/ShoppingmallApi/src/test/java/com/example/ShoppingmallApi/web/PostsApiControllerTest.java @@ -0,0 +1,90 @@ +package com.example.ShoppingmallApi.web; + +import com.example.ShoppingmallApi.domain.posts.Posts; +import com.example.ShoppingmallApi.domain.posts.PostsRepository; +import com.example.ShoppingmallApi.web.dto.PostsCreateDto; +import com.example.ShoppingmallApi.web.dto.PostsUpdateDto; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class PostsApiControllerTest { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private PostsRepository postsRepository; + + + @After + public void tearDown() throws Exception { + postsRepository.deleteAll(); + } + + @Test + public void 등록() throws Exception { + //given + String product_name = "코트"; + int price = 50000; + String product_number = "E98Y512"; + int stock = 100; + String category = "Outer"; + PostsCreateDto requestDto = PostsCreateDto.builder().product_name(product_name).price(price).product_number(product_number).stock(stock) + .category(category).build(); + String url = "http://localhost:" + port + "/api/v1/posts"; + + //when + ResponseEntity responseEntity = restTemplate.postForEntity(url, requestDto, Long.class); + + //then + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(responseEntity.getBody()).isGreaterThan(0L); + List all = postsRepository.findAll(); + assertThat(all.get(0).getProduct_name()).isEqualTo(product_name); + assertThat(all.get(0).getPrice()).isEqualTo(price); + } + @Test + public void 수정() throws Exception{ + //given + Posts savedPosts = postsRepository.save(Posts.builder().product_name("product_name").price(50000).product_number("product_number").stock(100) + .category("category").build()); + + Long updateId = savedPosts.getId(); + String expectedProduct_name = "product_name"; + int expectedPrice = 40000; + int expectedStock = 50; + + PostsUpdateDto requestDto = PostsUpdateDto.builder().product_name(expectedProduct_name).price(expectedPrice).stock(expectedStock).build(); + String url = "http://localhost:" + port + "/api/v1/posts/" + updateId; + HttpEntity requestEntity = new HttpEntity<>(requestDto); + + // when + ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.PUT, requestEntity, Long.class); + + // then + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(responseEntity.getBody()).isGreaterThan(0L); + List all = postsRepository.findAll(); + assertThat(all.get(0).getProduct_name()).isEqualTo(expectedProduct_name); + assertThat(all.get(0).getPrice()).isEqualTo(expectedPrice); + } +} \ No newline at end of file