diff --git a/.gitignore b/.gitignore index 395f479..522ea06 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ src/main/resources/application.yml bin/ !**/src/main/**/bin/ !**/src/test/**/bin/ +src/main/resources/application.yml ### IntelliJ IDEA ### .idea diff --git a/build.gradle b/build.gradle index 9820aea..63e1ad4 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,12 @@ dependencies { // swagger 어노테이션 라이브러리 implementation 'io.swagger:swagger-annotations:1.5.21' + // AWS 연동 + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' + + // 채팅 - WebSocket + implementation 'org.springframework.boot:spring-boot-starter-websocket' + } tasks.named('test') { diff --git a/hs_err_pid11388.log b/hs_err_pid11388.log new file mode 100644 index 0000000..250ebb9 --- /dev/null +++ b/hs_err_pid11388.log @@ -0,0 +1,197 @@ +# +# There is insufficient memory for the Java Runtime Environment to continue. +# Native memory allocation (mmap) failed to map 134217728 bytes for Failed to commit area from 0x0000000081600000 to 0x0000000089600000 of length 134217728. +# Possible reasons: +# The system is out of physical RAM or swap space +# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap +# Possible solutions: +# Reduce memory load on the system +# Increase physical memory or swap space +# Check if swap backing store is full +# Decrease Java heap size (-Xmx/-Xms) +# Decrease number of Java threads +# Decrease Java thread stack sizes (-Xss) +# Set larger code cache with -XX:ReservedCodeCacheSize= +# This output file may be truncated or incomplete. +# +# Out of Memory Error (src/hotspot/os/windows/os_windows.cpp:3624), pid=11388, tid=6308 +# +# JRE version: (11.0.14.1+1) (build ) +# Java VM: OpenJDK 64-Bit Server VM (11.0.14.1+1-b2043.25, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64) +# No core dump will be written. Minidumps are not enabled by default on client versions of Windows +# + +--------------- S U M M A R Y ------------ + +Command Line: git4idea.http.GitAskPassApp Username for 'https://github.com': + +Host: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz, 4 cores, 7G, Windows 10 , 64 bit Build 19041 (10.0.19041.1023) +Time: Thu Jan 12 21:57:43 2023 ѹα ǥؽ elapsed time: 0.023085 seconds (0d 0h 0m 0s) + +--------------- T H R E A D --------------- + +Current thread (0x0000022a857ec000): JavaThread "Unknown thread" [_thread_in_vm, id=6308, stack(0x0000009d6d500000,0x0000009d6d600000)] + +Stack: [0x0000009d6d500000,0x0000009d6d600000] +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +V [jvm.dll+0x61618a] +V [jvm.dll+0x79c450] +V [jvm.dll+0x79da6d] +V [jvm.dll+0x79e143] +V [jvm.dll+0x24c968] +V [jvm.dll+0x6131f4] +V [jvm.dll+0x607ef5] +V [jvm.dll+0x30b35b] +V [jvm.dll+0x30b2ca] +V [jvm.dll+0x30b1a2] +V [jvm.dll+0x3100f6] +V [jvm.dll+0x35b7e3] +V [jvm.dll+0x35bee6] +V [jvm.dll+0x35b8e3] +V [jvm.dll+0x2e5b68] +V [jvm.dll+0x2e6d17] +V [jvm.dll+0x779087] +V [jvm.dll+0x77a87c] +V [jvm.dll+0x368d99] +V [jvm.dll+0x75c9de] +V [jvm.dll+0x3d6d53] +V [jvm.dll+0x3d92f1] +C [jli.dll+0x536b] +C [ucrtbase.dll+0x21bb2] +C [KERNEL32.DLL+0x17034] +C [ntdll.dll+0x52651] + + +--------------- P R O C E S S --------------- + +Threads class SMR info: +_java_thread_list=0x0000022a836d1a90, length=0, elements={ +} + +Java Threads: ( => current thread ) + +Other Threads: + 0x0000022a85805000 GCTaskThread "GC Thread#0" [stack: 0x0000009d6d600000,0x0000009d6d700000] [id=12136] + 0x0000022a85838800 ConcurrentGCThread "G1 Main Marker" [stack: 0x0000009d6d700000,0x0000009d6d800000] [id=4796] + 0x0000022a85839800 ConcurrentGCThread "G1 Conc#0" [stack: 0x0000009d6d800000,0x0000009d6d900000] [id=4676] + +[error occurred during error reporting (printing all threads), id 0xc0000005, EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff919df6177] + +VM state:not at safepoint (not fully initialized) + +VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event]) +[0x0000022a857e9980] Heap_lock - owner thread: 0x0000022a857ec000 + +Heap address: 0x0000000081600000, size: 2026 MB, Compressed Oops mode: Non-zero based: 0x0000000081600000 +Narrow klass base: 0x0000000000000000, Narrow klass shift: 0 + +GC Heap History (0 events): +No events + +Deoptimization events (0 events): +No events + +Classes redefined (0 events): +No events + +Internal exceptions (0 events): +No events + +Events (1 events): +Event: 0.016 Loaded shared library C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\zip.dll + + +Dynamic libraries: +0x00007ff779990000 - 0x00007ff77999a000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\java.exe +0x00007ff97f8f0000 - 0x00007ff97fae5000 C:\WINDOWS\SYSTEM32\ntdll.dll +0x00007ff97f7f0000 - 0x00007ff97f8ad000 C:\WINDOWS\System32\KERNEL32.DLL +0x00007ff97d030000 - 0x00007ff97d2f8000 C:\WINDOWS\System32\KERNELBASE.dll +0x00007ff97d3e0000 - 0x00007ff97d4e0000 C:\WINDOWS\System32\ucrtbase.dll +0x00007ff9783c0000 - 0x00007ff9783d9000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\jli.dll +0x00007ff9783e0000 - 0x00007ff9783f6000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\VCRUNTIME140.dll +0x00007ff97f650000 - 0x00007ff97f7f0000 C:\WINDOWS\System32\USER32.dll +0x00007ff97d300000 - 0x00007ff97d322000 C:\WINDOWS\System32\win32u.dll +0x00007ff97ec80000 - 0x00007ff97ecaa000 C:\WINDOWS\System32\GDI32.dll +0x00007ff97d5e0000 - 0x00007ff97d6eb000 C:\WINDOWS\System32\gdi32full.dll +0x00007ff97d4e0000 - 0x00007ff97d57d000 C:\WINDOWS\System32\msvcp_win.dll +0x00007ff963b40000 - 0x00007ff963dda000 C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.1052_none_60b8f8fd71f5e8cb\COMCTL32.dll +0x00007ff97e280000 - 0x00007ff97e31e000 C:\WINDOWS\System32\msvcrt.dll +0x00007ff97e450000 - 0x00007ff97e480000 C:\WINDOWS\System32\IMM32.DLL +0x00007ff95d6b0000 - 0x00007ff95d75a000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\msvcp140.dll +0x00007ff919b00000 - 0x00007ff91a67a000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\server\jvm.dll +0x00007ff97f440000 - 0x00007ff97f4ec000 C:\WINDOWS\System32\ADVAPI32.dll +0x00007ff97d960000 - 0x00007ff97d9fb000 C:\WINDOWS\System32\sechost.dll +0x00007ff97e320000 - 0x00007ff97e44b000 C:\WINDOWS\System32\RPCRT4.dll +0x00007ff97f3c0000 - 0x00007ff97f3c8000 C:\WINDOWS\System32\PSAPI.DLL +0x00007ff975080000 - 0x00007ff97508a000 C:\WINDOWS\SYSTEM32\VERSION.dll +0x00007ff963a00000 - 0x00007ff963a27000 C:\WINDOWS\SYSTEM32\WINMM.dll +0x00007ff957c30000 - 0x00007ff957c39000 C:\WINDOWS\SYSTEM32\WSOCK32.dll +0x00007ff97ee40000 - 0x00007ff97eeab000 C:\WINDOWS\System32\WS2_32.dll +0x00007ff97b950000 - 0x00007ff97b962000 C:\WINDOWS\SYSTEM32\kernel.appcore.dll +0x00007ff95c3c0000 - 0x00007ff95c3d1000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\verify.dll +0x00007ff97ae30000 - 0x00007ff97b014000 C:\WINDOWS\SYSTEM32\DBGHELP.DLL +0x00007ff969aa0000 - 0x00007ff969acc000 C:\WINDOWS\SYSTEM32\dbgcore.DLL +0x00007ff97d6f0000 - 0x00007ff97d773000 C:\WINDOWS\System32\bcryptPrimitives.dll +0x00007ff95c390000 - 0x00007ff95c3b9000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\java.dll +0x00007ff95c380000 - 0x00007ff95c38b000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\jimage.dll +0x00007ff95c360000 - 0x00007ff95c379000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\zip.dll + +dbghelp: loaded successfully - version: 4.0.5 - missing functions: none +symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin;C:\WINDOWS\SYSTEM32;C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.1052_none_60b8f8fd71f5e8cb;C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\server + +VM Arguments: +java_command: git4idea.http.GitAskPassApp Username for 'https://github.com': +java_class_path (initial): C:/Program Files/JetBrains/IntelliJ IDEA 2022.1/plugins/git4idea/lib/git4idea-rt.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2022.1/lib/externalProcess-rt.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2022.1/lib/app.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2022.1/lib/3rd-party-rt.jar +Launcher Type: SUN_STANDARD + +[Global flags] + intx CICompilerCount = 3 {product} {ergonomic} + uint ConcGCThreads = 1 {product} {ergonomic} + uint G1ConcRefinementThreads = 4 {product} {ergonomic} + size_t G1HeapRegionSize = 1048576 {product} {ergonomic} + uintx GCDrainStackTargetSize = 64 {product} {ergonomic} + size_t InitialHeapSize = 134217728 {product} {ergonomic} + size_t MarkStackSize = 4194304 {product} {ergonomic} + size_t MaxHeapSize = 2124414976 {product} {ergonomic} + size_t MinHeapDeltaBytes = 1048576 {product} {ergonomic} + uintx NonNMethodCodeHeapSize = 5830732 {pd product} {ergonomic} + uintx NonProfiledCodeHeapSize = 122913754 {pd product} {ergonomic} + uintx ProfiledCodeHeapSize = 122913754 {pd product} {ergonomic} + uintx ReservedCodeCacheSize = 251658240 {pd product} {ergonomic} + bool SegmentedCodeCache = true {product} {ergonomic} + bool UseCompressedClassPointers = true {lp64_product} {ergonomic} + bool UseCompressedOops = true {lp64_product} {ergonomic} + bool UseG1GC = true {product} {ergonomic} + bool UseLargePagesIndividualAllocation = false {pd product} {ergonomic} + +Logging: +Log output configuration: + #0: stdout all=warning uptime,level,tags + #1: stderr all=off uptime,level,tags + +Environment Variables: +JAVA_HOME=C:\Program Files\Java\jdk-15 +PATH=C:\Program Files\Git\mingw64\libexec\git-core;C:\Program Files\Git\mingw64\libexec\git-core;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\ne466\bin;C:\Program Files\Java\jdk-15\bin;C:\Program Files (x86)\VMware\VMware Player\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\NAT Service;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files\Git\cmd;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\ne466\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\SoftForum\XecureHSM;C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\bin;C:\Users\ne466\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Java\jdk-15\bin +USERNAME=ne466 +DISPLAY=:0.0 +LC_ALL=en_US.UTF-8 +OS=Windows_NT +PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 142 Stepping 9, GenuineIntel + + + +--------------- S Y S T E M --------------- + +OS: Windows 10 , 64 bit Build 19041 (10.0.19041.1023) +OS uptime: 0 days 9:17 hours + +CPU:total 4 (initial active 4) (2 cores per cpu, 2 threads per core) family 6 model 142 stepping 9 microcode 0xb4, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, clmul, erms, 3dnowpref, lzcnt, ht, tsc, tscinvbit, bmi1, bmi2, adx, fma + +Memory: 4k page, system-wide physical 8102M (868M free) +TotalPageFile size 10877M (AvailPageFile size 87M) +current process WorkingSet (physical memory assigned to process): 10M, peak: 10M +current process commit charge ("private bytes"): 51M, peak: 179M + +vm_info: OpenJDK 64-Bit Server VM (11.0.14.1+1-b2043.25) for windows-amd64 JRE (11.0.14.1+1-b2043.25), built on Mar 30 2022 06:22:56 by "" with MS VC++ 14.0 (VS2015) + +END. diff --git a/hs_err_pid12644.log b/hs_err_pid12644.log new file mode 100644 index 0000000..fc227e2 --- /dev/null +++ b/hs_err_pid12644.log @@ -0,0 +1,197 @@ +# +# There is insufficient memory for the Java Runtime Environment to continue. +# Native memory allocation (mmap) failed to map 134217728 bytes for Failed to commit area from 0x0000000081600000 to 0x0000000089600000 of length 134217728. +# Possible reasons: +# The system is out of physical RAM or swap space +# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap +# Possible solutions: +# Reduce memory load on the system +# Increase physical memory or swap space +# Check if swap backing store is full +# Decrease Java heap size (-Xmx/-Xms) +# Decrease number of Java threads +# Decrease Java thread stack sizes (-Xss) +# Set larger code cache with -XX:ReservedCodeCacheSize= +# This output file may be truncated or incomplete. +# +# Out of Memory Error (src/hotspot/os/windows/os_windows.cpp:3624), pid=12644, tid=7520 +# +# JRE version: (11.0.14.1+1) (build ) +# Java VM: OpenJDK 64-Bit Server VM (11.0.14.1+1-b2043.25, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64) +# No core dump will be written. Minidumps are not enabled by default on client versions of Windows +# + +--------------- S U M M A R Y ------------ + +Command Line: git4idea.http.GitAskPassApp Username for 'https://github.com': + +Host: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz, 4 cores, 7G, Windows 10 , 64 bit Build 19041 (10.0.19041.1023) +Time: Thu Jan 12 21:57:25 2023 ѹα ǥؽ elapsed time: 0.026167 seconds (0d 0h 0m 0s) + +--------------- T H R E A D --------------- + +Current thread (0x00000230feecc000): JavaThread "Unknown thread" [_thread_in_vm, id=7520, stack(0x000000f047200000,0x000000f047300000)] + +Stack: [0x000000f047200000,0x000000f047300000] +Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) +V [jvm.dll+0x61618a] +V [jvm.dll+0x79c450] +V [jvm.dll+0x79da6d] +V [jvm.dll+0x79e143] +V [jvm.dll+0x24c968] +V [jvm.dll+0x6131f4] +V [jvm.dll+0x607ef5] +V [jvm.dll+0x30b35b] +V [jvm.dll+0x30b2ca] +V [jvm.dll+0x30b1a2] +V [jvm.dll+0x3100f6] +V [jvm.dll+0x35b7e3] +V [jvm.dll+0x35bee6] +V [jvm.dll+0x35b8e3] +V [jvm.dll+0x2e5b68] +V [jvm.dll+0x2e6d17] +V [jvm.dll+0x779087] +V [jvm.dll+0x77a87c] +V [jvm.dll+0x368d99] +V [jvm.dll+0x75c9de] +V [jvm.dll+0x3d6d53] +V [jvm.dll+0x3d92f1] +C [jli.dll+0x536b] +C [ucrtbase.dll+0x21bb2] +C [KERNEL32.DLL+0x17034] +C [ntdll.dll+0x52651] + + +--------------- P R O C E S S --------------- + +Threads class SMR info: +_java_thread_list=0x00000230fcdc1ee0, length=0, elements={ +} + +Java Threads: ( => current thread ) + +Other Threads: + 0x00000230feee5000 GCTaskThread "GC Thread#0" [stack: 0x000000f047300000,0x000000f047400000] [id=19628] + 0x00000230fef19800 ConcurrentGCThread "G1 Main Marker" [stack: 0x000000f047400000,0x000000f047500000] [id=2876] + 0x00000230fef1a800 ConcurrentGCThread "G1 Conc#0" [stack: 0x000000f047500000,0x000000f047600000] [id=19336] + +[error occurred during error reporting (printing all threads), id 0xc0000005, EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ff919df6177] + +VM state:not at safepoint (not fully initialized) + +VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event]) +[0x00000230feec8db0] Heap_lock - owner thread: 0x00000230feecc000 + +Heap address: 0x0000000081600000, size: 2026 MB, Compressed Oops mode: Non-zero based: 0x0000000081600000 +Narrow klass base: 0x0000000000000000, Narrow klass shift: 0 + +GC Heap History (0 events): +No events + +Deoptimization events (0 events): +No events + +Classes redefined (0 events): +No events + +Internal exceptions (0 events): +No events + +Events (1 events): +Event: 0.019 Loaded shared library C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\zip.dll + + +Dynamic libraries: +0x00007ff779990000 - 0x00007ff77999a000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\java.exe +0x00007ff97f8f0000 - 0x00007ff97fae5000 C:\WINDOWS\SYSTEM32\ntdll.dll +0x00007ff97f7f0000 - 0x00007ff97f8ad000 C:\WINDOWS\System32\KERNEL32.DLL +0x00007ff97d030000 - 0x00007ff97d2f8000 C:\WINDOWS\System32\KERNELBASE.dll +0x00007ff97d3e0000 - 0x00007ff97d4e0000 C:\WINDOWS\System32\ucrtbase.dll +0x00007ff9783e0000 - 0x00007ff9783f6000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\VCRUNTIME140.dll +0x00007ff9783c0000 - 0x00007ff9783d9000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\jli.dll +0x00007ff97f650000 - 0x00007ff97f7f0000 C:\WINDOWS\System32\USER32.dll +0x00007ff97d300000 - 0x00007ff97d322000 C:\WINDOWS\System32\win32u.dll +0x00007ff97ec80000 - 0x00007ff97ecaa000 C:\WINDOWS\System32\GDI32.dll +0x00007ff97d5e0000 - 0x00007ff97d6eb000 C:\WINDOWS\System32\gdi32full.dll +0x00007ff97d4e0000 - 0x00007ff97d57d000 C:\WINDOWS\System32\msvcp_win.dll +0x00007ff963b40000 - 0x00007ff963dda000 C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.1052_none_60b8f8fd71f5e8cb\COMCTL32.dll +0x00007ff97e280000 - 0x00007ff97e31e000 C:\WINDOWS\System32\msvcrt.dll +0x00007ff97e450000 - 0x00007ff97e480000 C:\WINDOWS\System32\IMM32.DLL +0x00007ff95d6b0000 - 0x00007ff95d75a000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\msvcp140.dll +0x00007ff919b00000 - 0x00007ff91a67a000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\server\jvm.dll +0x00007ff97f440000 - 0x00007ff97f4ec000 C:\WINDOWS\System32\ADVAPI32.dll +0x00007ff97d960000 - 0x00007ff97d9fb000 C:\WINDOWS\System32\sechost.dll +0x00007ff97e320000 - 0x00007ff97e44b000 C:\WINDOWS\System32\RPCRT4.dll +0x00007ff97f3c0000 - 0x00007ff97f3c8000 C:\WINDOWS\System32\PSAPI.DLL +0x00007ff957c30000 - 0x00007ff957c39000 C:\WINDOWS\SYSTEM32\WSOCK32.dll +0x00007ff97ee40000 - 0x00007ff97eeab000 C:\WINDOWS\System32\WS2_32.dll +0x00007ff963a00000 - 0x00007ff963a27000 C:\WINDOWS\SYSTEM32\WINMM.dll +0x00007ff975080000 - 0x00007ff97508a000 C:\WINDOWS\SYSTEM32\VERSION.dll +0x00007ff97b950000 - 0x00007ff97b962000 C:\WINDOWS\SYSTEM32\kernel.appcore.dll +0x00007ff95c3c0000 - 0x00007ff95c3d1000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\verify.dll +0x00007ff97ae30000 - 0x00007ff97b014000 C:\WINDOWS\SYSTEM32\DBGHELP.DLL +0x00007ff969aa0000 - 0x00007ff969acc000 C:\WINDOWS\SYSTEM32\dbgcore.DLL +0x00007ff97d6f0000 - 0x00007ff97d773000 C:\WINDOWS\System32\bcryptPrimitives.dll +0x00007ff95c390000 - 0x00007ff95c3b9000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\java.dll +0x00007ff95c380000 - 0x00007ff95c38b000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\jimage.dll +0x00007ff95c360000 - 0x00007ff95c379000 C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\zip.dll + +dbghelp: loaded successfully - version: 4.0.5 - missing functions: none +symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin;C:\WINDOWS\SYSTEM32;C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.1052_none_60b8f8fd71f5e8cb;C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\jbr\bin\server + +VM Arguments: +java_command: git4idea.http.GitAskPassApp Username for 'https://github.com': +java_class_path (initial): C:/Program Files/JetBrains/IntelliJ IDEA 2022.1/plugins/git4idea/lib/git4idea-rt.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2022.1/lib/externalProcess-rt.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2022.1/lib/app.jar;C:/Program Files/JetBrains/IntelliJ IDEA 2022.1/lib/3rd-party-rt.jar +Launcher Type: SUN_STANDARD + +[Global flags] + intx CICompilerCount = 3 {product} {ergonomic} + uint ConcGCThreads = 1 {product} {ergonomic} + uint G1ConcRefinementThreads = 4 {product} {ergonomic} + size_t G1HeapRegionSize = 1048576 {product} {ergonomic} + uintx GCDrainStackTargetSize = 64 {product} {ergonomic} + size_t InitialHeapSize = 134217728 {product} {ergonomic} + size_t MarkStackSize = 4194304 {product} {ergonomic} + size_t MaxHeapSize = 2124414976 {product} {ergonomic} + size_t MinHeapDeltaBytes = 1048576 {product} {ergonomic} + uintx NonNMethodCodeHeapSize = 5830732 {pd product} {ergonomic} + uintx NonProfiledCodeHeapSize = 122913754 {pd product} {ergonomic} + uintx ProfiledCodeHeapSize = 122913754 {pd product} {ergonomic} + uintx ReservedCodeCacheSize = 251658240 {pd product} {ergonomic} + bool SegmentedCodeCache = true {product} {ergonomic} + bool UseCompressedClassPointers = true {lp64_product} {ergonomic} + bool UseCompressedOops = true {lp64_product} {ergonomic} + bool UseG1GC = true {product} {ergonomic} + bool UseLargePagesIndividualAllocation = false {pd product} {ergonomic} + +Logging: +Log output configuration: + #0: stdout all=warning uptime,level,tags + #1: stderr all=off uptime,level,tags + +Environment Variables: +JAVA_HOME=C:\Program Files\Java\jdk-15 +PATH=C:\Program Files\Git\mingw64\libexec\git-core;C:\Program Files\Git\mingw64\libexec\git-core;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\ne466\bin;C:\Program Files\Java\jdk-15\bin;C:\Program Files (x86)\VMware\VMware Player\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\NAT Service;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files\Git\cmd;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\ne466\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\SoftForum\XecureHSM;C:\Program Files\JetBrains\IntelliJ IDEA 2022.1\bin;C:\Users\ne466\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\Java\jdk-15\bin +USERNAME=ne466 +DISPLAY=:0.0 +LC_ALL=en_US.UTF-8 +OS=Windows_NT +PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 142 Stepping 9, GenuineIntel + + + +--------------- S Y S T E M --------------- + +OS: Windows 10 , 64 bit Build 19041 (10.0.19041.1023) +OS uptime: 0 days 9:17 hours + +CPU:total 4 (initial active 4) (2 cores per cpu, 2 threads per core) family 6 model 142 stepping 9 microcode 0xb4, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, clmul, erms, 3dnowpref, lzcnt, ht, tsc, tscinvbit, bmi1, bmi2, adx, fma + +Memory: 4k page, system-wide physical 8102M (820M free) +TotalPageFile size 10877M (AvailPageFile size 24M) +current process WorkingSet (physical memory assigned to process): 10M, peak: 10M +current process commit charge ("private bytes"): 51M, peak: 179M + +vm_info: OpenJDK 64-Bit Server VM (11.0.14.1+1-b2043.25) for windows-amd64 JRE (11.0.14.1+1-b2043.25), built on Mar 30 2022 06:22:56 by "" with MS VC++ 14.0 (VS2015) + +END. diff --git a/src/main/java/com/zatch/zatchserver/ErrorHandler/ApiResponse.java b/src/main/java/com/zatch/zatchserver/ErrorHandler/ApiResponse.java new file mode 100644 index 0000000..859ed61 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/ErrorHandler/ApiResponse.java @@ -0,0 +1,35 @@ +package com.zatch.zatchserver.ErrorHandler; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.http.HttpStatus; + +import java.util.HashMap; +import java.util.Map; + +@Setter +@Getter +public class ApiResponse { + private int code = HttpStatus.OK.value(); + private Object result; + + public ApiResponse() { } + + public void setResult(Object result) { + this.result = result; + } + + public static class ResponseMap extends ApiResponse { + + private Map responseData = new HashMap(); + + public ResponseMap() { + setResult(responseData); + } + + public void setResponseData(String key, Object value) { + this.responseData.put(key, value); + } + + } +} \ No newline at end of file diff --git a/src/main/java/com/zatch/zatchserver/Handler/WebSocketHandler.java b/src/main/java/com/zatch/zatchserver/Handler/WebSocketHandler.java new file mode 100644 index 0000000..6dba196 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/Handler/WebSocketHandler.java @@ -0,0 +1,29 @@ +package com.zatch.zatchserver.Handler; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.zatch.zatchserver.domain.ChatRoom; +import com.zatch.zatchserver.dto.ChatMessage; +import com.zatch.zatchserver.service.ChatService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; +import org.springframework.web.socket.handler.TextWebSocketHandler; + +@Slf4j +@RequiredArgsConstructor +@Component +public class WebSocketHandler extends TextWebSocketHandler { + private final ObjectMapper objectMapper; + private final ChatService chatService; + + protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { + String payload = message.getPayload(); + log.info("{}", payload); + ChatMessage chatMessage = objectMapper.readValue(payload, ChatMessage.class); + + ChatRoom chatRoom = chatService.findRoomById(chatMessage.getRoomId()); + chatRoom.handlerActions(session, chatMessage, chatService); + } +} diff --git a/src/main/java/com/zatch/zatchserver/ResponseMessage.java b/src/main/java/com/zatch/zatchserver/ResponseMessage.java index 66f9ac4..f96626d 100644 --- a/src/main/java/com/zatch/zatchserver/ResponseMessage.java +++ b/src/main/java/com/zatch/zatchserver/ResponseMessage.java @@ -11,7 +11,11 @@ public class ResponseMessage { public static final String USER_TOWN_SUCCESS = "회원 동네 설정 성공"; public static final String MY_PROFILE_SUCCESS = "내 프로필 불러오기 성공"; public static final String MYPAGE_SUCCESS = "마이페이지 불러오기 성공"; + public static final String PROFILE_IMAGE_UPLOAD_SUCCESS = "프로필 업로드 성공"; public static final String USER_NICKNAME_EDIT_SUCCESS ="회원 닉네임 수정 성공"; public static final String INTERNAL_SERVER_ERROR = "서버 내부 에러"; public static final String DB_ERROR = "데이터베이스 에러"; + + public static final String AFTER_CHAT_SUCCESS = "채팅 후기&리뷰 작성 성공"; + public static final String AFTER_CHAT_ERROR = "채팅 후기&리뷰 작성 에러"; } diff --git a/src/main/java/com/zatch/zatchserver/ZatchserverApplication.java b/src/main/java/com/zatch/zatchserver/ZatchserverApplication.java index 679c03e..e0dc174 100644 --- a/src/main/java/com/zatch/zatchserver/ZatchserverApplication.java +++ b/src/main/java/com/zatch/zatchserver/ZatchserverApplication.java @@ -7,6 +7,9 @@ public class ZatchserverApplication { public static void main(String[] args) { + // EC2 메타데이터 비활성화 + System.setProperty("com.amazonaws.sdk.disableEc2Metadata", "true"); + // 실행 SpringApplication.run(ZatchserverApplication.class, args); } diff --git a/src/main/java/com/zatch/zatchserver/config/S3Config.java b/src/main/java/com/zatch/zatchserver/config/S3Config.java new file mode 100644 index 0000000..c7aab55 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/config/S3Config.java @@ -0,0 +1,48 @@ +package com.zatch.zatchserver.config; + +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +public class S3Config { + @Value("${cloud.aws.credentials.accessKey}") + private String accessKey; + + @Value("${cloud.aws.credentials.secretKey}") + private String secretKey; + + @Value("${cloud.aws.region.static}") + private String region; + +// @Bean +// @Primary +// public BasicAWSCredentials awsCredentialsProvider(){ +// BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey); +// return basicAWSCredentials; +// } + + @Bean + public AmazonS3 amazonS3Client() { + System.out.println("KEY"+secretKey); + AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); +// AmazonS3 s3Builder = AmazonS3ClientBuilder +// .standard() +// .withRegion(region) +// .withCredentials(new AWSStaticCredentialsProvider(awsCredentialsProvider())) +// .build(); +// return s3Builder; + + return AmazonS3ClientBuilder + .standard() + .withCredentials(new AWSStaticCredentialsProvider(credentials)) + .withRegion(region) + .build(); + } +} diff --git a/src/main/java/com/zatch/zatchserver/config/WebSocketConfig.java b/src/main/java/com/zatch/zatchserver/config/WebSocketConfig.java new file mode 100644 index 0000000..732c900 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/config/WebSocketConfig.java @@ -0,0 +1,20 @@ +package com.zatch.zatchserver.config; + +import com.zatch.zatchserver.Handler.WebSocketHandler; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; + +@RequiredArgsConstructor +@Configuration +@EnableWebSocket //webSocket 활성화 +public class WebSocketConfig implements WebSocketConfigurer { + private final WebSocketHandler webSocketHandler; + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + // Handler와 webSocket 주소를 WebSocketHandlerRegistry에 추가 -> 해당 주소로 접근하면 웹소켓 연결 가능 + registry.addHandler(webSocketHandler, "/ws/chat").setAllowedOrigins("*"); + } +} diff --git a/src/main/java/com/zatch/zatchserver/controller/ChatController.java b/src/main/java/com/zatch/zatchserver/controller/ChatController.java new file mode 100644 index 0000000..1c10b2e --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/controller/ChatController.java @@ -0,0 +1,50 @@ +package com.zatch.zatchserver.controller; + +import com.zatch.zatchserver.DefaultRes; +import com.zatch.zatchserver.ResponseMessage; +import com.zatch.zatchserver.StatusCode; +import com.zatch.zatchserver.domain.ChatRoom; +import com.zatch.zatchserver.dto.PostChatReqDto; +import com.zatch.zatchserver.service.ChatService; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/chat") +public class ChatController { + + private final ChatService chatService; + + @PostMapping + public ChatRoom createRoom(@RequestBody String name) { + return chatService.createRoom(name); + } + + @GetMapping + public List findAllRoom() { + return chatService.findAllRoom(); + } + + //(거래 후) 별점, 후기 등록하기 + @PostMapping("/after_deal") + @ApiOperation(value = "별점&후기 등록", notes = "별점&후기 등록 API") + public ResponseEntity postStarReview(HttpServletRequest req) { + try { + Long send_user_id = Long.valueOf(req.getParameter("send_user_id")); + Long receive_user_id = Long.valueOf(req.getParameter("receive_user_id")); + String review_context = req.getParameter("review_context"); + int star_rating = Integer.parseInt(req.getParameter("star_rating")); + chatService.after_deal(send_user_id, receive_user_id, review_context, star_rating); + return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.AFTER_CHAT_SUCCESS, new PostChatReqDto(send_user_id, receive_user_id, review_context, star_rating)), HttpStatus.OK); + } catch (Exception e) { + return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error After Chat(Review&Star)"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } +} diff --git a/src/main/java/com/zatch/zatchserver/controller/MainController.java b/src/main/java/com/zatch/zatchserver/controller/MainController.java new file mode 100644 index 0000000..e106163 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/controller/MainController.java @@ -0,0 +1,33 @@ +package com.zatch.zatchserver.controller; + +import com.zatch.zatchserver.domain.ViewNearZatch; +import com.zatch.zatchserver.service.MainService; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/main") +public class MainController { + private final MainService mainService; + +// //메인페이지에 선택한 동네 띄우기 +// @GetMapping("/myTown") +// public List getMyTown(Long userId){ +// return mainService.getNearZatch(userId); +// +// } + + //메인페이지 내 주변 재치 조회 리스트 + @GetMapping("/{userId}/viewNearZatch") + @ApiOperation(value = "메인페이지 내 주변 재치 조회", notes = "내 주변 재치 조회 API") + public List getNearZatch(@PathVariable("userId") Long userId){ + return mainService.getNearZatch(userId); + } +} diff --git a/src/main/java/com/zatch/zatchserver/controller/UserController.java b/src/main/java/com/zatch/zatchserver/controller/UserController.java index 57827a4..cc80b77 100644 --- a/src/main/java/com/zatch/zatchserver/controller/UserController.java +++ b/src/main/java/com/zatch/zatchserver/controller/UserController.java @@ -14,6 +14,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -148,4 +149,28 @@ public ResponseEntity getMypage(@PathVariable("userId") Long userId) { return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Profile"), HttpStatus.INTERNAL_SERVER_ERROR); } } + + @PostMapping("/{userId}/upload_profile") + @ApiOperation(value = "회원 프로필 이미지 업로드", notes = "회원 프로필 이미지 업로드 API") + public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @RequestParam(value="image") MultipartFile image) { + try { + System.out.println("param_image : "+image); + userService.uploadProfile(userId, image); + return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.PROFILE_IMAGE_UPLOAD_SUCCESS, image), HttpStatus.OK); + } catch (Exception e) { + return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Image Upload"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @PatchMapping("/{userId}/patch_profile") + @ApiOperation(value = "회원 프로필 이미지 수정", notes = "회원 프로필 이미지 수정 API") + public ResponseEntity patchProfile(@PathVariable("userId") Long userId, @RequestParam(value="image") MultipartFile image) { + try { + System.out.println("param_image : "+image); + userService.patchProfile(userId, image); + return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.PROFILE_IMAGE_UPLOAD_SUCCESS, image), HttpStatus.OK); + } catch (Exception e) { + return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Image Upload"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } } diff --git a/src/main/java/com/zatch/zatchserver/controller/ZatchController.java b/src/main/java/com/zatch/zatchserver/controller/ZatchController.java new file mode 100644 index 0000000..aecf78e --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/controller/ZatchController.java @@ -0,0 +1,61 @@ +package com.zatch.zatchserver.controller; + + +import com.zatch.zatchserver.domain.ExchangeSearch; +import com.zatch.zatchserver.domain.ViewMyZatch; +import com.zatch.zatchserver.domain.Zatch; +import com.zatch.zatchserver.dto.PostZatchReq; +import com.zatch.zatchserver.service.ZatchService; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/zatch") +public class ZatchController { + + private final ZatchService postService; + + //메인페이지 조회 리스트 + @GetMapping("") + public List getPost(){ + return postService.getPostList(); + + } + + @PostMapping("") + @ApiOperation(value = "재치 등록", notes = "재치등록 API") + public void makeNewZatch(@RequestBody PostZatchReq postZatchReq) { + Zatch newPost = new Zatch( + postZatchReq.getUserId(), + postZatchReq.getCategoryId(), + postZatchReq.getIsFree(), + postZatchReq.getItemName(), + postZatchReq.getContent(), + postZatchReq.getQuantity(), + postZatchReq.getPurchaseDate(), + postZatchReq.getExpirationDate(), + postZatchReq.getIsOpened(), + postZatchReq.getAnyZatch() + ); + + postService.register(newPost); + } + + //내 재치 검색어 띄우기 + @GetMapping("/{userId}/search") + @ApiOperation(value = "교환할 수 있는 재치", notes = "검색 시, 내 재치 조회 API") + public List getMyZatch(@PathVariable("userId") Long userId){ + return postService.getZatchName(userId); + } + + //교환할 재치 검색 결과 + @GetMapping("/{userId}/search/{itemName1}&{itemName2}") + @ApiOperation(value = "교환할 재치", notes = "교환 재치 검색 결과 조회 API") + public List getSearch(@PathVariable("itemName1") String itemName1, @PathVariable("itemName2") String itemName2) { + return postService.viewAll(itemName1, itemName2); + } +} diff --git a/src/main/java/com/zatch/zatchserver/domain/ChatRoom.java b/src/main/java/com/zatch/zatchserver/domain/ChatRoom.java new file mode 100644 index 0000000..315ce0b --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/domain/ChatRoom.java @@ -0,0 +1,38 @@ +package com.zatch.zatchserver.domain; + +import com.zatch.zatchserver.dto.ChatMessage; +import com.zatch.zatchserver.service.ChatService; +import lombok.Builder; +import lombok.Getter; +import org.springframework.web.socket.WebSocketSession; + +import java.util.HashSet; +import java.util.Set; + +@Getter +public class ChatRoom { + private String roomId; + private String name; + private Set sessions = new HashSet<>(); + + @Builder + public ChatRoom(String roomId, String name) { + this.roomId = roomId; + this.name = name; + } + + public void handlerActions(WebSocketSession session, ChatMessage chatMessage, ChatService chatService) { + chatService.updateDB(String.valueOf(chatMessage.getType()), chatMessage.getRoomId(), chatMessage.getSender(), chatMessage.getMessage()); + if (chatMessage.getType().equals(ChatMessage.MessageType.ENTER)) { + sessions.add(session); + chatMessage.setMessage(chatMessage.getSender() + "님이 입장했습니다."); + } + sendMessage(chatMessage, chatService); + } + + private void sendMessage(T message, ChatService chatService) { + sessions.parallelStream() + .forEach(session -> chatService.sendMessage(session, message)); + } +} + diff --git a/src/main/java/com/zatch/zatchserver/domain/ExchangeSearch.java b/src/main/java/com/zatch/zatchserver/domain/ExchangeSearch.java new file mode 100644 index 0000000..313253f --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/domain/ExchangeSearch.java @@ -0,0 +1,22 @@ +package com.zatch.zatchserver.domain; + +import lombok.Getter; + +@Getter +public class ExchangeSearch { + private Long id; + private Long userId; + private Integer isFree; + private String itemName; + private Integer anyZatch; + private Integer likeCount; + + /*---Constructor---*/ + public ExchangeSearch(Long userId, Integer isFree, String itemName, Integer anyZatch, Integer likeCount) { + this.userId = userId; + this.isFree = isFree; + this.itemName = itemName; + this.anyZatch = anyZatch; + this.likeCount = likeCount; + } +} diff --git a/src/main/java/com/zatch/zatchserver/domain/User.java b/src/main/java/com/zatch/zatchserver/domain/User.java index 0d9d3f6..7795823 100644 --- a/src/main/java/com/zatch/zatchserver/domain/User.java +++ b/src/main/java/com/zatch/zatchserver/domain/User.java @@ -12,12 +12,12 @@ public class User { private String email; private String profileImgUrl; private String town; + private String imageUrl; /*---Constructor---*/ public User(String name, String email, String nickname) { this.name = name; this.email = email; - this.nickname = nickname; } /*---Setter---*/ @@ -27,4 +27,7 @@ public void changeProfileImg(String profileImgUrl) { public void setTown(String town) { this.town = town; } +// public void setImgaeUrl(String imageUrl) { +// this.imageUrl = imageUrl; +// } } diff --git a/src/main/java/com/zatch/zatchserver/domain/ViewMyZatch.java b/src/main/java/com/zatch/zatchserver/domain/ViewMyZatch.java new file mode 100644 index 0000000..9aef2ad --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/domain/ViewMyZatch.java @@ -0,0 +1,12 @@ +package com.zatch.zatchserver.domain; + +import lombok.Getter; + +@Getter +public class ViewMyZatch { + private String itemName; + + public ViewMyZatch(String itemName){ + this.itemName = itemName; + } +} diff --git a/src/main/java/com/zatch/zatchserver/domain/ViewNearZatch.java b/src/main/java/com/zatch/zatchserver/domain/ViewNearZatch.java new file mode 100644 index 0000000..9f6fb82 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/domain/ViewNearZatch.java @@ -0,0 +1,44 @@ +package com.zatch.zatchserver.domain; + +import lombok.Getter; + +import java.util.Date; + +@Getter +public class ViewNearZatch { + private Long categoryId; + private Boolean isFree; + private String itemName; + private String content; + private String zatchImgUrl; + private Integer quantity; + private Date purchaseDate; + private Date expirationDate; + private Date updated_at; + private Integer isOpened; + private Integer anyZatch; + private Integer likeCount; + private String town1; + private String town2; + private String town3; + + public ViewNearZatch(Long categoryId, Boolean isFree, String itemName, String content, String zatchImgUrl + , Integer quantity, Date purchaseDate, Date expirationDate, Date updated_at, Integer isOpened, Integer anyZatch, + Integer likeCount, String town1, String town2, String town3){ + this.categoryId = categoryId; + this.isFree = isFree; + this.itemName = itemName; + this.content = content; + this.zatchImgUrl = zatchImgUrl; + this.quantity = quantity; + this.purchaseDate = purchaseDate; + this.expirationDate = expirationDate; + this.updated_at = updated_at; + this.isOpened = isOpened; + this.anyZatch = anyZatch; + this.likeCount = likeCount; + this.town1 = town1; + this.town2 = town2; + this.town3 = town3; + } +} diff --git a/src/main/java/com/zatch/zatchserver/domain/Zatch.java b/src/main/java/com/zatch/zatchserver/domain/Zatch.java new file mode 100644 index 0000000..415b177 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/domain/Zatch.java @@ -0,0 +1,39 @@ +package com.zatch.zatchserver.domain; + +import lombok.Builder; +import lombok.Getter; + +import java.math.BigInteger; +import java.util.Date; + +@Getter +public class Zatch { + private Long id; + private Long userId; + private Long categoryId; + private Boolean isFree; + private String itemName; + private String content; + private Integer quantity; + private Date purchaseDate; + private Date expirationDate; + private Integer isOpened; + private Integer anyZatch; + private Integer likeCount; + + /*---Constructor---*/ + @Builder + public Zatch(Long userId, Long categoryId, Boolean isFree, String itemName, String content, Integer quantity, Date purchaseDate, Date expirationDate, Integer isOpened, Integer anyZatch) { + this.userId = userId; + this.categoryId = categoryId; + this.isFree = isFree; + this.itemName = itemName; + this.content = content; + this.quantity = quantity; + this.purchaseDate = purchaseDate; + this.expirationDate = expirationDate; + this.isOpened = isOpened; + this.anyZatch = anyZatch; + } +} + diff --git a/src/main/java/com/zatch/zatchserver/dto/ChatMessage.java b/src/main/java/com/zatch/zatchserver/dto/ChatMessage.java new file mode 100644 index 0000000..36fe0f2 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/dto/ChatMessage.java @@ -0,0 +1,19 @@ +package com.zatch.zatchserver.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ChatMessage { + public enum MessageType{ + ENTER, TALK + // ENTER : 처음 채팅방에 들어온 상태 + // TALK : 이미 session에 연결되어 있고 채팅 중인 상태 + } + + private MessageType type; + private String roomId; + private String sender; + private String message; +} diff --git a/src/main/java/com/zatch/zatchserver/dto/GetExchangeSearchResDto.java b/src/main/java/com/zatch/zatchserver/dto/GetExchangeSearchResDto.java new file mode 100644 index 0000000..fe80061 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/dto/GetExchangeSearchResDto.java @@ -0,0 +1,13 @@ +package com.zatch.zatchserver.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class GetExchangeSearchResDto { + String itemName1; // 내 물건 + String itemName2; // 교환할 물건 +} diff --git a/src/main/java/com/zatch/zatchserver/dto/PostChatReqDto.java b/src/main/java/com/zatch/zatchserver/dto/PostChatReqDto.java new file mode 100644 index 0000000..445010d --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/dto/PostChatReqDto.java @@ -0,0 +1,15 @@ +package com.zatch.zatchserver.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class PostChatReqDto { + Long send_user_id; + Long receive_user_id; + String review_context; + int star_rating; +} diff --git a/src/main/java/com/zatch/zatchserver/dto/PostUserProfileReqDto.java b/src/main/java/com/zatch/zatchserver/dto/PostUserProfileReqDto.java new file mode 100644 index 0000000..1dd1584 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/dto/PostUserProfileReqDto.java @@ -0,0 +1,11 @@ +package com.zatch.zatchserver.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.web.multipart.MultipartFile; + +@Getter +@AllArgsConstructor +public class PostUserProfileReqDto { + private MultipartFile image; +} diff --git a/src/main/java/com/zatch/zatchserver/dto/PostZatchReq.java b/src/main/java/com/zatch/zatchserver/dto/PostZatchReq.java new file mode 100644 index 0000000..63f6bc3 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/dto/PostZatchReq.java @@ -0,0 +1,24 @@ +package com.zatch.zatchserver.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.math.BigInteger; +import java.util.Date; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class PostZatchReq { + private Long userId; + private Long categoryId; + private Boolean isFree; + private String itemName; + private String content; + private Integer quantity; + private Date purchaseDate; + private Date expirationDate; + private Integer isOpened; + private Integer anyZatch; +} diff --git a/src/main/java/com/zatch/zatchserver/repository/ChatRepository.java b/src/main/java/com/zatch/zatchserver/repository/ChatRepository.java new file mode 100644 index 0000000..75f518c --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/repository/ChatRepository.java @@ -0,0 +1,43 @@ +package com.zatch.zatchserver.repository; + +import org.springframework.http.HttpStatus; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; +import org.springframework.web.server.ResponseStatusException; + +@Repository +public class ChatRepository implements ChatRepositoryImpl { + private final JdbcTemplate jdbcTemplate; + + public ChatRepository(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @Override + public String updateDB(String type, String roomId, String sender, String message) { + try { + String chat_info = "type : " + type + " / roomId : " + roomId + " / sender" + sender + " / message" + message; + System.out.println(chat_info); + String sql = "INSERT INTO chat(chat_type, chat_room_id, chat_sender, chat_message) VALUES(?, ?, ?, ?)"; + Object[] params = {type, roomId, sender, message}; + jdbcTemplate.update(sql, params); + System.out.println("chat sql insert"); + return chat_info; + } catch (Exception e){ + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Chat SQL ERROR"); + } + } + + @Override + public String after_deal(Long send_user_id, Long receive_user_id, String review_context, int star_rating) { + try { + String sql = "INSERT INTO review_star(send_user_id, receive_user_id, review_context, star_rating) VALUES(?, ?, ?, ?)"; + Object[] params = {send_user_id, receive_user_id, review_context, star_rating}; + jdbcTemplate.update(sql, params); + System.out.println("after_deal sql insert"); + return send_user_id + " -> " + receive_user_id; + } catch (Exception e){ + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "After Chat >> Review or Star Not Found"); + } + } +} diff --git a/src/main/java/com/zatch/zatchserver/repository/ChatRepositoryImpl.java b/src/main/java/com/zatch/zatchserver/repository/ChatRepositoryImpl.java new file mode 100644 index 0000000..cff76ea --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/repository/ChatRepositoryImpl.java @@ -0,0 +1,6 @@ +package com.zatch.zatchserver.repository; + +public interface ChatRepositoryImpl { + String updateDB(String type, String roomId, String sender, String message); + String after_deal(Long send_user_id, Long receive_user_id, String review_context, int star_rating); +} diff --git a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java index 0517f89..e53ba5e 100644 --- a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java @@ -1,12 +1,16 @@ package com.zatch.zatchserver.repository; import com.zatch.zatchserver.domain.User; +import com.zatch.zatchserver.service.S3Uploader; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.server.ResponseStatusException; import javax.sql.DataSource; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,6 +35,7 @@ public List selectAll() { return null; } + // 회원가입 or 로그인 확인 @Override public String isSignup(String email) { try{ @@ -43,7 +48,8 @@ public String isSignup(String email) { } return "login"; } catch (Exception e){ - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Login or Signup Error"); } + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Login or Signup Error"); + } } @Override @@ -59,10 +65,13 @@ public String getUserId(String email) { } } + // 회원가입 @Override public Long insert(User user) { try { - System.out.println("user >>> : "+ user.getName()); + System.out.println("user name >>> : "+ user.getName()); + System.out.println("user nickname >>> : "+ user.getNickname()); + System.out.println("user email >>> : "+ user.getEmail()); String sql = "INSERT INTO user(name, nickname, email) VALUES(?, ?, ?)"; Object[] params = {user.getName(), user.getNickname(), user.getEmail()}; jdbcTemplate.update(sql, params); @@ -83,6 +92,7 @@ public Long insert(User user) { } } + // 닉네임 수정 @Override public Long modifyNickname(Long userId, String newNickname) { try { @@ -96,10 +106,16 @@ public Long modifyNickname(Long userId, String newNickname) { } } + // 프로필 보기 @Override public List> profile(Long userId) { try { - String sql = "SELECT user.user_id, user.nickname, zatch.zatch_id, zatch.item_name review_context, star_rating " + + // 재치 없을 때 + + // 후기 없을 때 + + // DB 바뀌면서 item_name -> md_name 변경됨 + String sql = "SELECT user.user_id, user.nickname, user.profile_img_url, zatch.zatch_id, zatch.md_name review_context, star_rating " + "FROM zatch.review_star LEFT JOIN zatch.zatch on review_star.send_user_id = zatch.user_id LEFT JOIN zatch.user on zatch.user_id = user.user_id " + "WHERE user.user_id = ? ORDER BY review_star.created_at DESC;"; Object[] params = {userId}; @@ -110,6 +126,7 @@ public List> profile(Long userId) { } } + // 동네 설정 @Override public String addressInsert(Long userId, String addr_name, String addr_x, String addr_y){ try { @@ -138,6 +155,7 @@ else if (addr_name_3 == null){ } } + // 토큰 @Override public String insertToken(Long userId, String token) { try { @@ -149,12 +167,13 @@ public String insertToken(Long userId, String token) { } } + // 마이페이지 보기 @Override public List> getMypage(Long userId) { try { - String sql = "SELECT user.user_id, user.nickname, COUNT(*) AS zatch_count, (SELECT COUNT(zatch_like.zatch_id) AS zatch_like_count FROM zatch.zatch_like WHERE user_id = 6) AS zatch_like_count " + + String sql = "SELECT user.user_id, user.nickname, user.profile_img_url, COUNT(*) AS zatch_count, (SELECT COUNT(zatch_like.zatch_id) AS zatch_like_count FROM zatch.zatch_like WHERE user_id = ?) AS zatch_like_count " + "FROM zatch.zatch AS A LEFT JOIN zatch.user on user.user_id = A.user_id WHERE user.user_id = ?;"; - Object[] params = {userId}; + Object[] params = {userId, userId}; System.out.println("User's My Page SQL select"); return jdbcTemplate.queryForList(sql, params); } catch (Exception e){ @@ -162,4 +181,43 @@ public List> getMypage(Long userId) { } } + // S3 + @Autowired + private S3Uploader s3Uploader; + + // 프로필 이미지 업로드 + @Override + public String uploadProfile(MultipartFile image, Long userId) { + if(!image.isEmpty()) { + String storedFileName = null; + try { + storedFileName = s3Uploader.upload(image,"images"); + System.out.println("filename : "+storedFileName); + jdbcTemplate.update("UPDATE zatch.user SET profile_img_url = ? WHERE user_id = ?", storedFileName, userId); + System.out.println("Profile image upload sql update"); + return String.valueOf(image); + } catch (IOException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Profile Upload Error"); + } + } + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Profile Empty Error"); + } + + // 프로필 이미지 수정 + @Override + public String patchProfile(MultipartFile image, Long userId) { + if(!image.isEmpty()) { + String storedFileName = null; + try { + storedFileName = s3Uploader.upload(image,"images"); + System.out.println("filename : "+storedFileName); + jdbcTemplate.update("UPDATE zatch.user SET profile_img_url = ? WHERE user_id = ?", storedFileName, userId); + System.out.println("Profile image upload sql update"); + return String.valueOf(image); + } catch (IOException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Profile Upload Error"); + } + } + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Profile Empty Error"); + } } diff --git a/src/main/java/com/zatch/zatchserver/repository/MainRepository.java b/src/main/java/com/zatch/zatchserver/repository/MainRepository.java new file mode 100644 index 0000000..893501a --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/repository/MainRepository.java @@ -0,0 +1,9 @@ +package com.zatch.zatchserver.repository; + +import com.zatch.zatchserver.domain.ViewNearZatch; + +import java.util.List; + +public interface MainRepository { + List getNearZatch(Long userId); +} diff --git a/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java b/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java new file mode 100644 index 0000000..6fd2379 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java @@ -0,0 +1,50 @@ +package com.zatch.zatchserver.repository; + +import com.zatch.zatchserver.domain.ViewNearZatch; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.stereotype.Repository; + +import javax.sql.DataSource; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +@Repository +public class MainRepositoryImpl implements MainRepository { + private final JdbcTemplate jdbcTemplate; + + public MainRepositoryImpl(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + @Override + public List getNearZatch(Long userId) { + List results = jdbcTemplate.query( + "SELECT user.user_id, zatch.zatch_id, zatch.category_id, zatch.is_free, zatch.item_name, zatch.content, zatch.updated_at, quantity, purchase_date, expiration_date, is_opened, allow_any_zatch, zatch.like_count, user.town1, user.town2, user.town3, zatch_img.zatch_img_url FROM zatch LEFT OUTER JOIN zatch_img ON zatch.zatch_id = zatch_img.zatch_id JOIN user ON zatch.user_id = user.user_id WHERE ((town1 IN (SELECT town1 or town2 or town3 FROM user)) or (town2 IN (SELECT town1 or town2 or town3 FROM user)) or (town3 IN (SELECT town1 or town2 or town3 FROM user))) and user.user_id != ?", + new RowMapper() { + @Override + public ViewNearZatch mapRow(ResultSet rs, int rowNum) throws SQLException { + ViewNearZatch nearZatch = new ViewNearZatch( + rs.getLong("category_id"), + rs.getBoolean("is_free"), + rs.getString("item_name"), + rs.getString("content"), + rs.getString("zatch_img_url"), + rs.getInt("quantity"), + rs.getDate("purchase_date"), + rs.getDate("expiration_date"), + rs.getDate("updated_at"), + rs.getInt("is_opened"), + rs.getInt("allow_any_zatch"), + rs.getInt("like_count"), + rs.getString("town1"), + rs.getString("town2"), + rs.getString("town3") + ); + return nearZatch; + } + }, userId); + return results.isEmpty() ? null : results; + } +} diff --git a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java index a80a2c6..49c08ff 100644 --- a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java @@ -1,6 +1,7 @@ package com.zatch.zatchserver.repository; import com.zatch.zatchserver.domain.User; +import org.springframework.web.multipart.MultipartFile; import java.util.List; import java.util.Map; @@ -25,4 +26,8 @@ public interface UserRepository { String insertToken(Long userId, String token); List> getMypage(Long userId); + + String uploadProfile(MultipartFile image, Long userId); + + String patchProfile(MultipartFile image, Long userId); } diff --git a/src/main/java/com/zatch/zatchserver/repository/ZatchRepository.java b/src/main/java/com/zatch/zatchserver/repository/ZatchRepository.java new file mode 100644 index 0000000..f8d2fd1 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/repository/ZatchRepository.java @@ -0,0 +1,23 @@ +package com.zatch.zatchserver.repository; + + +import com.zatch.zatchserver.domain.ExchangeSearch; +import com.zatch.zatchserver.domain.ViewMyZatch; +import com.zatch.zatchserver.domain.Zatch; + +import java.util.List; + +public interface ZatchRepository { + + List findAllByOrderByCreatedAtDesc(); + + + Long register(Zatch zatch); + + List getZatchName(Long userId); + + List viewAll(String itemName1, String itemName2); + +} + + diff --git a/src/main/java/com/zatch/zatchserver/repository/ZatchRepositoryImpl.java b/src/main/java/com/zatch/zatchserver/repository/ZatchRepositoryImpl.java new file mode 100644 index 0000000..ff64d51 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/repository/ZatchRepositoryImpl.java @@ -0,0 +1,92 @@ +package com.zatch.zatchserver.repository; + + +import com.zatch.zatchserver.domain.ExchangeSearch; +import com.zatch.zatchserver.domain.ViewMyZatch; +import com.zatch.zatchserver.domain.Zatch; +import lombok.AllArgsConstructor; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.PreparedStatementCreator; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + + +@Repository +@AllArgsConstructor +public class ZatchRepositoryImpl implements ZatchRepository { + + private final JdbcTemplate jdbcTemplate; + + @Override + public List findAllByOrderByCreatedAtDesc() { + return null; + } + + @Override + public Long register(Zatch zatch) { + KeyHolder keyHolder = new GeneratedKeyHolder(); + PreparedStatementCreator preparedStatementCreator = (connection) -> { + PreparedStatement preparedStatement = connection.prepareStatement("insert into zatch (user_id,category_id,is_Free,item_name, content, quantity, purchase_date, expiration_date, is_opened, allow_any_zatch) values (?,?,?,?,?,?,?,?,?,?)", + new String[]{"zatchId"}); + preparedStatement.setLong(1, zatch.getUserId()); + preparedStatement.setLong(2, zatch.getCategoryId()); + preparedStatement.setBoolean(3, zatch.getIsFree()); + preparedStatement.setString(4, zatch.getItemName()); + preparedStatement.setString(5, zatch.getContent()); + preparedStatement.setInt(6, zatch.getQuantity()); + preparedStatement.setDate(7, (Date) zatch.getPurchaseDate()); + preparedStatement.setDate(8, (Date) zatch.getExpirationDate()); + preparedStatement.setInt(9, zatch.getIsOpened()); + preparedStatement.setInt(10, zatch.getAnyZatch()); + + return preparedStatement; + }; + jdbcTemplate.update(preparedStatementCreator, keyHolder); + return keyHolder.getKey().longValue(); + } + + @Override + public List getZatchName(Long userId) { + List results = jdbcTemplate.query( + "SELECT item_name from zatch where user_id = ?", + new RowMapper() { + @Override + public ViewMyZatch mapRow(ResultSet rs, int rowNum) throws SQLException { + ViewMyZatch myZatch = new ViewMyZatch( + rs.getString("item_name")); + return myZatch; + } + }, userId); + return results.isEmpty() ? null : results; + } + + @Override + public List viewAll(String itemName1, String itemName2) { + List results = jdbcTemplate.query( + "SELECT * from zatch where (item_name LIKE ? OR item_name LIKE ?)", + new RowMapper() { + @Override + public ExchangeSearch mapRow(ResultSet rs, int rowNum) throws SQLException { + ExchangeSearch exchangeSearch = new ExchangeSearch( + rs.getLong("user_id"), + rs.getInt("is_free"), + rs.getString("item_name"), + rs.getInt("allow_any_zatch"), + rs.getInt("like_count") + ); + return exchangeSearch; + } + }, itemName1, itemName2); + return results.isEmpty() ? null : results; + } +} + + diff --git a/src/main/java/com/zatch/zatchserver/service/ChatService.java b/src/main/java/com/zatch/zatchserver/service/ChatService.java new file mode 100644 index 0000000..91c793b --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/service/ChatService.java @@ -0,0 +1,15 @@ +package com.zatch.zatchserver.service; + +import com.zatch.zatchserver.domain.ChatRoom; +import org.springframework.web.socket.WebSocketSession; + +import java.util.List; + +public interface ChatService { + List findAllRoom(); + ChatRoom createRoom(String name); + ChatRoom findRoomById(String roomId); + void sendMessage(WebSocketSession session, T message); + String after_deal(Long send_user_id, Long receive_user_id, String review_context, int star_rating); + String updateDB(String type, String roomId, String sender, String message); +} diff --git a/src/main/java/com/zatch/zatchserver/service/ChatServiceImpl.java b/src/main/java/com/zatch/zatchserver/service/ChatServiceImpl.java new file mode 100644 index 0000000..3f31074 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/service/ChatServiceImpl.java @@ -0,0 +1,65 @@ +package com.zatch.zatchserver.service; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.zatch.zatchserver.domain.ChatRoom; +import com.zatch.zatchserver.repository.ChatRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; + +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.util.*; + +@Slf4j +@RequiredArgsConstructor +@Service +public class ChatServiceImpl implements ChatService { + private final ObjectMapper objectMapper; + private Map chatRooms; + + private final ChatRepository chatRepository; + + @PostConstruct + private void init() { + chatRooms = new LinkedHashMap<>(); + } + + public List findAllRoom() { + return new ArrayList<>(chatRooms.values()); + } + + public ChatRoom findRoomById(String roomId) { + return chatRooms.get(roomId); + } + + public ChatRoom createRoom(String name) { + String randomId = UUID.randomUUID().toString(); + ChatRoom chatRoom = ChatRoom.builder() + .roomId(randomId) + .name(name) + .build(); + chatRooms.put(randomId, chatRoom); + return chatRoom; + } + + public void sendMessage(WebSocketSession session, T message) { + try{ + session.sendMessage(new TextMessage(objectMapper.writeValueAsString(message))); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + + @Override + public String after_deal(Long send_user_id, Long receive_user_id, String review_context, int star_rating) { + return chatRepository.after_deal(send_user_id, receive_user_id, review_context, star_rating); + } + + @Override + public String updateDB(String type, String roomId, String sender, String message) { + return chatRepository.updateDB(type, roomId, sender, message); + } +} diff --git a/src/main/java/com/zatch/zatchserver/service/MainService.java b/src/main/java/com/zatch/zatchserver/service/MainService.java new file mode 100644 index 0000000..9443ba9 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/service/MainService.java @@ -0,0 +1,17 @@ +package com.zatch.zatchserver.service; + +import com.zatch.zatchserver.domain.ViewNearZatch; +import com.zatch.zatchserver.repository.MainRepositoryImpl; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@RequiredArgsConstructor +@Service +public class MainService { + private final MainRepositoryImpl mainRepository; + + public List getNearZatch(Long userId){return mainRepository.getNearZatch(userId);} + +} diff --git a/src/main/java/com/zatch/zatchserver/service/S3Uploader.java b/src/main/java/com/zatch/zatchserver/service/S3Uploader.java new file mode 100644 index 0000000..03a3762 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/service/S3Uploader.java @@ -0,0 +1,72 @@ +package com.zatch.zatchserver.service; + +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.PutObjectRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Optional; + +@Slf4j +@RequiredArgsConstructor // final 멤버변수가 있으면 생성자 항목에 포함시킴 +@Component +@Service +public class S3Uploader { + + private final AmazonS3Client amazonS3Client; + + @Value("${cloud.aws.s3.bucket}") + private String bucket; + + // MultipartFile을 전달받아 File로 전환한 후 S3에 업로드 + public String upload(MultipartFile multipartFile, String dirName) throws IOException { + File uploadFile = convert(multipartFile) + .orElseThrow(() -> new IllegalArgumentException("MultipartFile -> File 전환 실패")); + return upload(uploadFile, dirName); + } + + private String upload(File uploadFile, String dirName) { + String fileName = dirName + "/" + uploadFile.getName(); + String uploadImageUrl = putS3(uploadFile, fileName); + + removeNewFile(uploadFile); // 로컬에 생성된 File 삭제 (MultipartFile -> File 전환 하며 로컬에 파일 생성됨) + + return uploadImageUrl; // 업로드된 파일의 S3 URL 주소 반환 + } + + private String putS3(File uploadFile, String fileName) { + amazonS3Client.putObject( + new PutObjectRequest(bucket, fileName, uploadFile) + .withCannedAcl(CannedAccessControlList.PublicRead) // PublicRead 권한으로 업로드 됨 + ); + return amazonS3Client.getUrl(bucket, fileName).toString(); + } + + private void removeNewFile(File targetFile) { + if(targetFile.delete()) { + log.info("파일이 삭제되었습니다."); + }else { + log.info("파일이 삭제되지 못했습니다."); + } + } + + private Optional convert(MultipartFile file) throws IOException { + File convertFile = new File(file.getOriginalFilename()); + if(convertFile.createNewFile()) { + try (FileOutputStream fos = new FileOutputStream(convertFile)) { + fos.write(file.getBytes()); + } + return Optional.of(convertFile); + } + return Optional.empty(); + } +} \ No newline at end of file diff --git a/src/main/java/com/zatch/zatchserver/service/UserService.java b/src/main/java/com/zatch/zatchserver/service/UserService.java index 1fc42ea..18f6d39 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserService.java +++ b/src/main/java/com/zatch/zatchserver/service/UserService.java @@ -1,6 +1,7 @@ package com.zatch.zatchserver.service; import com.zatch.zatchserver.domain.User; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -24,4 +25,8 @@ public interface UserService { String token(Long userId, String token); String mypage(Long userId); + + String uploadProfile(Long userId, MultipartFile image); + + String patchProfile(Long userId, MultipartFile image); } diff --git a/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java b/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java index c7dc72f..00d4946 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java +++ b/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java @@ -3,8 +3,12 @@ import com.zatch.zatchserver.domain.User; import com.zatch.zatchserver.repository.UserRepository; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import javax.transaction.Transactional; +import java.io.IOException; import java.util.List; @RequiredArgsConstructor @@ -13,6 +17,10 @@ public class UserServiceImpl implements UserService { private final UserRepository userRepository; + // S3 + @Autowired + private S3Uploader s3Uploader; + @Override public String loginOrSignup(String email) { return userRepository.isSignup(email); @@ -62,4 +70,14 @@ public String token(Long userId, String token) { public String mypage(Long userId) { return String.valueOf(userRepository.getMypage(userId)); } + + @Override + public String uploadProfile(Long userId, MultipartFile image) { + return userRepository.uploadProfile(image, userId); + } + + @Override + public String patchProfile(Long userId, MultipartFile image) { + return userRepository.patchProfile(image, userId); + } } diff --git a/src/main/java/com/zatch/zatchserver/service/ZatchService.java b/src/main/java/com/zatch/zatchserver/service/ZatchService.java new file mode 100644 index 0000000..bfd5c7f --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/service/ZatchService.java @@ -0,0 +1,36 @@ +package com.zatch.zatchserver.service; + +import com.zatch.zatchserver.domain.ExchangeSearch; +import com.zatch.zatchserver.domain.ViewMyZatch; +import com.zatch.zatchserver.domain.Zatch; +import com.zatch.zatchserver.repository.ZatchRepository; +import com.zatch.zatchserver.repository.ZatchRepositoryImpl; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@RequiredArgsConstructor +@Service +public class ZatchService { + + private final ZatchRepository zatchRepository; + + @Autowired + public ZatchService(ZatchRepositoryImpl zatchRepository) { + this.zatchRepository = zatchRepository; + } + + public List getPostList() { + return zatchRepository.findAllByOrderByCreatedAtDesc(); + } + + public Long register(Zatch zatch) { + return zatchRepository.register(zatch); + } + + public List getZatchName(Long userId){return zatchRepository.getZatchName(userId);} + + public List viewAll(String itemName1, String itemName2) {return zatchRepository.viewAll(itemName1, itemName2);} +} diff --git a/src/main/java/com/zatch/zatchserver/swagger/config/SwaggerConfig.java b/src/main/java/com/zatch/zatchserver/swagger/config/SwaggerConfig.java index f1d8c1b..181ae75 100644 --- a/src/main/java/com/zatch/zatchserver/swagger/config/SwaggerConfig.java +++ b/src/main/java/com/zatch/zatchserver/swagger/config/SwaggerConfig.java @@ -6,7 +6,6 @@ import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; -import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2;