-
Notifications
You must be signed in to change notification settings - Fork 0
[UPLUS-57] 할인 추가삭제 기능 추가/developer브랜치와 병합 및 오류 수정 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,68 @@ | ||
| package com.project.core.controller; | ||
|
|
||
| import com.project.core.controller.dto.request.FindCustomerRequest; | ||
| import java.util.List; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
|
|
||
| import com.project.core.controller.dto.request.ChangeEmailRequest; | ||
| import com.project.core.controller.dto.request.ChangeGradeRequest; | ||
| import com.project.core.controller.dto.response.ChangeEmailResponse; | ||
| import com.project.core.controller.dto.response.ChangeGradeResponse; | ||
| import com.project.core.infra.entity.customer.Customer; | ||
| import com.project.core.service.CustomerService; | ||
| 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.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
|
|
||
|
|
||
| @RestController | ||
| @RequestMapping("/user") | ||
| @RequiredArgsConstructor | ||
| public class CustomerController { | ||
| private final CustomerService customerService; | ||
| private final CustomerService customerService; | ||
|
|
||
| /** | ||
| * 고객 조회 (전화번호 기준) | ||
| */ | ||
| @GetMapping | ||
| public ResponseEntity<List<Customer>> loadByContactEnc( | ||
| @RequestParam String contactEnc | ||
| ) { | ||
| List<Customer> customers = customerService.loadByContactEnc(contactEnc); | ||
| return ResponseEntity.ok(customers); | ||
| } | ||
|
|
||
| /** | ||
| * 이메일 변경 | ||
| * @throws Exception | ||
| */ | ||
| @PostMapping("/{userId}/email") | ||
| public ResponseEntity<ChangeEmailResponse> changeEmail( | ||
| @PathVariable Long userId, | ||
| @RequestBody ChangeEmailRequest request | ||
| ) throws Exception { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ChangeEmailResponse response = | ||
| customerService.changeEmailEnc(userId, request); | ||
| return ResponseEntity.ok(response); | ||
| } | ||
|
|
||
| /** | ||
| * 고객 등급 변경 | ||
| */ | ||
| @PostMapping("/{userId}/grade") | ||
| public ResponseEntity<ChangeGradeResponse> changeGrade( | ||
| @PathVariable Long userId, | ||
| @RequestBody ChangeGradeRequest request | ||
| ) { | ||
| ChangeGradeResponse response = | ||
| customerService.changeUserGrade(userId, request); | ||
| return ResponseEntity.ok(response); | ||
| } | ||
|
|
||
| @GetMapping | ||
| public Long save(@RequestBody FindCustomerRequest request) { | ||
| Customer customer = customerService.loadByContactEnc(request.contactEnc()); | ||
| return customer.getCustomerId(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||
| package com.project.core.infra.entity.discount; | ||||||||||
|
|
||||||||||
| import java.util.ArrayList; | ||||||||||
| import java.util.List; | ||||||||||
|
|
||||||||||
| import com.project.core.infra.entity.discount.enums.Active; | ||||||||||
| import com.project.core.infra.entity.discount.enums.Category; | ||||||||||
| import com.project.core.infra.entity.discount.enums.DiscountType; | ||||||||||
| import com.project.core.infra.entity.discount.enums.TargetScope; | ||||||||||
|
|
||||||||||
| import jakarta.persistence.CascadeType; | ||||||||||
| import jakarta.persistence.Column; | ||||||||||
| import jakarta.persistence.Entity; | ||||||||||
| import jakarta.persistence.GeneratedValue; | ||||||||||
| import jakarta.persistence.GenerationType; | ||||||||||
| import jakarta.persistence.Id; | ||||||||||
| import jakarta.persistence.OneToMany; | ||||||||||
| import jakarta.persistence.Table; | ||||||||||
| import lombok.AccessLevel; | ||||||||||
| import lombok.Getter; | ||||||||||
| import lombok.NoArgsConstructor; | ||||||||||
|
|
||||||||||
| @Entity | ||||||||||
| @Getter | ||||||||||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||||||||||
| @Table(name = "discount_policy") | ||||||||||
| public class DiscountPolicy { | ||||||||||
| @Id | ||||||||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||||||||||
| @Column(name = "discount_id") | ||||||||||
| private Long discountId; | ||||||||||
|
|
||||||||||
| @Column(name = "name", nullable = false) | ||||||||||
| private String name; | ||||||||||
|
|
||||||||||
| @Column(name = "discount_type", nullable = false) | ||||||||||
| private DiscountType discountType; | ||||||||||
|
|
||||||||||
| @Column(name = "value", nullable = false) | ||||||||||
| private Double value; | ||||||||||
|
Comment on lines
+39
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 금액이나 비율과 같은 값을
Suggested change
|
||||||||||
|
|
||||||||||
| @Column(name = "category", nullable = false) | ||||||||||
| private Category category; | ||||||||||
|
|
||||||||||
| @Column(name = "target_scope", nullable = false) | ||||||||||
| private TargetScope targetScope; | ||||||||||
|
|
||||||||||
| @Column(name = "active", nullable = false) | ||||||||||
| private Active active; | ||||||||||
| //------------------------------------------------------------------ | ||||||||||
| @OneToMany(mappedBy = "discountPolicy", cascade = CascadeType.ALL) | ||||||||||
| private List<SubscriptionDiscount> discountHistory = new ArrayList<>(); | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package com.project.core.infra.entity.discount; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import com.project.core.infra.entity.discount.enums.DiscountType; | ||
| import com.project.core.infra.entity.discount.enums.Status; | ||
| import com.project.core.infra.entity.discount.enums.TargetScope; | ||
| import com.project.core.infra.entity.subscription.Subscription; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.FetchType; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table(name = "subscription_discount") | ||
| public class SubscriptionDiscount { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "sd_id") | ||
| private Long sdId; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "discount_id", nullable = false) | ||
| private DiscountPolicy discountPolicy; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "sub_id", nullable = false) | ||
| private Subscription subscription; | ||
|
|
||
| @Column(name = "discount_type", nullable = false) | ||
| private DiscountType discountType; | ||
|
|
||
| @Column(name = "value", nullable = false) | ||
| private Double value; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| @Column(name = "target_scope", nullable = false) | ||
| private TargetScope targetScope; | ||
|
|
||
| @Column(name = "start_date", nullable = false) | ||
| private LocalDateTime startDate; | ||
|
|
||
| @Column(name = "end_date") | ||
| private LocalDateTime endDate; | ||
|
|
||
| @Column(name = "status", nullable = false) | ||
| private Status status; | ||
|
|
||
| public void setEndDate(LocalDateTime endDate) { | ||
| this.endDate = endDate; | ||
| } | ||
| public void setStatusTerminated() { | ||
| this.status = Status.TERMINATED; | ||
| } | ||
|
|
||
| @Builder | ||
| private SubscriptionDiscount( | ||
| DiscountPolicy discountPolicy, | ||
| Subscription subscription, | ||
| DiscountType discountType, | ||
| Double value, | ||
| TargetScope targetScope, | ||
| LocalDateTime startDate | ||
| ) { | ||
| if (discountPolicy == null) throw new IllegalArgumentException("discountPolicy는 필수입니다."); | ||
| if (subscription == null) throw new IllegalArgumentException("subscription은 필수입니다."); | ||
| if (discountType == null) throw new IllegalArgumentException("discountType는 필수입니다."); | ||
| if (value == null) throw new IllegalArgumentException("value는 필수입니다."); | ||
| if (targetScope == null) throw new IllegalArgumentException("targetScope는 필수입니다."); | ||
|
|
||
| this.discountPolicy = discountPolicy; | ||
| this.subscription = subscription; | ||
| this.discountType = discountType; | ||
| this.value = value; | ||
| this.targetScope = targetScope; | ||
| this.startDate = startDate != null ? startDate : LocalDateTime.now(); | ||
|
|
||
| // 기본값 | ||
| this.endDate = null; | ||
| this.status = Status.ACTIVE; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.project.core.infra.entity.discount.enums; | ||
|
|
||
| public enum Active { | ||
| ACTIVE | ||
| ,INACTIVE | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.project.core.infra.entity.discount.enums; | ||
|
|
||
| public enum Category { | ||
| 복지 | ||
| ,프로모션 | ||
| ,결합 | ||
|
Comment on lines
+4
to
+6
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.project.core.infra.entity.discount.enums; | ||
|
|
||
| public enum DiscountType { | ||
| Rate | ||
| ,Fixed | ||
|
Comment on lines
+4
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.project.core.infra.entity.discount.enums; | ||
|
|
||
| public enum Status { | ||
| ACTIVE | ||
| ,TERMINATED | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.project.core.infra.entity.discount.enums; | ||
|
|
||
| public enum TargetScope { | ||
| PLAN_FEE | ||
| ,TOTAL_AMOUNT | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,4 +73,8 @@ public void terminate(Clock clock) { | |
| this.status = SubscriptionStatus.TERMINATED; | ||
| this.endDate = LocalDateTime.now(clock); | ||
| } | ||
| } | ||
|
|
||
| public void setPhoneNumber(String maskedNum) { | ||
| this.phoneNumber = maskedNum; | ||
| } | ||
|
Comment on lines
+77
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| package com.project.core.infra.repository.customer; | ||
|
|
||
| import java.util.List; | ||
| import com.project.core.infra.entity.customer.Customer; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface CustomerRepository extends JpaRepository<Customer, Long> { | ||
| Optional<Customer> findByContactEnc(String contactEnc); | ||
| List<Customer> findByContactEnc(String contactEnc); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.project.core.infra.repository.discount; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import com.project.core.infra.entity.discount.DiscountPolicy; | ||
|
|
||
| public interface DiscountPolicyRepository extends JpaRepository<DiscountPolicy, Long> { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.project.core.infra.repository.discount; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import com.project.core.infra.entity.discount.SubscriptionDiscount; | ||
|
|
||
| public interface SubscriptionDiscountRepository extends JpaRepository<SubscriptionDiscount, Long> { | ||
| List<SubscriptionDiscount> findBySubscription_SubId(Long subId); | ||
| Optional<SubscriptionDiscount> findBySdId(Long sdId); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
컨트롤러에서 JPA 엔티티(
Customer)를 직접 반환하고 있습니다. 이는 다음과 같은 문제를 야기할 수 있습니다.Customer엔티티의 정보를 담는 별도의 DTO(e.g.,CustomerResponseDto)를 생성하고, 엔티티를 DTO로 변환하여 반환하도록 수정하는 것이 좋습니다.