From 10e3d2c184f553db7732f3aea23b65fe0e4c525e Mon Sep 17 00:00:00 2001 From: k000927 Date: Tue, 30 Jul 2024 16:41:25 +0900 Subject: [PATCH 01/17] =?UTF-8?q?feat:=20validateEnumField=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=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 --- .../event/entity/casperBot/CasperBot.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java index ec9d3fbf..00a22c4d 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java @@ -3,6 +3,7 @@ import JGS.CasperEvent.domain.event.entity.casperBot.casperEnum.*; import JGS.CasperEvent.global.entity.BaseEntity; import com.google.gson.annotations.SerializedName; +import jakarta.annotation.PostConstruct; import jakarta.persistence.*; import static jakarta.persistence.GenerationType.IDENTITY; @@ -73,4 +74,23 @@ public String getName() { public String getExpectation() { return expectation; } + + @PostConstruct + public void validateEnumFields() { + if (eyeShape == null) { + throw new IllegalArgumentException("EyeShape cannot be null"); + } + if (eyePosition == null) { + throw new IllegalArgumentException("EyePosition cannot be null"); + } + if (mouthShape == null) { + throw new IllegalArgumentException("MouthShape cannot be null"); + } + if (color == null) { + throw new IllegalArgumentException("Color cannot be null"); + } + if (sticker == null) { + throw new IllegalArgumentException("Sticker cannot be null"); + } + } } From 97d7f87e9934f204a707fdf46202c2340fb63640 Mon Sep 17 00:00:00 2001 From: k000927 Date: Tue, 30 Jul 2024 17:29:01 +0900 Subject: [PATCH 02/17] =?UTF-8?q?chore:=20CustomException=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 --- .../global/error/exception/CustomException.java | 10 ++++++++++ .../global/error/exception/ErrorCode.java | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java create mode 100644 Server/src/main/java/JGS/CasperEvent/global/error/exception/ErrorCode.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java b/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java new file mode 100644 index 00000000..4c3f653a --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java @@ -0,0 +1,10 @@ +package JGS.CasperEvent.global.error.exception; + +public class CustomException extends RuntimeException{ + private final ErrorCode errorCode; + + public CustomException(String message, ErrorCode errorCode) { + super(message); + this.errorCode = errorCode; + } +} diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/exception/ErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/error/exception/ErrorCode.java new file mode 100644 index 00000000..5f02fc37 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/error/exception/ErrorCode.java @@ -0,0 +1,15 @@ +package JGS.CasperEvent.global.error.exception; + +public enum ErrorCode { + AUTHENTICATION_REQUIRED(401), + ACCESS_DENIED(403), + INTERNAL_SERVER_ERROR(500), + USER_NOT_FOUND(404), + INVALID_REQUEST_ERROR(400); + + private final int status; + + ErrorCode(int status) { + this.status = status; + } +} From 7be3af55d412de57e944780c44c0ecb725330d4f Mon Sep 17 00:00:00 2001 From: k000927 Date: Tue, 30 Jul 2024 17:29:20 +0900 Subject: [PATCH 03/17] =?UTF-8?q?chore:=20@Repository=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=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 --- .../domain/event/repository/AdminRepository.java | 3 +++ .../domain/event/repository/CasperBotRepository.java | 3 +++ .../eventRepository/LotteryEventRepository.java | 7 ++++++- .../eventRepository/RushEventRepository.java | 3 +++ .../eventRepository/RushOptionRepository.java | 3 +++ .../LotteryParticipantsRepository.java | 11 ++++++++++- .../RushParticipantsRepository.java | 3 +++ 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java index 1d464802..dd173c9a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/AdminRepository.java @@ -1,4 +1,7 @@ package JGS.CasperEvent.domain.event.repository; +import org.springframework.stereotype.Repository; + +@Repository public interface AdminRepository { } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java index 02d9f674..cc08098b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java @@ -1,4 +1,7 @@ package JGS.CasperEvent.domain.event.repository; +import org.springframework.stereotype.Repository; + +@Repository public interface CasperBotRepository { } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/LotteryEventRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/LotteryEventRepository.java index 86a1742a..039cf35a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/LotteryEventRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/LotteryEventRepository.java @@ -1,4 +1,9 @@ package JGS.CasperEvent.domain.event.repository.eventRepository; -public interface LotteryEventRepository { +import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface LotteryEventRepository extends JpaRepository { } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushEventRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushEventRepository.java index 451de41d..4e0cacfb 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushEventRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushEventRepository.java @@ -1,4 +1,7 @@ package JGS.CasperEvent.domain.event.repository.eventRepository; +import org.springframework.stereotype.Repository; + +@Repository public interface RushEventRepository { } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushOptionRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushOptionRepository.java index a00cb153..e4e65d12 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushOptionRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/eventRepository/RushOptionRepository.java @@ -1,4 +1,7 @@ package JGS.CasperEvent.domain.event.repository.eventRepository; +import org.springframework.stereotype.Repository; + +@Repository public interface RushOptionRepository { } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java index b164a23e..7aa57454 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/LotteryParticipantsRepository.java @@ -1,4 +1,13 @@ package JGS.CasperEvent.domain.event.repository.participantsRepository; -public interface LotteryParticipantsRepository { +import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface LotteryParticipantsRepository extends JpaRepository { + Optional findByPhoneNumber(String phoneNumber); } + diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java index 737e0961..e4723fe9 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/participantsRepository/RushParticipantsRepository.java @@ -1,4 +1,7 @@ package JGS.CasperEvent.domain.event.repository.participantsRepository; +import org.springframework.stereotype.Repository; + +@Repository public interface RushParticipantsRepository { } From 588cda42ba32c6993223a0442074488f72555a45 Mon Sep 17 00:00:00 2001 From: k000927 Date: Tue, 30 Jul 2024 17:35:25 +0900 Subject: [PATCH 04/17] =?UTF-8?q?chore:=20createdAt=20=EC=9E=91=EB=8F=99?= =?UTF-8?q?=20=EC=9C=84=ED=95=B4=20@EnableJpaAuditing=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/JGS/CasperEvent/CasperEventApplication.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/CasperEventApplication.java b/Server/src/main/java/JGS/CasperEvent/CasperEventApplication.java index 20c02235..1ab48770 100644 --- a/Server/src/main/java/JGS/CasperEvent/CasperEventApplication.java +++ b/Server/src/main/java/JGS/CasperEvent/CasperEventApplication.java @@ -2,9 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) +@SpringBootApplication +@EnableJpaAuditing public class CasperEventApplication { public static void main(String[] args) { From 86b47074251f9651d82926b9d95d3939b3027f81 Mon Sep 17 00:00:00 2001 From: k000927 Date: Tue, 30 Jul 2024 17:36:03 +0900 Subject: [PATCH 05/17] =?UTF-8?q?chore:=20lotteryEvent=EC=99=80=20LotteryP?= =?UTF-8?q?articipants=20=EC=82=AC=EC=9D=B4=EC=9D=98=20=EC=97=B0=EA=B4=80?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/entity/event/LotteryEvent.java | 6 ------ .../participants/LotteryParticipants.java | 17 ++++++++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java index b026deda..4d1e254c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java @@ -1,19 +1,13 @@ package JGS.CasperEvent.domain.event.entity.event; -import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; import jakarta.persistence.*; -import java.util.Set; - @Entity public class LotteryEvent extends BaseEvent { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lotteryEventId; - @OneToMany(mappedBy = "lotteryEvent", cascade = CascadeType.ALL, orphanRemoval = true) - private Set lotteryParticipants; - public Long getLotteryEventId() { return lotteryEventId; } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java index 701d308f..535895e7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java @@ -1,21 +1,24 @@ package JGS.CasperEvent.domain.event.entity.participants; -import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.global.entity.BaseEntity; import jakarta.persistence.Entity; import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; @Entity public class LotteryParticipants extends BaseEntity { private int linkClickedCount; private int expectations; - @ManyToOne - @JoinColumn(name="lottery_event_id") - private LotteryEvent lotteryEvent; - @Id private String phoneNumber; + + public LotteryParticipants() { + + } + + public LotteryParticipants(String phoneNumber){ + this.phoneNumber = phoneNumber; + this.linkClickedCount = 0; + this.expectations = 0; + } } From 7dd8993d1fc2aeffb60b22ca73bfaa38cc34c387 Mon Sep 17 00:00:00 2001 From: k000927 Date: Tue, 30 Jul 2024 17:36:24 +0900 Subject: [PATCH 06/17] =?UTF-8?q?chore:=20=EC=9C=A0=EC=A0=80=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20=EB=8D=94?= =?UTF-8?q?=EB=AF=B8=EB=A9=94=EC=84=9C=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 --- .../main/java/JGS/CasperEvent/global/util/UserUtil.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java b/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java new file mode 100644 index 00000000..ccadeec1 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java @@ -0,0 +1,9 @@ +package JGS.CasperEvent.global.util; + +public class UserUtil { + + //TODO: 현재는 그냥 userData 즉시 반환, 키 이용한 복호화로 수정하기 + public static String getDecodedPhoneNumber(String userData){ + return userData; + } +} From 8ad2bb80f1dafb88060e667f7ced3b52b307e0d5 Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:08:55 +0900 Subject: [PATCH 07/17] =?UTF-8?q?chore:=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 --- .../JGS/CasperEvent/domain/event/entity/event/RushEvent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java index 7a75a782..b1586548 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/RushEvent.java @@ -1,6 +1,6 @@ package JGS.CasperEvent.domain.event.entity.event; -import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import JGS.CasperEvent.domain.event.entity.participants.RushParticipants; import jakarta.persistence.*; import java.util.Set; @@ -23,7 +23,7 @@ public class RushEvent extends BaseEvent { private RushOption rightOption; @OneToMany(mappedBy = "rushEvent", cascade = CascadeType.ALL, orphanRemoval = true) - private Set rushParticipants; + private Set rushParticipants; public String getPrizeImageUrl() { return prizeImageUrl; From 5890833580ed15396b516ea58343acaa03ea8773 Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:09:39 +0900 Subject: [PATCH 08/17] =?UTF-8?q?chore:=20Getter=EC=99=80=20=EC=9D=91?= =?UTF-8?q?=EB=AA=A8=20=ED=9A=9F=EC=88=98=20=EC=A0=80=EC=9E=A5=EC=9A=A9=20?= =?UTF-8?q?=EC=B9=BC=EB=9F=BC=20appliedCount=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/entity/participants/LotteryParticipants.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java index 535895e7..b262f4d9 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/participants/LotteryParticipants.java @@ -8,16 +8,26 @@ public class LotteryParticipants extends BaseEntity { private int linkClickedCount; private int expectations; + private int appliedCount; @Id private String phoneNumber; + public String getPhoneNumber() { + return phoneNumber; + } + public LotteryParticipants() { } + public void expectationAdded(){ + expectations++; + } + public LotteryParticipants(String phoneNumber){ this.phoneNumber = phoneNumber; + this.appliedCount = 1; this.linkClickedCount = 0; this.expectations = 0; } From c2fc4d464a21288fa9c5d3f94f17c78f4161483e Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:11:23 +0900 Subject: [PATCH 09/17] =?UTF-8?q?feat:=20postCasperBot=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20registerUserIfNeed=20=EB=A9=94=EC=84=9C=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 - postCasperBot: 데이터 무결성 검증 및 참가자와 매핑 - registerUserIfNeed: 유저 식별 인코딩 값을 통해 등록된 유저인지를 판단 후 등록되지 않았다면 등록 --- .../eventService/LotteryEventService.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java index 3ae5dc2c..3f5dc94b 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/LotteryEventService.java @@ -2,19 +2,56 @@ import JGS.CasperEvent.domain.event.dto.GetCasperBot; import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; +import JGS.CasperEvent.domain.event.entity.participants.LotteryParticipants; +import JGS.CasperEvent.domain.event.repository.CasperBotRepository; import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; +import JGS.CasperEvent.domain.event.repository.participantsRepository.LotteryParticipantsRepository; +import JGS.CasperEvent.global.error.exception.CustomException; import com.google.gson.Gson; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import static JGS.CasperEvent.global.util.GsonUtil.getGson; +import static JGS.CasperEvent.global.util.UserUtil.getDecodedPhoneNumber; @Service +@Transactional public class LotteryEventService { + + @Autowired private LotteryEventRepository lotteryEventRepository; + @Autowired + private LotteryParticipantsRepository lotteryParticipantsRepository; + @Autowired + private CasperBotRepository casperBotRepository; + + public GetCasperBot postCasperBot(String userData, String body) throws CustomException { + LotteryParticipants participants = registerUserIfNeed(userData); - public GetCasperBot postCasperBot(String body) { Gson gson = getGson(); CasperBot casperBot = gson.fromJson(body, CasperBot.class); + casperBot.validateEnumFields(); + casperBot.updatePhoneNumber(participants.getPhoneNumber()); + + if (casperBot.getEyePosition() != null) participants.expectationAdded(); + + casperBotRepository.save(casperBot); + lotteryParticipantsRepository.save(participants); return GetCasperBot.of(casperBot); } + + public LotteryParticipants registerUserIfNeed(String userData) { + String phoneNumber = getDecodedPhoneNumber(userData); + + LotteryParticipants participants = lotteryParticipantsRepository.findByPhoneNumber(phoneNumber) + .orElse(null); + + if (participants == null) { + participants = new LotteryParticipants(phoneNumber); + lotteryParticipantsRepository.save(participants); + } + + return participants; + } } From 4a52c5089032d0c6bf4828fea9ace01b4d532ded Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:12:03 +0900 Subject: [PATCH 10/17] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20-=20=EC=BF=A0=ED=82=A4=EC=97=90=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=9D=B8=EC=A6=9D=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EA=B0=80=20=EC=97=86=EC=9D=84=20=EB=95=8C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LotteryEventControllerTest.java | 107 ++++++++++++------ 1 file changed, 73 insertions(+), 34 deletions(-) diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 8f89de26..65dc4a2e 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -1,57 +1,55 @@ package JGS.CasperEvent.domain.event.controller.eventController; -import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; -import org.junit.jupiter.api.BeforeEach; +import JGS.CasperEvent.domain.event.service.eventService.LotteryEventService; +import jakarta.servlet.http.Cookie; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.filter.CharacterEncodingFilter; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(controllers = LotteryEvent.class) +@SpringBootTest +@AutoConfigureMockMvc public class LotteryEventControllerTest { @Autowired MockMvc mockMvc; - @BeforeEach - public void setup() { - this.mockMvc = MockMvcBuilders - .standaloneSetup(new LotteryEvent()) - .addFilter(new CharacterEncodingFilter("UTF-8", true)) - .build(); - } + @Autowired + private LotteryEventService lotteryEventService; @Test @DisplayName("캐스퍼 봇 생성 성공 테스트") void createCasperBotSuccessTest() throws Exception { //given - String casperBotRequest = "{" + - "\"eye_shape\": \"2\"," + - "\"eye_position\": \"1\"," + - "\"mouth_shape\": \"4\"," + - "\"color\": \"2\"," + - "\"sticker\": \"4\"," + - "\"name\": \"myCasperBot\"," + - "\"expectation\": \"myExpectation\"" + "}"; + String casperBotRequest = "{\n" + + "\"eyeShape\": \"2\",\n" + + "\"eyePosition\": \"1\",\n" + + "\"mouthShape\": \"4\",\n" + + "\"color\": \"2\",\n" + + "\"sticker\": \"4\",\n" + + "\"name\": \"myCasperBot\",\n" + + "\"expectation\": \"myExpectation\"\n" + "}"; + + Cookie myCookie = new Cookie("userData", "abc"); //when ResultActions perform = mockMvc.perform(post("/event/lottery") .contentType(MediaType.APPLICATION_JSON) - .contentType(casperBotRequest)); + .content(casperBotRequest) + .cookie(myCookie)); //then - perform.andExpect(status().isCreated()) - .andExpect(jsonPath("$.statusCode").value(201)) - .andExpect(jsonPath("$.message").value("생성에 성공하였습니다.")) + perform + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.message").value("생성에 성공했습니다.")) .andExpect(jsonPath("$.result.eyeShape").value("ALLOY_WHEEL_17")) .andExpect(jsonPath("$.result.eyePosition").value("CENTER")) .andExpect(jsonPath("$.result.mouthShape").value("BEAMING")) @@ -63,7 +61,7 @@ void createCasperBotSuccessTest() throws Exception { } @Test - @DisplayName("캐스퍼 봇 생성 실패 테스트입니다. - 필수 필드 없음") + @DisplayName("캐스퍼 봇 생성 실패 테스트 - 필수 필드 없음") void createCasperBotFailureTest_RequiredFieldNotExist() throws Exception { //given String casperBotRequest = "{" + @@ -74,38 +72,79 @@ void createCasperBotFailureTest_RequiredFieldNotExist() throws Exception { "\"sticker\": \"4\"," + "\"expectation\": \"myExpectation\"" + "}"; + Cookie myCookie = new Cookie("userData", "abc"); + //when ResultActions perform = mockMvc.perform(post("/event/lottery") .contentType(MediaType.APPLICATION_JSON) - .contentType(casperBotRequest)); + .content(casperBotRequest) + .cookie(myCookie)); //then perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.message").value("필수 필드가 입력되지 않았습니다.")) + .andExpect(jsonPath("$.message").value("eyeShape cannot be null")) .andDo(print()); } @Test - @DisplayName("캐스퍼 봇 생성 실패 테스트입니다. - 잘못된 값") + @DisplayName("캐스퍼 봇 생성 실패 테스트 - 잘못된 값") void createCasperBotSuccessTest_WrongValue() throws Exception { //given String casperBotRequest = "{" + - "\"eye_shape\": \"15\"," + - "\"eye_position\": \"1\"," + - "\"mouth_shape\": \"4\"," + + "\"eyeShape\": \"15\"," + + "\"eyePosition\": \"1\"," + + "\"mouthShape\": \"4\"," + "\"color\": \"2\"," + "\"sticker\": \"4\"," + "\"name\": \"myCasperBot\"," + "\"expectation\": \"myExpectation\"" + "}"; + Cookie myCookie = new Cookie("userData", "abc"); //when ResultActions perform = mockMvc.perform(post("/event/lottery") .contentType(MediaType.APPLICATION_JSON) - .contentType(casperBotRequest)); + .content(casperBotRequest) + .cookie(myCookie)); //then perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.message").value("잘못된 값이 포함된 요청입니다.")) + .andExpect(jsonPath("$.message").value("eyeShape cannot be null")) + .andDo(print()); + } + + @Test + @DisplayName("캐스퍼 봇 생성 실패 테스트 - 쿠키 없음") + void createCasperBotSuccessTest_CookieNotPresent() throws Exception { + //given + String casperBotRequest = "{" + + "\"eyeShape\": \"1\"," + + "\"eyePosition\": \"1\"," + + "\"mouthShape\": \"4\"," + + "\"color\": \"2\"," + + "\"sticker\": \"4\"," + + "\"name\": \"myCasperBot\"," + + "\"expectation\": \"myExpectation\"" + "}"; + + //when + ResultActions perform = mockMvc.perform(post("/event/lottery") + .contentType(MediaType.APPLICATION_JSON) + .content(casperBotRequest)); + + //then + perform.andExpect(status().isUnauthorized()) + .andExpect(jsonPath("$.message").value("유저 정보가 없습니다.")) .andDo(print()); + + } + + @Test + @DisplayName("캐스퍼 봇 응모 여부 조회 - 성공") + void userHasAppliedCasperBot() { + + //given + + //when + + //then } } \ No newline at end of file From 41ec64281394163e0536611fbd901be012e33d7c Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:12:26 +0900 Subject: [PATCH 11/17] =?UTF-8?q?chore:=20JpaAuditingConfiguration=20confi?= =?UTF-8?q?g=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/configuration/JpaAuditingConfiguration.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/configuration/JpaAuditingConfiguration.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/configuration/JpaAuditingConfiguration.java b/Server/src/main/java/JGS/CasperEvent/global/configuration/JpaAuditingConfiguration.java new file mode 100644 index 00000000..17ba1305 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/configuration/JpaAuditingConfiguration.java @@ -0,0 +1,9 @@ +package JGS.CasperEvent.global.configuration; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@Configuration +@EnableJpaAuditing +public class JpaAuditingConfiguration { +} From 6853da86515fa18bd900709cb11be83780f70c68 Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:12:43 +0900 Subject: [PATCH 12/17] =?UTF-8?q?feat:=20GlobalExceptionHandler=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 --- .../global/error/GlobalExceptionHandler.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java new file mode 100644 index 00000000..2fbe4567 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java @@ -0,0 +1,25 @@ +package JGS.CasperEvent.global.error; + +import JGS.CasperEvent.global.error.exception.CustomException; +import JGS.CasperEvent.global.response.CustomErrorResponse; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MissingRequestCookieException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import static JGS.CasperEvent.global.response.CustomErrorResponse.returnError; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(CustomException.class) + public ResponseEntity handler(CustomException e){ + return new ResponseEntity<>(returnError(e), HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(MissingRequestCookieException.class) + public ResponseEntity missingCookieHandler(MissingRequestCookieException e){ + return new ResponseEntity<>(returnError("유저 정보가 없습니다."), HttpStatus.UNAUTHORIZED); + } +} From 0ebf49bf7e7d37c583e9fc049823c1e6af985f5c Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:13:29 +0900 Subject: [PATCH 13/17] =?UTF-8?q?feat:=20=EC=BA=90=EC=8A=A4=ED=8D=BC=20?= =?UTF-8?q?=EB=B4=87=20=EB=AC=B4=EA=B2=B0=EC=84=B1=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=B0=8F=20phoneNumber=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=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 --- .../event/entity/casperBot/CasperBot.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java index 00a22c4d..06ecbd08 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/casperBot/CasperBot.java @@ -2,8 +2,9 @@ import JGS.CasperEvent.domain.event.entity.casperBot.casperEnum.*; import JGS.CasperEvent.global.entity.BaseEntity; +import JGS.CasperEvent.global.error.exception.CustomException; +import JGS.CasperEvent.global.error.exception.ErrorCode; import com.google.gson.annotations.SerializedName; -import jakarta.annotation.PostConstruct; import jakarta.persistence.*; import static jakarta.persistence.GenerationType.IDENTITY; @@ -75,22 +76,25 @@ public String getExpectation() { return expectation; } - @PostConstruct - public void validateEnumFields() { + public void validateEnumFields() throws CustomException{ if (eyeShape == null) { - throw new IllegalArgumentException("EyeShape cannot be null"); + throw new CustomException("eyeShape cannot be null", ErrorCode.INVALID_REQUEST_ERROR); } if (eyePosition == null) { - throw new IllegalArgumentException("EyePosition cannot be null"); + throw new CustomException("EyePosition cannot be null", ErrorCode.INVALID_REQUEST_ERROR); } if (mouthShape == null) { - throw new IllegalArgumentException("MouthShape cannot be null"); + throw new CustomException("MouthShape cannot be null", ErrorCode.INVALID_REQUEST_ERROR); } if (color == null) { - throw new IllegalArgumentException("Color cannot be null"); + throw new CustomException("Color cannot be null", ErrorCode.INVALID_REQUEST_ERROR); } if (sticker == null) { - throw new IllegalArgumentException("Sticker cannot be null"); + throw new CustomException("Sticker cannot be null", ErrorCode.INVALID_REQUEST_ERROR); } } + + public void updatePhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } } From 7bec1e1c2f8407528916583350c980fb1721a69f Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:13:55 +0900 Subject: [PATCH 14/17] =?UTF-8?q?chore:=20=EB=B0=98=ED=99=98=EA=B0=92=20Re?= =?UTF-8?q?sponseEntity=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 --- .../LotteryEventController.java | 19 ++++++++----------- .../domain/health/api/HealthController.java | 8 ++++++-- .../error/exception/CustomException.java | 6 +++++- .../global/error/exception/ErrorCode.java | 4 ++++ .../global/response/CustomErrorResponse.java | 13 +++++++++++++ .../global/response/CustomResponse.java | 10 +++++++--- 6 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/response/CustomErrorResponse.java diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java index 7e2d6e5f..ebb6d513 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java @@ -4,24 +4,21 @@ import JGS.CasperEvent.domain.event.service.eventService.LotteryEventService; import JGS.CasperEvent.global.response.CustomResponse; import org.springframework.beans.factory.annotation.Autowired; -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 org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/event/lottery") public class LotteryEventController { - private final LotteryEventService lotteryEventService; - @Autowired - public LotteryEventController(LotteryEventService lotteryEventService) { - this.lotteryEventService = lotteryEventService; - } + private LotteryEventService lotteryEventService; @PostMapping - public CustomResponse postCasperBot(@RequestBody String body) { - return CustomResponse.create(lotteryEventService.postCasperBot(body)); + public ResponseEntity> postCasperBot(@CookieValue String userData, + @RequestBody String body) { + + return new ResponseEntity<>(CustomResponse.create(lotteryEventService.postCasperBot(userData, body)), HttpStatus.CREATED); } } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/health/api/HealthController.java b/Server/src/main/java/JGS/CasperEvent/domain/health/api/HealthController.java index d360d32d..745ca347 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/health/api/HealthController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/health/api/HealthController.java @@ -1,16 +1,20 @@ package JGS.CasperEvent.domain.health.api; import JGS.CasperEvent.global.response.CustomResponse; +import org.springframework.http.HttpStatus; +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 static JGS.CasperEvent.global.response.CustomResponse.response; + @RestController @RequestMapping("/health") public class HealthController { @GetMapping - public CustomResponse health(){ - return CustomResponse.success(true); + public ResponseEntity> health(){ + return new ResponseEntity<>(CustomResponse.success(true), HttpStatus.OK); } } diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java b/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java index 4c3f653a..79bcaab5 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/exception/CustomException.java @@ -1,10 +1,14 @@ package JGS.CasperEvent.global.error.exception; -public class CustomException extends RuntimeException{ +public class CustomException extends RuntimeException { private final ErrorCode errorCode; public CustomException(String message, ErrorCode errorCode) { super(message); this.errorCode = errorCode; } + + public ErrorCode getErrorCode() { + return errorCode; + } } diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/exception/ErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/error/exception/ErrorCode.java index 5f02fc37..8787ddfa 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/exception/ErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/exception/ErrorCode.java @@ -12,4 +12,8 @@ public enum ErrorCode { ErrorCode(int status) { this.status = status; } + + public int getStatus(){ + return status; + } } diff --git a/Server/src/main/java/JGS/CasperEvent/global/response/CustomErrorResponse.java b/Server/src/main/java/JGS/CasperEvent/global/response/CustomErrorResponse.java new file mode 100644 index 00000000..e7f2adc0 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/response/CustomErrorResponse.java @@ -0,0 +1,13 @@ +package JGS.CasperEvent.global.response; + +import JGS.CasperEvent.global.error.exception.CustomException; + +public record CustomErrorResponse(String message) { + public static CustomErrorResponse returnError(CustomException e){ + return new CustomErrorResponse(e.getMessage()); + } + + public static CustomErrorResponse returnError(String message){ + return new CustomErrorResponse(message); + } +} \ No newline at end of file diff --git a/Server/src/main/java/JGS/CasperEvent/global/response/CustomResponse.java b/Server/src/main/java/JGS/CasperEvent/global/response/CustomResponse.java index 24263ad7..806299e3 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/response/CustomResponse.java +++ b/Server/src/main/java/JGS/CasperEvent/global/response/CustomResponse.java @@ -1,12 +1,16 @@ package JGS.CasperEvent.global.response; -public record CustomResponse (int statusCode, String message, T result){ +public record CustomResponse(String message, T result) { + public static CustomResponse response(String message, T result) { + return new CustomResponse<>(message, result); + } + public static CustomResponse success(T result){ - return new CustomResponse<>(200, "요청에 성공하였습니다.", result); + return new CustomResponse<>("요청에 성공했습니다.", result); } public static CustomResponse create(T result){ - return new CustomResponse<>(201, "생성에 성공하였습니다", result); + return new CustomResponse<>("생성에 성공했습니다.", result); } } From 71b9e1b1ffc046e41662c71b4db510784e620062 Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:14:10 +0900 Subject: [PATCH 15/17] =?UTF-8?q?chore:=20=EC=82=AC=EC=86=8C=ED=95=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 --- .../main/java/JGS/CasperEvent/CasperEventApplication.java | 2 -- .../domain/event/repository/CasperBotRepository.java | 4 +++- .../java/JGS/CasperEvent/CasperEventApplicationTests.java | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/CasperEventApplication.java b/Server/src/main/java/JGS/CasperEvent/CasperEventApplication.java index 1ab48770..0c439005 100644 --- a/Server/src/main/java/JGS/CasperEvent/CasperEventApplication.java +++ b/Server/src/main/java/JGS/CasperEvent/CasperEventApplication.java @@ -2,10 +2,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication -@EnableJpaAuditing public class CasperEventApplication { public static void main(String[] args) { diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java index cc08098b..c96afd56 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/repository/CasperBotRepository.java @@ -1,7 +1,9 @@ package JGS.CasperEvent.domain.event.repository; +import JGS.CasperEvent.domain.event.entity.casperBot.CasperBot; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface CasperBotRepository { +public interface CasperBotRepository extends JpaRepository { } diff --git a/Server/src/test/java/JGS/CasperEvent/CasperEventApplicationTests.java b/Server/src/test/java/JGS/CasperEvent/CasperEventApplicationTests.java index add233cb..26425399 100644 --- a/Server/src/test/java/JGS/CasperEvent/CasperEventApplicationTests.java +++ b/Server/src/test/java/JGS/CasperEvent/CasperEventApplicationTests.java @@ -11,6 +11,7 @@ import org.springframework.web.filter.CharacterEncodingFilter; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @WebMvcTest(HealthController.class) @@ -32,8 +33,9 @@ public void setup(){ void HealthTest() throws Exception { mockMvc.perform(get("/health")) .andExpect(status().isOk()) - .andExpect(jsonPath("$.statusCode").value(200)) - .andExpect(jsonPath("$.result").value(true)); + .andExpect(jsonPath("$.message").value("요청에 성공하였습니다.")) + .andExpect(jsonPath("$.result").value(true)) + .andDo(print()); } } From da87a203a98e449a72c127e940631af7fcec4da0 Mon Sep 17 00:00:00 2001 From: k000927 Date: Wed, 31 Jul 2024 15:18:18 +0900 Subject: [PATCH 16/17] =?UTF-8?q?chore:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=ED=85=8D=EC=8A=A4=ED=8A=B8=EB=B8=94?= =?UTF-8?q?=EB=A1=9D=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 --- .../LotteryEventController.java | 1 - .../domain/health/api/HealthController.java | 2 - .../LotteryEventControllerTest.java | 72 +++++++++++-------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java index ebb6d513..86e9d9fd 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventController.java @@ -18,7 +18,6 @@ public class LotteryEventController { @PostMapping public ResponseEntity> postCasperBot(@CookieValue String userData, @RequestBody String body) { - return new ResponseEntity<>(CustomResponse.create(lotteryEventService.postCasperBot(userData, body)), HttpStatus.CREATED); } } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/health/api/HealthController.java b/Server/src/main/java/JGS/CasperEvent/domain/health/api/HealthController.java index 745ca347..6e6ed520 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/health/api/HealthController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/health/api/HealthController.java @@ -7,8 +7,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import static JGS.CasperEvent.global.response.CustomResponse.response; - @RestController @RequestMapping("/health") public class HealthController { diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 65dc4a2e..c48349f7 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -29,14 +29,16 @@ public class LotteryEventControllerTest { @DisplayName("캐스퍼 봇 생성 성공 테스트") void createCasperBotSuccessTest() throws Exception { //given - String casperBotRequest = "{\n" + - "\"eyeShape\": \"2\",\n" + - "\"eyePosition\": \"1\",\n" + - "\"mouthShape\": \"4\",\n" + - "\"color\": \"2\",\n" + - "\"sticker\": \"4\",\n" + - "\"name\": \"myCasperBot\",\n" + - "\"expectation\": \"myExpectation\"\n" + "}"; + String casperBotRequest = """ + { + "eyeShape": "2", + "eyePosition": "1", + "mouthShape": "4", + "color": "2", + "sticker": "4", + "name": "myCasperBot", + "expectation": "myExpectation" + }"""; Cookie myCookie = new Cookie("userData", "abc"); @@ -64,13 +66,16 @@ void createCasperBotSuccessTest() throws Exception { @DisplayName("캐스퍼 봇 생성 실패 테스트 - 필수 필드 없음") void createCasperBotFailureTest_RequiredFieldNotExist() throws Exception { //given - String casperBotRequest = "{" + - "\"eye_shape\": \"2\"," + - "\"eye_position\": \"1\"," + - "\"mouth_shape\": \"4\"," + - "\"color\": \"2\"," + - "\"sticker\": \"4\"," + - "\"expectation\": \"myExpectation\"" + "}"; + String casperBotRequest = """ + { + "eye_shape": "2", + "eye_position": "1", + "mouth_shape": "4", + "color": "2", + "sticker": "4", + "expectation": "myExpectation" + } + """; Cookie myCookie = new Cookie("userData", "abc"); @@ -90,14 +95,16 @@ void createCasperBotFailureTest_RequiredFieldNotExist() throws Exception { @DisplayName("캐스퍼 봇 생성 실패 테스트 - 잘못된 값") void createCasperBotSuccessTest_WrongValue() throws Exception { //given - String casperBotRequest = "{" + - "\"eyeShape\": \"15\"," + - "\"eyePosition\": \"1\"," + - "\"mouthShape\": \"4\"," + - "\"color\": \"2\"," + - "\"sticker\": \"4\"," + - "\"name\": \"myCasperBot\"," + - "\"expectation\": \"myExpectation\"" + "}"; + String casperBotRequest = """ + { + "eyeShape": "15", + "eyePosition": "1", + "mouthShape": "4", + "color": "2", + "sticker": "4", + "name": "myCasperBot", + "expectation": "myExpectation" + }"""; Cookie myCookie = new Cookie("userData", "abc"); //when @@ -116,14 +123,17 @@ void createCasperBotSuccessTest_WrongValue() throws Exception { @DisplayName("캐스퍼 봇 생성 실패 테스트 - 쿠키 없음") void createCasperBotSuccessTest_CookieNotPresent() throws Exception { //given - String casperBotRequest = "{" + - "\"eyeShape\": \"1\"," + - "\"eyePosition\": \"1\"," + - "\"mouthShape\": \"4\"," + - "\"color\": \"2\"," + - "\"sticker\": \"4\"," + - "\"name\": \"myCasperBot\"," + - "\"expectation\": \"myExpectation\"" + "}"; + String casperBotRequest = """ + { + "eyeShape": "1", + "eyePosition": "1", + "mouthShape": "4", + "color": "2", + "sticker": "4", + "name": "myCasperBot", + "expectation": "myExpectation" + } + """; //when ResultActions perform = mockMvc.perform(post("/event/lottery") From e7cfc0bfbf63f79dd9d826ec6046d0cc223936de Mon Sep 17 00:00:00 2001 From: k000927 Date: Tue, 30 Jul 2024 17:36:24 +0900 Subject: [PATCH 17/17] =?UTF-8?q?chore:=20=EC=9C=A0=EC=A0=80=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B0=98=ED=99=98=ED=95=98=EB=8A=94=20=EB=8D=94?= =?UTF-8?q?=EB=AF=B8=EB=A9=94=EC=84=9C=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 --- .../main/java/JGS/CasperEvent/global/util/UserUtil.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java diff --git a/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java b/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java new file mode 100644 index 00000000..ccadeec1 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/global/util/UserUtil.java @@ -0,0 +1,9 @@ +package JGS.CasperEvent.global.util; + +public class UserUtil { + + //TODO: 현재는 그냥 userData 즉시 반환, 키 이용한 복호화로 수정하기 + public static String getDecodedPhoneNumber(String userData){ + return userData; + } +}