From fff44ecb8dca59e83c66490e112db660f55d939f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 8 Dec 2022 21:59:29 +0900 Subject: [PATCH 001/264] =?UTF-8?q?[BE-15]=20feat:=20BaseEntity=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recodeit/server/domain/BaseEntity.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/com/recodeit/server/domain/BaseEntity.java diff --git a/src/main/java/com/recodeit/server/domain/BaseEntity.java b/src/main/java/com/recodeit/server/domain/BaseEntity.java new file mode 100644 index 00000000..5348713c --- /dev/null +++ b/src/main/java/com/recodeit/server/domain/BaseEntity.java @@ -0,0 +1,27 @@ +package com.recodeit.server.domain; + +import com.sun.istack.NotNull; +import java.time.LocalDateTime; +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public abstract class BaseEntity { + + @NotNull + @CreatedDate + private LocalDateTime createdAt; + + @NotNull + @LastModifiedDate + private LocalDateTime modifiedAt; + + @NotNull + protected boolean isDeleted; +} From 17a985d6996f9514a87abadefe7f7914e67074a2 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 8 Dec 2022 21:59:51 +0900 Subject: [PATCH 002/264] =?UTF-8?q?[BE-15]=20feat:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EA=B4=80=EB=A0=A8=20Entity=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recodeit/server/constant/LoginType.java | 7 ++++ .../com/recodeit/server/domain/Member.java | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/com/recodeit/server/constant/LoginType.java create mode 100644 src/main/java/com/recodeit/server/domain/Member.java diff --git a/src/main/java/com/recodeit/server/constant/LoginType.java b/src/main/java/com/recodeit/server/constant/LoginType.java new file mode 100644 index 00000000..714b26aa --- /dev/null +++ b/src/main/java/com/recodeit/server/constant/LoginType.java @@ -0,0 +1,7 @@ +package com.recodeit.server.constant; + +public enum LoginType { + LOCAL, + KAKAO, + GOOGLE; +} diff --git a/src/main/java/com/recodeit/server/domain/Member.java b/src/main/java/com/recodeit/server/domain/Member.java new file mode 100644 index 00000000..123a1b65 --- /dev/null +++ b/src/main/java/com/recodeit/server/domain/Member.java @@ -0,0 +1,37 @@ +package com.recodeit.server.domain; + +import com.recodeit.server.constant.LoginType; +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +public class Member extends BaseEntity { + + @Id + @GeneratedValue(generator = "uuid2") + @Column(name = "MEMBER_ID", columnDefinition = "BINARY(16)") + private UUID id; + private String password; + private String nickname; + private String oauthId; + private LoginType loginType; + + private Member(String password, String nickname, String oauthId, LoginType loginType) { + this.password = password; + this.nickname = nickname; + this.oauthId = oauthId; + this.loginType = loginType; + } + + public static Member of(String password, String nickname, String oauthId, LoginType loginType) { + return new Member(password, nickname, oauthId, loginType); + } +} From a63a327090a5fde038abc7df9916adb09e73b89f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 8 Dec 2022 22:12:12 +0900 Subject: [PATCH 003/264] =?UTF-8?q?[BE-17]=20chore:=20application.yml?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.properties | 1 - src/main/resources/application.yml | 0 2 files changed, 1 deletion(-) delete mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/application.yml diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 00000000..e69de29b From 00a91fc0d0776b040870a92f3e1138ea082dc75c Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 00:21:32 +0900 Subject: [PATCH 004/264] =?UTF-8?q?[BE-17]=20refactor:=20BaseEntity=20dele?= =?UTF-8?q?teAt=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recodeit/server/domain/BaseEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recodeit/server/domain/BaseEntity.java b/src/main/java/com/recodeit/server/domain/BaseEntity.java index 5348713c..188b1f84 100644 --- a/src/main/java/com/recodeit/server/domain/BaseEntity.java +++ b/src/main/java/com/recodeit/server/domain/BaseEntity.java @@ -23,5 +23,5 @@ public abstract class BaseEntity { private LocalDateTime modifiedAt; @NotNull - protected boolean isDeleted; + private LocalDateTime deletedAt; } From 2f3a18770fce06acdbee83193e5a66572da37d5b Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 00:22:01 +0900 Subject: [PATCH 005/264] =?UTF-8?q?[BE-17]=20refactor:=20Member=20SoftDele?= =?UTF-8?q?te=EC=99=80=20Where=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recodeit/server/domain/Member.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/recodeit/server/domain/Member.java b/src/main/java/com/recodeit/server/domain/Member.java index 123a1b65..ffbd5744 100644 --- a/src/main/java/com/recodeit/server/domain/Member.java +++ b/src/main/java/com/recodeit/server/domain/Member.java @@ -9,10 +9,14 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter +@Where(clause = "deleted_at is null") +@SQLDelete(sql = "UPDATE member SET deleted_at = CURRENT_TIMESTAMP WHERE id = ?") public class Member extends BaseEntity { @Id From 5d867e171a25bd948fa0846defd3192c9c9137ae Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 09:36:50 +0900 Subject: [PATCH 006/264] =?UTF-8?q?[BE-12]=20feat:=20MemberController=20?= =?UTF-8?q?=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/MemberController.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/recodeit/server/controller/MemberController.java diff --git a/src/main/java/com/recodeit/server/controller/MemberController.java b/src/main/java/com/recodeit/server/controller/MemberController.java new file mode 100644 index 00000000..ace44817 --- /dev/null +++ b/src/main/java/com/recodeit/server/controller/MemberController.java @@ -0,0 +1,25 @@ +package com.recodeit.server.controller; + +import com.recodeit.server.service.MemberService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class MemberController { + + private final MemberService memberService; + + @GetMapping("/member/oauth/{logintype}") + public void oauthLogin(@PathVariable("logintype") String loginType) { + memberService.oauthLogin(loginType); + } + + @PostMapping("/member/oauth/{loginType}") + public void oauthRegister(@PathVariable("logintype") String loginType) { + memberService.oauthRegister(loginType); + } +} From c13fccc8528f4f41d6416a9c69cfeadfbb6708b8 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 09:37:17 +0900 Subject: [PATCH 007/264] =?UTF-8?q?[BE-12]=20feat:=20string=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20LoginType=EC=9D=84=20=EC=B0=BE=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recodeit/server/constant/LoginType.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/recodeit/server/constant/LoginType.java b/src/main/java/com/recodeit/server/constant/LoginType.java index 714b26aa..35c8fe93 100644 --- a/src/main/java/com/recodeit/server/constant/LoginType.java +++ b/src/main/java/com/recodeit/server/constant/LoginType.java @@ -1,7 +1,16 @@ package com.recodeit.server.constant; +import java.util.Arrays; + public enum LoginType { LOCAL, KAKAO, GOOGLE; + + public static LoginType findByString(String str) { + return Arrays.stream(LoginType.values()) + .filter(loginType -> loginType.name().equals(str)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("")); + } } From 7cd6a31827698c67ccfbc015dd026342afedfa51 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 09:37:37 +0900 Subject: [PATCH 008/264] =?UTF-8?q?[BE-12]=20feat:=20Oauth=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/oauth/GoogleOauthService.java | 15 +++++++++++++++ .../server/service/oauth/KakaoOauthService.java | 15 +++++++++++++++ .../server/service/oauth/OauthService.java | 10 ++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java create mode 100644 src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java create mode 100644 src/main/java/com/recodeit/server/service/oauth/OauthService.java diff --git a/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java new file mode 100644 index 00000000..710931fb --- /dev/null +++ b/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java @@ -0,0 +1,15 @@ +package com.recodeit.server.service.oauth; + +import com.recodeit.server.constant.LoginType; + +public class GoogleOauthService implements OauthService { + @Override + public LoginType getLoginType(String loginType) { + return LoginType.GOOGLE; + } + + @Override + public void request() { + + } +} diff --git a/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java new file mode 100644 index 00000000..43c92eb6 --- /dev/null +++ b/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java @@ -0,0 +1,15 @@ +package com.recodeit.server.service.oauth; + +import com.recodeit.server.constant.LoginType; + +public class KakaoOauthService implements OauthService { + @Override + public LoginType getLoginType(String loginType) { + return LoginType.KAKAO; + } + + @Override + public void request() { + + } +} diff --git a/src/main/java/com/recodeit/server/service/oauth/OauthService.java b/src/main/java/com/recodeit/server/service/oauth/OauthService.java new file mode 100644 index 00000000..606ebc6f --- /dev/null +++ b/src/main/java/com/recodeit/server/service/oauth/OauthService.java @@ -0,0 +1,10 @@ +package com.recodeit.server.service.oauth; + +import com.recodeit.server.constant.LoginType; + +public interface OauthService { + + LoginType getLoginType(String loginType); + + void request(); +} From 35bc9fa008e8bd4cc75faf65c65669890e15c8d7 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 09:38:07 +0900 Subject: [PATCH 009/264] =?UTF-8?q?[BE-12]=20feat:=20MemberService?= =?UTF-8?q?=EC=9D=98=20Oauth=20=EB=A1=9C=EA=B7=B8=EC=9D=B8/=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EA=B0=80=EC=9E=85=20=EC=9D=B8=ED=84=B0=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/MemberService.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/recodeit/server/service/MemberService.java diff --git a/src/main/java/com/recodeit/server/service/MemberService.java b/src/main/java/com/recodeit/server/service/MemberService.java new file mode 100644 index 00000000..adb83af2 --- /dev/null +++ b/src/main/java/com/recodeit/server/service/MemberService.java @@ -0,0 +1,20 @@ +package com.recodeit.server.service; + +import com.recodeit.server.service.oauth.OauthService; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class MemberService { + private final List oauthServices; + + public void oauthLogin(String loginType) { + + } + + public void oauthRegister(String loginType) { + + } +} From 6b2adba98ad6b119ccae30c5b417d47eaa4cf761 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 09:48:19 +0900 Subject: [PATCH 010/264] =?UTF-8?q?[BE-12]=20feat:=20Transactional=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recodeit/server/service/MemberService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/recodeit/server/service/MemberService.java b/src/main/java/com/recodeit/server/service/MemberService.java index adb83af2..a08cc145 100644 --- a/src/main/java/com/recodeit/server/service/MemberService.java +++ b/src/main/java/com/recodeit/server/service/MemberService.java @@ -4,16 +4,19 @@ import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor public class MemberService { private final List oauthServices; + @Transactional public void oauthLogin(String loginType) { } + @Transactional public void oauthRegister(String loginType) { } From 936ddf6ae8829e9ebdf1f842f41befbddde44b43 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 13:17:16 +0900 Subject: [PATCH 011/264] =?UTF-8?q?[BE-12]=20refactor:=20OauthService.getL?= =?UTF-8?q?oginType=20Arguments=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recodeit/server/service/oauth/GoogleOauthService.java | 2 +- .../com/recodeit/server/service/oauth/KakaoOauthService.java | 2 +- .../java/com/recodeit/server/service/oauth/OauthService.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java index 710931fb..458c9dbe 100644 --- a/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java +++ b/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java @@ -4,7 +4,7 @@ public class GoogleOauthService implements OauthService { @Override - public LoginType getLoginType(String loginType) { + public LoginType getLoginType() { return LoginType.GOOGLE; } diff --git a/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java index 43c92eb6..3cd999ca 100644 --- a/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java +++ b/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java @@ -4,7 +4,7 @@ public class KakaoOauthService implements OauthService { @Override - public LoginType getLoginType(String loginType) { + public LoginType getLoginType() { return LoginType.KAKAO; } diff --git a/src/main/java/com/recodeit/server/service/oauth/OauthService.java b/src/main/java/com/recodeit/server/service/oauth/OauthService.java index 606ebc6f..94917f15 100644 --- a/src/main/java/com/recodeit/server/service/oauth/OauthService.java +++ b/src/main/java/com/recodeit/server/service/oauth/OauthService.java @@ -4,7 +4,7 @@ public interface OauthService { - LoginType getLoginType(String loginType); + LoginType getLoginType(); void request(); } From 2793c5868c9c60802443add493f989bec8e2cd30 Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 9 Dec 2022 16:39:31 +0900 Subject: [PATCH 012/264] =?UTF-8?q?[BE-14]=20chore:=20local=20=EB=82=B4?= =?UTF-8?q?=EC=9E=A5=20redis=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 6 ++++ .../RecodeItServerApplicationTests.java | 2 ++ .../LocalRedisConfiguration.java | 34 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/test/java/com/recodeit/server/configuration/LocalRedisConfiguration.java diff --git a/build.gradle b/build.gradle index fc72faee..84c9b12b 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,12 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.session:spring-session-data-redis' + + // embedded redis + implementation('it.ozimov:embedded-redis:0.7.3') { + exclude group : "org.slf4j", module : "slf4j-simple" + } + compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'com.h2database:h2' diff --git a/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java b/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java index d836da3a..12de41b3 100644 --- a/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java +++ b/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java @@ -2,8 +2,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Profile; @SpringBootTest +@Profile("test") class RecodeItServerApplicationTests { @Test diff --git a/src/test/java/com/recodeit/server/configuration/LocalRedisConfiguration.java b/src/test/java/com/recodeit/server/configuration/LocalRedisConfiguration.java new file mode 100644 index 00000000..fcac515b --- /dev/null +++ b/src/test/java/com/recodeit/server/configuration/LocalRedisConfiguration.java @@ -0,0 +1,34 @@ +package com.recodeit.server.configuration; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import redis.embedded.RedisServer; + +@Configuration +@Profile("test") +public class LocalRedisConfiguration { + + private final int redisPort; + + private RedisServer redisServer; + + public LocalRedisConfiguration(@Value("${spring.redis.port}") int redisPort) { + this.redisPort = redisPort; + } + + @PostConstruct + public void startRedis() { + redisServer = new RedisServer(redisPort); + redisServer.start(); + } + + @PreDestroy + public void stop() { + if (redisServer != null) { + redisServer.stop(); + } + } +} From d120c65af8fc2c2d49f02438073983c80fd94e66 Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 9 Dec 2022 16:44:38 +0900 Subject: [PATCH 013/264] =?UTF-8?q?[BE-15]=20chore:=20application.yml?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/{application.properties => application.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/resources/{application.properties => application.yml} (100%) diff --git a/src/main/resources/application.properties b/src/main/resources/application.yml similarity index 100% rename from src/main/resources/application.properties rename to src/main/resources/application.yml From 8099603abb1708e0d2b3cc3b5753e5146e59c11d Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 9 Dec 2022 17:10:24 +0900 Subject: [PATCH 014/264] =?UTF-8?q?[BE-14]=20fix:=20PostConstruct=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0,=20=EC=83=9D=EC=84=B1=EC=9E=90=20protected?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD,=20final=20=ED=82=A4=EC=9B=8C?= =?UTF-8?q?=EB=93=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...guration.java => EmbeddedRedisConfiguration.java} | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) rename src/test/java/com/recodeit/server/configuration/{LocalRedisConfiguration.java => EmbeddedRedisConfiguration.java} (69%) diff --git a/src/test/java/com/recodeit/server/configuration/LocalRedisConfiguration.java b/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java similarity index 69% rename from src/test/java/com/recodeit/server/configuration/LocalRedisConfiguration.java rename to src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java index fcac515b..b2252085 100644 --- a/src/test/java/com/recodeit/server/configuration/LocalRedisConfiguration.java +++ b/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java @@ -9,19 +9,15 @@ @Configuration @Profile("test") -public class LocalRedisConfiguration { +public class EmbeddedRedisConfiguration { private final int redisPort; - private RedisServer redisServer; + private final RedisServer redisServer; - public LocalRedisConfiguration(@Value("${spring.redis.port}") int redisPort) { + protected EmbeddedRedisConfiguration(@Value("${spring.redis.port}") int redisPort) { this.redisPort = redisPort; - } - - @PostConstruct - public void startRedis() { - redisServer = new RedisServer(redisPort); + this.redisServer = new RedisServer(redisPort); redisServer.start(); } From f869695be93de1780a88955391042a3c13ae10ac Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 9 Dec 2022 17:11:00 +0900 Subject: [PATCH 015/264] =?UTF-8?q?[BE-14]=20fix:=20Profile=EC=9D=84=20Act?= =?UTF-8?q?iveProfiles=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recodeit/server/RecodeItServerApplicationTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java b/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java index 12de41b3..38ddb31f 100644 --- a/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java +++ b/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java @@ -3,9 +3,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Profile; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest -@Profile("test") +@ActiveProfiles("test") class RecodeItServerApplicationTests { @Test From 9e982e122891c58d927a8dd88e732011458fb146 Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 9 Dec 2022 17:31:37 +0900 Subject: [PATCH 016/264] =?UTF-8?q?[BE-15]=20chore:=20profile=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-OAuth.yml | 4 +++ src/main/resources/application-datasource.yml | 10 +++++++ src/main/resources/application-dev.yml | 27 +++++++++++++++++++ src/main/resources/application-local.yml | 27 +++++++++++++++++++ src/main/resources/application-redis.yml | 10 +++++++ src/main/resources/application.yml | 8 +++++- .../com/recodeit/server/application-test.yml | 14 ++++++++++ 7 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/application-OAuth.yml create mode 100644 src/main/resources/application-datasource.yml create mode 100644 src/main/resources/application-dev.yml create mode 100644 src/main/resources/application-local.yml create mode 100644 src/main/resources/application-redis.yml create mode 100644 src/test/java/com/recodeit/server/application-test.yml diff --git a/src/main/resources/application-OAuth.yml b/src/main/resources/application-OAuth.yml new file mode 100644 index 00000000..6396c8c5 --- /dev/null +++ b/src/main/resources/application-OAuth.yml @@ -0,0 +1,4 @@ +spring: + config: + activate: + on-profile: "OAuth" \ No newline at end of file diff --git a/src/main/resources/application-datasource.yml b/src/main/resources/application-datasource.yml new file mode 100644 index 00000000..6f1fd8e4 --- /dev/null +++ b/src/main/resources/application-datasource.yml @@ -0,0 +1,10 @@ +spring: + config: + activate: + on-profile: "datasource" + datasource: + driver-class-name: org.mariadb.jdbc.Driver + url: jdbc:mariadb://${DATASOURCE_HOST:localhost}:3306/RecordIt?characterEncoding=UTF-8&serverTimezone=UTC + username: ${DATASOURCE_USERNAME:root} + password: ${DATASOURCE_PASSWORD:} + diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 00000000..cd23c70d --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,27 @@ +server: + port: 8080 + servlet: + context-path: / + encoding: + charset: utf-8 +spring: + config: + activate: + on-profile: "dev" + jpa: + open-in-view: true + hibernate: + ddl-auto: update + naming: + physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl + show-sql: true + properties: + hibernate: + format_sql: true + output: + ansi: + enabled: always + logging: + level: + '[org.springframework.web]': INFO + '[org.hibernate]': INFO diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml new file mode 100644 index 00000000..26f3314c --- /dev/null +++ b/src/main/resources/application-local.yml @@ -0,0 +1,27 @@ +server: + port: 8080 + servlet: + context-path: / + encoding: + charset: utf-8 +spring: + config: + activate: + on-profile: "local" + jpa: + open-in-view: true + hibernate: + ddl-auto: update + naming: + physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl + show-sql: true + properties: + hibernate: + format_sql: true + output: + ansi: + enabled: always + logging: + level: + '[org.springframework.web]': DEBUG + '[org.hibernate]': DEBUG diff --git a/src/main/resources/application-redis.yml b/src/main/resources/application-redis.yml new file mode 100644 index 00000000..66c3bebb --- /dev/null +++ b/src/main/resources/application-redis.yml @@ -0,0 +1,10 @@ +spring: + config: + activate: + on-profile: "redis" + redis: + host: ${REDIS_HOST:localhost} + port: ${REDIS_PORT:6379} + session: + store-type: redis + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8b137891..d6a64ef2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1 +1,7 @@ - +spring: + profiles: + group: + "test": "test" + "local": "local, datasource, redis, OAuth" + "dev": "dev, datasource, redis, OAuth" + "prod": "prod" \ No newline at end of file diff --git a/src/test/java/com/recodeit/server/application-test.yml b/src/test/java/com/recodeit/server/application-test.yml new file mode 100644 index 00000000..f959f6d4 --- /dev/null +++ b/src/test/java/com/recodeit/server/application-test.yml @@ -0,0 +1,14 @@ +spring: + config: + activate: + on-profile: "test" + datasource: + driver-class-name: org.h2.Driver + url: jdbc:h2:~/RecordIt + username: sa + password: + redis: + host: localhost + port: 49151 + session: + store-type: redis \ No newline at end of file From 98574068ad22a012c441f49f07d87c543d33c7c2 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 18:10:01 +0900 Subject: [PATCH 017/264] =?UTF-8?q?[BE-14]=20refactor:=20=EC=A0=91?= =?UTF-8?q?=EA=B7=BC=EC=A0=9C=EC=96=B4=EC=9E=90=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/configuration/EmbeddedRedisConfiguration.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java b/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java index b2252085..025d8d6b 100644 --- a/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java +++ b/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java @@ -1,6 +1,5 @@ package com.recodeit.server.configuration; -import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; @@ -11,18 +10,15 @@ @Profile("test") public class EmbeddedRedisConfiguration { - private final int redisPort; - private final RedisServer redisServer; protected EmbeddedRedisConfiguration(@Value("${spring.redis.port}") int redisPort) { - this.redisPort = redisPort; this.redisServer = new RedisServer(redisPort); redisServer.start(); } @PreDestroy - public void stop() { + private void stop() { if (redisServer != null) { redisServer.stop(); } From 41c906326ce7849ec0c7ee3b6ce13ec5b43c00fc Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 18:18:16 +0900 Subject: [PATCH 018/264] =?UTF-8?q?[BE-15]=20chore:=20application-oauth.ym?= =?UTF-8?q?l=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{application-OAuth.yml => application-oauth.yml} | 2 +- src/main/resources/application.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/main/resources/{application-OAuth.yml => application-oauth.yml} (56%) diff --git a/src/main/resources/application-OAuth.yml b/src/main/resources/application-oauth.yml similarity index 56% rename from src/main/resources/application-OAuth.yml rename to src/main/resources/application-oauth.yml index 6396c8c5..6a17e631 100644 --- a/src/main/resources/application-OAuth.yml +++ b/src/main/resources/application-oauth.yml @@ -1,4 +1,4 @@ spring: config: activate: - on-profile: "OAuth" \ No newline at end of file + on-profile: "oauth" \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d6a64ef2..95437214 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,6 +2,6 @@ spring: profiles: group: "test": "test" - "local": "local, datasource, redis, OAuth" - "dev": "dev, datasource, redis, OAuth" + "local": "local, datasource, redis, oauth" + "dev": "dev, datasource, redis, oauth" "prod": "prod" \ No newline at end of file From 98429b55a428e0f40e5ce806d143ab330a2c2b50 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 18:35:27 +0900 Subject: [PATCH 019/264] =?UTF-8?q?[BE-15]=20chore:=20application-test.yml?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recodeit/server => resources}/application-test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) rename src/test/{java/com/recodeit/server => resources}/application-test.yml (80%) diff --git a/src/test/java/com/recodeit/server/application-test.yml b/src/test/resources/application-test.yml similarity index 80% rename from src/test/java/com/recodeit/server/application-test.yml rename to src/test/resources/application-test.yml index f959f6d4..210ca9a2 100644 --- a/src/test/java/com/recodeit/server/application-test.yml +++ b/src/test/resources/application-test.yml @@ -2,13 +2,18 @@ spring: config: activate: on-profile: "test" + datasource: driver-class-name: org.h2.Driver url: jdbc:h2:~/RecordIt username: sa password: + h2: + console: + enabled: true + redis: host: localhost - port: 49151 + port: 63790 session: store-type: redis \ No newline at end of file From 1c4200775d7ff8069ef6cce0c47dc9b3f649ff33 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 9 Dec 2022 18:39:36 +0900 Subject: [PATCH 020/264] =?UTF-8?q?[BE-15]=20chore:=20application-dev.yml,?= =?UTF-8?q?=20application-local.yml=20=EC=8A=A4=ED=83=80=EC=9D=BC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 11 +++-------- src/main/resources/application-local.yml | 7 +------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index cd23c70d..49d7e5de 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,13 +1,8 @@ -server: - port: 8080 - servlet: - context-path: / - encoding: - charset: utf-8 spring: config: activate: on-profile: "dev" + jpa: open-in-view: true hibernate: @@ -23,5 +18,5 @@ spring: enabled: always logging: level: - '[org.springframework.web]': INFO - '[org.hibernate]': INFO + '[org.springframework.web]': DEBUG + '[org.hibernate]': DEBUG diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 26f3314c..027d88ec 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -1,13 +1,8 @@ -server: - port: 8080 - servlet: - context-path: / - encoding: - charset: utf-8 spring: config: activate: on-profile: "local" + jpa: open-in-view: true hibernate: From 721cfd7b5f5292234266652c2271bbc31f2dc71c Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 10 Dec 2022 00:22:41 +0900 Subject: [PATCH 021/264] =?UTF-8?q?[BE-21]=20feat:=20RedisConfiguration?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20Redis=20=EC=84=A4=EC=A0=95=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/RedisConfiguration.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main/java/com/recodeit/server/configuration/RedisConfiguration.java diff --git a/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java b/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java new file mode 100644 index 00000000..7ad25a87 --- /dev/null +++ b/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java @@ -0,0 +1,38 @@ +package com.recodeit.server.configuration; + +import java.util.Objects; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Configuration +public class RedisConfiguration { + + private final String host; + private final int port; + + public RedisConfiguration( + @Value("${spring.redis.host}") String host, + @Value("${spring.redis.port}") int port + ) { + this.host = Objects.requireNonNull(host); + this.port = Objects.requireNonNull(port); + } + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(host, port); + } + + @Bean + public StringRedisTemplate stringRedisTemplate() { + StringRedisTemplate stringRedisTemplate = new StringRedisTemplate(); + stringRedisTemplate.setDefaultSerializer(new StringRedisSerializer()); + stringRedisTemplate.setConnectionFactory(redisConnectionFactory()); + return stringRedisTemplate; + } +} From 5a01576b7799278c05fee2d54315543c519009cb Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Tue, 20 Dec 2022 19:36:25 +0900 Subject: [PATCH 022/264] =?UTF-8?q?[BE-15]=20style:=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/RedisConfiguration.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java b/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java index 7ad25a87..c88a4812 100644 --- a/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java +++ b/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java @@ -1,6 +1,7 @@ package com.recodeit.server.configuration; import java.util.Objects; + import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -12,27 +13,27 @@ @Configuration public class RedisConfiguration { - private final String host; - private final int port; + private final String host; + private final int port; - public RedisConfiguration( - @Value("${spring.redis.host}") String host, - @Value("${spring.redis.port}") int port - ) { - this.host = Objects.requireNonNull(host); - this.port = Objects.requireNonNull(port); - } + public RedisConfiguration( + @Value("${spring.redis.host}") String host, + @Value("${spring.redis.port}") int port + ) { + this.host = Objects.requireNonNull(host); + this.port = Objects.requireNonNull(port); + } - @Bean - public RedisConnectionFactory redisConnectionFactory() { - return new LettuceConnectionFactory(host, port); - } + @Bean + public RedisConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(host, port); + } - @Bean - public StringRedisTemplate stringRedisTemplate() { - StringRedisTemplate stringRedisTemplate = new StringRedisTemplate(); - stringRedisTemplate.setDefaultSerializer(new StringRedisSerializer()); - stringRedisTemplate.setConnectionFactory(redisConnectionFactory()); - return stringRedisTemplate; - } + @Bean + public StringRedisTemplate stringRedisTemplate() { + StringRedisTemplate stringRedisTemplate = new StringRedisTemplate(); + stringRedisTemplate.setDefaultSerializer(new StringRedisSerializer()); + stringRedisTemplate.setConnectionFactory(redisConnectionFactory()); + return stringRedisTemplate; + } } From b28d82ff84a3370815ecc7f0d818c0e3d8b2cf5a Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Tue, 20 Dec 2022 22:56:45 +0900 Subject: [PATCH 023/264] =?UTF-8?q?[BE-21]=20refactor:=20StringRedisTempla?= =?UTF-8?q?te=20=EB=B9=88=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20Redis=20?= =?UTF-8?q?=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/RedisConfiguration.java | 27 +++++++++---------- src/main/resources/application-redis.yml | 1 + 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java b/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java index c88a4812..55f99a96 100644 --- a/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java +++ b/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java @@ -1,39 +1,36 @@ package com.recodeit.server.configuration; -import java.util.Objects; - import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.data.redis.serializer.StringRedisSerializer; @Configuration public class RedisConfiguration { private final String host; private final int port; + private final String password; public RedisConfiguration( @Value("${spring.redis.host}") String host, - @Value("${spring.redis.port}") int port + @Value("${spring.redis.port}") int port, + @Value("${spring.redis.password}") String password ) { - this.host = Objects.requireNonNull(host); - this.port = Objects.requireNonNull(port); + this.host = host; + this.port = port; + this.password = password; } @Bean public RedisConnectionFactory redisConnectionFactory() { - return new LettuceConnectionFactory(host, port); + RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(); + configuration.setHostName(host); + configuration.setPort(port); + configuration.setPassword(password); + return new LettuceConnectionFactory(configuration); } - @Bean - public StringRedisTemplate stringRedisTemplate() { - StringRedisTemplate stringRedisTemplate = new StringRedisTemplate(); - stringRedisTemplate.setDefaultSerializer(new StringRedisSerializer()); - stringRedisTemplate.setConnectionFactory(redisConnectionFactory()); - return stringRedisTemplate; - } } diff --git a/src/main/resources/application-redis.yml b/src/main/resources/application-redis.yml index 66c3bebb..a7673504 100644 --- a/src/main/resources/application-redis.yml +++ b/src/main/resources/application-redis.yml @@ -5,6 +5,7 @@ spring: redis: host: ${REDIS_HOST:localhost} port: ${REDIS_PORT:6379} + password: ${REDIS_PASSWORD:} session: store-type: redis From 4db1ba702a7a50d3156716a2d7eb5303c39024e3 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Tue, 20 Dec 2022 23:33:19 +0900 Subject: [PATCH 024/264] =?UTF-8?q?[BE-21]=20feat:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20TEMP=5FUUID=20=EC=A0=80=EC=9E=A5=EC=9A=A9?= =?UTF-8?q?=20RedisTemplate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/configuration/RedisConfiguration.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java b/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java index 55f99a96..bb2f3e4b 100644 --- a/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java +++ b/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java @@ -6,6 +6,9 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; @Configuration public class RedisConfiguration { @@ -33,4 +36,13 @@ public RedisConnectionFactory redisConnectionFactory() { return new LettuceConnectionFactory(configuration); } + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); + redisTemplate.setConnectionFactory(redisConnectionFactory); + return redisTemplate; + } + } From 187d0b39006a199b7daa00585c1c074befd6929d Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 13:21:23 +0900 Subject: [PATCH 025/264] =?UTF-8?q?[BE-51]=20chore:=20datasource=20yml=20p?= =?UTF-8?q?ort=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?,=20serverTimezone=20Asia/Seoul=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-datasource.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-datasource.yml b/src/main/resources/application-datasource.yml index 6f1fd8e4..2d8f2b98 100644 --- a/src/main/resources/application-datasource.yml +++ b/src/main/resources/application-datasource.yml @@ -4,7 +4,7 @@ spring: on-profile: "datasource" datasource: driver-class-name: org.mariadb.jdbc.Driver - url: jdbc:mariadb://${DATASOURCE_HOST:localhost}:3306/RecordIt?characterEncoding=UTF-8&serverTimezone=UTC + url: jdbc:mariadb://${DATASOURCE_HOST:localhost}:${DATASOURCE_PORT:3306}/RecordIt?characterEncoding=UTF-8&serverTimezone=Asia/Seoul username: ${DATASOURCE_USERNAME:root} password: ${DATASOURCE_PASSWORD:} From d0630a927a35ce03f854874c87b1e6411ef0bc4f Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 13:40:57 +0900 Subject: [PATCH 026/264] =?UTF-8?q?[BE-46]=20rename:=20pull=5Freuqest=5Fte?= =?UTF-8?q?mplate=20=ED=8F=B4=EB=8D=94=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pull_request_template.md => .github/pull_request_template.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pull_request_template.md => .github/pull_request_template.md (100%) diff --git a/pull_request_template.md b/.github/pull_request_template.md similarity index 100% rename from pull_request_template.md rename to .github/pull_request_template.md From f7f8d444b9bce9d516e36b8eaa2f43d55478b490 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 13:42:25 +0900 Subject: [PATCH 027/264] =?UTF-8?q?[BE-46]=20chore:=20pr=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=20=EB=A6=AC=EB=B7=B0=EC=96=B4=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..ce5b24a9 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @Jaeyeop-Jung @Pull-Stack @kdomo \ No newline at end of file From 093ed17980631070b6c1e130bbff4586b39e07b7 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 14:19:56 +0900 Subject: [PATCH 028/264] =?UTF-8?q?[BE-52]=20chore:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../server/RecodeItServerApplication.java | 2 +- .../server/RecodeItServerApplicationTests.java | 3 +-- .../server/configuration/EmbeddedRedisConfiguration.java | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) rename src/main/java/com/{recodeit => recordit}/server/RecodeItServerApplication.java (91%) rename src/test/java/com/{recodeit => recordit}/server/RecodeItServerApplicationTests.java (76%) rename src/test/java/com/{recodeit => recordit}/server/configuration/EmbeddedRedisConfiguration.java (94%) diff --git a/build.gradle b/build.gradle index 84c9b12b..8e835d6e 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { id 'io.spring.dependency-management' version '1.0.15.RELEASE' } -group = 'com.recodeit' +group = 'com.recordit' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' diff --git a/src/main/java/com/recodeit/server/RecodeItServerApplication.java b/src/main/java/com/recordit/server/RecodeItServerApplication.java similarity index 91% rename from src/main/java/com/recodeit/server/RecodeItServerApplication.java rename to src/main/java/com/recordit/server/RecodeItServerApplication.java index 2d4cbae3..8cdb043f 100644 --- a/src/main/java/com/recodeit/server/RecodeItServerApplication.java +++ b/src/main/java/com/recordit/server/RecodeItServerApplication.java @@ -1,4 +1,4 @@ -package com.recodeit.server; +package com.recordit.server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java b/src/test/java/com/recordit/server/RecodeItServerApplicationTests.java similarity index 76% rename from src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java rename to src/test/java/com/recordit/server/RecodeItServerApplicationTests.java index 38ddb31f..3eaaa9a3 100644 --- a/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java +++ b/src/test/java/com/recordit/server/RecodeItServerApplicationTests.java @@ -1,8 +1,7 @@ -package com.recodeit.server; +package com.recordit.server; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Profile; import org.springframework.test.context.ActiveProfiles; @SpringBootTest diff --git a/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java b/src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java similarity index 94% rename from src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java rename to src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java index 025d8d6b..5c1ed65e 100644 --- a/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java +++ b/src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java @@ -1,4 +1,4 @@ -package com.recodeit.server.configuration; +package com.recordit.server.configuration; import javax.annotation.PreDestroy; import org.springframework.beans.factory.annotation.Value; From 0e4b884a969230194cf46b32737a43776aa677b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AA=A8?= Date: Wed, 21 Dec 2022 14:33:39 +0900 Subject: [PATCH 029/264] =?UTF-8?q?Revert=20"[BE-52]=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=EB=AA=85=20=EC=88=98=EC=A0=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../server/RecodeItServerApplication.java | 2 +- .../server/RecodeItServerApplicationTests.java | 3 ++- .../server/configuration/EmbeddedRedisConfiguration.java | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) rename src/main/java/com/{recordit => recodeit}/server/RecodeItServerApplication.java (91%) rename src/test/java/com/{recordit => recodeit}/server/RecodeItServerApplicationTests.java (76%) rename src/test/java/com/{recordit => recodeit}/server/configuration/EmbeddedRedisConfiguration.java (94%) diff --git a/build.gradle b/build.gradle index 8e835d6e..84c9b12b 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { id 'io.spring.dependency-management' version '1.0.15.RELEASE' } -group = 'com.recordit' +group = 'com.recodeit' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' diff --git a/src/main/java/com/recordit/server/RecodeItServerApplication.java b/src/main/java/com/recodeit/server/RecodeItServerApplication.java similarity index 91% rename from src/main/java/com/recordit/server/RecodeItServerApplication.java rename to src/main/java/com/recodeit/server/RecodeItServerApplication.java index 8cdb043f..2d4cbae3 100644 --- a/src/main/java/com/recordit/server/RecodeItServerApplication.java +++ b/src/main/java/com/recodeit/server/RecodeItServerApplication.java @@ -1,4 +1,4 @@ -package com.recordit.server; +package com.recodeit.server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/test/java/com/recordit/server/RecodeItServerApplicationTests.java b/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java similarity index 76% rename from src/test/java/com/recordit/server/RecodeItServerApplicationTests.java rename to src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java index 3eaaa9a3..38ddb31f 100644 --- a/src/test/java/com/recordit/server/RecodeItServerApplicationTests.java +++ b/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java @@ -1,7 +1,8 @@ -package com.recordit.server; +package com.recodeit.server; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Profile; import org.springframework.test.context.ActiveProfiles; @SpringBootTest diff --git a/src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java b/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java similarity index 94% rename from src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java rename to src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java index 5c1ed65e..025d8d6b 100644 --- a/src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java +++ b/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java @@ -1,4 +1,4 @@ -package com.recordit.server.configuration; +package com.recodeit.server.configuration; import javax.annotation.PreDestroy; import org.springframework.beans.factory.annotation.Value; From b1ca5b2d0efb317ad380676f811ef13207de07ef Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 15:06:38 +0900 Subject: [PATCH 030/264] =?UTF-8?q?[BE-48]=20feat:=20Swagger3.0.0=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 ++ .../configuration/SwaggerConfiguration.java | 30 +++++++++++++++++++ src/main/resources/application-dev.yml | 4 ++- src/main/resources/application-local.yml | 4 ++- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/recodeit/server/configuration/SwaggerConfiguration.java diff --git a/build.gradle b/build.gradle index 84c9b12b..1518e6e7 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.session:spring-session-data-redis' + implementation 'io.springfox:springfox-boot-starter:3.0.0' + implementation 'io.springfox:springfox-swagger-ui:3.0.0' // embedded redis implementation('it.ozimov:embedded-redis:0.7.3') { diff --git a/src/main/java/com/recodeit/server/configuration/SwaggerConfiguration.java b/src/main/java/com/recodeit/server/configuration/SwaggerConfiguration.java new file mode 100644 index 00000000..d55ba52d --- /dev/null +++ b/src/main/java/com/recodeit/server/configuration/SwaggerConfiguration.java @@ -0,0 +1,30 @@ +package com.recodeit.server.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +@Configuration +public class SwaggerConfiguration { + @Bean + public Docket api() { + return new Docket(DocumentationType.OAS_30) + .select() + .apis(RequestHandlerSelectors.basePackage("com.recodeit")) + .paths(PathSelectors.any()) + .build().apiInfo(apiInfo()); + } + + private ApiInfo apiInfo(){ + return new ApiInfoBuilder() + .title("RecordIt Backend - DEV") + .description("RecordIt Backend - DEV 서버 API 명세") + .version("1.0") + .build(); + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 49d7e5de..3d1367b6 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -2,7 +2,9 @@ spring: config: activate: on-profile: "dev" - + mvc: + pathmatch: + matching-strategy: ant_path_matcher jpa: open-in-view: true hibernate: diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 027d88ec..d9fb295a 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -2,7 +2,9 @@ spring: config: activate: on-profile: "local" - + mvc: + pathmatch: + matching-strategy: ant_path_matcher jpa: open-in-view: true hibernate: From 2e5392f022df1f61374a26a8b33003c4abab3548 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 16:49:02 +0900 Subject: [PATCH 031/264] =?UTF-8?q?[BE-53]=20style:=20NAVER=20Code=20Conve?= =?UTF-8?q?ntions=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- naver-intellij-formatter.xml | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 naver-intellij-formatter.xml diff --git a/naver-intellij-formatter.xml b/naver-intellij-formatter.xml new file mode 100644 index 00000000..a4f6cc7d --- /dev/null +++ b/naver-intellij-formatter.xml @@ -0,0 +1,62 @@ + + + \ No newline at end of file From b1b8aab2396edc6069b082edb4b83239d950f580 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 16:59:52 +0900 Subject: [PATCH 032/264] =?UTF-8?q?[BE-53]=20style:=20NAVER=20Checkstyle?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- naver-checkstyle-rules.xml | 439 ++++++++++++++++++++++++++++++ naver-checkstyle-suppressions.xml | 7 + 2 files changed, 446 insertions(+) create mode 100644 naver-checkstyle-rules.xml create mode 100644 naver-checkstyle-suppressions.xml diff --git a/naver-checkstyle-rules.xml b/naver-checkstyle-rules.xml new file mode 100644 index 00000000..5eefb788 --- /dev/null +++ b/naver-checkstyle-rules.xml @@ -0,0 +1,439 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/naver-checkstyle-suppressions.xml b/naver-checkstyle-suppressions.xml new file mode 100644 index 00000000..efd97d80 --- /dev/null +++ b/naver-checkstyle-suppressions.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file From 60752c5cf40c72a31d49fb61a4c43a9fbb7fef73 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 19:08:05 +0900 Subject: [PATCH 033/264] =?UTF-8?q?[BE-20]=20feat:=20=EC=84=B8=EC=85=98=20?= =?UTF-8?q?=EC=9C=A0=ED=8B=B8=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 세션을 저장할 때 정상적으로 저장되는지 테스트 추가 2. 세션에서 값을 불러올 때 happy/unhappy 테스트 추가 3. 세션 삭제 기능 테스트 추가 --- .../NotFoundUserInfoInSessionException.java | 4 + .../com/recodeit/server/util/SessionUtil.java | 33 ++++++++ .../recodeit/server/util/SessionUtilTest.java | 80 +++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java create mode 100644 src/main/java/com/recodeit/server/util/SessionUtil.java create mode 100644 src/test/java/com/recodeit/server/util/SessionUtilTest.java diff --git a/src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java b/src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java new file mode 100644 index 00000000..ac852556 --- /dev/null +++ b/src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java @@ -0,0 +1,4 @@ +package com.recodeit.server.exception; + +public class NotFoundUserInfoInSessionException extends RuntimeException { +} diff --git a/src/main/java/com/recodeit/server/util/SessionUtil.java b/src/main/java/com/recodeit/server/util/SessionUtil.java new file mode 100644 index 00000000..60bc87a2 --- /dev/null +++ b/src/main/java/com/recodeit/server/util/SessionUtil.java @@ -0,0 +1,33 @@ +package com.recodeit.server.util; + +import javax.servlet.http.HttpSession; + +import org.springframework.stereotype.Component; + +import com.recodeit.server.exception.NotFoundUserInfoInSessionException; + +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class SessionUtil { + + private static final String PREFIX_USER_ID = "LOGIN_USER_ID"; + private final HttpSession httpSession; + + public void saveUserIdInSession(Long id) { + httpSession.setAttribute(PREFIX_USER_ID, id); + } + + public Long findUserIdBySession() { + Long userId = (Long)httpSession.getAttribute(PREFIX_USER_ID); + if (userId == null) { + throw new NotFoundUserInfoInSessionException(); + } + return userId; + } + + public void removeSession() { + httpSession.invalidate(); + } +} \ No newline at end of file diff --git a/src/test/java/com/recodeit/server/util/SessionUtilTest.java b/src/test/java/com/recodeit/server/util/SessionUtilTest.java new file mode 100644 index 00000000..fa4b03f4 --- /dev/null +++ b/src/test/java/com/recodeit/server/util/SessionUtilTest.java @@ -0,0 +1,80 @@ +package com.recodeit.server.util; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.mock.web.MockHttpSession; + +import com.recodeit.server.exception.NotFoundUserInfoInSessionException; + +@ExtendWith(MockitoExtension.class) +public class SessionUtilTest { + + @InjectMocks + private SessionUtil sessionUtil; + + @Spy + MockHttpSession mockHttpSession; + + @Test + @DisplayName("세션에 userId를 저장하는 기능을 테스트한다") + void 세션에_UserId를_저장하는_기능을_테스트한다() { + // given + + // when + sessionUtil.saveUserIdInSession(1L); + + // then + assertThat(mockHttpSession.getAttribute("LOGIN_USER_ID")).isEqualTo((Long)1L); + } + + @Nested + @DisplayName("세션에서 userId를 찾을 때") + class 세션에서_userId를_찾을_때 { + + @Test + @DisplayName("세션에 userId가 있으면 값이 찾아와진다") + void 세션에_정상적으로_userId를_저장하고_있으면_정상적으로_값이_찾아와진다() { + // given + long userId = 1L; + mockHttpSession.setAttribute("LOGIN_USER_ID", userId); + + // when + Long userIdBySession = sessionUtil.findUserIdBySession(); + + // then + assertThat(userIdBySession.longValue()).isEqualTo(userId); + assertThatCode(() -> sessionUtil.findUserIdBySession()).doesNotThrowAnyException(); + } + + @Test + @DisplayName("세션에 userId가 없으면 예외를 던진다") + void 세션에_userId가_없으면_예외를_던진다() { + // given + + // when, then + assertThatThrownBy(() -> sessionUtil.findUserIdBySession()) + .isInstanceOf(NotFoundUserInfoInSessionException.class); + + } + } + + @Test + @DisplayName("세션을 삭제하는 기능을 테스트한다") + void 세션을_삭제하는_기능을_테스트한다() { + // given + + // when + sessionUtil.removeSession(); + + // then + assertThat(mockHttpSession.isInvalid()).isTrue(); + } + +} \ No newline at end of file From 2fb638c78d57b8497ee59752f3ad7eac72da89f6 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 19:48:22 +0900 Subject: [PATCH 034/264] =?UTF-8?q?[BE-20]=20refactor:=20=EC=84=B8?= =?UTF-8?q?=EC=85=98=EC=97=90=EC=84=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EA=B0=80=20=EC=97=86=EC=9D=84=20=EB=95=8C=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=97=90=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/exception/NotFoundUserInfoInSessionException.java | 3 +++ src/main/java/com/recodeit/server/util/SessionUtil.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java b/src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java index ac852556..3df9b13d 100644 --- a/src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java +++ b/src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java @@ -1,4 +1,7 @@ package com.recodeit.server.exception; public class NotFoundUserInfoInSessionException extends RuntimeException { + public NotFoundUserInfoInSessionException(String message) { + super(message); + } } diff --git a/src/main/java/com/recodeit/server/util/SessionUtil.java b/src/main/java/com/recodeit/server/util/SessionUtil.java index 60bc87a2..c94f6d11 100644 --- a/src/main/java/com/recodeit/server/util/SessionUtil.java +++ b/src/main/java/com/recodeit/server/util/SessionUtil.java @@ -22,7 +22,7 @@ public void saveUserIdInSession(Long id) { public Long findUserIdBySession() { Long userId = (Long)httpSession.getAttribute(PREFIX_USER_ID); if (userId == null) { - throw new NotFoundUserInfoInSessionException(); + throw new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다"); } return userId; } From ab17311b90e8d1b4e4619a3f4f2a72154fc6599f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 19:52:21 +0900 Subject: [PATCH 035/264] =?UTF-8?q?[BE-20]=20refactor:=20=EC=84=B8?= =?UTF-8?q?=EC=85=98=20=EC=82=AD=EC=A0=9C=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recodeit/server/util/SessionUtil.java | 2 +- src/test/java/com/recodeit/server/util/SessionUtilTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recodeit/server/util/SessionUtil.java b/src/main/java/com/recodeit/server/util/SessionUtil.java index c94f6d11..48bffded 100644 --- a/src/main/java/com/recodeit/server/util/SessionUtil.java +++ b/src/main/java/com/recodeit/server/util/SessionUtil.java @@ -27,7 +27,7 @@ public Long findUserIdBySession() { return userId; } - public void removeSession() { + public void invalidateSession() { httpSession.invalidate(); } } \ No newline at end of file diff --git a/src/test/java/com/recodeit/server/util/SessionUtilTest.java b/src/test/java/com/recodeit/server/util/SessionUtilTest.java index fa4b03f4..697d6866 100644 --- a/src/test/java/com/recodeit/server/util/SessionUtilTest.java +++ b/src/test/java/com/recodeit/server/util/SessionUtilTest.java @@ -71,7 +71,7 @@ class 세션에서_userId를_찾을_때 { // given // when - sessionUtil.removeSession(); + sessionUtil.invalidateSession(); // then assertThat(mockHttpSession.isInvalid()).isTrue(); From 380f7078fe359c6412d43badc61593d12b5da3ea Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 20:24:04 +0900 Subject: [PATCH 036/264] =?UTF-8?q?[BE-8]=20refactor:=20@Notnull=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recodeit/server/domain/BaseEntity.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/recodeit/server/domain/BaseEntity.java b/src/main/java/com/recodeit/server/domain/BaseEntity.java index 188b1f84..8cd7d2a9 100644 --- a/src/main/java/com/recodeit/server/domain/BaseEntity.java +++ b/src/main/java/com/recodeit/server/domain/BaseEntity.java @@ -1,27 +1,29 @@ package com.recodeit.server.domain; -import com.sun.istack.NotNull; import java.time.LocalDateTime; + import javax.persistence.EntityListeners; import javax.persistence.MappedSuperclass; -import lombok.Getter; +import javax.validation.constraints.NotNull; + import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import lombok.Getter; + @Getter @MappedSuperclass @EntityListeners(AuditingEntityListener.class) public abstract class BaseEntity { - @NotNull - @CreatedDate - private LocalDateTime createdAt; + @NotNull + @CreatedDate + private LocalDateTime createdAt; - @NotNull - @LastModifiedDate - private LocalDateTime modifiedAt; + @NotNull + @LastModifiedDate + private LocalDateTime modifiedAt; - @NotNull - private LocalDateTime deletedAt; + private LocalDateTime deletedAt; } From 003d9f95220c57c96d5a09c94726822561c2e37b Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 21:04:00 +0900 Subject: [PATCH 037/264] =?UTF-8?q?[BE-54]=20style:=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=EC=A0=9D=ED=8A=B8=EB=AA=85=20recodeit=EC=9D=84=20recordit?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- settings.gradle | 2 +- .../server/RecodeItServerApplication.java | 13 ------ .../configuration/SwaggerConfiguration.java | 30 ------------- .../recodeit/server/constant/LoginType.java | 16 ------- .../server/controller/MemberController.java | 25 ----------- .../com/recodeit/server/domain/Member.java | 41 ----------------- .../server/service/MemberService.java | 23 ---------- .../service/oauth/GoogleOauthService.java | 15 ------- .../service/oauth/KakaoOauthService.java | 15 ------- .../server/service/oauth/OauthService.java | 10 ----- .../server/RecordItServerApplication.java | 13 ++++++ .../configuration/RedisConfiguration.java | 8 ++-- .../configuration/SwaggerConfiguration.java | 31 +++++++++++++ .../recordit/server/constant/LoginType.java | 16 +++++++ .../server/controller/MemberController.java | 27 +++++++++++ .../server/domain/BaseEntity.java | 2 +- .../com/recordit/server/domain/Member.java | 45 +++++++++++++++++++ .../NotFoundUserInfoInSessionException.java | 2 +- .../server/service/MemberService.java | 26 +++++++++++ .../service/oauth/GoogleOauthService.java | 15 +++++++ .../service/oauth/KakaoOauthService.java | 15 +++++++ .../server/service/oauth/OauthService.java | 10 +++++ .../server/util/SessionUtil.java | 4 +- .../EmbeddedRedisConfiguration.java | 26 ----------- .../RecordItServerApplicationTests.java} | 11 +++-- .../EmbeddedRedisConfiguration.java | 28 ++++++++++++ .../server/util/SessionUtilTest.java | 4 +- 27 files changed, 242 insertions(+), 231 deletions(-) delete mode 100644 src/main/java/com/recodeit/server/RecodeItServerApplication.java delete mode 100644 src/main/java/com/recodeit/server/configuration/SwaggerConfiguration.java delete mode 100644 src/main/java/com/recodeit/server/constant/LoginType.java delete mode 100644 src/main/java/com/recodeit/server/controller/MemberController.java delete mode 100644 src/main/java/com/recodeit/server/domain/Member.java delete mode 100644 src/main/java/com/recodeit/server/service/MemberService.java delete mode 100644 src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java delete mode 100644 src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java delete mode 100644 src/main/java/com/recodeit/server/service/oauth/OauthService.java create mode 100644 src/main/java/com/recordit/server/RecordItServerApplication.java rename src/main/java/com/{recodeit => recordit}/server/configuration/RedisConfiguration.java (89%) create mode 100644 src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java create mode 100644 src/main/java/com/recordit/server/constant/LoginType.java create mode 100644 src/main/java/com/recordit/server/controller/MemberController.java rename src/main/java/com/{recodeit => recordit}/server/domain/BaseEntity.java (94%) create mode 100644 src/main/java/com/recordit/server/domain/Member.java rename src/main/java/com/{recodeit => recordit}/server/exception/NotFoundUserInfoInSessionException.java (80%) create mode 100644 src/main/java/com/recordit/server/service/MemberService.java create mode 100644 src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java create mode 100644 src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java create mode 100644 src/main/java/com/recordit/server/service/oauth/OauthService.java rename src/main/java/com/{recodeit => recordit}/server/util/SessionUtil.java (88%) delete mode 100644 src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java rename src/test/java/com/{recodeit/server/RecodeItServerApplicationTests.java => recordit/server/RecordItServerApplicationTests.java} (54%) create mode 100644 src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java rename src/test/java/com/{recodeit => recordit}/server/util/SessionUtilTest.java (95%) diff --git a/settings.gradle b/settings.gradle index 86a18c1d..e6d960dd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'recodeIt-server' +rootProject.name = 'recordIt-server' diff --git a/src/main/java/com/recodeit/server/RecodeItServerApplication.java b/src/main/java/com/recodeit/server/RecodeItServerApplication.java deleted file mode 100644 index 2d4cbae3..00000000 --- a/src/main/java/com/recodeit/server/RecodeItServerApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.recodeit.server; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class RecodeItServerApplication { - - public static void main(String[] args) { - SpringApplication.run(RecodeItServerApplication.class, args); - } - -} diff --git a/src/main/java/com/recodeit/server/configuration/SwaggerConfiguration.java b/src/main/java/com/recodeit/server/configuration/SwaggerConfiguration.java deleted file mode 100644 index d55ba52d..00000000 --- a/src/main/java/com/recodeit/server/configuration/SwaggerConfiguration.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.recodeit.server.configuration; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; - -@Configuration -public class SwaggerConfiguration { - @Bean - public Docket api() { - return new Docket(DocumentationType.OAS_30) - .select() - .apis(RequestHandlerSelectors.basePackage("com.recodeit")) - .paths(PathSelectors.any()) - .build().apiInfo(apiInfo()); - } - - private ApiInfo apiInfo(){ - return new ApiInfoBuilder() - .title("RecordIt Backend - DEV") - .description("RecordIt Backend - DEV 서버 API 명세") - .version("1.0") - .build(); - } -} diff --git a/src/main/java/com/recodeit/server/constant/LoginType.java b/src/main/java/com/recodeit/server/constant/LoginType.java deleted file mode 100644 index 35c8fe93..00000000 --- a/src/main/java/com/recodeit/server/constant/LoginType.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.recodeit.server.constant; - -import java.util.Arrays; - -public enum LoginType { - LOCAL, - KAKAO, - GOOGLE; - - public static LoginType findByString(String str) { - return Arrays.stream(LoginType.values()) - .filter(loginType -> loginType.name().equals(str)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException("")); - } -} diff --git a/src/main/java/com/recodeit/server/controller/MemberController.java b/src/main/java/com/recodeit/server/controller/MemberController.java deleted file mode 100644 index ace44817..00000000 --- a/src/main/java/com/recodeit/server/controller/MemberController.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.recodeit.server.controller; - -import com.recodeit.server.service.MemberService; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequiredArgsConstructor -public class MemberController { - - private final MemberService memberService; - - @GetMapping("/member/oauth/{logintype}") - public void oauthLogin(@PathVariable("logintype") String loginType) { - memberService.oauthLogin(loginType); - } - - @PostMapping("/member/oauth/{loginType}") - public void oauthRegister(@PathVariable("logintype") String loginType) { - memberService.oauthRegister(loginType); - } -} diff --git a/src/main/java/com/recodeit/server/domain/Member.java b/src/main/java/com/recodeit/server/domain/Member.java deleted file mode 100644 index ffbd5744..00000000 --- a/src/main/java/com/recodeit/server/domain/Member.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.recodeit.server.domain; - -import com.recodeit.server.constant.LoginType; -import java.util.UUID; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.SQLDelete; -import org.hibernate.annotations.Where; - -@Entity -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter -@Where(clause = "deleted_at is null") -@SQLDelete(sql = "UPDATE member SET deleted_at = CURRENT_TIMESTAMP WHERE id = ?") -public class Member extends BaseEntity { - - @Id - @GeneratedValue(generator = "uuid2") - @Column(name = "MEMBER_ID", columnDefinition = "BINARY(16)") - private UUID id; - private String password; - private String nickname; - private String oauthId; - private LoginType loginType; - - private Member(String password, String nickname, String oauthId, LoginType loginType) { - this.password = password; - this.nickname = nickname; - this.oauthId = oauthId; - this.loginType = loginType; - } - - public static Member of(String password, String nickname, String oauthId, LoginType loginType) { - return new Member(password, nickname, oauthId, loginType); - } -} diff --git a/src/main/java/com/recodeit/server/service/MemberService.java b/src/main/java/com/recodeit/server/service/MemberService.java deleted file mode 100644 index a08cc145..00000000 --- a/src/main/java/com/recodeit/server/service/MemberService.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.recodeit.server.service; - -import com.recodeit.server.service.oauth.OauthService; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -public class MemberService { - private final List oauthServices; - - @Transactional - public void oauthLogin(String loginType) { - - } - - @Transactional - public void oauthRegister(String loginType) { - - } -} diff --git a/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java deleted file mode 100644 index 458c9dbe..00000000 --- a/src/main/java/com/recodeit/server/service/oauth/GoogleOauthService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.recodeit.server.service.oauth; - -import com.recodeit.server.constant.LoginType; - -public class GoogleOauthService implements OauthService { - @Override - public LoginType getLoginType() { - return LoginType.GOOGLE; - } - - @Override - public void request() { - - } -} diff --git a/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java deleted file mode 100644 index 3cd999ca..00000000 --- a/src/main/java/com/recodeit/server/service/oauth/KakaoOauthService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.recodeit.server.service.oauth; - -import com.recodeit.server.constant.LoginType; - -public class KakaoOauthService implements OauthService { - @Override - public LoginType getLoginType() { - return LoginType.KAKAO; - } - - @Override - public void request() { - - } -} diff --git a/src/main/java/com/recodeit/server/service/oauth/OauthService.java b/src/main/java/com/recodeit/server/service/oauth/OauthService.java deleted file mode 100644 index 94917f15..00000000 --- a/src/main/java/com/recodeit/server/service/oauth/OauthService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.recodeit.server.service.oauth; - -import com.recodeit.server.constant.LoginType; - -public interface OauthService { - - LoginType getLoginType(); - - void request(); -} diff --git a/src/main/java/com/recordit/server/RecordItServerApplication.java b/src/main/java/com/recordit/server/RecordItServerApplication.java new file mode 100644 index 00000000..63f8d8d6 --- /dev/null +++ b/src/main/java/com/recordit/server/RecordItServerApplication.java @@ -0,0 +1,13 @@ +package com.recordit.server; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RecordItServerApplication { + + public static void main(String[] args) { + SpringApplication.run(RecordItServerApplication.class, args); + } + +} diff --git a/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java b/src/main/java/com/recordit/server/configuration/RedisConfiguration.java similarity index 89% rename from src/main/java/com/recodeit/server/configuration/RedisConfiguration.java rename to src/main/java/com/recordit/server/configuration/RedisConfiguration.java index bb2f3e4b..b1e9997d 100644 --- a/src/main/java/com/recodeit/server/configuration/RedisConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/RedisConfiguration.java @@ -1,4 +1,4 @@ -package com.recodeit.server.configuration; +package com.recordit.server.configuration; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -18,9 +18,9 @@ public class RedisConfiguration { private final String password; public RedisConfiguration( - @Value("${spring.redis.host}") String host, - @Value("${spring.redis.port}") int port, - @Value("${spring.redis.password}") String password + @Value("${spring.redis.host}") String host, + @Value("${spring.redis.port}") int port, + @Value("${spring.redis.password}") String password ) { this.host = host; this.port = port; diff --git a/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java b/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java new file mode 100644 index 00000000..9ec335f4 --- /dev/null +++ b/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java @@ -0,0 +1,31 @@ +package com.recordit.server.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +@Configuration +public class SwaggerConfiguration { + @Bean + public Docket api() { + return new Docket(DocumentationType.OAS_30) + .select() + .apis(RequestHandlerSelectors.basePackage("com.recodeit")) + .paths(PathSelectors.any()) + .build().apiInfo(apiInfo()); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("RecordIt Backend - DEV") + .description("RecordIt Backend - DEV 서버 API 명세") + .version("1.0") + .build(); + } +} diff --git a/src/main/java/com/recordit/server/constant/LoginType.java b/src/main/java/com/recordit/server/constant/LoginType.java new file mode 100644 index 00000000..5e4f71c4 --- /dev/null +++ b/src/main/java/com/recordit/server/constant/LoginType.java @@ -0,0 +1,16 @@ +package com.recordit.server.constant; + +import java.util.Arrays; + +public enum LoginType { + LOCAL, + KAKAO, + GOOGLE; + + public static LoginType findByString(String str) { + return Arrays.stream(LoginType.values()) + .filter(loginType -> loginType.name().equals(str)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("")); + } +} diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java new file mode 100644 index 00000000..2e1232ba --- /dev/null +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -0,0 +1,27 @@ +package com.recordit.server.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.recordit.server.service.MemberService; + +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +public class MemberController { + + private final MemberService memberService; + + @GetMapping("/member/oauth/{logintype}") + public void oauthLogin(@PathVariable("logintype") String loginType) { + memberService.oauthLogin(loginType); + } + + @PostMapping("/member/oauth/{loginType}") + public void oauthRegister(@PathVariable("logintype") String loginType) { + memberService.oauthRegister(loginType); + } +} diff --git a/src/main/java/com/recodeit/server/domain/BaseEntity.java b/src/main/java/com/recordit/server/domain/BaseEntity.java similarity index 94% rename from src/main/java/com/recodeit/server/domain/BaseEntity.java rename to src/main/java/com/recordit/server/domain/BaseEntity.java index 8cd7d2a9..81925e87 100644 --- a/src/main/java/com/recodeit/server/domain/BaseEntity.java +++ b/src/main/java/com/recordit/server/domain/BaseEntity.java @@ -1,4 +1,4 @@ -package com.recodeit.server.domain; +package com.recordit.server.domain; import java.time.LocalDateTime; diff --git a/src/main/java/com/recordit/server/domain/Member.java b/src/main/java/com/recordit/server/domain/Member.java new file mode 100644 index 00000000..647979d9 --- /dev/null +++ b/src/main/java/com/recordit/server/domain/Member.java @@ -0,0 +1,45 @@ +package com.recordit.server.domain; + +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import com.recordit.server.constant.LoginType; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +@Where(clause = "deleted_at is null") +@SQLDelete(sql = "UPDATE member SET deleted_at = CURRENT_TIMESTAMP WHERE id = ?") +public class Member extends BaseEntity { + + @Id + @GeneratedValue(generator = "uuid2") + @Column(name = "MEMBER_ID", columnDefinition = "BINARY(16)") + private UUID id; + private String password; + private String nickname; + private String oauthId; + private LoginType loginType; + + private Member(String password, String nickname, String oauthId, LoginType loginType) { + this.password = password; + this.nickname = nickname; + this.oauthId = oauthId; + this.loginType = loginType; + } + + public static Member of(String password, String nickname, String oauthId, LoginType loginType) { + return new Member(password, nickname, oauthId, loginType); + } +} diff --git a/src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java b/src/main/java/com/recordit/server/exception/NotFoundUserInfoInSessionException.java similarity index 80% rename from src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java rename to src/main/java/com/recordit/server/exception/NotFoundUserInfoInSessionException.java index 3df9b13d..f7ad63c7 100644 --- a/src/main/java/com/recodeit/server/exception/NotFoundUserInfoInSessionException.java +++ b/src/main/java/com/recordit/server/exception/NotFoundUserInfoInSessionException.java @@ -1,4 +1,4 @@ -package com.recodeit.server.exception; +package com.recordit.server.exception; public class NotFoundUserInfoInSessionException extends RuntimeException { public NotFoundUserInfoInSessionException(String message) { diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java new file mode 100644 index 00000000..300cae1e --- /dev/null +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -0,0 +1,26 @@ +package com.recordit.server.service; + +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.recordit.server.service.oauth.OauthService; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class MemberService { + private final List oauthServices; + + @Transactional + public void oauthLogin(String loginType) { + + } + + @Transactional + public void oauthRegister(String loginType) { + + } +} diff --git a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java new file mode 100644 index 00000000..35a7f8fb --- /dev/null +++ b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java @@ -0,0 +1,15 @@ +package com.recordit.server.service.oauth; + +import com.recordit.server.constant.LoginType; + +public class GoogleOauthService implements OauthService { + @Override + public LoginType getLoginType() { + return LoginType.GOOGLE; + } + + @Override + public void request() { + + } +} diff --git a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java new file mode 100644 index 00000000..72df904f --- /dev/null +++ b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java @@ -0,0 +1,15 @@ +package com.recordit.server.service.oauth; + +import com.recordit.server.constant.LoginType; + +public class KakaoOauthService implements OauthService { + @Override + public LoginType getLoginType() { + return LoginType.KAKAO; + } + + @Override + public void request() { + + } +} diff --git a/src/main/java/com/recordit/server/service/oauth/OauthService.java b/src/main/java/com/recordit/server/service/oauth/OauthService.java new file mode 100644 index 00000000..92f71480 --- /dev/null +++ b/src/main/java/com/recordit/server/service/oauth/OauthService.java @@ -0,0 +1,10 @@ +package com.recordit.server.service.oauth; + +import com.recordit.server.constant.LoginType; + +public interface OauthService { + + LoginType getLoginType(); + + void request(); +} diff --git a/src/main/java/com/recodeit/server/util/SessionUtil.java b/src/main/java/com/recordit/server/util/SessionUtil.java similarity index 88% rename from src/main/java/com/recodeit/server/util/SessionUtil.java rename to src/main/java/com/recordit/server/util/SessionUtil.java index 48bffded..9f851d29 100644 --- a/src/main/java/com/recodeit/server/util/SessionUtil.java +++ b/src/main/java/com/recordit/server/util/SessionUtil.java @@ -1,10 +1,10 @@ -package com.recodeit.server.util; +package com.recordit.server.util; import javax.servlet.http.HttpSession; import org.springframework.stereotype.Component; -import com.recodeit.server.exception.NotFoundUserInfoInSessionException; +import com.recordit.server.exception.NotFoundUserInfoInSessionException; import lombok.RequiredArgsConstructor; diff --git a/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java b/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java deleted file mode 100644 index 025d8d6b..00000000 --- a/src/test/java/com/recodeit/server/configuration/EmbeddedRedisConfiguration.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.recodeit.server.configuration; - -import javax.annotation.PreDestroy; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import redis.embedded.RedisServer; - -@Configuration -@Profile("test") -public class EmbeddedRedisConfiguration { - - private final RedisServer redisServer; - - protected EmbeddedRedisConfiguration(@Value("${spring.redis.port}") int redisPort) { - this.redisServer = new RedisServer(redisPort); - redisServer.start(); - } - - @PreDestroy - private void stop() { - if (redisServer != null) { - redisServer.stop(); - } - } -} diff --git a/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java b/src/test/java/com/recordit/server/RecordItServerApplicationTests.java similarity index 54% rename from src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java rename to src/test/java/com/recordit/server/RecordItServerApplicationTests.java index 38ddb31f..dfc23898 100644 --- a/src/test/java/com/recodeit/server/RecodeItServerApplicationTests.java +++ b/src/test/java/com/recordit/server/RecordItServerApplicationTests.java @@ -1,16 +1,15 @@ -package com.recodeit.server; +package com.recordit.server; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Profile; import org.springframework.test.context.ActiveProfiles; @SpringBootTest @ActiveProfiles("test") -class RecodeItServerApplicationTests { +class RecordItServerApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + } } diff --git a/src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java b/src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java new file mode 100644 index 00000000..3d8ad624 --- /dev/null +++ b/src/test/java/com/recordit/server/configuration/EmbeddedRedisConfiguration.java @@ -0,0 +1,28 @@ +package com.recordit.server.configuration; + +import javax.annotation.PreDestroy; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import redis.embedded.RedisServer; + +@Configuration +@Profile("test") +public class EmbeddedRedisConfiguration { + + private final RedisServer redisServer; + + protected EmbeddedRedisConfiguration(@Value("${spring.redis.port}") int redisPort) { + this.redisServer = new RedisServer(redisPort); + redisServer.start(); + } + + @PreDestroy + private void stop() { + if (redisServer != null) { + redisServer.stop(); + } + } +} diff --git a/src/test/java/com/recodeit/server/util/SessionUtilTest.java b/src/test/java/com/recordit/server/util/SessionUtilTest.java similarity index 95% rename from src/test/java/com/recodeit/server/util/SessionUtilTest.java rename to src/test/java/com/recordit/server/util/SessionUtilTest.java index 697d6866..00d4160e 100644 --- a/src/test/java/com/recodeit/server/util/SessionUtilTest.java +++ b/src/test/java/com/recordit/server/util/SessionUtilTest.java @@ -1,4 +1,4 @@ -package com.recodeit.server.util; +package com.recordit.server.util; import static org.assertj.core.api.Assertions.*; @@ -11,7 +11,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.mock.web.MockHttpSession; -import com.recodeit.server.exception.NotFoundUserInfoInSessionException; +import com.recordit.server.exception.NotFoundUserInfoInSessionException; @ExtendWith(MockitoExtension.class) public class SessionUtilTest { From 1c7e6adea2540f489d1f55f939bd84f7330b672a Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 21:06:23 +0900 Subject: [PATCH 038/264] =?UTF-8?q?[BE-54]=20style:=20build.gradle=20group?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 1518e6e7..dd557aa9 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { id 'io.spring.dependency-management' version '1.0.15.RELEASE' } -group = 'com.recodeit' +group = 'com.recordit' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' @@ -29,7 +29,7 @@ dependencies { // embedded redis implementation('it.ozimov:embedded-redis:0.7.3') { - exclude group : "org.slf4j", module : "slf4j-simple" + exclude group: "org.slf4j", module: "slf4j-simple" } compileOnly 'org.projectlombok:lombok' From 21817c90e1e9847ae4431fdb618b55cbbfba0f23 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 21:06:51 +0900 Subject: [PATCH 039/264] =?UTF-8?q?[BE-54]=20style:=20SwaggerConfiguration?= =?UTF-8?q?=20basePackage=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/configuration/SwaggerConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java b/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java index 9ec335f4..5876ed71 100644 --- a/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java @@ -16,7 +16,7 @@ public class SwaggerConfiguration { public Docket api() { return new Docket(DocumentationType.OAS_30) .select() - .apis(RequestHandlerSelectors.basePackage("com.recodeit")) + .apis(RequestHandlerSelectors.basePackage("com.recordit")) .paths(PathSelectors.any()) .build().apiInfo(apiInfo()); } From 6863077d348d6621bda66bcb424280b048276650 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 21:57:14 +0900 Subject: [PATCH 040/264] =?UTF-8?q?[BE-55]=20feat:=20endPoint=EB=AA=85=20?= =?UTF-8?q?=EC=B9=B4=EB=A9=9C=EC=BC=80=EC=9D=B4=EC=8A=A4=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/controller/MemberController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 2e1232ba..ec8c5180 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -15,13 +15,13 @@ public class MemberController { private final MemberService memberService; - @GetMapping("/member/oauth/{logintype}") - public void oauthLogin(@PathVariable("logintype") String loginType) { + @GetMapping("/member/oauth/{loginType}") + public void oauthLogin(@PathVariable("loginType") String loginType) { memberService.oauthLogin(loginType); } @PostMapping("/member/oauth/{loginType}") - public void oauthRegister(@PathVariable("logintype") String loginType) { + public void oauthRegister(@PathVariable("loginType") String loginType) { memberService.oauthRegister(loginType); } } From 5b6a7d0e4154541c63f763d3a9d3f8f02cfa7d41 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 21:58:24 +0900 Subject: [PATCH 041/264] =?UTF-8?q?[BE-55]=20feat:=20OauthService=EC=97=90?= =?UTF-8?q?=20Service=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EB=B6=99=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/service/oauth/GoogleOauthService.java | 3 +++ .../com/recordit/server/service/oauth/KakaoOauthService.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java index 35a7f8fb..58ce11e1 100644 --- a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java @@ -1,7 +1,10 @@ package com.recordit.server.service.oauth; +import org.springframework.stereotype.Service; + import com.recordit.server.constant.LoginType; +@Service public class GoogleOauthService implements OauthService { @Override public LoginType getLoginType() { diff --git a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java index 72df904f..293c832d 100644 --- a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java @@ -1,7 +1,10 @@ package com.recordit.server.service.oauth; +import org.springframework.stereotype.Service; + import com.recordit.server.constant.LoginType; +@Service public class KakaoOauthService implements OauthService { @Override public LoginType getLoginType() { From 48f97222beea1dd11c51027bbaac374b353e1ec4 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 22:00:22 +0900 Subject: [PATCH 042/264] =?UTF-8?q?[BE-56]=20hotfix:=20application-test.ym?= =?UTF-8?q?l=EC=97=90=20swagger=20=EC=84=A4=EC=A0=95=EA=B0=92=EA=B3=BC=20r?= =?UTF-8?q?edis=20password=20=EC=84=A4=EC=A0=95=EA=B0=92=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application-test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index 210ca9a2..dc3202bc 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -3,6 +3,9 @@ spring: activate: on-profile: "test" + mvc: + pathmatch: + matching-strategy: ant_path_matcher datasource: driver-class-name: org.h2.Driver url: jdbc:h2:~/RecordIt @@ -15,5 +18,6 @@ spring: redis: host: localhost port: 63790 + password: session: store-type: redis \ No newline at end of file From b5c3dfd4fa9fc9fc7a3eeac30c8aeb7882f5d09c Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 22:07:09 +0900 Subject: [PATCH 043/264] =?UTF-8?q?[BE-55]=20feat:=20OauthServiceLocator?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/MemberService.java | 9 +++---- .../service/oauth/OauthServiceLocator.java | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index 300cae1e..17157d31 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -1,26 +1,25 @@ package com.recordit.server.service; -import java.util.List; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.recordit.server.service.oauth.OauthService; +import com.recordit.server.service.oauth.OauthServiceLocator; import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor public class MemberService { - private final List oauthServices; + private final OauthServiceLocator oauthServiceLocator; @Transactional public void oauthLogin(String loginType) { - + OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType); } @Transactional public void oauthRegister(String loginType) { - + OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType); } } diff --git a/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java b/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java new file mode 100644 index 00000000..796ae640 --- /dev/null +++ b/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java @@ -0,0 +1,26 @@ +package com.recordit.server.service.oauth; + +import java.util.List; + +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class OauthServiceLocator { + private final List oauthServices; + + public OauthService getOauthServiceByLoginType(String loginType) { + if (!StringUtils.hasText(loginType)) { + throw new NullPointerException("로그인 타입이 없습니다."); + } + for (OauthService service : oauthServices) { + if (loginType.equals(service.getLoginType().name())) { + return service; + } + } + throw new NullPointerException("일치하는 로그인 타입이 없습니다."); + } +} From 51841a270d35ab9483dcf4e22743e8ef9cd99e41 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 22:25:14 +0900 Subject: [PATCH 044/264] =?UTF-8?q?[BE-55]=20fix:=20OauthServiceLocator=20?= =?UTF-8?q?stream=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/oauth/OauthServiceLocator.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java b/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java index 796ae640..f7b065cc 100644 --- a/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java +++ b/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java @@ -14,13 +14,11 @@ public class OauthServiceLocator { public OauthService getOauthServiceByLoginType(String loginType) { if (!StringUtils.hasText(loginType)) { - throw new NullPointerException("로그인 타입이 없습니다."); + throw new NullPointerException("로그인 타입이 입력되지 않았습니다."); } - for (OauthService service : oauthServices) { - if (loginType.equals(service.getLoginType().name())) { - return service; - } - } - throw new NullPointerException("일치하는 로그인 타입이 없습니다."); + return oauthServices.stream() + .filter(oauthService -> oauthService.getLoginType().name().equals(loginType)) + .findFirst() + .orElseThrow(() -> new NullPointerException("일치하는 로그인 타입이 없습니다.")); } } From 6a6fb9c7a3a3ef72a42e808decca1fbafc520b0e Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 22:40:18 +0900 Subject: [PATCH 045/264] =?UTF-8?q?[BE-37]=20refactor:=20Member=20Entity?= =?UTF-8?q?=20ID=20=EC=A0=84=EB=9E=B5=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20L?= =?UTF-8?q?oginType=20DB=20=EC=A0=80=EC=9E=A5=EC=8B=9C=20String=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/Member.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/Member.java b/src/main/java/com/recordit/server/domain/Member.java index 647979d9..727cb169 100644 --- a/src/main/java/com/recordit/server/domain/Member.java +++ b/src/main/java/com/recordit/server/domain/Member.java @@ -1,10 +1,10 @@ package com.recordit.server.domain; -import java.util.UUID; - -import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import org.hibernate.annotations.SQLDelete; @@ -24,12 +24,12 @@ public class Member extends BaseEntity { @Id - @GeneratedValue(generator = "uuid2") - @Column(name = "MEMBER_ID", columnDefinition = "BINARY(16)") - private UUID id; + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; private String password; private String nickname; private String oauthId; + @Enumerated(value = EnumType.STRING) private LoginType loginType; private Member(String password, String nickname, String oauthId, LoginType loginType) { From 05c60a871473a89869b03d7d7b8c5431154892cd Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 23:05:43 +0900 Subject: [PATCH 046/264] =?UTF-8?q?[BE-60]=20fix:=20IllegalArgumentExcepti?= =?UTF-8?q?on=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/constant/LoginType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/constant/LoginType.java b/src/main/java/com/recordit/server/constant/LoginType.java index 5e4f71c4..fa332d70 100644 --- a/src/main/java/com/recordit/server/constant/LoginType.java +++ b/src/main/java/com/recordit/server/constant/LoginType.java @@ -11,6 +11,6 @@ public static LoginType findByString(String str) { return Arrays.stream(LoginType.values()) .filter(loginType -> loginType.name().equals(str)) .findFirst() - .orElseThrow(() -> new IllegalArgumentException("")); + .orElseThrow(() -> new IllegalArgumentException("일치하는 로그인 타입이 없습니다.")); } } From b3acaedead40c06ba7591e23f33e2a0be07e4f7a Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 23:07:50 +0900 Subject: [PATCH 047/264] =?UTF-8?q?[BE-60]=20feat:=20GlobalExceptionHandle?= =?UTF-8?q?r=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/exception/ErrorMessage.java | 16 +++++++ .../exception/GlobalExceptionHandler.java | 48 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/ErrorMessage.java create mode 100644 src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java diff --git a/src/main/java/com/recordit/server/exception/ErrorMessage.java b/src/main/java/com/recordit/server/exception/ErrorMessage.java new file mode 100644 index 00000000..e2263bcc --- /dev/null +++ b/src/main/java/com/recordit/server/exception/ErrorMessage.java @@ -0,0 +1,16 @@ +package com.recordit.server.exception; + +import java.time.LocalDateTime; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@Builder +public class ErrorMessage { + private String msg; + private String errorCode; + private LocalDateTime timestamp; +} \ No newline at end of file diff --git a/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java b/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..b1d00e97 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java @@ -0,0 +1,48 @@ +package com.recordit.server.exception; + +import java.time.LocalDateTime; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler { + private static String getSimpleName(Exception e) { + return e.getClass().getSimpleName(); + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(NotFoundUserInfoInSessionException.class) + public ErrorMessage handleNotFoundUserInfoInSessionException(NotFoundUserInfoInSessionException e) { + return ErrorMessage.builder() + .msg(e.getLocalizedMessage()) + .errorCode(getSimpleName(e)) + .timestamp(LocalDateTime.now()) + .build(); + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(IllegalArgumentException.class) + public ErrorMessage handleIllegalArgumentException(IllegalArgumentException e) { + return ErrorMessage.builder() + .msg(e.getLocalizedMessage()) + .errorCode(getSimpleName(e)) + .timestamp(LocalDateTime.now()) + .build(); + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(NullPointerException.class) + public ErrorMessage handleNullPointerException(NullPointerException e) { + return ErrorMessage.builder() + .msg(e.getLocalizedMessage()) + .errorCode(getSimpleName(e)) + .timestamp(LocalDateTime.now()) + .build(); + } +} From 85d571701925b7be6e3182177ab632c4bf2aee7b Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 23:14:30 +0900 Subject: [PATCH 048/264] =?UTF-8?q?[BE-70]=20chore:=20pull=5Frequest=5Ftem?= =?UTF-8?q?plate=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/pull_request_template.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index f7317f15..88b7bd54 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,8 +1,11 @@ ## 관련 이슈 번호 + + ## 설명 ## 변경사항 + From fe1529143534b9a81258490bc2a4cf53b2002a78 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 23:24:05 +0900 Subject: [PATCH 049/264] =?UTF-8?q?[BE-59]=20feat:=20RecordCategory=20Enti?= =?UTF-8?q?ty=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/domain/RecordCategory.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/recordit/server/domain/RecordCategory.java diff --git a/src/main/java/com/recordit/server/domain/RecordCategory.java b/src/main/java/com/recordit/server/domain/RecordCategory.java new file mode 100644 index 00000000..e9f6d003 --- /dev/null +++ b/src/main/java/com/recordit/server/domain/RecordCategory.java @@ -0,0 +1,36 @@ +package com.recordit.server.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity(name = "RECORD_CATEGORY") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Where(clause = "deleted_at is null") +@SQLDelete(sql = "UPDATE RECORD_CATEGORY SET RECORD_CATEGORY.deletedAt = CURRENT_TIMESTAMP WHERE RECORD_CATEGORY.RECORD_CATEGORY_ID = ?") +@Getter +public class RecordCategory extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "RECORD_CATEGORY_ID") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "PARENT_RECORD_CATEGORY_ID") + private RecordCategory parentRecordCategory; + + private String name; +} From 117b7fc5b4495febcea6b37f0b94cf3793938705 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 23:24:34 +0900 Subject: [PATCH 050/264] =?UTF-8?q?[BE-67]=20fix:=20oauthLogin=20Get=20->?= =?UTF-8?q?=20Post=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/controller/MemberController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index ec8c5180..98eec6f5 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -1,6 +1,5 @@ package com.recordit.server.controller; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; @@ -15,7 +14,7 @@ public class MemberController { private final MemberService memberService; - @GetMapping("/member/oauth/{loginType}") + @PostMapping("/member/oauth/{loginType}") public void oauthLogin(@PathVariable("loginType") String loginType) { memberService.oauthLogin(loginType); } From b9ab46a29c493650068431ef194cc9d265cc3adf Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 21 Dec 2022 23:27:06 +0900 Subject: [PATCH 051/264] =?UTF-8?q?[BE-59]=20refactor:=20Member=20Entity?= =?UTF-8?q?=20=EC=BB=AC=EB=9F=BC=EA=B3=BC=20SQLDelete=20=EB=82=B4=EC=9A=A9?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/Member.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/Member.java b/src/main/java/com/recordit/server/domain/Member.java index 727cb169..2e3fde1c 100644 --- a/src/main/java/com/recordit/server/domain/Member.java +++ b/src/main/java/com/recordit/server/domain/Member.java @@ -1,5 +1,6 @@ package com.recordit.server.domain; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -16,15 +17,16 @@ import lombok.Getter; import lombok.NoArgsConstructor; -@Entity +@Entity(name = "MEMBER") @NoArgsConstructor(access = AccessLevel.PROTECTED) -@Getter @Where(clause = "deleted_at is null") -@SQLDelete(sql = "UPDATE member SET deleted_at = CURRENT_TIMESTAMP WHERE id = ?") +@SQLDelete(sql = "UPDATE MEMBER SET MEMBER.deletedAt = CURRENT_TIMESTAMP WHERE MEMBER.MEMBER_ID = ?") +@Getter public class Member extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "MEMBER_ID") private Long id; private String password; private String nickname; From 75f9d0c6bf9cc87b9dbbdc72bbeabdd9157fdf3c Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 21 Dec 2022 23:27:47 +0900 Subject: [PATCH 052/264] =?UTF-8?q?[BE-67]=20feat:=20oauthLogin=20RequestB?= =?UTF-8?q?ody=20String=20token=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/controller/MemberController.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 98eec6f5..3593dd90 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -2,6 +2,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import com.recordit.server.service.MemberService; @@ -15,7 +16,7 @@ public class MemberController { private final MemberService memberService; @PostMapping("/member/oauth/{loginType}") - public void oauthLogin(@PathVariable("loginType") String loginType) { + public void oauthLogin(@PathVariable("loginType") String loginType, @RequestBody String token) { memberService.oauthLogin(loginType); } From 202a0a54988c8243b0a7f6635c9a9b3394bbf863 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 22 Dec 2022 00:14:03 +0900 Subject: [PATCH 053/264] =?UTF-8?q?[BE-67]=20fix:=20useDefaultResponseMess?= =?UTF-8?q?ages=20=EC=98=B5=EC=85=98=20false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/configuration/SwaggerConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java b/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java index 5876ed71..c94b09f8 100644 --- a/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java @@ -15,6 +15,7 @@ public class SwaggerConfiguration { @Bean public Docket api() { return new Docket(DocumentationType.OAS_30) + .useDefaultResponseMessages(false) .select() .apis(RequestHandlerSelectors.basePackage("com.recordit")) .paths(PathSelectors.any()) From 79a6d4989b2fb554a11db83fb812583ff52e348c Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 12:20:31 +0900 Subject: [PATCH 054/264] =?UTF-8?q?[BE-59]=20refactor:=20BaseEntity=20?= =?UTF-8?q?=EC=BB=AC=EB=9F=BC=EB=AA=85=20=EB=8C=80=EB=AC=B8=EC=9E=90=20?= =?UTF-8?q?=EC=8A=A4=EB=84=A4=EC=9D=B4=ED=81=AC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/BaseEntity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/recordit/server/domain/BaseEntity.java b/src/main/java/com/recordit/server/domain/BaseEntity.java index 81925e87..ef52bef2 100644 --- a/src/main/java/com/recordit/server/domain/BaseEntity.java +++ b/src/main/java/com/recordit/server/domain/BaseEntity.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; +import javax.persistence.Column; import javax.persistence.EntityListeners; import javax.persistence.MappedSuperclass; import javax.validation.constraints.NotNull; @@ -19,11 +20,14 @@ public abstract class BaseEntity { @NotNull @CreatedDate + @Column(name = "CREATED_AT") private LocalDateTime createdAt; @NotNull @LastModifiedDate + @Column(name = "MODIFIED_AT") private LocalDateTime modifiedAt; + @Column(name = "DELETED_AT") private LocalDateTime deletedAt; } From 1ba2db0eff44ad65c62b359621ddc9d569675fd7 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 12:20:44 +0900 Subject: [PATCH 055/264] =?UTF-8?q?[BE-59]=20refactor:=20Member=20?= =?UTF-8?q?=EC=BB=AC=EB=9F=BC=EB=AA=85=20=EB=8C=80=EB=AC=B8=EC=9E=90=20?= =?UTF-8?q?=EC=8A=A4=EB=84=A4=EC=9D=B4=ED=81=AC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/domain/Member.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/Member.java b/src/main/java/com/recordit/server/domain/Member.java index 2e3fde1c..76871bb2 100644 --- a/src/main/java/com/recordit/server/domain/Member.java +++ b/src/main/java/com/recordit/server/domain/Member.java @@ -19,8 +19,8 @@ @Entity(name = "MEMBER") @NoArgsConstructor(access = AccessLevel.PROTECTED) -@Where(clause = "deleted_at is null") -@SQLDelete(sql = "UPDATE MEMBER SET MEMBER.deletedAt = CURRENT_TIMESTAMP WHERE MEMBER.MEMBER_ID = ?") +@Where(clause = "DELETED_AT is null") +@SQLDelete(sql = "UPDATE MEMBER SET MEMBER.DELETED_AT = CURRENT_TIMESTAMP WHERE MEMBER.MEMBER_ID = ?") @Getter public class Member extends BaseEntity { @@ -28,9 +28,20 @@ public class Member extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "MEMBER_ID") private Long id; + + @Column(name = "USERNAME") + private String username; + + @Column(name = "PASSWORD") private String password; + + @Column(name = "NICKNAME") private String nickname; + + @Column(name = "OAUTH_ID") private String oauthId; + + @Column(name = "LOGIN_TYPE") @Enumerated(value = EnumType.STRING) private LoginType loginType; From 0decfc372f9cd5e5f628487583f5ce7d0796a261 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 12:24:57 +0900 Subject: [PATCH 056/264] =?UTF-8?q?[BE-59]=20feat:=20RecordColor,=20Record?= =?UTF-8?q?Icon=20Entity=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/domain/RecordColor.java | 33 +++++++++++++++++++ .../recordit/server/domain/RecordIcon.java | 30 +++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/main/java/com/recordit/server/domain/RecordColor.java create mode 100644 src/main/java/com/recordit/server/domain/RecordIcon.java diff --git a/src/main/java/com/recordit/server/domain/RecordColor.java b/src/main/java/com/recordit/server/domain/RecordColor.java new file mode 100644 index 00000000..e894bc5a --- /dev/null +++ b/src/main/java/com/recordit/server/domain/RecordColor.java @@ -0,0 +1,33 @@ +package com.recordit.server.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity(name = "RECORD_COLOR") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Where(clause = "DELETED_AT is null") +@SQLDelete(sql = "UPDATE RECORD_COLOR SET RECORD_COLOR.DELETED_AT = CURRENT_TIMESTAMP WHERE RECORD_COLOR.RECORD_COLOR_ID = ?") +@Getter +public class RecordColor extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "RECORD_COLOR_ID") + private Long id; + + @Column(name = "NAME") + private String name; + + @Column(name = "HEX_CODE") + private String hexCode; +} diff --git a/src/main/java/com/recordit/server/domain/RecordIcon.java b/src/main/java/com/recordit/server/domain/RecordIcon.java new file mode 100644 index 00000000..2dbb2668 --- /dev/null +++ b/src/main/java/com/recordit/server/domain/RecordIcon.java @@ -0,0 +1,30 @@ +package com.recordit.server.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity(name = "RECORD_ICON") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Where(clause = "DELETED_AT is null") +@SQLDelete(sql = "UPDATE RECORD_ICON SET RECORD_ICON.DELETED_AT = CURRENT_TIMESTAMP WHERE RECORD_ICON.RECORD_ICON_ID = ?") +@Getter +public class RecordIcon extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "RECORD_ICON_ID") + private Long id; + + @Column(name = "NAME") + private String name; +} From 0a70ed8c07f5f2eb4fe04b9a303dcde265d32d70 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 12:26:21 +0900 Subject: [PATCH 057/264] =?UTF-8?q?[BE-59]=20feat:=20RecordCategory=20Enti?= =?UTF-8?q?ty=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/RecordCategory.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/RecordCategory.java b/src/main/java/com/recordit/server/domain/RecordCategory.java index e9f6d003..87cd3d95 100644 --- a/src/main/java/com/recordit/server/domain/RecordCategory.java +++ b/src/main/java/com/recordit/server/domain/RecordCategory.java @@ -18,8 +18,8 @@ @Entity(name = "RECORD_CATEGORY") @NoArgsConstructor(access = AccessLevel.PROTECTED) -@Where(clause = "deleted_at is null") -@SQLDelete(sql = "UPDATE RECORD_CATEGORY SET RECORD_CATEGORY.deletedAt = CURRENT_TIMESTAMP WHERE RECORD_CATEGORY.RECORD_CATEGORY_ID = ?") +@Where(clause = "DELETED_AT is null") +@SQLDelete(sql = "UPDATE RECORD_CATEGORY SET RECORD_CATEGORY.DELETED_AT = CURRENT_TIMESTAMP WHERE RECORD_CATEGORY.RECORD_CATEGORY_ID = ?") @Getter public class RecordCategory extends BaseEntity { @@ -32,5 +32,6 @@ public class RecordCategory extends BaseEntity { @JoinColumn(name = "PARENT_RECORD_CATEGORY_ID") private RecordCategory parentRecordCategory; + @Column(name = "NAME") private String name; } From 3639eee59dc12d2318ab4dff3c719eef137ef9ad Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 12:31:18 +0900 Subject: [PATCH 058/264] =?UTF-8?q?[BE-59]=20feat:=20Record=20Entity=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/domain/Record.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/java/com/recordit/server/domain/Record.java diff --git a/src/main/java/com/recordit/server/domain/Record.java b/src/main/java/com/recordit/server/domain/Record.java new file mode 100644 index 00000000..24bbf57e --- /dev/null +++ b/src/main/java/com/recordit/server/domain/Record.java @@ -0,0 +1,54 @@ +package com.recordit.server.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity(name = "RECORD") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Where(clause = "DELETED_AT is null") +@SQLDelete(sql = "UPDATE RECORD SET RECORD.DELETED_AT = CURRENT_TIMESTAMP WHERE RECORD.RECORD_ID = ?") +@Getter +public class Record extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "RECORD_ID") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "RECORD_CATEGORY_ID") + private RecordCategory recordCategory; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "MEMBER_ID") + private Member writer; + + @Column(name = "TITLE") + private String title; + + @Column(name = "CONTENT") + private String content; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "RECORD_COLOR_ID") + private RecordColor recordColor; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "RECORD_ICON_ID") + private RecordIcon recordIcon; + +} From 4171863270a909b59ae162c313badfb39bacd1aa Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 12:39:21 +0900 Subject: [PATCH 059/264] =?UTF-8?q?[BE-59]=20refactor:=20Record=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EA=B0=9C=EC=88=98=20=EC=BB=AC?= =?UTF-8?q?=EB=9F=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/Record.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/recordit/server/domain/Record.java b/src/main/java/com/recordit/server/domain/Record.java index 24bbf57e..6cde2e9a 100644 --- a/src/main/java/com/recordit/server/domain/Record.java +++ b/src/main/java/com/recordit/server/domain/Record.java @@ -43,6 +43,9 @@ public class Record extends BaseEntity { @Column(name = "CONTENT") private String content; + @Column(name = "NUM_OF_IMAGE") + private Integer numOfImage; + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "RECORD_COLOR_ID") private RecordColor recordColor; From fd0b44fc96fd32a45d3e43375f6da049d5d51fbe Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 12:40:42 +0900 Subject: [PATCH 060/264] =?UTF-8?q?[BE-59]=20feat:=20Comment=20Entity=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/domain/Comment.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/com/recordit/server/domain/Comment.java diff --git a/src/main/java/com/recordit/server/domain/Comment.java b/src/main/java/com/recordit/server/domain/Comment.java new file mode 100644 index 00000000..3e3b5fa0 --- /dev/null +++ b/src/main/java/com/recordit/server/domain/Comment.java @@ -0,0 +1,40 @@ +package com.recordit.server.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity(name = "COMMENT") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Where(clause = "DELETED_AT is null") +@SQLDelete(sql = "UPDATE COMMENT SET COMMENT.DELETED_AT = CURRENT_TIMESTAMP WHERE COMMENT.COMMENT_ID = ?") +@Getter +public class Comment extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "COMMENT_ID") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "PARENT_COMMENT_ID") + private Comment parentComment; + + @Column(name = "CONTENT") + private String content; + + @Column(name = "NUM_OF_IMAGE") + private Integer numOfImage; +} From 866ea94441959c396d541c7c6dbdec572beee261 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 13:13:12 +0900 Subject: [PATCH 061/264] =?UTF-8?q?[BE-59]=20feat:=20ImagFile,=20RefType?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/constant/RefType.java | 5 ++ .../com/recordit/server/domain/ImageFile.java | 60 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/main/java/com/recordit/server/constant/RefType.java create mode 100644 src/main/java/com/recordit/server/domain/ImageFile.java diff --git a/src/main/java/com/recordit/server/constant/RefType.java b/src/main/java/com/recordit/server/constant/RefType.java new file mode 100644 index 00000000..3e9ff8c0 --- /dev/null +++ b/src/main/java/com/recordit/server/constant/RefType.java @@ -0,0 +1,5 @@ +package com.recordit.server.constant; + +public enum RefType { + RECORD, COMMENT +} diff --git a/src/main/java/com/recordit/server/domain/ImageFile.java b/src/main/java/com/recordit/server/domain/ImageFile.java new file mode 100644 index 00000000..e3d75a88 --- /dev/null +++ b/src/main/java/com/recordit/server/domain/ImageFile.java @@ -0,0 +1,60 @@ +package com.recordit.server.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import com.recordit.server.constant.RefType; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity(name = "IMAGE_FILE") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Where(clause = "DELETED_AT is null") +@SQLDelete(sql = "UPDATE IMAGE_FILE SET IMAGE_FILE.DELETED_AT = CURRENT_TIMESTAMP WHERE IMAGE_FILE.IMAGE_FILE_ID = ?") +@Getter +public class ImageFile extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "IMAGE_FILE_ID") + private Long id; + + @Enumerated(EnumType.STRING) + @Column(name = "REF_TYPE") + private RefType refType; + + @Column(name = "REF_ID") + private Long refId; + + @Column(name = "DOWNLOAD_URL") + private String downloadUrl; + + @Column(name = "ORIGINAL_NAME") + private String originalName; + + @Column(name = "SAVE_NAME") + private String saveName; + + @Column(name = "EXTENSION") + private String extension; + + @Column(name = "SIZE") + private Integer size; + + @Column(name = "REGISTER_IP") + private String registerIp; + + @Column(name = "DOWNLOAD_COUNT") + private Integer downloadCount; + +} From ba3926c9aed78b2ad194d5a21872b44db7169bb3 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 14:14:11 +0900 Subject: [PATCH 062/264] =?UTF-8?q?[BE-59]=20feat:=20=EC=8B=A0=EA=B3=A0?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=9C=20CommentReport,=20RecordReport?= =?UTF-8?q?=20Entity=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/domain/CommentReport.java | 39 +++++++++++++++++++ .../recordit/server/domain/RecordReport.java | 39 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/main/java/com/recordit/server/domain/CommentReport.java create mode 100644 src/main/java/com/recordit/server/domain/RecordReport.java diff --git a/src/main/java/com/recordit/server/domain/CommentReport.java b/src/main/java/com/recordit/server/domain/CommentReport.java new file mode 100644 index 00000000..343757c7 --- /dev/null +++ b/src/main/java/com/recordit/server/domain/CommentReport.java @@ -0,0 +1,39 @@ +package com.recordit.server.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity(name = "COMMENT_REPORT") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Where(clause = "DELETED_AT is null") +@SQLDelete(sql = "UPDATE COMMENT_REPORT SET COMMENT_REPORT.DELETED_AT = CURRENT_TIMESTAMP WHERE COMMENT_REPORT.RECORD_REPORT_ID = ?") +@Getter +public class CommentReport extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "COMMENT_REPORT_ID") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "MEMBER_ID") + private Member reporter; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "COMMENT_ID") + private Comment reportedComment; + +} diff --git a/src/main/java/com/recordit/server/domain/RecordReport.java b/src/main/java/com/recordit/server/domain/RecordReport.java new file mode 100644 index 00000000..45d11552 --- /dev/null +++ b/src/main/java/com/recordit/server/domain/RecordReport.java @@ -0,0 +1,39 @@ +package com.recordit.server.domain; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity(name = "RECORD_REPORT") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Where(clause = "DELETED_AT is null") +@SQLDelete(sql = "UPDATE RECORD_REPORT SET RECORD_REPORT.DELETED_AT = CURRENT_TIMESTAMP WHERE RECORD_REPORT.RECORD_REPORT_ID = ?") +@Getter +public class RecordReport extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "RECORD_REPORT_ID") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "MEMBER_ID") + private Member reporter; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "RECORD_ID") + private Record reportedRecord; + +} From 4a0405017f009ef670484c84cb9dbc472a22d0fd Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 14:37:51 +0900 Subject: [PATCH 063/264] =?UTF-8?q?[BE-59]=20feat:=20refType=EA=B3=BC=20re?= =?UTF-8?q?fId=EB=A1=9C=20=EB=B3=B5=ED=95=A9=20=EC=9C=A0=EB=8B=88=ED=81=AC?= =?UTF-8?q?=ED=82=A4=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/ImageFile.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/recordit/server/domain/ImageFile.java b/src/main/java/com/recordit/server/domain/ImageFile.java index e3d75a88..9ecb7865 100644 --- a/src/main/java/com/recordit/server/domain/ImageFile.java +++ b/src/main/java/com/recordit/server/domain/ImageFile.java @@ -7,6 +7,8 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; @@ -18,6 +20,9 @@ import lombok.NoArgsConstructor; @Entity(name = "IMAGE_FILE") +@Table(uniqueConstraints = { + @UniqueConstraint(columnNames = {"REF_TYPE", "REF_ID"}) +}) @NoArgsConstructor(access = AccessLevel.PROTECTED) @Where(clause = "DELETED_AT is null") @SQLDelete(sql = "UPDATE IMAGE_FILE SET IMAGE_FILE.DELETED_AT = CURRENT_TIMESTAMP WHERE IMAGE_FILE.IMAGE_FILE_ID = ?") From 40e5a8b46dbc94e946b3f65c7f50918d9f740e0d Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 14:39:26 +0900 Subject: [PATCH 064/264] =?UTF-8?q?[BE-59]=20fix:=20@SqlDelete=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=EC=97=90=20Id=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/CommentReport.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/CommentReport.java b/src/main/java/com/recordit/server/domain/CommentReport.java index 343757c7..2eafb6fe 100644 --- a/src/main/java/com/recordit/server/domain/CommentReport.java +++ b/src/main/java/com/recordit/server/domain/CommentReport.java @@ -19,7 +19,7 @@ @Entity(name = "COMMENT_REPORT") @NoArgsConstructor(access = AccessLevel.PROTECTED) @Where(clause = "DELETED_AT is null") -@SQLDelete(sql = "UPDATE COMMENT_REPORT SET COMMENT_REPORT.DELETED_AT = CURRENT_TIMESTAMP WHERE COMMENT_REPORT.RECORD_REPORT_ID = ?") +@SQLDelete(sql = "UPDATE COMMENT_REPORT SET COMMENT_REPORT.DELETED_AT = CURRENT_TIMESTAMP WHERE COMMENT_REPORT.COMMENT_REPORT_ID = ?") @Getter public class CommentReport extends BaseEntity { @@ -35,5 +35,5 @@ public class CommentReport extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "COMMENT_ID") private Comment reportedComment; - + } From 03bcd644092d727627a722970111457d846e9a86 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 22 Dec 2022 15:05:58 +0900 Subject: [PATCH 065/264] =?UTF-8?q?[BE-67]=20feat:=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?API=20=EB=AA=85=EC=84=B8=20Swagger=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/MemberController.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 3593dd90..24022577 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -3,25 +3,46 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.recordit.server.service.MemberService; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; @RestController @RequiredArgsConstructor +@RequestMapping("/member") public class MemberController { private final MemberService memberService; - @PostMapping("/member/oauth/{loginType}") - public void oauthLogin(@PathVariable("loginType") String loginType, @RequestBody String token) { + @ApiOperation(value = "로그인", + notes = "로그인 타입과 세션을 받아 가입된 회원이라면 로그인을 진행시키고 Header에 setCookie로 응답합니다") + @ApiResponses({ + @ApiResponse(code = 200, message = "API 정상 작동 / Header에 setCookie값 응답"), + @ApiResponse(code = 401, message = "회원정보가 없어 회원가입이 필요한 경우입니다." + + "Body로 응답된 TEMPSESSIONUUID와 사용자에게 닉네임을 받아 '/member/oauth/register/{loginType}'으로 요청하세요") + }) + @PostMapping("/oauth/login/{loginType}") + public void oauthLogin( + @PathVariable("loginType") String loginType, @RequestBody String token) { memberService.oauthLogin(loginType); } - @PostMapping("/member/oauth/{loginType}") - public void oauthRegister(@PathVariable("loginType") String loginType) { + @ApiOperation(value = "회원가입", + notes = "로그인 타입, TEMPSESSIONID, 닉네임을 받아 회원가입을 진행합니다") + @ApiResponses({ + @ApiResponse(code = 200, message = "API 정상 작동 / 세션 로그인 처리하고 SESSIONID 헤더로 응답"), + @ApiResponse(code = 428, message = "TEMPSESSIONUUID 정보가 Redis에 없거나 비정상적일 경우"), + @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") + }) + + @PostMapping("/oauth/register/{loginType}") + public void oauthRegister(@PathVariable("loginType") String loginType, @RequestBody String nickname) { memberService.oauthRegister(loginType); } } From f5e09cfbce92198d661cb56d731f1eab9f5ad0e2 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 22 Dec 2022 15:11:58 +0900 Subject: [PATCH 066/264] =?UTF-8?q?[BE-67]=20feat:=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EC=A4=91=EB=B3=B5=ED=99=95=EC=9D=B8=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/MemberController.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 24022577..81b1f39c 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -1,5 +1,6 @@ package com.recordit.server.controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -40,9 +41,19 @@ public void oauthLogin( @ApiResponse(code = 428, message = "TEMPSESSIONUUID 정보가 Redis에 없거나 비정상적일 경우"), @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") }) - @PostMapping("/oauth/register/{loginType}") public void oauthRegister(@PathVariable("loginType") String loginType, @RequestBody String nickname) { memberService.oauthRegister(loginType); } + + @ApiOperation(value = "닉네임 중복확인", + notes = "닉네임을 받아 해당 닉네임이 중복되었는지 판별") + @ApiResponses({ + @ApiResponse(code = 200, message = "닉네임이 사용 가능한 경우"), + @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") + }) + @GetMapping + public void duplicateNicknameCheck(@RequestBody String nickname) { + + } } From adb4b1d1375dde3417b801ec657a31389f02c096 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 22 Dec 2022 15:36:09 +0900 Subject: [PATCH 067/264] =?UTF-8?q?[BE-67]=20fix:=20temp=5Fsession=5Fid=20?= =?UTF-8?q?->=20register=5Fsession=20=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/controller/MemberController.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 81b1f39c..b2383b7a 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -22,11 +22,11 @@ public class MemberController { private final MemberService memberService; @ApiOperation(value = "로그인", - notes = "로그인 타입과 세션을 받아 가입된 회원이라면 로그인을 진행시키고 Header에 setCookie로 응답합니다") + notes = "로그인 타입과 세션을 받아 가입된 회원이라면 로그인을 진행시키고 Header에 Set-cookie: SESSION=;응답합니다") @ApiResponses({ - @ApiResponse(code = 200, message = "API 정상 작동 / Header에 setCookie값 응답"), + @ApiResponse(code = 200, message = "API 정상 작동 / Header에 Set-cookie: SESSION=;응답"), @ApiResponse(code = 401, message = "회원정보가 없어 회원가입이 필요한 경우입니다." - + "Body로 응답된 TEMPSESSIONUUID와 사용자에게 닉네임을 받아 '/member/oauth/register/{loginType}'으로 요청하세요") + + "Body로 응답된 register_session과 사용자에게 닉네임을 받아 '/member/oauth/register/{loginType}'으로 요청하세요") }) @PostMapping("/oauth/login/{loginType}") public void oauthLogin( @@ -37,8 +37,8 @@ public void oauthLogin( @ApiOperation(value = "회원가입", notes = "로그인 타입, TEMPSESSIONID, 닉네임을 받아 회원가입을 진행합니다") @ApiResponses({ - @ApiResponse(code = 200, message = "API 정상 작동 / 세션 로그인 처리하고 SESSIONID 헤더로 응답"), - @ApiResponse(code = 428, message = "TEMPSESSIONUUID 정보가 Redis에 없거나 비정상적일 경우"), + @ApiResponse(code = 200, message = "API 정상 작동 / 세션 로그인 처리하고 Header에 Set-cookie: SESSION=; 헤더로 응답"), + @ApiResponse(code = 428, message = "register_session 정보가 Redis에 없거나 비정상적일 경우"), @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") }) @PostMapping("/oauth/register/{loginType}") From 6c9deb08e4b7a87495572227d3d84db7208ae2cd Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 22 Dec 2022 15:37:31 +0900 Subject: [PATCH 068/264] =?UTF-8?q?[BE-67]=20fix:=20ApiResponse=20200=20me?= =?UTF-8?q?ssage=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/controller/MemberController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index b2383b7a..7118fd12 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -35,9 +35,9 @@ public void oauthLogin( } @ApiOperation(value = "회원가입", - notes = "로그인 타입, TEMPSESSIONID, 닉네임을 받아 회원가입을 진행합니다") + notes = "로그인 타입, register_session, 닉네임을 받아 회원가입을 진행합니다") @ApiResponses({ - @ApiResponse(code = 200, message = "API 정상 작동 / 세션 로그인 처리하고 Header에 Set-cookie: SESSION=; 헤더로 응답"), + @ApiResponse(code = 200, message = "API 정상 작동 / 회원가입을 진행하고 세션 로그인 처리하고 Header에 Set-cookie: SESSION=; 헤더로 응답"), @ApiResponse(code = 428, message = "register_session 정보가 Redis에 없거나 비정상적일 경우"), @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") }) From 51bbfbdf794f12758634eeb34ca99b13f9149762 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 22 Dec 2022 15:49:44 +0900 Subject: [PATCH 069/264] =?UTF-8?q?[BE-60]=20fix:=20GlobalExceptionHandler?= =?UTF-8?q?=20=EB=8C=80=EC=8B=A0=20=ED=8C=A8=ED=82=A4=EC=A7=80=EB=B3=84?= =?UTF-8?q?=EB=A1=9C=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/constant/LoginType.java | 4 +- .../server/exception/ErrorMessage.java | 3 +- .../exception/GlobalExceptionHandler.java | 48 --------------- .../member/MemberExceptionHandler.java | 61 +++++++++++++++++++ .../member/NotEnteredLoginTypeException.java | 7 +++ .../NotFoundUserInfoInSessionException.java | 2 +- .../member/NotMatchLoginTypeException.java | 7 +++ .../service/oauth/OauthServiceLocator.java | 7 ++- .../com/recordit/server/util/SessionUtil.java | 2 +- .../recordit/server/util/SessionUtilTest.java | 2 +- 10 files changed, 88 insertions(+), 55 deletions(-) delete mode 100644 src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java create mode 100644 src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java create mode 100644 src/main/java/com/recordit/server/exception/member/NotEnteredLoginTypeException.java rename src/main/java/com/recordit/server/exception/{ => member}/NotFoundUserInfoInSessionException.java (77%) create mode 100644 src/main/java/com/recordit/server/exception/member/NotMatchLoginTypeException.java diff --git a/src/main/java/com/recordit/server/constant/LoginType.java b/src/main/java/com/recordit/server/constant/LoginType.java index fa332d70..45b8d908 100644 --- a/src/main/java/com/recordit/server/constant/LoginType.java +++ b/src/main/java/com/recordit/server/constant/LoginType.java @@ -2,6 +2,8 @@ import java.util.Arrays; +import com.recordit.server.exception.member.NotMatchLoginTypeException; + public enum LoginType { LOCAL, KAKAO, @@ -11,6 +13,6 @@ public static LoginType findByString(String str) { return Arrays.stream(LoginType.values()) .filter(loginType -> loginType.name().equals(str)) .findFirst() - .orElseThrow(() -> new IllegalArgumentException("일치하는 로그인 타입이 없습니다.")); + .orElseThrow(() -> new NotMatchLoginTypeException("일치하는 로그인 타입이 없습니다.")); } } diff --git a/src/main/java/com/recordit/server/exception/ErrorMessage.java b/src/main/java/com/recordit/server/exception/ErrorMessage.java index e2263bcc..ee448012 100644 --- a/src/main/java/com/recordit/server/exception/ErrorMessage.java +++ b/src/main/java/com/recordit/server/exception/ErrorMessage.java @@ -10,7 +10,8 @@ @AllArgsConstructor @Builder public class ErrorMessage { + private int code; + private String errorSimpleName; private String msg; - private String errorCode; private LocalDateTime timestamp; } \ No newline at end of file diff --git a/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java b/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java deleted file mode 100644 index b1d00e97..00000000 --- a/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.recordit.server.exception; - -import java.time.LocalDateTime; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestControllerAdvice; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@RestControllerAdvice -public class GlobalExceptionHandler { - private static String getSimpleName(Exception e) { - return e.getClass().getSimpleName(); - } - - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(NotFoundUserInfoInSessionException.class) - public ErrorMessage handleNotFoundUserInfoInSessionException(NotFoundUserInfoInSessionException e) { - return ErrorMessage.builder() - .msg(e.getLocalizedMessage()) - .errorCode(getSimpleName(e)) - .timestamp(LocalDateTime.now()) - .build(); - } - - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(IllegalArgumentException.class) - public ErrorMessage handleIllegalArgumentException(IllegalArgumentException e) { - return ErrorMessage.builder() - .msg(e.getLocalizedMessage()) - .errorCode(getSimpleName(e)) - .timestamp(LocalDateTime.now()) - .build(); - } - - @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(NullPointerException.class) - public ErrorMessage handleNullPointerException(NullPointerException e) { - return ErrorMessage.builder() - .msg(e.getLocalizedMessage()) - .errorCode(getSimpleName(e)) - .timestamp(LocalDateTime.now()) - .build(); - } -} diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java new file mode 100644 index 00000000..b2a449bd --- /dev/null +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -0,0 +1,61 @@ +package com.recordit.server.exception.member; + +import java.time.LocalDateTime; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import com.recordit.server.controller.MemberController; +import com.recordit.server.exception.ErrorMessage; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestControllerAdvice(basePackageClasses = MemberController.class) +public class MemberExceptionHandler { + private static String getSimpleName(Exception e) { + return e.getClass().getSimpleName(); + } + + @ExceptionHandler(NotFoundUserInfoInSessionException.class) + public ResponseEntity handleNotFoundUserInfoInSessionException(NotFoundUserInfoInSessionException e) { + return ResponseEntity.badRequest() + .body( + ErrorMessage.builder() + .code(HttpStatus.BAD_REQUEST.value()) + .msg(e.getLocalizedMessage()) + .errorSimpleName(getSimpleName(e)) + .timestamp(LocalDateTime.now()) + .build() + ); + } + + @ExceptionHandler(NotMatchLoginTypeException.class) + public ResponseEntity handleNotMatchLoginTypeException(NotMatchLoginTypeException e) { + return ResponseEntity.badRequest() + .body( + ErrorMessage.builder() + .code(HttpStatus.BAD_REQUEST.value()) + .msg(e.getLocalizedMessage()) + .errorSimpleName(getSimpleName(e)) + .timestamp(LocalDateTime.now()) + .build() + ); + } + + @ExceptionHandler(NotEnteredLoginTypeException.class) + public ResponseEntity handleNotEnteredLoginTypeException(NotEnteredLoginTypeException e) { + return ResponseEntity.badRequest() + .body( + ErrorMessage.builder() + .code(HttpStatus.BAD_REQUEST.value()) + .msg(e.getLocalizedMessage()) + .errorSimpleName(getSimpleName(e)) + .timestamp(LocalDateTime.now()) + .build() + ); + } +} + diff --git a/src/main/java/com/recordit/server/exception/member/NotEnteredLoginTypeException.java b/src/main/java/com/recordit/server/exception/member/NotEnteredLoginTypeException.java new file mode 100644 index 00000000..20d516f2 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/member/NotEnteredLoginTypeException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.member; + +public class NotEnteredLoginTypeException extends RuntimeException { + public NotEnteredLoginTypeException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/exception/NotFoundUserInfoInSessionException.java b/src/main/java/com/recordit/server/exception/member/NotFoundUserInfoInSessionException.java similarity index 77% rename from src/main/java/com/recordit/server/exception/NotFoundUserInfoInSessionException.java rename to src/main/java/com/recordit/server/exception/member/NotFoundUserInfoInSessionException.java index f7ad63c7..2ed24817 100644 --- a/src/main/java/com/recordit/server/exception/NotFoundUserInfoInSessionException.java +++ b/src/main/java/com/recordit/server/exception/member/NotFoundUserInfoInSessionException.java @@ -1,4 +1,4 @@ -package com.recordit.server.exception; +package com.recordit.server.exception.member; public class NotFoundUserInfoInSessionException extends RuntimeException { public NotFoundUserInfoInSessionException(String message) { diff --git a/src/main/java/com/recordit/server/exception/member/NotMatchLoginTypeException.java b/src/main/java/com/recordit/server/exception/member/NotMatchLoginTypeException.java new file mode 100644 index 00000000..355c581f --- /dev/null +++ b/src/main/java/com/recordit/server/exception/member/NotMatchLoginTypeException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.member; + +public class NotMatchLoginTypeException extends RuntimeException { + public NotMatchLoginTypeException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java b/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java index f7b065cc..628602ad 100644 --- a/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java +++ b/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java @@ -5,6 +5,9 @@ import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; +import com.recordit.server.exception.member.NotEnteredLoginTypeException; +import com.recordit.server.exception.member.NotMatchLoginTypeException; + import lombok.RequiredArgsConstructor; @Component @@ -14,11 +17,11 @@ public class OauthServiceLocator { public OauthService getOauthServiceByLoginType(String loginType) { if (!StringUtils.hasText(loginType)) { - throw new NullPointerException("로그인 타입이 입력되지 않았습니다."); + throw new NotEnteredLoginTypeException("로그인 타입이 입력되지 않았습니다."); } return oauthServices.stream() .filter(oauthService -> oauthService.getLoginType().name().equals(loginType)) .findFirst() - .orElseThrow(() -> new NullPointerException("일치하는 로그인 타입이 없습니다.")); + .orElseThrow(() -> new NotMatchLoginTypeException("일치하는 로그인 타입이 없습니다.")); } } diff --git a/src/main/java/com/recordit/server/util/SessionUtil.java b/src/main/java/com/recordit/server/util/SessionUtil.java index 9f851d29..abb400a3 100644 --- a/src/main/java/com/recordit/server/util/SessionUtil.java +++ b/src/main/java/com/recordit/server/util/SessionUtil.java @@ -4,7 +4,7 @@ import org.springframework.stereotype.Component; -import com.recordit.server.exception.NotFoundUserInfoInSessionException; +import com.recordit.server.exception.member.NotFoundUserInfoInSessionException; import lombok.RequiredArgsConstructor; diff --git a/src/test/java/com/recordit/server/util/SessionUtilTest.java b/src/test/java/com/recordit/server/util/SessionUtilTest.java index 00d4160e..0999c0ac 100644 --- a/src/test/java/com/recordit/server/util/SessionUtilTest.java +++ b/src/test/java/com/recordit/server/util/SessionUtilTest.java @@ -11,7 +11,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.mock.web.MockHttpSession; -import com.recordit.server.exception.NotFoundUserInfoInSessionException; +import com.recordit.server.exception.member.NotFoundUserInfoInSessionException; @ExtendWith(MockitoExtension.class) public class SessionUtilTest { From fe1d4b00074b637d355365ad8e7e99887ea01e67 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 22 Dec 2022 16:10:08 +0900 Subject: [PATCH 070/264] =?UTF-8?q?[BE-60]=20fix:=20ErrorMessage=20?= =?UTF-8?q?=EC=A0=95=EC=A0=81=20=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/exception/ErrorMessage.java | 15 ++++++- .../member/MemberExceptionHandler.java | 39 ++++--------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/recordit/server/exception/ErrorMessage.java b/src/main/java/com/recordit/server/exception/ErrorMessage.java index ee448012..899b49c2 100644 --- a/src/main/java/com/recordit/server/exception/ErrorMessage.java +++ b/src/main/java/com/recordit/server/exception/ErrorMessage.java @@ -2,16 +2,27 @@ import java.time.LocalDateTime; +import org.springframework.http.HttpStatus; + import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; @Getter @AllArgsConstructor -@Builder public class ErrorMessage { private int code; private String errorSimpleName; private String msg; private LocalDateTime timestamp; + + public ErrorMessage(Exception exception, HttpStatus httpStatus) { + this.code = httpStatus.value(); + this.errorSimpleName = exception.getClass().getSimpleName(); + this.msg = exception.getLocalizedMessage(); + this.timestamp = LocalDateTime.now(); + } + + public static ErrorMessage of(Exception exception, HttpStatus httpStatus) { + return new ErrorMessage(exception, httpStatus); + } } \ No newline at end of file diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index b2a449bd..4536f6b5 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -1,7 +1,5 @@ package com.recordit.server.exception.member; -import java.time.LocalDateTime; - import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -15,47 +13,24 @@ @Slf4j @RestControllerAdvice(basePackageClasses = MemberController.class) public class MemberExceptionHandler { - private static String getSimpleName(Exception e) { - return e.getClass().getSimpleName(); - } @ExceptionHandler(NotFoundUserInfoInSessionException.class) - public ResponseEntity handleNotFoundUserInfoInSessionException(NotFoundUserInfoInSessionException e) { + public ResponseEntity handleNotFoundUserInfoInSessionException( + NotFoundUserInfoInSessionException exception) { return ResponseEntity.badRequest() - .body( - ErrorMessage.builder() - .code(HttpStatus.BAD_REQUEST.value()) - .msg(e.getLocalizedMessage()) - .errorSimpleName(getSimpleName(e)) - .timestamp(LocalDateTime.now()) - .build() - ); + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); } @ExceptionHandler(NotMatchLoginTypeException.class) - public ResponseEntity handleNotMatchLoginTypeException(NotMatchLoginTypeException e) { + public ResponseEntity handleNotMatchLoginTypeException(NotMatchLoginTypeException exception) { return ResponseEntity.badRequest() - .body( - ErrorMessage.builder() - .code(HttpStatus.BAD_REQUEST.value()) - .msg(e.getLocalizedMessage()) - .errorSimpleName(getSimpleName(e)) - .timestamp(LocalDateTime.now()) - .build() - ); + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); } @ExceptionHandler(NotEnteredLoginTypeException.class) - public ResponseEntity handleNotEnteredLoginTypeException(NotEnteredLoginTypeException e) { + public ResponseEntity handleNotEnteredLoginTypeException(NotEnteredLoginTypeException exception) { return ResponseEntity.badRequest() - .body( - ErrorMessage.builder() - .code(HttpStatus.BAD_REQUEST.value()) - .msg(e.getLocalizedMessage()) - .errorSimpleName(getSimpleName(e)) - .timestamp(LocalDateTime.now()) - .build() - ); + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); } } From a86942f7f51e56dad2c18d7efc97509e7479ea00 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 20:45:37 +0900 Subject: [PATCH 071/264] =?UTF-8?q?[BE-71]=20fix:=20@ApiResponse=EC=97=90?= =?UTF-8?q?=EC=84=9C=20response=EC=97=90=20DTO=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=A5=BC=20=EC=A7=80=EC=A0=95=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=98=A4=EC=9E=91=EB=8F=99=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=ED=95=B4=EB=8B=B9=20=ED=8C=8C=EC=9D=BC=EB=93=A4?= =?UTF-8?q?=EC=9D=84=20=EC=88=98=EC=A0=95=ED=95=B4=EC=84=9C=20=EA=B3=A0?= =?UTF-8?q?=EC=B9=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/configuration/SwaggerConfiguration.java | 2 +- src/main/resources/application-local.yml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java b/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java index c94b09f8..0910f210 100644 --- a/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/SwaggerConfiguration.java @@ -14,7 +14,7 @@ public class SwaggerConfiguration { @Bean public Docket api() { - return new Docket(DocumentationType.OAS_30) + return new Docket(DocumentationType.SWAGGER_2) .useDefaultResponseMessages(false) .select() .apis(RequestHandlerSelectors.basePackage("com.recordit")) diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index d9fb295a..2a22e698 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -22,3 +22,7 @@ spring: level: '[org.springframework.web]': DEBUG '[org.hibernate]': DEBUG +springfox: + documentation: + swagger: + use-model-v3: false \ No newline at end of file From 10dc5d2650e5fc81c120251b40d9d79b61df7ba5 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 21:45:00 +0900 Subject: [PATCH 072/264] =?UTF-8?q?[BE-71]=20feat:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8/=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/dto/member/LoginRequestDto.java | 22 +++++++++++++++ .../server/dto/member/RegisterRequestDto.java | 26 +++++++++++++++++ .../member/RegisterSessionResponseDto.java | 28 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/main/java/com/recordit/server/dto/member/LoginRequestDto.java create mode 100644 src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java create mode 100644 src/main/java/com/recordit/server/dto/member/RegisterSessionResponseDto.java diff --git a/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java b/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java new file mode 100644 index 00000000..75630616 --- /dev/null +++ b/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java @@ -0,0 +1,22 @@ +package com.recordit.server.dto.member; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class LoginRequestDto { + + @ApiModelProperty(notes = "Oauth API에서 응답 받은 토큰", required = true) + private String oauthToken; +} diff --git a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java new file mode 100644 index 00000000..54059bec --- /dev/null +++ b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java @@ -0,0 +1,26 @@ +package com.recordit.server.dto.member; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class RegisterRequestDto { + + @ApiModelProperty(notes = "회원가입시 필요한 임시 Session", required = true) + private String registerSession; + + @ApiModelProperty(notes = "사용자 닉네임", required = true) + private String nickname; + +} diff --git a/src/main/java/com/recordit/server/dto/member/RegisterSessionResponseDto.java b/src/main/java/com/recordit/server/dto/member/RegisterSessionResponseDto.java new file mode 100644 index 00000000..9a7de0fb --- /dev/null +++ b/src/main/java/com/recordit/server/dto/member/RegisterSessionResponseDto.java @@ -0,0 +1,28 @@ +package com.recordit.server.dto.member; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class RegisterSessionResponseDto { + + @ApiModelProperty(notes = "회원가입시 필요한 임시 Session", required = true) + private String registerSession; + + @Builder + public RegisterSessionResponseDto(String registerSession) { + this.registerSession = registerSession; + } +} From 5cef4899a0ddcd1900517cd14ef4ffdf49f4d8c1 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 21:45:39 +0900 Subject: [PATCH 073/264] =?UTF-8?q?[BE-71]=20refactor:=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8/=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20DTO=EB=A5=BC=20=EC=8A=A4=EC=9B=A8=EA=B1=B0?= =?UTF-8?q?=EC=97=90=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/MemberController.java | 63 ++++++++++++++----- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 7118fd12..6e5f3091 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -1,17 +1,24 @@ package com.recordit.server.controller; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.recordit.server.dto.member.LoginRequestDto; +import com.recordit.server.dto.member.RegisterRequestDto; +import com.recordit.server.dto.member.RegisterSessionResponseDto; import com.recordit.server.service.MemberService; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.ResponseHeader; import lombok.RequiredArgsConstructor; @RestController @@ -21,39 +28,63 @@ public class MemberController { private final MemberService memberService; - @ApiOperation(value = "로그인", - notes = "로그인 타입과 세션을 받아 가입된 회원이라면 로그인을 진행시키고 Header에 Set-cookie: SESSION=;응답합니다") + @ApiOperation( + value = "Oauth 로그인", + notes = "로그인 타입과 Oauth 토큰을 통해 Oauth 로그인을 진행합니다." + ) @ApiResponses({ - @ApiResponse(code = 200, message = "API 정상 작동 / Header에 Set-cookie: SESSION=;응답"), - @ApiResponse(code = 401, message = "회원정보가 없어 회원가입이 필요한 경우입니다." - + "Body로 응답된 register_session과 사용자에게 닉네임을 받아 '/member/oauth/register/{loginType}'으로 요청하세요") + @ApiResponse( + code = 200, message = "API 정상 작동 / Header에 세션 응답", + responseHeaders = { + @ResponseHeader(name = "Set-cookie: SESSION=FOO;", description = "FOO = 서버의 세션", response = String.class) + } + ), + @ApiResponse( + code = 401, message = "회원정보가 없어 회원가입이 필요한 경우입니다\t\n" + + "Body로 응답된 register_session과 사용자에게 닉네임을 받아 '/member/oauth/register/{loginType}'으로 요청하세요", + response = RegisterSessionResponseDto.class + ) }) @PostMapping("/oauth/login/{loginType}") - public void oauthLogin( - @PathVariable("loginType") String loginType, @RequestBody String token) { + public ResponseEntity oauthLogin( + @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") String loginType, + @RequestBody LoginRequestDto loginRequestDto + ) { memberService.oauthLogin(loginType); + return ResponseEntity.ok(null); } - @ApiOperation(value = "회원가입", - notes = "로그인 타입, register_session, 닉네임을 받아 회원가입을 진행합니다") + @ApiOperation( + value = "회원가입", + notes = "로그인 타입, register_session, 닉네임을 받아 회원가입을 진행합니다" + ) @ApiResponses({ - @ApiResponse(code = 200, message = "API 정상 작동 / 회원가입을 진행하고 세션 로그인 처리하고 Header에 Set-cookie: SESSION=; 헤더로 응답"), + @ApiResponse( + code = 200, message = "API 정상 작동 / Header에 세션 응답", + responseHeaders = { + @ResponseHeader(name = "Set-cookie: SESSION=FOO;", description = "FOO = 서버의 세션", response = String.class) + } + ), @ApiResponse(code = 428, message = "register_session 정보가 Redis에 없거나 비정상적일 경우"), @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") }) @PostMapping("/oauth/register/{loginType}") - public void oauthRegister(@PathVariable("loginType") String loginType, @RequestBody String nickname) { + public void oauthRegister( + @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") String loginType, + @RequestBody RegisterRequestDto registerRequestDto + ) { memberService.oauthRegister(loginType); } - @ApiOperation(value = "닉네임 중복확인", - notes = "닉네임을 받아 해당 닉네임이 중복되었는지 판별") + @ApiOperation( + value = "닉네임 중복확인", + notes = "닉네임을 받아 해당 닉네임이 중복되었는지 판별" + ) @ApiResponses({ @ApiResponse(code = 200, message = "닉네임이 사용 가능한 경우"), @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") }) - @GetMapping - public void duplicateNicknameCheck(@RequestBody String nickname) { - + @GetMapping("/nickname") + public void duplicateNicknameCheck(@RequestParam String nickname) { } } From ef046174a8fda240e6b87306561b1f7e75be2278 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 21:46:52 +0900 Subject: [PATCH 074/264] =?UTF-8?q?[BE-71]=20fix:=20@ApiResponse=EC=97=90?= =?UTF-8?q?=EC=84=9C=20response=EC=97=90=20DTO=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=A5=BC=20=EC=A7=80=EC=A0=95=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=98=A4=EC=9E=91=EB=8F=99=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=ED=95=B4=EB=8B=B9=20=ED=8C=8C=EC=9D=BC=EB=93=A4?= =?UTF-8?q?=EC=9D=84=20=EC=88=98=EC=A0=95=ED=95=B4=EC=84=9C=20=EA=B3=A0?= =?UTF-8?q?=EC=B9=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 4 ++++ src/test/resources/application-test.yml | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 3d1367b6..77621018 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -22,3 +22,7 @@ spring: level: '[org.springframework.web]': DEBUG '[org.hibernate]': DEBUG +springfox: + documentation: + swagger: + use-model-v3: false \ No newline at end of file diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index dc3202bc..4d4392be 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -20,4 +20,8 @@ spring: port: 63790 password: session: - store-type: redis \ No newline at end of file + store-type: redis +springfox: + documentation: + swagger: + use-model-v3: false \ No newline at end of file From 671bc2f93694f3211e69d437fe8cac934d10c212 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 22:30:59 +0900 Subject: [PATCH 075/264] =?UTF-8?q?[BE-29]=20refactor:=20MemberController,?= =?UTF-8?q?=20MemberService=EC=9D=98=20arguments=EC=99=80=20return=20type?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/MemberController.java | 13 ++++++++----- .../com/recordit/server/service/MemberService.java | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 6e5f3091..59d68999 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -1,5 +1,6 @@ package com.recordit.server.controller; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -50,8 +51,7 @@ public ResponseEntity oauthLogin( @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") String loginType, @RequestBody LoginRequestDto loginRequestDto ) { - memberService.oauthLogin(loginType); - return ResponseEntity.ok(null); + return new ResponseEntity(memberService.oauthLogin(loginType, loginRequestDto), HttpStatus.UNAUTHORIZED); } @ApiOperation( @@ -69,11 +69,12 @@ public ResponseEntity oauthLogin( @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") }) @PostMapping("/oauth/register/{loginType}") - public void oauthRegister( + public ResponseEntity oauthRegister( @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") String loginType, @RequestBody RegisterRequestDto registerRequestDto ) { - memberService.oauthRegister(loginType); + memberService.oauthRegister(loginType, registerRequestDto); + return new ResponseEntity(HttpStatus.OK); } @ApiOperation( @@ -85,6 +86,8 @@ public void oauthRegister( @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") }) @GetMapping("/nickname") - public void duplicateNicknameCheck(@RequestParam String nickname) { + public ResponseEntity duplicateNicknameCheck(@RequestParam String nickname) { + memberService.isDuplicateNickname(nickname); + return new ResponseEntity(HttpStatus.OK); } } diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index 17157d31..5bee9780 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -3,6 +3,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.recordit.server.dto.member.LoginRequestDto; +import com.recordit.server.dto.member.RegisterRequestDto; +import com.recordit.server.dto.member.RegisterSessionResponseDto; +import com.recordit.server.repository.MemberRepository; import com.recordit.server.service.oauth.OauthService; import com.recordit.server.service.oauth.OauthServiceLocator; @@ -12,14 +16,20 @@ @RequiredArgsConstructor public class MemberService { private final OauthServiceLocator oauthServiceLocator; + private final MemberRepository memberRepository; @Transactional - public void oauthLogin(String loginType) { + public RegisterSessionResponseDto oauthLogin(String loginType, LoginRequestDto loginRequestDto) { OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType); + return null; } @Transactional - public void oauthRegister(String loginType) { + public void oauthRegister(String loginType, RegisterRequestDto registerRequestDto) { OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType); } + + @Transactional(readOnly = true) + public void isDuplicateNickname(String nickname) { + } } From b3999dea9fcd71b88b6254756baab227aa2104e2 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 22:31:11 +0900 Subject: [PATCH 076/264] =?UTF-8?q?[BE-29]=20feat:=20MemberRepository=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/repository/MemberRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/com/recordit/server/repository/MemberRepository.java diff --git a/src/main/java/com/recordit/server/repository/MemberRepository.java b/src/main/java/com/recordit/server/repository/MemberRepository.java new file mode 100644 index 00000000..758fab7f --- /dev/null +++ b/src/main/java/com/recordit/server/repository/MemberRepository.java @@ -0,0 +1,10 @@ +package com.recordit.server.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.recordit.server.domain.Member; + +public interface MemberRepository extends JpaRepository { + + boolean existsByNickname(String nickname); +} From 1ce3d8462e3f948d5ca2914e055da4e32cd730da Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 22:36:25 +0900 Subject: [PATCH 077/264] =?UTF-8?q?[BE-29]=20feat:=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EC=A4=91=EB=B3=B5=20=ED=99=95=EC=9D=B8=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=EA=B3=BC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/DuplicateNicknameException.java | 7 +++ .../member/MemberExceptionHandler.java | 6 ++ .../server/service/MemberService.java | 4 ++ .../server/service/MemberServiceTest.java | 62 +++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/member/DuplicateNicknameException.java create mode 100644 src/test/java/com/recordit/server/service/MemberServiceTest.java diff --git a/src/main/java/com/recordit/server/exception/member/DuplicateNicknameException.java b/src/main/java/com/recordit/server/exception/member/DuplicateNicknameException.java new file mode 100644 index 00000000..d3d24718 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/member/DuplicateNicknameException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.member; + +public class DuplicateNicknameException extends RuntimeException { + public DuplicateNicknameException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index 4536f6b5..c9db95ad 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -32,5 +32,11 @@ public ResponseEntity handleNotEnteredLoginTypeException(NotEntere return ResponseEntity.badRequest() .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); } + + @ExceptionHandler(DuplicateNicknameException.class) + public ResponseEntity handleDuplicateNicknameException(DuplicateNicknameException exception) { + return ResponseEntity.status(HttpStatus.CONFLICT) + .body(ErrorMessage.of(exception, HttpStatus.CONFLICT)); + } } diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index 5bee9780..49e3e4f2 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -6,6 +6,7 @@ import com.recordit.server.dto.member.LoginRequestDto; import com.recordit.server.dto.member.RegisterRequestDto; import com.recordit.server.dto.member.RegisterSessionResponseDto; +import com.recordit.server.exception.member.DuplicateNicknameException; import com.recordit.server.repository.MemberRepository; import com.recordit.server.service.oauth.OauthService; import com.recordit.server.service.oauth.OauthServiceLocator; @@ -31,5 +32,8 @@ public void oauthRegister(String loginType, RegisterRequestDto registerRequestDt @Transactional(readOnly = true) public void isDuplicateNickname(String nickname) { + if (memberRepository.existsByNickname(nickname)) { + throw new DuplicateNicknameException("중복된 닉네임이 존재합니다."); + } } } diff --git a/src/test/java/com/recordit/server/service/MemberServiceTest.java b/src/test/java/com/recordit/server/service/MemberServiceTest.java new file mode 100644 index 00000000..e1120e40 --- /dev/null +++ b/src/test/java/com/recordit/server/service/MemberServiceTest.java @@ -0,0 +1,62 @@ +package com.recordit.server.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.recordit.server.exception.member.DuplicateNicknameException; +import com.recordit.server.repository.MemberRepository; +import com.recordit.server.service.oauth.OauthServiceLocator; + +@ExtendWith(MockitoExtension.class) +public class MemberServiceTest { + + @InjectMocks + private MemberService memberService; + + @Mock + private OauthServiceLocator oauthServiceLocator; + + @Mock + private MemberRepository memberRepository; + + @Nested + @DisplayName("닉네임 중복 확인 기능에서 닉네임이") + class 닉네임_중복_확인_기능에서_닉네임이 { + + @Test + @DisplayName("중복되면 예외를 던진다") + void 중복되면_예외를_던진다() { + // given + String nickname = "test"; + + given(memberRepository.existsByNickname(anyString())) + .willReturn(true); + + // when, then + assertThatThrownBy(() -> memberService.isDuplicateNickname(nickname)) + .isInstanceOf(DuplicateNicknameException.class); + } + + @Test + @DisplayName("중복되지 않으면 예외를 던지지 않는다") + void 중복되지_않으면_예외를_던지지_않는다() { + // given + String nickname = "test"; + + given(memberRepository.existsByNickname(anyString())) + .willReturn(false); + + // when, then + assertThatCode(() -> memberService.isDuplicateNickname(nickname)) + .doesNotThrowAnyException(); + } + } +} From e661290ea44b8530d9b658052fa2a2034e82d88a Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 23:06:44 +0900 Subject: [PATCH 078/264] =?UTF-8?q?[BE-29]=20refactor:=20oauthId=EB=A5=BC?= =?UTF-8?q?=20=EB=B0=9B=EC=95=84=EC=98=A4=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?retun=20type=EC=9D=84=20String=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/service/oauth/GoogleOauthService.java | 4 ++-- .../com/recordit/server/service/oauth/KakaoOauthService.java | 4 ++-- .../java/com/recordit/server/service/oauth/OauthService.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java index 58ce11e1..111c0cfd 100644 --- a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java @@ -12,7 +12,7 @@ public LoginType getLoginType() { } @Override - public void request() { - + public String request() { + return null; } } diff --git a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java index 293c832d..39784446 100644 --- a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java @@ -12,7 +12,7 @@ public LoginType getLoginType() { } @Override - public void request() { - + public String request() { + return null; } } diff --git a/src/main/java/com/recordit/server/service/oauth/OauthService.java b/src/main/java/com/recordit/server/service/oauth/OauthService.java index 92f71480..17be0826 100644 --- a/src/main/java/com/recordit/server/service/oauth/OauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/OauthService.java @@ -6,5 +6,5 @@ public interface OauthService { LoginType getLoginType(); - void request(); + String request(); } From b60b6a8952be186e03345f8938d6c26bcd01a1cc Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 23:07:17 +0900 Subject: [PATCH 079/264] =?UTF-8?q?[BE-29]=20fix:=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EC=99=80=20of=20=EB=A9=94=EC=86=8C=EB=93=9C=EC=97=90?= =?UTF-8?q?=20=EB=88=84=EB=9D=BD=EB=90=9C=20username=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/Member.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/Member.java b/src/main/java/com/recordit/server/domain/Member.java index 76871bb2..fd4cfc20 100644 --- a/src/main/java/com/recordit/server/domain/Member.java +++ b/src/main/java/com/recordit/server/domain/Member.java @@ -45,14 +45,14 @@ public class Member extends BaseEntity { @Enumerated(value = EnumType.STRING) private LoginType loginType; - private Member(String password, String nickname, String oauthId, LoginType loginType) { + private Member(String username, String password, String nickname, String oauthId, LoginType loginType) { this.password = password; this.nickname = nickname; this.oauthId = oauthId; this.loginType = loginType; } - public static Member of(String password, String nickname, String oauthId, LoginType loginType) { - return new Member(password, nickname, oauthId, loginType); + public static Member of(String username, String password, String nickname, String oauthId, LoginType loginType) { + return new Member(username, password, nickname, oauthId, loginType); } } From d6ae994f40a36c22fd2d766955b6539394e7e29d Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 23:08:11 +0900 Subject: [PATCH 080/264] =?UTF-8?q?[BE-29]=20feat:=20MemberRepository?= =?UTF-8?q?=EC=97=90=20oauthId=EB=A1=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EB=A5=BC=20=EC=B0=BE=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/repository/MemberRepository.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/recordit/server/repository/MemberRepository.java b/src/main/java/com/recordit/server/repository/MemberRepository.java index 758fab7f..236705b8 100644 --- a/src/main/java/com/recordit/server/repository/MemberRepository.java +++ b/src/main/java/com/recordit/server/repository/MemberRepository.java @@ -1,10 +1,14 @@ package com.recordit.server.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import com.recordit.server.domain.Member; public interface MemberRepository extends JpaRepository { + Optional findByOauthId(String oauthId); + boolean existsByNickname(String nickname); } From a033b26dbd4f0c56492113176f2e694228975fac Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 23:16:39 +0900 Subject: [PATCH 081/264] =?UTF-8?q?[BE-29]=20feat:=20RegisterSession?= =?UTF-8?q?=EC=9D=B4=20=EC=97=86=EA=B1=B0=EB=82=98=20=EB=B9=84=EC=A0=95?= =?UTF-8?q?=EC=83=81=EC=A0=81=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=EC=97=90=20?= =?UTF-8?q?=EB=8C=80=ED=95=9C=20=EC=98=88=EC=99=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/exception/member/MemberExceptionHandler.java | 7 +++++++ .../exception/member/NotFoundRegisterSessionException.java | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/member/NotFoundRegisterSessionException.java diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index c9db95ad..2da5782f 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -38,5 +38,12 @@ public ResponseEntity handleDuplicateNicknameException(DuplicateNi return ResponseEntity.status(HttpStatus.CONFLICT) .body(ErrorMessage.of(exception, HttpStatus.CONFLICT)); } + + @ExceptionHandler(NotFoundRegisterSessionException.class) + public ResponseEntity handleNotFoundRegisterSessionException( + NotFoundRegisterSessionException exception) { + return ResponseEntity.status(HttpStatus.PRECONDITION_REQUIRED) + .body(ErrorMessage.of(exception, HttpStatus.PRECONDITION_REQUIRED)); + } } diff --git a/src/main/java/com/recordit/server/exception/member/NotFoundRegisterSessionException.java b/src/main/java/com/recordit/server/exception/member/NotFoundRegisterSessionException.java new file mode 100644 index 00000000..a7ee0953 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/member/NotFoundRegisterSessionException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.member; + +public class NotFoundRegisterSessionException extends RuntimeException { + public NotFoundRegisterSessionException(String message) { + super(message); + } +} From efefc22cada65b5b987df12ad46752684bf543cb Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 23:17:17 +0900 Subject: [PATCH 082/264] =?UTF-8?q?[BE-29]=20feat:=20RegisterSession=20?= =?UTF-8?q?=EC=A0=95=EC=9D=98=EC=97=90=20=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EC=83=81=EC=88=98=EB=A5=BC=20=EA=B0=96=EB=8A=94=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/constant/RegisterSessionConstants.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/com/recordit/server/constant/RegisterSessionConstants.java diff --git a/src/main/java/com/recordit/server/constant/RegisterSessionConstants.java b/src/main/java/com/recordit/server/constant/RegisterSessionConstants.java new file mode 100644 index 00000000..ad4c70b1 --- /dev/null +++ b/src/main/java/com/recordit/server/constant/RegisterSessionConstants.java @@ -0,0 +1,6 @@ +package com.recordit.server.constant; + +public class RegisterSessionConstants { + public static final String PREFIX_REGISTER_SESSION = "REGISTER_SESSION="; + public static final long TIMEOUT = 30; +} From 88d00899ffcd840b592bf52f1a96e2145e46156a Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 23:21:28 +0900 Subject: [PATCH 083/264] =?UTF-8?q?[BE-29]=20refactor:=20request=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=EC=97=90=20argument=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/service/oauth/GoogleOauthService.java | 2 +- .../com/recordit/server/service/oauth/KakaoOauthService.java | 2 +- .../java/com/recordit/server/service/oauth/OauthService.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java index 111c0cfd..1efd60af 100644 --- a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java @@ -12,7 +12,7 @@ public LoginType getLoginType() { } @Override - public String request() { + public String request(String oauthToken) { return null; } } diff --git a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java index 39784446..8cf4ce22 100644 --- a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java @@ -12,7 +12,7 @@ public LoginType getLoginType() { } @Override - public String request() { + public String request(String oauthToken) { return null; } } diff --git a/src/main/java/com/recordit/server/service/oauth/OauthService.java b/src/main/java/com/recordit/server/service/oauth/OauthService.java index 17be0826..2bd1068d 100644 --- a/src/main/java/com/recordit/server/service/oauth/OauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/OauthService.java @@ -6,5 +6,5 @@ public interface OauthService { LoginType getLoginType(); - String request(); + String request(String oauthToken); } From a1fa9991bfc1d1769977305e2231199ab379ab62 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 23:25:25 +0900 Subject: [PATCH 084/264] =?UTF-8?q?[BE-29]=20refactor:=20MemberController?= =?UTF-8?q?=EC=97=90=20oauthLogin=EA=B3=BC=20oauthRegister=EC=97=90=20Logi?= =?UTF-8?q?nType=EC=9D=B4=20=EB=B9=84=EC=A0=95=EC=83=81=EC=A0=81=EC=9D=BC?= =?UTF-8?q?=20=EA=B2=BD=EC=9A=B0=20400=20=EB=B0=98=ED=99=98=EC=9D=84=20?= =?UTF-8?q?=EB=AA=85=EC=84=B8=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/controller/MemberController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 59d68999..e13c8b64 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -40,6 +40,9 @@ public class MemberController { @ResponseHeader(name = "Set-cookie: SESSION=FOO;", description = "FOO = 서버의 세션", response = String.class) } ), + @ApiResponse( + code = 400, message = "API에서 지정한 LoginType이 아닐 경우입니다" + ), @ApiResponse( code = 401, message = "회원정보가 없어 회원가입이 필요한 경우입니다\t\n" + "Body로 응답된 register_session과 사용자에게 닉네임을 받아 '/member/oauth/register/{loginType}'으로 요청하세요", @@ -65,6 +68,9 @@ public ResponseEntity oauthLogin( @ResponseHeader(name = "Set-cookie: SESSION=FOO;", description = "FOO = 서버의 세션", response = String.class) } ), + @ApiResponse( + code = 400, message = "API에서 지정한 LoginType이 아닐 경우입니다" + ), @ApiResponse(code = 428, message = "register_session 정보가 Redis에 없거나 비정상적일 경우"), @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") }) From 5808bbc1f8900dcdce7e17bdfffaa241eeb280b9 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 22 Dec 2022 23:27:50 +0900 Subject: [PATCH 085/264] =?UTF-8?q?[BE-29]=20test:=20MemberService?= =?UTF-8?q?=EC=9D=98=20=EB=B3=80=ED=99=94=EB=A1=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=EC=97=90=EB=8F=84=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/service/MemberServiceTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/com/recordit/server/service/MemberServiceTest.java b/src/test/java/com/recordit/server/service/MemberServiceTest.java index e1120e40..b5b26d6d 100644 --- a/src/test/java/com/recordit/server/service/MemberServiceTest.java +++ b/src/test/java/com/recordit/server/service/MemberServiceTest.java @@ -14,6 +14,8 @@ import com.recordit.server.exception.member.DuplicateNicknameException; import com.recordit.server.repository.MemberRepository; import com.recordit.server.service.oauth.OauthServiceLocator; +import com.recordit.server.util.RedisManager; +import com.recordit.server.util.SessionUtil; @ExtendWith(MockitoExtension.class) public class MemberServiceTest { @@ -27,6 +29,12 @@ public class MemberServiceTest { @Mock private MemberRepository memberRepository; + @Mock + private SessionUtil sessionUtil; + + @Mock + RedisManager redisManager; + @Nested @DisplayName("닉네임 중복 확인 기능에서 닉네임이") class 닉네임_중복_확인_기능에서_닉네임이 { From ae10886dad0aefd386f448463108dc9d62848e90 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 00:39:36 +0900 Subject: [PATCH 086/264] =?UTF-8?q?[BE-29]=20build:=20staticMock=EC=9D=84?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=B4=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index dd557aa9..22fe0f98 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,9 @@ dependencies { runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' + + // use static mock + testImplementation 'org.mockito:mockito-inline:4.5.1' } tasks.named('test') { From 6f2837aad45d363933b572a2ea9f9ddbe3f9c365 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 00:52:04 +0900 Subject: [PATCH 087/264] =?UTF-8?q?[BE-29]=20feat:=20DTO=EC=97=90=20Builde?= =?UTF-8?q?r=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/dto/member/LoginRequestDto.java | 6 ++++++ .../com/recordit/server/dto/member/RegisterRequestDto.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java b/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java index 75630616..22542fc3 100644 --- a/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java +++ b/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java @@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; @@ -19,4 +20,9 @@ public class LoginRequestDto { @ApiModelProperty(notes = "Oauth API에서 응답 받은 토큰", required = true) private String oauthToken; + + @Builder + public LoginRequestDto(String oauthToken) { + this.oauthToken = oauthToken; + } } diff --git a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java index 54059bec..9e794089 100644 --- a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java +++ b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java @@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; @@ -23,4 +24,9 @@ public class RegisterRequestDto { @ApiModelProperty(notes = "사용자 닉네임", required = true) private String nickname; + @Builder + public RegisterRequestDto(String registerSession, String nickname) { + this.registerSession = registerSession; + this.nickname = nickname; + } } From 0531458d4e64bc13fad772cb9897c149d3194566 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 13:08:33 +0900 Subject: [PATCH 088/264] =?UTF-8?q?[BE-29]=20feat:=20RedisExceptionHandler?= =?UTF-8?q?=EC=99=80=20Parsing=20=EC=98=88=EC=99=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../redis/RedisExceptionHandler.java | 24 +++++++++++++++++++ .../redis/RedisParsingException.java | 7 ++++++ 2 files changed, 31 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java create mode 100644 src/main/java/com/recordit/server/exception/redis/RedisParsingException.java diff --git a/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java b/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java new file mode 100644 index 00000000..bb7dc148 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java @@ -0,0 +1,24 @@ +package com.recordit.server.exception.redis; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import com.recordit.server.exception.ErrorMessage; +import com.recordit.server.exception.member.NotFoundUserInfoInSessionException; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestControllerAdvice +public class RedisExceptionHandler { + + @ExceptionHandler(RedisParsingException.class) + public ResponseEntity handleRedisParsingException( + NotFoundUserInfoInSessionException exception) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(ErrorMessage.of(exception, HttpStatus.INTERNAL_SERVER_ERROR)); + } + +} diff --git a/src/main/java/com/recordit/server/exception/redis/RedisParsingException.java b/src/main/java/com/recordit/server/exception/redis/RedisParsingException.java new file mode 100644 index 00000000..03d5a7d2 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/redis/RedisParsingException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.redis; + +public class RedisParsingException extends RuntimeException { + public RedisParsingException(String message) { + super(message); + } +} From b67879fd5f5ab233b058ecb5e9e38f701ec414e2 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 13:14:17 +0900 Subject: [PATCH 089/264] =?UTF-8?q?[BE-29]=20feat:=20RedisConfiguration?= =?UTF-8?q?=EC=9D=98=20RedisTemplate=EB=A5=BC=20StringRedisTemplate?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20RedisManager=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/RedisConfiguration.java | 9 ++-- .../recordit/server/util/RedisManager.java | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/recordit/server/util/RedisManager.java diff --git a/src/main/java/com/recordit/server/configuration/RedisConfiguration.java b/src/main/java/com/recordit/server/configuration/RedisConfiguration.java index b1e9997d..143402c9 100644 --- a/src/main/java/com/recordit/server/configuration/RedisConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/RedisConfiguration.java @@ -6,8 +6,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.StringRedisSerializer; @Configuration @@ -37,10 +36,10 @@ public RedisConnectionFactory redisConnectionFactory() { } @Bean - public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { - RedisTemplate redisTemplate = new RedisTemplate<>(); + public StringRedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { + StringRedisTemplate redisTemplate = new StringRedisTemplate(); redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); + redisTemplate.setValueSerializer(new StringRedisSerializer()); redisTemplate.setConnectionFactory(redisConnectionFactory); return redisTemplate; } diff --git a/src/main/java/com/recordit/server/util/RedisManager.java b/src/main/java/com/recordit/server/util/RedisManager.java new file mode 100644 index 00000000..4f9844a9 --- /dev/null +++ b/src/main/java/com/recordit/server/util/RedisManager.java @@ -0,0 +1,52 @@ +package com.recordit.server.util; + +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.recordit.server.exception.redis.RedisParsingException; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class RedisManager { + + private static final String REDIS_PARSING_ERROR_MESSAGE = "Redis에서 Json을 파싱할 때 에러가 발생했습니다."; + private final StringRedisTemplate stringRedisTemplate; + private final ObjectMapper objectMapper; + + public void set(@NonNull String key, @NonNull Object value) { + try { + stringRedisTemplate.opsForValue().set(key, objectMapper.writeValueAsString(value)); + } catch (JsonProcessingException e) { + throw new RedisParsingException(REDIS_PARSING_ERROR_MESSAGE); + } + } + + public void set(@NonNull String key, @NonNull Object value, long timeout, @NonNull TimeUnit timeUnit) { + try { + stringRedisTemplate.opsForValue().set(key, objectMapper.writeValueAsString(value), timeout, timeUnit); + } catch (JsonProcessingException e) { + throw new RedisParsingException(REDIS_PARSING_ERROR_MESSAGE); + } + } + + public Optional get(@NonNull String key, Class clazz) { + String jsonString = stringRedisTemplate.opsForValue().get(key); + if (!StringUtils.hasText(jsonString)) { + return Optional.empty(); + } + try { + return Optional.of(objectMapper.readValue(jsonString, clazz)); + } catch (JsonProcessingException e) { + throw new RedisParsingException(REDIS_PARSING_ERROR_MESSAGE); + } + } +} From 7e149c90836da6a8873142663dca45cde0d7f3f0 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 13:21:32 +0900 Subject: [PATCH 090/264] =?UTF-8?q?[BE-29]=20feat:=20MemberService.oauthLo?= =?UTF-8?q?gin,=20MemberService.oauthRegister=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/MemberController.java | 13 +- .../server/service/MemberService.java | 48 +++++- .../server/service/MemberServiceTest.java | 159 +++++++++++++++++- 3 files changed, 210 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index e13c8b64..33750c29 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -1,5 +1,7 @@ package com.recordit.server.controller; +import java.util.Optional; + import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -54,7 +56,15 @@ public ResponseEntity oauthLogin( @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") String loginType, @RequestBody LoginRequestDto loginRequestDto ) { - return new ResponseEntity(memberService.oauthLogin(loginType, loginRequestDto), HttpStatus.UNAUTHORIZED); + + Optional registerSessionResponseDto = memberService.oauthLogin( + loginType, + loginRequestDto + ); + if (registerSessionResponseDto.isEmpty()) { + return ResponseEntity.ok().build(); + } + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(registerSessionResponseDto.get()); } @ApiOperation( @@ -96,4 +106,5 @@ public ResponseEntity duplicateNicknameCheck(@RequestParam String nickname) { memberService.isDuplicateNickname(nickname); return new ResponseEntity(HttpStatus.OK); } + } diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index 49e3e4f2..799d903c 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -1,15 +1,26 @@ package com.recordit.server.service; +import static com.recordit.server.constant.RegisterSessionConstants.*; + +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.recordit.server.constant.LoginType; +import com.recordit.server.domain.Member; import com.recordit.server.dto.member.LoginRequestDto; import com.recordit.server.dto.member.RegisterRequestDto; import com.recordit.server.dto.member.RegisterSessionResponseDto; import com.recordit.server.exception.member.DuplicateNicknameException; +import com.recordit.server.exception.member.NotFoundRegisterSessionException; import com.recordit.server.repository.MemberRepository; import com.recordit.server.service.oauth.OauthService; import com.recordit.server.service.oauth.OauthServiceLocator; +import com.recordit.server.util.RedisManager; +import com.recordit.server.util.SessionUtil; import lombok.RequiredArgsConstructor; @@ -18,16 +29,47 @@ public class MemberService { private final OauthServiceLocator oauthServiceLocator; private final MemberRepository memberRepository; + private final SessionUtil sessionUtil; + private final RedisManager redisManager; @Transactional - public RegisterSessionResponseDto oauthLogin(String loginType, LoginRequestDto loginRequestDto) { + public Optional oauthLogin(String loginType, LoginRequestDto loginRequestDto) { OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType); - return null; + + String oauthId = oauthService.request(loginRequestDto.getOauthToken()); + Optional findMember = memberRepository.findByOauthId(oauthId); + + if (findMember.isPresent()) { + sessionUtil.saveUserIdInSession(findMember.get().getId()); + return Optional.empty(); + } + String registerSessionUUID = UUID.randomUUID().toString(); + redisManager.set(PREFIX_REGISTER_SESSION + registerSessionUUID, oauthId, TIMEOUT, TimeUnit.MINUTES); + return Optional.of(RegisterSessionResponseDto.builder() + .registerSession(registerSessionUUID) + .build()); } @Transactional public void oauthRegister(String loginType, RegisterRequestDto registerRequestDto) { - OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType); + Optional oauthId = redisManager.get( + PREFIX_REGISTER_SESSION + registerRequestDto.getRegisterSession(), + String.class); + if (oauthId.isEmpty()) { + throw new NotFoundRegisterSessionException("Oauth 회원가입을 위한 register_session이 존재하지 않습니다."); + } + + isDuplicateNickname(registerRequestDto.getNickname()); + Member saveMember = memberRepository.save( + Member.of( + null, + null, + registerRequestDto.getNickname(), + oauthId.get(), + LoginType.findByString(loginType) + ) + ); + sessionUtil.saveUserIdInSession(saveMember.getId()); } @Transactional(readOnly = true) diff --git a/src/test/java/com/recordit/server/service/MemberServiceTest.java b/src/test/java/com/recordit/server/service/MemberServiceTest.java index b5b26d6d..6595e6ae 100644 --- a/src/test/java/com/recordit/server/service/MemberServiceTest.java +++ b/src/test/java/com/recordit/server/service/MemberServiceTest.java @@ -3,16 +3,30 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; +import java.util.Arrays; +import java.util.Optional; +import java.util.UUID; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.MockedStatic; import org.mockito.junit.jupiter.MockitoExtension; +import com.recordit.server.constant.LoginType; +import com.recordit.server.domain.Member; +import com.recordit.server.dto.member.LoginRequestDto; +import com.recordit.server.dto.member.RegisterRequestDto; +import com.recordit.server.dto.member.RegisterSessionResponseDto; import com.recordit.server.exception.member.DuplicateNicknameException; +import com.recordit.server.exception.member.NotFoundRegisterSessionException; import com.recordit.server.repository.MemberRepository; +import com.recordit.server.service.oauth.OauthService; import com.recordit.server.service.oauth.OauthServiceLocator; import com.recordit.server.util.RedisManager; import com.recordit.server.util.SessionUtil; @@ -33,18 +47,153 @@ public class MemberServiceTest { private SessionUtil sessionUtil; @Mock - RedisManager redisManager; + private RedisManager redisManager; + + @Mock + private Member mockMember; + + private MockedStatic mockUUID; + + private final String loginType = Arrays.stream(LoginType.values()) + .findFirst() + .get().name(); + + private final UUID testUUID = UUID.randomUUID(); + + private final String mockOauthId = "testOauthId"; + private final String nickname = "testNickname"; + + @BeforeEach + void init() { + mockUUID = mockStatic(UUID.class); + } + + @AfterEach + void afterEach() { + mockUUID.close(); + } @Nested - @DisplayName("닉네임 중복 확인 기능에서 닉네임이") + @DisplayName("oauth 로그인을 할 때") + class oauth_로그인을_할_때_oauthToken을_통해_찾은_사용자가 { + + @Nested + @DisplayName("oauthToken을 통해 찾은 사용자가") + class oauthToken을_통해_찾은_사용자가 { + + @Mock + private OauthService oauthService; + + private final String mockOauthToken = "testOauthToken"; + + private final LoginRequestDto loginRequestDto = LoginRequestDto.builder() + .oauthToken(mockOauthToken) + .build(); + + @Test + @DisplayName("있으면 null을 반환한다") + void 있으면_null을_반환한다() { + // given + Optional mockMember = Optional.of(MemberServiceTest.this.mockMember); + + given(oauthServiceLocator.getOauthServiceByLoginType(anyString())) + .willReturn(oauthService); + given(oauthService.request(anyString())) + .willReturn(mockOauthId); + given(memberRepository.findByOauthId(mockOauthId)) + .willReturn(mockMember); + + // when + Optional result = memberService.oauthLogin( + loginType, + loginRequestDto + ); + + // then + assertThat(result.isEmpty()).isTrue(); + } + + @Test + @DisplayName("없으면 registerSessionUUID를 반환한다") + void 없으면_registerSessionUUID를_반환한다() { + // given + given(oauthServiceLocator.getOauthServiceByLoginType(anyString())) + .willReturn(oauthService); + given(oauthService.request(anyString())) + .willReturn(mockOauthId); + given(memberRepository.findByOauthId(mockOauthId)) + .willReturn(Optional.empty()); + given(UUID.randomUUID()) + .willReturn(testUUID); + + // when + Optional result = memberService.oauthLogin( + loginType, + loginRequestDto + ); + + // then + assertThat(result.isPresent()).isTrue(); + assertThat(result.get().getRegisterSession()).isEqualTo(testUUID.toString()); + } + } + } + + @Nested + @DisplayName("oauth 회원가입을 할 때") + class oauth_회원가입을_할_때 { + + @Nested + @DisplayName("Redis에 RegisterSession이") + class Redis에_RegisterSession이 { + + private RegisterRequestDto registerRequestDto = RegisterRequestDto.builder() + .registerSession(testUUID.toString()) + .nickname(nickname) + .build(); + + @Test + @DisplayName("없으면 예외를 던진다") + void 없으면_예외를_던진다() { + // given + given(redisManager.get(anyString(), any())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> memberService.oauthRegister( + loginType, + registerRequestDto + )).isInstanceOf(NotFoundRegisterSessionException.class); + + } + + @Test + @DisplayName("있으면 예외를 던지지 않는다") + void 있으면_예외를_던지지_않는다() { + // given + given(redisManager.get(anyString(), any())) + .willReturn(Optional.of(mockOauthId)); + given(memberRepository.existsByNickname(anyString())) + .willReturn(false); + given(memberRepository.save(any())).willReturn(mockMember); + willDoNothing().given(sessionUtil).saveUserIdInSession(anyLong()); + + // when, then + assertThatCode(() -> memberService.oauthRegister(loginType, registerRequestDto)) + .doesNotThrowAnyException(); + } + + } + } + + @Nested + @DisplayName("닉네임 중복 확인 기능에서") class 닉네임_중복_확인_기능에서_닉네임이 { @Test @DisplayName("중복되면 예외를 던진다") void 중복되면_예외를_던진다() { // given - String nickname = "test"; - given(memberRepository.existsByNickname(anyString())) .willReturn(true); @@ -57,8 +206,6 @@ class 닉네임_중복_확인_기능에서_닉네임이 { @DisplayName("중복되지 않으면 예외를 던지지 않는다") void 중복되지_않으면_예외를_던지지_않는다() { // given - String nickname = "test"; - given(memberRepository.existsByNickname(anyString())) .willReturn(false); From 1bf6e35b4c065bd884d332ca40b7ab4503fb6898 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 15:02:18 +0900 Subject: [PATCH 091/264] =?UTF-8?q?[BE-29]=20fix:=20Member=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=EC=97=90=20username=20=EB=88=84=EB=9D=BD?= =?UTF-8?q?=EB=90=9C=20=EA=B2=83=20=EC=88=98=EC=A0=95,=20RedisExceptionHan?= =?UTF-8?q?dler=20Parsing=20=EC=98=88=EC=99=B8=20Argument=EB=A5=BC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/Member.java | 1 + .../server/exception/redis/RedisExceptionHandler.java | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/Member.java b/src/main/java/com/recordit/server/domain/Member.java index fd4cfc20..cd85a87a 100644 --- a/src/main/java/com/recordit/server/domain/Member.java +++ b/src/main/java/com/recordit/server/domain/Member.java @@ -46,6 +46,7 @@ public class Member extends BaseEntity { private LoginType loginType; private Member(String username, String password, String nickname, String oauthId, LoginType loginType) { + this.username = username; this.password = password; this.nickname = nickname; this.oauthId = oauthId; diff --git a/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java b/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java index bb7dc148..5b167160 100644 --- a/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java @@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import com.recordit.server.exception.ErrorMessage; -import com.recordit.server.exception.member.NotFoundUserInfoInSessionException; import lombok.extern.slf4j.Slf4j; @@ -15,8 +14,7 @@ public class RedisExceptionHandler { @ExceptionHandler(RedisParsingException.class) - public ResponseEntity handleRedisParsingException( - NotFoundUserInfoInSessionException exception) { + public ResponseEntity handleRedisParsingException(RedisParsingException exception) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(ErrorMessage.of(exception, HttpStatus.INTERNAL_SERVER_ERROR)); } From 7b1a24bdc91192f622677d7bc9e72d61e39703e0 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 15:03:47 +0900 Subject: [PATCH 092/264] =?UTF-8?q?[BE-29]=20refactor:=20Argument=EC=97=90?= =?UTF-8?q?=20@NonNull=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/util/RedisManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/util/RedisManager.java b/src/main/java/com/recordit/server/util/RedisManager.java index 4f9844a9..ef443d71 100644 --- a/src/main/java/com/recordit/server/util/RedisManager.java +++ b/src/main/java/com/recordit/server/util/RedisManager.java @@ -38,7 +38,7 @@ public void set(@NonNull String key, @NonNull Object value, long timeout, @NonNu } } - public Optional get(@NonNull String key, Class clazz) { + public Optional get(@NonNull String key, @NonNull Class clazz) { String jsonString = stringRedisTemplate.opsForValue().get(key); if (!StringUtils.hasText(jsonString)) { return Optional.empty(); From 857829d8f2978d9a5d48e7a60bfb49207870147a Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 19:47:33 +0900 Subject: [PATCH 093/264] =?UTF-8?q?[BE-29]=20chore:=20application-oauth.ym?= =?UTF-8?q?l=EC=97=90=20oauth=20=EA=B4=80=EB=A0=A8=20=ED=99=98=EA=B2=BD=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-oauth.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application-oauth.yml b/src/main/resources/application-oauth.yml index 6a17e631..a03b70c1 100644 --- a/src/main/resources/application-oauth.yml +++ b/src/main/resources/application-oauth.yml @@ -1,4 +1,18 @@ spring: config: activate: - on-profile: "oauth" \ No newline at end of file + on-profile: "oauth" + +oauth: + kakao: + client-id: ${OAUTH_KAKAO_CLIENT_ID:} + client-secret: ${OAUTH_KAKAO_CLIENT_SECRET:} + redirect-url: ${OAUTH_KAKAO_REDIRECT_URL:} + token-request-url: https://kauth.kakao.com/oauth/token + user-info-request-url: https://kapi.kakao.com/v2/user/me + google: + client-id: ${OAUTH_GOOGLE_CLIENT_ID:} + client-secret: ${OAUTH_GOOGLE_CLIENT_SECRET:} + redirect-url: ${OAUTH_GOOGLE_REDIRECT_URL:} + token-request-url: https://oauth2.googleapis.com/token + user-info-request-url: https://www.googleapis.com/drive/v2/files From 5951332609ca289f77b50e222583fbe16f43856a Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 19:55:31 +0900 Subject: [PATCH 094/264] =?UTF-8?q?[BE-72]=20refactor:=20OauthService?= =?UTF-8?q?=EC=97=90=20oauthToken=EC=9C=BC=EB=A1=9C=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EC=96=BB=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/service/MemberService.java | 2 +- .../com/recordit/server/service/oauth/GoogleOauthService.java | 2 +- .../com/recordit/server/service/oauth/KakaoOauthService.java | 2 +- .../java/com/recordit/server/service/oauth/OauthService.java | 2 +- .../java/com/recordit/server/service/MemberServiceTest.java | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index 799d903c..c3b6975e 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -36,7 +36,7 @@ public class MemberService { public Optional oauthLogin(String loginType, LoginRequestDto loginRequestDto) { OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType); - String oauthId = oauthService.request(loginRequestDto.getOauthToken()); + String oauthId = oauthService.getUserInfoByOauthToken(loginRequestDto.getOauthToken()); Optional findMember = memberRepository.findByOauthId(oauthId); if (findMember.isPresent()) { diff --git a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java index 1efd60af..d19d0717 100644 --- a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java @@ -12,7 +12,7 @@ public LoginType getLoginType() { } @Override - public String request(String oauthToken) { + public String getUserInfoByOauthToken(String oauthToken) { return null; } } diff --git a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java index 8cf4ce22..85e04928 100644 --- a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java @@ -12,7 +12,7 @@ public LoginType getLoginType() { } @Override - public String request(String oauthToken) { + public String getUserInfoByOauthToken(String oauthToken) { return null; } } diff --git a/src/main/java/com/recordit/server/service/oauth/OauthService.java b/src/main/java/com/recordit/server/service/oauth/OauthService.java index 2bd1068d..a827efa3 100644 --- a/src/main/java/com/recordit/server/service/oauth/OauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/OauthService.java @@ -6,5 +6,5 @@ public interface OauthService { LoginType getLoginType(); - String request(String oauthToken); + String getUserInfoByOauthToken(String oauthToken); } diff --git a/src/test/java/com/recordit/server/service/MemberServiceTest.java b/src/test/java/com/recordit/server/service/MemberServiceTest.java index 6595e6ae..6eefb215 100644 --- a/src/test/java/com/recordit/server/service/MemberServiceTest.java +++ b/src/test/java/com/recordit/server/service/MemberServiceTest.java @@ -98,7 +98,7 @@ class oauthToken을_통해_찾은_사용자가 { given(oauthServiceLocator.getOauthServiceByLoginType(anyString())) .willReturn(oauthService); - given(oauthService.request(anyString())) + given(oauthService.getUserInfoByOauthToken(anyString())) .willReturn(mockOauthId); given(memberRepository.findByOauthId(mockOauthId)) .willReturn(mockMember); @@ -119,7 +119,7 @@ class oauthToken을_통해_찾은_사용자가 { // given given(oauthServiceLocator.getOauthServiceByLoginType(anyString())) .willReturn(oauthService); - given(oauthService.request(anyString())) + given(oauthService.getUserInfoByOauthToken(anyString())) .willReturn(mockOauthId); given(memberRepository.findByOauthId(mockOauthId)) .willReturn(Optional.empty()); From a1a3080fa5e0aea2d509fac8455bc7b899e7ca80 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 20:42:34 +0900 Subject: [PATCH 095/264] =?UTF-8?q?[BE-72]=20build:=20ConfigurationPropert?= =?UTF-8?q?ies=20=EC=82=AC=EC=9A=A9=EC=9D=84=20=EC=9C=84=ED=95=B4=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 22fe0f98..cc4ff556 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,9 @@ dependencies { // use static mock testImplementation 'org.mockito:mockito-inline:4.5.1' + + // use ConfigurationProperties + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" } tasks.named('test') { From 9fbefac1f51ac293e99775542f8fcd132402a46a Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 23 Dec 2022 20:52:17 +0900 Subject: [PATCH 096/264] =?UTF-8?q?[BE-76]=20chore:=20JpaAuditing=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/RecordItServerApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/recordit/server/RecordItServerApplication.java b/src/main/java/com/recordit/server/RecordItServerApplication.java index 63f8d8d6..86cd06f7 100644 --- a/src/main/java/com/recordit/server/RecordItServerApplication.java +++ b/src/main/java/com/recordit/server/RecordItServerApplication.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication +@EnableJpaAuditing public class RecordItServerApplication { public static void main(String[] args) { From e00d8187c1fe5921c3ff3a8ecf0d6604370671a1 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 23 Dec 2022 20:53:20 +0900 Subject: [PATCH 097/264] =?UTF-8?q?[BE-72]=20feat:=20ConfigurationProperti?= =?UTF-8?q?es=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=B4=20Google,=20Kakao=20O?= =?UTF-8?q?auth=20=EC=9D=B8=EC=A6=9D=20=EA=B4=80=EB=A0=A8=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EB=B3=80=EC=88=98=20=EB=B0=9B=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/RecordItServerApplication.java | 4 +++ .../environment/GoogleOauthProperties.java | 30 +++++++++++++++++++ .../environment/KakaoOauthProperties.java | 30 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/main/java/com/recordit/server/environment/GoogleOauthProperties.java create mode 100644 src/main/java/com/recordit/server/environment/KakaoOauthProperties.java diff --git a/src/main/java/com/recordit/server/RecordItServerApplication.java b/src/main/java/com/recordit/server/RecordItServerApplication.java index 63f8d8d6..3a9630e4 100644 --- a/src/main/java/com/recordit/server/RecordItServerApplication.java +++ b/src/main/java/com/recordit/server/RecordItServerApplication.java @@ -2,8 +2,12 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +import org.springframework.boot.context.properties.EnableConfigurationProperties; @SpringBootApplication +@EnableConfigurationProperties +@ConfigurationPropertiesScan public class RecordItServerApplication { public static void main(String[] args) { diff --git a/src/main/java/com/recordit/server/environment/GoogleOauthProperties.java b/src/main/java/com/recordit/server/environment/GoogleOauthProperties.java new file mode 100644 index 00000000..ba5af10d --- /dev/null +++ b/src/main/java/com/recordit/server/environment/GoogleOauthProperties.java @@ -0,0 +1,30 @@ +package com.recordit.server.environment; + +import javax.validation.constraints.NotBlank; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; +import org.springframework.validation.annotation.Validated; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@Validated +@ConstructorBinding +@ConfigurationProperties(prefix = "oauth.google") +@RequiredArgsConstructor +public class GoogleOauthProperties { + + @NotBlank + private final String clientId; + @NotBlank + private final String clientSecret; + @NotBlank + private final String redirectUrl; + @NotBlank + private final String tokenRequestUrl; + @NotBlank + private final String userInfoRequestUrl; + +} diff --git a/src/main/java/com/recordit/server/environment/KakaoOauthProperties.java b/src/main/java/com/recordit/server/environment/KakaoOauthProperties.java new file mode 100644 index 00000000..c0cfbedb --- /dev/null +++ b/src/main/java/com/recordit/server/environment/KakaoOauthProperties.java @@ -0,0 +1,30 @@ +package com.recordit.server.environment; + +import javax.validation.constraints.NotBlank; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; +import org.springframework.validation.annotation.Validated; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@Validated +@ConstructorBinding +@ConfigurationProperties(prefix = "oauth.kakao") +@RequiredArgsConstructor +public class KakaoOauthProperties { + + @NotBlank + private final String clientId; + @NotBlank + private final String clientSecret; + @NotBlank + private final String redirectUrl; + @NotBlank + private final String tokenRequestUrl; + @NotBlank + private final String userInfoRequestUrl; + +} From 9e0f31d05d7a039d3e3d4ed1b0c804afaebac7b3 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 24 Dec 2022 01:32:47 +0900 Subject: [PATCH 098/264] =?UTF-8?q?[BE-72]=20chore:=20application-oauth.ym?= =?UTF-8?q?l=20=EA=B5=AC=EA=B8=80=20user-info-request-url=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-oauth.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-oauth.yml b/src/main/resources/application-oauth.yml index a03b70c1..b65b9b42 100644 --- a/src/main/resources/application-oauth.yml +++ b/src/main/resources/application-oauth.yml @@ -15,4 +15,4 @@ oauth: client-secret: ${OAUTH_GOOGLE_CLIENT_SECRET:} redirect-url: ${OAUTH_GOOGLE_REDIRECT_URL:} token-request-url: https://oauth2.googleapis.com/token - user-info-request-url: https://www.googleapis.com/drive/v2/files + user-info-request-url: https://oauth2.googleapis.com/tokeninfo From daa0062989435f9617a5ebd0b2b4449a4df1dcb5 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 24 Dec 2022 01:33:46 +0900 Subject: [PATCH 099/264] =?UTF-8?q?[BE-72]=20feat:=20Oauth=20=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EA=B4=80=EB=A0=A8=20Enum?= =?UTF-8?q?=EC=9D=B8=20OauthConstants=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/constant/OauthConstants.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/com/recordit/server/constant/OauthConstants.java diff --git a/src/main/java/com/recordit/server/constant/OauthConstants.java b/src/main/java/com/recordit/server/constant/OauthConstants.java new file mode 100644 index 00000000..c6a1d1f4 --- /dev/null +++ b/src/main/java/com/recordit/server/constant/OauthConstants.java @@ -0,0 +1,19 @@ +package com.recordit.server.constant; + +public enum OauthConstants { + CLIENT_ID("client_id"), + CLIENT_SECRET("client_secret"), + CODE("code"), + GRANT_TYPE("grant_type"), + REDIRECT_URI("redirect_uri"); + + public final String key; + + OauthConstants(String key) { + this.key = key; + } + + public static String getFixGrantType() { + return "authorization_code"; + } +} From 50216268630d0bf5f00e2ac33168708ac2d7223f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 24 Dec 2022 15:12:43 +0900 Subject: [PATCH 100/264] =?UTF-8?q?[BE-72]=20feat:=20KAKAO,=20GOOGLE?= =?UTF-8?q?=EC=9D=98=20AccessTokenResponseDto=EC=99=80=20UserInfoResponseD?= =?UTF-8?q?to=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/GoogleAccessTokenResponseDto.java | 21 +++++++++++++ .../dto/member/GoogleUserInfoResponseDto.java | 31 +++++++++++++++++++ .../member/KakaoAccessTokenResponseDto.java | 23 ++++++++++++++ .../dto/member/KakaoUserInfoResponseDto.java | 18 +++++++++++ 4 files changed, 93 insertions(+) create mode 100644 src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java create mode 100644 src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java create mode 100644 src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java create mode 100644 src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java diff --git a/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java b/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java new file mode 100644 index 00000000..84744255 --- /dev/null +++ b/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java @@ -0,0 +1,21 @@ +package com.recordit.server.dto.member; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class GoogleAccessTokenResponseDto { + private String accessToken; + private String expiresIn; + private String scope; + private String tokenType; + private String idToken; +} diff --git a/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java b/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java new file mode 100644 index 00000000..1d26b2ce --- /dev/null +++ b/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java @@ -0,0 +1,31 @@ +package com.recordit.server.dto.member; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class GoogleUserInfoResponseDto { + private String iss; + private String azp; + private String aud; + private String sub; + private String atHash; + private String name; + private String picture; + private String givenName; + private String familyName; + private String locale; + private String iat; + private String exp; + private String alg; + private String kid; + private String typ; +} diff --git a/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java b/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java new file mode 100644 index 00000000..cb19f788 --- /dev/null +++ b/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java @@ -0,0 +1,23 @@ +package com.recordit.server.dto.member; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class KakaoAccessTokenResponseDto { + private String accessToken; + private String tokenType; + private String refreshToken; + private String refreshTokenExpiresIn; + private String expiresIn; + private String scope; +} + diff --git a/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java b/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java new file mode 100644 index 00000000..c71faf9e --- /dev/null +++ b/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java @@ -0,0 +1,18 @@ +package com.recordit.server.dto.member; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class KakaoUserInfoResponseDto { + private String id; + private String connectedAt; +} From 6c478ff49d00f545272ef71a27d787c36fbaf02d Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 24 Dec 2022 15:41:42 +0900 Subject: [PATCH 101/264] =?UTF-8?q?[BE-72]=20feat:=20OauthConstants?= =?UTF-8?q?=EC=97=90=20=EC=83=81=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/constant/OauthConstants.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/constant/OauthConstants.java b/src/main/java/com/recordit/server/constant/OauthConstants.java index c6a1d1f4..3df7e959 100644 --- a/src/main/java/com/recordit/server/constant/OauthConstants.java +++ b/src/main/java/com/recordit/server/constant/OauthConstants.java @@ -5,7 +5,8 @@ public enum OauthConstants { CLIENT_SECRET("client_secret"), CODE("code"), GRANT_TYPE("grant_type"), - REDIRECT_URI("redirect_uri"); + REDIRECT_URI("redirect_uri"), + ID_TOKEN("id_token"); public final String key; From 373541633a168c2824c92d83cd8f3abae66793c6 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 24 Dec 2022 15:52:03 +0900 Subject: [PATCH 102/264] =?UTF-8?q?[BE-72]=20chore:=20MemberService.oauthR?= =?UTF-8?q?egister=20TODO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/service/MemberService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index c3b6975e..40368be6 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -70,6 +70,7 @@ public void oauthRegister(String loginType, RegisterRequestDto registerRequestDt ) ); sessionUtil.saveUserIdInSession(saveMember.getId()); + // TODO RegisterSession을 읽어와서 가입까지 완료 했다면 RegisterSession을 삭제 해야함 } @Transactional(readOnly = true) From 968d349e430f19709a895bd96dd27acd4941737b Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 24 Dec 2022 15:52:30 +0900 Subject: [PATCH 103/264] =?UTF-8?q?[BE-72]=20feat:=20JpaAuditing=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/RecordItServerApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/recordit/server/RecordItServerApplication.java b/src/main/java/com/recordit/server/RecordItServerApplication.java index 3a9630e4..2ea64b33 100644 --- a/src/main/java/com/recordit/server/RecordItServerApplication.java +++ b/src/main/java/com/recordit/server/RecordItServerApplication.java @@ -4,10 +4,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication @EnableConfigurationProperties @ConfigurationPropertiesScan +@EnableJpaAuditing public class RecordItServerApplication { public static void main(String[] args) { From e2137f47b009bdacde4ab6eb4df07f40f6c2d35c Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 24 Dec 2022 15:54:39 +0900 Subject: [PATCH 104/264] =?UTF-8?q?[BE-72]=20feat:=20CustomObjectMapper=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/util/CustomObjectMapper.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/com/recordit/server/util/CustomObjectMapper.java diff --git a/src/main/java/com/recordit/server/util/CustomObjectMapper.java b/src/main/java/com/recordit/server/util/CustomObjectMapper.java new file mode 100644 index 00000000..177bda96 --- /dev/null +++ b/src/main/java/com/recordit/server/util/CustomObjectMapper.java @@ -0,0 +1,18 @@ +package com.recordit.server.util; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import lombok.NonNull; + +public class CustomObjectMapper { + private static final ObjectMapper objectMapper = new ObjectMapper(); + + public static T readValue(@NonNull String str, @NonNull Class clazz) { + try { + return objectMapper.readValue(str, clazz); + } catch (JsonProcessingException e) { + throw new IllegalArgumentException("잘못된 Json값이나 Class Type을 입력했습니다."); + } + } +} From 4cde281e46d8294d6247da70845cc0168776de5a Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 24 Dec 2022 16:27:51 +0900 Subject: [PATCH 105/264] =?UTF-8?q?[BE-72]=20feat:=20OauthConstants=20?= =?UTF-8?q?=EC=83=81=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/constant/OauthConstants.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/constant/OauthConstants.java b/src/main/java/com/recordit/server/constant/OauthConstants.java index 3df7e959..cbe3024c 100644 --- a/src/main/java/com/recordit/server/constant/OauthConstants.java +++ b/src/main/java/com/recordit/server/constant/OauthConstants.java @@ -6,7 +6,8 @@ public enum OauthConstants { CODE("code"), GRANT_TYPE("grant_type"), REDIRECT_URI("redirect_uri"), - ID_TOKEN("id_token"); + ID_TOKEN("id_token"), + AUTHORIZATION("Authorization"); public final String key; @@ -17,4 +18,8 @@ public enum OauthConstants { public static String getFixGrantType() { return "authorization_code"; } + + public static String getFixPrefixJwt() { + return "Bearer "; + } } From 7be233f51d5ae1b1a9ac7547c9350256b1cd4a2f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 24 Dec 2022 16:28:25 +0900 Subject: [PATCH 106/264] =?UTF-8?q?[BE-72]=20feat:=20KakaoUserInfoResponse?= =?UTF-8?q?Dto=EC=97=90=20JsonIgnoreProperties=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=EC=9D=84=20=ED=86=B5=ED=95=B4=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EA=B0=92=EB=A7=8C=20Parsing=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/dto/member/KakaoUserInfoResponseDto.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java b/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java index c71faf9e..e1281930 100644 --- a/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java @@ -1,5 +1,6 @@ package com.recordit.server.dto.member; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -12,6 +13,7 @@ @ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +@JsonIgnoreProperties(ignoreUnknown = true) public class KakaoUserInfoResponseDto { private String id; private String connectedAt; From d9bab2366e504e4e1c29a43d84c0362a321a92fe Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 26 Dec 2022 09:09:29 +0900 Subject: [PATCH 107/264] =?UTF-8?q?[BE-72]=20feat:=20RestTemplate=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EB=A5=BC=20ExceptionHandler=EC=97=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/exception/member/MemberExceptionHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index 2da5782f..f6103443 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -4,6 +4,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.client.RestClientException; import com.recordit.server.controller.MemberController; import com.recordit.server.exception.ErrorMessage; @@ -45,5 +46,12 @@ public ResponseEntity handleNotFoundRegisterSessionException( return ResponseEntity.status(HttpStatus.PRECONDITION_REQUIRED) .body(ErrorMessage.of(exception, HttpStatus.PRECONDITION_REQUIRED)); } + + @ExceptionHandler(RestClientException.class) + public ResponseEntity handleRestClientException( + RestClientException exception) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(ErrorMessage.of(exception, HttpStatus.INTERNAL_SERVER_ERROR)); + } } From 29b7a56fe50a9f36cc7a9bc0b5e19b1becf2609c Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 26 Dec 2022 09:13:32 +0900 Subject: [PATCH 108/264] =?UTF-8?q?[BE-72]=20feat:=20GoogleOauthService=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/oauth/GoogleOauthService.java | 59 ++++++++++++++++++- .../service/oauth/GoogleOauthServiceTest.java | 35 +++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/recordit/server/service/oauth/GoogleOauthServiceTest.java diff --git a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java index d19d0717..bbdd3899 100644 --- a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java @@ -1,18 +1,75 @@ package com.recordit.server.service.oauth; +import static com.recordit.server.constant.OauthConstants.*; + +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; import com.recordit.server.constant.LoginType; +import com.recordit.server.dto.member.GoogleAccessTokenResponseDto; +import com.recordit.server.dto.member.GoogleUserInfoResponseDto; +import com.recordit.server.environment.GoogleOauthProperties; +import com.recordit.server.util.CustomObjectMapper; + +import lombok.RequiredArgsConstructor; @Service +@RequiredArgsConstructor public class GoogleOauthService implements OauthService { + + private final GoogleOauthProperties googleOauthProperties; + @Override + @Transactional(readOnly = true) public LoginType getLoginType() { return LoginType.GOOGLE; } @Override + @Transactional(readOnly = true) public String getUserInfoByOauthToken(String oauthToken) { - return null; + GoogleAccessTokenResponseDto googleAccessTokenResponseDto = requestAccessToken(oauthToken); + GoogleUserInfoResponseDto googleUserInfoResponseDto = requestUserInfo(googleAccessTokenResponseDto); + return googleUserInfoResponseDto.getSub(); + } + + @Transactional(readOnly = true) + protected GoogleAccessTokenResponseDto requestAccessToken(String oauthToken) { + String params = UriComponentsBuilder.fromUriString(googleOauthProperties.getTokenRequestUrl()) + .queryParam(CODE.key, oauthToken) + .queryParam(CLIENT_ID.key, googleOauthProperties.getClientId()) + .queryParam(CLIENT_SECRET.key, googleOauthProperties.getClientSecret()) + .queryParam(REDIRECT_URI.key, googleOauthProperties.getRedirectUrl()) + .queryParam(GRANT_TYPE.key, getFixGrantType()) + .toUriString(); + + ResponseEntity exchange = new RestTemplate().exchange( + params, + HttpMethod.POST, + null, + String.class + ); + + return CustomObjectMapper.readValue(exchange.getBody(), GoogleAccessTokenResponseDto.class); + } + + @Transactional(readOnly = true) + protected GoogleUserInfoResponseDto requestUserInfo(GoogleAccessTokenResponseDto googleAccessTokenResponseDto) { + String uri = UriComponentsBuilder.fromUriString(googleOauthProperties.getUserInfoRequestUrl()) + .queryParam(ID_TOKEN.key, googleAccessTokenResponseDto.getIdToken()) + .toUriString(); + + ResponseEntity exchange = new RestTemplate().exchange( + uri, + HttpMethod.GET, + null, + String.class + ); + + return CustomObjectMapper.readValue(exchange.getBody(), GoogleUserInfoResponseDto.class); } } diff --git a/src/test/java/com/recordit/server/service/oauth/GoogleOauthServiceTest.java b/src/test/java/com/recordit/server/service/oauth/GoogleOauthServiceTest.java new file mode 100644 index 00000000..a34b4841 --- /dev/null +++ b/src/test/java/com/recordit/server/service/oauth/GoogleOauthServiceTest.java @@ -0,0 +1,35 @@ +package com.recordit.server.service.oauth; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.recordit.server.constant.LoginType; +import com.recordit.server.environment.GoogleOauthProperties; + +@ExtendWith(MockitoExtension.class) +public class GoogleOauthServiceTest { + + @InjectMocks + private GoogleOauthService googleOauthService; + + @Mock + private GoogleOauthProperties googleOauthProperties; + + @Test + @DisplayName("LoginType이 정상적으로 응답되는지 테스트한다") + void LoginType이_정상적으로_응답되는지_테스트한다() { + // given + + // when + LoginType loginType = googleOauthService.getLoginType(); + + // then + assertThat(loginType).isEqualTo(LoginType.GOOGLE); + } +} From 92cf2d188e4ee1a33436507a1af5d23cff2d85a7 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 26 Dec 2022 09:36:03 +0900 Subject: [PATCH 109/264] =?UTF-8?q?[BE-72]=20test:=20CustomObjectMapperTes?= =?UTF-8?q?t=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/dummy/Foo.java | 40 ++++++++++++++++ .../server/util/CustomObjectMapperTest.java | 48 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/test/java/com/recordit/server/dummy/Foo.java create mode 100644 src/test/java/com/recordit/server/util/CustomObjectMapperTest.java diff --git a/src/test/java/com/recordit/server/dummy/Foo.java b/src/test/java/com/recordit/server/dummy/Foo.java new file mode 100644 index 00000000..a873dde7 --- /dev/null +++ b/src/test/java/com/recordit/server/dummy/Foo.java @@ -0,0 +1,40 @@ +package com.recordit.server.dummy; + +import java.util.Objects; + +public class Foo { + private String field1; + private String field2; + + public Foo(String field1, String field2) { + this.field1 = field1; + this.field2 = field2; + } + + public Foo() { + } + + public String getField1() { + return field1; + } + + public String getField2() { + return field2; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Foo foo = (Foo)o; + return Objects.equals(getField1(), foo.getField1()) && Objects.equals(getField2(), + foo.getField2()); + } + + @Override + public int hashCode() { + return Objects.hash(getField1(), getField2()); + } +} diff --git a/src/test/java/com/recordit/server/util/CustomObjectMapperTest.java b/src/test/java/com/recordit/server/util/CustomObjectMapperTest.java new file mode 100644 index 00000000..5834f71e --- /dev/null +++ b/src/test/java/com/recordit/server/util/CustomObjectMapperTest.java @@ -0,0 +1,48 @@ +package com.recordit.server.util; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.recordit.server.dummy.Foo; + +@ExtendWith(MockitoExtension.class) +public class CustomObjectMapperTest { + + @Nested + @DisplayName("입력된 Json 값이") + class 입력된_Json_값이 { + + @Test + @DisplayName("잘못된 경우 예외를 던진다") + void 잘못된_경우_예외를_던진다() { + // given + String str = "test"; + Class anyClassType = Object.class; + + // when, then + assertThatThrownBy(() -> CustomObjectMapper.readValue(str, anyClassType)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + @DisplayName("정상적인 경우 예외를 던지지 않는다") + void 정상적인_경우_예외를_던지지_않는다() throws Exception { + // given + Foo foo = new Foo("testField1", "testField2"); + String fooToJsonString = "{\"field1\":\"testField1\",\"field2\":\"testField2\"}"; + Class fooClass = Foo.class; + + // when, then + assertThatCode(() -> CustomObjectMapper.readValue(fooToJsonString, fooClass)) + .doesNotThrowAnyException(); + assertThat(foo).isEqualTo(CustomObjectMapper.readValue(fooToJsonString, fooClass)); + + } + } + +} From cd5a0e95ea8fb381be48c789b45bf3b6ede3a150 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 26 Dec 2022 09:14:03 +0900 Subject: [PATCH 110/264] =?UTF-8?q?[BE-74]=20feat:=20KakaoOauthService=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/oauth/KakaoOauthService.java | 61 ++++++++++++++++++- .../service/oauth/KakaoOauthServiceTest.java | 35 +++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/recordit/server/service/oauth/KakaoOauthServiceTest.java diff --git a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java index 85e04928..dbdb4a65 100644 --- a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java @@ -1,18 +1,77 @@ package com.recordit.server.service.oauth; +import static com.recordit.server.constant.OauthConstants.*; + +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; import com.recordit.server.constant.LoginType; +import com.recordit.server.dto.member.KakaoAccessTokenResponseDto; +import com.recordit.server.dto.member.KakaoUserInfoResponseDto; +import com.recordit.server.environment.KakaoOauthProperties; +import com.recordit.server.util.CustomObjectMapper; + +import lombok.RequiredArgsConstructor; @Service +@RequiredArgsConstructor public class KakaoOauthService implements OauthService { + + private final KakaoOauthProperties kakaoOauthProperties; + @Override + @Transactional(readOnly = true) public LoginType getLoginType() { return LoginType.KAKAO; } @Override + @Transactional(readOnly = true) public String getUserInfoByOauthToken(String oauthToken) { - return null; + KakaoAccessTokenResponseDto kakaoAccessTokenResponseDto = requestAccessToken(oauthToken); + KakaoUserInfoResponseDto kakaoUserInfoResponseDto = requestUserInfo(kakaoAccessTokenResponseDto); + return String.valueOf(kakaoUserInfoResponseDto.getId()); } + + @Transactional(readOnly = true) + protected KakaoAccessTokenResponseDto requestAccessToken(String oauthToken) { + String params = UriComponentsBuilder.fromUriString(kakaoOauthProperties.getTokenRequestUrl()) + .queryParam(CODE.key, oauthToken) + .queryParam(CLIENT_ID.key, kakaoOauthProperties.getClientId()) + .queryParam(CLIENT_SECRET.key, kakaoOauthProperties.getClientSecret()) + .queryParam(REDIRECT_URI.key, kakaoOauthProperties.getRedirectUrl()) + .queryParam(GRANT_TYPE.key, getFixGrantType()) + .toUriString(); + + ResponseEntity exchange = new RestTemplate().exchange( + params, + HttpMethod.POST, + null, + String.class + ); + + return CustomObjectMapper.readValue(exchange.getBody(), KakaoAccessTokenResponseDto.class); + } + + @Transactional(readOnly = true) + protected KakaoUserInfoResponseDto requestUserInfo(KakaoAccessTokenResponseDto kakaoAccessTokenResponseDto) { + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.add(AUTHORIZATION.key, getFixPrefixJwt() + kakaoAccessTokenResponseDto.getAccessToken()); + + ResponseEntity exchange = new RestTemplate().exchange( + kakaoOauthProperties.getUserInfoRequestUrl(), + HttpMethod.GET, + new HttpEntity(httpHeaders), + String.class + ); + + return CustomObjectMapper.readValue(exchange.getBody(), KakaoUserInfoResponseDto.class); + } + } diff --git a/src/test/java/com/recordit/server/service/oauth/KakaoOauthServiceTest.java b/src/test/java/com/recordit/server/service/oauth/KakaoOauthServiceTest.java new file mode 100644 index 00000000..26e15c66 --- /dev/null +++ b/src/test/java/com/recordit/server/service/oauth/KakaoOauthServiceTest.java @@ -0,0 +1,35 @@ +package com.recordit.server.service.oauth; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.recordit.server.constant.LoginType; +import com.recordit.server.environment.KakaoOauthProperties; + +@ExtendWith(MockitoExtension.class) +class KakaoOauthServiceTest { + + @InjectMocks + private KakaoOauthService kakaoOauthService; + + @Mock + private KakaoOauthProperties kakaoOauthProperties; + + @Test + @DisplayName("LoginType이 정상적으로 응답되는지 테스트한다") + void LoginType이_정상적으로_응답되는지_테스트한다() { + // given + + // when + LoginType loginType = kakaoOauthService.getLoginType(); + + // then + assertThat(loginType).isEqualTo(LoginType.KAKAO); + } +} \ No newline at end of file From 6f8aa915fcd4c4453235bf44ba5a29ea4565fe62 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 26 Dec 2022 13:10:57 +0900 Subject: [PATCH 111/264] =?UTF-8?q?[BE-77]=20docs:=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20API=20Swagger=20=EB=AA=85=EC=84=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RecordCategoryController.java | 37 +++++++++++++++++++ .../category/RecordCategoryResponseDto.java | 28 ++++++++++++++ .../repository/RecordCategoryRepository.java | 8 ++++ .../server/service/RecordCategoryService.java | 14 +++++++ 4 files changed, 87 insertions(+) create mode 100644 src/main/java/com/recordit/server/controller/RecordCategoryController.java create mode 100644 src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java create mode 100644 src/main/java/com/recordit/server/repository/RecordCategoryRepository.java create mode 100644 src/main/java/com/recordit/server/service/RecordCategoryService.java diff --git a/src/main/java/com/recordit/server/controller/RecordCategoryController.java b/src/main/java/com/recordit/server/controller/RecordCategoryController.java new file mode 100644 index 00000000..95545c90 --- /dev/null +++ b/src/main/java/com/recordit/server/controller/RecordCategoryController.java @@ -0,0 +1,37 @@ +package com.recordit.server.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.recordit.server.dto.record.category.RecordCategoryResponseDto; +import com.recordit.server.repository.RecordCategoryRepository; + +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/record/category") +public class RecordCategoryController { + + private final RecordCategoryRepository recordCategoryRepository; + + @ApiOperation( + value = "레코트 카테고리 전체 조회", + notes = "레코트 카테고리 전체를 조회합니다." + ) + @ApiResponses({ + @ApiResponse( + code = 200, message = "API 정상 작동 / 레코드 카테고리 목록 반환", + response = RecordCategoryResponseDto.class + ) + }) + @GetMapping + public ResponseEntity getAllRecordCategories() { + return null; + } +} diff --git a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java new file mode 100644 index 00000000..fb635919 --- /dev/null +++ b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java @@ -0,0 +1,28 @@ +package com.recordit.server.dto.record.category; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +@AllArgsConstructor +@Builder +public class RecordCategoryResponseDto { + @ApiModelProperty(notes = "레코드 카테고리 목록", required = true) + private HashMap> recordCategory; +} diff --git a/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java b/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java new file mode 100644 index 00000000..975c2ea9 --- /dev/null +++ b/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java @@ -0,0 +1,8 @@ +package com.recordit.server.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.recordit.server.domain.RecordCategory; + +public interface RecordCategoryRepository extends JpaRepository { +} diff --git a/src/main/java/com/recordit/server/service/RecordCategoryService.java b/src/main/java/com/recordit/server/service/RecordCategoryService.java new file mode 100644 index 00000000..ea745bc8 --- /dev/null +++ b/src/main/java/com/recordit/server/service/RecordCategoryService.java @@ -0,0 +1,14 @@ +package com.recordit.server.service; + +import org.springframework.stereotype.Service; + +import com.recordit.server.repository.RecordCategoryRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class RecordCategoryService { + private final RecordCategoryRepository recordCategoryRepository; + +} From 66ca815cb54483cfd033e5d43cec82f3a89091c9 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 26 Dec 2022 13:33:10 +0900 Subject: [PATCH 112/264] =?UTF-8?q?[BE-77]=20fix:=20HashMap,=20ArrayList?= =?UTF-8?q?=20->=20Map,=20List=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/record/category/RecordCategoryResponseDto.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java index fb635919..3a50ffb8 100644 --- a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java +++ b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java @@ -1,7 +1,7 @@ package com.recordit.server.dto.record.category; -import java.util.ArrayList; -import java.util.HashMap; +import java.util.List; +import java.util.Map; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -24,5 +24,5 @@ @Builder public class RecordCategoryResponseDto { @ApiModelProperty(notes = "레코드 카테고리 목록", required = true) - private HashMap> recordCategory; + private Map> recordCategory; } From adc0e21fbd9b3e1c09e00a0c5a16625f1ce673b1 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 26 Dec 2022 13:35:14 +0900 Subject: [PATCH 113/264] =?UTF-8?q?[BE-77]=20fix:=20Builder=20=EC=9C=84?= =?UTF-8?q?=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/record/category/RecordCategoryResponseDto.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java index 3a50ffb8..98f0da74 100644 --- a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java +++ b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java @@ -9,7 +9,6 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; -import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -20,9 +19,12 @@ @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) -@AllArgsConstructor -@Builder public class RecordCategoryResponseDto { @ApiModelProperty(notes = "레코드 카테고리 목록", required = true) private Map> recordCategory; + + @Builder + public RecordCategoryResponseDto(Map> recordCategory) { + this.recordCategory = recordCategory; + } } From be962838766506f18e923f025009def93bb2a8f0 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 26 Dec 2022 14:14:41 +0900 Subject: [PATCH 114/264] =?UTF-8?q?[BE-72]=20test:=20Foo=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=ED=9B=84=20MappingDummy=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20CustomObjectMapperTest=20=EB=82=B4=EB=B6=80?= =?UTF-8?q?=EC=97=90=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/dummy/Foo.java | 40 -------------- .../server/util/CustomObjectMapperTest.java | 52 ++++++++++++++++--- 2 files changed, 45 insertions(+), 47 deletions(-) delete mode 100644 src/test/java/com/recordit/server/dummy/Foo.java diff --git a/src/test/java/com/recordit/server/dummy/Foo.java b/src/test/java/com/recordit/server/dummy/Foo.java deleted file mode 100644 index a873dde7..00000000 --- a/src/test/java/com/recordit/server/dummy/Foo.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.recordit.server.dummy; - -import java.util.Objects; - -public class Foo { - private String field1; - private String field2; - - public Foo(String field1, String field2) { - this.field1 = field1; - this.field2 = field2; - } - - public Foo() { - } - - public String getField1() { - return field1; - } - - public String getField2() { - return field2; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - Foo foo = (Foo)o; - return Objects.equals(getField1(), foo.getField1()) && Objects.equals(getField2(), - foo.getField2()); - } - - @Override - public int hashCode() { - return Objects.hash(getField1(), getField2()); - } -} diff --git a/src/test/java/com/recordit/server/util/CustomObjectMapperTest.java b/src/test/java/com/recordit/server/util/CustomObjectMapperTest.java index 5834f71e..40a3409c 100644 --- a/src/test/java/com/recordit/server/util/CustomObjectMapperTest.java +++ b/src/test/java/com/recordit/server/util/CustomObjectMapperTest.java @@ -2,14 +2,14 @@ import static org.assertj.core.api.Assertions.*; +import java.util.Objects; + import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; -import com.recordit.server.dummy.Foo; - @ExtendWith(MockitoExtension.class) public class CustomObjectMapperTest { @@ -33,16 +33,54 @@ class 입력된_Json_값이 { @DisplayName("정상적인 경우 예외를 던지지 않는다") void 정상적인_경우_예외를_던지지_않는다() throws Exception { // given - Foo foo = new Foo("testField1", "testField2"); - String fooToJsonString = "{\"field1\":\"testField1\",\"field2\":\"testField2\"}"; - Class fooClass = Foo.class; + MappingDummy mappingDummy = new MappingDummy("testField1", "testField2"); + String mappingDummyToJsonString = "{\"field1\":\"testField1\",\"field2\":\"testField2\"}"; + Class mappingDummyClass = MappingDummy.class; // when, then - assertThatCode(() -> CustomObjectMapper.readValue(fooToJsonString, fooClass)) + assertThatCode(() -> CustomObjectMapper.readValue(mappingDummyToJsonString, mappingDummyClass)) .doesNotThrowAnyException(); - assertThat(foo).isEqualTo(CustomObjectMapper.readValue(fooToJsonString, fooClass)); + assertThat(mappingDummy).isEqualTo( + CustomObjectMapper.readValue(mappingDummyToJsonString, mappingDummyClass)); } } } + +class MappingDummy { + private String field1; + private String field2; + + public MappingDummy(String field1, String field2) { + this.field1 = field1; + this.field2 = field2; + } + + public MappingDummy() { + } + + public String getField1() { + return field1; + } + + public String getField2() { + return field2; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + MappingDummy mappingDummy = (MappingDummy)o; + return Objects.equals(getField1(), mappingDummy.getField1()) && Objects.equals(getField2(), + mappingDummy.getField2()); + } + + @Override + public int hashCode() { + return Objects.hash(getField1(), getField2()); + } +} From 835741471fdc65e562e10febb0c665043768e47c Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 26 Dec 2022 16:09:44 +0900 Subject: [PATCH 115/264] =?UTF-8?q?[BE-44]=20docs:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20API=20=EB=AA=85=EC=84=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/RecordController.java | 74 +++++++++++++++++++ .../dto/record/RecordDetailResponseDto.java | 38 ++++++++++ .../dto/record/WriteRecordRequestDto.java | 49 ++++++++++++ .../server/repository/RecordRepository.java | 8 ++ .../server/service/RecordService.java | 13 ++++ 5 files changed, 182 insertions(+) create mode 100644 src/main/java/com/recordit/server/controller/RecordController.java create mode 100644 src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java create mode 100644 src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java create mode 100644 src/main/java/com/recordit/server/repository/RecordRepository.java create mode 100644 src/main/java/com/recordit/server/service/RecordService.java diff --git a/src/main/java/com/recordit/server/controller/RecordController.java b/src/main/java/com/recordit/server/controller/RecordController.java new file mode 100644 index 00000000..5d26b28e --- /dev/null +++ b/src/main/java/com/recordit/server/controller/RecordController.java @@ -0,0 +1,74 @@ +package com.recordit.server.controller; + +import javax.validation.Valid; + +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import com.recordit.server.dto.record.RecordDetailResponseDto; +import com.recordit.server.dto.record.WriteRecordRequestDto; +import com.recordit.server.exception.ErrorMessage; +import com.recordit.server.service.RecordService; + +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/record") +public class RecordController { + + private final RecordService recordService; + + @ApiOperation( + value = "레코드 작성", + notes = "레코드를 작성합니다." + ) + @ApiResponses({ + @ApiResponse( + code = 200, message = "레코드 작성 성공" + ), + @ApiResponse( + code = 400, message = "잘못된 요청", + response = ErrorMessage.class + ) + }) + @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) + public ResponseEntity writeRecord( + @ApiParam(required = true) @RequestPart(required = true) @Valid WriteRecordRequestDto writeRecordRequestDto, + @ApiParam @RequestPart MultipartFile file + ) { + return null; + } + + @ApiOperation( + value = "레코드 단건 조회", + notes = "레코드를 단건 조회합니다." + ) + @ApiResponses({ + @ApiResponse( + code = 200, message = "레코드 조회 성공", + response = RecordDetailResponseDto.class + ), + @ApiResponse( + code = 400, message = "레코드가 없는 경우", + response = ErrorMessage.class + ) + }) + @GetMapping("/{recordId}") + public ResponseEntity getDetailRecord( + @PathVariable("recordId") Long recordId) { + return null; + } + +} diff --git a/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java b/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java new file mode 100644 index 00000000..b6293fd2 --- /dev/null +++ b/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java @@ -0,0 +1,38 @@ +package com.recordit.server.dto.record; + +import java.time.LocalDateTime; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class RecordDetailResponseDto { + private String title; + private String content; + private String hex; + private String iconName; + private LocalDateTime createdAt; + private String imageUrl; + + @Builder + public RecordDetailResponseDto(String title, String content, String hex, String iconName, LocalDateTime createdAt, + String imageUrl) { + this.title = title; + this.content = content; + this.hex = hex; + this.iconName = iconName; + this.createdAt = createdAt; + this.imageUrl = imageUrl; + } +} diff --git a/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java b/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java new file mode 100644 index 00000000..15fbed1e --- /dev/null +++ b/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java @@ -0,0 +1,49 @@ +package com.recordit.server.dto.record; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class WriteRecordRequestDto { + @NotNull + private Long recordCategoryId; + + @Size(max = 10, message = "레코드 제목은 최대 10자 입니다.") + @NotBlank(message = "레코드 제목은 빈 값일 수 없습니다.") + private String title; + + @Size(max = 200, message = "레코드 내용은 최대 200자 입니다.") + @NotBlank(message = "레코드 내용은 빈 값일 수 없습니다.") + private String content; + + @Pattern(regexp = "^#[A-Z0-9]{6}", message = "'#FFBF00'의 형태로 입력해 주세요.") + private String hex; + + @NotBlank(message = "아이콘이름은 빈 값일 수 없습니다.") + private String iconName; + + @Builder + public WriteRecordRequestDto(Long recordCategoryId, String title, String content, String hex, String iconName) { + this.recordCategoryId = recordCategoryId; + this.title = title; + this.content = content; + this.hex = hex; + this.iconName = iconName; + } +} diff --git a/src/main/java/com/recordit/server/repository/RecordRepository.java b/src/main/java/com/recordit/server/repository/RecordRepository.java new file mode 100644 index 00000000..3718590d --- /dev/null +++ b/src/main/java/com/recordit/server/repository/RecordRepository.java @@ -0,0 +1,8 @@ +package com.recordit.server.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.recordit.server.domain.Record; + +public interface RecordRepository extends JpaRepository { +} diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java new file mode 100644 index 00000000..34448c32 --- /dev/null +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -0,0 +1,13 @@ +package com.recordit.server.service; + +import org.springframework.stereotype.Service; + +import com.recordit.server.repository.RecordRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class RecordService { + private final RecordRepository recordRepository; +} From 5fc4748999f42004974e264b7a75e74dbf7c4812 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 26 Dec 2022 16:15:17 +0900 Subject: [PATCH 116/264] =?UTF-8?q?[BE-81]=20fix:=20RecordCategoryControll?= =?UTF-8?q?er=EC=97=90=20Repository=20DI=EB=A5=BC=20Service=20DI=EB=A1=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/controller/RecordCategoryController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/RecordCategoryController.java b/src/main/java/com/recordit/server/controller/RecordCategoryController.java index 95545c90..a0090007 100644 --- a/src/main/java/com/recordit/server/controller/RecordCategoryController.java +++ b/src/main/java/com/recordit/server/controller/RecordCategoryController.java @@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RestController; import com.recordit.server.dto.record.category.RecordCategoryResponseDto; -import com.recordit.server.repository.RecordCategoryRepository; +import com.recordit.server.service.RecordCategoryService; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -18,7 +18,7 @@ @RequestMapping("/record/category") public class RecordCategoryController { - private final RecordCategoryRepository recordCategoryRepository; + private final RecordCategoryService recordCategoryService; @ApiOperation( value = "레코트 카테고리 전체 조회", From 22ea5f771e29f1f6662d6c7c8a7962dc1a5c888b Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 26 Dec 2022 16:21:15 +0900 Subject: [PATCH 117/264] =?UTF-8?q?[BE-81]=20fix:=20ApiOperation=EC=97=90?= =?UTF-8?q?=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/controller/RecordCategoryController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/RecordCategoryController.java b/src/main/java/com/recordit/server/controller/RecordCategoryController.java index a0090007..2ced2db7 100644 --- a/src/main/java/com/recordit/server/controller/RecordCategoryController.java +++ b/src/main/java/com/recordit/server/controller/RecordCategoryController.java @@ -21,8 +21,8 @@ public class RecordCategoryController { private final RecordCategoryService recordCategoryService; @ApiOperation( - value = "레코트 카테고리 전체 조회", - notes = "레코트 카테고리 전체를 조회합니다." + value = "레코드 카테고리 전체 조회", + notes = "레코드 카테고리 전체를 조회합니다." ) @ApiResponses({ @ApiResponse( From 2fb23cc749ca2b5f6fa4ddf8f74ef94a3a500f05 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 26 Dec 2022 16:57:02 +0900 Subject: [PATCH 118/264] =?UTF-8?q?[BE-82]=20fix:=20application-test.yml?= =?UTF-8?q?=EC=97=90=20oauth=20=EA=B4=80=EB=A0=A8=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application-test.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index 4d4392be..c8727295 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -24,4 +24,18 @@ spring: springfox: documentation: swagger: - use-model-v3: false \ No newline at end of file + use-model-v3: false + +oauth: + kakao: + client-id: ${OAUTH_KAKAO_CLIENT_ID:} + client-secret: ${OAUTH_KAKAO_CLIENT_SECRET:} + redirect-url: ${OAUTH_KAKAO_REDIRECT_URL:} + token-request-url: https://kauth.kakao.com/oauth/token + user-info-request-url: https://kapi.kakao.com/v2/user/me + google: + client-id: ${OAUTH_GOOGLE_CLIENT_ID:} + client-secret: ${OAUTH_GOOGLE_CLIENT_SECRET:} + redirect-url: ${OAUTH_GOOGLE_REDIRECT_URL:} + token-request-url: https://oauth2.googleapis.com/token + user-info-request-url: https://oauth2.googleapis.com/tokeninfo \ No newline at end of file From 106269a41d3fc4895d080af66b0f89c5cd4439e8 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 26 Dec 2022 17:38:08 +0900 Subject: [PATCH 119/264] =?UTF-8?q?[BE-81]=20docs:=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?API=20=EB=AA=85=EC=84=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/CommentController.java | 64 +++++++++++++++++++ .../server/dto/comment/CommentDto.java | 23 +++++++ .../server/dto/comment/CommentRequestDto.java | 33 ++++++++++ .../dto/comment/CommentResponseDto.java | 35 ++++++++++ .../dto/comment/WriteCommentRequestDto.java | 31 +++++++++ .../server/repository/CommentRepository.java | 8 +++ .../server/service/CommentService.java | 14 ++++ 7 files changed, 208 insertions(+) create mode 100644 src/main/java/com/recordit/server/controller/CommentController.java create mode 100644 src/main/java/com/recordit/server/dto/comment/CommentDto.java create mode 100644 src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java create mode 100644 src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java create mode 100644 src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java create mode 100644 src/main/java/com/recordit/server/repository/CommentRepository.java create mode 100644 src/main/java/com/recordit/server/service/CommentService.java diff --git a/src/main/java/com/recordit/server/controller/CommentController.java b/src/main/java/com/recordit/server/controller/CommentController.java new file mode 100644 index 00000000..28e7fb1f --- /dev/null +++ b/src/main/java/com/recordit/server/controller/CommentController.java @@ -0,0 +1,64 @@ +package com.recordit.server.controller; + +import javax.validation.Valid; + +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import com.recordit.server.dto.comment.CommentRequestDto; +import com.recordit.server.dto.comment.CommentResponseDto; +import com.recordit.server.dto.comment.WriteCommentRequestDto; +import com.recordit.server.service.CommentService; + +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/comment") +public class CommentController { + + private final CommentService commentService; + + @ApiOperation( + value = "레코드에 댓글 작성", + notes = "레코드에 댓글을 작성합니다" + ) + @ApiResponses({ + @ApiResponse( + code = 200, message = "API 정상 작동" + ) + }) + @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) + public ResponseEntity writeComment( + @ApiParam(required = true) @RequestPart(required = true) @Valid WriteCommentRequestDto writeCommentRequestDto, + @ApiParam @RequestPart MultipartFile file + ) { + return null; + } + + @ApiOperation( + value = "레코드의 댓글을 조회", + notes = "레코드의 댓글을 조회합니다" + ) + @ApiResponses({ + @ApiResponse( + code = 200, message = "API 정상 작동 / 댓글 조회 완료", + response = CommentResponseDto.class + ) + }) + @GetMapping + public ResponseEntity getComment(@Valid @RequestBody CommentRequestDto commentRequestDto) { + return null; + } +} diff --git a/src/main/java/com/recordit/server/dto/comment/CommentDto.java b/src/main/java/com/recordit/server/dto/comment/CommentDto.java new file mode 100644 index 00000000..24fb593a --- /dev/null +++ b/src/main/java/com/recordit/server/dto/comment/CommentDto.java @@ -0,0 +1,23 @@ +package com.recordit.server.dto.comment; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class CommentDto { + private Long commentId; + + private String content; + + private String imageUrl; +} diff --git a/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java new file mode 100644 index 00000000..42a9a709 --- /dev/null +++ b/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java @@ -0,0 +1,33 @@ +package com.recordit.server.dto.comment; + +import javax.validation.constraints.NotNull; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class CommentRequestDto { + @ApiModelProperty(notes = "레코드의 id", required = true) + @NotNull + private Long recordId; + + @ApiModelProperty(notes = "자식 댓글을 조회하는 경우 부모 댓글의 id") + private Long parentId; + + @ApiModelProperty(notes = "댓글 리스트의 현재 페이지", required = true) + private int page; + + @ApiModelProperty(notes = "댓글 리스트의 사이즈", required = true) + private int size; +} diff --git a/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java b/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java new file mode 100644 index 00000000..21149955 --- /dev/null +++ b/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java @@ -0,0 +1,35 @@ +package com.recordit.server.dto.comment; + +import java.util.List; + +import javax.validation.constraints.NotNull; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class CommentResponseDto { + @ApiModelProperty(notes = "레코드의 id", required = true) + @NotNull + private Long recordId; + + @ApiModelProperty(notes = "자식 댓글의 리스트일 경우 부모 댓글이 들어감") + private Long parentId; + + @ApiModelProperty(notes = "레코드 댓글의 전체 개수", required = true) + private Long totalCount; + + @ApiModelProperty(notes = "댓글 리스트", required = true) + private List commentList; +} diff --git a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java new file mode 100644 index 00000000..870e7225 --- /dev/null +++ b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java @@ -0,0 +1,31 @@ +package com.recordit.server.dto.comment; + +import javax.validation.constraints.Size; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class WriteCommentRequestDto { + @ApiModelProperty(notes = "레코드의 id", required = true) + private Long recordId; + + @ApiModelProperty(notes = "자식 댓글일 경우 부모 댓글의 id") + private Long parentId; + + @ApiModelProperty(notes = "댓글 내용", required = true) + @Size(max = 200) + private String comment; + +} diff --git a/src/main/java/com/recordit/server/repository/CommentRepository.java b/src/main/java/com/recordit/server/repository/CommentRepository.java new file mode 100644 index 00000000..8f314d72 --- /dev/null +++ b/src/main/java/com/recordit/server/repository/CommentRepository.java @@ -0,0 +1,8 @@ +package com.recordit.server.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.recordit.server.domain.Comment; + +public interface CommentRepository extends JpaRepository { +} diff --git a/src/main/java/com/recordit/server/service/CommentService.java b/src/main/java/com/recordit/server/service/CommentService.java new file mode 100644 index 00000000..80b6cf3a --- /dev/null +++ b/src/main/java/com/recordit/server/service/CommentService.java @@ -0,0 +1,14 @@ +package com.recordit.server.service; + +import org.springframework.stereotype.Service; + +import com.recordit.server.repository.CommentRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class CommentService { + private final CommentRepository commentRepository; + +} From 777952c202d462442a0198a0025e48b93f4a896e Mon Sep 17 00:00:00 2001 From: kdomo Date: Tue, 27 Dec 2022 19:39:19 +0900 Subject: [PATCH 120/264] =?UTF-8?q?[BE-86]=20feat:=20color,=20icon=20sql?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schema/color.sql | 10 ++++++++++ schema/icon.sql | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 schema/color.sql create mode 100644 schema/icon.sql diff --git a/schema/color.sql b/schema/color.sql new file mode 100644 index 00000000..e1c269d6 --- /dev/null +++ b/schema/color.sql @@ -0,0 +1,10 @@ +INSERT INTO RECORD_COLOR(RECORD_COLOR_ID, NAME, HEX_CODE, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'icon-purple', '#9067E5', now(), now(), null); +INSERT INTO RECORD_COLOR(RECORD_COLOR_ID, NAME, HEX_CODE, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'icon-yellow', '#F3D06C', now(), now(), null); +INSERT INTO RECORD_COLOR(RECORD_COLOR_ID, NAME, HEX_CODE, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'icon-pink', '#D78A86', now(), now(), null); +INSERT INTO RECORD_COLOR(RECORD_COLOR_ID, NAME, HEX_CODE, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'icon-blue', '#6F99F2', now(), now(), null); +INSERT INTO RECORD_COLOR(RECORD_COLOR_ID, NAME, HEX_CODE, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'icon-green', '#78BCB7', now(), now(), null); \ No newline at end of file diff --git a/schema/icon.sql b/schema/icon.sql new file mode 100644 index 00000000..dd858fcc --- /dev/null +++ b/schema/icon.sql @@ -0,0 +1,26 @@ +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'crown', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'gift', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'heart', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'like', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'lock', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'modal', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'moon', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'music', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'rocket', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'speechbubble', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'trashcan', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'umbrella', now(), now(), null); +INSERT INTO RECORD_ICON(RECORD_ICON_ID, NAME, CREATED_AT, MODIFIED_AT, DELETED_AT) +VALUES (null, 'wine', now(), now(), null); \ No newline at end of file From e2b7f70ad60b735ca51f84fbbf0a7e756a0913d6 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Tue, 27 Dec 2022 22:12:38 +0900 Subject: [PATCH 121/264] =?UTF-8?q?[BE-85]=20build:=20build.gradle?= =?UTF-8?q?=EC=97=90=20s3=20SDK=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index cc4ff556..d3ff97a0 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,9 @@ dependencies { // use ConfigurationProperties annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + + // use s3 + implementation 'com.amazonaws:aws-java-sdk-s3:1.12.372' } tasks.named('test') { From 3568e787f34cdb9305cbc452c3e947e9d6cea1fd Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Tue, 27 Dec 2022 22:13:14 +0900 Subject: [PATCH 122/264] =?UTF-8?q?[BE-85]=20chore:=20application-s3.yml?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-s3.yml | 12 ++++++++++++ src/main/resources/application.yml | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/application-s3.yml diff --git a/src/main/resources/application-s3.yml b/src/main/resources/application-s3.yml new file mode 100644 index 00000000..6c0d3975 --- /dev/null +++ b/src/main/resources/application-s3.yml @@ -0,0 +1,12 @@ +spring: + config: + activate: + on-profile: "s3" + +s3: + credentials: + access-key: ${S3_ACCESS_KEY:} + secret-key: ${S3_SECRET_ACCESS_KEY:} + bucket: ${S3_BUCKET_NAME:} + directory: ${S3_DIRECTORY_NAME:} + region: ap-northeast-2 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 95437214..71f68046 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,6 +2,6 @@ spring: profiles: group: "test": "test" - "local": "local, datasource, redis, oauth" - "dev": "dev, datasource, redis, oauth" - "prod": "prod" \ No newline at end of file + "local": "local, datasource, redis, oauth, s3" + "dev": "dev, datasource, redis, oauth, s3" + "prod": "prod" From c70d468ef0d40e160e7d8d9d08f32895eb88be9e Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 00:14:58 +0900 Subject: [PATCH 123/264] =?UTF-8?q?[BE-85]=20feat:=20ImageFileExceptionHan?= =?UTF-8?q?dler=EC=99=80=20FileInputStreamException=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../imagefile/FileInputStreamException.java | 7 +++++++ .../imagefile/ImageFileExceptionHandler.java | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/imagefile/FileInputStreamException.java create mode 100644 src/main/java/com/recordit/server/exception/imagefile/ImageFileExceptionHandler.java diff --git a/src/main/java/com/recordit/server/exception/imagefile/FileInputStreamException.java b/src/main/java/com/recordit/server/exception/imagefile/FileInputStreamException.java new file mode 100644 index 00000000..f62b1a9d --- /dev/null +++ b/src/main/java/com/recordit/server/exception/imagefile/FileInputStreamException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.imagefile; + +public class FileInputStreamException extends RuntimeException { + public FileInputStreamException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/exception/imagefile/ImageFileExceptionHandler.java b/src/main/java/com/recordit/server/exception/imagefile/ImageFileExceptionHandler.java new file mode 100644 index 00000000..f0c7ef3e --- /dev/null +++ b/src/main/java/com/recordit/server/exception/imagefile/ImageFileExceptionHandler.java @@ -0,0 +1,21 @@ +package com.recordit.server.exception.imagefile; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import com.recordit.server.exception.ErrorMessage; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestControllerAdvice +public class ImageFileExceptionHandler { + + @ExceptionHandler(FileInputStreamException.class) + public ResponseEntity handleFileInputStreamException(FileInputStreamException exception) { + return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY) + .body(ErrorMessage.of(exception, HttpStatus.UNPROCESSABLE_ENTITY)); + } +} From 975c30274a9e861ac1e05e6147ff30ef7e3db316 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 00:16:33 +0900 Subject: [PATCH 124/264] =?UTF-8?q?[BE-85]=20feat:=20S3Configuration?= =?UTF-8?q?=EA=B3=BC=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=EB=A5=BC=20?= =?UTF-8?q?=EC=9D=BD=EC=96=B4=EC=98=A4=EB=8A=94=20S3Properties=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/configuration/S3Configuration.java | 34 +++++++++++++++ .../server/environment/S3Properties.java | 42 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/main/java/com/recordit/server/configuration/S3Configuration.java create mode 100644 src/main/java/com/recordit/server/environment/S3Properties.java diff --git a/src/main/java/com/recordit/server/configuration/S3Configuration.java b/src/main/java/com/recordit/server/configuration/S3Configuration.java new file mode 100644 index 00000000..b13a2b32 --- /dev/null +++ b/src/main/java/com/recordit/server/configuration/S3Configuration.java @@ -0,0 +1,34 @@ +package com.recordit.server.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +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 com.recordit.server.environment.S3Properties; + +import lombok.RequiredArgsConstructor; + +@Configuration +@RequiredArgsConstructor +public class S3Configuration { + + private final S3Properties s3Properties; + + @Bean + public AmazonS3 amazonS3() { + AWSCredentials awsCredentials = new BasicAWSCredentials( + s3Properties.getCredentials().getAccessKey(), + s3Properties.getCredentials().getSecretKey() + ); + + return AmazonS3ClientBuilder + .standard() + .withRegion(s3Properties.getRegion()) + .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) + .build(); + } +} diff --git a/src/main/java/com/recordit/server/environment/S3Properties.java b/src/main/java/com/recordit/server/environment/S3Properties.java new file mode 100644 index 00000000..2338fdda --- /dev/null +++ b/src/main/java/com/recordit/server/environment/S3Properties.java @@ -0,0 +1,42 @@ +package com.recordit.server.environment; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.ConstructorBinding; +import org.springframework.validation.annotation.Validated; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@Validated +@ConstructorBinding +@ConfigurationProperties(prefix = "s3") +@RequiredArgsConstructor +public class S3Properties { + + @NotNull + private final Credentials credentials; + + @NotBlank + private final String bucket; + + @NotBlank + private final String directory; + + @NotBlank + private final String region; + + @Getter + @Validated + @RequiredArgsConstructor + public static final class Credentials { + @NotBlank + private final String accessKey; + + @NotBlank + private final String secretKey; + } +} From a3e930716d74f7f6eb8b56919648032ec7db3a2b Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 01:11:24 +0900 Subject: [PATCH 125/264] =?UTF-8?q?[BE-85]=20chore:=20application-test.yml?= =?UTF-8?q?=20s3=EA=B4=80=EB=A0=A4=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application-test.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index c8727295..da10b4ca 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -38,4 +38,12 @@ oauth: client-secret: ${OAUTH_GOOGLE_CLIENT_SECRET:} redirect-url: ${OAUTH_GOOGLE_REDIRECT_URL:} token-request-url: https://oauth2.googleapis.com/token - user-info-request-url: https://oauth2.googleapis.com/tokeninfo \ No newline at end of file + user-info-request-url: https://oauth2.googleapis.com/tokeninfo + +s3: + credentials: + access-key: ${S3_ACCESS_KEY:} + secret-key: ${S3_SECRET_ACCESS_KEY:} + bucket: ${S3_BUCKET_NAME:} + directory: ${S3_DIRECTORY_NAME:} + region: ap-northeast-2 From 0876be5ef87599c048bafdf4ed56e4fd81aeed80 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 01:12:10 +0900 Subject: [PATCH 126/264] =?UTF-8?q?[BE-85]=20feat:=20S3=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EB=B0=8F=20URL=EC=9D=84=20=EB=B0=9B?= =?UTF-8?q?=EC=95=84=EC=98=A4=EB=8A=94=20S3Uploader=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/util/S3Uploader.java | 54 +++++++++++ .../recordit/server/util/S3UploaderTest.java | 89 +++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 src/main/java/com/recordit/server/util/S3Uploader.java create mode 100644 src/test/java/com/recordit/server/util/S3UploaderTest.java diff --git a/src/main/java/com/recordit/server/util/S3Uploader.java b/src/main/java/com/recordit/server/util/S3Uploader.java new file mode 100644 index 00000000..983bf360 --- /dev/null +++ b/src/main/java/com/recordit/server/util/S3Uploader.java @@ -0,0 +1,54 @@ +package com.recordit.server.util; + +import java.io.IOException; +import java.util.UUID; + +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.ObjectMetadata; +import com.amazonaws.services.s3.model.PutObjectRequest; +import com.recordit.server.environment.S3Properties; +import com.recordit.server.exception.imagefile.FileInputStreamException; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +public class S3Uploader { + + private final AmazonS3 amazonS3; + private final S3Properties s3Properties; + + public String upload(@NonNull MultipartFile multipartFile) { + String fileName = UUID.randomUUID().toString(); + try { + amazonS3.putObject( + new PutObjectRequest( + s3Properties.getBucket(), + fileName, + multipartFile.getInputStream(), + getObjectMetadataBy(multipartFile) + ).withCannedAcl(CannedAccessControlList.PublicRead) + ); + } catch (IOException e) { + throw new FileInputStreamException("해당 파일을 읽어올 수 없습니다."); + } + return fileName; + } + + public String getUrlByFileName(String fileName) { + return amazonS3.getUrl(s3Properties.getBucket(), fileName).toString(); + } + + private ObjectMetadata getObjectMetadataBy(@NonNull MultipartFile multipartFile) { + ObjectMetadata objectMetadata = new ObjectMetadata(); + objectMetadata.setContentLength(multipartFile.getSize()); + objectMetadata.setContentType(multipartFile.getContentType()); + return objectMetadata; + } + +} diff --git a/src/test/java/com/recordit/server/util/S3UploaderTest.java b/src/test/java/com/recordit/server/util/S3UploaderTest.java new file mode 100644 index 00000000..cf683dff --- /dev/null +++ b/src/test/java/com/recordit/server/util/S3UploaderTest.java @@ -0,0 +1,89 @@ +package com.recordit.server.util; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.io.IOException; +import java.util.UUID; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.mock.web.MockMultipartFile; + +import com.amazonaws.services.s3.AmazonS3; +import com.recordit.server.environment.S3Properties; +import com.recordit.server.exception.imagefile.FileInputStreamException; + +@ExtendWith(MockitoExtension.class) +class S3UploaderTest { + + @InjectMocks + private S3Uploader s3Uploader; + + @Mock + private AmazonS3 amazonS3; + + @Mock + private S3Properties s3Properties; + + @Mock + private MockMultipartFile multipartFile; + + private MockedStatic mockUUID; + + private final UUID testUUID = UUID.randomUUID(); + + @BeforeEach + void init() { + mockUUID = mockStatic(UUID.class); + given(s3Properties.getBucket()) + .willReturn("testBucket"); + } + + @AfterEach + void afterEach() { + mockUUID.close(); + } + + @Nested + @DisplayName("파일을 업로드할 때") + class 파일을_업로드할_때 { + + @Test + @DisplayName("MultipartFile을 읽어올 수 없을 경우 예외를 던진다") + void MultipartFile을_읽어올_수_없을_경우_예외를_던진다() throws Exception { + // given + given(UUID.randomUUID()) + .willReturn(testUUID); + given(multipartFile.getInputStream()) + .willThrow(IOException.class); + + // when, then + assertThatThrownBy(() -> s3Uploader.upload(multipartFile)) + .isInstanceOf(FileInputStreamException.class); + } + + @Test + @DisplayName("정상적으로 읽어올 수 있을 경우 예외를 던지지 않는다") + void 정상적으로_읽어올_수_있을_경우_예외를_던지지_않는다() { + // given + given(UUID.randomUUID()) + .willReturn(testUUID); + + // when + String fileName = s3Uploader.upload(multipartFile); + + // then + assertThat(fileName).isEqualTo(testUUID.toString()); + } + } + +} \ No newline at end of file From 8fbfc70590b08df5477d8c678b107c1ade0414a4 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 01:17:29 +0900 Subject: [PATCH 127/264] =?UTF-8?q?[BE-85]=20refactor:=20imagefile=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=A6=84=EC=9D=84=20fil?= =?UTF-8?q?e=EB=A1=9C=20=EB=B3=80=EA=B2=BD(=ED=9B=84=EC=97=90=20=EB=8B=A4?= =?UTF-8?q?=EB=A5=B8=20=EC=A2=85=EB=A5=98=EC=9D=98=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=9D=84=20=EB=B0=9B=EC=9D=84=20=EC=88=98=20=EC=9E=88=EC=96=B4?= =?UTF-8?q?=EC=84=9C=20=EC=A0=95=ED=99=95=ED=9E=88=20=EB=AA=85=EC=8B=9C?= =?UTF-8?q?=ED=95=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FileExceptionHandler.java} | 4 ++-- .../{imagefile => file}/FileInputStreamException.java | 2 +- src/main/java/com/recordit/server/util/S3Uploader.java | 2 +- src/test/java/com/recordit/server/util/S3UploaderTest.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename src/main/java/com/recordit/server/exception/{imagefile/ImageFileExceptionHandler.java => file/FileExceptionHandler.java} (87%) rename src/main/java/com/recordit/server/exception/{imagefile => file}/FileInputStreamException.java (74%) diff --git a/src/main/java/com/recordit/server/exception/imagefile/ImageFileExceptionHandler.java b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java similarity index 87% rename from src/main/java/com/recordit/server/exception/imagefile/ImageFileExceptionHandler.java rename to src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java index f0c7ef3e..cb0450b5 100644 --- a/src/main/java/com/recordit/server/exception/imagefile/ImageFileExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java @@ -1,4 +1,4 @@ -package com.recordit.server.exception.imagefile; +package com.recordit.server.exception.file; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -11,7 +11,7 @@ @Slf4j @RestControllerAdvice -public class ImageFileExceptionHandler { +public class FileExceptionHandler { @ExceptionHandler(FileInputStreamException.class) public ResponseEntity handleFileInputStreamException(FileInputStreamException exception) { diff --git a/src/main/java/com/recordit/server/exception/imagefile/FileInputStreamException.java b/src/main/java/com/recordit/server/exception/file/FileInputStreamException.java similarity index 74% rename from src/main/java/com/recordit/server/exception/imagefile/FileInputStreamException.java rename to src/main/java/com/recordit/server/exception/file/FileInputStreamException.java index f62b1a9d..140d149b 100644 --- a/src/main/java/com/recordit/server/exception/imagefile/FileInputStreamException.java +++ b/src/main/java/com/recordit/server/exception/file/FileInputStreamException.java @@ -1,4 +1,4 @@ -package com.recordit.server.exception.imagefile; +package com.recordit.server.exception.file; public class FileInputStreamException extends RuntimeException { public FileInputStreamException(String message) { diff --git a/src/main/java/com/recordit/server/util/S3Uploader.java b/src/main/java/com/recordit/server/util/S3Uploader.java index 983bf360..5330605c 100644 --- a/src/main/java/com/recordit/server/util/S3Uploader.java +++ b/src/main/java/com/recordit/server/util/S3Uploader.java @@ -11,7 +11,7 @@ import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; import com.recordit.server.environment.S3Properties; -import com.recordit.server.exception.imagefile.FileInputStreamException; +import com.recordit.server.exception.file.FileInputStreamException; import lombok.NonNull; import lombok.RequiredArgsConstructor; diff --git a/src/test/java/com/recordit/server/util/S3UploaderTest.java b/src/test/java/com/recordit/server/util/S3UploaderTest.java index cf683dff..c9d00a25 100644 --- a/src/test/java/com/recordit/server/util/S3UploaderTest.java +++ b/src/test/java/com/recordit/server/util/S3UploaderTest.java @@ -20,7 +20,7 @@ import com.amazonaws.services.s3.AmazonS3; import com.recordit.server.environment.S3Properties; -import com.recordit.server.exception.imagefile.FileInputStreamException; +import com.recordit.server.exception.file.FileInputStreamException; @ExtendWith(MockitoExtension.class) class S3UploaderTest { From 39e6c1dcc03fe735cfcd29ba2db285d65a1fb72e Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 12:43:23 +0900 Subject: [PATCH 128/264] =?UTF-8?q?[BE-87]=20fix:=20=EA=B0=9C=EB=B0=9C?= =?UTF-8?q?=EC=9A=A9=20cors=20=EA=B0=9C=EB=B0=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/WebMvcConfiguration.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java diff --git a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java new file mode 100644 index 00000000..e66d83cd --- /dev/null +++ b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java @@ -0,0 +1,21 @@ +package com.recordit.server.configuration; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebMvcConfiguration implements WebMvcConfigurer { + + private final long MAX_AGE_SECS = 3000; + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOriginPatterns("*") + .allowedMethods("*") + .allowedHeaders("*") + .allowCredentials(true) + .maxAge(MAX_AGE_SECS); + } +} From cac7011659881e47e399f67d73c2652a82b7fd8b Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 12:58:07 +0900 Subject: [PATCH 129/264] =?UTF-8?q?[BE-85]=20refactor:=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=20=EC=9D=B4=EB=A6=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/util/S3Uploader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/util/S3Uploader.java b/src/main/java/com/recordit/server/util/S3Uploader.java index 5330605c..64d3f575 100644 --- a/src/main/java/com/recordit/server/util/S3Uploader.java +++ b/src/main/java/com/recordit/server/util/S3Uploader.java @@ -29,7 +29,7 @@ public String upload(@NonNull MultipartFile multipartFile) { amazonS3.putObject( new PutObjectRequest( s3Properties.getBucket(), - fileName, + s3Properties.getDirectory() + "/" + fileName, multipartFile.getInputStream(), getObjectMetadataBy(multipartFile) ).withCannedAcl(CannedAccessControlList.PublicRead) @@ -41,7 +41,7 @@ public String upload(@NonNull MultipartFile multipartFile) { } public String getUrlByFileName(String fileName) { - return amazonS3.getUrl(s3Properties.getBucket(), fileName).toString(); + return amazonS3.getUrl(s3Properties.getBucket(), s3Properties.getDirectory() + "/" + fileName).toString(); } private ObjectMetadata getObjectMetadataBy(@NonNull MultipartFile multipartFile) { From 7b0a0ec862d20fe188d668ccf1d828e6ec44e8d2 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 28 Dec 2022 16:37:23 +0900 Subject: [PATCH 130/264] =?UTF-8?q?[BE-84]=20test:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1,=20=EB=A0=88=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/RecordServiceTest.java | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 src/test/java/com/recordit/server/service/RecordServiceTest.java diff --git a/src/test/java/com/recordit/server/service/RecordServiceTest.java b/src/test/java/com/recordit/server/service/RecordServiceTest.java new file mode 100644 index 00000000..89e8ca65 --- /dev/null +++ b/src/test/java/com/recordit/server/service/RecordServiceTest.java @@ -0,0 +1,190 @@ +package com.recordit.server.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.util.Optional; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.web.multipart.MultipartFile; + +import com.recordit.server.domain.Member; +import com.recordit.server.domain.RecordCategory; +import com.recordit.server.domain.RecordColor; +import com.recordit.server.domain.RecordIcon; +import com.recordit.server.dto.record.WriteRecordRequestDto; +import com.recordit.server.exception.member.MemberNotFoundException; +import com.recordit.server.exception.record.RecordColorNotFoundException; +import com.recordit.server.exception.record.RecordIconNotFoundException; +import com.recordit.server.exception.record.category.RecordCategoryNotFoundException; +import com.recordit.server.repository.ImageFileRepository; +import com.recordit.server.repository.MemberRepository; +import com.recordit.server.repository.RecordCategoryRepository; +import com.recordit.server.repository.RecordColorRepository; +import com.recordit.server.repository.RecordIconRepository; +import com.recordit.server.repository.RecordRepository; +import com.recordit.server.util.SessionUtil; + +@ExtendWith(MockitoExtension.class) +@ActiveProfiles("test") +class RecordServiceTest { + @InjectMocks + private RecordService recordService; + + @Mock + private ImageFileRepository imageFileRepository; + + @Mock + private SessionUtil sessionUtil; + + @Mock + private MemberRepository memberRepository; + + @Mock + private RecordCategoryRepository recordCategoryRepository; + + @Mock + private RecordColorRepository recordColorRepository; + + @Mock + private RecordIconRepository recordIconRepository; + + @Mock + private RecordRepository recordRepository; + + @Mock + private Member mockMember; + + @Mock + private RecordCategory mockRecordCategory; + + @Mock + private RecordColor mockRecordColor; + + @Mock + private RecordIcon mockRecordIcon; + + @Nested + @DisplayName("레코드를 작성 할 때") + class 레코드를_작성_할_때 { + private final Long recordCategoryId = 10L; + private final String title = "오늘 내 생일이야!"; + private final String content = "오늘은 내 20번째 생일입니다. \n모두 축하와 선물을 준비해 주세요."; + private final String colorName = "icon-purple"; + private final String iconName = "moon"; + private MultipartFile emptyFile = new MockMultipartFile("비어있는 파일", new byte[0]); + private MultipartFile notEmptyFile = new MockMultipartFile("비어있지 않은 파일", new byte[10]); + + private final WriteRecordRequestDto writeRecordRequestDto = WriteRecordRequestDto.builder() + .recordCategoryId(recordCategoryId) + .title(title) + .content(content) + .colorName(colorName) + .iconName(iconName) + .build(); + + @Nested + @DisplayName("회원 정보를") + class 회원_정보를 { + + @Test + @DisplayName("찾을 수 없다면 예외를 던진다") + void 찾을_수_없다면_예외를_던진다() { + // given + given(memberRepository.findById(anyLong())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + .isInstanceOf(MemberNotFoundException.class) + .hasMessage("회원 정보를 찾을 수 없습니다."); + } + } + + @Nested + @DisplayName("카테고리 정보를") + class 카테고리_정보를 { + @Test + @DisplayName("찾을 수 없다면 예외를 던진다") + void 찾을_수_없다면_예외를_던진다() { + given(memberRepository.findById(anyLong())) + .willReturn(Optional.of(mockMember)); + given(recordCategoryRepository.findById(anyLong())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + .isInstanceOf(RecordCategoryNotFoundException.class) + .hasMessage("카테고리 정보를 찾을 수 없습니다."); + } + } + + @Nested + @DisplayName("컬러 정보를") + class 컬러_정보를 { + @Test + @DisplayName("찾을 수 없다면 예외를 던진다") + void 찾을_수_없다면_예외를_던진다() { + given(memberRepository.findById(anyLong())) + .willReturn(Optional.of(mockMember)); + given(recordCategoryRepository.findById(anyLong())) + .willReturn(Optional.of(mockRecordCategory)); + given(recordColorRepository.findByName(anyString())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + .isInstanceOf(RecordColorNotFoundException.class) + .hasMessage("컬러 정보를 찾을 수 없습니다."); + } + } + + @Nested + @DisplayName("아이콘 정보를") + class 아이콘_정보를 { + @Test + @DisplayName("찾을 수 없다면 예외를 던진다") + void 찾을_수_없다면_예외를_던진다() { + given(memberRepository.findById(anyLong())) + .willReturn(Optional.of(mockMember)); + given(recordCategoryRepository.findById(anyLong())) + .willReturn(Optional.of(mockRecordCategory)); + given(recordColorRepository.findByName(anyString())) + .willReturn(Optional.of(mockRecordColor)); + given(recordIconRepository.findByName(anyString())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + .isInstanceOf(RecordIconNotFoundException.class) + .hasMessage("아이콘 정보를 찾을 수 없습니다."); + } + } + + @Test + @DisplayName("입력_정보가_올바르다면 예외를 던지지 않는다") + void 입력_정보가_올바르다면_예외를_던지지_않는다() { + // given + given(memberRepository.findById(anyLong())) + .willReturn(Optional.of(mockMember)); + given(recordCategoryRepository.findById(anyLong())) + .willReturn(Optional.of(mockRecordCategory)); + given(recordColorRepository.findByName(anyString())) + .willReturn(Optional.of(mockRecordColor)); + given(recordIconRepository.findByName(anyString())) + .willReturn(Optional.of(mockRecordIcon)); + + // when, then + assertThatCode(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + .doesNotThrowAnyException(); + } + } +} \ No newline at end of file From d24417725c1a1ef09cfb73a24eb849fc2e83fd66 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 28 Dec 2022 17:33:20 +0900 Subject: [PATCH 131/264] =?UTF-8?q?[BE-30]=20feat:=20Record=20Exception=20?= =?UTF-8?q?Handler=20=EC=A0=95=EC=9D=98,=20Custom=20Exception=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/MemberNotFoundException.java | 7 ++++ .../record/RecordColorNotFoundException.java | 7 ++++ .../record/RecordExceptionHandler.java | 38 +++++++++++++++++++ .../record/RecordIconNotFoundException.java | 7 ++++ .../record/RecordNotFoundException.java | 7 ++++ .../RecordCategoryNotFoundException.java | 7 ++++ 6 files changed, 73 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/member/MemberNotFoundException.java create mode 100644 src/main/java/com/recordit/server/exception/record/RecordColorNotFoundException.java create mode 100644 src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java create mode 100644 src/main/java/com/recordit/server/exception/record/RecordIconNotFoundException.java create mode 100644 src/main/java/com/recordit/server/exception/record/RecordNotFoundException.java create mode 100644 src/main/java/com/recordit/server/exception/record/category/RecordCategoryNotFoundException.java diff --git a/src/main/java/com/recordit/server/exception/member/MemberNotFoundException.java b/src/main/java/com/recordit/server/exception/member/MemberNotFoundException.java new file mode 100644 index 00000000..fbb312ce --- /dev/null +++ b/src/main/java/com/recordit/server/exception/member/MemberNotFoundException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.member; + +public class MemberNotFoundException extends RuntimeException { + public MemberNotFoundException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/com/recordit/server/exception/record/RecordColorNotFoundException.java b/src/main/java/com/recordit/server/exception/record/RecordColorNotFoundException.java new file mode 100644 index 00000000..b6e04d01 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/record/RecordColorNotFoundException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.record; + +public class RecordColorNotFoundException extends RuntimeException { + public RecordColorNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java b/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java new file mode 100644 index 00000000..61f4cba8 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java @@ -0,0 +1,38 @@ +package com.recordit.server.exception.record; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import com.recordit.server.controller.RecordController; +import com.recordit.server.exception.ErrorMessage; +import com.recordit.server.exception.member.MemberNotFoundException; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestControllerAdvice(basePackageClasses = RecordController.class) +public class RecordExceptionHandler { + @ExceptionHandler(MemberNotFoundException.class) + public ResponseEntity handleMemberNotFoundException( + MemberNotFoundException exception) { + return ResponseEntity.badRequest() + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); + } + + @ExceptionHandler(RecordColorNotFoundException.class) + public ResponseEntity handleRecordColorNotFoundException( + RecordColorNotFoundException exception) { + return ResponseEntity.badRequest() + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); + } + + @ExceptionHandler(RecordNotFoundException.class) + public ResponseEntity handleRecordNotFoundException( + RecordNotFoundException exception) { + return ResponseEntity.badRequest() + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); + } +} + diff --git a/src/main/java/com/recordit/server/exception/record/RecordIconNotFoundException.java b/src/main/java/com/recordit/server/exception/record/RecordIconNotFoundException.java new file mode 100644 index 00000000..e45088f3 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/record/RecordIconNotFoundException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.record; + +public class RecordIconNotFoundException extends RuntimeException { + public RecordIconNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/exception/record/RecordNotFoundException.java b/src/main/java/com/recordit/server/exception/record/RecordNotFoundException.java new file mode 100644 index 00000000..88626dfa --- /dev/null +++ b/src/main/java/com/recordit/server/exception/record/RecordNotFoundException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.record; + +public class RecordNotFoundException extends RuntimeException { + public RecordNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/exception/record/category/RecordCategoryNotFoundException.java b/src/main/java/com/recordit/server/exception/record/category/RecordCategoryNotFoundException.java new file mode 100644 index 00000000..f63ec97c --- /dev/null +++ b/src/main/java/com/recordit/server/exception/record/category/RecordCategoryNotFoundException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.record.category; + +public class RecordCategoryNotFoundException extends RuntimeException { + public RecordCategoryNotFoundException(String message) { + super(message); + } +} From 0c93b5b61e3a7ab49176dfe920b4ea0fe16def56 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 28 Dec 2022 17:33:51 +0900 Subject: [PATCH 132/264] =?UTF-8?q?[BE-30]=20feat:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1,=20=EB=A0=88=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/RecordController.java | 10 ++- .../com/recordit/server/domain/Record.java | 38 ++++++++++ .../dto/record/RecordDetailResponseDto.java | 22 ++++-- .../dto/record/WriteRecordRequestDto.java | 17 +++-- .../repository/ImageFileRepository.java | 8 ++ .../repository/RecordColorRepository.java | 11 +++ .../repository/RecordIconRepository.java | 11 +++ .../server/repository/RecordRepository.java | 6 ++ .../server/service/RecordService.java | 76 +++++++++++++++++++ 9 files changed, 184 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/recordit/server/repository/ImageFileRepository.java create mode 100644 src/main/java/com/recordit/server/repository/RecordColorRepository.java create mode 100644 src/main/java/com/recordit/server/repository/RecordIconRepository.java diff --git a/src/main/java/com/recordit/server/controller/RecordController.java b/src/main/java/com/recordit/server/controller/RecordController.java index 5d26b28e..e15e5907 100644 --- a/src/main/java/com/recordit/server/controller/RecordController.java +++ b/src/main/java/com/recordit/server/controller/RecordController.java @@ -1,7 +1,10 @@ package com.recordit.server.controller; +import java.util.List; + import javax.validation.Valid; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -46,9 +49,10 @@ public class RecordController { @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity writeRecord( @ApiParam(required = true) @RequestPart(required = true) @Valid WriteRecordRequestDto writeRecordRequestDto, - @ApiParam @RequestPart MultipartFile file + @ApiParam @RequestPart(required = false) List files ) { - return null; + recordService.writeRecord(writeRecordRequestDto, files); + return new ResponseEntity<>(HttpStatus.CREATED); } @ApiOperation( @@ -68,7 +72,7 @@ public ResponseEntity writeRecord( @GetMapping("/{recordId}") public ResponseEntity getDetailRecord( @PathVariable("recordId") Long recordId) { - return null; + return ResponseEntity.ok().body(recordService.getDetailRecord(recordId)); } } diff --git a/src/main/java/com/recordit/server/domain/Record.java b/src/main/java/com/recordit/server/domain/Record.java index 6cde2e9a..1b7be6e4 100644 --- a/src/main/java/com/recordit/server/domain/Record.java +++ b/src/main/java/com/recordit/server/domain/Record.java @@ -13,6 +13,8 @@ import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; +import com.recordit.server.dto.record.WriteRecordRequestDto; + import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -54,4 +56,40 @@ public class Record extends BaseEntity { @JoinColumn(name = "RECORD_ICON_ID") private RecordIcon recordIcon; + private Record( + RecordCategory recordCategory, + Member writer, + String title, + String content, + Integer numOfImage, + RecordColor recordColor, + RecordIcon recordIcon + ) { + this.recordCategory = recordCategory; + this.writer = writer; + this.title = title; + this.content = content; + this.numOfImage = numOfImage; + this.recordColor = recordColor; + this.recordIcon = recordIcon; + } + + public static Record of( + WriteRecordRequestDto writeRecordRequestDto, + RecordCategory recordCategory, + Member member, + Integer numOfImage, + RecordColor recordColor, + RecordIcon recordIcon + ) { + return new Record( + recordCategory, + member, + writeRecordRequestDto.getTitle(), + writeRecordRequestDto.getContent(), + numOfImage, + recordColor, + recordIcon + ); + } } diff --git a/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java b/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java index b6293fd2..cadb7538 100644 --- a/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java +++ b/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java @@ -1,6 +1,7 @@ package com.recordit.server.dto.record; import java.time.LocalDateTime; +import java.util.List; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -20,19 +21,28 @@ public class RecordDetailResponseDto { private String title; private String content; - private String hex; + private String writer; + private String colorName; private String iconName; private LocalDateTime createdAt; - private String imageUrl; + private List imageUrls; @Builder - public RecordDetailResponseDto(String title, String content, String hex, String iconName, LocalDateTime createdAt, - String imageUrl) { + public RecordDetailResponseDto( + String title, + String content, + String writer, + String colorName, + String iconName, + LocalDateTime createdAt, + List imageUrls + ) { this.title = title; this.content = content; - this.hex = hex; + this.writer = writer; + this.colorName = colorName; this.iconName = iconName; this.createdAt = createdAt; - this.imageUrl = imageUrl; + this.imageUrls = imageUrls; } } diff --git a/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java b/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java index 15fbed1e..fed8a68d 100644 --- a/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java +++ b/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java @@ -2,7 +2,6 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import com.fasterxml.jackson.databind.PropertyNamingStrategies; @@ -32,18 +31,24 @@ public class WriteRecordRequestDto { @NotBlank(message = "레코드 내용은 빈 값일 수 없습니다.") private String content; - @Pattern(regexp = "^#[A-Z0-9]{6}", message = "'#FFBF00'의 형태로 입력해 주세요.") - private String hex; + @NotBlank(message = "컬러 이름은 빈 값일 수 없습니다.") + private String colorName; - @NotBlank(message = "아이콘이름은 빈 값일 수 없습니다.") + @NotBlank(message = "아이콘 이름은 빈 값일 수 없습니다.") private String iconName; @Builder - public WriteRecordRequestDto(Long recordCategoryId, String title, String content, String hex, String iconName) { + public WriteRecordRequestDto( + Long recordCategoryId, + String title, + String content, + String colorName, + String iconName + ) { this.recordCategoryId = recordCategoryId; this.title = title; this.content = content; - this.hex = hex; + this.colorName = colorName; this.iconName = iconName; } } diff --git a/src/main/java/com/recordit/server/repository/ImageFileRepository.java b/src/main/java/com/recordit/server/repository/ImageFileRepository.java new file mode 100644 index 00000000..f9d5b08a --- /dev/null +++ b/src/main/java/com/recordit/server/repository/ImageFileRepository.java @@ -0,0 +1,8 @@ +package com.recordit.server.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.recordit.server.domain.ImageFile; + +public interface ImageFileRepository extends JpaRepository { +} diff --git a/src/main/java/com/recordit/server/repository/RecordColorRepository.java b/src/main/java/com/recordit/server/repository/RecordColorRepository.java new file mode 100644 index 00000000..ee605036 --- /dev/null +++ b/src/main/java/com/recordit/server/repository/RecordColorRepository.java @@ -0,0 +1,11 @@ +package com.recordit.server.repository; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.recordit.server.domain.RecordColor; + +public interface RecordColorRepository extends JpaRepository { + Optional findByName(String colorName); +} diff --git a/src/main/java/com/recordit/server/repository/RecordIconRepository.java b/src/main/java/com/recordit/server/repository/RecordIconRepository.java new file mode 100644 index 00000000..d8b0ac41 --- /dev/null +++ b/src/main/java/com/recordit/server/repository/RecordIconRepository.java @@ -0,0 +1,11 @@ +package com.recordit.server.repository; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.recordit.server.domain.RecordIcon; + +public interface RecordIconRepository extends JpaRepository { + Optional findByName(String iconName); +} diff --git a/src/main/java/com/recordit/server/repository/RecordRepository.java b/src/main/java/com/recordit/server/repository/RecordRepository.java index 3718590d..251cdfe5 100644 --- a/src/main/java/com/recordit/server/repository/RecordRepository.java +++ b/src/main/java/com/recordit/server/repository/RecordRepository.java @@ -1,8 +1,14 @@ package com.recordit.server.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import com.recordit.server.domain.Record; public interface RecordRepository extends JpaRepository { + @Query("select r from RECORD r join fetch r.writer join fetch r.recordColor join fetch r.recordIcon" + + " where r.id = :id") + Optional findById(Long id); } diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 34448c32..32c0b7bd 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -1,13 +1,89 @@ package com.recordit.server.service; +import java.util.List; + import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import com.recordit.server.domain.Member; +import com.recordit.server.domain.Record; +import com.recordit.server.domain.RecordCategory; +import com.recordit.server.domain.RecordColor; +import com.recordit.server.domain.RecordIcon; +import com.recordit.server.dto.record.RecordDetailResponseDto; +import com.recordit.server.dto.record.WriteRecordRequestDto; +import com.recordit.server.exception.member.MemberNotFoundException; +import com.recordit.server.exception.record.RecordColorNotFoundException; +import com.recordit.server.exception.record.RecordIconNotFoundException; +import com.recordit.server.exception.record.RecordNotFoundException; +import com.recordit.server.exception.record.category.RecordCategoryNotFoundException; +import com.recordit.server.repository.ImageFileRepository; +import com.recordit.server.repository.MemberRepository; +import com.recordit.server.repository.RecordCategoryRepository; +import com.recordit.server.repository.RecordColorRepository; +import com.recordit.server.repository.RecordIconRepository; import com.recordit.server.repository.RecordRepository; +import com.recordit.server.util.SessionUtil; import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor public class RecordService { + private final ImageFileRepository imageFileRepository; + private final SessionUtil sessionUtil; + private final MemberRepository memberRepository; + private final RecordCategoryRepository recordCategoryRepository; + private final RecordColorRepository recordColorRepository; + private final RecordIconRepository recordIconRepository; private final RecordRepository recordRepository; + + @Transactional + public void writeRecord(WriteRecordRequestDto writeRecordRequestDto, List files) { + List urls = List.of(); + // if (!file.isEmpty()) { // 파일 데이터가 존재할 때 + // /* todo + // 1.이미지 저장 후 url 가져오기 + // 2.imageFileRepository에 save + // 3.numOfImage에 file 개수 대입 (개발 초기 단계에는 1개만 가능) + // */ + // } + sessionUtil.saveUserIdInSession(1L); + Long userIdBySession = sessionUtil.findUserIdBySession(); + Member member = memberRepository.findById(userIdBySession) + .orElseThrow(() -> new MemberNotFoundException("회원 정보를 찾을 수 없습니다.")); + + RecordCategory recordCategory = recordCategoryRepository.findById(writeRecordRequestDto.getRecordCategoryId()) + .orElseThrow(() -> new RecordCategoryNotFoundException("카테고리 정보를 찾을 수 없습니다.")); + + RecordColor recordColor = recordColorRepository.findByName(writeRecordRequestDto.getColorName()) + .orElseThrow(() -> new RecordColorNotFoundException("컬러 정보를 찾을 수 없습니다.")); + + RecordIcon recordIcon = recordIconRepository.findByName(writeRecordRequestDto.getIconName()) + .orElseThrow(() -> new RecordIconNotFoundException("아이콘 정보를 찾을 수 없습니다.")); + + Record record = Record.of(writeRecordRequestDto, recordCategory, member, + urls.size(), recordColor, recordIcon); + recordRepository.save(record); + } + + @Transactional(readOnly = true) + public RecordDetailResponseDto getDetailRecord(Long recordId) { + Record record = recordRepository.findById(recordId) + .orElseThrow(() -> new RecordNotFoundException("레코드 정보를 찾을 수 없습니다.")); + + List imageUrls = List.of(); + // List urls = imageFileService.findByRecordId(record.getId(), record.getNumOfImage()); + + return RecordDetailResponseDto.builder() + .title(record.getTitle()) + .content(record.getContent()) + .writer(record.getWriter().getNickname()) + .colorName(record.getRecordColor().getName()) + .iconName(record.getRecordIcon().getName()) + .createdAt(record.getCreatedAt()) + .imageUrls(imageUrls) + .build(); + } } From c113a18aafdbd4ec9e0cce56d2939d969eccaf62 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 18:33:45 +0900 Subject: [PATCH 133/264] =?UTF-8?q?[BE-90]=20refactor:=20ImageFile?= =?UTF-8?q?=EC=97=90=20=EC=BB=AC=EB=9F=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/ImageFile.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/ImageFile.java b/src/main/java/com/recordit/server/domain/ImageFile.java index 9ecb7865..f6e2e278 100644 --- a/src/main/java/com/recordit/server/domain/ImageFile.java +++ b/src/main/java/com/recordit/server/domain/ImageFile.java @@ -56,10 +56,4 @@ public class ImageFile extends BaseEntity { @Column(name = "SIZE") private Integer size; - @Column(name = "REGISTER_IP") - private String registerIp; - - @Column(name = "DOWNLOAD_COUNT") - private Integer downloadCount; - } From 2edec645736c7df4ab304222a9a7c446243da986 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 18:46:12 +0900 Subject: [PATCH 134/264] =?UTF-8?q?[BE-89]=20feat:=20EmptyFileException,?= =?UTF-8?q?=20FileContentTypeNotAllowedException=EC=99=80=20FileExceptionH?= =?UTF-8?q?andler=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/exception/file/EmptyFileException.java | 7 +++++++ .../file/FileContentTypeNotAllowedException.java | 7 +++++++ .../server/exception/file/FileExceptionHandler.java | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/file/EmptyFileException.java create mode 100644 src/main/java/com/recordit/server/exception/file/FileContentTypeNotAllowedException.java diff --git a/src/main/java/com/recordit/server/exception/file/EmptyFileException.java b/src/main/java/com/recordit/server/exception/file/EmptyFileException.java new file mode 100644 index 00000000..18642358 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/file/EmptyFileException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.file; + +public class EmptyFileException extends RuntimeException { + public EmptyFileException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/exception/file/FileContentTypeNotAllowedException.java b/src/main/java/com/recordit/server/exception/file/FileContentTypeNotAllowedException.java new file mode 100644 index 00000000..d1e00c1f --- /dev/null +++ b/src/main/java/com/recordit/server/exception/file/FileContentTypeNotAllowedException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.file; + +public class FileContentTypeNotAllowedException extends RuntimeException { + public FileContentTypeNotAllowedException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java index cb0450b5..fd7f0260 100644 --- a/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java @@ -18,4 +18,17 @@ public ResponseEntity handleFileInputStreamException(FileInputStre return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY) .body(ErrorMessage.of(exception, HttpStatus.UNPROCESSABLE_ENTITY)); } + + @ExceptionHandler(EmptyFileException.class) + public ResponseEntity handleEmptyFileException(EmptyFileException exception) { + return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY) + .body(ErrorMessage.of(exception, HttpStatus.UNPROCESSABLE_ENTITY)); + } + + @ExceptionHandler(FileContentTypeNotAllowedException.class) + public ResponseEntity handleFileContentTypeNotAllowedException( + FileContentTypeNotAllowedException exception) { + return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY) + .body(ErrorMessage.of(exception, HttpStatus.UNPROCESSABLE_ENTITY)); + } } From b9c7bc03321c5ff532793ef6b982619d7087837d Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 18:47:19 +0900 Subject: [PATCH 135/264] =?UTF-8?q?[BE-89]=20feat:=20=EC=A0=95=EC=A0=81=20?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=EC=99=80=20=ED=8C=8C=EC=9D=BC=20=EC=82=AC=EC=9D=B4=EC=A6=88=20?= =?UTF-8?q?Long=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/domain/ImageFile.java | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/domain/ImageFile.java b/src/main/java/com/recordit/server/domain/ImageFile.java index f6e2e278..50c14d28 100644 --- a/src/main/java/com/recordit/server/domain/ImageFile.java +++ b/src/main/java/com/recordit/server/domain/ImageFile.java @@ -12,6 +12,7 @@ import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; +import org.springframework.web.multipart.MultipartFile; import com.recordit.server.constant.RefType; @@ -54,6 +55,41 @@ public class ImageFile extends BaseEntity { private String extension; @Column(name = "SIZE") - private Integer size; + private Long size; + private ImageFile( + RefType refType, + Long refId, + String downloadUrl, + String originalName, + String saveName, + String extension, + Long size + ) { + this.refType = refType; + this.refId = refId; + this.downloadUrl = downloadUrl; + this.originalName = originalName; + this.saveName = saveName; + this.extension = extension; + this.size = size; + } + + public static ImageFile of( + RefType refType, + Long refId, + MultipartFile multipartFile, + String saveName, + String saveImageUrl + ) { + return new ImageFile( + refType, + refId, + saveImageUrl, + multipartFile.getOriginalFilename(), + saveName, + multipartFile.getOriginalFilename().substring(multipartFile.getOriginalFilename().lastIndexOf(".")), + multipartFile.getSize() + ); + } } From 01b3c914b1885798200ae9100ec4d1a3e647ea06 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 18:47:27 +0900 Subject: [PATCH 136/264] =?UTF-8?q?[BE-89]=20feat:=20ImageFileRepository?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/repository/ImageFileRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/com/recordit/server/repository/ImageFileRepository.java diff --git a/src/main/java/com/recordit/server/repository/ImageFileRepository.java b/src/main/java/com/recordit/server/repository/ImageFileRepository.java new file mode 100644 index 00000000..f9d5b08a --- /dev/null +++ b/src/main/java/com/recordit/server/repository/ImageFileRepository.java @@ -0,0 +1,8 @@ +package com.recordit.server.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.recordit.server.domain.ImageFile; + +public interface ImageFileRepository extends JpaRepository { +} From c507648739ab30053fa209687650831ae8a0d995 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 28 Dec 2022 18:50:23 +0900 Subject: [PATCH 137/264] =?UTF-8?q?[BE-89]=20fix:=20ImageFile=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=99=95=EC=9E=A5=EC=9E=90=20=EC=96=BB=EC=96=B4?= =?UTF-8?q?=EC=98=A4=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/ImageFile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/domain/ImageFile.java b/src/main/java/com/recordit/server/domain/ImageFile.java index 50c14d28..2c708671 100644 --- a/src/main/java/com/recordit/server/domain/ImageFile.java +++ b/src/main/java/com/recordit/server/domain/ImageFile.java @@ -88,7 +88,7 @@ public static ImageFile of( saveImageUrl, multipartFile.getOriginalFilename(), saveName, - multipartFile.getOriginalFilename().substring(multipartFile.getOriginalFilename().lastIndexOf(".")), + multipartFile.getOriginalFilename().substring(multipartFile.getOriginalFilename().lastIndexOf(".") + 1), multipartFile.getSize() ); } From 2cf41a52b2a243c73f33e5c23d265425ca24b78f Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 00:55:19 +0900 Subject: [PATCH 138/264] =?UTF-8?q?[BE-84]=20fix:=20=EB=82=B4=EB=B6=80=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0=ED=95=98?= =?UTF-8?q?=EA=B3=A0=20=EB=B0=96=EC=9C=BC=EB=A1=9C=20=EB=85=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/RecordServiceTest.java | 123 ++++++++---------- 1 file changed, 53 insertions(+), 70 deletions(-) diff --git a/src/test/java/com/recordit/server/service/RecordServiceTest.java b/src/test/java/com/recordit/server/service/RecordServiceTest.java index 89e8ca65..b276ab4c 100644 --- a/src/test/java/com/recordit/server/service/RecordServiceTest.java +++ b/src/test/java/com/recordit/server/service/RecordServiceTest.java @@ -91,82 +91,65 @@ class 레코드를_작성_할_때 { .iconName(iconName) .build(); - @Nested - @DisplayName("회원 정보를") - class 회원_정보를 { - - @Test - @DisplayName("찾을 수 없다면 예외를 던진다") - void 찾을_수_없다면_예외를_던진다() { - // given - given(memberRepository.findById(anyLong())) - .willReturn(Optional.empty()); - - // when, then - assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) - .isInstanceOf(MemberNotFoundException.class) - .hasMessage("회원 정보를 찾을 수 없습니다."); - } + @Test + @DisplayName("회원_정보를_찾을 수 없다면 예외를 던진다") + void 회원_정보를_찾을_수_없다면_예외를_던진다() { + // given + given(memberRepository.findById(anyLong())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + .isInstanceOf(MemberNotFoundException.class) + .hasMessage("회원 정보를 찾을 수 없습니다."); } - @Nested - @DisplayName("카테고리 정보를") - class 카테고리_정보를 { - @Test - @DisplayName("찾을 수 없다면 예외를 던진다") - void 찾을_수_없다면_예외를_던진다() { - given(memberRepository.findById(anyLong())) - .willReturn(Optional.of(mockMember)); - given(recordCategoryRepository.findById(anyLong())) - .willReturn(Optional.empty()); - - // when, then - assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) - .isInstanceOf(RecordCategoryNotFoundException.class) - .hasMessage("카테고리 정보를 찾을 수 없습니다."); - } + @Test + @DisplayName("카테고리_정보를_찾을 수 없다면 예외를 던진다") + void 카테고리_정보를_찾을_수_없다면_예외를_던진다() { + given(memberRepository.findById(anyLong())) + .willReturn(Optional.of(mockMember)); + given(recordCategoryRepository.findById(anyLong())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + .isInstanceOf(RecordCategoryNotFoundException.class) + .hasMessage("카테고리 정보를 찾을 수 없습니다."); } - @Nested - @DisplayName("컬러 정보를") - class 컬러_정보를 { - @Test - @DisplayName("찾을 수 없다면 예외를 던진다") - void 찾을_수_없다면_예외를_던진다() { - given(memberRepository.findById(anyLong())) - .willReturn(Optional.of(mockMember)); - given(recordCategoryRepository.findById(anyLong())) - .willReturn(Optional.of(mockRecordCategory)); - given(recordColorRepository.findByName(anyString())) - .willReturn(Optional.empty()); - - // when, then - assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) - .isInstanceOf(RecordColorNotFoundException.class) - .hasMessage("컬러 정보를 찾을 수 없습니다."); - } + @Test + @DisplayName("컬러_정보를_찾을 수 없다면 예외를 던진다") + void 컬러_정보를_찾을_수_없다면_예외를_던진다() { + given(memberRepository.findById(anyLong())) + .willReturn(Optional.of(mockMember)); + given(recordCategoryRepository.findById(anyLong())) + .willReturn(Optional.of(mockRecordCategory)); + given(recordColorRepository.findByName(anyString())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + .isInstanceOf(RecordColorNotFoundException.class) + .hasMessage("컬러 정보를 찾을 수 없습니다."); } - @Nested - @DisplayName("아이콘 정보를") - class 아이콘_정보를 { - @Test - @DisplayName("찾을 수 없다면 예외를 던진다") - void 찾을_수_없다면_예외를_던진다() { - given(memberRepository.findById(anyLong())) - .willReturn(Optional.of(mockMember)); - given(recordCategoryRepository.findById(anyLong())) - .willReturn(Optional.of(mockRecordCategory)); - given(recordColorRepository.findByName(anyString())) - .willReturn(Optional.of(mockRecordColor)); - given(recordIconRepository.findByName(anyString())) - .willReturn(Optional.empty()); - - // when, then - assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) - .isInstanceOf(RecordIconNotFoundException.class) - .hasMessage("아이콘 정보를 찾을 수 없습니다."); - } + @Test + @DisplayName("아이콘 정보를 찾을 수 없다면 예외를 던진다") + void 아이콘_정보를_찾을_수_없다면_예외를_던진다() { + given(memberRepository.findById(anyLong())) + .willReturn(Optional.of(mockMember)); + given(recordCategoryRepository.findById(anyLong())) + .willReturn(Optional.of(mockRecordCategory)); + given(recordColorRepository.findByName(anyString())) + .willReturn(Optional.of(mockRecordColor)); + given(recordIconRepository.findByName(anyString())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + .isInstanceOf(RecordIconNotFoundException.class) + .hasMessage("아이콘 정보를 찾을 수 없습니다."); } @Test From 3936d6b4f23a13f41e46c541015544f504d285ea Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 01:14:34 +0900 Subject: [PATCH 139/264] =?UTF-8?q?[BE-84]=20test:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/RecordServiceTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/test/java/com/recordit/server/service/RecordServiceTest.java b/src/test/java/com/recordit/server/service/RecordServiceTest.java index b276ab4c..33877a9c 100644 --- a/src/test/java/com/recordit/server/service/RecordServiceTest.java +++ b/src/test/java/com/recordit/server/service/RecordServiceTest.java @@ -17,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile; import com.recordit.server.domain.Member; +import com.recordit.server.domain.Record; import com.recordit.server.domain.RecordCategory; import com.recordit.server.domain.RecordColor; import com.recordit.server.domain.RecordIcon; @@ -72,6 +73,9 @@ class RecordServiceTest { @Mock private RecordIcon mockRecordIcon; + @Mock + private Record mockRecord; + @Nested @DisplayName("레코드를 작성 할 때") class 레코드를_작성_할_때 { @@ -170,4 +174,42 @@ class 레코드를_작성_할_때 { .doesNotThrowAnyException(); } } + + @Nested + @DisplayName("레코드를 단건 조회 할 때") + class 레코드를_단건_조회_할_때 { + @Test + @DisplayName("레코드 정보를 찾을 수 없다면 예외를 던진다") + void 레코드_정보를_찾을_수_없다면_예외를_던진다() { + // given + given(recordRepository.findById(anyLong())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> recordService.getDetailRecord(234L)) + .isInstanceOf(RecordNotFoundException.class) + .hasMessage("레코드 정보를 찾을 수 없습니다."); + } + + @Test + @DisplayName("레코드 정보를 찾을 수 있다면 예외를 던지지 않는다") + void 레코드_정보를_찾을_수_있다면_예외를_던지지_않는다() { + // given + given(mockRecord.getWriter()).willReturn(mockMember); + given(mockMember.getNickname()).willReturn("히니"); + + given(mockRecord.getRecordColor()).willReturn(mockRecordColor); + given(mockRecordColor.getName()).willReturn("icon-pink"); + + given(mockRecord.getRecordIcon()).willReturn(mockRecordIcon); + given(mockRecordIcon.getName()).willReturn("umbrella"); + + given(recordRepository.findById(anyLong())) + .willReturn(Optional.of(mockRecord)); + + // when, then + assertThatCode(() -> recordService.getDetailRecord(5421L)) + .doesNotThrowAnyException(); + } + } } \ No newline at end of file From c2332702b365c392789f901f0e34b9cc6887a247 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 12:37:02 +0900 Subject: [PATCH 140/264] =?UTF-8?q?[BE-30]=20fix:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EA=B2=B0=EA=B3=BC=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?fetch=20join=20=EC=A0=81=EC=9A=A9=ED=95=B4=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/repository/RecordRepository.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/repository/RecordRepository.java b/src/main/java/com/recordit/server/repository/RecordRepository.java index 251cdfe5..b140e6af 100644 --- a/src/main/java/com/recordit/server/repository/RecordRepository.java +++ b/src/main/java/com/recordit/server/repository/RecordRepository.java @@ -3,12 +3,11 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import com.recordit.server.domain.Record; public interface RecordRepository extends JpaRepository { - @Query("select r from RECORD r join fetch r.writer join fetch r.recordColor join fetch r.recordIcon" - + " where r.id = :id") + // @Query("select r from RECORD r join fetch r.writer join fetch r.recordColor join fetch r.recordIcon" + // + " where r.id = :id") Optional findById(Long id); } From bb70419ac9306ba786394214eff3a105699af868 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 13:06:07 +0900 Subject: [PATCH 141/264] =?UTF-8?q?[BE-30]=20fix:=20writeRecord=20return?= =?UTF-8?q?=EC=97=90=20id=20=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/RecordController.java | 9 ++++--- .../dto/record/WriteRecordResponseDto.java | 25 +++++++++++++++++++ .../server/service/RecordService.java | 10 ++++++-- 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/recordit/server/dto/record/WriteRecordResponseDto.java diff --git a/src/main/java/com/recordit/server/controller/RecordController.java b/src/main/java/com/recordit/server/controller/RecordController.java index e15e5907..0476ad49 100644 --- a/src/main/java/com/recordit/server/controller/RecordController.java +++ b/src/main/java/com/recordit/server/controller/RecordController.java @@ -17,6 +17,7 @@ import com.recordit.server.dto.record.RecordDetailResponseDto; import com.recordit.server.dto.record.WriteRecordRequestDto; +import com.recordit.server.dto.record.WriteRecordResponseDto; import com.recordit.server.exception.ErrorMessage; import com.recordit.server.service.RecordService; @@ -47,12 +48,14 @@ public class RecordController { ) }) @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) - public ResponseEntity writeRecord( + public ResponseEntity writeRecord( @ApiParam(required = true) @RequestPart(required = true) @Valid WriteRecordRequestDto writeRecordRequestDto, @ApiParam @RequestPart(required = false) List files ) { - recordService.writeRecord(writeRecordRequestDto, files); - return new ResponseEntity<>(HttpStatus.CREATED); + return new ResponseEntity<>( + recordService.writeRecord(writeRecordRequestDto, files), + HttpStatus.CREATED + ); } @ApiOperation( diff --git a/src/main/java/com/recordit/server/dto/record/WriteRecordResponseDto.java b/src/main/java/com/recordit/server/dto/record/WriteRecordResponseDto.java new file mode 100644 index 00000000..bc9eb1bc --- /dev/null +++ b/src/main/java/com/recordit/server/dto/record/WriteRecordResponseDto.java @@ -0,0 +1,25 @@ +package com.recordit.server.dto.record; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class WriteRecordResponseDto { + private Long recordId; + + @Builder + public WriteRecordResponseDto(Long recordId) { + this.recordId = recordId; + } +} diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 32c0b7bd..30db8aa6 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -13,6 +13,7 @@ import com.recordit.server.domain.RecordIcon; import com.recordit.server.dto.record.RecordDetailResponseDto; import com.recordit.server.dto.record.WriteRecordRequestDto; +import com.recordit.server.dto.record.WriteRecordResponseDto; import com.recordit.server.exception.member.MemberNotFoundException; import com.recordit.server.exception.record.RecordColorNotFoundException; import com.recordit.server.exception.record.RecordIconNotFoundException; @@ -40,7 +41,7 @@ public class RecordService { private final RecordRepository recordRepository; @Transactional - public void writeRecord(WriteRecordRequestDto writeRecordRequestDto, List files) { + public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordRequestDto, List files) { List urls = List.of(); // if (!file.isEmpty()) { // 파일 데이터가 존재할 때 // /* todo @@ -65,7 +66,12 @@ public void writeRecord(WriteRecordRequestDto writeRecordRequestDto, List Date: Thu, 29 Dec 2022 13:14:01 +0900 Subject: [PATCH 142/264] =?UTF-8?q?[BE-30]=20fix:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20recordId,=20catego?= =?UTF-8?q?ryId,=20categoryName=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/dto/record/RecordDetailResponseDto.java | 9 +++++++++ .../java/com/recordit/server/service/RecordService.java | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java b/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java index cadb7538..01efcd8b 100644 --- a/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java +++ b/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java @@ -19,6 +19,9 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class RecordDetailResponseDto { + private Long recordId; + private Long categoryId; + private String categoryName; private String title; private String content; private String writer; @@ -29,6 +32,9 @@ public class RecordDetailResponseDto { @Builder public RecordDetailResponseDto( + Long recordId, + Long categoryId, + String categoryName, String title, String content, String writer, @@ -37,6 +43,9 @@ public RecordDetailResponseDto( LocalDateTime createdAt, List imageUrls ) { + this.recordId = recordId; + this.categoryId = categoryId; + this.categoryName = categoryName; this.title = title; this.content = content; this.writer = writer; diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 30db8aa6..24d21fca 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -83,6 +83,9 @@ public RecordDetailResponseDto getDetailRecord(Long recordId) { // List urls = imageFileService.findByRecordId(record.getId(), record.getNumOfImage()); return RecordDetailResponseDto.builder() + .recordId(record.getId()) + .categoryId(record.getRecordCategory().getId()) + .categoryName(record.getRecordCategory().getName()) .title(record.getTitle()) .content(record.getContent()) .writer(record.getWriter().getNickname()) From 0fedc32fdc4823f9ccbbbce3a79aee4aa4a3a00d Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 13:23:17 +0900 Subject: [PATCH 143/264] =?UTF-8?q?[BE-84]=20test,=20fix:=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20categoryI?= =?UTF-8?q?d,=20categoryName=20=EC=B6=94=EA=B0=80=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/service/RecordServiceTest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/recordit/server/service/RecordServiceTest.java b/src/test/java/com/recordit/server/service/RecordServiceTest.java index 33877a9c..76fc1ed8 100644 --- a/src/test/java/com/recordit/server/service/RecordServiceTest.java +++ b/src/test/java/com/recordit/server/service/RecordServiceTest.java @@ -195,6 +195,15 @@ class 레코드를_단건_조회_할_때 { @DisplayName("레코드 정보를 찾을 수 있다면 예외를 던지지 않는다") void 레코드_정보를_찾을_수_있다면_예외를_던지지_않는다() { // given + Long recordId = 5421L; + Long recordCategotyId = 5L; + + given(mockRecord.getId()).willReturn(recordId); + + given(mockRecord.getRecordCategory()).willReturn(mockRecordCategory); + given(mockRecordCategory.getId()).willReturn(recordCategotyId); + given(mockRecordCategory.getName()).willReturn("축하해주세요"); + given(mockRecord.getWriter()).willReturn(mockMember); given(mockMember.getNickname()).willReturn("히니"); @@ -208,7 +217,7 @@ class 레코드를_단건_조회_할_때 { .willReturn(Optional.of(mockRecord)); // when, then - assertThatCode(() -> recordService.getDetailRecord(5421L)) + assertThatCode(() -> recordService.getDetailRecord(recordId)) .doesNotThrowAnyException(); } } From 1736fd7cc8273c6dac036702aea4c4e3d75f2eaa Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 14:22:03 +0900 Subject: [PATCH 144/264] =?UTF-8?q?[BE-30]=20fix:=20ResponseEntity.status?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9,=20findById=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/controller/RecordController.java | 5 +---- .../com/recordit/server/repository/RecordRepository.java | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/RecordController.java b/src/main/java/com/recordit/server/controller/RecordController.java index 0476ad49..8b373eac 100644 --- a/src/main/java/com/recordit/server/controller/RecordController.java +++ b/src/main/java/com/recordit/server/controller/RecordController.java @@ -52,10 +52,7 @@ public ResponseEntity writeRecord( @ApiParam(required = true) @RequestPart(required = true) @Valid WriteRecordRequestDto writeRecordRequestDto, @ApiParam @RequestPart(required = false) List files ) { - return new ResponseEntity<>( - recordService.writeRecord(writeRecordRequestDto, files), - HttpStatus.CREATED - ); + return ResponseEntity.status(HttpStatus.CREATED).body(recordService.writeRecord(writeRecordRequestDto, files)); } @ApiOperation( diff --git a/src/main/java/com/recordit/server/repository/RecordRepository.java b/src/main/java/com/recordit/server/repository/RecordRepository.java index b140e6af..e077bf88 100644 --- a/src/main/java/com/recordit/server/repository/RecordRepository.java +++ b/src/main/java/com/recordit/server/repository/RecordRepository.java @@ -1,7 +1,5 @@ package com.recordit.server.repository; -import java.util.Optional; - import org.springframework.data.jpa.repository.JpaRepository; import com.recordit.server.domain.Record; @@ -9,5 +7,5 @@ public interface RecordRepository extends JpaRepository { // @Query("select r from RECORD r join fetch r.writer join fetch r.recordColor join fetch r.recordIcon" // + " where r.id = :id") - Optional findById(Long id); + // Optional findById(Long id); } From 4b420741b12bd362171f5585e1fff8b1c787f292 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 15:23:45 +0900 Subject: [PATCH 145/264] =?UTF-8?q?[BE-92]=20fix:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1,=20=EB=A0=88=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/RecordServiceTest.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/recordit/server/service/RecordServiceTest.java b/src/test/java/com/recordit/server/service/RecordServiceTest.java index 76fc1ed8..90df410c 100644 --- a/src/test/java/com/recordit/server/service/RecordServiceTest.java +++ b/src/test/java/com/recordit/server/service/RecordServiceTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.BDDMockito.*; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.DisplayName; @@ -12,7 +13,6 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.ActiveProfiles; import org.springframework.web.multipart.MultipartFile; @@ -25,6 +25,7 @@ import com.recordit.server.exception.member.MemberNotFoundException; import com.recordit.server.exception.record.RecordColorNotFoundException; import com.recordit.server.exception.record.RecordIconNotFoundException; +import com.recordit.server.exception.record.RecordNotFoundException; import com.recordit.server.exception.record.category.RecordCategoryNotFoundException; import com.recordit.server.repository.ImageFileRepository; import com.recordit.server.repository.MemberRepository; @@ -84,8 +85,7 @@ class 레코드를_작성_할_때 { private final String content = "오늘은 내 20번째 생일입니다. \n모두 축하와 선물을 준비해 주세요."; private final String colorName = "icon-purple"; private final String iconName = "moon"; - private MultipartFile emptyFile = new MockMultipartFile("비어있는 파일", new byte[0]); - private MultipartFile notEmptyFile = new MockMultipartFile("비어있지 않은 파일", new byte[10]); + private List files = List.of(); private final WriteRecordRequestDto writeRecordRequestDto = WriteRecordRequestDto.builder() .recordCategoryId(recordCategoryId) @@ -103,7 +103,7 @@ class 레코드를_작성_할_때 { .willReturn(Optional.empty()); // when, then - assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, files)) .isInstanceOf(MemberNotFoundException.class) .hasMessage("회원 정보를 찾을 수 없습니다."); } @@ -117,7 +117,7 @@ class 레코드를_작성_할_때 { .willReturn(Optional.empty()); // when, then - assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, files)) .isInstanceOf(RecordCategoryNotFoundException.class) .hasMessage("카테고리 정보를 찾을 수 없습니다."); } @@ -133,7 +133,7 @@ class 레코드를_작성_할_때 { .willReturn(Optional.empty()); // when, then - assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, files)) .isInstanceOf(RecordColorNotFoundException.class) .hasMessage("컬러 정보를 찾을 수 없습니다."); } @@ -151,7 +151,7 @@ class 레코드를_작성_할_때 { .willReturn(Optional.empty()); // when, then - assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + assertThatThrownBy(() -> recordService.writeRecord(writeRecordRequestDto, files)) .isInstanceOf(RecordIconNotFoundException.class) .hasMessage("아이콘 정보를 찾을 수 없습니다."); } @@ -169,8 +169,11 @@ class 레코드를_작성_할_때 { given(recordIconRepository.findByName(anyString())) .willReturn(Optional.of(mockRecordIcon)); + given(recordRepository.save(any())).willReturn(mockRecord); + given(mockRecord.getId()).willReturn(2394L); + // when, then - assertThatCode(() -> recordService.writeRecord(writeRecordRequestDto, emptyFile)) + assertThatCode(() -> recordService.writeRecord(writeRecordRequestDto, files)) .doesNotThrowAnyException(); } } From a498d05aba65dc0488616a77b2a3e437f09bbc30 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 15:52:42 +0900 Subject: [PATCH 146/264] =?UTF-8?q?[BE-91]=20feat:=20GlobalExceptionHandle?= =?UTF-8?q?r=EC=97=90=20Validation=20=EC=98=88=EC=99=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GlobalExceptionHandler.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java diff --git a/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java b/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..0c4ae241 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java @@ -0,0 +1,20 @@ +package com.recordit.server.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler { + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity handleMethodArgumentNotValidException( + MethodArgumentNotValidException exception) { + return ResponseEntity.badRequest() + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); + } +} From 5c7e097502ba9cef3641a27a03b60363c97a4d61 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 17:25:41 +0900 Subject: [PATCH 147/264] =?UTF-8?q?[BE-22]=20feat,=20chore:=20=EB=A1=9C?= =?UTF-8?q?=EA=B9=85=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- src/main/resources/logback-spring.xml | 71 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/logback-spring.xml diff --git a/.gitignore b/.gitignore index e48b6be6..6f3ad35c 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,7 @@ out/ /.nb-gradle/ ### VS Code ### -.vscode/ \ No newline at end of file +.vscode/ + +### Custom ### +logs/ \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..1aac2541 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,71 @@ + + + + + + + %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %magenta(%-5relative) --- [ %thread{10} ] %cyan(%logger{20}) : %msg%n + + + + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %magenta(%-5relative) --- [ %thread{10} ] %cyan(%logger{20}) : %msg%n + UTF-8 + + + + + + ${LOGS_PATH}/RECORD_DEV_INFO.log + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n + UTF-8 + + + + ${LOGS_PATH}/%d{yyyy-MM-dd}_%i.log + + + 10MB + + + 60 + + + + + + ${LOGS_PATH}/RECORD_DEV_ERROR.log + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n + UTF-8 + + + + ${LOGS_PATH}/%d{yyyy-MM-dd}_error.log + 30 + + + + ERROR + + + + + + + + + + + \ No newline at end of file From 1c85985e7318fcde5dd54fe9a81b4d8e1f9e937b Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 29 Dec 2022 17:30:14 +0900 Subject: [PATCH 148/264] =?UTF-8?q?[BE-93]=20refactor:=20=EC=9C=A0?= =?UTF-8?q?=EB=8B=88=ED=81=AC=ED=82=A4=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F=20?= =?UTF-8?q?=EC=9D=B8=EB=8D=B1=EC=8A=A4=20=EC=84=A4=EC=A0=95,=20=EC=A0=95?= =?UTF-8?q?=EC=A0=81=20=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80,=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9D=B4=EC=A6=88=20=ED=83=80=EC=9E=85=EC=9D=84=20Lon?= =?UTF-8?q?g=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/domain/ImageFile.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/ImageFile.java b/src/main/java/com/recordit/server/domain/ImageFile.java index f6e2e278..e5c54ad6 100644 --- a/src/main/java/com/recordit/server/domain/ImageFile.java +++ b/src/main/java/com/recordit/server/domain/ImageFile.java @@ -7,11 +7,12 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Index; import javax.persistence.Table; -import javax.persistence.UniqueConstraint; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; +import org.springframework.web.multipart.MultipartFile; import com.recordit.server.constant.RefType; @@ -20,9 +21,7 @@ import lombok.NoArgsConstructor; @Entity(name = "IMAGE_FILE") -@Table(uniqueConstraints = { - @UniqueConstraint(columnNames = {"REF_TYPE", "REF_ID"}) -}) +@Table(indexes = @Index(columnList = "REF_TYPE, REF_ID")) @NoArgsConstructor(access = AccessLevel.PROTECTED) @Where(clause = "DELETED_AT is null") @SQLDelete(sql = "UPDATE IMAGE_FILE SET IMAGE_FILE.DELETED_AT = CURRENT_TIMESTAMP WHERE IMAGE_FILE.IMAGE_FILE_ID = ?") @@ -54,6 +53,41 @@ public class ImageFile extends BaseEntity { private String extension; @Column(name = "SIZE") - private Integer size; + private Long size; + private ImageFile( + RefType refType, + Long refId, + String downloadUrl, + String originalName, + String saveName, + String extension, + Long size + ) { + this.refType = refType; + this.refId = refId; + this.downloadUrl = downloadUrl; + this.originalName = originalName; + this.saveName = saveName; + this.extension = extension; + this.size = size; + } + + public static ImageFile of( + RefType refType, + Long refId, + String saveUrl, + String saveName, + MultipartFile multipartFile + ) { + return new ImageFile( + refType, + refId, + saveUrl, + multipartFile.getOriginalFilename(), + saveName, + multipartFile.getOriginalFilename().substring(multipartFile.getOriginalFilename().lastIndexOf(".") + 1), + multipartFile.getSize() + ); + } } From 79e13ad90bcb72ec981e9e52c2ca68fea11b197f Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 19:53:47 +0900 Subject: [PATCH 149/264] =?UTF-8?q?[BE-22]=20fix:=20logback=20->=20log4j2?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 8 +++ .../exception/file/FileExceptionHandler.java | 4 +- .../member/MemberExceptionHandler.java | 4 +- .../record/RecordExceptionHandler.java | 4 +- .../redis/RedisExceptionHandler.java | 4 +- src/main/resources/application-dev.yml | 4 +- src/main/resources/application-local.yml | 4 +- src/main/resources/log4j2-dev.xml | 44 ++++++++++++ src/main/resources/log4j2-local.xml | 14 ++++ src/main/resources/logback-spring.xml | 71 ------------------- 10 files changed, 80 insertions(+), 81 deletions(-) create mode 100644 src/main/resources/log4j2-dev.xml create mode 100644 src/main/resources/log4j2-local.xml delete mode 100644 src/main/resources/logback-spring.xml diff --git a/build.gradle b/build.gradle index d3ff97a0..cc84b73d 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,10 @@ configurations { compileOnly { extendsFrom annotationProcessor } + all { + // log4j2를 위해 logback 의존성 제거 + exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' + } } repositories { @@ -47,6 +51,10 @@ dependencies { // use s3 implementation 'com.amazonaws:aws-java-sdk-s3:1.12.372' + + // log4j2 + implementation 'org.springframework.boot:spring-boot-starter-log4j2' + } tasks.named('test') { diff --git a/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java index cb0450b5..6818a617 100644 --- a/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java @@ -7,9 +7,9 @@ import com.recordit.server.exception.ErrorMessage; -import lombok.extern.slf4j.Slf4j; +import lombok.extern.log4j.Log4j2; -@Slf4j +@Log4j2 @RestControllerAdvice public class FileExceptionHandler { diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index f6103443..afc2844d 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -9,9 +9,9 @@ import com.recordit.server.controller.MemberController; import com.recordit.server.exception.ErrorMessage; -import lombok.extern.slf4j.Slf4j; +import lombok.extern.log4j.Log4j2; -@Slf4j +@Log4j2 @RestControllerAdvice(basePackageClasses = MemberController.class) public class MemberExceptionHandler { diff --git a/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java b/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java index 61f4cba8..d2e272be 100644 --- a/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java @@ -9,9 +9,9 @@ import com.recordit.server.exception.ErrorMessage; import com.recordit.server.exception.member.MemberNotFoundException; -import lombok.extern.slf4j.Slf4j; +import lombok.extern.log4j.Log4j2; -@Slf4j +@Log4j2 @RestControllerAdvice(basePackageClasses = RecordController.class) public class RecordExceptionHandler { @ExceptionHandler(MemberNotFoundException.class) diff --git a/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java b/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java index 5b167160..d4cea45a 100644 --- a/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java @@ -7,9 +7,9 @@ import com.recordit.server.exception.ErrorMessage; -import lombok.extern.slf4j.Slf4j; +import lombok.extern.log4j.Log4j2; -@Slf4j +@Log4j2 @RestControllerAdvice public class RedisExceptionHandler { diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 77621018..335d22b7 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -25,4 +25,6 @@ spring: springfox: documentation: swagger: - use-model-v3: false \ No newline at end of file + use-model-v3: false +logging: + config: classpath:log4j2-dev.xml \ No newline at end of file diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 2a22e698..f5482a15 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -25,4 +25,6 @@ spring: springfox: documentation: swagger: - use-model-v3: false \ No newline at end of file + use-model-v3: false +logging: + config: classpath:log4j2-local.xml \ No newline at end of file diff --git a/src/main/resources/log4j2-dev.xml b/src/main/resources/log4j2-dev.xml new file mode 100644 index 00000000..f976b65d --- /dev/null +++ b/src/main/resources/log4j2-dev.xml @@ -0,0 +1,44 @@ + + + + ./logs + recordIt + + + + + + + + + ${LOGS_PATH}/${LOGS_NAME}.log + ${LOGS_PATH}/${LOGS_NAME}.%d{yyyy-MM-dd}.%i.log + + %d{yyyy-MM-dd HH:mm:ss} %5p [%c] %m%n + + + + + + + + ${LOGS_PATH}/ERROR/${LOGS_NAME}_ERROR.log + ${LOGS_PATH}/ERROR/${LOGS_NAME}_ERROR.%d{yyyy-MM-dd}.%i.log + + %d{yyyy-MM-dd HH:mm:ss} %5p [%c] %m%n + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/log4j2-local.xml b/src/main/resources/log4j2-local.xml new file mode 100644 index 00000000..4100e5fc --- /dev/null +++ b/src/main/resources/log4j2-local.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml deleted file mode 100644 index 1aac2541..00000000 --- a/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %magenta(%-5relative) --- [ %thread{10} ] %cyan(%logger{20}) : %msg%n - - - - - - - - - - - - - %d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %magenta(%-5relative) --- [ %thread{10} ] %cyan(%logger{20}) : %msg%n - UTF-8 - - - - - - ${LOGS_PATH}/RECORD_DEV_INFO.log - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n - UTF-8 - - - - ${LOGS_PATH}/%d{yyyy-MM-dd}_%i.log - - - 10MB - - - 60 - - - - - - ${LOGS_PATH}/RECORD_DEV_ERROR.log - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{35} - %msg%n - UTF-8 - - - - ${LOGS_PATH}/%d{yyyy-MM-dd}_error.log - 30 - - - - ERROR - - - - - - - - - - - \ No newline at end of file From 00a4c7b62a7d0f7f0278176e6e5a96e6d8d90ff3 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 21:37:33 +0900 Subject: [PATCH 150/264] =?UTF-8?q?[BE-83]=20feat:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20request=EC=97=90=20Validation=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/dto/member/RegisterRequestDto.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java index 9e794089..b33bd29b 100644 --- a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java +++ b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java @@ -1,5 +1,7 @@ package com.recordit.server.dto.member; +import javax.validation.constraints.Pattern; + import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -22,6 +24,7 @@ public class RegisterRequestDto { private String registerSession; @ApiModelProperty(notes = "사용자 닉네임", required = true) + @Pattern(regexp = "[가-힣a-zA-z0-9]{2,10}") private String nickname; @Builder From a0a5f5af85959f340621dfdd54a4fca78d0f7085 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 21:44:54 +0900 Subject: [PATCH 151/264] =?UTF-8?q?[BE-83]=20feat:=20MemberController=20oa?= =?UTF-8?q?uthRegister=20=EB=A9=94=EC=86=8C=EB=93=9C=EC=97=90=20Valid=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/controller/MemberController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 33750c29..c60e1bee 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -2,6 +2,8 @@ import java.util.Optional; +import javax.validation.Valid; + import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -87,7 +89,7 @@ public ResponseEntity oauthLogin( @PostMapping("/oauth/register/{loginType}") public ResponseEntity oauthRegister( @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") String loginType, - @RequestBody RegisterRequestDto registerRequestDto + @RequestBody @Valid RegisterRequestDto registerRequestDto ) { memberService.oauthRegister(loginType, registerRequestDto); return new ResponseEntity(HttpStatus.OK); From 848707d63be6a35b8f8ec22f6d3f8bc5d77ca28d Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 29 Dec 2022 22:10:39 +0900 Subject: [PATCH 152/264] =?UTF-8?q?[BE-89]=20feat:=20S3=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EB=A1=A4=EB=B0=B1=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20S3ImageRollbackEvent=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/event/S3ImageRollbackEvent.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/com/recordit/server/event/S3ImageRollbackEvent.java diff --git a/src/main/java/com/recordit/server/event/S3ImageRollbackEvent.java b/src/main/java/com/recordit/server/event/S3ImageRollbackEvent.java new file mode 100644 index 00000000..4aa35b8b --- /dev/null +++ b/src/main/java/com/recordit/server/event/S3ImageRollbackEvent.java @@ -0,0 +1,18 @@ +package com.recordit.server.event; + +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +public class S3ImageRollbackEvent { + private final String rollbackFileName; + + private S3ImageRollbackEvent(String rollbackFileName) { + this.rollbackFileName = rollbackFileName; + } + + public static S3ImageRollbackEvent from(String rollbackFileName) { + return new S3ImageRollbackEvent(rollbackFileName); + } +} From d5e21322993eb1e0d413f57574c02f1ca9d840fb Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 29 Dec 2022 22:16:21 +0900 Subject: [PATCH 153/264] =?UTF-8?q?[BE-94]=20feat:=20S3=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/util/S3Uploader.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/recordit/server/util/S3Uploader.java b/src/main/java/com/recordit/server/util/S3Uploader.java index 64d3f575..c5184dae 100644 --- a/src/main/java/com/recordit/server/util/S3Uploader.java +++ b/src/main/java/com/recordit/server/util/S3Uploader.java @@ -40,6 +40,10 @@ public String upload(@NonNull MultipartFile multipartFile) { return fileName; } + public void delete(@NonNull String fileName) { + amazonS3.deleteObject(s3Properties.getBucket(), s3Properties.getDirectory() + "/" + fileName); + } + public String getUrlByFileName(String fileName) { return amazonS3.getUrl(s3Properties.getBucket(), s3Properties.getDirectory() + "/" + fileName).toString(); } From 562f475ff76ac5e8127251d60094deacb5644a6f Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 22:37:45 +0900 Subject: [PATCH 154/264] =?UTF-8?q?[BE-22]=20fix:=20log4j2=20->=20Slf4j=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/exception/file/FileExceptionHandler.java | 4 ++-- .../server/exception/member/MemberExceptionHandler.java | 4 ++-- .../server/exception/record/RecordExceptionHandler.java | 4 ++-- .../server/exception/redis/RedisExceptionHandler.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java index 6818a617..cb0450b5 100644 --- a/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java @@ -7,9 +7,9 @@ import com.recordit.server.exception.ErrorMessage; -import lombok.extern.log4j.Log4j2; +import lombok.extern.slf4j.Slf4j; -@Log4j2 +@Slf4j @RestControllerAdvice public class FileExceptionHandler { diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index afc2844d..f6103443 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -9,9 +9,9 @@ import com.recordit.server.controller.MemberController; import com.recordit.server.exception.ErrorMessage; -import lombok.extern.log4j.Log4j2; +import lombok.extern.slf4j.Slf4j; -@Log4j2 +@Slf4j @RestControllerAdvice(basePackageClasses = MemberController.class) public class MemberExceptionHandler { diff --git a/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java b/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java index d2e272be..61f4cba8 100644 --- a/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/record/RecordExceptionHandler.java @@ -9,9 +9,9 @@ import com.recordit.server.exception.ErrorMessage; import com.recordit.server.exception.member.MemberNotFoundException; -import lombok.extern.log4j.Log4j2; +import lombok.extern.slf4j.Slf4j; -@Log4j2 +@Slf4j @RestControllerAdvice(basePackageClasses = RecordController.class) public class RecordExceptionHandler { @ExceptionHandler(MemberNotFoundException.class) diff --git a/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java b/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java index d4cea45a..5b167160 100644 --- a/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/redis/RedisExceptionHandler.java @@ -7,9 +7,9 @@ import com.recordit.server.exception.ErrorMessage; -import lombok.extern.log4j.Log4j2; +import lombok.extern.slf4j.Slf4j; -@Log4j2 +@Slf4j @RestControllerAdvice public class RedisExceptionHandler { From 690bcb19ea2904be22f933734b386c4fe0b5c9c5 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 29 Dec 2022 22:57:35 +0900 Subject: [PATCH 155/264] =?UTF-8?q?[BE-94]=20feat:=20ImageFileService=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=A0=80=EC=9E=A5,=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EA=B3=BC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/ImageFileService.java | 86 ++++++++++++++++ .../server/service/ImageFileServiceTest.java | 99 +++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 src/main/java/com/recordit/server/service/ImageFileService.java create mode 100644 src/test/java/com/recordit/server/service/ImageFileServiceTest.java diff --git a/src/main/java/com/recordit/server/service/ImageFileService.java b/src/main/java/com/recordit/server/service/ImageFileService.java new file mode 100644 index 00000000..e64dd415 --- /dev/null +++ b/src/main/java/com/recordit/server/service/ImageFileService.java @@ -0,0 +1,86 @@ +package com.recordit.server.service; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.event.TransactionPhase; +import org.springframework.transaction.event.TransactionalEventListener; +import org.springframework.web.multipart.MultipartFile; + +import com.recordit.server.constant.RefType; +import com.recordit.server.domain.ImageFile; +import com.recordit.server.event.S3ImageRollbackEvent; +import com.recordit.server.exception.file.EmptyFileException; +import com.recordit.server.exception.file.FileContentTypeNotAllowedException; +import com.recordit.server.repository.ImageFileRepository; +import com.recordit.server.util.S3Uploader; + +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class ImageFileService { + + private final ImageFileRepository imageFileRepository; + private final S3Uploader s3Uploader; + private final ApplicationEventPublisher applicationEventPublisher; + + @Transactional + public List saveAttachmentFiles( + @NonNull RefType refType, + @NonNull Long refId, + @NonNull List attachments + ) { + List imageUrls = new ArrayList<>(); + for (MultipartFile multipartFile : attachments) { + validateEmptyFile(multipartFile); + validateImageContentType(multipartFile); + + String saveFileName = s3Uploader.upload(multipartFile); + String saveFileUrl = s3Uploader.getUrlByFileName(saveFileName); + applicationEventPublisher.publishEvent(S3ImageRollbackEvent.from(saveFileName)); + + imageFileRepository.save( + ImageFile.of( + refType, + refId, + saveFileUrl, + saveFileName, + multipartFile + ) + ); + imageUrls.add(saveFileUrl); + } + + return imageUrls; + } + + @TransactionalEventListener(classes = S3ImageRollbackEvent.class, phase = TransactionPhase.AFTER_ROLLBACK) + public void handleRollback(S3ImageRollbackEvent event) { + s3Uploader.delete(event.getRollbackFileName()); + } + + @Transactional + public void deleteAttachmentFiles(List attachmentFileNames) { + for (String attachmentFileName : attachmentFileNames) { + s3Uploader.delete(attachmentFileName); + } + } + + private void validateEmptyFile(MultipartFile multipartFile) { + if (multipartFile.isEmpty()) { + throw new EmptyFileException("요청한 파일이 비어있습니다."); + } + } + + private void validateImageContentType(MultipartFile multipartFile) { + if (!multipartFile.getContentType().startsWith("image")) { + throw new FileContentTypeNotAllowedException("이미지 파일이 아닙니다."); + } + } + +} diff --git a/src/test/java/com/recordit/server/service/ImageFileServiceTest.java b/src/test/java/com/recordit/server/service/ImageFileServiceTest.java new file mode 100644 index 00000000..21468fad --- /dev/null +++ b/src/test/java/com/recordit/server/service/ImageFileServiceTest.java @@ -0,0 +1,99 @@ +package com.recordit.server.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.web.multipart.MultipartFile; + +import com.recordit.server.constant.RefType; +import com.recordit.server.exception.file.EmptyFileException; +import com.recordit.server.exception.file.FileContentTypeNotAllowedException; +import com.recordit.server.repository.ImageFileRepository; +import com.recordit.server.util.S3Uploader; + +@ExtendWith(MockitoExtension.class) +class ImageFileServiceTest { + + @InjectMocks + private ImageFileService imageFileService; + + @Mock + private ImageFileRepository imageFileRepository; + + @Mock + private S3Uploader s3Uploader; + + @Mock + private ApplicationEventPublisher applicationEventPublisher; + + @Nested + @DisplayName("첨부 파일을 저장할 때") + class 첨부_파일을_저장할_때 { + + private final RefType refType = Arrays.stream(RefType.values()).findAny().get(); + private final Long refId = 0L; + private final MultipartFile mock = mock(MultipartFile.class); + private final List mockMultipartFiles = List.of(mock); + + @Test + @DisplayName("빈 파일이 넘어오면 예외를 던진다") + void 빈_파일이_넘어오면_예외를_던진다() { + // given + given(mock.isEmpty()) + .willReturn(true); + + // when, then + assertThatThrownBy(() -> imageFileService.saveAttachmentFiles(refType, refId, mockMultipartFiles)) + .isInstanceOf(EmptyFileException.class); + } + + @Test + @DisplayName("규정한 ContentType이 아니면 예외를 던진다") + void 규정한_ContentType이_아니면_예외를_던진다() { + // given + given(mock.isEmpty()) + .willReturn(false); + given(mock.getContentType()) + .willReturn("notImage"); + + // when, then + assertThatThrownBy(() -> imageFileService.saveAttachmentFiles(refType, refId, mockMultipartFiles)) + .isInstanceOf(FileContentTypeNotAllowedException.class); + } + + @Test + @DisplayName("정상적으로 파일을 저장할 경우 Url을 응답한다") + void 정상적으로_파일을_저장할_경우_URL을_응답한다() { + // given + given(mock.isEmpty()) + .willReturn(false); + given(mock.getContentType()) + .willReturn("image"); + given(s3Uploader.upload(any())) + .willReturn("saveFileName"); + given(s3Uploader.getUrlByFileName(any())) + .willReturn("saveFileUrl"); + given(mock.getOriginalFilename()) + .willReturn("test.png"); + + // when + List result = imageFileService.saveAttachmentFiles(refType, refId, mockMultipartFiles); + + // then + assertThat(result.size()).isEqualTo(1); + assertThat(result.get(0)).isEqualTo("saveFileUrl"); + } + + } +} \ No newline at end of file From 7ec8f2ebfc24ed583fcfe5216cbdaf5da1cf4d80 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 29 Dec 2022 22:59:17 +0900 Subject: [PATCH 156/264] =?UTF-8?q?[BE-83]=20fix:=20regex=20nickname=202-1?= =?UTF-8?q?0=EC=97=90=EC=84=9C=202-8=EA=B8=80=EC=9E=90=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/dto/member/RegisterRequestDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java index b33bd29b..d5c32205 100644 --- a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java +++ b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java @@ -24,7 +24,7 @@ public class RegisterRequestDto { private String registerSession; @ApiModelProperty(notes = "사용자 닉네임", required = true) - @Pattern(regexp = "[가-힣a-zA-z0-9]{2,10}") + @Pattern(regexp = "[가-힣a-zA-z0-9]{2,8}") private String nickname; @Builder From f04245f6d9b49e8240f38c84c5ceb01a6fdd1941 Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 30 Dec 2022 00:28:06 +0900 Subject: [PATCH 157/264] =?UTF-8?q?[BE-83]=20fix:=20nickname=20regex=20?= =?UTF-8?q?=EA=B0=80-=ED=9E=A3=EC=97=90=EC=84=9C=20=E3=84=B1-=ED=9E=A3=20?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/dto/member/RegisterRequestDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java index d5c32205..729088b8 100644 --- a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java +++ b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java @@ -24,7 +24,7 @@ public class RegisterRequestDto { private String registerSession; @ApiModelProperty(notes = "사용자 닉네임", required = true) - @Pattern(regexp = "[가-힣a-zA-z0-9]{2,8}") + @Pattern(regexp = "[ㄱ-힣a-zA-z0-9]{2,8}") private String nickname; @Builder From 524b90c52ed20b2c87aa42ffb051e25f094d0cda Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 30 Dec 2022 09:50:36 +0900 Subject: [PATCH 158/264] =?UTF-8?q?[BE-95]=20feat:=20RecordCategory?= =?UTF-8?q?=EC=97=90=20=EC=A0=95=EC=A0=81=20=ED=8C=A9=ED=86=A0=EB=A6=AC=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=EC=99=80=20=EC=96=91=EB=B0=A9?= =?UTF-8?q?=ED=96=A5=20=EB=A7=A4=ED=95=91=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/domain/RecordCategory.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/com/recordit/server/domain/RecordCategory.java b/src/main/java/com/recordit/server/domain/RecordCategory.java index 87cd3d95..52c30317 100644 --- a/src/main/java/com/recordit/server/domain/RecordCategory.java +++ b/src/main/java/com/recordit/server/domain/RecordCategory.java @@ -1,5 +1,8 @@ package com.recordit.server.domain; +import java.util.ArrayList; +import java.util.List; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -8,6 +11,7 @@ import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; @@ -34,4 +38,16 @@ public class RecordCategory extends BaseEntity { @Column(name = "NAME") private String name; + + @OneToMany(mappedBy = "parentRecordCategory") + private List subcategories = new ArrayList<>(); + + private RecordCategory(RecordCategory parentRecordCategory, String name) { + this.parentRecordCategory = parentRecordCategory; + this.name = name; + } + + public static RecordCategory of(RecordCategory parentRecordCategory, String name) { + return new RecordCategory(parentRecordCategory, name); + } } From e40d51c32f09b3e9d7284d0c95f835bb54bd49f1 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 30 Dec 2022 09:51:13 +0900 Subject: [PATCH 159/264] =?UTF-8?q?[BE-95]=20feat:=20RecordCategoryReposit?= =?UTF-8?q?ory=EC=97=90=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=EC=8B=9C?= =?UTF-8?q?=20fetch=20join=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/repository/RecordCategoryRepository.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java b/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java index 975c2ea9..865c07dc 100644 --- a/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java +++ b/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java @@ -1,8 +1,14 @@ package com.recordit.server.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import com.recordit.server.domain.RecordCategory; public interface RecordCategoryRepository extends JpaRepository { + + @Query("select rc from RECORD_CATEGORY rc left join fetch rc.subcategories") + List findAll(); } From 9ffd9a7ac5195cfc6fffe38196b8c94ff6819bd0 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 30 Dec 2022 09:51:47 +0900 Subject: [PATCH 160/264] =?UTF-8?q?[BE-95]=20feat:=20RecordCategoryControl?= =?UTF-8?q?ler=EC=97=90=20=EB=B0=98=ED=99=98=EA=B0=92=20=EC=A7=80=EC=A0=95?= =?UTF-8?q?=20=EB=B0=8F=20=EC=8A=A4=EC=9B=A8=EA=B1=B0=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/RecordCategoryController.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/RecordCategoryController.java b/src/main/java/com/recordit/server/controller/RecordCategoryController.java index 2ced2db7..6a6fa707 100644 --- a/src/main/java/com/recordit/server/controller/RecordCategoryController.java +++ b/src/main/java/com/recordit/server/controller/RecordCategoryController.java @@ -1,5 +1,7 @@ package com.recordit.server.controller; +import java.util.List; + import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -27,11 +29,12 @@ public class RecordCategoryController { @ApiResponses({ @ApiResponse( code = 200, message = "API 정상 작동 / 레코드 카테고리 목록 반환", - response = RecordCategoryResponseDto.class + response = RecordCategoryResponseDto.class, responseContainer = "List" ) }) @GetMapping - public ResponseEntity getAllRecordCategories() { - return null; + public ResponseEntity> getAllRecordCategories() { + return ResponseEntity.ok(recordCategoryService.getAllRecordCategories()); } + } From 368c0c7c9ae850099a1496ef4d1d475c255a7fd8 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 30 Dec 2022 09:52:23 +0900 Subject: [PATCH 161/264] =?UTF-8?q?[BE-95]=20feat:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/RecordCategoryResponseDto.java | 27 ++++++-- .../server/service/RecordCategoryService.java | 17 +++++ .../service/RecordCategoryServiceTest.java | 65 +++++++++++++++++++ 3 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java diff --git a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java index 98f0da74..8f34533d 100644 --- a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java +++ b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java @@ -1,10 +1,11 @@ package com.recordit.server.dto.record.category; import java.util.List; -import java.util.Map; +import java.util.stream.Collectors; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.recordit.server.domain.RecordCategory; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -20,11 +21,27 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class RecordCategoryResponseDto { - @ApiModelProperty(notes = "레코드 카테고리 목록", required = true) - private Map> recordCategory; + + @ApiModelProperty(notes = "레코드 카테고리 ID", required = true) + private Long id; + + @ApiModelProperty(notes = "레코드 카테고리 이름", required = true) + private String name; + + @ApiModelProperty(notes = "하위 레코드 목록", required = true) + private List subcategories; @Builder - public RecordCategoryResponseDto(Map> recordCategory) { - this.recordCategory = recordCategory; + public RecordCategoryResponseDto(Long id, String name, List subcategories) { + this.id = id; + this.name = name; + this.subcategories = subcategories.stream().map( + subcategory -> RecordCategoryResponseDto.builder() + .id(subcategory.getId()) + .name(subcategory.getName()) + .subcategories(subcategory.getSubcategories()) + .build() + ).collect(Collectors.toList()); } + } diff --git a/src/main/java/com/recordit/server/service/RecordCategoryService.java b/src/main/java/com/recordit/server/service/RecordCategoryService.java index ea745bc8..05ca4519 100644 --- a/src/main/java/com/recordit/server/service/RecordCategoryService.java +++ b/src/main/java/com/recordit/server/service/RecordCategoryService.java @@ -1,7 +1,12 @@ package com.recordit.server.service; +import java.util.List; +import java.util.stream.Collectors; + import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.recordit.server.dto.record.category.RecordCategoryResponseDto; import com.recordit.server.repository.RecordCategoryRepository; import lombok.RequiredArgsConstructor; @@ -11,4 +16,16 @@ public class RecordCategoryService { private final RecordCategoryRepository recordCategoryRepository; + @Transactional(readOnly = true) + public List getAllRecordCategories() { + return recordCategoryRepository.findAll().stream() + .filter(recordCategory -> recordCategory.getParentRecordCategory() == null) + .map( + recordCategory -> RecordCategoryResponseDto.builder() + .id(recordCategory.getId()) + .name(recordCategory.getName()) + .subcategories(recordCategory.getSubcategories()) + .build() + ).collect(Collectors.toList()); + } } diff --git a/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java b/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java new file mode 100644 index 00000000..51747202 --- /dev/null +++ b/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java @@ -0,0 +1,65 @@ +package com.recordit.server.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.util.List; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import com.recordit.server.domain.RecordCategory; +import com.recordit.server.dto.record.category.RecordCategoryResponseDto; +import com.recordit.server.repository.RecordCategoryRepository; + +@ExtendWith({MockitoExtension.class}) +class RecordCategoryServiceTest { + + @InjectMocks + private RecordCategoryService recordCategoryService; + + @Mock + private RecordCategoryRepository recordCategoryRepository; + + @Test + @DisplayName("레코드 전제 조회를 테스트한다") + void 레코드_전제_조회를_테스트한다() { + // given + RecordCategory recordCategory1 = mock(RecordCategory.class); + RecordCategory recordCategory2 = mock(RecordCategory.class); + RecordCategory recordCategory3 = mock(RecordCategory.class); + + given(recordCategory1.getId()) + .willReturn(1L); + given(recordCategory1.getName()) + .willReturn("recordCategory1"); + given(recordCategory1.getSubcategories()) + .willReturn(List.of(recordCategory2)); + + given(recordCategory2.getId()) + .willReturn(2L); + given(recordCategory2.getName()) + .willReturn("recordCategory2"); + + given(recordCategory3.getId()) + .willReturn(3L); + given(recordCategory3.getName()) + .willReturn("recordCategory3"); + + given(recordCategoryRepository.findAll()) + .willReturn(List.of(recordCategory1, recordCategory3)); + // when + List result = recordCategoryService.getAllRecordCategories(); + + // then + assertThat(result.size()).isEqualTo(2); + assertThat(result.get(0).getSubcategories().size()).isEqualTo(1); + assertThat(result.get(0).getSubcategories().get(0).getId()).isEqualTo(2L); + assertThat(result.get(1).getId()).isEqualTo(3L); + } + +} \ No newline at end of file From 0c095de52aa8dab4e721432b58aa1d91ebffd506 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 30 Dec 2022 10:31:30 +0900 Subject: [PATCH 162/264] =?UTF-8?q?[BE-96]=20refactor:=20=EB=8B=89?= =?UTF-8?q?=EB=84=A4=EC=9E=84=20=EC=A4=91=EB=B3=B5=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=97=90=20Boolean=20=EC=9D=91=EB=8B=B5=EA=B0=92=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/MemberController.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index c60e1bee..c2693ae5 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -17,6 +17,7 @@ import com.recordit.server.dto.member.LoginRequestDto; import com.recordit.server.dto.member.RegisterRequestDto; import com.recordit.server.dto.member.RegisterSessionResponseDto; +import com.recordit.server.exception.member.DuplicateNicknameException; import com.recordit.server.service.MemberService; import io.swagger.annotations.ApiOperation; @@ -100,13 +101,17 @@ public ResponseEntity oauthRegister( notes = "닉네임을 받아 해당 닉네임이 중복되었는지 판별" ) @ApiResponses({ - @ApiResponse(code = 200, message = "닉네임이 사용 가능한 경우"), - @ApiResponse(code = 409, message = "닉네임이 중복 된 경우") + @ApiResponse(code = 200, message = "닉네임이 사용 가능한 경우 true 반환", response = Boolean.class), + @ApiResponse(code = 409, message = "닉네임이 중복 된 경우 false 반환") }) @GetMapping("/nickname") public ResponseEntity duplicateNicknameCheck(@RequestParam String nickname) { - memberService.isDuplicateNickname(nickname); - return new ResponseEntity(HttpStatus.OK); + try { + memberService.isDuplicateNickname(nickname); + } catch (DuplicateNicknameException e) { + return ResponseEntity.status(HttpStatus.CONFLICT).body(false); + } + return ResponseEntity.status(HttpStatus.OK).body(true); } } From 8f0ad977815791e13eda6b3733465227b8d86e7f Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 30 Dec 2022 13:15:37 +0900 Subject: [PATCH 163/264] =?UTF-8?q?[BE-83]=20fix:=20nickname=20regex=20'[?= =?UTF-8?q?=EA=B0=80-=ED=9E=A3A-z0-9]{2,8}=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/dto/member/RegisterRequestDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java index 729088b8..52c64751 100644 --- a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java +++ b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java @@ -24,7 +24,7 @@ public class RegisterRequestDto { private String registerSession; @ApiModelProperty(notes = "사용자 닉네임", required = true) - @Pattern(regexp = "[ㄱ-힣a-zA-z0-9]{2,8}") + @Pattern(regexp = "[가-힣A-z0-9]{2,8}") private String nickname; @Builder From 11cdbd7c54e36fdbf02a8443723fb58400868ea5 Mon Sep 17 00:00:00 2001 From: kdomo Date: Sat, 31 Dec 2022 01:43:33 +0900 Subject: [PATCH 164/264] =?UTF-8?q?[BE-99]=20chore:=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20SQL=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schema/category.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 schema/category.sql diff --git a/schema/category.sql b/schema/category.sql new file mode 100644 index 00000000..260ac2aa --- /dev/null +++ b/schema/category.sql @@ -0,0 +1,22 @@ +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('축하 레코드', now(), now(), null); +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('위로 레코드', now(), now(), null); + +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('축하해주세요', now(), now(), 1); +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('기념일이에요', now(), now(), 1); +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('연애중이에요', now(), now(), 1); +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('행복해요', now(), now(), 1); + +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('위로해주세요', now(), now(), 2); +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('공감이 필요해요', now(), now(), 2); +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('내편이 되어주세요', now(), now(), 2); +insert into RECORD_CATEGORY(NAME, CREATED_AT, MODIFIED_AT, PARENT_RECORD_CATEGORY_ID) + value ('우울해요', now(), now(), 2); \ No newline at end of file From 526ff7bac0a47fc378751a555cffd0f73566393c Mon Sep 17 00:00:00 2001 From: kdomo Date: Sat, 31 Dec 2022 02:01:00 +0900 Subject: [PATCH 165/264] =?UTF-8?q?[BE-100]=20feat:=20redis=20cache=20conf?= =?UTF-8?q?ig=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/CacheConfiguration.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/com/recordit/server/configuration/CacheConfiguration.java diff --git a/src/main/java/com/recordit/server/configuration/CacheConfiguration.java b/src/main/java/com/recordit/server/configuration/CacheConfiguration.java new file mode 100644 index 00000000..44af4e68 --- /dev/null +++ b/src/main/java/com/recordit/server/configuration/CacheConfiguration.java @@ -0,0 +1,40 @@ +package com.recordit.server.configuration; + +import org.springframework.cache.CacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +import lombok.RequiredArgsConstructor; + +@Configuration +@RequiredArgsConstructor +public class CacheConfiguration { + + @Bean + public CacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) { + RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig() + .disableCachingNullValues() + .prefixCacheNameWith("cache:") + .serializeKeysWith( + RedisSerializationContext + .SerializationPair + .fromSerializer(new StringRedisSerializer()) + ) + .serializeValuesWith( + RedisSerializationContext + .SerializationPair + .fromSerializer(new Jackson2JsonRedisSerializer<>(Object.class)) + ); + + return RedisCacheManager.RedisCacheManagerBuilder + .fromConnectionFactory(redisConnectionFactory) + .cacheDefaults(configuration) + .build(); + } +} \ No newline at end of file From 31c0d586eb3b434aea37d3eb9bc2d48e3838ed48 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 31 Dec 2022 11:56:04 +0900 Subject: [PATCH 166/264] =?UTF-8?q?[BE-98]=20refactor:=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20DTO=EC=97=90=20=EB=B9=8C=EB=8D=94=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/RecordCategoryResponseDto.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java index 8f34533d..daa90bac 100644 --- a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java +++ b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java @@ -1,7 +1,7 @@ package com.recordit.server.dto.record.category; +import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -29,19 +29,12 @@ public class RecordCategoryResponseDto { private String name; @ApiModelProperty(notes = "하위 레코드 목록", required = true) - private List subcategories; + private List subcategories = new ArrayList<>(); @Builder - public RecordCategoryResponseDto(Long id, String name, List subcategories) { - this.id = id; - this.name = name; - this.subcategories = subcategories.stream().map( - subcategory -> RecordCategoryResponseDto.builder() - .id(subcategory.getId()) - .name(subcategory.getName()) - .subcategories(subcategory.getSubcategories()) - .build() - ).collect(Collectors.toList()); + public RecordCategoryResponseDto(RecordCategory recordCategory, List children) { + this.id = recordCategory.getId(); + this.name = recordCategory.getName(); + this.subcategories = children; } - } From f353822b6c802d837bb86afe94d09201f9d0d154 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 31 Dec 2022 12:00:57 +0900 Subject: [PATCH 167/264] =?UTF-8?q?[BE-98]=20fix:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/RecordCategoryRepository.java | 4 +- .../server/service/RecordCategoryService.java | 45 +++++++++++++++---- .../service/RecordCategoryServiceTest.java | 8 ++-- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java b/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java index 865c07dc..ca602a8e 100644 --- a/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java +++ b/src/main/java/com/recordit/server/repository/RecordCategoryRepository.java @@ -9,6 +9,6 @@ public interface RecordCategoryRepository extends JpaRepository { - @Query("select rc from RECORD_CATEGORY rc left join fetch rc.subcategories") - List findAll(); + @Query("select rc from RECORD_CATEGORY rc left join fetch rc.parentRecordCategory") + List findAllFetchDepthIsOne(); } diff --git a/src/main/java/com/recordit/server/service/RecordCategoryService.java b/src/main/java/com/recordit/server/service/RecordCategoryService.java index 05ca4519..b63c6ad5 100644 --- a/src/main/java/com/recordit/server/service/RecordCategoryService.java +++ b/src/main/java/com/recordit/server/service/RecordCategoryService.java @@ -1,11 +1,15 @@ package com.recordit.server.service; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.recordit.server.domain.RecordCategory; import com.recordit.server.dto.record.category.RecordCategoryResponseDto; import com.recordit.server.repository.RecordCategoryRepository; @@ -18,14 +22,39 @@ public class RecordCategoryService { @Transactional(readOnly = true) public List getAllRecordCategories() { - return recordCategoryRepository.findAll().stream() + List findRecordCategories = recordCategoryRepository.findAllFetchDepthIsOne(); + + // 부모이면서 자식이 null이 아닌 Map 생성 + Map> parentToChildren = findRecordCategories.stream() + .filter(recordCategory -> recordCategory.getParentRecordCategory() != null) + .collect(Collectors.groupingBy(RecordCategory::getParentRecordCategory)); + + // 부모이면서 자식이 null인 객체 Map에 추가 + findRecordCategories.stream() .filter(recordCategory -> recordCategory.getParentRecordCategory() == null) - .map( - recordCategory -> RecordCategoryResponseDto.builder() - .id(recordCategory.getId()) - .name(recordCategory.getName()) - .subcategories(recordCategory.getSubcategories()) - .build() - ).collect(Collectors.toList()); + .forEach(recordCategory -> parentToChildren.putIfAbsent(recordCategory, Collections.emptyList())); + + List result = new ArrayList<>(); + for (RecordCategory parent : parentToChildren.keySet()) { + // 자식 객체들을 자식 DTO List로 변환 + List children = parentToChildren.get(parent) + .stream() + .map( + child -> RecordCategoryResponseDto.builder() + .recordCategory(child) + .children(Collections.emptyList()) + .build() + ) + .collect(Collectors.toList()); + + // 자식 DTO 객체들을 부모 DTO 객체에 추가 후 result에 담음 + RecordCategoryResponseDto parentDto = RecordCategoryResponseDto.builder() + .recordCategory(parent) + .children(children) + .build(); + result.add(parentDto); + } + + return result; } } diff --git a/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java b/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java index 51747202..859a83f9 100644 --- a/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java +++ b/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java @@ -37,21 +37,21 @@ class RecordCategoryServiceTest { .willReturn(1L); given(recordCategory1.getName()) .willReturn("recordCategory1"); - given(recordCategory1.getSubcategories()) - .willReturn(List.of(recordCategory2)); given(recordCategory2.getId()) .willReturn(2L); given(recordCategory2.getName()) .willReturn("recordCategory2"); + given(recordCategory2.getParentRecordCategory()) + .willReturn(recordCategory1); given(recordCategory3.getId()) .willReturn(3L); given(recordCategory3.getName()) .willReturn("recordCategory3"); - given(recordCategoryRepository.findAll()) - .willReturn(List.of(recordCategory1, recordCategory3)); + given(recordCategoryRepository.findAllFetchDepthIsOne()) + .willReturn(List.of(recordCategory1, recordCategory2, recordCategory3)); // when List result = recordCategoryService.getAllRecordCategories(); From 51dd7ce7a07a80b97a2798fd7c296e4d3549067f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sun, 1 Jan 2023 17:01:39 +0900 Subject: [PATCH 168/264] =?UTF-8?q?[BE-103]=20feat:=20String=EC=9D=84=20Lo?= =?UTF-8?q?ginType=EC=9C=BC=EB=A1=9C=20=EB=B0=94=EA=BF=94=EC=A3=BC?= =?UTF-8?q?=EB=8A=94=20converter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/configuration/WebMvcConfiguration.java | 8 ++++++++ .../server/converter/LoginTypeConverter.java | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/main/java/com/recordit/server/converter/LoginTypeConverter.java diff --git a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java index e66d83cd..1bef3213 100644 --- a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java @@ -1,9 +1,12 @@ package com.recordit.server.configuration; import org.springframework.context.annotation.Configuration; +import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import com.recordit.server.converter.LoginTypeConverter; + @Configuration public class WebMvcConfiguration implements WebMvcConfigurer { @@ -18,4 +21,9 @@ public void addCorsMappings(CorsRegistry registry) { .allowCredentials(true) .maxAge(MAX_AGE_SECS); } + + @Override + public void addFormatters(FormatterRegistry registry) { + registry.addConverter(new LoginTypeConverter()); + } } diff --git a/src/main/java/com/recordit/server/converter/LoginTypeConverter.java b/src/main/java/com/recordit/server/converter/LoginTypeConverter.java new file mode 100644 index 00000000..58d8efb3 --- /dev/null +++ b/src/main/java/com/recordit/server/converter/LoginTypeConverter.java @@ -0,0 +1,13 @@ +package com.recordit.server.converter; + +import org.springframework.core.convert.converter.Converter; + +import com.recordit.server.constant.LoginType; + +public class LoginTypeConverter implements Converter { + + @Override + public LoginType convert(String source) { + return LoginType.findByString(source); + } +} From 3b60f00f39286e41e9227a274bd54e749b7fd61e Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sun, 1 Jan 2023 17:02:40 +0900 Subject: [PATCH 169/264] =?UTF-8?q?[BE-103]=20refactor:=20Controller?= =?UTF-8?q?=EC=97=90=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=9B=EB=8A=94=20LoginType=EC=9D=84=20String=EC=9D=B4=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20LoginType=EC=9C=BC=EB=A1=9C=20=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/controller/MemberController.java | 5 +++-- .../com/recordit/server/service/MemberService.java | 6 +++--- .../server/service/oauth/OauthServiceLocator.java | 10 +++------- .../com/recordit/server/service/MemberServiceTest.java | 8 ++++---- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index c2693ae5..ce8f0d05 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import com.recordit.server.constant.LoginType; import com.recordit.server.dto.member.LoginRequestDto; import com.recordit.server.dto.member.RegisterRequestDto; import com.recordit.server.dto.member.RegisterSessionResponseDto; @@ -56,7 +57,7 @@ public class MemberController { }) @PostMapping("/oauth/login/{loginType}") public ResponseEntity oauthLogin( - @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") String loginType, + @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") LoginType loginType, @RequestBody LoginRequestDto loginRequestDto ) { @@ -89,7 +90,7 @@ public ResponseEntity oauthLogin( }) @PostMapping("/oauth/register/{loginType}") public ResponseEntity oauthRegister( - @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") String loginType, + @ApiParam(allowableValues = "KAKAO, GOOGLE", required = true) @PathVariable("loginType") LoginType loginType, @RequestBody @Valid RegisterRequestDto registerRequestDto ) { memberService.oauthRegister(loginType, registerRequestDto); diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index 40368be6..7d7eb9ee 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -33,7 +33,7 @@ public class MemberService { private final RedisManager redisManager; @Transactional - public Optional oauthLogin(String loginType, LoginRequestDto loginRequestDto) { + public Optional oauthLogin(LoginType loginType, LoginRequestDto loginRequestDto) { OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType); String oauthId = oauthService.getUserInfoByOauthToken(loginRequestDto.getOauthToken()); @@ -51,7 +51,7 @@ public Optional oauthLogin(String loginType, LoginRe } @Transactional - public void oauthRegister(String loginType, RegisterRequestDto registerRequestDto) { + public void oauthRegister(LoginType loginType, RegisterRequestDto registerRequestDto) { Optional oauthId = redisManager.get( PREFIX_REGISTER_SESSION + registerRequestDto.getRegisterSession(), String.class); @@ -66,7 +66,7 @@ public void oauthRegister(String loginType, RegisterRequestDto registerRequestDt null, registerRequestDto.getNickname(), oauthId.get(), - LoginType.findByString(loginType) + loginType ) ); sessionUtil.saveUserIdInSession(saveMember.getId()); diff --git a/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java b/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java index 628602ad..f77bf4ad 100644 --- a/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java +++ b/src/main/java/com/recordit/server/service/oauth/OauthServiceLocator.java @@ -3,9 +3,8 @@ import java.util.List; import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; -import com.recordit.server.exception.member.NotEnteredLoginTypeException; +import com.recordit.server.constant.LoginType; import com.recordit.server.exception.member.NotMatchLoginTypeException; import lombok.RequiredArgsConstructor; @@ -15,12 +14,9 @@ public class OauthServiceLocator { private final List oauthServices; - public OauthService getOauthServiceByLoginType(String loginType) { - if (!StringUtils.hasText(loginType)) { - throw new NotEnteredLoginTypeException("로그인 타입이 입력되지 않았습니다."); - } + public OauthService getOauthServiceByLoginType(LoginType loginType) { return oauthServices.stream() - .filter(oauthService -> oauthService.getLoginType().name().equals(loginType)) + .filter(oauthService -> oauthService.getLoginType() == loginType) .findFirst() .orElseThrow(() -> new NotMatchLoginTypeException("일치하는 로그인 타입이 없습니다.")); } diff --git a/src/test/java/com/recordit/server/service/MemberServiceTest.java b/src/test/java/com/recordit/server/service/MemberServiceTest.java index 6eefb215..f9dfc961 100644 --- a/src/test/java/com/recordit/server/service/MemberServiceTest.java +++ b/src/test/java/com/recordit/server/service/MemberServiceTest.java @@ -54,9 +54,9 @@ public class MemberServiceTest { private MockedStatic mockUUID; - private final String loginType = Arrays.stream(LoginType.values()) + private final LoginType loginType = Arrays.stream(LoginType.values()) .findFirst() - .get().name(); + .get(); private final UUID testUUID = UUID.randomUUID(); @@ -96,7 +96,7 @@ class oauthToken을_통해_찾은_사용자가 { // given Optional mockMember = Optional.of(MemberServiceTest.this.mockMember); - given(oauthServiceLocator.getOauthServiceByLoginType(anyString())) + given(oauthServiceLocator.getOauthServiceByLoginType(any())) .willReturn(oauthService); given(oauthService.getUserInfoByOauthToken(anyString())) .willReturn(mockOauthId); @@ -117,7 +117,7 @@ class oauthToken을_통해_찾은_사용자가 { @DisplayName("없으면 registerSessionUUID를 반환한다") void 없으면_registerSessionUUID를_반환한다() { // given - given(oauthServiceLocator.getOauthServiceByLoginType(anyString())) + given(oauthServiceLocator.getOauthServiceByLoginType(any())) .willReturn(oauthService); given(oauthService.getUserInfoByOauthToken(anyString())) .willReturn(mockOauthId); From a015724f7621a9d63cc77e858a3acd642253aa42 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sun, 1 Jan 2023 17:53:31 +0900 Subject: [PATCH 170/264] =?UTF-8?q?[BE-97]=20chore:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=20=ED=8C=A8=ED=84=B4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/log4j2-dev.xml | 15 ++++++++------- src/main/resources/log4j2-local.xml | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/resources/log4j2-dev.xml b/src/main/resources/log4j2-dev.xml index f976b65d..f648de7c 100644 --- a/src/main/resources/log4j2-dev.xml +++ b/src/main/resources/log4j2-dev.xml @@ -7,14 +7,15 @@ - + - + ${LOGS_PATH}/${LOGS_NAME}.log ${LOGS_PATH}/${LOGS_NAME}.%d{yyyy-MM-dd}.%i.log - %d{yyyy-MM-dd HH:mm:ss} %5p [%c] %m%n + %d{yyyy-MM-dd HH:mm:ss} %5p [%equals{%X{trace_id}}{}{system}] [%c] %m%n @@ -25,7 +26,7 @@ ${LOGS_PATH}/ERROR/${LOGS_NAME}_ERROR.log ${LOGS_PATH}/ERROR/${LOGS_NAME}_ERROR.%d{yyyy-MM-dd}.%i.log - %d{yyyy-MM-dd HH:mm:ss} %5p [%c] %m%n + %d{yyyy-MM-dd HH:mm:ss} %5p [%equals{%X{trace_id}}{}{system}] [%c] %m%n @@ -36,9 +37,9 @@ - - - + + + \ No newline at end of file diff --git a/src/main/resources/log4j2-local.xml b/src/main/resources/log4j2-local.xml index 4100e5fc..6ffa7132 100644 --- a/src/main/resources/log4j2-local.xml +++ b/src/main/resources/log4j2-local.xml @@ -2,7 +2,8 @@ - + From 46b510dc2b65e30807fda22d78ca559d3647248b Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sun, 1 Jan 2023 18:31:27 +0900 Subject: [PATCH 171/264] =?UTF-8?q?[BE-97]=20feat:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9A=A9=20HTTP=20=EC=9A=94=EC=B2=AD=EB=B3=84=20UUID=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=B0=8F=20HTTP=20=EC=9A=94=EC=B2=AD,=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20Parameter/Body=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/logger/HTTPLogFilter.java | 120 ++++++++++++++++++ .../server/logger/MDCLoggingFilter.java | 32 +++++ 2 files changed, 152 insertions(+) create mode 100644 src/main/java/com/recordit/server/logger/HTTPLogFilter.java create mode 100644 src/main/java/com/recordit/server/logger/MDCLoggingFilter.java diff --git a/src/main/java/com/recordit/server/logger/HTTPLogFilter.java b/src/main/java/com/recordit/server/logger/HTTPLogFilter.java new file mode 100644 index 00000000..018f97cd --- /dev/null +++ b/src/main/java/com/recordit/server/logger/HTTPLogFilter.java @@ -0,0 +1,120 @@ +package com.recordit.server.logger; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Component; +import org.springframework.web.util.ContentCachingRequestWrapper; +import org.springframework.web.util.ContentCachingResponseWrapper; +import org.springframework.web.util.WebUtils; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +public class HTTPLogFilter implements Filter { + + @Override + public void doFilter( + ServletRequest request, + ServletResponse response, + FilterChain chain + ) throws IOException, ServletException { + ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper( + (HttpServletRequest)request + ); + ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper( + (HttpServletResponse)response + ); + + long start = System.currentTimeMillis(); + chain.doFilter(requestWrapper, responseWrapper); + long end = System.currentTimeMillis(); + + log.info("\n" + + "[REQUEST] {} - {} {} - {}ms\n" + + "Headers : {}\n" + + "RequestParameter : {}\n" + + "RequestBody : {}\n" + + "Response : {}\n", + ((HttpServletRequest)request).getMethod(), + ((HttpServletRequest)request).getRequestURI(), + responseWrapper.getStatus(), + (end - start), + getHeaders((HttpServletRequest)request), + getRequestParameter(requestWrapper), + getRequestBody(requestWrapper), + getResponseBody(responseWrapper)); + } + + private Map getHeaders(HttpServletRequest request) { + Map headerMap = new HashMap<>(); + + Enumeration headerArray = request.getHeaderNames(); + while (headerArray.hasMoreElements()) { + String headerName = (String)headerArray.nextElement(); + headerMap.put(headerName, request.getHeader(headerName)); + } + return headerMap; + } + + private String getRequestParameter(ContentCachingRequestWrapper request) { + Map parameterMap = request.getParameterMap(); + if (parameterMap.size() == 0) { + return "-"; + } + + StringBuilder sb = new StringBuilder(); + for (Map.Entry entry : parameterMap.entrySet()) { + sb.append(entry.getKey() + "="); + for (String value : entry.getValue()) { + sb.append(value + ", "); + } + sb.replace(sb.length() - 2, sb.length(), " | "); + } + sb.replace(sb.length() - 2, sb.length(), ""); + return sb.toString(); + } + + private String getRequestBody(ContentCachingRequestWrapper request) { + ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class); + if (wrapper != null) { + byte[] buf = wrapper.getContentAsByteArray(); + if (buf.length > 0) { + try { + return new String(buf, 0, buf.length, wrapper.getCharacterEncoding()); + } catch (UnsupportedEncodingException e) { + return " - "; + } + } + } + return " - "; + } + + private String getResponseBody(final HttpServletResponse response) throws IOException { + String payload = null; + ContentCachingResponseWrapper wrapper = WebUtils.getNativeResponse( + response, + ContentCachingResponseWrapper.class + ); + if (wrapper != null) { + byte[] buf = wrapper.getContentAsByteArray(); + if (buf.length > 0) { + payload = new String(buf, 0, buf.length, wrapper.getCharacterEncoding()); + wrapper.copyBodyToResponse(); + } + } + return null == payload ? " - " : payload; + } +} diff --git a/src/main/java/com/recordit/server/logger/MDCLoggingFilter.java b/src/main/java/com/recordit/server/logger/MDCLoggingFilter.java new file mode 100644 index 00000000..2217516e --- /dev/null +++ b/src/main/java/com/recordit/server/logger/MDCLoggingFilter.java @@ -0,0 +1,32 @@ +package com.recordit.server.logger; + +import java.io.IOException; +import java.util.UUID; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.slf4j.MDC; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Component +@Order(Ordered.HIGHEST_PRECEDENCE) +public class MDCLoggingFilter implements Filter { + + @Override + public void doFilter( + final ServletRequest request, + final ServletResponse response, + final FilterChain chain + ) throws IOException, ServletException { + final UUID uuid = UUID.randomUUID(); + MDC.put("trace_id", uuid.toString().substring(0, uuid.toString().indexOf("-"))); + chain.doFilter(request, response); + MDC.clear(); + } +} From f050af4ecdcd1f8803373e3275a8fcd06ccc0650 Mon Sep 17 00:00:00 2001 From: kdomo Date: Sun, 1 Jan 2023 21:41:56 +0900 Subject: [PATCH 172/264] =?UTF-8?q?[BE-101]=20feat:=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=BA=90=EC=8B=9C=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/service/RecordCategoryService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/recordit/server/service/RecordCategoryService.java b/src/main/java/com/recordit/server/service/RecordCategoryService.java index b63c6ad5..fcaf097b 100644 --- a/src/main/java/com/recordit/server/service/RecordCategoryService.java +++ b/src/main/java/com/recordit/server/service/RecordCategoryService.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.stream.Collectors; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,6 +22,7 @@ public class RecordCategoryService { private final RecordCategoryRepository recordCategoryRepository; @Transactional(readOnly = true) + @Cacheable(value = "Categories") public List getAllRecordCategories() { List findRecordCategories = recordCategoryRepository.findAllFetchDepthIsOne(); From d1588059f3667eebae4aa979bded3e31f73f687f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 2 Jan 2023 09:46:32 +0900 Subject: [PATCH 173/264] =?UTF-8?q?[BE-97]=20refactor:=20Member=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EC=A7=81=EC=97=90=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/member/MemberExceptionHandler.java | 3 --- .../com/recordit/server/service/MemberService.java | 12 +++++++++++- .../server/service/oauth/GoogleOauthService.java | 6 ++++++ .../server/service/oauth/KakaoOauthService.java | 6 ++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index f6103443..41fc30c5 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -9,9 +9,6 @@ import com.recordit.server.controller.MemberController; import com.recordit.server.exception.ErrorMessage; -import lombok.extern.slf4j.Slf4j; - -@Slf4j @RestControllerAdvice(basePackageClasses = MemberController.class) public class MemberExceptionHandler { diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index 7d7eb9ee..4a831599 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -23,7 +23,9 @@ import com.recordit.server.util.SessionUtil; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service @RequiredArgsConstructor public class MemberService { @@ -37,14 +39,19 @@ public Optional oauthLogin(LoginType loginType, Logi OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType); String oauthId = oauthService.getUserInfoByOauthToken(loginRequestDto.getOauthToken()); + log.info("Oauth 로그인 응답 ID : {}", oauthId); + Optional findMember = memberRepository.findByOauthId(oauthId); if (findMember.isPresent()) { sessionUtil.saveUserIdInSession(findMember.get().getId()); + log.info("사용자 세션 저장 ID : {}", findMember.get().getId()); return Optional.empty(); } + String registerSessionUUID = UUID.randomUUID().toString(); redisManager.set(PREFIX_REGISTER_SESSION + registerSessionUUID, oauthId, TIMEOUT, TimeUnit.MINUTES); + log.info("사용자 회원가입 세션 Redis에 저장 : {}", registerSessionUUID); return Optional.of(RegisterSessionResponseDto.builder() .registerSession(registerSessionUUID) .build()); @@ -54,8 +61,10 @@ public Optional oauthLogin(LoginType loginType, Logi public void oauthRegister(LoginType loginType, RegisterRequestDto registerRequestDto) { Optional oauthId = redisManager.get( PREFIX_REGISTER_SESSION + registerRequestDto.getRegisterSession(), - String.class); + String.class + ); if (oauthId.isEmpty()) { + log.warn("요청한 Register Session이 존재하지 않음 : {}", registerRequestDto.getRegisterSession()); throw new NotFoundRegisterSessionException("Oauth 회원가입을 위한 register_session이 존재하지 않습니다."); } @@ -76,6 +85,7 @@ public void oauthRegister(LoginType loginType, RegisterRequestDto registerReques @Transactional(readOnly = true) public void isDuplicateNickname(String nickname) { if (memberRepository.existsByNickname(nickname)) { + log.warn("중복된 닉네임이 존재함 : {}", nickname); throw new DuplicateNicknameException("중복된 닉네임이 존재합니다."); } } diff --git a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java index bbdd3899..70b7efd6 100644 --- a/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/GoogleOauthService.java @@ -16,7 +16,9 @@ import com.recordit.server.util.CustomObjectMapper; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service @RequiredArgsConstructor public class GoogleOauthService implements OauthService { @@ -46,6 +48,7 @@ protected GoogleAccessTokenResponseDto requestAccessToken(String oauthToken) { .queryParam(REDIRECT_URI.key, googleOauthProperties.getRedirectUrl()) .queryParam(GRANT_TYPE.key, getFixGrantType()) .toUriString(); + log.info("구글 Oauth AccessToken 요청 : {}", params); ResponseEntity exchange = new RestTemplate().exchange( params, @@ -53,6 +56,7 @@ protected GoogleAccessTokenResponseDto requestAccessToken(String oauthToken) { null, String.class ); + log.info("구글 Oauth AccessToken 응답 : {}", exchange); return CustomObjectMapper.readValue(exchange.getBody(), GoogleAccessTokenResponseDto.class); } @@ -62,6 +66,7 @@ protected GoogleUserInfoResponseDto requestUserInfo(GoogleAccessTokenResponseDto String uri = UriComponentsBuilder.fromUriString(googleOauthProperties.getUserInfoRequestUrl()) .queryParam(ID_TOKEN.key, googleAccessTokenResponseDto.getIdToken()) .toUriString(); + log.info("구글 Oauth UserInfo 요청 : {}", uri); ResponseEntity exchange = new RestTemplate().exchange( uri, @@ -69,6 +74,7 @@ protected GoogleUserInfoResponseDto requestUserInfo(GoogleAccessTokenResponseDto null, String.class ); + log.info("구글 Oauth UserInfo 응답 : {}", exchange); return CustomObjectMapper.readValue(exchange.getBody(), GoogleUserInfoResponseDto.class); } diff --git a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java index dbdb4a65..770bc36b 100644 --- a/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java +++ b/src/main/java/com/recordit/server/service/oauth/KakaoOauthService.java @@ -18,7 +18,9 @@ import com.recordit.server.util.CustomObjectMapper; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service @RequiredArgsConstructor public class KakaoOauthService implements OauthService { @@ -48,6 +50,7 @@ protected KakaoAccessTokenResponseDto requestAccessToken(String oauthToken) { .queryParam(REDIRECT_URI.key, kakaoOauthProperties.getRedirectUrl()) .queryParam(GRANT_TYPE.key, getFixGrantType()) .toUriString(); + log.info("카카오 Oauth AccessToken 요청 : {}", params); ResponseEntity exchange = new RestTemplate().exchange( params, @@ -55,6 +58,7 @@ protected KakaoAccessTokenResponseDto requestAccessToken(String oauthToken) { null, String.class ); + log.info("카카오 Oauth AccessToken 응답 : {}", exchange); return CustomObjectMapper.readValue(exchange.getBody(), KakaoAccessTokenResponseDto.class); } @@ -63,6 +67,7 @@ protected KakaoAccessTokenResponseDto requestAccessToken(String oauthToken) { protected KakaoUserInfoResponseDto requestUserInfo(KakaoAccessTokenResponseDto kakaoAccessTokenResponseDto) { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add(AUTHORIZATION.key, getFixPrefixJwt() + kakaoAccessTokenResponseDto.getAccessToken()); + log.info("카카오 Oauth UserInfo 요청 : {}", httpHeaders); ResponseEntity exchange = new RestTemplate().exchange( kakaoOauthProperties.getUserInfoRequestUrl(), @@ -70,6 +75,7 @@ protected KakaoUserInfoResponseDto requestUserInfo(KakaoAccessTokenResponseDto k new HttpEntity(httpHeaders), String.class ); + log.info("카카오 Oauth UserInfo 응답 : {}", exchange); return CustomObjectMapper.readValue(exchange.getBody(), KakaoUserInfoResponseDto.class); } From a09eb59d4eef2fa8c0d7d6ac56f5877ac0e16487 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 2 Jan 2023 09:52:21 +0900 Subject: [PATCH 174/264] =?UTF-8?q?[BE-97]=20refactor:=20Record=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EA=B7=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/service/RecordService.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 24d21fca..d726b1dc 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -28,7 +28,9 @@ import com.recordit.server.util.SessionUtil; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service @RequiredArgsConstructor public class RecordService { @@ -52,6 +54,8 @@ public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordReque // } sessionUtil.saveUserIdInSession(1L); Long userIdBySession = sessionUtil.findUserIdBySession(); + log.info("세션에서 찾은 사용자 ID : {}", userIdBySession); + Member member = memberRepository.findById(userIdBySession) .orElseThrow(() -> new MemberNotFoundException("회원 정보를 찾을 수 없습니다.")); @@ -64,10 +68,17 @@ public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordReque RecordIcon recordIcon = recordIconRepository.findByName(writeRecordRequestDto.getIconName()) .orElseThrow(() -> new RecordIconNotFoundException("아이콘 정보를 찾을 수 없습니다.")); - Record record = Record.of(writeRecordRequestDto, recordCategory, member, - urls.size(), recordColor, recordIcon); + Record record = Record.of( + writeRecordRequestDto, + recordCategory, + member, + urls.size(), + recordColor, + recordIcon + ); Long recordId = recordRepository.save(record).getId(); + log.info("저장한 레코드 ID : ", record); return WriteRecordResponseDto.builder() .recordId(recordId) From 91ae0542930f5fd6e91cf544e74238ab7ba532ba Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 2 Jan 2023 10:15:24 +0900 Subject: [PATCH 175/264] =?UTF-8?q?[BE-97]=20refactor:=20ImageFile=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=A1=9C=EA=B7=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/service/ImageFileService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/recordit/server/service/ImageFileService.java b/src/main/java/com/recordit/server/service/ImageFileService.java index e64dd415..0b7e4b95 100644 --- a/src/main/java/com/recordit/server/service/ImageFileService.java +++ b/src/main/java/com/recordit/server/service/ImageFileService.java @@ -20,7 +20,9 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service @RequiredArgsConstructor public class ImageFileService { @@ -41,7 +43,9 @@ public List saveAttachmentFiles( validateImageContentType(multipartFile); String saveFileName = s3Uploader.upload(multipartFile); + log.info("S3에 저장한 파일 이름 : {}", saveFileName); String saveFileUrl = s3Uploader.getUrlByFileName(saveFileName); + log.info("S3에 저장한 URL : {}", saveFileUrl); applicationEventPublisher.publishEvent(S3ImageRollbackEvent.from(saveFileName)); imageFileRepository.save( @@ -54,6 +58,7 @@ public List saveAttachmentFiles( ) ); imageUrls.add(saveFileUrl); + log.info("이미지 파일 저장 성공 및 URL : {}", saveFileUrl); } return imageUrls; @@ -61,6 +66,7 @@ public List saveAttachmentFiles( @TransactionalEventListener(classes = S3ImageRollbackEvent.class, phase = TransactionPhase.AFTER_ROLLBACK) public void handleRollback(S3ImageRollbackEvent event) { + log.warn("S3에 업로드한 이미지 파일 롤백 : {}", event); s3Uploader.delete(event.getRollbackFileName()); } @@ -68,6 +74,7 @@ public void handleRollback(S3ImageRollbackEvent event) { public void deleteAttachmentFiles(List attachmentFileNames) { for (String attachmentFileName : attachmentFileNames) { s3Uploader.delete(attachmentFileName); + log.info("저장한 이미지 파일 삭제 : {}", attachmentFileName); } } @@ -79,6 +86,7 @@ private void validateEmptyFile(MultipartFile multipartFile) { private void validateImageContentType(MultipartFile multipartFile) { if (!multipartFile.getContentType().startsWith("image")) { + log.warn("요청 파일 ContentType : {}", multipartFile.getContentType()); throw new FileContentTypeNotAllowedException("이미지 파일이 아닙니다."); } } From 6a86a69d37ce57a2d1ba642a1b1c8dd4b064e28b Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 2 Jan 2023 13:26:54 +0900 Subject: [PATCH 176/264] =?UTF-8?q?[BE-104]=20feat:=20=EC=84=B8=EC=85=98?= =?UTF-8?q?=20set-cookie=20SameSite=20None=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/configuration/WebMvcConfiguration.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java index 1bef3213..1bf8685a 100644 --- a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java @@ -1,7 +1,10 @@ package com.recordit.server.configuration; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; +import org.springframework.session.web.http.CookieSerializer; +import org.springframework.session.web.http.DefaultCookieSerializer; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -26,4 +29,12 @@ public void addCorsMappings(CorsRegistry registry) { public void addFormatters(FormatterRegistry registry) { registry.addConverter(new LoginTypeConverter()); } + + @Bean + public CookieSerializer cookieSerializer() { + DefaultCookieSerializer serializer = new DefaultCookieSerializer(); + serializer.setUseSecureCookie(true); + serializer.setSameSite("None"); + return serializer; + } } From a2b7822b1b28c5f6ca79aa737d2ce18441a4f486 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 2 Jan 2023 14:16:46 +0900 Subject: [PATCH 177/264] =?UTF-8?q?[BE-105]=20refactor:=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=8B=9C=20=EC=88=9C=EC=84=9C=EB=A5=BC=20nul?= =?UTF-8?q?lLast=EB=A1=9C=20=EC=A1=B0=ED=9A=8C=20=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/service/RecordCategoryService.java | 8 +++++--- .../server/service/RecordCategoryServiceTest.java | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/recordit/server/service/RecordCategoryService.java b/src/main/java/com/recordit/server/service/RecordCategoryService.java index fcaf097b..ed36bdcf 100644 --- a/src/main/java/com/recordit/server/service/RecordCategoryService.java +++ b/src/main/java/com/recordit/server/service/RecordCategoryService.java @@ -2,8 +2,8 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import org.springframework.cache.annotation.Cacheable; @@ -26,10 +26,12 @@ public class RecordCategoryService { public List getAllRecordCategories() { List findRecordCategories = recordCategoryRepository.findAllFetchDepthIsOne(); + LinkedHashMap> parentToChildren = new LinkedHashMap<>(); + // 부모이면서 자식이 null이 아닌 Map 생성 - Map> parentToChildren = findRecordCategories.stream() + parentToChildren.putAll(findRecordCategories.stream() .filter(recordCategory -> recordCategory.getParentRecordCategory() != null) - .collect(Collectors.groupingBy(RecordCategory::getParentRecordCategory)); + .collect(Collectors.groupingBy(RecordCategory::getParentRecordCategory))); // 부모이면서 자식이 null인 객체 Map에 추가 findRecordCategories.stream() diff --git a/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java b/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java index 859a83f9..d109e02e 100644 --- a/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java +++ b/src/test/java/com/recordit/server/service/RecordCategoryServiceTest.java @@ -26,8 +26,8 @@ class RecordCategoryServiceTest { private RecordCategoryRepository recordCategoryRepository; @Test - @DisplayName("레코드 전제 조회를 테스트한다") - void 레코드_전제_조회를_테스트한다() { + @DisplayName("레코드 카테고리 전체 조회를 테스트한다") + void 레코드_카테고리_전체_조회를_테스트한다() { // given RecordCategory recordCategory1 = mock(RecordCategory.class); RecordCategory recordCategory2 = mock(RecordCategory.class); From 4c0d605ff6228e87136397d73b39498f72ce54d9 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 2 Jan 2023 14:26:46 +0900 Subject: [PATCH 178/264] =?UTF-8?q?[BE-104]=20fix:=20Cookie=20config=20Bea?= =?UTF-8?q?n=20=EC=82=AD=EC=A0=9C=20=ED=9B=84=20yml=EB=A1=9C=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/configuration/WebMvcConfiguration.java | 11 ----------- src/main/resources/application-dev.yml | 8 +++++++- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java index 1bf8685a..1bef3213 100644 --- a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java @@ -1,10 +1,7 @@ package com.recordit.server.configuration; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; -import org.springframework.session.web.http.CookieSerializer; -import org.springframework.session.web.http.DefaultCookieSerializer; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -29,12 +26,4 @@ public void addCorsMappings(CorsRegistry registry) { public void addFormatters(FormatterRegistry registry) { registry.addConverter(new LoginTypeConverter()); } - - @Bean - public CookieSerializer cookieSerializer() { - DefaultCookieSerializer serializer = new DefaultCookieSerializer(); - serializer.setUseSecureCookie(true); - serializer.setSameSite("None"); - return serializer; - } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 335d22b7..8c9a2cd6 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -27,4 +27,10 @@ springfox: swagger: use-model-v3: false logging: - config: classpath:log4j2-dev.xml \ No newline at end of file + config: classpath:log4j2-dev.xml +server: + servlet: + session: + cookie: + same-site: none + secure: true \ No newline at end of file From 55cf0dcf44860db535d55b9909e776d596ff88c1 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 2 Jan 2023 16:15:50 +0900 Subject: [PATCH 179/264] =?UTF-8?q?[BE-106]=20feat:=20exposedHeaders?= =?UTF-8?q?=EC=97=90=20Set-Cookie=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/configuration/WebMvcConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java index 1bef3213..cbb22fcb 100644 --- a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java @@ -19,6 +19,7 @@ public void addCorsMappings(CorsRegistry registry) { .allowedMethods("*") .allowedHeaders("*") .allowCredentials(true) + .exposedHeaders("Set-Cookie") .maxAge(MAX_AGE_SECS); } From 321a8e8143b1be7ded2a5d952b45bbbbc3e51788 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 2 Jan 2023 17:43:41 +0900 Subject: [PATCH 180/264] =?UTF-8?q?[BE-109]=20fix:=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?ResponseBody=EC=97=90=20UTF-8=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/logger/HTTPLogFilter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/recordit/server/logger/HTTPLogFilter.java b/src/main/java/com/recordit/server/logger/HTTPLogFilter.java index 018f97cd..959c6101 100644 --- a/src/main/java/com/recordit/server/logger/HTTPLogFilter.java +++ b/src/main/java/com/recordit/server/logger/HTTPLogFilter.java @@ -109,6 +109,7 @@ private String getResponseBody(final HttpServletResponse response) throws IOExce ContentCachingResponseWrapper.class ); if (wrapper != null) { + wrapper.setCharacterEncoding("UTF-8"); byte[] buf = wrapper.getContentAsByteArray(); if (buf.length > 0) { payload = new String(buf, 0, buf.length, wrapper.getCharacterEncoding()); From ae2733e4b46acde59fd278efbca4e77a5642bcf1 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 4 Jan 2023 22:17:12 +0900 Subject: [PATCH 181/264] =?UTF-8?q?[BE-122]=20fix:=20allowedOriginPatterns?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SameSite 정책으로 인해 Set-Cookie가 안되는 버그가 발생하였습니다. NGINX 설정을 하여 같은 origin으로 변경하였고, 그에 따른 originPattern을 변경하였습니다 --- .../server/configuration/WebMvcConfiguration.java | 5 ++++- src/main/resources/application-dev.yml | 8 ++------ src/main/resources/application-local.yml | 4 +++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java index cbb22fcb..bc1e78a1 100644 --- a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java @@ -1,5 +1,6 @@ package com.recordit.server.configuration; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.web.servlet.config.annotation.CorsRegistry; @@ -11,11 +12,13 @@ public class WebMvcConfiguration implements WebMvcConfigurer { private final long MAX_AGE_SECS = 3000; + @Value("${cors.origin}") + private String originPattern; @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedOriginPatterns("*") + .allowedOriginPatterns(originPattern) .allowedMethods("*") .allowedHeaders("*") .allowCredentials(true) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 8c9a2cd6..bf3fca6b 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -28,9 +28,5 @@ springfox: use-model-v3: false logging: config: classpath:log4j2-dev.xml -server: - servlet: - session: - cookie: - same-site: none - secure: true \ No newline at end of file +cors: + origin: ${CORS_ORIGIN_NAME:} \ No newline at end of file diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index f5482a15..0f8dd633 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -27,4 +27,6 @@ springfox: swagger: use-model-v3: false logging: - config: classpath:log4j2-local.xml \ No newline at end of file + config: classpath:log4j2-local.xml +cors: + origin: ${CORS_ORIGIN_NAME:} \ No newline at end of file From 2795eaebca37e40ce5bc50567fce2978718ca75b Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 4 Jan 2023 22:27:55 +0900 Subject: [PATCH 182/264] =?UTF-8?q?[BE-122]=20fix:=20=EB=AA=A8=EB=93=A0=20?= =?UTF-8?q?Controller=20RequestMapping=EC=97=90=20/api=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/controller/CommentController.java | 2 +- .../java/com/recordit/server/controller/MemberController.java | 2 +- .../recordit/server/controller/RecordCategoryController.java | 2 +- .../java/com/recordit/server/controller/RecordController.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/CommentController.java b/src/main/java/com/recordit/server/controller/CommentController.java index 28e7fb1f..1a111980 100644 --- a/src/main/java/com/recordit/server/controller/CommentController.java +++ b/src/main/java/com/recordit/server/controller/CommentController.java @@ -25,7 +25,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/comment") +@RequestMapping("/api/comment") public class CommentController { private final CommentService commentService; diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index ce8f0d05..e2805108 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -30,7 +30,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/member") +@RequestMapping("/api/member") public class MemberController { private final MemberService memberService; diff --git a/src/main/java/com/recordit/server/controller/RecordCategoryController.java b/src/main/java/com/recordit/server/controller/RecordCategoryController.java index 6a6fa707..d6b9e98f 100644 --- a/src/main/java/com/recordit/server/controller/RecordCategoryController.java +++ b/src/main/java/com/recordit/server/controller/RecordCategoryController.java @@ -17,7 +17,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/record/category") +@RequestMapping("/api/record/category") public class RecordCategoryController { private final RecordCategoryService recordCategoryService; diff --git a/src/main/java/com/recordit/server/controller/RecordController.java b/src/main/java/com/recordit/server/controller/RecordController.java index 8b373eac..ce18168d 100644 --- a/src/main/java/com/recordit/server/controller/RecordController.java +++ b/src/main/java/com/recordit/server/controller/RecordController.java @@ -29,7 +29,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/record") +@RequestMapping("/api/record") public class RecordController { private final RecordService recordService; From acfd7cb86a408a6b15eae02e21d8496c675c27f3 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 4 Jan 2023 22:58:13 +0900 Subject: [PATCH 183/264] =?UTF-8?q?[BE-123]=20fix:=20=EA=B8=80=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C=20=EC=84=B8=EC=85=98=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=20=EC=9D=B4=EC=9A=A9=ED=95=98=EC=97=AC=20=EA=B8=80=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=EC=9E=90=EB=A5=BC=20=EB=8B=89=EB=84=A4=EC=9E=84?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/service/RecordService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index d726b1dc..81f96039 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -52,7 +52,7 @@ public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordReque // 3.numOfImage에 file 개수 대입 (개발 초기 단계에는 1개만 가능) // */ // } - sessionUtil.saveUserIdInSession(1L); + Long userIdBySession = sessionUtil.findUserIdBySession(); log.info("세션에서 찾은 사용자 ID : {}", userIdBySession); From 5ddb9c4e82e700f6bb3bb0ebe3d51e82cb47cebd Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 5 Jan 2023 00:34:04 +0900 Subject: [PATCH 184/264] =?UTF-8?q?[BE-122]=20fix:=20originPattern?= =?UTF-8?q?=EC=97=90=20final=20=ED=82=A4=EC=9B=8C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80,=20=EC=83=9D=EC=84=B1=EC=9E=90=EC=97=90=EC=84=9C=20Va?= =?UTF-8?q?lue=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/configuration/WebMvcConfiguration.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java index bc1e78a1..bfefdde1 100644 --- a/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/WebMvcConfiguration.java @@ -12,8 +12,14 @@ public class WebMvcConfiguration implements WebMvcConfigurer { private final long MAX_AGE_SECS = 3000; - @Value("${cors.origin}") - private String originPattern; + + private final String originPattern; + + public WebMvcConfiguration( + @Value("${cors.origin}") String originPattern + ) { + this.originPattern = originPattern; + } @Override public void addCorsMappings(CorsRegistry registry) { From d30f7abc36d386e40c7ecb4ce7835b1f8995fb25 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 5 Jan 2023 00:37:49 +0900 Subject: [PATCH 185/264] =?UTF-8?q?[BE-122]=20fix:=20application-test.yml?= =?UTF-8?q?=EC=97=90=20cors.origin=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/application-test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index da10b4ca..2a0bc97e 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -47,3 +47,6 @@ s3: bucket: ${S3_BUCKET_NAME:} directory: ${S3_DIRECTORY_NAME:} region: ap-northeast-2 + +cors: + origin: ${CORS_ORIGIN_NAME:} From 730d4567b1431c8f02461761853c437518aa072c Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 5 Jan 2023 17:37:15 +0900 Subject: [PATCH 186/264] =?UTF-8?q?[BE-125]=20fix:=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EC=A4=91=EB=B3=B5=EC=8B=9C=20true=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/controller/MemberController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index e2805108..e4d3af72 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -110,9 +110,9 @@ public ResponseEntity duplicateNicknameCheck(@RequestParam String nickname) { try { memberService.isDuplicateNickname(nickname); } catch (DuplicateNicknameException e) { - return ResponseEntity.status(HttpStatus.CONFLICT).body(false); + return ResponseEntity.status(HttpStatus.CONFLICT).body(true); } - return ResponseEntity.status(HttpStatus.OK).body(true); + return ResponseEntity.status(HttpStatus.OK).body(false); } } From faee43a671c24f403505e754038572f5c6a6e7d9 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 6 Jan 2023 01:01:16 +0900 Subject: [PATCH 187/264] =?UTF-8?q?[BE-133]=20fix:=20Redis=20=EC=84=B8?= =?UTF-8?q?=EC=85=98=20Serializer=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/configuration/RedisConfiguration.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/configuration/RedisConfiguration.java b/src/main/java/com/recordit/server/configuration/RedisConfiguration.java index 143402c9..5401acac 100644 --- a/src/main/java/com/recordit/server/configuration/RedisConfiguration.java +++ b/src/main/java/com/recordit/server/configuration/RedisConfiguration.java @@ -7,6 +7,8 @@ import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; @Configuration @@ -38,10 +40,14 @@ public RedisConnectionFactory redisConnectionFactory() { @Bean public StringRedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { StringRedisTemplate redisTemplate = new StringRedisTemplate(); + redisTemplate.setConnectionFactory(redisConnectionFactory); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new StringRedisSerializer()); - redisTemplate.setConnectionFactory(redisConnectionFactory); return redisTemplate; } + @Bean + public RedisSerializer springSessionDefaultRedisSerializer() { + return new Jackson2JsonRedisSerializer(Object.class); + } } From 77dc4a6e1a77a1073981542a89729d774a7e8e16 Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 6 Jan 2023 01:08:52 +0900 Subject: [PATCH 188/264] =?UTF-8?q?[BE-134]=20fix:=20EnableCaching=20?= =?UTF-8?q?=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EB=88=84?= =?UTF-8?q?=EB=9D=BD=20=EB=B2=84=EA=B7=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/RecordItServerApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/recordit/server/RecordItServerApplication.java b/src/main/java/com/recordit/server/RecordItServerApplication.java index 2ea64b33..fc245572 100644 --- a/src/main/java/com/recordit/server/RecordItServerApplication.java +++ b/src/main/java/com/recordit/server/RecordItServerApplication.java @@ -4,12 +4,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cache.annotation.EnableCaching; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication @EnableConfigurationProperties @ConfigurationPropertiesScan @EnableJpaAuditing +@EnableCaching public class RecordItServerApplication { public static void main(String[] args) { From 537efbd86cef6b43a6b4b011cb4da085f2dfecfa Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 6 Jan 2023 12:59:12 +0900 Subject: [PATCH 189/264] =?UTF-8?q?[BE-128]=20refactor:=20WriteCommentRequ?= =?UTF-8?q?estDto=EC=97=90=20validation=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/dto/comment/WriteCommentRequestDto.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java index 870e7225..9c1ec626 100644 --- a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java +++ b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java @@ -1,5 +1,6 @@ package com.recordit.server.dto.comment; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import com.fasterxml.jackson.databind.PropertyNamingStrategies; @@ -18,14 +19,16 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class WriteCommentRequestDto { + @ApiModelProperty(notes = "레코드의 id", required = true) + @NotNull(message = "레코드 ID를 지정해야 합니다") private Long recordId; @ApiModelProperty(notes = "자식 댓글일 경우 부모 댓글의 id") private Long parentId; @ApiModelProperty(notes = "댓글 내용", required = true) - @Size(max = 200) + @Size(max = 200, message = "댓글 내용은 200자를 넘길 수 없습니다") private String comment; } From e0e8be5c8ca8270a77b0057399e08ade343522b2 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 6 Jan 2023 12:59:38 +0900 Subject: [PATCH 190/264] =?UTF-8?q?[BE-128]=20feat:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=20=ED=9B=84=20=EC=9D=91=EB=8B=B5=20DTO=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/comment/WriteCommentResponseDto.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/recordit/server/dto/comment/WriteCommentResponseDto.java diff --git a/src/main/java/com/recordit/server/dto/comment/WriteCommentResponseDto.java b/src/main/java/com/recordit/server/dto/comment/WriteCommentResponseDto.java new file mode 100644 index 00000000..b73bdbcd --- /dev/null +++ b/src/main/java/com/recordit/server/dto/comment/WriteCommentResponseDto.java @@ -0,0 +1,26 @@ +package com.recordit.server.dto.comment; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import io.swagger.annotations.ApiModel; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Getter +@ToString +@ApiModel +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class WriteCommentResponseDto { + + private Long commentId; + + @Builder + public WriteCommentResponseDto(Long commentId) { + this.commentId = commentId; + } +} From c2ca81036b2913f00aa28d07ed7fad9dcefb8555 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 6 Jan 2023 12:59:56 +0900 Subject: [PATCH 191/264] =?UTF-8?q?[BE-128]=20feat:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=20=EC=B4=88=EA=B8=B0=20API=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/CommentController.java | 13 +++++++++---- .../recordit/server/service/CommentService.java | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/CommentController.java b/src/main/java/com/recordit/server/controller/CommentController.java index 1a111980..b0de84bd 100644 --- a/src/main/java/com/recordit/server/controller/CommentController.java +++ b/src/main/java/com/recordit/server/controller/CommentController.java @@ -15,6 +15,8 @@ import com.recordit.server.dto.comment.CommentRequestDto; import com.recordit.server.dto.comment.CommentResponseDto; import com.recordit.server.dto.comment.WriteCommentRequestDto; +import com.recordit.server.dto.comment.WriteCommentResponseDto; +import com.recordit.server.exception.ErrorMessage; import com.recordit.server.service.CommentService; import io.swagger.annotations.ApiOperation; @@ -36,15 +38,18 @@ public class CommentController { ) @ApiResponses({ @ApiResponse( - code = 200, message = "API 정상 작동" + code = 200, message = "API 정상 작동", response = WriteCommentResponseDto.class + ), + @ApiResponse( + code = 400, message = "잘못된 요청", response = ErrorMessage.class ) }) @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) - public ResponseEntity writeComment( + public ResponseEntity writeComment( @ApiParam(required = true) @RequestPart(required = true) @Valid WriteCommentRequestDto writeCommentRequestDto, - @ApiParam @RequestPart MultipartFile file + @ApiParam @RequestPart MultipartFile attachment ) { - return null; + return ResponseEntity.ok(commentService.writeComment(writeCommentRequestDto, attachment)); } @ApiOperation( diff --git a/src/main/java/com/recordit/server/service/CommentService.java b/src/main/java/com/recordit/server/service/CommentService.java index 80b6cf3a..966cc0f8 100644 --- a/src/main/java/com/recordit/server/service/CommentService.java +++ b/src/main/java/com/recordit/server/service/CommentService.java @@ -1,14 +1,28 @@ package com.recordit.server.service; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import com.recordit.server.dto.comment.WriteCommentRequestDto; +import com.recordit.server.dto.comment.WriteCommentResponseDto; import com.recordit.server.repository.CommentRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Service @RequiredArgsConstructor public class CommentService { + private final CommentRepository commentRepository; + @Transactional + public WriteCommentResponseDto writeComment( + WriteCommentRequestDto writeCommentRequestDto, + MultipartFile attachment + ) { + return null; + } } From d3f3b1f9e25f1078ef45b5f8b68113a5cb2c8ea5 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 6 Jan 2023 13:10:27 +0900 Subject: [PATCH 192/264] =?UTF-8?q?[BE-128]=20refactor:=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EB=82=B4=EC=9A=A9=20=EC=B5=9C=EB=8C=80=20100?= =?UTF-8?q?=EC=9E=90=EA=B9=8C=EC=A7=80=20=EC=A0=95=EC=B1=85=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/dto/comment/WriteCommentRequestDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java index 9c1ec626..21e2a617 100644 --- a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java +++ b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java @@ -28,7 +28,7 @@ public class WriteCommentRequestDto { private Long parentId; @ApiModelProperty(notes = "댓글 내용", required = true) - @Size(max = 200, message = "댓글 내용은 200자를 넘길 수 없습니다") + @Size(max = 100, message = "댓글 내용은 200자를 넘길 수 없습니다") private String comment; } From 1441ddc042f9d2b6b5d024499eb5905d0224cfb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=EC=9B=90?= Date: Fri, 6 Jan 2023 16:30:34 +0900 Subject: [PATCH 193/264] =?UTF-8?q?[BE-121]=20feat:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1,=20=EC=A1=B0=ED=9A=8C=EC=8B=9C?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=EC=A7=80=EA=B0=80=20DB=EC=97=90=20?= =?UTF-8?q?=EB=B0=98=EC=98=81=EB=90=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/ImageFileRepository.java | 7 +++++ .../server/repository/RecordRepository.java | 6 ++++ .../server/service/RecordService.java | 28 +++++++++++++------ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/recordit/server/repository/ImageFileRepository.java b/src/main/java/com/recordit/server/repository/ImageFileRepository.java index f9d5b08a..d12bdbbe 100644 --- a/src/main/java/com/recordit/server/repository/ImageFileRepository.java +++ b/src/main/java/com/recordit/server/repository/ImageFileRepository.java @@ -1,8 +1,15 @@ package com.recordit.server.repository; +import java.util.List; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import com.recordit.server.domain.ImageFile; public interface ImageFileRepository extends JpaRepository { + @Query("SELECT i.downloadUrl FROM IMAGE_FILE i WHERE i.refId = :refId") + Optional> findDownloadUrls(@Param("refId") Long recordId); } diff --git a/src/main/java/com/recordit/server/repository/RecordRepository.java b/src/main/java/com/recordit/server/repository/RecordRepository.java index e077bf88..44151185 100644 --- a/src/main/java/com/recordit/server/repository/RecordRepository.java +++ b/src/main/java/com/recordit/server/repository/RecordRepository.java @@ -1,6 +1,9 @@ package com.recordit.server.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import com.recordit.server.domain.Record; @@ -8,4 +11,7 @@ public interface RecordRepository extends JpaRepository { // @Query("select r from RECORD r join fetch r.writer join fetch r.recordColor join fetch r.recordIcon" // + " where r.id = :id") // Optional findById(Long id); + + @Query("SELECT MAX(r.id) FROM RECORD r") + Optional findLatestRecordId(); } diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 81f96039..568cc332 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -1,11 +1,13 @@ package com.recordit.server.service; import java.util.List; +import java.util.Optional; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import com.recordit.server.constant.RefType; import com.recordit.server.domain.Member; import com.recordit.server.domain.Record; import com.recordit.server.domain.RecordCategory; @@ -41,17 +43,23 @@ public class RecordService { private final RecordColorRepository recordColorRepository; private final RecordIconRepository recordIconRepository; private final RecordRepository recordRepository; + private final ImageFileService imageFileService; @Transactional public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordRequestDto, List files) { List urls = List.of(); - // if (!file.isEmpty()) { // 파일 데이터가 존재할 때 - // /* todo - // 1.이미지 저장 후 url 가져오기 - // 2.imageFileRepository에 save - // 3.numOfImage에 file 개수 대입 (개발 초기 단계에는 1개만 가능) - // */ - // } + + if (!files.isEmpty()) { + Optional optionalLong = recordRepository.findLatestRecordId(); + Long recordId = 1L; + + if (!optionalLong.isEmpty()) { + log.info("가장 최신의 레코드 ID : {} ", optionalLong.get()); + recordId = optionalLong.get() + 1; + } + + urls = imageFileService.saveAttachmentFiles(RefType.RECORD, recordId, files); + } Long userIdBySession = sessionUtil.findUserIdBySession(); log.info("세션에서 찾은 사용자 ID : {}", userIdBySession); @@ -91,7 +99,11 @@ public RecordDetailResponseDto getDetailRecord(Long recordId) { .orElseThrow(() -> new RecordNotFoundException("레코드 정보를 찾을 수 없습니다.")); List imageUrls = List.of(); - // List urls = imageFileService.findByRecordId(record.getId(), record.getNumOfImage()); + + Optional> optionalStrings = imageFileRepository.findDownloadUrls(recordId); + if (!optionalStrings.isEmpty()) { + imageUrls = optionalStrings.get(); + } return RecordDetailResponseDto.builder() .recordId(record.getId()) From 12bb538c56b3474a7d2750e711bdc61717cc2356 Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 6 Jan 2023 19:22:10 +0900 Subject: [PATCH 194/264] =?UTF-8?q?[BE-124]=20feat:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=ED=8C=90=EB=B3=84=20API=20-=20MemberController?= =?UTF-8?q?=EC=97=90=20loginCheck=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20-=20Redis=EC=97=90=EC=84=9C=20=EC=84=B8?= =?UTF-8?q?=EC=85=98=EC=9D=84=20=EC=A1=B0=ED=9A=8C=20=ED=9B=84=20id?= =?UTF-8?q?=EA=B0=92=EC=9D=B4=20null=EC=9D=B4=EB=9D=BC=EB=A9=B4=20403?= =?UTF-8?q?=EB=B0=98=ED=99=98=20-=20=EC=A0=95=EC=83=81=EC=A0=81=EC=9D=B4?= =?UTF-8?q?=EB=9D=BC=EB=A9=B4=20200=EB=B0=98=ED=99=98=20-=20=EC=84=B8?= =?UTF-8?q?=EC=85=98=EC=9D=B4=20=EC=97=86=EB=8A=94(=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=EC=9D=84=20=EC=8B=9C=EB=8F=84=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=9D=80)=20=EC=82=AC=EC=9A=A9=EC=9E=90=EB=8F=84=20?= =?UTF-8?q?=EC=84=B8=EC=85=98=EC=97=90=20=EC=A0=91=EA=B7=BC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=88=9C=EA=B0=84=20=EB=B9=84=EC=96=B4=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EC=84=B8=EC=85=98=EC=9D=B4=20=EC=83=9D=EA=B8=B0?= =?UTF-8?q?=EA=B8=B0=20=EB=96=84=EB=AC=B8=EC=97=90,=20=20=20invalidateSess?= =?UTF-8?q?ion=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=8B=A4=ED=96=89?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=84=B8=EC=85=98=EC=9D=84=20=EB=82=A0?= =?UTF-8?q?=EB=A0=A4=EC=A4=80=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/MemberController.java | 11 +++++++++++ .../exception/member/MemberExceptionHandler.java | 8 ++++++++ .../member/SessionAuthenticationException.java | 7 +++++++ .../java/com/recordit/server/util/SessionUtil.java | 13 +++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/member/SessionAuthenticationException.java diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index e4d3af72..a51691e4 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -20,6 +20,7 @@ import com.recordit.server.dto.member.RegisterSessionResponseDto; import com.recordit.server.exception.member.DuplicateNicknameException; import com.recordit.server.service.MemberService; +import com.recordit.server.util.SessionUtil; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -27,13 +28,16 @@ import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ResponseHeader; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; @RestController @RequiredArgsConstructor @RequestMapping("/api/member") +@Slf4j public class MemberController { private final MemberService memberService; + private final SessionUtil sessionUtil; @ApiOperation( value = "Oauth 로그인", @@ -115,4 +119,11 @@ public ResponseEntity duplicateNicknameCheck(@RequestParam String nickname) { return ResponseEntity.status(HttpStatus.OK).body(false); } + @GetMapping("/logincheck") + public ResponseEntity loginCheck() { + sessionUtil.isCorrectSession(); + log.info("정상적으로 로그인 되어있습니다."); + return ResponseEntity.ok().build(); + } + } diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index 41fc30c5..75b0bc09 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -50,5 +50,13 @@ public ResponseEntity handleRestClientException( return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(ErrorMessage.of(exception, HttpStatus.INTERNAL_SERVER_ERROR)); } + + @ExceptionHandler(SessionAuthenticationException.class) + public ResponseEntity handleSessionAuthenticationException( + SessionAuthenticationException exception) { + return ResponseEntity.status(HttpStatus.FORBIDDEN) + .body(ErrorMessage.of(exception, HttpStatus.INTERNAL_SERVER_ERROR)); + } + } diff --git a/src/main/java/com/recordit/server/exception/member/SessionAuthenticationException.java b/src/main/java/com/recordit/server/exception/member/SessionAuthenticationException.java new file mode 100644 index 00000000..514a05f9 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/member/SessionAuthenticationException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.member; + +public class SessionAuthenticationException extends RuntimeException { + public SessionAuthenticationException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/util/SessionUtil.java b/src/main/java/com/recordit/server/util/SessionUtil.java index abb400a3..0bb6028d 100644 --- a/src/main/java/com/recordit/server/util/SessionUtil.java +++ b/src/main/java/com/recordit/server/util/SessionUtil.java @@ -5,11 +5,14 @@ import org.springframework.stereotype.Component; import com.recordit.server.exception.member.NotFoundUserInfoInSessionException; +import com.recordit.server.exception.member.SessionAuthenticationException; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; @Component @RequiredArgsConstructor +@Slf4j public class SessionUtil { private static final String PREFIX_USER_ID = "LOGIN_USER_ID"; @@ -22,11 +25,21 @@ public void saveUserIdInSession(Long id) { public Long findUserIdBySession() { Long userId = (Long)httpSession.getAttribute(PREFIX_USER_ID); if (userId == null) { + invalidateSession(); + log.info("세션에서 사용자 정보를 찾지 못함"); throw new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다"); } return userId; } + public void isCorrectSession() { + if (httpSession.getAttribute(PREFIX_USER_ID) == null) { + log.info("로그인이 되어있지 않아 접근이 거부되었습니다."); + invalidateSession(); + throw new SessionAuthenticationException("로그인이 되어있지 않아 접근이 거부되었습니다."); + } + } + public void invalidateSession() { httpSession.invalidate(); } From 48f8c3c638b105a3a2b4e37b623142029bbf7622 Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 6 Jan 2023 20:36:20 +0900 Subject: [PATCH 195/264] =?UTF-8?q?[BE-124]=20fix:=20ExceptionHandler?= =?UTF-8?q?=EC=97=90=EC=84=9C=20body=EC=97=90=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/exception/member/MemberExceptionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index 75b0bc09..ac674413 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -55,7 +55,7 @@ public ResponseEntity handleRestClientException( public ResponseEntity handleSessionAuthenticationException( SessionAuthenticationException exception) { return ResponseEntity.status(HttpStatus.FORBIDDEN) - .body(ErrorMessage.of(exception, HttpStatus.INTERNAL_SERVER_ERROR)); + .body(ErrorMessage.of(exception, HttpStatus.FORBIDDEN)); } } From 3463104ad5840294741f931186584d7010858568 Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 6 Jan 2023 20:37:17 +0900 Subject: [PATCH 196/264] =?UTF-8?q?[BE-124]=20fix:=20findUserIdBySession?= =?UTF-8?q?=20log=20=EB=9D=BC=EC=9D=B4=ED=8C=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/util/SessionUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/util/SessionUtil.java b/src/main/java/com/recordit/server/util/SessionUtil.java index 0bb6028d..946de137 100644 --- a/src/main/java/com/recordit/server/util/SessionUtil.java +++ b/src/main/java/com/recordit/server/util/SessionUtil.java @@ -26,7 +26,7 @@ public Long findUserIdBySession() { Long userId = (Long)httpSession.getAttribute(PREFIX_USER_ID); if (userId == null) { invalidateSession(); - log.info("세션에서 사용자 정보를 찾지 못함"); + log.info("세션에 사용자 정보가 저장되어 있지 않습니다"); throw new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다"); } return userId; From 547a931f9daa48e0143ed6adfdf4e859234a106e Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 6 Jan 2023 20:40:09 +0900 Subject: [PATCH 197/264] =?UTF-8?q?[BE-124]=20=EB=A1=9C=EA=B7=B8=EC=9D=B8?= =?UTF-8?q?=20=ED=8C=90=EB=B3=84=20API=20Endpoint=EB=AA=85=20GET=20loginch?= =?UTF-8?q?eck=20->=20GET=20login=20=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/controller/MemberController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index a51691e4..c48c163a 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -119,8 +119,8 @@ public ResponseEntity duplicateNicknameCheck(@RequestParam String nickname) { return ResponseEntity.status(HttpStatus.OK).body(false); } - @GetMapping("/logincheck") - public ResponseEntity loginCheck() { + @GetMapping("/login") + public ResponseEntity checkLogin() { sessionUtil.isCorrectSession(); log.info("정상적으로 로그인 되어있습니다."); return ResponseEntity.ok().build(); From 36128c026f17be5f91c5a7eb2f69753979b93083 Mon Sep 17 00:00:00 2001 From: kdomo Date: Fri, 6 Jan 2023 20:42:40 +0900 Subject: [PATCH 198/264] =?UTF-8?q?[BE-124]=20fix:=20log=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/util/SessionUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/util/SessionUtil.java b/src/main/java/com/recordit/server/util/SessionUtil.java index 946de137..7a4ab75b 100644 --- a/src/main/java/com/recordit/server/util/SessionUtil.java +++ b/src/main/java/com/recordit/server/util/SessionUtil.java @@ -25,8 +25,8 @@ public void saveUserIdInSession(Long id) { public Long findUserIdBySession() { Long userId = (Long)httpSession.getAttribute(PREFIX_USER_ID); if (userId == null) { - invalidateSession(); log.info("세션에 사용자 정보가 저장되어 있지 않습니다"); + invalidateSession(); throw new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다"); } return userId; From d5aae95470e4a6e288cd91393cacd1aa63c7547f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 7 Jan 2023 22:48:06 +0900 Subject: [PATCH 199/264] =?UTF-8?q?[BE-135]=20fix:=20Session=20Serializer?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?Long=EC=9C=BC=EB=A1=9C=20=EB=B0=9B=EC=95=84=EC=98=A4=EB=8D=98?= =?UTF-8?q?=20=EA=B2=83=EC=9D=84=20Integer=EB=A1=9C=20=EB=B0=9B=EC=95=84?= =?UTF-8?q?=EC=98=A4=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/util/SessionUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/util/SessionUtil.java b/src/main/java/com/recordit/server/util/SessionUtil.java index 7a4ab75b..65672481 100644 --- a/src/main/java/com/recordit/server/util/SessionUtil.java +++ b/src/main/java/com/recordit/server/util/SessionUtil.java @@ -23,13 +23,13 @@ public void saveUserIdInSession(Long id) { } public Long findUserIdBySession() { - Long userId = (Long)httpSession.getAttribute(PREFIX_USER_ID); + Integer userId = (Integer)httpSession.getAttribute(PREFIX_USER_ID); if (userId == null) { log.info("세션에 사용자 정보가 저장되어 있지 않습니다"); invalidateSession(); throw new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다"); } - return userId; + return userId.longValue(); } public void isCorrectSession() { From 6275c4f59fa35ce3a023cc1f96a7e23db91a926a Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sun, 8 Jan 2023 15:27:10 +0900 Subject: [PATCH 200/264] =?UTF-8?q?[BE-136]=20refactor:=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=20=ED=8C=8C=EC=9D=BC=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=EB=A5=BC=20=EB=8B=A8=EC=9D=BC,=20?= =?UTF-8?q?=EB=B3=B5=EC=88=98=EA=B0=9C=20=EB=A9=94=EC=86=8C=EB=93=9C?= =?UTF-8?q?=EB=A1=9C=20=EB=82=98=EB=88=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/ImageFileService.java | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/recordit/server/service/ImageFileService.java b/src/main/java/com/recordit/server/service/ImageFileService.java index 0b7e4b95..c8ba66bc 100644 --- a/src/main/java/com/recordit/server/service/ImageFileService.java +++ b/src/main/java/com/recordit/server/service/ImageFileService.java @@ -1,7 +1,7 @@ package com.recordit.server.service; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; @@ -31,37 +31,43 @@ public class ImageFileService { private final S3Uploader s3Uploader; private final ApplicationEventPublisher applicationEventPublisher; + @Transactional + public String saveAttachmentFile( + @NonNull RefType refType, + @NonNull Long refId, + @NonNull MultipartFile attachment + ) { + validateEmptyFile(attachment); + validateImageContentType(attachment); + + String saveFileName = s3Uploader.upload(attachment); + log.info("S3에 저장한 파일 이름 : {}", saveFileName); + String saveFileUrl = s3Uploader.getUrlByFileName(saveFileName); + log.info("S3에 저장한 URL : {}", saveFileUrl); + applicationEventPublisher.publishEvent(S3ImageRollbackEvent.from(saveFileName)); + + imageFileRepository.save( + ImageFile.of( + refType, + refId, + saveFileUrl, + saveFileName, + attachment + ) + ); + + return saveFileUrl; + } + @Transactional public List saveAttachmentFiles( @NonNull RefType refType, @NonNull Long refId, @NonNull List attachments ) { - List imageUrls = new ArrayList<>(); - for (MultipartFile multipartFile : attachments) { - validateEmptyFile(multipartFile); - validateImageContentType(multipartFile); - - String saveFileName = s3Uploader.upload(multipartFile); - log.info("S3에 저장한 파일 이름 : {}", saveFileName); - String saveFileUrl = s3Uploader.getUrlByFileName(saveFileName); - log.info("S3에 저장한 URL : {}", saveFileUrl); - applicationEventPublisher.publishEvent(S3ImageRollbackEvent.from(saveFileName)); - - imageFileRepository.save( - ImageFile.of( - refType, - refId, - saveFileUrl, - saveFileName, - multipartFile - ) - ); - imageUrls.add(saveFileUrl); - log.info("이미지 파일 저장 성공 및 URL : {}", saveFileUrl); - } - - return imageUrls; + return attachments.stream() + .map(attachment -> saveAttachmentFile(refType, refId, attachment)) + .collect(Collectors.toList()); } @TransactionalEventListener(classes = S3ImageRollbackEvent.class, phase = TransactionPhase.AFTER_ROLLBACK) From b998a469988554c94b604ebe2ad508515fb6f0dc Mon Sep 17 00:00:00 2001 From: kdomo Date: Sun, 8 Jan 2023 21:27:36 +0900 Subject: [PATCH 201/264] =?UTF-8?q?[BE-137]=20fix:=20swagger=20endpoint?= =?UTF-8?q?=EB=AA=85=EC=97=90=20/api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 2 ++ src/main/resources/application-local.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index bf3fca6b..db0fc027 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -26,6 +26,8 @@ springfox: documentation: swagger: use-model-v3: false + swagger-ui: + base-url: /api logging: config: classpath:log4j2-dev.xml cors: diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 0f8dd633..e31a5b3a 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -26,6 +26,8 @@ springfox: documentation: swagger: use-model-v3: false + swagger-ui: + base-url: /api logging: config: classpath:log4j2-local.xml cors: From 34a1091deec431fef241ba9bd1c017e16c201647 Mon Sep 17 00:00:00 2001 From: kdomo Date: Sun, 8 Jan 2023 23:28:10 +0900 Subject: [PATCH 202/264] =?UTF-8?q?[BE-132]=20fix:=20log=EC=97=90=20Swagge?= =?UTF-8?q?r=20=EC=A0=91=EC=86=8D=20=EB=A1=9C=EA=B7=B8=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HTTPLogFilter 에서 Swagger에 대한 로그를 제거하였습니다 --- .../recordit/server/logger/HTTPLogFilter.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/logger/HTTPLogFilter.java b/src/main/java/com/recordit/server/logger/HTTPLogFilter.java index 959c6101..270afba1 100644 --- a/src/main/java/com/recordit/server/logger/HTTPLogFilter.java +++ b/src/main/java/com/recordit/server/logger/HTTPLogFilter.java @@ -39,9 +39,13 @@ public void doFilter( ); long start = System.currentTimeMillis(); - chain.doFilter(requestWrapper, responseWrapper); + chain.doFilter(request, response); long end = System.currentTimeMillis(); + if (isInExcludeURIForLog(request)) { + return; + } + log.info("\n" + "[REQUEST] {} - {} {} - {}ms\n" + "Headers : {}\n" + @@ -58,6 +62,16 @@ public void doFilter( getResponseBody(responseWrapper)); } + private boolean isInExcludeURIForLog(ServletRequest request) { + if (((HttpServletRequest)request).getRequestURI().contains("/api/swagger")) { + return true; + } + if ("/v2/api-docs".equals(((HttpServletRequest)request).getRequestURI())) { + return true; + } + return false; + } + private Map getHeaders(HttpServletRequest request) { Map headerMap = new HashMap<>(); From d426cdba4c23ecd18fc21acb108e2a7408e32372 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sun, 8 Jan 2023 23:56:14 +0900 Subject: [PATCH 203/264] =?UTF-8?q?[BE-138]=20refactor:=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EC=99=80=20=EB=8C=93=EA=B8=80=EC=97=90=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=A0=80=EC=9E=A5=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=20Column=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/domain/Comment.java | 2 -- src/main/java/com/recordit/server/domain/Record.java | 7 ------- 2 files changed, 9 deletions(-) diff --git a/src/main/java/com/recordit/server/domain/Comment.java b/src/main/java/com/recordit/server/domain/Comment.java index 3e3b5fa0..7b80976b 100644 --- a/src/main/java/com/recordit/server/domain/Comment.java +++ b/src/main/java/com/recordit/server/domain/Comment.java @@ -35,6 +35,4 @@ public class Comment extends BaseEntity { @Column(name = "CONTENT") private String content; - @Column(name = "NUM_OF_IMAGE") - private Integer numOfImage; } diff --git a/src/main/java/com/recordit/server/domain/Record.java b/src/main/java/com/recordit/server/domain/Record.java index 1b7be6e4..19abccdf 100644 --- a/src/main/java/com/recordit/server/domain/Record.java +++ b/src/main/java/com/recordit/server/domain/Record.java @@ -45,9 +45,6 @@ public class Record extends BaseEntity { @Column(name = "CONTENT") private String content; - @Column(name = "NUM_OF_IMAGE") - private Integer numOfImage; - @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "RECORD_COLOR_ID") private RecordColor recordColor; @@ -61,7 +58,6 @@ private Record( Member writer, String title, String content, - Integer numOfImage, RecordColor recordColor, RecordIcon recordIcon ) { @@ -69,7 +65,6 @@ private Record( this.writer = writer; this.title = title; this.content = content; - this.numOfImage = numOfImage; this.recordColor = recordColor; this.recordIcon = recordIcon; } @@ -78,7 +73,6 @@ public static Record of( WriteRecordRequestDto writeRecordRequestDto, RecordCategory recordCategory, Member member, - Integer numOfImage, RecordColor recordColor, RecordIcon recordIcon ) { @@ -87,7 +81,6 @@ public static Record of( member, writeRecordRequestDto.getTitle(), writeRecordRequestDto.getContent(), - numOfImage, recordColor, recordIcon ); From 609f295e973c6913674b744b7904b648ff0744c6 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sun, 8 Jan 2023 23:57:09 +0900 Subject: [PATCH 204/264] =?UTF-8?q?[BE-138]=20fix:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EC=97=90=EC=84=9C=20Serializer=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20=EB=95=8C=EB=AC=B8=EC=97=90=20given=EC=9D=84=20Integer?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/recordit/server/util/SessionUtilTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/recordit/server/util/SessionUtilTest.java b/src/test/java/com/recordit/server/util/SessionUtilTest.java index 0999c0ac..bfd3469f 100644 --- a/src/test/java/com/recordit/server/util/SessionUtilTest.java +++ b/src/test/java/com/recordit/server/util/SessionUtilTest.java @@ -42,14 +42,14 @@ class 세션에서_userId를_찾을_때 { @DisplayName("세션에 userId가 있으면 값이 찾아와진다") void 세션에_정상적으로_userId를_저장하고_있으면_정상적으로_값이_찾아와진다() { // given - long userId = 1L; + Integer userId = 1; // Session Serializer 때문에 원래 Long을 넣어야 하지만 테스트에서 Integer를 사용 mockHttpSession.setAttribute("LOGIN_USER_ID", userId); // when Long userIdBySession = sessionUtil.findUserIdBySession(); // then - assertThat(userIdBySession.longValue()).isEqualTo(userId); + assertThat(userIdBySession.longValue()).isEqualTo(1L); assertThatCode(() -> sessionUtil.findUserIdBySession()).doesNotThrowAnyException(); } From 532d731ffa37ca053c6a7f298f8f2ff926527467 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 9 Jan 2023 00:18:22 +0900 Subject: [PATCH 205/264] =?UTF-8?q?[BE-128]=20feat:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=20=EA=B4=80=EB=A0=A8=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=99=80=20=EC=98=88=EC=99=B8=20=ED=95=B8=EB=93=A4=EB=9F=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/CommentExceptionHandler.java | 35 +++++++++++++++++++ .../comment/CommentNotFoundException.java | 7 ++++ .../comment/EmptyContentException.java | 7 ++++ 3 files changed, 49 insertions(+) create mode 100644 src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java create mode 100644 src/main/java/com/recordit/server/exception/comment/CommentNotFoundException.java create mode 100644 src/main/java/com/recordit/server/exception/comment/EmptyContentException.java diff --git a/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java b/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java new file mode 100644 index 00000000..ef6acfeb --- /dev/null +++ b/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java @@ -0,0 +1,35 @@ +package com.recordit.server.exception.comment; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import com.recordit.server.controller.CommentController; +import com.recordit.server.exception.ErrorMessage; +import com.recordit.server.exception.record.RecordNotFoundException; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestControllerAdvice(basePackageClasses = CommentController.class) +public class CommentExceptionHandler { + + @ExceptionHandler(EmptyContentException.class) + public ResponseEntity handleEmptyContentException(EmptyContentException exception) { + return ResponseEntity.badRequest() + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); + } + + @ExceptionHandler(RecordNotFoundException.class) + public ResponseEntity handleRecordNotFoundException(RecordNotFoundException exception) { + return ResponseEntity.badRequest() + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); + } + + @ExceptionHandler(CommentNotFoundException.class) + public ResponseEntity handleCommentNotFoundException(CommentNotFoundException exception) { + return ResponseEntity.badRequest() + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); + } +} diff --git a/src/main/java/com/recordit/server/exception/comment/CommentNotFoundException.java b/src/main/java/com/recordit/server/exception/comment/CommentNotFoundException.java new file mode 100644 index 00000000..0c44b232 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/comment/CommentNotFoundException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.comment; + +public class CommentNotFoundException extends RuntimeException { + public CommentNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/exception/comment/EmptyContentException.java b/src/main/java/com/recordit/server/exception/comment/EmptyContentException.java new file mode 100644 index 00000000..33fde658 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/comment/EmptyContentException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.comment; + +public class EmptyContentException extends RuntimeException { + public EmptyContentException(String message) { + super(message); + } +} From dd690ac79f8bb1da5af379d8002972743643253b Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 9 Jan 2023 00:19:28 +0900 Subject: [PATCH 206/264] =?UTF-8?q?[BE-128]=20feat:=20WriteCommentRequestD?= =?UTF-8?q?to=20Builder=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/dto/comment/WriteCommentRequestDto.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java index 21e2a617..b7b86d87 100644 --- a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java +++ b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java @@ -9,6 +9,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; @@ -31,4 +32,10 @@ public class WriteCommentRequestDto { @Size(max = 100, message = "댓글 내용은 200자를 넘길 수 없습니다") private String comment; + @Builder + public WriteCommentRequestDto(Long recordId, Long parentId, String comment) { + this.recordId = recordId; + this.parentId = parentId; + this.comment = comment; + } } From 2e61947caa8c329dbcdfbef93eda50e8e446b12b Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 9 Jan 2023 16:00:48 +0900 Subject: [PATCH 207/264] =?UTF-8?q?[BE-138]=20fix:=20Record=20Entity?= =?UTF-8?q?=EC=97=90=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EA=B0=9C=EC=88=98=20?= =?UTF-8?q?column=EC=A0=9C=EA=B1=B0=EC=97=90=20=EB=94=B0=EB=9D=BC=20record?= =?UTF-8?q?=20of=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/service/RecordService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 81f96039..3a5ecb77 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -72,7 +72,6 @@ public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordReque writeRecordRequestDto, recordCategory, member, - urls.size(), recordColor, recordIcon ); From a8520fb44d1fc8c2dfd1f6d0a27dc807cc1b9e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=EC=9B=90?= Date: Mon, 9 Jan 2023 16:23:45 +0900 Subject: [PATCH 208/264] =?UTF-8?q?[BE-121]=20refactor=20:=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=EB=A9=94=EC=86=8C=EB=93=9C=20=EB=B0=8F=20=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../record/RecordImageNotFoundException.java | 8 +++++++ .../repository/ImageFileRepository.java | 8 +++---- .../server/service/RecordService.java | 22 ++++++++++++++++--- 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/recordit/server/exception/record/RecordImageNotFoundException.java diff --git a/src/main/java/com/recordit/server/exception/record/RecordImageNotFoundException.java b/src/main/java/com/recordit/server/exception/record/RecordImageNotFoundException.java new file mode 100644 index 00000000..de257ba4 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/record/RecordImageNotFoundException.java @@ -0,0 +1,8 @@ +package com.recordit.server.exception.record; + +public class RecordImageNotFoundException extends RuntimeException { + + public RecordImageNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/com/recordit/server/repository/ImageFileRepository.java b/src/main/java/com/recordit/server/repository/ImageFileRepository.java index d12bdbbe..97f42cc2 100644 --- a/src/main/java/com/recordit/server/repository/ImageFileRepository.java +++ b/src/main/java/com/recordit/server/repository/ImageFileRepository.java @@ -4,12 +4,12 @@ import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; +import com.recordit.server.constant.RefType; import com.recordit.server.domain.ImageFile; public interface ImageFileRepository extends JpaRepository { - @Query("SELECT i.downloadUrl FROM IMAGE_FILE i WHERE i.refId = :refId") - Optional> findDownloadUrls(@Param("refId") Long recordId); + + Optional> findByRefIdAndRefType(Long refId, RefType refType); + } diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 568cc332..6e70d9fd 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -1,5 +1,6 @@ package com.recordit.server.service; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -8,6 +9,7 @@ import org.springframework.web.multipart.MultipartFile; import com.recordit.server.constant.RefType; +import com.recordit.server.domain.ImageFile; import com.recordit.server.domain.Member; import com.recordit.server.domain.Record; import com.recordit.server.domain.RecordCategory; @@ -19,6 +21,7 @@ import com.recordit.server.exception.member.MemberNotFoundException; import com.recordit.server.exception.record.RecordColorNotFoundException; import com.recordit.server.exception.record.RecordIconNotFoundException; +import com.recordit.server.exception.record.RecordImageNotFoundException; import com.recordit.server.exception.record.RecordNotFoundException; import com.recordit.server.exception.record.category.RecordCategoryNotFoundException; import com.recordit.server.repository.ImageFileRepository; @@ -100,10 +103,23 @@ public RecordDetailResponseDto getDetailRecord(Long recordId) { List imageUrls = List.of(); - Optional> optionalStrings = imageFileRepository.findDownloadUrls(recordId); - if (!optionalStrings.isEmpty()) { + List imageFileList = imageFileRepository + .findByRefIdAndRefType(recordId, RefType.RECORD) + .orElseThrow(() -> new RecordImageNotFoundException("레코드의 이미지가 존재하지 않습니다.")); + + List foundImageUrlList = new ArrayList<>(); + imageFileList.stream().forEach( + (imageFile) -> { + foundImageUrlList.add(imageFile.getDownloadUrl()); + } + ); + + imageUrls = foundImageUrlList; + + + /*if (!optionalStrings.isEmpty()) { imageUrls = optionalStrings.get(); - } + }*/ return RecordDetailResponseDto.builder() .recordId(record.getId()) From 5430ae8811c754d273a0c6bbb27a44854391c925 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 9 Jan 2023 17:41:43 +0900 Subject: [PATCH 209/264] =?UTF-8?q?[BE-128]=20feat:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=EC=97=90=20=EC=9E=91=EC=84=B1=EC=9E=90=20Column=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/domain/Comment.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/recordit/server/domain/Comment.java b/src/main/java/com/recordit/server/domain/Comment.java index 7b80976b..1e53f66e 100644 --- a/src/main/java/com/recordit/server/domain/Comment.java +++ b/src/main/java/com/recordit/server/domain/Comment.java @@ -28,6 +28,14 @@ public class Comment extends BaseEntity { @Column(name = "COMMENT_ID") private Long id; + @ManyToOne + @JoinColumn(name = "MEMBER_ID") + private Member writer; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "RECORD_ID") + private Record record; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "PARENT_COMMENT_ID") private Comment parentComment; @@ -35,4 +43,14 @@ public class Comment extends BaseEntity { @Column(name = "CONTENT") private String content; + private Comment(Member writer, Record record, Comment parentComment, String content) { + this.writer = writer; + this.record = record; + this.parentComment = parentComment; + this.content = content; + } + + public static Comment of(Member writer, Record record, Comment parentComment, String content) { + return new Comment(writer, record, parentComment, content); + } } From 53ad3bc17eeda1f846da2685d57fb4a9382f1d9d Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 9 Jan 2023 17:42:27 +0900 Subject: [PATCH 210/264] =?UTF-8?q?[BE-128]=20feat:=20=EC=84=B8=EC=85=98?= =?UTF-8?q?=EC=97=90=20=EB=8B=B4=EA=B8=B4=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?ID=EA=B0=80=20DB=EC=97=90=20=EC=A1=B4=EC=9E=AC=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=84=20=EB=95=8C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=20=ED=95=B8=EB=93=A4=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/exception/comment/CommentExceptionHandler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java b/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java index ef6acfeb..b4d15574 100644 --- a/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java @@ -7,6 +7,7 @@ import com.recordit.server.controller.CommentController; import com.recordit.server.exception.ErrorMessage; +import com.recordit.server.exception.member.MemberNotFoundException; import com.recordit.server.exception.record.RecordNotFoundException; import lombok.extern.slf4j.Slf4j; @@ -32,4 +33,10 @@ public ResponseEntity handleCommentNotFoundException(CommentNotFou return ResponseEntity.badRequest() .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); } + + @ExceptionHandler(MemberNotFoundException.class) + public ResponseEntity handleMemberNotFoundException(MemberNotFoundException exception) { + return ResponseEntity.badRequest() + .body(ErrorMessage.of(exception, HttpStatus.INTERNAL_SERVER_ERROR)); + } } From 2abe0bb44ee9be29fa3c2ea56a1ec600ca4b93ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=EC=9B=90?= Date: Mon, 9 Jan 2023 17:44:38 +0900 Subject: [PATCH 211/264] =?UTF-8?q?[BE-121]=20refactor:=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1,=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=BF=BC=EB=A6=AC=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EB=B0=8F=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../record/RecordImageNotFoundException.java | 8 --- .../repository/ImageFileRepository.java | 1 - .../server/repository/RecordRepository.java | 5 -- .../server/service/RecordService.java | 49 +++++++------------ 4 files changed, 18 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/com/recordit/server/exception/record/RecordImageNotFoundException.java diff --git a/src/main/java/com/recordit/server/exception/record/RecordImageNotFoundException.java b/src/main/java/com/recordit/server/exception/record/RecordImageNotFoundException.java deleted file mode 100644 index de257ba4..00000000 --- a/src/main/java/com/recordit/server/exception/record/RecordImageNotFoundException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.recordit.server.exception.record; - -public class RecordImageNotFoundException extends RuntimeException { - - public RecordImageNotFoundException(String message) { - super(message); - } -} diff --git a/src/main/java/com/recordit/server/repository/ImageFileRepository.java b/src/main/java/com/recordit/server/repository/ImageFileRepository.java index 97f42cc2..cffa0df9 100644 --- a/src/main/java/com/recordit/server/repository/ImageFileRepository.java +++ b/src/main/java/com/recordit/server/repository/ImageFileRepository.java @@ -9,7 +9,6 @@ import com.recordit.server.domain.ImageFile; public interface ImageFileRepository extends JpaRepository { - Optional> findByRefIdAndRefType(Long refId, RefType refType); } diff --git a/src/main/java/com/recordit/server/repository/RecordRepository.java b/src/main/java/com/recordit/server/repository/RecordRepository.java index 44151185..2fafe07a 100644 --- a/src/main/java/com/recordit/server/repository/RecordRepository.java +++ b/src/main/java/com/recordit/server/repository/RecordRepository.java @@ -1,9 +1,6 @@ package com.recordit.server.repository; -import java.util.Optional; - import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import com.recordit.server.domain.Record; @@ -12,6 +9,4 @@ public interface RecordRepository extends JpaRepository { // + " where r.id = :id") // Optional findById(Long id); - @Query("SELECT MAX(r.id) FROM RECORD r") - Optional findLatestRecordId(); } diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 8a77ef7c..1506ff37 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -21,7 +21,6 @@ import com.recordit.server.exception.member.MemberNotFoundException; import com.recordit.server.exception.record.RecordColorNotFoundException; import com.recordit.server.exception.record.RecordIconNotFoundException; -import com.recordit.server.exception.record.RecordImageNotFoundException; import com.recordit.server.exception.record.RecordNotFoundException; import com.recordit.server.exception.record.category.RecordCategoryNotFoundException; import com.recordit.server.repository.ImageFileRepository; @@ -50,19 +49,6 @@ public class RecordService { @Transactional public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordRequestDto, List files) { - List urls = List.of(); - - if (!files.isEmpty()) { - Optional optionalLong = recordRepository.findLatestRecordId(); - Long recordId = 1L; - - if (!optionalLong.isEmpty()) { - log.info("가장 최신의 레코드 ID : {} ", optionalLong.get()); - recordId = optionalLong.get() + 1; - } - - urls = imageFileService.saveAttachmentFiles(RefType.RECORD, recordId, files); - } Long userIdBySession = sessionUtil.findUserIdBySession(); log.info("세션에서 찾은 사용자 ID : {}", userIdBySession); @@ -90,6 +76,11 @@ public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordReque Long recordId = recordRepository.save(record).getId(); log.info("저장한 레코드 ID : ", record); + if (files != null) { + List urls = imageFileService.saveAttachmentFiles(RefType.RECORD, recordId, files); + log.info("저장된 이미지 urls : {}", urls); + } + return WriteRecordResponseDto.builder() .recordId(recordId) .build(); @@ -102,23 +93,19 @@ public RecordDetailResponseDto getDetailRecord(Long recordId) { List imageUrls = List.of(); - List imageFileList = imageFileRepository - .findByRefIdAndRefType(recordId, RefType.RECORD) - .orElseThrow(() -> new RecordImageNotFoundException("레코드의 이미지가 존재하지 않습니다.")); - - List foundImageUrlList = new ArrayList<>(); - imageFileList.stream().forEach( - (imageFile) -> { - foundImageUrlList.add(imageFile.getDownloadUrl()); - } - ); - - imageUrls = foundImageUrlList; - - - /*if (!optionalStrings.isEmpty()) { - imageUrls = optionalStrings.get(); - }*/ + Optional> optionalImageFileList = imageFileRepository.findByRefIdAndRefType(recordId, + RefType.RECORD); + + if (!optionalImageFileList.isEmpty()) { + List foundImageUrlList = new ArrayList<>(); + optionalImageFileList.get().stream() + .forEach( + (imageFile) -> { + foundImageUrlList.add(imageFile.getDownloadUrl()); + } + ); + imageUrls = foundImageUrlList; + } return RecordDetailResponseDto.builder() .recordId(record.getId()) From 84c59d2ac30f33178d194ba534272d0331257046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9E=AC=EC=9B=90?= Date: Mon, 9 Jan 2023 18:09:29 +0900 Subject: [PATCH 212/264] =?UTF-8?q?[BE-121]=20refactor:=20=EB=A0=88?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1,=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A0=88=EC=9D=B4=EC=96=B4=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/service/RecordService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 1506ff37..9a1c85ac 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -1,6 +1,6 @@ package com.recordit.server.service; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -74,7 +74,7 @@ public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordReque ); Long recordId = recordRepository.save(record).getId(); - log.info("저장한 레코드 ID : ", record); + log.info("저장한 레코드 ID : ", recordId); if (files != null) { List urls = imageFileService.saveAttachmentFiles(RefType.RECORD, recordId, files); @@ -91,20 +91,20 @@ public RecordDetailResponseDto getDetailRecord(Long recordId) { Record record = recordRepository.findById(recordId) .orElseThrow(() -> new RecordNotFoundException("레코드 정보를 찾을 수 없습니다.")); - List imageUrls = List.of(); + List imageUrls = Collections.emptyList(); Optional> optionalImageFileList = imageFileRepository.findByRefIdAndRefType(recordId, RefType.RECORD); if (!optionalImageFileList.isEmpty()) { - List foundImageUrlList = new ArrayList<>(); + optionalImageFileList.get().stream() .forEach( (imageFile) -> { - foundImageUrlList.add(imageFile.getDownloadUrl()); + imageUrls.add(imageFile.getDownloadUrl()); } ); - imageUrls = foundImageUrlList; + } return RecordDetailResponseDto.builder() From 4963c904f6ed511aefe48a42e28cee15c6c9db63 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 9 Jan 2023 19:14:51 +0900 Subject: [PATCH 213/264] =?UTF-8?q?[BE-128]=20feat:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/CommentService.java | 59 +++++- .../server/service/CommentServiceTest.java | 184 ++++++++++++++++++ 2 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/recordit/server/service/CommentServiceTest.java diff --git a/src/main/java/com/recordit/server/service/CommentService.java b/src/main/java/com/recordit/server/service/CommentService.java index 966cc0f8..5344c0e3 100644 --- a/src/main/java/com/recordit/server/service/CommentService.java +++ b/src/main/java/com/recordit/server/service/CommentService.java @@ -2,11 +2,24 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; +import com.recordit.server.constant.RefType; +import com.recordit.server.domain.Comment; +import com.recordit.server.domain.Member; +import com.recordit.server.domain.Record; import com.recordit.server.dto.comment.WriteCommentRequestDto; import com.recordit.server.dto.comment.WriteCommentResponseDto; +import com.recordit.server.exception.comment.CommentNotFoundException; +import com.recordit.server.exception.comment.EmptyContentException; +import com.recordit.server.exception.member.MemberNotFoundException; +import com.recordit.server.exception.member.NotFoundUserInfoInSessionException; +import com.recordit.server.exception.record.RecordNotFoundException; import com.recordit.server.repository.CommentRepository; +import com.recordit.server.repository.MemberRepository; +import com.recordit.server.repository.RecordRepository; +import com.recordit.server.util.SessionUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -16,13 +29,57 @@ @RequiredArgsConstructor public class CommentService { + private final ImageFileService imageFileService; private final CommentRepository commentRepository; + private final MemberRepository memberRepository; + private final RecordRepository recordRepository; + private final SessionUtil sessionUtil; @Transactional public WriteCommentResponseDto writeComment( WriteCommentRequestDto writeCommentRequestDto, MultipartFile attachment ) { - return null; + validateEmptyContent(writeCommentRequestDto, attachment); + + Member writer = null; + try { + writer = memberRepository.findById(sessionUtil.findUserIdBySession()) + .orElseThrow(() -> new MemberNotFoundException("세션에 저장된 사용자가 DB에 존재하지 않습니다.")); + } catch (NotFoundUserInfoInSessionException e) { + } + + Record record = recordRepository.findById(writeCommentRequestDto.getRecordId()) + .orElseThrow(() -> new RecordNotFoundException("댓글을 작성할 레코드가 존재하지 않습니다.")); + + Comment parentComment = (writeCommentRequestDto.getParentId() == null) ? null : + commentRepository.findById(writeCommentRequestDto.getParentId()) + .orElseThrow(() -> new CommentNotFoundException("지정한 부모 댓글이 존재하지 않습니다.")); + + Comment saveComment = commentRepository.save( + Comment.of( + writer, + record, + parentComment, + writeCommentRequestDto.getComment() + ) + ); + + imageFileService.saveAttachmentFile(RefType.COMMENT, saveComment.getId(), attachment); + + log.info("저장한 댓글 ID : {}", saveComment.getId()); + + return WriteCommentResponseDto.builder() + .commentId(saveComment.getId()) + .build(); + } + + private void validateEmptyContent( + WriteCommentRequestDto writeCommentRequestDto, + MultipartFile attachment + ) { + if (attachment.isEmpty() && !StringUtils.hasText(writeCommentRequestDto.getComment())) { + throw new EmptyContentException("댓글 내용과 이미지 파일 모두 비어있을 수 없습니다."); + } } } diff --git a/src/test/java/com/recordit/server/service/CommentServiceTest.java b/src/test/java/com/recordit/server/service/CommentServiceTest.java new file mode 100644 index 00000000..482ecfb2 --- /dev/null +++ b/src/test/java/com/recordit/server/service/CommentServiceTest.java @@ -0,0 +1,184 @@ +package com.recordit.server.service; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.BDDMockito.*; + +import java.util.Optional; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.mock.web.MockMultipartFile; + +import com.recordit.server.domain.Comment; +import com.recordit.server.domain.Record; +import com.recordit.server.dto.comment.WriteCommentRequestDto; +import com.recordit.server.dto.comment.WriteCommentResponseDto; +import com.recordit.server.exception.comment.CommentNotFoundException; +import com.recordit.server.exception.comment.EmptyContentException; +import com.recordit.server.exception.member.MemberNotFoundException; +import com.recordit.server.exception.member.NotFoundUserInfoInSessionException; +import com.recordit.server.exception.record.RecordNotFoundException; +import com.recordit.server.repository.CommentRepository; +import com.recordit.server.repository.MemberRepository; +import com.recordit.server.repository.RecordRepository; +import com.recordit.server.util.SessionUtil; + +@ExtendWith(MockitoExtension.class) +public class CommentServiceTest { + + @InjectMocks + private CommentService commentService; + + @Mock + private ImageFileService imageFileService; + + @Mock + private CommentRepository commentRepository; + + @Mock + private MemberRepository memberRepository; + + @Mock + private RecordRepository recordRepository; + + @Mock + private SessionUtil sessionUtil; + + @Nested + @DisplayName("댓글을 작성 할 때") + class 댓글을_작성_할_때 { + + @Test + @DisplayName("내용과 첨부파일이 모두 비어있다면 예외를 던진다") + void 내용과_첨부파일이_모두_비어있다면_예외를_던진다() { + // given + WriteCommentRequestDto writeCommentRequestDto = WriteCommentRequestDto.builder() + .recordId(1L) + .parentId(1L) + .comment("") + .build(); + MockMultipartFile multipartFile = mock(MockMultipartFile.class); + + given(multipartFile.isEmpty()) + .willReturn(true); + + // when, then + assertThatThrownBy(() -> commentService.writeComment(writeCommentRequestDto, multipartFile)) + .isInstanceOf(EmptyContentException.class); + } + + @Test + @DisplayName("세션에 저장된 사용자가 DB에 존재하지 않으면 예외를 던진다") + void 세션에_저장된_사용자가_DB에_존재하지_않으면_예외를_던진다() { + // given + WriteCommentRequestDto writeCommentRequestDto = WriteCommentRequestDto.builder() + .recordId(1L) + .parentId(1L) + .comment("test") + .build(); + MockMultipartFile multipartFile = mock(MockMultipartFile.class); + + given(multipartFile.isEmpty()) + .willReturn(false); + given(sessionUtil.findUserIdBySession()) + .willReturn(1L); + given(memberRepository.findById(1L)) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> commentService.writeComment(writeCommentRequestDto, multipartFile)) + .isInstanceOf(MemberNotFoundException.class); + + } + + @Test + @DisplayName("지정한 레코드가 존재하지 않으면 예외를 던진다") + void 지정한_레코드가_존재하지_않으면_예외를_던진다() { + // given + WriteCommentRequestDto writeCommentRequestDto = WriteCommentRequestDto.builder() + .recordId(1L) + .parentId(1L) + .comment("test") + .build(); + MockMultipartFile multipartFile = mock(MockMultipartFile.class); + + given(multipartFile.isEmpty()) + .willReturn(false); + given(recordRepository.findById(writeCommentRequestDto.getRecordId())) + .willReturn(Optional.empty()); + given(sessionUtil.findUserIdBySession()) + .willThrow(new NotFoundUserInfoInSessionException("")); + + // when, then + assertThatThrownBy(() -> commentService.writeComment(writeCommentRequestDto, multipartFile)) + .isInstanceOf(RecordNotFoundException.class); + } + + @Test + @DisplayName("지정한 부모 댓글이 존재하지 않으면 예외를 던진다") + void 지정한_부모_댓글이_존재하지_않으면_예외를_던진다() { + // given + WriteCommentRequestDto writeCommentRequestDto = WriteCommentRequestDto.builder() + .recordId(1L) + .parentId(1L) + .comment("test") + .build(); + MockMultipartFile multipartFile = mock(MockMultipartFile.class); + Record record = mock(Record.class); + + given(multipartFile.isEmpty()) + .willReturn(false); + given(recordRepository.findById(writeCommentRequestDto.getRecordId())) + .willReturn(Optional.of(record)); + given(commentRepository.findById(writeCommentRequestDto.getParentId())) + .willReturn(Optional.empty()); + given(sessionUtil.findUserIdBySession()) + .willThrow(new NotFoundUserInfoInSessionException("")); + + // when, then + assertThatThrownBy(() -> commentService.writeComment(writeCommentRequestDto, multipartFile)) + .isInstanceOf(CommentNotFoundException.class); + } + + @Test + @DisplayName("정상적으로 작성이 완료되면 ID를 반환한다") + void 정상적으로_작성이_완료되면_ID를_반환한다() { + // given + WriteCommentRequestDto writeCommentRequestDto = WriteCommentRequestDto.builder() + .recordId(1L) + .parentId(1L) + .comment("test") + .build(); + MockMultipartFile multipartFile = mock(MockMultipartFile.class); + Record record = mock(Record.class); + Comment parentComment = mock(Comment.class); + Comment saveComment = mock(Comment.class); + + given(recordRepository.findById(writeCommentRequestDto.getRecordId())) + .willReturn(Optional.of(record)); + given(commentRepository.findById(writeCommentRequestDto.getParentId())) + .willReturn(Optional.of(parentComment)); + given(commentRepository.save(any())) + .willReturn(saveComment); + given(sessionUtil.findUserIdBySession()) + .willThrow(new NotFoundUserInfoInSessionException("")); + given(saveComment.getId()) + .willReturn(2L); + + // when + WriteCommentResponseDto result = commentService.writeComment( + writeCommentRequestDto, + multipartFile + ); + + // then + assertThat(result.getCommentId()).isEqualTo(2L); + } + } + +} From 9a20dbb98839e44bc3824382cc858001e7d8d0d5 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 9 Jan 2023 20:18:52 +0900 Subject: [PATCH 214/264] =?UTF-8?q?[BE-142]=20fix:=20SessionUtil=20findUse?= =?UTF-8?q?rIdBySession=20=EB=A9=94=EC=84=9C=EB=93=9C=EC=97=90=EC=84=9C=20?= =?UTF-8?q?id=EA=B0=92=20Long=EC=9C=BC=EB=A1=9C=20=ED=98=95=EB=B3=80?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 springSessionDefaultRedisSerializer를 Jackson2JsonRedisSerializer 로 변경하면서 형변환 문제가 생겼습니다. Long -> Integer로 변경 후 문제가 해결되었으나 다른 문제 발생으로 처음부터 Long으로 변환하였습니다. --- src/main/java/com/recordit/server/util/SessionUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/util/SessionUtil.java b/src/main/java/com/recordit/server/util/SessionUtil.java index 65672481..fc6fed0b 100644 --- a/src/main/java/com/recordit/server/util/SessionUtil.java +++ b/src/main/java/com/recordit/server/util/SessionUtil.java @@ -23,7 +23,7 @@ public void saveUserIdInSession(Long id) { } public Long findUserIdBySession() { - Integer userId = (Integer)httpSession.getAttribute(PREFIX_USER_ID); + Long userId = Long.valueOf(httpSession.getAttribute(PREFIX_USER_ID).toString()); if (userId == null) { log.info("세션에 사용자 정보가 저장되어 있지 않습니다"); invalidateSession(); From 569bbf549ecd8817001ed4de0dfc631a31ba309d Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 9 Jan 2023 20:41:14 +0900 Subject: [PATCH 215/264] =?UTF-8?q?[BE-141]=20feat:=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=ED=8C=8C=EC=9D=BC=20=ED=99=95=EC=9E=A5=EC=9E=90=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/constant/ImageFileExtension.java | 7 +++++++ .../server/exception/file/FileExceptionHandler.java | 8 ++++++++ .../exception/file/FileExtensionNotAllowedException.java | 7 +++++++ 3 files changed, 22 insertions(+) create mode 100644 src/main/java/com/recordit/server/constant/ImageFileExtension.java create mode 100644 src/main/java/com/recordit/server/exception/file/FileExtensionNotAllowedException.java diff --git a/src/main/java/com/recordit/server/constant/ImageFileExtension.java b/src/main/java/com/recordit/server/constant/ImageFileExtension.java new file mode 100644 index 00000000..00858972 --- /dev/null +++ b/src/main/java/com/recordit/server/constant/ImageFileExtension.java @@ -0,0 +1,7 @@ +package com.recordit.server.constant; + +public enum ImageFileExtension { + JPG, JPEG, jpg, jpeg, + PNG, png, + SVG, svg +} diff --git a/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java index fd7f0260..6e54c7bd 100644 --- a/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/file/FileExceptionHandler.java @@ -31,4 +31,12 @@ public ResponseEntity handleFileContentTypeNotAllowedException( return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY) .body(ErrorMessage.of(exception, HttpStatus.UNPROCESSABLE_ENTITY)); } + + @ExceptionHandler(FileExtensionNotAllowedException.class) + public ResponseEntity handleFileExtensionNotAllowedException( + FileExtensionNotAllowedException exception + ) { + return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY) + .body(ErrorMessage.of(exception, HttpStatus.UNPROCESSABLE_ENTITY)); + } } diff --git a/src/main/java/com/recordit/server/exception/file/FileExtensionNotAllowedException.java b/src/main/java/com/recordit/server/exception/file/FileExtensionNotAllowedException.java new file mode 100644 index 00000000..f2b12fb7 --- /dev/null +++ b/src/main/java/com/recordit/server/exception/file/FileExtensionNotAllowedException.java @@ -0,0 +1,7 @@ +package com.recordit.server.exception.file; + +public class FileExtensionNotAllowedException extends RuntimeException { + public FileExtensionNotAllowedException(String message) { + super(message); + } +} From 549f1e7a4da18a0ac96f1717f9e54a05592f6ef1 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 9 Jan 2023 20:42:10 +0900 Subject: [PATCH 216/264] =?UTF-8?q?[BE-141]=20feat:=20=EC=A1=B0=EA=B1=B4?= =?UTF-8?q?=EC=A0=88=EC=9D=84=20=EB=84=A3=EC=9D=80=20=EC=BF=BC=EB=A6=AC?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/repository/ImageFileRepository.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/recordit/server/repository/ImageFileRepository.java b/src/main/java/com/recordit/server/repository/ImageFileRepository.java index f9d5b08a..fc27da84 100644 --- a/src/main/java/com/recordit/server/repository/ImageFileRepository.java +++ b/src/main/java/com/recordit/server/repository/ImageFileRepository.java @@ -1,8 +1,16 @@ package com.recordit.server.repository; +import java.util.List; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; +import com.recordit.server.constant.RefType; import com.recordit.server.domain.ImageFile; public interface ImageFileRepository extends JpaRepository { + + Optional findByRefTypeAndRefId(RefType refType, Long refId); + + List findAllByRefTypeAndRefId(RefType refType, Long refId); } From ec81707621f46f6e18d754b32c5b6e129fb4cdd8 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 9 Jan 2023 20:48:15 +0900 Subject: [PATCH 217/264] =?UTF-8?q?[BE-141]=20feat:=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=ED=8C=8C=EC=9D=BC=20=EC=A0=80=EC=9E=A5=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20=ED=99=95=EC=9E=A5=EC=9E=90=20=EA=B2=80=EC=82=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?URL=EC=9D=84=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/ImageFileService.java | 49 ++++++++++++++++--- .../server/service/ImageFileServiceTest.java | 28 +++++++++-- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/recordit/server/service/ImageFileService.java b/src/main/java/com/recordit/server/service/ImageFileService.java index c8ba66bc..6e4ce1eb 100644 --- a/src/main/java/com/recordit/server/service/ImageFileService.java +++ b/src/main/java/com/recordit/server/service/ImageFileService.java @@ -1,6 +1,8 @@ package com.recordit.server.service; +import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import org.springframework.context.ApplicationEventPublisher; @@ -10,11 +12,12 @@ import org.springframework.transaction.event.TransactionalEventListener; import org.springframework.web.multipart.MultipartFile; +import com.recordit.server.constant.ImageFileExtension; import com.recordit.server.constant.RefType; import com.recordit.server.domain.ImageFile; import com.recordit.server.event.S3ImageRollbackEvent; -import com.recordit.server.exception.file.EmptyFileException; import com.recordit.server.exception.file.FileContentTypeNotAllowedException; +import com.recordit.server.exception.file.FileExtensionNotAllowedException; import com.recordit.server.repository.ImageFileRepository; import com.recordit.server.util.S3Uploader; @@ -37,8 +40,11 @@ public String saveAttachmentFile( @NonNull Long refId, @NonNull MultipartFile attachment ) { - validateEmptyFile(attachment); + if (attachment.isEmpty()) { + return null; + } validateImageContentType(attachment); + validateFileExtension(attachment); String saveFileName = s3Uploader.upload(attachment); log.info("S3에 저장한 파일 이름 : {}", saveFileName); @@ -67,6 +73,7 @@ public List saveAttachmentFiles( ) { return attachments.stream() .map(attachment -> saveAttachmentFile(refType, refId, attachment)) + .filter(saveUrl -> saveUrl != null) .collect(Collectors.toList()); } @@ -76,6 +83,28 @@ public void handleRollback(S3ImageRollbackEvent event) { s3Uploader.delete(event.getRollbackFileName()); } + @Transactional(readOnly = true) + public String getImageFile( + @NonNull RefType refType, + @NonNull Long refId + ) { + Optional findImageFile = imageFileRepository.findByRefTypeAndRefId(refType, refId); + if (findImageFile.isPresent()) { + return findImageFile.get().getDownloadUrl(); + } + return null; + } + + @Transactional(readOnly = true) + public List getImageFiles( + @NonNull RefType refType, + @NonNull Long refId + ) { + return imageFileRepository.findAllByRefTypeAndRefId(refType, refId).stream() + .map(ImageFile::getDownloadUrl) + .collect(Collectors.toList()); + } + @Transactional public void deleteAttachmentFiles(List attachmentFileNames) { for (String attachmentFileName : attachmentFileNames) { @@ -84,12 +113,6 @@ public void deleteAttachmentFiles(List attachmentFileNames) { } } - private void validateEmptyFile(MultipartFile multipartFile) { - if (multipartFile.isEmpty()) { - throw new EmptyFileException("요청한 파일이 비어있습니다."); - } - } - private void validateImageContentType(MultipartFile multipartFile) { if (!multipartFile.getContentType().startsWith("image")) { log.warn("요청 파일 ContentType : {}", multipartFile.getContentType()); @@ -97,4 +120,14 @@ private void validateImageContentType(MultipartFile multipartFile) { } } + private void validateFileExtension(MultipartFile multipartFile) { + String extension = multipartFile + .getOriginalFilename() + .substring(multipartFile.getOriginalFilename().lastIndexOf(".") + 1); + Arrays.stream(ImageFileExtension.values()) + .filter(imageFileExtension -> imageFileExtension.name().equals(extension)) + .findFirst() + .orElseThrow(() -> new FileExtensionNotAllowedException("지원하지 않은 파일 확장자입니다.")); + } + } diff --git a/src/test/java/com/recordit/server/service/ImageFileServiceTest.java b/src/test/java/com/recordit/server/service/ImageFileServiceTest.java index 21468fad..372387e3 100644 --- a/src/test/java/com/recordit/server/service/ImageFileServiceTest.java +++ b/src/test/java/com/recordit/server/service/ImageFileServiceTest.java @@ -17,8 +17,8 @@ import org.springframework.web.multipart.MultipartFile; import com.recordit.server.constant.RefType; -import com.recordit.server.exception.file.EmptyFileException; import com.recordit.server.exception.file.FileContentTypeNotAllowedException; +import com.recordit.server.exception.file.FileExtensionNotAllowedException; import com.recordit.server.repository.ImageFileRepository; import com.recordit.server.util.S3Uploader; @@ -47,15 +47,17 @@ class 첨부_파일을_저장할_때 { private final List mockMultipartFiles = List.of(mock); @Test - @DisplayName("빈 파일이 넘어오면 예외를 던진다") + @DisplayName("빈 파일이 넘어오면 null을 응답한다") void 빈_파일이_넘어오면_예외를_던진다() { // given given(mock.isEmpty()) .willReturn(true); - // when, then - assertThatThrownBy(() -> imageFileService.saveAttachmentFiles(refType, refId, mockMultipartFiles)) - .isInstanceOf(EmptyFileException.class); + // when + List result = imageFileService.saveAttachmentFiles(refType, refId, mockMultipartFiles); + + // then + assertThat(result.isEmpty()).isTrue(); } @Test @@ -72,6 +74,22 @@ class 첨부_파일을_저장할_때 { .isInstanceOf(FileContentTypeNotAllowedException.class); } + @Test + @DisplayName("규정한 이미지 파일 확장자가 아니면 예외를 던진다") + void 규정한_이미지_파일_확장자가_아니면_예외를_던진다() { + // given + given(mock.isEmpty()) + .willReturn(false); + given(mock.getContentType()) + .willReturn("image/jpg"); + given(mock.getOriginalFilename()) + .willReturn("test.xlsx"); + + // when, then + assertThatThrownBy(() -> imageFileService.saveAttachmentFiles(refType, refId, mockMultipartFiles)) + .isInstanceOf(FileExtensionNotAllowedException.class); + } + @Test @DisplayName("정상적으로 파일을 저장할 경우 Url을 응답한다") void 정상적으로_파일을_저장할_경우_URL을_응답한다() { From 40a54e00433fa6405d7dc5b39f56caabba1d8eeb Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 9 Jan 2023 20:57:03 +0900 Subject: [PATCH 218/264] [BE-141] resolve conflict --- .../java/com/recordit/server/service/RecordService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 9a1c85ac..b659ca8e 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -93,8 +93,12 @@ public RecordDetailResponseDto getDetailRecord(Long recordId) { List imageUrls = Collections.emptyList(); - Optional> optionalImageFileList = imageFileRepository.findByRefIdAndRefType(recordId, - RefType.RECORD); + Optional> optionalImageFileList = Optional.of( + imageFileRepository.findAllByRefTypeAndRefId( + RefType.RECORD, + recordId + ) + ); if (!optionalImageFileList.isEmpty()) { From 000ff30715147a5acb4620b0224a904bb77ee741 Mon Sep 17 00:00:00 2001 From: kdomo Date: Tue, 10 Jan 2023 18:32:13 +0900 Subject: [PATCH 219/264] =?UTF-8?q?[BE-143]=20fix:=20SessionUtil=20findUse?= =?UTF-8?q?rIdBySession=20=EB=A9=94=EC=84=9C=EB=93=9C=20NullPointException?= =?UTF-8?q?=20=EB=B2=84=EA=B7=B8=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/util/SessionUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/util/SessionUtil.java b/src/main/java/com/recordit/server/util/SessionUtil.java index fc6fed0b..a002ca8a 100644 --- a/src/main/java/com/recordit/server/util/SessionUtil.java +++ b/src/main/java/com/recordit/server/util/SessionUtil.java @@ -23,13 +23,13 @@ public void saveUserIdInSession(Long id) { } public Long findUserIdBySession() { - Long userId = Long.valueOf(httpSession.getAttribute(PREFIX_USER_ID).toString()); + Object userId = httpSession.getAttribute(PREFIX_USER_ID); if (userId == null) { log.info("세션에 사용자 정보가 저장되어 있지 않습니다"); invalidateSession(); throw new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다"); } - return userId.longValue(); + return Long.valueOf(userId.toString()); } public void isCorrectSession() { From cb17326592846e057ac3702516faddf949f2ca5d Mon Sep 17 00:00:00 2001 From: kdomo Date: Tue, 10 Jan 2023 18:43:08 +0900 Subject: [PATCH 220/264] =?UTF-8?q?[BE-144]=20fix:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1=20Happy=20case=20test=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/service/RecordServiceTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/com/recordit/server/service/RecordServiceTest.java b/src/test/java/com/recordit/server/service/RecordServiceTest.java index 90df410c..14886fe4 100644 --- a/src/test/java/com/recordit/server/service/RecordServiceTest.java +++ b/src/test/java/com/recordit/server/service/RecordServiceTest.java @@ -44,6 +44,9 @@ class RecordServiceTest { @Mock private ImageFileRepository imageFileRepository; + @Mock + private ImageFileService imageFileService; + @Mock private SessionUtil sessionUtil; From b48a023c67660478374eebef69e254be025d1100 Mon Sep 17 00:00:00 2001 From: kdomo Date: Tue, 10 Jan 2023 18:55:19 +0900 Subject: [PATCH 221/264] =?UTF-8?q?[BE-139]=20feat:=20=EC=83=81=EC=9A=A9?= =?UTF-8?q?=20=ED=99=98=EA=B2=BD=20=EA=B5=AC=EC=84=B1=EC=9D=84=20=EC=9C=84?= =?UTF-8?q?=ED=95=9C=20yml=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-prod.yml | 16 +++++++++ src/main/resources/application.yml | 2 +- src/main/resources/log4j2-prod.xml | 45 +++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/application-prod.yml create mode 100644 src/main/resources/log4j2-prod.xml diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 00000000..7f905414 --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,16 @@ +spring: + config: + activate: + on-profile: "prod" + mvc: + pathmatch: + matching-strategy: ant_path_matcher + jpa: + hibernate: + ddl-auto: none + naming: + physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl +logging: + config: classpath:log4j2-prod.xml +cors: + origin: ${CORS_ORIGIN_NAME:} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 71f68046..9ea40c73 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,4 +4,4 @@ spring: "test": "test" "local": "local, datasource, redis, oauth, s3" "dev": "dev, datasource, redis, oauth, s3" - "prod": "prod" + "prod": "prod, datasource, redis, oauth, s3" diff --git a/src/main/resources/log4j2-prod.xml b/src/main/resources/log4j2-prod.xml new file mode 100644 index 00000000..f648de7c --- /dev/null +++ b/src/main/resources/log4j2-prod.xml @@ -0,0 +1,45 @@ + + + + ./logs + recordIt + + + + + + + + + ${LOGS_PATH}/${LOGS_NAME}.log + ${LOGS_PATH}/${LOGS_NAME}.%d{yyyy-MM-dd}.%i.log + + %d{yyyy-MM-dd HH:mm:ss} %5p [%equals{%X{trace_id}}{}{system}] [%c] %m%n + + + + + + + + ${LOGS_PATH}/ERROR/${LOGS_NAME}_ERROR.log + ${LOGS_PATH}/ERROR/${LOGS_NAME}_ERROR.%d{yyyy-MM-dd}.%i.log + + %d{yyyy-MM-dd HH:mm:ss} %5p [%equals{%X{trace_id}}{}{system}] [%c] %m%n + + + + + + + + + + + + + + + + \ No newline at end of file From 867b7f133842f2daf29d31229be5c5069a8d666f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 11 Jan 2023 00:47:22 +0900 Subject: [PATCH 222/264] =?UTF-8?q?[BE-128]=20refactor:=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=EC=99=80=20doesNotException=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/CommentServiceTest.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/recordit/server/service/CommentServiceTest.java b/src/test/java/com/recordit/server/service/CommentServiceTest.java index 482ecfb2..3d8e994f 100644 --- a/src/test/java/com/recordit/server/service/CommentServiceTest.java +++ b/src/test/java/com/recordit/server/service/CommentServiceTest.java @@ -109,10 +109,10 @@ class 댓글을_작성_할_때 { given(multipartFile.isEmpty()) .willReturn(false); + given(sessionUtil.findUserIdBySession()) + .willThrow(new NotFoundUserInfoInSessionException("세션에 저장된 사용자가 DB에 존재하지 않습니다.")); given(recordRepository.findById(writeCommentRequestDto.getRecordId())) .willReturn(Optional.empty()); - given(sessionUtil.findUserIdBySession()) - .willThrow(new NotFoundUserInfoInSessionException("")); // when, then assertThatThrownBy(() -> commentService.writeComment(writeCommentRequestDto, multipartFile)) @@ -133,12 +133,12 @@ class 댓글을_작성_할_때 { given(multipartFile.isEmpty()) .willReturn(false); + given(sessionUtil.findUserIdBySession()) + .willThrow(new NotFoundUserInfoInSessionException("세션에 저장된 사용자가 DB에 존재하지 않습니다.")); given(recordRepository.findById(writeCommentRequestDto.getRecordId())) .willReturn(Optional.of(record)); given(commentRepository.findById(writeCommentRequestDto.getParentId())) .willReturn(Optional.empty()); - given(sessionUtil.findUserIdBySession()) - .willThrow(new NotFoundUserInfoInSessionException("")); // when, then assertThatThrownBy(() -> commentService.writeComment(writeCommentRequestDto, multipartFile)) @@ -159,14 +159,14 @@ class 댓글을_작성_할_때 { Comment parentComment = mock(Comment.class); Comment saveComment = mock(Comment.class); + given(sessionUtil.findUserIdBySession()) + .willThrow(new NotFoundUserInfoInSessionException("세션에 저장된 사용자가 DB에 존재하지 않습니다.")); given(recordRepository.findById(writeCommentRequestDto.getRecordId())) .willReturn(Optional.of(record)); given(commentRepository.findById(writeCommentRequestDto.getParentId())) .willReturn(Optional.of(parentComment)); given(commentRepository.save(any())) .willReturn(saveComment); - given(sessionUtil.findUserIdBySession()) - .willThrow(new NotFoundUserInfoInSessionException("")); given(saveComment.getId()) .willReturn(2L); @@ -178,6 +178,10 @@ class 댓글을_작성_할_때 { // then assertThat(result.getCommentId()).isEqualTo(2L); + assertThatCode(() -> commentService.writeComment( + writeCommentRequestDto, + multipartFile + )).doesNotThrowAnyException(); } } From c0a6d4efdcf08c58313666062d733e81353f60ce Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 11 Jan 2023 00:48:30 +0900 Subject: [PATCH 223/264] =?UTF-8?q?[BE-128]=20refactor:=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EB=82=B4=EC=9A=A9=20=EC=B5=9C=EB=8C=80=20100=20?= =?UTF-8?q?=EA=B8=80=EC=9E=90=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/dto/comment/WriteCommentRequestDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java index b7b86d87..689716dd 100644 --- a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java +++ b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java @@ -29,7 +29,7 @@ public class WriteCommentRequestDto { private Long parentId; @ApiModelProperty(notes = "댓글 내용", required = true) - @Size(max = 100, message = "댓글 내용은 200자를 넘길 수 없습니다") + @Size(max = 200, message = "댓글 내용은 100자를 넘길 수 없습니다") private String comment; @Builder From 9f7cafd2899134434b82a9c01676154fe3351211 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 11 Jan 2023 00:56:24 +0900 Subject: [PATCH 224/264] =?UTF-8?q?[BE-128]=20refactor:=20=EC=84=B8?= =?UTF-8?q?=EC=85=98=EC=9D=84=20=ED=86=B5=ED=95=B4=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EB=A5=BC=20=EC=B0=BE=EB=8A=94=20=EB=B6=80=EB=B6=84?= =?UTF-8?q?=EC=9D=84=20=EB=A9=94=EC=86=8C=EB=93=9C=EB=A1=9C=20extract?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/service/CommentService.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/recordit/server/service/CommentService.java b/src/main/java/com/recordit/server/service/CommentService.java index 5344c0e3..4cb646ca 100644 --- a/src/main/java/com/recordit/server/service/CommentService.java +++ b/src/main/java/com/recordit/server/service/CommentService.java @@ -42,12 +42,7 @@ public WriteCommentResponseDto writeComment( ) { validateEmptyContent(writeCommentRequestDto, attachment); - Member writer = null; - try { - writer = memberRepository.findById(sessionUtil.findUserIdBySession()) - .orElseThrow(() -> new MemberNotFoundException("세션에 저장된 사용자가 DB에 존재하지 않습니다.")); - } catch (NotFoundUserInfoInSessionException e) { - } + Member writer = findWriterIfPresent(); Record record = recordRepository.findById(writeCommentRequestDto.getRecordId()) .orElseThrow(() -> new RecordNotFoundException("댓글을 작성할 레코드가 존재하지 않습니다.")); @@ -82,4 +77,14 @@ private void validateEmptyContent( throw new EmptyContentException("댓글 내용과 이미지 파일 모두 비어있을 수 없습니다."); } } + + private Member findWriterIfPresent() { + try { + Long userIdInSession = sessionUtil.findUserIdBySession(); + return memberRepository.findById(userIdInSession) + .orElseThrow(() -> new MemberNotFoundException("세션에 저장된 사용자가 DB에 존재하지 않습니다.")); + } catch (NotFoundUserInfoInSessionException e) { + return null; + } + } } From 69c00792cf6a74e957d2ab1e1e58b0e1961789e5 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 11 Jan 2023 01:00:25 +0900 Subject: [PATCH 225/264] =?UTF-8?q?[BE-128]=20refactor:=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20100=EC=9E=90=20=EC=A0=95=EC=B1=85=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/dto/comment/WriteCommentRequestDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java index 689716dd..4cbb0df3 100644 --- a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java +++ b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java @@ -29,7 +29,7 @@ public class WriteCommentRequestDto { private Long parentId; @ApiModelProperty(notes = "댓글 내용", required = true) - @Size(max = 200, message = "댓글 내용은 100자를 넘길 수 없습니다") + @Size(max = 100, message = "댓글 내용은 100자를 넘길 수 없습니다") private String comment; @Builder From 41810ea7771b4eb7030023976a2dab397325330e Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Wed, 11 Jan 2023 01:02:40 +0900 Subject: [PATCH 226/264] =?UTF-8?q?[BE-128]=20test:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=EC=97=90=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EC=B0=BE=EB=8A=94=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/service/CommentServiceTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/recordit/server/service/CommentServiceTest.java b/src/test/java/com/recordit/server/service/CommentServiceTest.java index 3d8e994f..7dfb25dc 100644 --- a/src/test/java/com/recordit/server/service/CommentServiceTest.java +++ b/src/test/java/com/recordit/server/service/CommentServiceTest.java @@ -110,7 +110,7 @@ class 댓글을_작성_할_때 { given(multipartFile.isEmpty()) .willReturn(false); given(sessionUtil.findUserIdBySession()) - .willThrow(new NotFoundUserInfoInSessionException("세션에 저장된 사용자가 DB에 존재하지 않습니다.")); + .willThrow(new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다")); given(recordRepository.findById(writeCommentRequestDto.getRecordId())) .willReturn(Optional.empty()); @@ -134,7 +134,7 @@ class 댓글을_작성_할_때 { given(multipartFile.isEmpty()) .willReturn(false); given(sessionUtil.findUserIdBySession()) - .willThrow(new NotFoundUserInfoInSessionException("세션에 저장된 사용자가 DB에 존재하지 않습니다.")); + .willThrow(new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다")); given(recordRepository.findById(writeCommentRequestDto.getRecordId())) .willReturn(Optional.of(record)); given(commentRepository.findById(writeCommentRequestDto.getParentId())) @@ -160,7 +160,7 @@ class 댓글을_작성_할_때 { Comment saveComment = mock(Comment.class); given(sessionUtil.findUserIdBySession()) - .willThrow(new NotFoundUserInfoInSessionException("세션에 저장된 사용자가 DB에 존재하지 않습니다.")); + .willThrow(new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다")); given(recordRepository.findById(writeCommentRequestDto.getRecordId())) .willReturn(Optional.of(record)); given(commentRepository.findById(writeCommentRequestDto.getParentId())) From 9b8b978358cf717776f4e727c389b0e2c9eecc01 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 11 Jan 2023 23:01:47 +0900 Subject: [PATCH 227/264] =?UTF-8?q?[BE-113]=20chore:=20build=EC=8B=9C=20pl?= =?UTF-8?q?ain=20jar=20=EC=83=9D=EA=B8=B0=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index cc84b73d..243d1272 100644 --- a/build.gradle +++ b/build.gradle @@ -60,3 +60,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +jar { + enabled = false +} \ No newline at end of file From a96d9fd816b386f6a5a748b3723b5fc0a83c8697 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 11 Jan 2023 23:02:23 +0900 Subject: [PATCH 228/264] =?UTF-8?q?[BE-113]=20chore:=20pem=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20gitignore=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6f3ad35c..5d47a5fe 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ out/ .vscode/ ### Custom ### -logs/ \ No newline at end of file +logs/ +*.pem \ No newline at end of file From b2fadb19950df77c3df30e1282906b63456cfb60 Mon Sep 17 00:00:00 2001 From: kdomo Date: Wed, 11 Jan 2023 23:03:00 +0900 Subject: [PATCH 229/264] =?UTF-8?q?[BE-113]=20chore:=20dockerfile=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dockerfile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 dockerfile diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000..6428fde0 --- /dev/null +++ b/dockerfile @@ -0,0 +1,4 @@ +FROM adoptopenjdk/openjdk11 +ARG JAR_FILE=target/*.jar +COPY ${JAR_FILE} app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file From 51cd4828c72501b285e96902dcf0e147d3208afa Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 12 Jan 2023 00:00:48 +0900 Subject: [PATCH 230/264] =?UTF-8?q?[BE-154]=20fix:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=ED=8C=90=EB=B3=84=20API=20endpoint=EB=AA=85?= =?UTF-8?q?=EC=9D=84=20/auth=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98?= =?UTF-8?q?=EA=B3=A0=20=ED=9A=8C=EC=9B=90=EC=9D=98=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/controller/MemberController.java | 8 +++----- .../server/exception/member/MemberExceptionHandler.java | 8 -------- .../exception/member/SessionAuthenticationException.java | 7 ------- .../java/com/recordit/server/service/MemberService.java | 8 ++++++++ src/main/java/com/recordit/server/util/SessionUtil.java | 9 --------- 5 files changed, 11 insertions(+), 29 deletions(-) delete mode 100644 src/main/java/com/recordit/server/exception/member/SessionAuthenticationException.java diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index c48c163a..84d34d0f 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -119,11 +119,9 @@ public ResponseEntity duplicateNicknameCheck(@RequestParam String nickname) { return ResponseEntity.status(HttpStatus.OK).body(false); } - @GetMapping("/login") - public ResponseEntity checkLogin() { - sessionUtil.isCorrectSession(); - log.info("정상적으로 로그인 되어있습니다."); - return ResponseEntity.ok().build(); + @GetMapping("/auth") + public ResponseEntity findNicknameIfPresent() { + return ResponseEntity.status(HttpStatus.OK).body(memberService.findNicknameIfPresent()); } } diff --git a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java index ac674413..41fc30c5 100644 --- a/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/member/MemberExceptionHandler.java @@ -50,13 +50,5 @@ public ResponseEntity handleRestClientException( return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(ErrorMessage.of(exception, HttpStatus.INTERNAL_SERVER_ERROR)); } - - @ExceptionHandler(SessionAuthenticationException.class) - public ResponseEntity handleSessionAuthenticationException( - SessionAuthenticationException exception) { - return ResponseEntity.status(HttpStatus.FORBIDDEN) - .body(ErrorMessage.of(exception, HttpStatus.FORBIDDEN)); - } - } diff --git a/src/main/java/com/recordit/server/exception/member/SessionAuthenticationException.java b/src/main/java/com/recordit/server/exception/member/SessionAuthenticationException.java deleted file mode 100644 index 514a05f9..00000000 --- a/src/main/java/com/recordit/server/exception/member/SessionAuthenticationException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.recordit.server.exception.member; - -public class SessionAuthenticationException extends RuntimeException { - public SessionAuthenticationException(String message) { - super(message); - } -} diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index 4a831599..67e4aa30 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -15,6 +15,7 @@ import com.recordit.server.dto.member.RegisterRequestDto; import com.recordit.server.dto.member.RegisterSessionResponseDto; import com.recordit.server.exception.member.DuplicateNicknameException; +import com.recordit.server.exception.member.MemberNotFoundException; import com.recordit.server.exception.member.NotFoundRegisterSessionException; import com.recordit.server.repository.MemberRepository; import com.recordit.server.service.oauth.OauthService; @@ -89,4 +90,11 @@ public void isDuplicateNickname(String nickname) { throw new DuplicateNicknameException("중복된 닉네임이 존재합니다."); } } + + public String findNicknameIfPresent() { + Long userIdBySession = sessionUtil.findUserIdBySession(); + Member member = memberRepository.findById(userIdBySession) + .orElseThrow(() -> new MemberNotFoundException("회원 정보를 찾을 수 없습니다.")); + return member.getNickname(); + } } diff --git a/src/main/java/com/recordit/server/util/SessionUtil.java b/src/main/java/com/recordit/server/util/SessionUtil.java index a002ca8a..15f3e103 100644 --- a/src/main/java/com/recordit/server/util/SessionUtil.java +++ b/src/main/java/com/recordit/server/util/SessionUtil.java @@ -5,7 +5,6 @@ import org.springframework.stereotype.Component; import com.recordit.server.exception.member.NotFoundUserInfoInSessionException; -import com.recordit.server.exception.member.SessionAuthenticationException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -32,14 +31,6 @@ public Long findUserIdBySession() { return Long.valueOf(userId.toString()); } - public void isCorrectSession() { - if (httpSession.getAttribute(PREFIX_USER_ID) == null) { - log.info("로그인이 되어있지 않아 접근이 거부되었습니다."); - invalidateSession(); - throw new SessionAuthenticationException("로그인이 되어있지 않아 접근이 거부되었습니다."); - } - } - public void invalidateSession() { httpSession.invalidate(); } From 890122147fcdfbe569164c27b4133c0d4d9c056b Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 12 Jan 2023 00:19:59 +0900 Subject: [PATCH 231/264] =?UTF-8?q?[BE-154]=20test:=20findNicknameIfPresen?= =?UTF-8?q?t=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/MemberServiceTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/test/java/com/recordit/server/service/MemberServiceTest.java b/src/test/java/com/recordit/server/service/MemberServiceTest.java index f9dfc961..8ae98804 100644 --- a/src/test/java/com/recordit/server/service/MemberServiceTest.java +++ b/src/test/java/com/recordit/server/service/MemberServiceTest.java @@ -24,7 +24,9 @@ import com.recordit.server.dto.member.RegisterRequestDto; import com.recordit.server.dto.member.RegisterSessionResponseDto; import com.recordit.server.exception.member.DuplicateNicknameException; +import com.recordit.server.exception.member.MemberNotFoundException; import com.recordit.server.exception.member.NotFoundRegisterSessionException; +import com.recordit.server.exception.member.NotFoundUserInfoInSessionException; import com.recordit.server.repository.MemberRepository; import com.recordit.server.service.oauth.OauthService; import com.recordit.server.service.oauth.OauthServiceLocator; @@ -214,4 +216,51 @@ class 닉네임_중복_확인_기능에서_닉네임이 { .doesNotThrowAnyException(); } } + + @Nested + @DisplayName("로그인 된 사용자의 닉네임을 응답하는 기능에서") + class 로그인_된_사용자의_닉네임을_응답하는_기능에서 { + + @Test + @DisplayName("로그인이 되어있지 않다면 예외를 던진다") + void 로그인이_되어있지_않으면_예외를_던진다() { + // given + given(sessionUtil.findUserIdBySession()) + .willReturn(null); + + // when, then + assertThatThrownBy(() -> memberService.findNicknameIfPresent()) + .isInstanceOf(NotFoundUserInfoInSessionException.class); + } + + @Test + @DisplayName("세션에 회원의 아이디는 존재하지만 테이블에 없다면 예외를 던진다") + void 세션에_회원의_아이디는_존재하지만_테이블에_없다면_예외를_던진다() { + // given + given(sessionUtil.findUserIdBySession()) + .willReturn(1L); + given(memberRepository.findById(any())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> memberService.findNicknameIfPresent()) + .isInstanceOf(MemberNotFoundException.class); + } + + @Test + @DisplayName("정상적으로 로그인되어있고 테이블에도 정보가 있는 경우엔 예외를 던지지 않는다") + void 정상적으로_로그인되어있고_테이블에도_정보가_있는_경우엔_예외를_던지지_않는다() { + //given + given(sessionUtil.findUserIdBySession()) + .willReturn(1L); + given(memberRepository.findById(any())) + .willReturn(Optional.of(mockMember)); + given(mockMember.getNickname()) + .willReturn(nickname); + + // when, then + assertThatCode(() -> memberService.findNicknameIfPresent()) + .doesNotThrowAnyException(); + } + } } From 3055e9d09d0d1fe925e4c67d54dc8c4e358e7101 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 12 Jan 2023 00:36:11 +0900 Subject: [PATCH 232/264] =?UTF-8?q?[BE-151]=20chore,=20fix:=20log=20xml?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20log4j2=20=ED=8F=B4=EB=8D=94=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 2 +- src/main/resources/application-local.yml | 2 +- src/main/resources/application-prod.yml | 2 +- src/main/resources/{ => log4j2}/log4j2-dev.xml | 0 src/main/resources/{ => log4j2}/log4j2-local.xml | 0 src/main/resources/{ => log4j2}/log4j2-prod.xml | 0 6 files changed, 3 insertions(+), 3 deletions(-) rename src/main/resources/{ => log4j2}/log4j2-dev.xml (100%) rename src/main/resources/{ => log4j2}/log4j2-local.xml (100%) rename src/main/resources/{ => log4j2}/log4j2-prod.xml (100%) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index db0fc027..555f126c 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -29,6 +29,6 @@ springfox: swagger-ui: base-url: /api logging: - config: classpath:log4j2-dev.xml + config: classpath:log4j2/log4j2-dev.xml cors: origin: ${CORS_ORIGIN_NAME:} \ No newline at end of file diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index e31a5b3a..dfc8f26d 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -29,6 +29,6 @@ springfox: swagger-ui: base-url: /api logging: - config: classpath:log4j2-local.xml + config: classpath:log4j2/log4j2-local.xml cors: origin: ${CORS_ORIGIN_NAME:} \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 7f905414..d9f7f0c2 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -11,6 +11,6 @@ spring: naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl logging: - config: classpath:log4j2-prod.xml + config: classpath:log4j2/log4j2-prod.xml cors: origin: ${CORS_ORIGIN_NAME:} \ No newline at end of file diff --git a/src/main/resources/log4j2-dev.xml b/src/main/resources/log4j2/log4j2-dev.xml similarity index 100% rename from src/main/resources/log4j2-dev.xml rename to src/main/resources/log4j2/log4j2-dev.xml diff --git a/src/main/resources/log4j2-local.xml b/src/main/resources/log4j2/log4j2-local.xml similarity index 100% rename from src/main/resources/log4j2-local.xml rename to src/main/resources/log4j2/log4j2-local.xml diff --git a/src/main/resources/log4j2-prod.xml b/src/main/resources/log4j2/log4j2-prod.xml similarity index 100% rename from src/main/resources/log4j2-prod.xml rename to src/main/resources/log4j2/log4j2-prod.xml From a6951dc2a36f02b5d470fc51bbd3bf79db870938 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 12 Jan 2023 14:08:47 +0900 Subject: [PATCH 233/264] =?UTF-8?q?[BE-130]=20feat:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B4=80=EB=A0=A8=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/CommentController.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/CommentController.java b/src/main/java/com/recordit/server/controller/CommentController.java index b0de84bd..77cfc6a2 100644 --- a/src/main/java/com/recordit/server/controller/CommentController.java +++ b/src/main/java/com/recordit/server/controller/CommentController.java @@ -54,16 +54,24 @@ public ResponseEntity writeComment( @ApiOperation( value = "레코드의 댓글을 조회", - notes = "레코드의 댓글을 조회합니다" + notes = "레코드의 댓글을 조회합니다\t\n\t\n" + + "레코드 ID는 필수 지정해야 합니다.\t\n" + + "부모 댓글 ID의 경우 지정하지 않으면 레코드의 Depth가 0인 댓글들을 조회하고, " + + "ID를 지정하면 해당 부모의 대댓글인 Depth가 1인 댓글들을 조회합니다.\t\n\t\n" + + "댓글 조회의 정렬 기준은 댓글 생성 시간으로 오름차순입니다." ) @ApiResponses({ @ApiResponse( - code = 200, message = "API 정상 작동 / 댓글 조회 완료", - response = CommentResponseDto.class + code = 200, + message = "API 정상 작동 / 댓글 조회 완료", response = CommentResponseDto.class + ), + @ApiResponse( + code = 400, message = "잘못된 요청", + response = ErrorMessage.class ) }) @GetMapping - public ResponseEntity getComment(@Valid @RequestBody CommentRequestDto commentRequestDto) { - return null; + public ResponseEntity getComment(@Valid @RequestBody CommentRequestDto commentRequestDto) { + return ResponseEntity.ok(commentService.getCommentsBy(commentRequestDto)); } } From ca7a3f1ddce5164ff75e47d7d1059d19223171c9 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 12 Jan 2023 14:09:15 +0900 Subject: [PATCH 234/264] =?UTF-8?q?[BE-130]=20feat:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B4=80=EB=A0=A8=20DTO=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/dto/comment/CommentDto.java | 28 ++++++++++++++++++ .../server/dto/comment/CommentRequestDto.java | 9 ++++-- .../dto/comment/CommentResponseDto.java | 29 ++++++++++++++----- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/recordit/server/dto/comment/CommentDto.java b/src/main/java/com/recordit/server/dto/comment/CommentDto.java index 24fb593a..1f3d1193 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentDto.java @@ -1,10 +1,15 @@ package com.recordit.server.dto.comment; +import java.time.LocalDateTime; + import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.recordit.server.domain.Comment; import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; @@ -15,9 +20,32 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class CommentDto { + + @ApiModelProperty(notes = "댓글 ID", required = true) private Long commentId; + @ApiModelProperty(notes = "댓글 작성자", required = true) + private String writer; + + @ApiModelProperty(notes = "댓글 내용", required = true) private String content; + @ApiModelProperty(notes = "첨부 이미지 URL", required = true) private String imageUrl; + + @ApiModelProperty(notes = "생성 일자") + private LocalDateTime createdAt; + + @ApiModelProperty(notes = "수정 일자") + private LocalDateTime modifiedAt; + + @Builder + public CommentDto(Comment comment, String imageUrl) { + this.commentId = comment.getId(); + this.writer = comment.getWriter().getNickname(); + this.content = comment.getContent(); + this.imageUrl = imageUrl; + this.createdAt = comment.getCreatedAt(); + this.modifiedAt = comment.getModifiedAt(); + } } diff --git a/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java index 42a9a709..1d28ce2a 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java @@ -18,16 +18,19 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class CommentRequestDto { - @ApiModelProperty(notes = "레코드의 id", required = true) + + @ApiModelProperty(notes = "레코드 ID", required = true) @NotNull private Long recordId; - @ApiModelProperty(notes = "자식 댓글을 조회하는 경우 부모 댓글의 id") + @ApiModelProperty(notes = "자식 댓글을 조회하는 경우 부모 댓글의 ID") private Long parentId; - @ApiModelProperty(notes = "댓글 리스트의 현재 페이지", required = true) + @ApiModelProperty(notes = "댓글 리스트의 요청 페이지 !주의: 0부터 시작", required = true) + @NotNull private int page; @ApiModelProperty(notes = "댓글 리스트의 사이즈", required = true) + @NotNull private int size; } diff --git a/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java b/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java index 21149955..3b1d7328 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java @@ -1,15 +1,18 @@ package com.recordit.server.dto.comment; +import java.util.ArrayList; import java.util.List; -import javax.validation.constraints.NotNull; +import org.springframework.data.domain.Page; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.recordit.server.domain.Comment; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; @@ -20,16 +23,28 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class CommentResponseDto { - @ApiModelProperty(notes = "레코드의 id", required = true) - @NotNull - private Long recordId; - @ApiModelProperty(notes = "자식 댓글의 리스트일 경우 부모 댓글이 들어감") - private Long parentId; + @ApiModelProperty(notes = "요청 댓글의 전체 페이지 개수", required = true) + private Integer totalPage; - @ApiModelProperty(notes = "레코드 댓글의 전체 개수", required = true) + @ApiModelProperty(notes = "요청 댓글의 전체 개수", required = true) private Long totalCount; @ApiModelProperty(notes = "댓글 리스트", required = true) private List commentList; + + @Builder + public CommentResponseDto(Page comments, List imageFileUrls) { + this.totalPage = comments.getTotalPages(); + this.totalCount = comments.getTotalElements(); + this.commentList = new ArrayList<>(); + for (int i = 0; i < comments.getContent().size(); i++) { + commentList.add( + CommentDto.builder() + .comment(comments.getContent().get(i)) + .imageUrl(imageFileUrls.get(i)) + .build() + ); + } + } } From ae6996bfe55d69d7351d935190994cf71e947925 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 12 Jan 2023 14:09:48 +0900 Subject: [PATCH 235/264] =?UTF-8?q?[BE-130]=20feat:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=EC=97=90=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=95=EC=9D=84=20=EC=A0=81=EC=9A=A9=20=EC=8B=9C=ED=82=A8=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/repository/CommentRepository.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/recordit/server/repository/CommentRepository.java b/src/main/java/com/recordit/server/repository/CommentRepository.java index 8f314d72..10209b9b 100644 --- a/src/main/java/com/recordit/server/repository/CommentRepository.java +++ b/src/main/java/com/recordit/server/repository/CommentRepository.java @@ -1,8 +1,22 @@ package com.recordit.server.repository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import com.recordit.server.domain.Comment; +import com.recordit.server.domain.Record; public interface CommentRepository extends JpaRepository { + + @EntityGraph(attributePaths = {"writer"}) + @Query("select c from COMMENT c left join c.writer where c.record = :record") + Page findAllByRecordWithPagination(@Param("record") Record record, Pageable pageable); + + @EntityGraph(attributePaths = "writer") + @Query("select c from COMMENT c left join c.writer where c.parentComment = :parentComment") + Page findAllByParentComment(@Param("parentComment") Comment parentComment, Pageable pageable); } From 1cbf83b6caf8e032d1923826e112ea5bdf3c3c0d Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 12 Jan 2023 14:18:00 +0900 Subject: [PATCH 236/264] =?UTF-8?q?[BE-130]=20feat:=20Depth=EA=B0=80=201?= =?UTF-8?q?=EC=9D=B4=20=EC=95=84=EB=8B=8C=20=EB=B6=80=EB=AA=A8=EA=B0=80=20?= =?UTF-8?q?=EB=B6=80=EB=AA=A8=EB=A5=BC=20=EA=B0=80=EC=A7=80=EB=8A=94=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20StatusCode=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=EC=BD=94=EB=93=9C=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/exception/comment/CommentExceptionHandler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java b/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java index b4d15574..7325073d 100644 --- a/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/comment/CommentExceptionHandler.java @@ -36,7 +36,13 @@ public ResponseEntity handleCommentNotFoundException(CommentNotFou @ExceptionHandler(MemberNotFoundException.class) public ResponseEntity handleMemberNotFoundException(MemberNotFoundException exception) { - return ResponseEntity.badRequest() + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(ErrorMessage.of(exception, HttpStatus.INTERNAL_SERVER_ERROR)); } + + @ExceptionHandler(IllegalStateException.class) + public ResponseEntity handleIllegalStateException(IllegalStateException exception) { + return ResponseEntity.badRequest() + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); + } } From f3046ada893083c03f543fb00a0642b53a1f9023 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 12 Jan 2023 14:18:27 +0900 Subject: [PATCH 237/264] =?UTF-8?q?[BE-130]=20feat:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/CommentService.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/java/com/recordit/server/service/CommentService.java b/src/main/java/com/recordit/server/service/CommentService.java index 4cb646ca..f611bf77 100644 --- a/src/main/java/com/recordit/server/service/CommentService.java +++ b/src/main/java/com/recordit/server/service/CommentService.java @@ -1,5 +1,11 @@ package com.recordit.server.service; +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; @@ -9,6 +15,8 @@ import com.recordit.server.domain.Comment; import com.recordit.server.domain.Member; import com.recordit.server.domain.Record; +import com.recordit.server.dto.comment.CommentRequestDto; +import com.recordit.server.dto.comment.CommentResponseDto; import com.recordit.server.dto.comment.WriteCommentRequestDto; import com.recordit.server.dto.comment.WriteCommentResponseDto; import com.recordit.server.exception.comment.CommentNotFoundException; @@ -50,6 +58,7 @@ public WriteCommentResponseDto writeComment( Comment parentComment = (writeCommentRequestDto.getParentId() == null) ? null : commentRepository.findById(writeCommentRequestDto.getParentId()) .orElseThrow(() -> new CommentNotFoundException("지정한 부모 댓글이 존재하지 않습니다.")); + validateParentHasParent(parentComment); Comment saveComment = commentRepository.save( Comment.of( @@ -69,6 +78,39 @@ public WriteCommentResponseDto writeComment( .build(); } + @Transactional(readOnly = true) + public CommentResponseDto getCommentsBy(CommentRequestDto commentRequestDto) { + Page findComments; + PageRequest pageRequest = PageRequest.of( + commentRequestDto.getPage(), + commentRequestDto.getSize(), + Sort.Direction.ASC, + "createdAt" + ); + + if (commentRequestDto.getParentId() == null) { + Record findRecord = recordRepository.findById(commentRequestDto.getRecordId()) + .orElseThrow(() -> new RecordNotFoundException("레코드 정보를 찾을 수 없습니다.")); + + findComments = commentRepository.findAllByRecordWithPagination(findRecord, pageRequest); + } else { + Comment parentComment = commentRepository.findById(commentRequestDto.getParentId()) + .orElseThrow(() -> new CommentNotFoundException("지정한 부모 댓글이 존재하지 않습니다.")); + validateParentHasParent(parentComment); + + findComments = commentRepository.findAllByParentComment(parentComment, pageRequest); + } + + List imageFileUrls = findComments.stream() + .map(comment -> imageFileService.getImageFile(RefType.COMMENT, comment.getId())) + .collect(Collectors.toList()); + + return CommentResponseDto.builder() + .comments(findComments) + .imageFileUrls(imageFileUrls) + .build(); + } + private void validateEmptyContent( WriteCommentRequestDto writeCommentRequestDto, MultipartFile attachment @@ -78,6 +120,12 @@ private void validateEmptyContent( } } + private void validateParentHasParent(Comment parentComment) { + if (parentComment.getParentComment() != null) { + throw new IllegalStateException("자식 댓글을 기준으로 조회 불가능합니다."); + } + } + private Member findWriterIfPresent() { try { Long userIdInSession = sessionUtil.findUserIdBySession(); From fc740c871dfa4baab86f2587eaa28470dd8d5612 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 12 Jan 2023 15:13:18 +0900 Subject: [PATCH 238/264] =?UTF-8?q?[BE-154]=20fix:=20Transactional=20readO?= =?UTF-8?q?nly=20true=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/service/MemberService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index 67e4aa30..e9e3a49c 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -91,6 +91,7 @@ public void isDuplicateNickname(String nickname) { } } + @Transactional(readOnly = true) public String findNicknameIfPresent() { Long userIdBySession = sessionUtil.findUserIdBySession(); Member member = memberRepository.findById(userIdBySession) From 87a407ee671529c4a53f08066802cad4bef38403 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 12 Jan 2023 15:15:31 +0900 Subject: [PATCH 239/264] =?UTF-8?q?[BE-156]=20fix:=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=B4=EB=AE=A4=ED=84=B0=EB=B8=94=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AE=A4=ED=84=B0=EB=B8=94=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/service/RecordService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index b659ca8e..99c0c600 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -1,6 +1,6 @@ package com.recordit.server.service; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -91,7 +91,7 @@ public RecordDetailResponseDto getDetailRecord(Long recordId) { Record record = recordRepository.findById(recordId) .orElseThrow(() -> new RecordNotFoundException("레코드 정보를 찾을 수 없습니다.")); - List imageUrls = Collections.emptyList(); + List imageUrls = new ArrayList<>(); Optional> optionalImageFileList = Optional.of( imageFileRepository.findAllByRefTypeAndRefId( From d9691beb7a19517251fa3661f59172f8fc29203b Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 12 Jan 2023 15:43:57 +0900 Subject: [PATCH 240/264] =?UTF-8?q?[BE-154]=20fix:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=EB=90=9C=20=ED=9A=8C=EC=9B=90=20=EB=8B=89=EB=84=A4?= =?UTF-8?q?=EC=9E=84=20=EB=B0=98=ED=99=98=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/service/MemberServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/recordit/server/service/MemberServiceTest.java b/src/test/java/com/recordit/server/service/MemberServiceTest.java index 8ae98804..1c5f51f7 100644 --- a/src/test/java/com/recordit/server/service/MemberServiceTest.java +++ b/src/test/java/com/recordit/server/service/MemberServiceTest.java @@ -226,7 +226,7 @@ class 로그인_된_사용자의_닉네임을_응답하는_기능에서 { void 로그인이_되어있지_않으면_예외를_던진다() { // given given(sessionUtil.findUserIdBySession()) - .willReturn(null); + .willThrow(new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다")); // when, then assertThatThrownBy(() -> memberService.findNicknameIfPresent()) From 2bbd1c3d63250e0506f381b77c47e32dedc72db7 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 12 Jan 2023 15:56:24 +0900 Subject: [PATCH 241/264] =?UTF-8?q?[BE-149]=20fix:=20DTO=20=EC=8A=A4?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=ED=81=AC=20=EC=BC=80=EC=9D=B4=EC=8A=A4?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=B9=B4=EB=A9=9C=20=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/dto/comment/CommentDto.java | 4 ---- .../com/recordit/server/dto/comment/CommentRequestDto.java | 4 ---- .../com/recordit/server/dto/comment/CommentResponseDto.java | 4 ---- .../recordit/server/dto/comment/WriteCommentRequestDto.java | 4 ---- .../recordit/server/dto/comment/WriteCommentResponseDto.java | 4 ---- .../server/dto/member/GoogleAccessTokenResponseDto.java | 4 ---- .../recordit/server/dto/member/GoogleUserInfoResponseDto.java | 4 ---- .../server/dto/member/KakaoAccessTokenResponseDto.java | 4 ---- .../recordit/server/dto/member/KakaoUserInfoResponseDto.java | 3 --- .../java/com/recordit/server/dto/member/LoginRequestDto.java | 4 ---- .../com/recordit/server/dto/member/RegisterRequestDto.java | 4 ---- .../server/dto/member/RegisterSessionResponseDto.java | 4 ---- .../recordit/server/dto/record/RecordDetailResponseDto.java | 4 ---- .../com/recordit/server/dto/record/WriteRecordRequestDto.java | 4 ---- .../recordit/server/dto/record/WriteRecordResponseDto.java | 4 ---- .../server/dto/record/category/RecordCategoryResponseDto.java | 3 --- 16 files changed, 62 deletions(-) diff --git a/src/main/java/com/recordit/server/dto/comment/CommentDto.java b/src/main/java/com/recordit/server/dto/comment/CommentDto.java index 24fb593a..855d2f83 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentDto.java @@ -1,8 +1,5 @@ package com.recordit.server.dto.comment; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import lombok.AccessLevel; import lombok.Getter; @@ -13,7 +10,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class CommentDto { private Long commentId; diff --git a/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java index 42a9a709..ee3aa56a 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java @@ -2,9 +2,6 @@ import javax.validation.constraints.NotNull; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; @@ -16,7 +13,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class CommentRequestDto { @ApiModelProperty(notes = "레코드의 id", required = true) @NotNull diff --git a/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java b/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java index 21149955..2f7b4f6f 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java @@ -4,9 +4,6 @@ import javax.validation.constraints.NotNull; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; @@ -18,7 +15,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class CommentResponseDto { @ApiModelProperty(notes = "레코드의 id", required = true) @NotNull diff --git a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java index 4cbb0df3..401968e5 100644 --- a/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java +++ b/src/main/java/com/recordit/server/dto/comment/WriteCommentRequestDto.java @@ -3,9 +3,6 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; @@ -18,7 +15,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class WriteCommentRequestDto { @ApiModelProperty(notes = "레코드의 id", required = true) diff --git a/src/main/java/com/recordit/server/dto/comment/WriteCommentResponseDto.java b/src/main/java/com/recordit/server/dto/comment/WriteCommentResponseDto.java index b73bdbcd..30ebc67f 100644 --- a/src/main/java/com/recordit/server/dto/comment/WriteCommentResponseDto.java +++ b/src/main/java/com/recordit/server/dto/comment/WriteCommentResponseDto.java @@ -1,8 +1,5 @@ package com.recordit.server.dto.comment; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import lombok.AccessLevel; import lombok.Builder; @@ -14,7 +11,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class WriteCommentResponseDto { private Long commentId; diff --git a/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java b/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java index 84744255..c50c9fbc 100644 --- a/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java @@ -1,8 +1,5 @@ package com.recordit.server.dto.member; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,7 +8,6 @@ @Getter @ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class GoogleAccessTokenResponseDto { private String accessToken; private String expiresIn; diff --git a/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java b/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java index 1d26b2ce..1a49d6e2 100644 --- a/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java @@ -1,8 +1,5 @@ package com.recordit.server.dto.member; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,7 +8,6 @@ @Getter @ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class GoogleUserInfoResponseDto { private String iss; private String azp; diff --git a/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java b/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java index cb19f788..aff2dc9f 100644 --- a/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java @@ -1,8 +1,5 @@ package com.recordit.server.dto.member; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,7 +8,6 @@ @Getter @ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class KakaoAccessTokenResponseDto { private String accessToken; private String tokenType; diff --git a/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java b/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java index e1281930..692882c8 100644 --- a/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java @@ -1,8 +1,6 @@ package com.recordit.server.dto.member; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.AccessLevel; import lombok.Getter; @@ -12,7 +10,6 @@ @Getter @ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) @JsonIgnoreProperties(ignoreUnknown = true) public class KakaoUserInfoResponseDto { private String id; diff --git a/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java b/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java index 22542fc3..05b98781 100644 --- a/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java +++ b/src/main/java/com/recordit/server/dto/member/LoginRequestDto.java @@ -1,8 +1,5 @@ package com.recordit.server.dto.member; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; @@ -15,7 +12,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class LoginRequestDto { @ApiModelProperty(notes = "Oauth API에서 응답 받은 토큰", required = true) diff --git a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java index 52c64751..69ce4208 100644 --- a/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java +++ b/src/main/java/com/recordit/server/dto/member/RegisterRequestDto.java @@ -2,9 +2,6 @@ import javax.validation.constraints.Pattern; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; @@ -17,7 +14,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class RegisterRequestDto { @ApiModelProperty(notes = "회원가입시 필요한 임시 Session", required = true) diff --git a/src/main/java/com/recordit/server/dto/member/RegisterSessionResponseDto.java b/src/main/java/com/recordit/server/dto/member/RegisterSessionResponseDto.java index 9a7de0fb..074e8f1b 100644 --- a/src/main/java/com/recordit/server/dto/member/RegisterSessionResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/RegisterSessionResponseDto.java @@ -1,8 +1,5 @@ package com.recordit.server.dto.member; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; @@ -15,7 +12,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class RegisterSessionResponseDto { @ApiModelProperty(notes = "회원가입시 필요한 임시 Session", required = true) diff --git a/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java b/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java index 01efcd8b..25564033 100644 --- a/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java +++ b/src/main/java/com/recordit/server/dto/record/RecordDetailResponseDto.java @@ -3,9 +3,6 @@ import java.time.LocalDateTime; import java.util.List; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import lombok.AccessLevel; import lombok.Builder; @@ -17,7 +14,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class RecordDetailResponseDto { private Long recordId; private Long categoryId; diff --git a/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java b/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java index fed8a68d..cc41ed46 100644 --- a/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java +++ b/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java @@ -4,9 +4,6 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import lombok.AccessLevel; import lombok.Builder; @@ -18,7 +15,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class WriteRecordRequestDto { @NotNull private Long recordCategoryId; diff --git a/src/main/java/com/recordit/server/dto/record/WriteRecordResponseDto.java b/src/main/java/com/recordit/server/dto/record/WriteRecordResponseDto.java index bc9eb1bc..c285d07d 100644 --- a/src/main/java/com/recordit/server/dto/record/WriteRecordResponseDto.java +++ b/src/main/java/com/recordit/server/dto/record/WriteRecordResponseDto.java @@ -1,8 +1,5 @@ package com.recordit.server.dto.record; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; - import io.swagger.annotations.ApiModel; import lombok.AccessLevel; import lombok.Builder; @@ -14,7 +11,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class WriteRecordResponseDto { private Long recordId; diff --git a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java index daa90bac..9471821f 100644 --- a/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java +++ b/src/main/java/com/recordit/server/dto/record/category/RecordCategoryResponseDto.java @@ -3,8 +3,6 @@ import java.util.ArrayList; import java.util.List; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.recordit.server.domain.RecordCategory; import io.swagger.annotations.ApiModel; @@ -19,7 +17,6 @@ @ToString @ApiModel @NoArgsConstructor(access = AccessLevel.PROTECTED) -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class RecordCategoryResponseDto { @ApiModelProperty(notes = "레코드 카테고리 ID", required = true) From eea2f849567d8352eab1ee1627a4c2e960d3a9d9 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 12 Jan 2023 21:18:26 +0900 Subject: [PATCH 242/264] =?UTF-8?q?[BE-130]=20fix:=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=EC=9E=90=EA=B0=80=20null=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=EC=9E=90=EB=A5=BC=20null=EB=A1=9C=20?= =?UTF-8?q?=EB=84=A3=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/dto/comment/CommentDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/dto/comment/CommentDto.java b/src/main/java/com/recordit/server/dto/comment/CommentDto.java index 1f3d1193..93419519 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentDto.java @@ -42,7 +42,7 @@ public class CommentDto { @Builder public CommentDto(Comment comment, String imageUrl) { this.commentId = comment.getId(); - this.writer = comment.getWriter().getNickname(); + this.writer = (comment.getWriter() != null) ? comment.getWriter().getNickname() : null; this.content = comment.getContent(); this.imageUrl = imageUrl; this.createdAt = comment.getCreatedAt(); From 36a3ddd24a3cde3c693a8d3d81e1b1b177ea8456 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 12 Jan 2023 21:18:51 +0900 Subject: [PATCH 243/264] =?UTF-8?q?[BE-130]=20fix:=20=EC=9D=B8=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20null=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=EB=A5=BC=20?= =?UTF-8?q?=EB=A8=BC=EC=A0=80=20=EC=B2=B4=ED=81=AC=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/service/CommentService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/service/CommentService.java b/src/main/java/com/recordit/server/service/CommentService.java index f611bf77..a5d829f3 100644 --- a/src/main/java/com/recordit/server/service/CommentService.java +++ b/src/main/java/com/recordit/server/service/CommentService.java @@ -121,7 +121,7 @@ private void validateEmptyContent( } private void validateParentHasParent(Comment parentComment) { - if (parentComment.getParentComment() != null) { + if (parentComment != null && parentComment.getParentComment() != null) { throw new IllegalStateException("자식 댓글을 기준으로 조회 불가능합니다."); } } From 22c6bb4ad53f8948d6b61e6cf5dcede74d36df29 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 12 Jan 2023 22:26:31 +0900 Subject: [PATCH 244/264] =?UTF-8?q?[BE-130]=20chore:=20merge=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=95=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/dto/comment/CommentDto.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/dto/comment/CommentDto.java b/src/main/java/com/recordit/server/dto/comment/CommentDto.java index aa88a6ee..3ee81a2e 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentDto.java @@ -1,7 +1,8 @@ package com.recordit.server.dto.comment; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; +import java.time.LocalDateTime; + +import com.recordit.server.domain.Comment; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; From 48bff55ff3c4ad43876cfc4428afb1f43cd962a1 Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 12 Jan 2023 22:40:17 +0900 Subject: [PATCH 245/264] =?UTF-8?q?[BE-157]=20fix:=20oauth=20dto=20?= =?UTF-8?q?=EC=8A=A4=EB=84=A4=EC=9D=B4=ED=81=AC=20=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존 스네이크 케이스에서 카멜 케이스로 변경하였으나, oauth에서 응답하는 값은 스네이크 케이스로 응답되어 oauth에서 응답되는 dto 는 스네이크 케이스로 변경하였습니다 --- .../server/dto/member/GoogleAccessTokenResponseDto.java | 4 ++++ .../recordit/server/dto/member/GoogleUserInfoResponseDto.java | 4 ++++ .../server/dto/member/KakaoAccessTokenResponseDto.java | 4 ++++ .../recordit/server/dto/member/KakaoUserInfoResponseDto.java | 3 +++ 4 files changed, 15 insertions(+) diff --git a/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java b/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java index c50c9fbc..84744255 100644 --- a/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/GoogleAccessTokenResponseDto.java @@ -1,5 +1,8 @@ package com.recordit.server.dto.member; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -8,6 +11,7 @@ @Getter @ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class GoogleAccessTokenResponseDto { private String accessToken; private String expiresIn; diff --git a/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java b/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java index 1a49d6e2..1d26b2ce 100644 --- a/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/GoogleUserInfoResponseDto.java @@ -1,5 +1,8 @@ package com.recordit.server.dto.member; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -8,6 +11,7 @@ @Getter @ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class GoogleUserInfoResponseDto { private String iss; private String azp; diff --git a/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java b/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java index aff2dc9f..cb19f788 100644 --- a/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/KakaoAccessTokenResponseDto.java @@ -1,5 +1,8 @@ package com.recordit.server.dto.member; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -8,6 +11,7 @@ @Getter @ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class KakaoAccessTokenResponseDto { private String accessToken; private String tokenType; diff --git a/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java b/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java index 692882c8..e1281930 100644 --- a/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java +++ b/src/main/java/com/recordit/server/dto/member/KakaoUserInfoResponseDto.java @@ -1,6 +1,8 @@ package com.recordit.server.dto.member; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.AccessLevel; import lombok.Getter; @@ -10,6 +12,7 @@ @Getter @ToString @NoArgsConstructor(access = AccessLevel.PROTECTED) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) @JsonIgnoreProperties(ignoreUnknown = true) public class KakaoUserInfoResponseDto { private String id; From 7e37994f66d5216ff0a85ff1ce7eab2629176e8a Mon Sep 17 00:00:00 2001 From: kdomo Date: Thu, 12 Jan 2023 23:40:17 +0900 Subject: [PATCH 246/264] =?UTF-8?q?[BE-158]=20fix:=20/auth=20swagger=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/controller/MemberController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/recordit/server/controller/MemberController.java b/src/main/java/com/recordit/server/controller/MemberController.java index 84d34d0f..fa81b0e9 100644 --- a/src/main/java/com/recordit/server/controller/MemberController.java +++ b/src/main/java/com/recordit/server/controller/MemberController.java @@ -119,6 +119,14 @@ public ResponseEntity duplicateNicknameCheck(@RequestParam String nickname) { return ResponseEntity.status(HttpStatus.OK).body(false); } + @ApiOperation( + value = "세션을 통해 닉네임 조회", + notes = "로그인 된 회원의 닉네임을 반환합니다" + ) + @ApiResponses({ + @ApiResponse(code = 200, message = "로그인 된 회원의 닉네임 반환", response = String.class), + @ApiResponse(code = 400, message = "세션에 사용자 정보가 저장되어 있지 않을 때") + }) @GetMapping("/auth") public ResponseEntity findNicknameIfPresent() { return ResponseEntity.status(HttpStatus.OK).body(memberService.findNicknameIfPresent()); From c6b09fc063f668faf9637e8895f8318d1c49df11 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Thu, 12 Jan 2023 23:54:07 +0900 Subject: [PATCH 247/264] =?UTF-8?q?[BE-130]=20test:=20=EB=8C=93=EA=B8=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B4=80=EB=A0=A8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/CommentServiceTest.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/src/test/java/com/recordit/server/service/CommentServiceTest.java b/src/test/java/com/recordit/server/service/CommentServiceTest.java index 7dfb25dc..92f8cfdb 100644 --- a/src/test/java/com/recordit/server/service/CommentServiceTest.java +++ b/src/test/java/com/recordit/server/service/CommentServiceTest.java @@ -5,6 +5,7 @@ import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -16,6 +17,7 @@ import com.recordit.server.domain.Comment; import com.recordit.server.domain.Record; +import com.recordit.server.dto.comment.CommentRequestDto; import com.recordit.server.dto.comment.WriteCommentRequestDto; import com.recordit.server.dto.comment.WriteCommentResponseDto; import com.recordit.server.exception.comment.CommentNotFoundException; @@ -185,4 +187,84 @@ class 댓글을_작성_할_때 { } } + @Nested + @DisplayName("댓글을 조회시") + class 댓글을_조회_할_때 { + + private CommentRequestDto commentRequestDto = mock(CommentRequestDto.class); + + @BeforeEach + void init() { + given(commentRequestDto.getPage()) + .willReturn(0); + given(commentRequestDto.getSize()) + .willReturn(1); + } + + @Nested + @DisplayName("조회하려는 부모 댓글 ID가 null일 때") + class 조회하려는_부모_댓글_ID가_null일_때 { + + @BeforeEach + void init() { + given(commentRequestDto.getParentId()) + .willReturn(null); + } + + @Test + @DisplayName("지정한 레코드 ID가 존재하지 않으면 예외를 던진다") + void 지정한_레코드_ID가_존재하지_않으면_예외를_던진다() { + // given + given(recordRepository.findById(any())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> commentService.getCommentsBy(commentRequestDto)) + .isInstanceOf(RecordNotFoundException.class); + } + + } + + @Nested + @DisplayName("조회하려는 부모 댓글 ID가 null이 아닐 때") + class 조회하려는_부모_댓글_ID가_null이_아닐_때 { + + @BeforeEach + void init() { + given(commentRequestDto.getParentId()) + .willReturn(1L); + } + + @Test + @DisplayName("지정한 부모 댓글이 존재하지 않으면 예외를 던진다") + void 지정한_부모_댓글이_존재하지_않으면_예외를_던진다() { + // given + given(commentRepository.findById(commentRequestDto.getParentId())) + .willReturn(Optional.empty()); + + // when, then + assertThatThrownBy(() -> commentService.getCommentsBy(commentRequestDto)) + .isInstanceOf(CommentNotFoundException.class); + } + + @Test + @DisplayName("부모가 부모를 가질 때 예외를 던진다") + void 부모가_부모를_가질_때_예외를_던진다() { + // given + Comment parentComment = mock(Comment.class); + Comment grandParentComment = mock(Comment.class); + given(commentRepository.findById(commentRequestDto.getParentId())) + .willReturn(Optional.of(parentComment)); + given(parentComment.getParentComment()) + .willReturn(grandParentComment); + + // when, then + assertThatThrownBy(() -> commentService.getCommentsBy(commentRequestDto)) + .isInstanceOf(IllegalStateException.class); + } + + } + + } + } From 20fab6b1d9ca21f2c9777b6fe4909ac0b369b5cb Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 13 Jan 2023 09:13:11 +0900 Subject: [PATCH 248/264] =?UTF-8?q?[BE-130]=20refactor:=20=ED=95=98?= =?UTF-8?q?=EC=9C=84=20=EB=8C=93=EA=B8=80=20=EA=B0=9C=EC=88=98=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20required?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/dto/comment/CommentDto.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/dto/comment/CommentDto.java b/src/main/java/com/recordit/server/dto/comment/CommentDto.java index 3ee81a2e..138cf6b8 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentDto.java @@ -30,18 +30,22 @@ public class CommentDto { @ApiModelProperty(notes = "첨부 이미지 URL", required = true) private String imageUrl; - @ApiModelProperty(notes = "생성 일자") + @ApiModelProperty(notes = "하위 댓글 개수", required = false) + private Long numOfSubComment; + + @ApiModelProperty(notes = "생성 일자", required = true) private LocalDateTime createdAt; - @ApiModelProperty(notes = "수정 일자") + @ApiModelProperty(notes = "수정 일자", required = false) private LocalDateTime modifiedAt; @Builder - public CommentDto(Comment comment, String imageUrl) { + public CommentDto(Comment comment, String imageUrl, Long numOfSubComment) { this.commentId = comment.getId(); this.writer = (comment.getWriter() != null) ? comment.getWriter().getNickname() : null; this.content = comment.getContent(); this.imageUrl = imageUrl; + this.numOfSubComment = numOfSubComment; this.createdAt = comment.getCreatedAt(); this.modifiedAt = comment.getModifiedAt(); } From 65224998353856373046d795b67de768df9b1f34 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 13 Jan 2023 09:13:33 +0900 Subject: [PATCH 249/264] =?UTF-8?q?[BE-130]=20feat:=20=ED=95=98=EC=9C=84?= =?UTF-8?q?=20=EB=8C=93=EA=B8=80=EC=9D=98=20=EA=B0=9C=EC=88=98=EB=A5=BC=20?= =?UTF-8?q?=EA=B5=AC=ED=95=98=EB=8A=94=20=EC=BF=BC=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/repository/CommentRepository.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/repository/CommentRepository.java b/src/main/java/com/recordit/server/repository/CommentRepository.java index 10209b9b..d2fecbdc 100644 --- a/src/main/java/com/recordit/server/repository/CommentRepository.java +++ b/src/main/java/com/recordit/server/repository/CommentRepository.java @@ -13,10 +13,12 @@ public interface CommentRepository extends JpaRepository { @EntityGraph(attributePaths = {"writer"}) - @Query("select c from COMMENT c left join c.writer where c.record = :record") + @Query("select c from COMMENT c left join c.writer where c.record = :record and c.parentComment is null") Page findAllByRecordWithPagination(@Param("record") Record record, Pageable pageable); @EntityGraph(attributePaths = "writer") @Query("select c from COMMENT c left join c.writer where c.parentComment = :parentComment") Page findAllByParentComment(@Param("parentComment") Comment parentComment, Pageable pageable); + + Long countAllByParentComment(Comment parentComment); } From 6f7aab8bd715de2e23772e6e8798905fcbdd3d92 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 13 Jan 2023 09:14:18 +0900 Subject: [PATCH 250/264] =?UTF-8?q?[BE-130]=20refactor:=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20DTO=EC=97=90=20=ED=95=98=EC=9C=84=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EA=B0=9C=EC=88=98=EB=A5=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/dto/comment/CommentResponseDto.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java b/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java index 2b66d6c7..f187d5c1 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentResponseDto.java @@ -5,8 +5,6 @@ import org.springframework.data.domain.Page; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; import com.recordit.server.domain.Comment; import io.swagger.annotations.ApiModel; @@ -33,7 +31,7 @@ public class CommentResponseDto { private List commentList; @Builder - public CommentResponseDto(Page comments, List imageFileUrls) { + public CommentResponseDto(Page comments, List imageFileUrls, List numOfSubComments) { this.totalPage = comments.getTotalPages(); this.totalCount = comments.getTotalElements(); this.commentList = new ArrayList<>(); @@ -42,6 +40,7 @@ public CommentResponseDto(Page comments, List imageFileUrls) { CommentDto.builder() .comment(comments.getContent().get(i)) .imageUrl(imageFileUrls.get(i)) + .numOfSubComment(numOfSubComments.get(i)) .build() ); } From b488a0a736326683bd7a71948341e2cc6d5f2d7f Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Fri, 13 Jan 2023 09:15:17 +0900 Subject: [PATCH 251/264] =?UTF-8?q?[BE-130]=20refactor:=20=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EC=A1=B0=ED=9A=8C=EB=A5=BC=20=EC=B5=9C=EC=8B=A0?= =?UTF-8?q?=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EB=B0=94=EA=BE=B8=EA=B3=A0,=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=9C=20=EB=8C=93=EA=B8=80=EC=9D=98=20?= =?UTF-8?q?=EC=84=9C=EB=B8=8C=20=EB=8C=93=EA=B8=80=EC=9D=98=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=EB=A5=BC=20=EA=B5=AC=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/recordit/server/service/CommentService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/service/CommentService.java b/src/main/java/com/recordit/server/service/CommentService.java index a5d829f3..995e4bad 100644 --- a/src/main/java/com/recordit/server/service/CommentService.java +++ b/src/main/java/com/recordit/server/service/CommentService.java @@ -84,7 +84,7 @@ public CommentResponseDto getCommentsBy(CommentRequestDto commentRequestDto) { PageRequest pageRequest = PageRequest.of( commentRequestDto.getPage(), commentRequestDto.getSize(), - Sort.Direction.ASC, + Sort.Direction.DESC, "createdAt" ); @@ -101,6 +101,10 @@ public CommentResponseDto getCommentsBy(CommentRequestDto commentRequestDto) { findComments = commentRepository.findAllByParentComment(parentComment, pageRequest); } + List numOfSubComments = findComments.stream() + .map(comment -> commentRepository.countAllByParentComment(comment)) + .collect(Collectors.toList()); + List imageFileUrls = findComments.stream() .map(comment -> imageFileService.getImageFile(RefType.COMMENT, comment.getId())) .collect(Collectors.toList()); @@ -108,6 +112,7 @@ public CommentResponseDto getCommentsBy(CommentRequestDto commentRequestDto) { return CommentResponseDto.builder() .comments(findComments) .imageFileUrls(imageFileUrls) + .numOfSubComments(numOfSubComments) .build(); } @@ -122,7 +127,7 @@ private void validateEmptyContent( private void validateParentHasParent(Comment parentComment) { if (parentComment != null && parentComment.getParentComment() != null) { - throw new IllegalStateException("자식 댓글을 기준으로 조회 불가능합니다."); + throw new IllegalStateException("부모 댓글은 부모를 가질 수 없습니다."); } } From b5a0076c7a0c956306bb8e699c5a7fd4506b188e Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 14 Jan 2023 17:13:40 +0900 Subject: [PATCH 252/264] =?UTF-8?q?[BE-164]=20test:=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=9D=B4=20null=EC=9D=B8=EC=A7=80=20=EB=98=90=EB=8A=94=20?= =?UTF-8?q?=EB=B9=84=EC=96=B4=EC=9E=88=EB=8A=94=EC=A7=80=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=ED=95=98=EB=8A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/service/CommentServiceTest.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/recordit/server/service/CommentServiceTest.java b/src/test/java/com/recordit/server/service/CommentServiceTest.java index 92f8cfdb..a77c0d27 100644 --- a/src/test/java/com/recordit/server/service/CommentServiceTest.java +++ b/src/test/java/com/recordit/server/service/CommentServiceTest.java @@ -14,6 +14,7 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.mock.web.MockMultipartFile; +import org.springframework.web.multipart.MultipartFile; import com.recordit.server.domain.Comment; import com.recordit.server.domain.Record; @@ -66,7 +67,7 @@ class 댓글을_작성_할_때 { .build(); MockMultipartFile multipartFile = mock(MockMultipartFile.class); - given(multipartFile.isEmpty()) + given(imageFileService.isEmptyFile(any(MultipartFile.class))) .willReturn(true); // when, then @@ -85,8 +86,6 @@ class 댓글을_작성_할_때 { .build(); MockMultipartFile multipartFile = mock(MockMultipartFile.class); - given(multipartFile.isEmpty()) - .willReturn(false); given(sessionUtil.findUserIdBySession()) .willReturn(1L); given(memberRepository.findById(1L)) @@ -109,8 +108,6 @@ class 댓글을_작성_할_때 { .build(); MockMultipartFile multipartFile = mock(MockMultipartFile.class); - given(multipartFile.isEmpty()) - .willReturn(false); given(sessionUtil.findUserIdBySession()) .willThrow(new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다")); given(recordRepository.findById(writeCommentRequestDto.getRecordId())) @@ -133,8 +130,6 @@ class 댓글을_작성_할_때 { MockMultipartFile multipartFile = mock(MockMultipartFile.class); Record record = mock(Record.class); - given(multipartFile.isEmpty()) - .willReturn(false); given(sessionUtil.findUserIdBySession()) .willThrow(new NotFoundUserInfoInSessionException("세션에 사용자 정보가 저장되어 있지 않습니다")); given(recordRepository.findById(writeCommentRequestDto.getRecordId())) @@ -257,7 +252,7 @@ void init() { .willReturn(Optional.of(parentComment)); given(parentComment.getParentComment()) .willReturn(grandParentComment); - + // when, then assertThatThrownBy(() -> commentService.getCommentsBy(commentRequestDto)) .isInstanceOf(IllegalStateException.class); From 3b9d8c7cfae3cf647503716ccdf3270185f51741 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 14 Jan 2023 17:14:05 +0900 Subject: [PATCH 253/264] =?UTF-8?q?[BE-164]=20feat:=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=9D=B4=20=EB=B9=84=EC=96=B4=EC=9E=88=EB=8A=94=EC=A7=80=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/ImageFileService.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/recordit/server/service/ImageFileService.java b/src/main/java/com/recordit/server/service/ImageFileService.java index 6e4ce1eb..b3a72bc1 100644 --- a/src/main/java/com/recordit/server/service/ImageFileService.java +++ b/src/main/java/com/recordit/server/service/ImageFileService.java @@ -130,4 +130,23 @@ private void validateFileExtension(MultipartFile multipartFile) { .orElseThrow(() -> new FileExtensionNotAllowedException("지원하지 않은 파일 확장자입니다.")); } + public boolean isEmptyFile(MultipartFile multipartFile) { + if (multipartFile == null || multipartFile.isEmpty()) { + return true; + } + return false; + } + + public boolean isEmptyFile(List multipartFiles) { + if (multipartFiles == null) { + return true; + } + for (MultipartFile multipartFile : multipartFiles) { + if (isEmptyFile(multipartFile)) { + return true; + } + } + return false; + } + } From 21d8ea66ea6c7e3100260d74c701e5acbbec7768 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 14 Jan 2023 17:14:51 +0900 Subject: [PATCH 254/264] =?UTF-8?q?[BE-164]=20refactor:=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EC=9D=B4=20=EB=B9=84=EC=96=B4=EC=9E=88=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=EA=B2=80=EC=A6=9D=ED=95=A0=20=EB=95=8C=20null=20?= =?UTF-8?q?=EB=98=90=EB=8A=94=20isEmpty=EB=A5=BC=20=ED=86=B5=ED=95=B4=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/controller/CommentController.java | 2 +- .../java/com/recordit/server/service/CommentService.java | 6 ++++-- .../java/com/recordit/server/service/RecordService.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/CommentController.java b/src/main/java/com/recordit/server/controller/CommentController.java index 77cfc6a2..ecd2f905 100644 --- a/src/main/java/com/recordit/server/controller/CommentController.java +++ b/src/main/java/com/recordit/server/controller/CommentController.java @@ -47,7 +47,7 @@ public class CommentController { @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity writeComment( @ApiParam(required = true) @RequestPart(required = true) @Valid WriteCommentRequestDto writeCommentRequestDto, - @ApiParam @RequestPart MultipartFile attachment + @ApiParam @RequestPart(required = false) MultipartFile attachment ) { return ResponseEntity.ok(commentService.writeComment(writeCommentRequestDto, attachment)); } diff --git a/src/main/java/com/recordit/server/service/CommentService.java b/src/main/java/com/recordit/server/service/CommentService.java index 995e4bad..cae4d536 100644 --- a/src/main/java/com/recordit/server/service/CommentService.java +++ b/src/main/java/com/recordit/server/service/CommentService.java @@ -69,7 +69,9 @@ public WriteCommentResponseDto writeComment( ) ); - imageFileService.saveAttachmentFile(RefType.COMMENT, saveComment.getId(), attachment); + if (!imageFileService.isEmptyFile(attachment)) { + imageFileService.saveAttachmentFile(RefType.COMMENT, saveComment.getId(), attachment); + } log.info("저장한 댓글 ID : {}", saveComment.getId()); @@ -120,7 +122,7 @@ private void validateEmptyContent( WriteCommentRequestDto writeCommentRequestDto, MultipartFile attachment ) { - if (attachment.isEmpty() && !StringUtils.hasText(writeCommentRequestDto.getComment())) { + if (imageFileService.isEmptyFile(attachment) && !StringUtils.hasText(writeCommentRequestDto.getComment())) { throw new EmptyContentException("댓글 내용과 이미지 파일 모두 비어있을 수 없습니다."); } } diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 99c0c600..1ee48d9f 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -76,7 +76,7 @@ public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordReque Long recordId = recordRepository.save(record).getId(); log.info("저장한 레코드 ID : ", recordId); - if (files != null) { + if (!imageFileService.isEmptyFile(files)) { List urls = imageFileService.saveAttachmentFiles(RefType.RECORD, recordId, files); log.info("저장된 이미지 urls : {}", urls); } From a45133f51cdf75365703a3504105134b7b5580fd Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 14 Jan 2023 17:22:13 +0900 Subject: [PATCH 255/264] =?UTF-8?q?[BE-160]=20feat:=20RedisManager?= =?UTF-8?q?=EC=97=90=20=EC=A7=80=EC=9A=B0=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/util/RedisManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/recordit/server/util/RedisManager.java b/src/main/java/com/recordit/server/util/RedisManager.java index ef443d71..79a395e1 100644 --- a/src/main/java/com/recordit/server/util/RedisManager.java +++ b/src/main/java/com/recordit/server/util/RedisManager.java @@ -38,6 +38,10 @@ public void set(@NonNull String key, @NonNull Object value, long timeout, @NonNu } } + public void delete(@NonNull String key) { + stringRedisTemplate.delete(key); + } + public Optional get(@NonNull String key, @NonNull Class clazz) { String jsonString = stringRedisTemplate.opsForValue().get(key); if (!StringUtils.hasText(jsonString)) { From 0b96374f78e2e17a5d6ee843a14eb84a904472c4 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 14 Jan 2023 17:22:46 +0900 Subject: [PATCH 256/264] =?UTF-8?q?[BE-160]=20refactor:=20=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=99=84=EB=A3=8C=20=ED=9B=84=EC=97=90=20RegisterS?= =?UTF-8?q?ession=EC=9D=84=20=EC=A7=80=EC=9A=B0=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/recordit/server/service/MemberService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/service/MemberService.java b/src/main/java/com/recordit/server/service/MemberService.java index e9e3a49c..81ff8250 100644 --- a/src/main/java/com/recordit/server/service/MemberService.java +++ b/src/main/java/com/recordit/server/service/MemberService.java @@ -80,7 +80,7 @@ public void oauthRegister(LoginType loginType, RegisterRequestDto registerReques ) ); sessionUtil.saveUserIdInSession(saveMember.getId()); - // TODO RegisterSession을 읽어와서 가입까지 완료 했다면 RegisterSession을 삭제 해야함 + redisManager.delete(PREFIX_REGISTER_SESSION + registerRequestDto.getRegisterSession()); } @Transactional(readOnly = true) From 1d755033f8d919ca4e743d44f1e3ef6c9e226d03 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Sat, 14 Jan 2023 19:08:51 +0900 Subject: [PATCH 257/264] =?UTF-8?q?[BE-165]=20fix:=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=A1=B0=EA=B1=B4=EC=9D=84=20Body?= =?UTF-8?q?=EA=B0=80=20=EC=95=84=EB=8B=8C=20Parameter=EB=A1=9C=20=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/CommentController.java | 4 ++-- .../server/dto/comment/CommentRequestDto.java | 20 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/CommentController.java b/src/main/java/com/recordit/server/controller/CommentController.java index ecd2f905..30ecf00e 100644 --- a/src/main/java/com/recordit/server/controller/CommentController.java +++ b/src/main/java/com/recordit/server/controller/CommentController.java @@ -5,8 +5,8 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; @@ -71,7 +71,7 @@ public ResponseEntity writeComment( ) }) @GetMapping - public ResponseEntity getComment(@Valid @RequestBody CommentRequestDto commentRequestDto) { + public ResponseEntity getComment(@Valid @ModelAttribute CommentRequestDto commentRequestDto) { return ResponseEntity.ok(commentService.getCommentsBy(commentRequestDto)); } } diff --git a/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java b/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java index 4f9edda5..6719429c 100644 --- a/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java +++ b/src/main/java/com/recordit/server/dto/comment/CommentRequestDto.java @@ -2,31 +2,29 @@ import javax.validation.constraints.NotNull; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; import lombok.AccessLevel; +import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.ToString; @Getter @ToString -@ApiModel -@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) public class CommentRequestDto { - @ApiModelProperty(notes = "레코드 ID", required = true) + @ApiParam(value = "레코드 ID", required = true, example = "0") @NotNull private Long recordId; - @ApiModelProperty(notes = "자식 댓글을 조회하는 경우 부모 댓글의 ID") + @ApiParam(value = "자식 댓글을 조회하는 경우 부모 댓글의 ID", example = "0") private Long parentId; - @ApiModelProperty(notes = "댓글 리스트의 요청 페이지 !주의: 0부터 시작", required = true) + @ApiParam(value = "댓글 리스트의 요청 페이지 !주의: 0부터 시작", required = true, example = "0") @NotNull - private int page; + private Integer page; - @ApiModelProperty(notes = "댓글 리스트의 사이즈", required = true) + @ApiParam(value = "댓글 리스트의 사이즈", required = true, example = "10") @NotNull - private int size; + private Integer size; } From ef15129ac4cc2683b0af0269a2fcdca9fd855f97 Mon Sep 17 00:00:00 2001 From: kdomo Date: Sun, 15 Jan 2023 22:59:23 +0900 Subject: [PATCH 258/264] =?UTF-8?q?[BE-155]=20chore:=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=ED=81=AC=EA=B8=B0=20=EC=A0=9C=ED=95=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 4 ++++ src/main/resources/application-local.yml | 4 ++++ src/main/resources/application-prod.yml | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 555f126c..4fabd053 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -22,6 +22,10 @@ spring: level: '[org.springframework.web]': DEBUG '[org.hibernate]': DEBUG + servlet: + multipart: + max-request-size: 5MB + max-file-size: 5MB springfox: documentation: swagger: diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index dfc8f26d..eb0d00ae 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -22,6 +22,10 @@ spring: level: '[org.springframework.web]': DEBUG '[org.hibernate]': DEBUG + servlet: + multipart: + max-request-size: 5MB + max-file-size: 5MB springfox: documentation: swagger: diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index d9f7f0c2..d18ecd50 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -10,6 +10,10 @@ spring: ddl-auto: none naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl + servlet: + multipart: + max-request-size: 5MB + max-file-size: 5MB logging: config: classpath:log4j2/log4j2-prod.xml cors: From b081cfa8b7faf32ad9b692fea02f7b7a1b47f966 Mon Sep 17 00:00:00 2001 From: kdomo Date: Sun, 15 Jan 2023 23:11:15 +0900 Subject: [PATCH 259/264] =?UTF-8?q?[BE-155]=20chore:=20max-request-size=20?= =?UTF-8?q?15MB=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-dev.yml | 2 +- src/main/resources/application-local.yml | 2 +- src/main/resources/application-prod.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 4fabd053..f59aaf65 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -24,7 +24,7 @@ spring: '[org.hibernate]': DEBUG servlet: multipart: - max-request-size: 5MB + max-request-size: 15MB max-file-size: 5MB springfox: documentation: diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index eb0d00ae..ae66f596 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -24,7 +24,7 @@ spring: '[org.hibernate]': DEBUG servlet: multipart: - max-request-size: 5MB + max-request-size: 15MB max-file-size: 5MB springfox: documentation: diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index d18ecd50..5692e7d5 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -12,7 +12,7 @@ spring: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl servlet: multipart: - max-request-size: 5MB + max-request-size: 15MB max-file-size: 5MB logging: config: classpath:log4j2/log4j2-prod.xml From 02c81c67b47238ca52189646346a36bc2f7ee406 Mon Sep 17 00:00:00 2001 From: kdomo Date: Sun, 15 Jan 2023 23:24:18 +0900 Subject: [PATCH 260/264] =?UTF-8?q?[BE-163]=20refactor:=20writeRecord=20fi?= =?UTF-8?q?les=EB=A5=BC=20attachments=EB=A1=9C=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/controller/RecordController.java | 5 +++-- .../java/com/recordit/server/service/RecordService.java | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/recordit/server/controller/RecordController.java b/src/main/java/com/recordit/server/controller/RecordController.java index ce18168d..af89e1af 100644 --- a/src/main/java/com/recordit/server/controller/RecordController.java +++ b/src/main/java/com/recordit/server/controller/RecordController.java @@ -50,9 +50,10 @@ public class RecordController { @PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity writeRecord( @ApiParam(required = true) @RequestPart(required = true) @Valid WriteRecordRequestDto writeRecordRequestDto, - @ApiParam @RequestPart(required = false) List files + @ApiParam @RequestPart(required = false) List attachments ) { - return ResponseEntity.status(HttpStatus.CREATED).body(recordService.writeRecord(writeRecordRequestDto, files)); + return ResponseEntity.status(HttpStatus.CREATED) + .body(recordService.writeRecord(writeRecordRequestDto, attachments)); } @ApiOperation( diff --git a/src/main/java/com/recordit/server/service/RecordService.java b/src/main/java/com/recordit/server/service/RecordService.java index 1ee48d9f..57259672 100644 --- a/src/main/java/com/recordit/server/service/RecordService.java +++ b/src/main/java/com/recordit/server/service/RecordService.java @@ -48,7 +48,8 @@ public class RecordService { private final ImageFileService imageFileService; @Transactional - public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordRequestDto, List files) { + public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordRequestDto, + List attachments) { Long userIdBySession = sessionUtil.findUserIdBySession(); log.info("세션에서 찾은 사용자 ID : {}", userIdBySession); @@ -76,8 +77,8 @@ public WriteRecordResponseDto writeRecord(WriteRecordRequestDto writeRecordReque Long recordId = recordRepository.save(record).getId(); log.info("저장한 레코드 ID : ", recordId); - if (!imageFileService.isEmptyFile(files)) { - List urls = imageFileService.saveAttachmentFiles(RefType.RECORD, recordId, files); + if (!imageFileService.isEmptyFile(attachments)) { + List urls = imageFileService.saveAttachmentFiles(RefType.RECORD, recordId, attachments); log.info("저장된 이미지 urls : {}", urls); } From 8d453388d6a2839c3e1125c8cc3df973992629eb Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 16 Jan 2023 01:30:27 +0900 Subject: [PATCH 261/264] =?UTF-8?q?[BE-167]=20fix:=20validation=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=20=EC=8B=9C=20ErrorMessage=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/exception/ErrorMessage.java | 13 ++++++++++++- .../server/exception/GlobalExceptionHandler.java | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/recordit/server/exception/ErrorMessage.java b/src/main/java/com/recordit/server/exception/ErrorMessage.java index 899b49c2..5455d1f6 100644 --- a/src/main/java/com/recordit/server/exception/ErrorMessage.java +++ b/src/main/java/com/recordit/server/exception/ErrorMessage.java @@ -15,14 +15,25 @@ public class ErrorMessage { private String msg; private LocalDateTime timestamp; + public ErrorMessage(Exception exception, HttpStatus httpStatus, String message) { + this.code = httpStatus.value(); + this.errorSimpleName = exception.getClass().getSimpleName(); + this.msg = message; + this.timestamp = LocalDateTime.now(); + } + public ErrorMessage(Exception exception, HttpStatus httpStatus) { this.code = httpStatus.value(); this.errorSimpleName = exception.getClass().getSimpleName(); - this.msg = exception.getLocalizedMessage(); + this.msg = exception.getMessage(); this.timestamp = LocalDateTime.now(); } public static ErrorMessage of(Exception exception, HttpStatus httpStatus) { return new ErrorMessage(exception, httpStatus); } + + public static ErrorMessage of(Exception exception, HttpStatus httpStatus, String message) { + return new ErrorMessage(exception, httpStatus, message); + } } \ No newline at end of file diff --git a/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java b/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java index 0c4ae241..6255998a 100644 --- a/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/recordit/server/exception/GlobalExceptionHandler.java @@ -14,7 +14,9 @@ public class GlobalExceptionHandler { @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity handleMethodArgumentNotValidException( MethodArgumentNotValidException exception) { + String message = exception.getBindingResult().getAllErrors().get(0).getDefaultMessage(); + return ResponseEntity.badRequest() - .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST)); + .body(ErrorMessage.of(exception, HttpStatus.BAD_REQUEST, message)); } } From 4385e7da18c36b7d29e3af370789e7b468956fd9 Mon Sep 17 00:00:00 2001 From: Jaeyeop-Jung Date: Mon, 16 Jan 2023 02:01:28 +0900 Subject: [PATCH 262/264] =?UTF-8?q?[BE-169]=20chore:=20prod=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20Swagger=20=EC=82=AC=EC=9A=A9=20=EB=AA=BB?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-prod.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 5692e7d5..e3e9d668 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -17,4 +17,14 @@ spring: logging: config: classpath:log4j2/log4j2-prod.xml cors: - origin: ${CORS_ORIGIN_NAME:} \ No newline at end of file + origin: ${CORS_ORIGIN_NAME:} +springfox: + documentation: + enabled: false + swagger-ui: + enabled: false + open-api: + enabled: false + swagger: + v2: + enabled: false From 00520818ec5c7f019dcc1c359bb8a062f09b12ae Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 16 Jan 2023 02:12:01 +0900 Subject: [PATCH 263/264] =?UTF-8?q?[BE-168]=20fix:=20HTTPLogFilter?= =?UTF-8?q?=EC=97=90=EC=84=9C=20body=EA=B0=92=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EC=95=88=EB=90=98=EB=8D=98=20=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../recordit/server/logger/HTTPLogFilter.java | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/recordit/server/logger/HTTPLogFilter.java b/src/main/java/com/recordit/server/logger/HTTPLogFilter.java index 270afba1..b8ab47ba 100644 --- a/src/main/java/com/recordit/server/logger/HTTPLogFilter.java +++ b/src/main/java/com/recordit/server/logger/HTTPLogFilter.java @@ -17,7 +17,6 @@ import org.springframework.stereotype.Component; import org.springframework.web.util.ContentCachingRequestWrapper; import org.springframework.web.util.ContentCachingResponseWrapper; -import org.springframework.web.util.WebUtils; import lombok.extern.slf4j.Slf4j; @@ -39,10 +38,11 @@ public void doFilter( ); long start = System.currentTimeMillis(); - chain.doFilter(request, response); + chain.doFilter(requestWrapper, responseWrapper); long end = System.currentTimeMillis(); - if (isInExcludeURIForLog(request)) { + if (isInExcludeURIForLog(requestWrapper)) { + responseWrapper.copyBodyToResponse(); return; } @@ -56,35 +56,35 @@ public void doFilter( ((HttpServletRequest)request).getRequestURI(), responseWrapper.getStatus(), (end - start), - getHeaders((HttpServletRequest)request), + getHeaders(requestWrapper), getRequestParameter(requestWrapper), getRequestBody(requestWrapper), getResponseBody(responseWrapper)); } - private boolean isInExcludeURIForLog(ServletRequest request) { - if (((HttpServletRequest)request).getRequestURI().contains("/api/swagger")) { + private boolean isInExcludeURIForLog(ContentCachingRequestWrapper requestWrapper) { + if ((requestWrapper.getRequestURI().contains("/api/swagger"))) { return true; } - if ("/v2/api-docs".equals(((HttpServletRequest)request).getRequestURI())) { + if ("/v2/api-docs".equals(requestWrapper.getRequestURI())) { return true; } return false; } - private Map getHeaders(HttpServletRequest request) { + private Map getHeaders(ContentCachingRequestWrapper requestWrapper) { Map headerMap = new HashMap<>(); - Enumeration headerArray = request.getHeaderNames(); + Enumeration headerArray = requestWrapper.getHeaderNames(); while (headerArray.hasMoreElements()) { String headerName = (String)headerArray.nextElement(); - headerMap.put(headerName, request.getHeader(headerName)); + headerMap.put(headerName, requestWrapper.getHeader(headerName)); } return headerMap; } - private String getRequestParameter(ContentCachingRequestWrapper request) { - Map parameterMap = request.getParameterMap(); + private String getRequestParameter(ContentCachingRequestWrapper requestWrapper) { + Map parameterMap = requestWrapper.getParameterMap(); if (parameterMap.size() == 0) { return "-"; } @@ -101,13 +101,12 @@ private String getRequestParameter(ContentCachingRequestWrapper request) { return sb.toString(); } - private String getRequestBody(ContentCachingRequestWrapper request) { - ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class); - if (wrapper != null) { - byte[] buf = wrapper.getContentAsByteArray(); + private String getRequestBody(ContentCachingRequestWrapper requestWrapper) { + if (requestWrapper != null) { + byte[] buf = requestWrapper.getContentAsByteArray(); if (buf.length > 0) { try { - return new String(buf, 0, buf.length, wrapper.getCharacterEncoding()); + return new String(buf, 0, buf.length, requestWrapper.getCharacterEncoding()); } catch (UnsupportedEncodingException e) { return " - "; } @@ -116,18 +115,14 @@ private String getRequestBody(ContentCachingRequestWrapper request) { return " - "; } - private String getResponseBody(final HttpServletResponse response) throws IOException { + private String getResponseBody(ContentCachingResponseWrapper responseWrapper) throws IOException { String payload = null; - ContentCachingResponseWrapper wrapper = WebUtils.getNativeResponse( - response, - ContentCachingResponseWrapper.class - ); - if (wrapper != null) { - wrapper.setCharacterEncoding("UTF-8"); - byte[] buf = wrapper.getContentAsByteArray(); + if (responseWrapper != null) { + responseWrapper.setCharacterEncoding("UTF-8"); + byte[] buf = responseWrapper.getContentAsByteArray(); if (buf.length > 0) { - payload = new String(buf, 0, buf.length, wrapper.getCharacterEncoding()); - wrapper.copyBodyToResponse(); + payload = new String(buf, 0, buf.length, responseWrapper.getCharacterEncoding()); + responseWrapper.copyBodyToResponse(); } } return null == payload ? " - " : payload; From aaeea41ffcaa46d1608bd014ad0dd03f64a22d98 Mon Sep 17 00:00:00 2001 From: kdomo Date: Mon, 16 Jan 2023 20:22:42 +0900 Subject: [PATCH 264/264] =?UTF-8?q?[BE-170]=20fix:=20=EC=A0=95=EC=B1=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20Wri?= =?UTF-8?q?teRecordRequestDto=20title=20Size=2012=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/recordit/server/dto/record/WriteRecordRequestDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java b/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java index cc41ed46..5cd5b9e1 100644 --- a/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java +++ b/src/main/java/com/recordit/server/dto/record/WriteRecordRequestDto.java @@ -19,7 +19,7 @@ public class WriteRecordRequestDto { @NotNull private Long recordCategoryId; - @Size(max = 10, message = "레코드 제목은 최대 10자 입니다.") + @Size(max = 12, message = "레코드 제목은 최대 10자 입니다.") @NotBlank(message = "레코드 제목은 빈 값일 수 없습니다.") private String title;