From 2f48a045ff08e697e2ac7c0e14d9d81377d1abcf Mon Sep 17 00:00:00 2001 From: mac <20j.code@gmail.com> Date: Tue, 6 Aug 2024 14:37:17 +0900 Subject: [PATCH 1/5] =?UTF-8?q?docs=20:=20step3=20=EB=AC=B8=EC=84=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 --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ebbff580..e60301fa9 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,10 @@ 2. 서비스 필요 DTO 추가 3. 서비스 필요 컨트롤러 추가 -4. 카카오 메세지 전송 서비스 추가 \ No newline at end of file +4. 카카오 메세지 전송 서비스 추가 + +## step3 + +1. 사용자 포인트 엔티티 추가 +2. 포인트 서비스 추가 +3. 관리자 포인트 충전 추가 From 06de9de0f250dd17aaaad7513c99290e89cdce74 Mon Sep 17 00:00:00 2001 From: mac <20j.code@gmail.com> Date: Tue, 6 Aug 2024 14:43:17 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat=20:=20point=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=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/gift/member/entity/Member.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/gift/member/entity/Member.java b/src/main/java/gift/member/entity/Member.java index 853aba950..d4609fe7e 100644 --- a/src/main/java/gift/member/entity/Member.java +++ b/src/main/java/gift/member/entity/Member.java @@ -36,11 +36,16 @@ public class Member { @OneToMany(mappedBy = "member") private List wishList = new ArrayList<>(); - public Member(Long id, String email, String password, MemberRole role) { + @Column(name="MEMBER_POINT") + private Integer point; + + public Member(Long id, String email, String password, MemberRole role, Integer point) { this.id = id; this.email = email; this.password = password; this.role = role; + this.point = point; + } public Member() { From 06ce25637c29e69ab3457917295cd010a9f38ef1 Mon Sep 17 00:00:00 2001 From: mac <20j.code@gmail.com> Date: Tue, 6 Aug 2024 14:43:47 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor=20:=20member=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=82=AC=ED=95=AD=20=EB=A7=9E=EC=B6=B0=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/gift/member/service/MemberService.java | 2 +- src/test/java/gift/service/WishListServiceTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/gift/member/service/MemberService.java b/src/main/java/gift/member/service/MemberService.java index fc30c151d..0a72e53fd 100644 --- a/src/main/java/gift/member/service/MemberService.java +++ b/src/main/java/gift/member/service/MemberService.java @@ -30,7 +30,7 @@ public void register(MemberRequest memberRequest) { throw new GiftUnauthorizedException("사용할 수 없는 이메일입니다."); } Member member = new Member(null, memberRequest.getEmail(), memberRequest.getPassword(), - memberRequest.getRole()); + memberRequest.getRole(), 0); jpaMemberRepository.save(member); } diff --git a/src/test/java/gift/service/WishListServiceTest.java b/src/test/java/gift/service/WishListServiceTest.java index 7abef69fc..62ec2cebf 100644 --- a/src/test/java/gift/service/WishListServiceTest.java +++ b/src/test/java/gift/service/WishListServiceTest.java @@ -28,7 +28,7 @@ class WishListServiceTest { @DisplayName("새로운 상품 목록 추가") void addProduct(){ //given - Member member = new Member(null,"hah@ha","1234", MemberRole.COMMON_MEMBER); + Member member = new Member(null,"hah@ha","1234", MemberRole.COMMON_MEMBER,0); Product product = new Product(null,"tuna",4000, "test"); member = jpaMemberRepository.save(member); @@ -49,7 +49,7 @@ void addProduct(){ @DisplayName("새로운 상품 여러개 추가") void addMultiProduct(){ //given - Member member = new Member(null,"hah@ha","1234", MemberRole.COMMON_MEMBER); + Member member = new Member(null,"hah@ha","1234", MemberRole.COMMON_MEMBER,0); Product product = new Product(null,"tuna",4000, "test"); Product product2 = new Product(null,"tuna2",5000, "test2"); Product product3 = new Product(null,"tuna3",6000, "test3"); From 27f56eab4e34010e3e3cb6116d9425a1086178c3 Mon Sep 17 00:00:00 2001 From: mac <20j.code@gmail.com> Date: Tue, 6 Aug 2024 14:57:44 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat=20:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=20=EC=A3=BC=EB=AC=B8=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/gift/member/entity/Member.java | 15 +++++++++++++++ .../java/gift/order/service/OrderService.java | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/gift/member/entity/Member.java b/src/main/java/gift/member/entity/Member.java index d4609fe7e..491bface8 100644 --- a/src/main/java/gift/member/entity/Member.java +++ b/src/main/java/gift/member/entity/Member.java @@ -83,4 +83,19 @@ public List getWishList() { return wishList; } + public Integer getPoint() { + return point; + } + + public void usePoint(Integer point) { + this.point -= point; + if(this.point < 0){ + this.point = 0; + } + } + + public void useAllPoint(){ + this.point = 0; + } + } diff --git a/src/main/java/gift/order/service/OrderService.java b/src/main/java/gift/order/service/OrderService.java index 2805f8537..90e8362e9 100644 --- a/src/main/java/gift/order/service/OrderService.java +++ b/src/main/java/gift/order/service/OrderService.java @@ -52,5 +52,18 @@ public void create(OrderRequest orderRequest) { jpaWishRepository.deleteByMemberIdAndProductId(member.getId(), product.getId()); } + usePoint(product.getPrice()*orderRequest.getQuantity(),member); + + } + + private int usePoint(int price, Member member){ + int memberPoint = member.getPoint(); + + if(memberPoint < price){ + member.useAllPoint(); + return price - memberPoint; + } + member.usePoint(price); + return 0; } } From e079b81b234f4b3314fbd381f84cdbde5b0f1bb5 Mon Sep 17 00:00:00 2001 From: mac <20j.code@gmail.com> Date: Tue, 6 Aug 2024 15:17:39 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat=20:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=EC=9E=90=ED=8E=98=EC=9D=B4=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 --- .../controller/AdminProductController.java | 14 +++++++ .../java/gift/admin/dto/LeafMemberDTO.java | 41 +++++++++++++++++++ .../java/gift/member/dto/MemberRequest.java | 7 ++++ 3 files changed, 62 insertions(+) create mode 100644 src/main/java/gift/admin/dto/LeafMemberDTO.java diff --git a/src/main/java/gift/admin/controller/AdminProductController.java b/src/main/java/gift/admin/controller/AdminProductController.java index c9cffbb5b..31c1b72e3 100644 --- a/src/main/java/gift/admin/controller/AdminProductController.java +++ b/src/main/java/gift/admin/controller/AdminProductController.java @@ -1,7 +1,11 @@ package gift.admin.controller; +import gift.admin.dto.LeafMemberDTO; import gift.admin.dto.LeafProductDTO; +import gift.auth.argumentResolver.KakaoMember; +import gift.member.dto.MemberRequest; import gift.product.dto.ProductRequest; +import gift.product.entity.Product; import gift.product.service.ProductService; import jakarta.validation.Valid; import org.springframework.stereotype.Controller; @@ -69,10 +73,20 @@ public String deletePageSubmit(@PathVariable Long id) { return "redirect:/admin/products"; } + @PostMapping("/member") + public String addPoint(@PathVariable Long id, @KakaoMember String token,@ModelAttribute("leafMemberDTO") LeafMemberDTO leafMemberDTO) { + MemberRequest memberRequest = toRestRequest(leafMemberDTO); + return "redirect:/admin/products"; + } + private ProductRequest toRestRequest(LeafProductDTO leafProductDTO) { return new ProductRequest(leafProductDTO.getId(), leafProductDTO.getName(), leafProductDTO.getPrice(), leafProductDTO.getImageUrl(), leafProductDTO.getCategoryId(), leafProductDTO.getGiftOptionName(), leafProductDTO.getGiftOptionQuantity()); } + private MemberRequest toRestRequest(LeafMemberDTO leafMemberDTO) { + return new MemberRequest(leafMemberDTO.getId(), leafMemberDTO.getEmail(), leafMemberDTO.getPoint()); + } + } diff --git a/src/main/java/gift/admin/dto/LeafMemberDTO.java b/src/main/java/gift/admin/dto/LeafMemberDTO.java new file mode 100644 index 000000000..48d638938 --- /dev/null +++ b/src/main/java/gift/admin/dto/LeafMemberDTO.java @@ -0,0 +1,41 @@ +package gift.admin.dto; + +public class LeafMemberDTO { + + private Long id; + private String email; + private Integer point; + + public LeafMemberDTO() { + } + + public LeafMemberDTO(Long id, String email, Integer point) { + this.id = id; + this.email = email; + this.point = point; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Integer getPoint() { + return point; + } + + public void setPoint(Integer point) { + this.point = point; + } +} diff --git a/src/main/java/gift/member/dto/MemberRequest.java b/src/main/java/gift/member/dto/MemberRequest.java index 7a0fcaab1..58f627304 100644 --- a/src/main/java/gift/member/dto/MemberRequest.java +++ b/src/main/java/gift/member/dto/MemberRequest.java @@ -11,6 +11,7 @@ public class MemberRequest { @NotBlank(message = "비밀번호를 입력해주세요") private String password; private MemberRole role; + private Integer point; public MemberRequest() { } @@ -31,6 +32,12 @@ public MemberRequest(Long id, String email, String password, MemberRole role) { this.role = role; } + public MemberRequest(Long id, String email, Integer point) { + this.id = id; + this.email = email; + this.point = point; + } + public Long getId() { return id; }