From 00bc58a76d5b2d35efb230c72ce4d7c55f62dff5 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 02:02:03 +0900 Subject: [PATCH 01/45] =?UTF-8?q?#106=20fix:=20=ED=99=98=EB=B6=88=20?= =?UTF-8?q?=EA=B0=80=EB=8A=A5=ED=95=9C=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20-?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=EA=B2=B0=EC=A0=9C=20=EC=99=84=EB=A3=8C?= =?UTF-8?q?=EC=9D=B8=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=EB=A7=8C=20=ED=95=A9?= =?UTF-8?q?=EC=82=B0=ED=95=98=EB=A9=B4=20totalPointBalance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/PointChargesCustomRepository.java | 2 +- .../repository/PointChargesCustomRepositoryImpl.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java index 2df00706..8db2a78d 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java @@ -7,7 +7,7 @@ public interface PointChargesCustomRepository { - Long sumChargePointByRefundable(Point point); + Long sumChargePointByPaidStatus(Point point); List findByPointAndRefundableAndRangeDate(Point point, YearMonth rangeDate); diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java index b3c0f918..c4a88efa 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java @@ -2,6 +2,7 @@ import com.backoffice.upjuyanolja.domain.point.entity.Point; import com.backoffice.upjuyanolja.domain.point.entity.PointCharges; +import com.backoffice.upjuyanolja.domain.point.entity.PointStatus; import com.backoffice.upjuyanolja.domain.point.entity.QPointCharges; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -18,10 +19,10 @@ public class PointChargesCustomRepositoryImpl implements PointChargesCustomRepos private final QPointCharges qPointCharges = QPointCharges.pointCharges; @Override - public Long sumChargePointByRefundable(Point point) { + public Long sumChargePointByPaidStatus(Point point) { return query.select(qPointCharges.chargePoint.sum()) .from(qPointCharges) - .where(isPointRefundable(point)) + .where(isPointPaidStatus(point)) .fetchFirst(); } @@ -37,15 +38,15 @@ private List getPointCharges( Point point, YearMonth rangeDate ) { return query.selectFrom(qPointCharges) - .where(isPointRefundable(point) + .where(isPointPaidStatus(point) .and(eqChargeDate(rangeDate)) ) .fetch(); } - private BooleanExpression isPointRefundable(Point point) { + private BooleanExpression isPointPaidStatus(Point point) { return qPointCharges.point.eq(point) - .and(qPointCharges.refundable.isTrue()); + .and(qPointCharges.pointStatus.eq(PointStatus.PAID)); } private BooleanExpression eqChargeDate(YearMonth rangeDate) { From 653761e145a2f05ab922146c14df32566e493405 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 03:15:18 +0900 Subject: [PATCH 02/45] =?UTF-8?q?#177=20refactor:=20pointRefunds=EC=99=80?= =?UTF-8?q?=20pintUsage=EB=8A=94=20Point=20=EA=B0=9D=EC=B2=B4=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20id=EB=A7=8C=20=EA=B0=80=EC=A7=80=EB=8F=84=EB=A1=9D?= =?UTF-8?q?=20=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/entity/PointRefunds.java | 9 ++++---- .../domain/point/entity/PointUsage.java | 21 ++++++++++++------- .../PointUsageCustomRepositoryImpl.java | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointRefunds.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointRefunds.java index 1770fa78..88f4bf6e 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointRefunds.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointRefunds.java @@ -32,10 +32,9 @@ public class PointRefunds extends BaseTime { @Comment("환불 일시") private LocalDateTime refundDate; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "point_id") + @Column(nullable = false) @Comment("포인트 식별자") - private Point point; + private Long pointId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "point_charges_id") @@ -46,12 +45,12 @@ public class PointRefunds extends BaseTime { public PointRefunds( Long id, LocalDateTime refundDate, - Point point, + Long pointId, PointCharges pointCharges ) { this.id = id; this.refundDate = refundDate; - this.point = point; + this.pointId = pointId; this.pointCharges = pointCharges; } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java index becba448..19df41c6 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java @@ -1,10 +1,9 @@ package com.backoffice.upjuyanolja.domain.point.entity; +import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation; import com.backoffice.upjuyanolja.global.common.entity.BaseTime; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -40,30 +39,36 @@ public class PointUsage extends BaseTime { @Comment("주문 금액") private long orderPrice; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "point_id") + @Column(nullable = false) @Comment("포인트 식별자") - private Point point; + private Long pointId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "point_charges_id") @Comment("포인트 충전 식별자") private PointCharges pointCharges; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "accommodation_id") + private Accommodation accommodation; + + @Builder public PointUsage( Long id, String orderName, LocalDateTime orderDate, long orderPrice, - Point point, - PointCharges pointcharges + Long pointId, + PointCharges pointcharges, + Accommodation accommodation ) { this.id = id; this.orderName = orderName; this.orderDate = orderDate; this.orderPrice = orderPrice; - this.point = point; + this.pointId = pointId; this.pointCharges = pointcharges; + this.accommodation = accommodation; } } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageCustomRepositoryImpl.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageCustomRepositoryImpl.java index c705b254..7e9ef760 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageCustomRepositoryImpl.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageCustomRepositoryImpl.java @@ -29,7 +29,7 @@ private List getPointUsages( Point point, YearMonth rangeDate ) { return query.selectFrom(qPointUsage) - .where(qPointUsage.point.eq(point) + .where(qPointUsage.pointId.eq(point.getId()) .and(eqChargeDate(rangeDate)) ) .fetch(); From 1e2b1246add6fe60992c91b45ecadf09b22c5bcb Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 03:58:31 +0900 Subject: [PATCH 03/45] =?UTF-8?q?#177=20refactor:=20PointUsage=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=EC=97=90=EC=84=9C=20=EA=B0=92=EC=9D=B4=20?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=ED=95=84=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../upjuyanolja/domain/point/entity/PointUsage.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java index 19df41c6..ceb5e288 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java @@ -27,10 +27,6 @@ public class PointUsage extends BaseTime { @Comment("포인트 사용 식별자") private Long id; - @Column(nullable = false) - @Comment("주문 이름") - private String orderName; - @Column(nullable = false) @Comment("주문 일시") private LocalDateTime orderDate; @@ -56,7 +52,6 @@ public class PointUsage extends BaseTime { @Builder public PointUsage( Long id, - String orderName, LocalDateTime orderDate, long orderPrice, Long pointId, @@ -64,7 +59,6 @@ public PointUsage( Accommodation accommodation ) { this.id = id; - this.orderName = orderName; this.orderDate = orderDate; this.orderPrice = orderPrice; this.pointId = pointId; From 0f0c1ba3eee4abbb89258d083c8ef2a9d047c87b Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 04:04:02 +0900 Subject: [PATCH 04/45] =?UTF-8?q?#177=20refactor:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=97=94=ED=84=B0=ED=8B=B0=EA=B0=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backoffice/upjuyanolja/domain/point/entity/Point.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/Point.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/Point.java index dbbc519e..21d7f9d1 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/Point.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/Point.java @@ -1,6 +1,5 @@ package com.backoffice.upjuyanolja.domain.point.entity; -import com.backoffice.upjuyanolja.domain.coupon.exception.InsufficientPointsException; import com.backoffice.upjuyanolja.domain.member.entity.Member; import com.backoffice.upjuyanolja.global.common.entity.BaseTime; import jakarta.persistence.Column; @@ -51,11 +50,4 @@ public void updatePointBalance(long totalPointBalance) { this.totalPointBalance = totalPointBalance; } - public void decreasePointBalance(long usedPoints) { - if (totalPointBalance - usedPoints < 0) { - throw new InsufficientPointsException(); - } - totalPointBalance -= usedPoints; - } - } From 421427812ffa409e47ed14759be301add52ec864 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 05:49:43 +0900 Subject: [PATCH 05/45] =?UTF-8?q?#177=20refactor:=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20repo=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../upjuyanolja/domain/point/repository/PointRepository.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointRepository.java index f14470b0..d0485d7e 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointRepository.java @@ -1,14 +1,11 @@ package com.backoffice.upjuyanolja.domain.point.repository; -import com.backoffice.upjuyanolja.domain.member.entity.Member; import com.backoffice.upjuyanolja.domain.point.entity.Point; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface PointRepository extends JpaRepository { - Optional findByMember(Member member); - Optional findByMemberId(Long memberId); } From 0e4bdda10a534d1a77a5851f64d15d45f02b6e65 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 05:50:51 +0900 Subject: [PATCH 06/45] =?UTF-8?q?#177=20feat:=20PointCharges=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A1=9C=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8A=94=20repo=20=EB=A9=94=EC=84=9C=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 --- .../domain/point/repository/PointChargesRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesRepository.java index 2ed9bc8a..acd130a0 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesRepository.java @@ -1,6 +1,7 @@ package com.backoffice.upjuyanolja.domain.point.repository; import com.backoffice.upjuyanolja.domain.point.entity.PointCharges; +import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -8,6 +9,8 @@ public interface PointChargesRepository extends JpaRepository, PointChargesCustomRepository { - Page findByPointId(Long pointId, Pageable pageable); + Page findPageByPointId(Long pointId, Pageable pageable); + + List findByPointId(Long pointId); } From 92e2ef7b4c33db1179147396d473ef001b4b5c69 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 05:52:01 +0900 Subject: [PATCH 07/45] =?UTF-8?q?#177=20refactor:=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=85=EC=9D=84=20=EB=B0=98=ED=99=98=ED=98=95=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=20=ED=95=B4=EC=84=9C=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/controller/PointController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java index 21c10c27..a1bff97d 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java @@ -56,7 +56,7 @@ public ResponseEntity getChargePoints( ) { log.info("Get /api/points/charges"); - PointChargePageResponse response = pointService.getChargePoints( + PointChargePageResponse response = pointService.getPointChargePageResponse( securityUtil.getCurrentMemberId(), pageable ); @@ -69,7 +69,7 @@ public ResponseEntity getDetailChargePoints( ) { log.info("Get /api/points/charges/{chargeId}"); - PointChargeResponse response = pointService.getDetailChargePoint(chargeId); + PointChargeResponse response = pointService.getDetailChargePointResponse(chargeId); return ResponseEntity.status(HttpStatus.OK).body(response); } @@ -80,7 +80,7 @@ public ResponseEntity chargePoint( ) { log.info("Post /api/points/charges"); - PointChargeResponse response = pointService.getChargePointResponse( + PointChargeResponse response = pointService.chargePoint( securityUtil.getCurrentMemberId(), request ); From 94849b5294fd4b5936b4fb52acaffc2003ec52c9 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 05:53:15 +0900 Subject: [PATCH 08/45] =?UTF-8?q?#177=20feat&refactor:=20=ED=8F=AC?= =?UTF-8?q?=EC=9D=B8=ED=8A=B8=20=ED=99=9C=EC=9A=A9=ED=95=9C=20=EA=B2=B0?= =?UTF-8?q?=EC=A0=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?=EB=B0=8F=20=EB=B9=84=EC=8A=B7=ED=95=9C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=81=BC=EB=A6=AC=20=EB=B0=B0=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/service/PointService.java | 279 +++++++++++------- 1 file changed, 174 insertions(+), 105 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index f0035476..ce6baa1a 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -1,6 +1,9 @@ package com.backoffice.upjuyanolja.domain.point.service; +import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation; +import com.backoffice.upjuyanolja.domain.accommodation.service.usecase.AccommodationQueryUseCase; +import com.backoffice.upjuyanolja.domain.coupon.exception.InsufficientPointsException; import com.backoffice.upjuyanolja.domain.member.service.MemberGetService; import com.backoffice.upjuyanolja.domain.point.dto.request.PointChargeRequest; import com.backoffice.upjuyanolja.domain.point.dto.response.PointChargeDetailResponse; @@ -30,6 +33,7 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; +import java.time.LocalDateTime; import java.time.YearMonth; import java.time.ZonedDateTime; import java.util.ArrayList; @@ -54,6 +58,8 @@ public class PointService { private final PointChargesRepository pointChargesRepository; private final PointRefundsRepository pointRefundsRepository; private final PointUsageRepository pointUsageRepository; + + private final AccommodationQueryUseCase accommodationQueryUseCase; private final MemberGetService memberGetService; private final ObjectMapper objectMapper; @@ -79,6 +85,92 @@ public PointSummaryResponse getPointSummaryResponse(Long memberId, YearMonth ran ); } + @Transactional(readOnly = true) + public PointChargeResponse getDetailChargePointResponse(Long chargeId) { + PointCharges detailchargePoint = pointChargesRepository.findById(chargeId) + .orElseThrow(PointNotFoundException::new); + + return PointChargeResponse.of(detailchargePoint); + } + + @Transactional(readOnly = true) + public PointChargePageResponse getPointChargePageResponse(Long memberId, Pageable pageable) { + Long pointId = getMemberPoint(memberId).getId(); + Page pointCharges = pointChargesRepository.findPageByPointId(pointId, + pageable); + + return PointChargePageResponse.of(new PageImpl<>( + pointCharges.stream() + .map(pointCharge -> PointChargeDetailResponse.of( + pointCharge, getPointChargeCategoryAndType(pointCharge).get(0), + getPointChargeCategoryAndType(pointCharge).get(1), + getPointChargeReceiptResponse(pointCharge)) + ) + .toList(), + pageable, + pointCharges.getTotalElements() + ) + ); + } + + public PointChargeResponse chargePoint(Long memberId, PointChargeRequest request) { + Point memberPoint = getMemberPoint(memberId); + TossResponse tossResponse = getTossChargeResponse(request); + + validatePointChargeRequest(request, tossResponse); + PointCharges chargePoint = createPointCharge(memberPoint, tossResponse); + updateTotalPointBalance(memberPoint); + + return PointChargeResponse.of(chargePoint); + } + + public void refundPoint(Long chargeId) { + PointCharges pointCharges = pointChargesRepository.findById(chargeId) + .orElseThrow(PointNotFoundException::new); + TossResponse tossResponse = getTossRefundResponse(pointCharges.getPaymentKey()); + + validatePointRefund(pointCharges); + updateChargePointRefundStatus(pointCharges); + updateTotalPointBalance(pointCharges.getPoint()); + createPointRefund(pointCharges, tossResponse); + + } + + @Transactional(readOnly = true) + public void validatePoint(final Long memberId, final long requestPointBalance) { + Point memberPoint = getMemberPoint(memberId); + + if (memberPoint.getTotalPointBalance() < requestPointBalance) { + throw new InsufficientPointsException(); + } + } + + public void usePointForCoupon( + final Long memberId, final Long accommodationId, final long couponPrice + ) { + Point memberPoint = getMemberPoint(memberId); + List pointCharges = + pointChargesRepository.findByPointId(memberPoint.getId()); + Accommodation couponAccommodation = + accommodationQueryUseCase.getAccommodationById(accommodationId); + long resultPoint = 0; + + for (PointCharges pointCharge : pointCharges) { + if (pointCharge.getPointStatus() != PointStatus.PAID) { + continue; + } + resultPoint += pointCharge.getChargePoint(); + createPointUsage(pointCharge, couponAccommodation); + updateChargePointUseStatus(pointCharge); + if (resultPoint >= couponPrice) { + break; + } + } + + resultPoint = memberPoint.getTotalPointBalance() - couponPrice; + memberPoint.updatePointBalance(resultPoint); + } + private Point getMemberPoint(Long memberId) { return pointRepository.findByMemberId(memberId) .orElseGet(() -> createPoint(memberId)); @@ -95,6 +187,55 @@ private Point createPoint(Long memberId) { return newPoint; } + private PointCharges createPointCharge( + Point point, TossResponse tossResponse + ) { + + PointCharges pointCharges = PointCharges.builder() + .point(point) + .pointStatus(PointStatus.PAID) + .paymentKey(tossResponse.paymentKey()) + .orderName(tossResponse.orderId()) + .chargePoint(tossResponse.totalAmount()) + .chargeDate(ZonedDateTime.parse(tossResponse.approvedAt()).toLocalDateTime()) + .endDate(ZonedDateTime.parse(tossResponse.approvedAt()).toLocalDateTime().plusDays(7)) + .refundable(true) + .build(); + + pointChargesRepository.save(pointCharges); + + return pointCharges; + } + + private PointRefunds createPointRefund(PointCharges pointCharges, TossResponse tossResponse) { + + PointRefunds pointRefunds = PointRefunds.builder() + .pointId(pointCharges.getPoint().getId()) + .pointCharges(pointCharges) + .refundDate(ZonedDateTime.parse(tossResponse.approvedAt()).toLocalDateTime()) + .build(); + + pointRefundsRepository.save(pointRefunds); + + return pointRefunds; + } + + private PointUsage createPointUsage( + PointCharges pointCharges, Accommodation accommodation + ) { + PointUsage pointUsage = PointUsage.builder() + .pointId(pointCharges.getPoint().getId()) + .pointcharges(pointCharges) + .orderPrice(pointCharges.getChargePoint()) + .orderDate(LocalDateTime.now()) + .accommodation(accommodation) + .build(); + + pointUsageRepository.save(pointUsage); + + return pointUsage; + } + private long getTotalChargePoint(Point point, YearMonth rangeDate) { return pointChargesRepository.findByPointAndRefundableAndRangeDate( point, rangeDate @@ -111,48 +252,19 @@ private long getTotalUsePoint(Point point, YearMonth rangeDate) { .sum(); } - @Transactional(readOnly = true) - public PointChargeResponse getDetailChargePoint(Long chargeId) { - PointCharges detailchargePoint = pointChargesRepository.findById(chargeId) - .orElseThrow(PointNotFoundException::new); - - return PointChargeResponse.of(detailchargePoint); + private void updateTotalPointBalance(Point point) { + long totalPoint = Optional.of(pointChargesRepository.sumChargePointByPaidStatus(point)) + .orElse(0L); + point.updatePointBalance(totalPoint); + pointRepository.save(point); } - public PointChargePageResponse getChargePoints(Long memberId, Pageable pageable) { - Long pointId = getMemberPoint(memberId).getId(); - Page pointCharges = pointChargesRepository.findByPointId(pointId, pageable); - - return PointChargePageResponse.of(new PageImpl<>( - pointCharges.stream() - .map(pointCharge -> PointChargeDetailResponse.of( - pointCharge, getPointChargeCategoryAndType(pointCharge).get(0), - getPointChargeCategoryAndType(pointCharge).get(1), - getPointChargeReceiptResponse(pointCharge)) - ) - .toList(), - pageable, - pointCharges.getTotalElements() - ) - ); + private void updateChargePointRefundStatus(PointCharges pointCharges) { + pointCharges.updatePointStatus(PointStatus.CANCELED); } - private List getPointChargeCategoryAndType(PointCharges pointCharges) { - List results = new ArrayList<>(); - - switch (pointCharges.getPointStatus()) { - case PAID: - results.add(PointCategory.CHARGE.getDescription()); - results.add(PointType.POINT.getDescription()); - case CANCELED: - results.add(PointCategory.REFUND.getDescription()); - results.add(PointType.REFUND.getDescription()); - case USED: - results.add(PointCategory.USE.getDescription()); - results.add(PointType.POINT.getDescription()); - } - return results; - + private void updateChargePointUseStatus(PointCharges pointCharges) { + pointCharges.updatePointStatus(PointStatus.USED); } private List getPointChargeReceiptResponse( @@ -176,7 +288,7 @@ private List getPointChargeReceiptResponse( case USED: return pointUsageRepository.findByPointCharges(pointCharges).stream() .map(pointUsage -> PointChargeReceiptResponse.of( - pointUsage.getOrderName(), + pointCharges.getOrderName(), pointUsage.getOrderDate().toString(), pointUsage.getOrderPrice() )) @@ -187,39 +299,22 @@ private List getPointChargeReceiptResponse( } + private List getPointChargeCategoryAndType(PointCharges pointCharges) { + List results = new ArrayList<>(); - public PointChargeResponse getChargePointResponse(Long memberId, PointChargeRequest request) { - Point memberPoint = getMemberPoint(memberId); - TossResponse tossResponse = getTossChargeResponse(request); - - validatePointChargeRequest(request, tossResponse); - PointCharges chargePoint = createPointCharge(memberPoint, tossResponse); - pointChargesRepository.save(chargePoint); - updateTotalPoint(memberPoint); - - return PointChargeResponse.of(chargePoint); - } - - private PointCharges createPointCharge( - Point point, TossResponse tossResponse - ) { - return PointCharges.builder() - .point(point) - .pointStatus(PointStatus.PAID) - .paymentKey(tossResponse.paymentKey()) - .orderName(tossResponse.orderId()) - .chargePoint(tossResponse.totalAmount()) - .chargeDate(ZonedDateTime.parse(tossResponse.approvedAt()).toLocalDateTime()) - .endDate(ZonedDateTime.parse(tossResponse.approvedAt()).toLocalDateTime().plusDays(7)) - .refundable(true) - .build(); - } + switch (pointCharges.getPointStatus()) { + case PAID: + results.add(PointCategory.CHARGE.getDescription()); + results.add(PointType.POINT.getDescription()); + case CANCELED: + results.add(PointCategory.REFUND.getDescription()); + results.add(PointType.REFUND.getDescription()); + case USED: + results.add(PointCategory.USE.getDescription()); + results.add(PointType.POINT.getDescription()); + } + return results; - private void updateTotalPoint(Point point) { - long chargeSum = Optional.of(pointChargesRepository.sumChargePointByRefundable(point)) - .orElse(0L); - point.updatePointBalance(chargeSum); - pointRepository.save(point); } private String createTossAuthorizations() { @@ -261,37 +356,13 @@ private TossResponse getTossChargeResponse(PointChargeRequest request) { } - private void validatePointChargeRequest( - PointChargeRequest request, TossResponse tossResponse - ) { - if (!request.orderId().equals(tossResponse.orderId()) || - !request.paymentKey().equals(tossResponse.paymentKey()) || - request.amount() != tossResponse.totalAmount()) { - throw new PaymentAuthorizationFailedException(); - } - } - - public void refundPoint(Long chargeId) { - PointCharges pointCharges = pointChargesRepository.findById(chargeId) - .orElseThrow(PointNotFoundException::new); - - validatePointRefund(pointCharges); - - TossResponse tossResponse = getTossRefundResponse(pointCharges.getPaymentKey()); - updateChargePointStatus(pointCharges); - updateTotalPoint(pointCharges.getPoint()); - - PointRefunds pointRefunds = createPointRefund(pointCharges, tossResponse); - pointRefundsRepository.save(pointRefunds); - } - private TossResponse getTossRefundResponse(String paymentKey) { HttpResponse response; try { HttpRequest httpRequest = HttpRequest.newBuilder() - .uri(URI.create(tossBaseUrl +paymentKey+ "/cancel")) + .uri(URI.create(tossBaseUrl + paymentKey + "/cancel")) .header("Authorization", "Basic " + createTossAuthorizations()) .header("Content-Type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString( @@ -309,16 +380,14 @@ private TossResponse getTossRefundResponse(String paymentKey) { } - private void updateChargePointStatus(PointCharges pointCharges) { - pointCharges.updatePointStatus(PointStatus.CANCELED); - } - - private PointRefunds createPointRefund(PointCharges pointCharges, TossResponse tossResponse) { - return PointRefunds.builder() - .point(pointCharges.getPoint()) - .pointCharges(pointCharges) - .refundDate(ZonedDateTime.parse(tossResponse.approvedAt()).toLocalDateTime()) - .build(); + private void validatePointChargeRequest( + PointChargeRequest request, TossResponse tossResponse + ) { + if (!request.orderId().equals(tossResponse.orderId()) || + !request.paymentKey().equals(tossResponse.paymentKey()) || + request.amount() != tossResponse.totalAmount()) { + throw new PaymentAuthorizationFailedException(); + } } private void validatePointRefund(PointCharges pointCharges) { From a7792928f4e5f7110d9d1b16d4a0600d186c78b9 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 06:01:59 +0900 Subject: [PATCH 09/45] =?UTF-8?q?feat:=20=EC=88=99=EC=86=8C=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=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 --- .../accommodation/service/AccommodationQueryService.java | 6 ++++++ .../service/usecase/AccommodationQueryUseCase.java | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationQueryService.java b/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationQueryService.java index 1959378c..bbd0108f 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationQueryService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationQueryService.java @@ -49,6 +49,12 @@ public Accommodation getAccommodationById(long accommodationId) { .orElseThrow(AccommodationNotFoundException::new); } + @Override + @Transactional(readOnly = true) + public boolean existsById(Long accommodationId) { + return accommodationRepository.existsById(accommodationId); + } + @Override public AccommodationOwnership saveOwnership(Member member, Accommodation accommodation) { return accommodationOwnershipRepository.save(AccommodationOwnership.builder() diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/usecase/AccommodationQueryUseCase.java b/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/usecase/AccommodationQueryUseCase.java index a7657523..2729a5b8 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/usecase/AccommodationQueryUseCase.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/usecase/AccommodationQueryUseCase.java @@ -16,6 +16,8 @@ public interface AccommodationQueryUseCase { Accommodation getAccommodationById(long id); + boolean existsById(Long accommodationId); + AccommodationOwnership saveOwnership(Member member, Accommodation accommodation); List getOwnershipByMember(Member member); From 52cc3747eb85203a85789fc616ac0a45471ac9fc Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 06:03:03 +0900 Subject: [PATCH 10/45] =?UTF-8?q?#177=20refactor:=20=EB=B0=B1=EC=98=A4?= =?UTF-8?q?=ED=94=BC=EC=8A=A4=20=EC=BF=A0=ED=8F=B0=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=EA=B0=80=20accommodation=EA=B3=BC=20point=EC=9D=98=20?= =?UTF-8?q?repo=20=EC=95=84=EB=8B=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=EB=A1=9C=20=EC=A0=91=EA=B7=BC=20=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 --- .../service/CouponBackofficeService.java | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java index 25cab1bc..513f3398 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java @@ -7,6 +7,7 @@ import com.backoffice.upjuyanolja.domain.accommodation.exception.AccommodationNotFoundException; import com.backoffice.upjuyanolja.domain.accommodation.repository.AccommodationRepository; +import com.backoffice.upjuyanolja.domain.accommodation.service.usecase.AccommodationQueryUseCase; import com.backoffice.upjuyanolja.domain.coupon.dto.request.backoffice.CouponAddInfos; import com.backoffice.upjuyanolja.domain.coupon.dto.request.backoffice.CouponAddRequest; import com.backoffice.upjuyanolja.domain.coupon.dto.request.backoffice.CouponDeleteRequest; @@ -29,6 +30,7 @@ import com.backoffice.upjuyanolja.domain.point.entity.Point; import com.backoffice.upjuyanolja.domain.point.exception.PointNotFoundException; import com.backoffice.upjuyanolja.domain.point.repository.PointRepository; +import com.backoffice.upjuyanolja.domain.point.service.PointService; import com.backoffice.upjuyanolja.domain.room.entity.Room; import com.backoffice.upjuyanolja.domain.room.repository.RoomRepository; import com.backoffice.upjuyanolja.global.exception.NotOwnerException; @@ -49,10 +51,11 @@ public class CouponBackofficeService { private final CouponRepository couponRepository; private final RoomRepository roomRepository; - private final PointRepository pointRepository; - private final AccommodationRepository accommodationRepository; private final CouponIssuanceRepository couponIssuanceRepository; + private final AccommodationQueryUseCase accommodationQueryUseCase; + private final PointService pointService; + // 쿠폰 만들기 View Response public CouponMakeViewResponse getRoomsByAccommodation(Long accommodationId) { return couponRepository.findRoomsByAccommodationId(accommodationId); @@ -63,7 +66,7 @@ public void createCoupon( final CouponMakeRequest couponMakeRequest, final Long memberId ) { final long totalPoints = couponMakeRequest.totalPoints(); - Point point = validationPoint(memberId, totalPoints); + pointService.validatePoint(memberId, totalPoints); List couponRooms = couponMakeRequest.rooms(); List coupons = new ArrayList<>(); @@ -107,8 +110,9 @@ public void createCoupon( // 8. 업주의 보유 포인트 차감 // todo: 도메인이 다른 서비스를 트랜잭션 안에서 호출하는 게 좋은 설계일까 고민해 보기. - point.decreasePointBalance(totalPoints); - pointRepository.save(point); + pointService.usePointForCoupon( + memberId, couponMakeRequest.accommodationId(), couponMakeRequest.totalPoints() + ); // 9. 포인트 사용 이력 전달 // Todo: 포인트 사용 내역 Point 도메인에 전달하기 @@ -145,8 +149,6 @@ public CouponManageResponse manageCoupon(final Long accommodationId) { // 쿠폰 추가 구매 public void addonCoupon(final CouponAddRequest couponAddRequest, final long memberId) { // 1. 업주의 보유 포인트 검증 - final Optional resultPoint = pointRepository.findByMemberId(memberId); - Point point = resultPoint.orElseThrow(PointNotFoundException::new); final int totalPoints = couponAddRequest.totalPoints(); List addCoupons = new ArrayList<>(); @@ -158,8 +160,9 @@ public void addonCoupon(final CouponAddRequest couponAddRequest, final long memb couponRepository.saveAll(addCoupons); // 2. 업주의 보유 포인트 차감 - point.decreasePointBalance(totalPoints); - pointRepository.save(point); + pointService.usePointForCoupon( + memberId, couponAddRequest.accommodationId(), couponAddRequest.totalPoints() + ); // Todo: 포인트 사용 내역 Point 도메인에 전달하기 log.info("쿠폰 추가 발급 성공. 금액: {}", totalPoints); @@ -243,21 +246,6 @@ private CouponManageRooms createManageRoom(final CouponManageQueryDto dto) { .build(); } - // 업주의 보유 포인트 검증 - @Transactional(readOnly = true) - protected Point validationPoint(final Long memberId, final long requestPoint) { - final Optional resultPoint = pointRepository.findByMemberId(memberId); - Point point = resultPoint.orElseThrow(PointNotFoundException::new); - final long ownerPoint = point.getTotalPointBalance(); - - // 쿠폰 구매 요청 금액이 업주의 보유 포인트보다 크다면 예외 발생 - if (ownerPoint < requestPoint) { - log.info("업주의 보유 포인트가 부족합니다. 보유 포인트: {}, 요청 포인트: {}", - ownerPoint, requestPoint); - throw new InsufficientPointsException(); - } - return point; - } // 정상적인 숙소 id 요청인지 검증 @Transactional(readOnly = true) @@ -270,7 +258,8 @@ public void validateAccommodationRequest( currentMemberId, accommodationId); throw new NotOwnerException(); } - if (!accommodationRepository.existsById(accommodationId)) { + + if (!accommodationQueryUseCase.existsById(accommodationId)) { log.info("숙소의 정보를 찾을 수 없습니다. id: {}", accommodationId); throw new AccommodationNotFoundException(); } From 63b5c3e741f4ea5be98cdfff4870783f82aeca4b Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 06:32:42 +0900 Subject: [PATCH 11/45] =?UTF-8?q?#177=20fix:=20=EB=B0=94=EB=80=90=20dto?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EB=B3=80=EC=88=98=20=EC=9E=90?= =?UTF-8?q?=EB=A3=8C=ED=98=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/coupon/service/CouponBackofficeService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java index be5dd995..d5f402c3 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java @@ -149,7 +149,7 @@ public CouponManageResponse manageCoupon(final Long accommodationId) { // 쿠폰 추가 구매 public void addonCoupon(final CouponAddRequest couponAddRequest, final long memberId) { // 1. 업주의 보유 포인트 검증 - final int totalPoints = couponAddRequest.totalPoints(); + final long totalPoints = couponAddRequest.totalPoints(); pointService.validatePoint(memberId, totalPoints); List addCoupons = new ArrayList<>(); From 2751ae8fce92c5158f4b4d1ac61eeaee899a022a Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 21:28:16 +0900 Subject: [PATCH 12/45] =?UTF-8?q?#108=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=A9=EC=A0=84=EC=9D=98=20status=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=EB=B0=8F=20=EC=97=94=ED=84=B0=ED=8B=B0=EC=97=90=20?= =?UTF-8?q?=EC=9E=94=EC=97=AC=20=EA=B8=88=EC=95=A1=20=ED=95=84=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 --- .../upjuyanolja/domain/point/entity/PointCharges.java | 6 ++++++ .../upjuyanolja/domain/point/entity/PointStatus.java | 1 + 2 files changed, 7 insertions(+) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCharges.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCharges.java index c91ef3bf..429ad753 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCharges.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCharges.java @@ -45,6 +45,10 @@ public class PointCharges extends BaseTime { @Comment("충전 포인트") private long chargePoint; + @Column(nullable = false) + @Comment("잔여 포인트") + private long remainPoint; + @Column(nullable = false) @Comment("충전 일시") private LocalDateTime chargeDate; @@ -70,6 +74,7 @@ public PointCharges( String paymentKey, String orderName, long chargePoint, + long remainPoint, LocalDateTime chargeDate, LocalDateTime endDate, boolean refundable, @@ -80,6 +85,7 @@ public PointCharges( this.paymentKey = paymentKey; this.orderName = orderName; this.chargePoint = chargePoint; + this.remainPoint = remainPoint; this.chargeDate = chargeDate; this.endDate = endDate; this.refundable = refundable; diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointStatus.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointStatus.java index c9fe0368..d0eb66e2 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointStatus.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointStatus.java @@ -8,6 +8,7 @@ public enum PointStatus { USED("구매 확정"), + REMAINED("잔액 존재"), PAID("결제 완료"), CANCELED("취소 완료"); From 460215e014470fe02bf46b59e176e87b29904ef1 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 21:33:35 +0900 Subject: [PATCH 13/45] =?UTF-8?q?#108=20refactor:=20=EC=83=88=EB=A1=9C=20?= =?UTF-8?q?=EC=83=9D=EA=B8=B4=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=B6=A9?= =?UTF-8?q?=EC=A0=84=20enum=EA=B3=BC=20=ED=95=84=EB=93=9C=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EA=B2=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=BD=94?= =?UTF-8?q?=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 --- .../upjuyanolja/domain/point/service/PointService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index 5652da08..5e116326 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -164,7 +164,8 @@ public void usePointForCoupon( long resultPoint = 0; for (PointCharges pointCharge : pointCharges) { - if (pointCharge.getPointStatus() != PointStatus.PAID) { + if (pointCharge.getPointStatus() != PointStatus.PAID || + pointCharge.getPointStatus() != PointStatus.REMAINED) { continue; } resultPoint += pointCharge.getChargePoint(); @@ -205,6 +206,7 @@ private PointCharges createPointCharge( .paymentKey(tossResponse.paymentKey()) .orderName(tossResponse.orderId()) .chargePoint(tossResponse.totalAmount()) + .remainPoint(0L) .chargeDate(ZonedDateTime.parse(tossResponse.approvedAt()).toLocalDateTime()) .endDate(ZonedDateTime.parse(tossResponse.approvedAt()).toLocalDateTime().plusDays(7)) .refundable(true) From 5704d69d6ece90f1780174423883a55034e7a32b Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 21:42:53 +0900 Subject: [PATCH 14/45] =?UTF-8?q?#108=20refactor:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AC=EC=9A=A9=EC=9D=80=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=A9=EC=A0=84=EC=9D=B4=20=EC=95=84=EB=8B=8C=20?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=EC=99=80=20=EC=97=B0=EA=B4=80=20?= =?UTF-8?q?=EA=B4=80=EA=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/entity/PointUsage.java | 23 ++++--------------- .../domain/point/service/PointService.java | 8 +++---- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java index ceb5e288..8c6c479a 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointUsage.java @@ -1,6 +1,5 @@ package com.backoffice.upjuyanolja.domain.point.entity; -import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation; import com.backoffice.upjuyanolja.global.common.entity.BaseTime; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -35,34 +34,20 @@ public class PointUsage extends BaseTime { @Comment("주문 금액") private long orderPrice; - @Column(nullable = false) - @Comment("포인트 식별자") - private Long pointId; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "point_charges_id") - @Comment("포인트 충전 식별자") - private PointCharges pointCharges; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "accommodation_id") - private Accommodation accommodation; - + @JoinColumn(name = "point_id") + private Point point; @Builder public PointUsage( Long id, LocalDateTime orderDate, long orderPrice, - Long pointId, - PointCharges pointcharges, - Accommodation accommodation + Point point ) { this.id = id; this.orderDate = orderDate; this.orderPrice = orderPrice; - this.pointId = pointId; - this.pointCharges = pointcharges; - this.accommodation = accommodation; + this.point = point; } } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index 5e116326..d788ad1c 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -231,14 +231,12 @@ private PointRefunds createPointRefund(PointCharges pointCharges, TossResponse t } private PointUsage createPointUsage( - PointCharges pointCharges, Accommodation accommodation + Point point, long orderPrice ) { PointUsage pointUsage = PointUsage.builder() - .pointId(pointCharges.getPoint().getId()) - .pointcharges(pointCharges) - .orderPrice(pointCharges.getChargePoint()) + .point(point) + .orderPrice(orderPrice) .orderDate(LocalDateTime.now()) - .accommodation(accommodation) .build(); pointUsageRepository.save(pointUsage); From 966b49222f0755a41e2e2f6a2148452a963f4ec1 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 21:43:53 +0900 Subject: [PATCH 15/45] =?UTF-8?q?#108=20refactor:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AC=EC=9A=A9=20builder=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=20=EC=8B=9C=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EB=B3=80?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../upjuyanolja/domain/point/service/PointService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index d788ad1c..7c578c1c 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -169,7 +169,7 @@ public void usePointForCoupon( continue; } resultPoint += pointCharge.getChargePoint(); - createPointUsage(pointCharge, couponAccommodation); + createPointUsage(memberPoint, pointCharge.getChargePoint()); updateChargePointUseStatus(pointCharge); if (resultPoint >= couponPrice) { break; From 5bb0f6b0e70f88dcd4817dfaf6f03c06e30b6a76 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 21:49:49 +0900 Subject: [PATCH 16/45] =?UTF-8?q?#108=20feat:=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=EC=99=80=20=EB=B0=9C=EA=B8=89=20?= =?UTF-8?q?=EC=BF=A0=ED=8F=B0=20=EB=82=B4=EC=97=AD=EC=9D=84=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=ED=95=A0=20PointCouponIssuance=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=83=88=EB=A1=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../point/entity/PointCouponIssuance.java | 49 +++++++++++++++++++ .../PointCouponIssuanceRepository.java | 8 +++ 2 files changed, 57 insertions(+) create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCouponIssuance.java create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointCouponIssuanceRepository.java diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCouponIssuance.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCouponIssuance.java new file mode 100644 index 00000000..a669bea4 --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCouponIssuance.java @@ -0,0 +1,49 @@ +package com.backoffice.upjuyanolja.domain.point.entity; + +import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; +import com.backoffice.upjuyanolja.global.common.entity.BaseTime; +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 lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Comment; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +public class PointCouponIssuance extends BaseTime { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Comment("포인트 쿠폰 발급 내역 식별자") + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "point_usage_id") + @Comment("포인트 사용 내역 식별자") + private PointUsage pointUsage; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "coupon_issuance_id") + @Comment("쿠폰 발급 내역 식별자") + private CouponIssuance couponIssuance; + + @Builder + public PointCouponIssuance( + Long id, + PointUsage pointUsage, + CouponIssuance couponIssuance + ) { + this.id = id; + this.pointUsage = pointUsage; + this.couponIssuance = couponIssuance; + } + +} diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointCouponIssuanceRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointCouponIssuanceRepository.java new file mode 100644 index 00000000..2edad61a --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointCouponIssuanceRepository.java @@ -0,0 +1,8 @@ +package com.backoffice.upjuyanolja.domain.point.repository; + +import com.backoffice.upjuyanolja.domain.point.entity.PointCouponIssuance; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PointCouponIssuanceRepository extends JpaRepository { + +} From 1da9c75a82c9397cfda27a4c0cba893ca5655b2c Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 22:27:37 +0900 Subject: [PATCH 17/45] =?UTF-8?q?#108=20refactor:=20couponIssuances?= =?UTF-8?q?=EB=A5=BC=20=EB=A7=A4=EA=B0=9C=20=EB=B3=80=EC=88=98=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EB=A9=94=EC=84=9C=EB=93=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 --- .../domain/point/service/PointService.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index 7c578c1c..9b409e74 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -1,8 +1,7 @@ package com.backoffice.upjuyanolja.domain.point.service; -import com.backoffice.upjuyanolja.domain.accommodation.entity.Accommodation; -import com.backoffice.upjuyanolja.domain.accommodation.service.usecase.AccommodationQueryUseCase; +import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; import com.backoffice.upjuyanolja.domain.coupon.exception.InsufficientPointsException; import com.backoffice.upjuyanolja.domain.member.service.MemberGetService; import com.backoffice.upjuyanolja.domain.point.dto.request.PointChargeRequest; @@ -25,6 +24,7 @@ import com.backoffice.upjuyanolja.domain.point.exception.TossApiErrorException; import com.backoffice.upjuyanolja.domain.point.exception.WrongRefundInfoException; import com.backoffice.upjuyanolja.domain.point.repository.PointChargesRepository; +import com.backoffice.upjuyanolja.domain.point.repository.PointCouponIssuanceRepository; import com.backoffice.upjuyanolja.domain.point.repository.PointRefundsRepository; import com.backoffice.upjuyanolja.domain.point.repository.PointRepository; import com.backoffice.upjuyanolja.domain.point.repository.PointUsageRepository; @@ -39,7 +39,6 @@ import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Base64; -import java.util.Collections; import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -59,8 +58,8 @@ public class PointService { private final PointChargesRepository pointChargesRepository; private final PointRefundsRepository pointRefundsRepository; private final PointUsageRepository pointUsageRepository; + private final PointCouponIssuanceRepository pointCouponIssuanceRepository; - private final AccommodationQueryUseCase accommodationQueryUseCase; private final MemberGetService memberGetService; private final ObjectMapper objectMapper; @@ -87,7 +86,7 @@ public PointSummaryResponse getPointSummaryResponse(Long memberId, YearMonth ran } @Transactional(readOnly = true) - public PointTotalBalanceResponse getPointTotalBalanceResponse(Long memberId){ + public PointTotalBalanceResponse getPointTotalBalanceResponse(Long memberId) { Point memberPoint = getMemberPoint(memberId); return PointTotalBalanceResponse.of(memberPoint.getTotalPointBalance()); @@ -154,13 +153,12 @@ public void validatePoint(final Long memberId, final long requestPointBalance) { } public void usePointForCoupon( - final Long memberId, final Long accommodationId, final long couponPrice + final Long memberId, final List couponIssuances, final long couponPrice ) { Point memberPoint = getMemberPoint(memberId); List pointCharges = pointChargesRepository.findByPointId(memberPoint.getId()); - Accommodation couponAccommodation = - accommodationQueryUseCase.getAccommodationById(accommodationId); + long resultPoint = 0; for (PointCharges pointCharge : pointCharges) { @@ -176,7 +174,7 @@ public void usePointForCoupon( } } - resultPoint = memberPoint.getTotalPointBalance() - couponPrice; + resultPoint = memberPoint.getTotalPointBalance() - couponPrice; memberPoint.updatePointBalance(resultPoint); } @@ -279,8 +277,8 @@ private PointChargeReceiptResponse getPointChargeReceiptResponse( PointCharges pointCharges) { switch (pointCharges.getPointStatus()) { - case PAID : - case USED : + case PAID: + case USED: return PointChargeReceiptResponse.of( pointCharges.getOrderName(), pointCharges.getChargeDate().toString(), From bf461bd708fd8fc1ce8224857f0f9ca4ce156472 Mon Sep 17 00:00:00 2001 From: HyunA Date: Fri, 26 Jan 2024 22:29:54 +0900 Subject: [PATCH 18/45] =?UTF-8?q?#108=20feat:=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EA=B5=AC=EB=A7=A4=ED=95=9C=20=EC=BF=A0=ED=8F=B0=EC=9D=84=20cou?= =?UTF-8?q?ponIssuance=EC=97=90=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=EC=9D=B4=20=EB=B9=A0=EC=A0=B8=20=EC=9E=88?= =?UTF-8?q?=EC=96=B4=EC=84=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../coupon/service/CouponBackofficeService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java index d5f402c3..dbd7bc31 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java @@ -111,7 +111,7 @@ public void createCoupon( // 8. 업주의 보유 포인트 차감 // todo: 도메인이 다른 서비스를 트랜잭션 안에서 호출하는 게 좋은 설계일까 고민해 보기. pointService.usePointForCoupon( - memberId, couponMakeRequest.accommodationId(), couponMakeRequest.totalPoints() + memberId, couponIssuances, totalPoints ); // 9. 포인트 사용 이력 전달 @@ -153,16 +153,29 @@ public void addonCoupon(final CouponAddRequest couponAddRequest, final long memb pointService.validatePoint(memberId, totalPoints); List addCoupons = new ArrayList<>(); + List addCouponIssuances = new ArrayList<>(); + for (var rooms : couponAddRequest.rooms()) { for (var coupons : rooms.coupons()) { addCoupons.add(increaseCouponStock(coupons)); + + Room room = roomRepository.findById(rooms.roomId()).orElseThrow( + InvalidCouponInfoException::new); + Coupon coupon = couponRepository.findById(coupons.couponId()).orElseThrow( + InvalidCouponInfoException::new); + int quantity = coupons.buyQuantity(); + int amount = coupons.eachPoint(); + + addCouponIssuances.add((createCouponIssuance(room, coupon,quantity,amount))); } } couponRepository.saveAll(addCoupons); + couponIssuanceRepository.saveAll(addCouponIssuances); + // 2. 업주의 보유 포인트 차감 pointService.usePointForCoupon( - memberId, couponAddRequest.accommodationId(), couponAddRequest.totalPoints() + memberId, addCouponIssuances, totalPoints ); // Todo: 포인트 사용 내역 Point 도메인에 전달하기 From 892b0ad5630429c66c259d476850c96ee2079bfb Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 01:31:02 +0900 Subject: [PATCH 19/45] =?UTF-8?q?#108=20refactor:=20PointUsage=EA=B0=80=20?= =?UTF-8?q?=EC=B6=A9=EC=A0=84=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20=EC=BF=A0=ED=8F=B0=20=EB=B0=9C=EA=B8=89=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D=EA=B3=BC=20=EA=B4=80=EB=A0=A8=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=84=A4=EA=B3=84=20=EB=B3=80=EA=B2=BD=20=ED=95=98?= =?UTF-8?q?=EB=A9=B4=EC=84=9C,=20=EC=A4=91=EA=B0=84=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/coupon/entity/CouponIssuance.java | 8 +++ .../point/entity/PointCouponIssuance.java | 49 ------------------- .../PointCouponIssuanceRepository.java | 8 --- 3 files changed, 8 insertions(+), 57 deletions(-) delete mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCouponIssuance.java delete mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointCouponIssuanceRepository.java diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/entity/CouponIssuance.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/entity/CouponIssuance.java index 01472d88..def55375 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/entity/CouponIssuance.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/entity/CouponIssuance.java @@ -1,5 +1,6 @@ package com.backoffice.upjuyanolja.domain.coupon.entity; +import com.backoffice.upjuyanolja.domain.point.entity.PointUsage; import com.backoffice.upjuyanolja.domain.room.entity.Room; import com.backoffice.upjuyanolja.global.common.entity.BaseTime; import jakarta.persistence.Column; @@ -40,6 +41,11 @@ public class CouponIssuance extends BaseTime { @Comment("객실 식별자") private Room room; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(nullable = false, name = "point_usage_id") + @Comment("객실 식별자") + private PointUsage pointUsage; + @Column(nullable = false) @Comment("발급 수량") private int quantity; @@ -53,6 +59,7 @@ public CouponIssuance( Long id, Coupon coupon, Room room, + PointUsage pointUsage, int quantity, int amount ) { @@ -62,4 +69,5 @@ public CouponIssuance( this.quantity = quantity; this.amount = amount; } + } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCouponIssuance.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCouponIssuance.java deleted file mode 100644 index a669bea4..00000000 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCouponIssuance.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.backoffice.upjuyanolja.domain.point.entity; - -import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; -import com.backoffice.upjuyanolja.global.common.entity.BaseTime; -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 lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.Comment; - -@Getter -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Entity -public class PointCouponIssuance extends BaseTime { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Comment("포인트 쿠폰 발급 내역 식별자") - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "point_usage_id") - @Comment("포인트 사용 내역 식별자") - private PointUsage pointUsage; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "coupon_issuance_id") - @Comment("쿠폰 발급 내역 식별자") - private CouponIssuance couponIssuance; - - @Builder - public PointCouponIssuance( - Long id, - PointUsage pointUsage, - CouponIssuance couponIssuance - ) { - this.id = id; - this.pointUsage = pointUsage; - this.couponIssuance = couponIssuance; - } - -} diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointCouponIssuanceRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointCouponIssuanceRepository.java deleted file mode 100644 index 2edad61a..00000000 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointCouponIssuanceRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.backoffice.upjuyanolja.domain.point.repository; - -import com.backoffice.upjuyanolja.domain.point.entity.PointCouponIssuance; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface PointCouponIssuanceRepository extends JpaRepository { - -} From 5f29a0cfb9ec42f43783320f2d9c9111c13f6c83 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 01:39:29 +0900 Subject: [PATCH 20/45] =?UTF-8?q?#108=20refactor:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EA=B2=B0=EC=A0=9C=20=ED=9B=84=20=EC=BF=A0=ED=8F=B0?= =?UTF-8?q?=20=EB=B0=9C=EA=B8=89=EC=9D=84=20=EC=83=9D=EC=84=B1=ED=95=B4?= =?UTF-8?q?=EC=84=9C,=20CouponIssuance=EA=B0=80=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EB=90=A0=20=EB=95=8C=20pointUsage=EB=A5=BC=20=EA=B0=99?= =?UTF-8?q?=EC=9D=B4=20=EC=A7=80=EC=A0=95=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/coupon/entity/CouponIssuance.java | 1 + .../service/CouponBackofficeService.java | 33 ++++++++----------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/entity/CouponIssuance.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/entity/CouponIssuance.java index def55375..fddf9a17 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/entity/CouponIssuance.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/entity/CouponIssuance.java @@ -66,6 +66,7 @@ public CouponIssuance( this.id = id; this.coupon = coupon; this.room = room; + this.pointUsage = pointUsage; this.quantity = quantity; this.amount = amount; } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java index dbd7bc31..26ab7066 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponBackofficeService.java @@ -6,7 +6,6 @@ import static java.util.stream.Collectors.toList; import com.backoffice.upjuyanolja.domain.accommodation.exception.AccommodationNotFoundException; -import com.backoffice.upjuyanolja.domain.accommodation.repository.AccommodationRepository; import com.backoffice.upjuyanolja.domain.accommodation.service.usecase.AccommodationQueryUseCase; import com.backoffice.upjuyanolja.domain.coupon.dto.request.backoffice.CouponAddInfos; import com.backoffice.upjuyanolja.domain.coupon.dto.request.backoffice.CouponAddRequest; @@ -23,13 +22,10 @@ import com.backoffice.upjuyanolja.domain.coupon.entity.Coupon; import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; import com.backoffice.upjuyanolja.domain.coupon.entity.DiscountType; -import com.backoffice.upjuyanolja.domain.coupon.exception.InsufficientPointsException; import com.backoffice.upjuyanolja.domain.coupon.exception.InvalidCouponInfoException; import com.backoffice.upjuyanolja.domain.coupon.repository.CouponIssuanceRepository; import com.backoffice.upjuyanolja.domain.coupon.repository.CouponRepository; -import com.backoffice.upjuyanolja.domain.point.entity.Point; -import com.backoffice.upjuyanolja.domain.point.exception.PointNotFoundException; -import com.backoffice.upjuyanolja.domain.point.repository.PointRepository; +import com.backoffice.upjuyanolja.domain.point.entity.PointUsage; import com.backoffice.upjuyanolja.domain.point.service.PointService; import com.backoffice.upjuyanolja.domain.room.entity.Room; import com.backoffice.upjuyanolja.domain.room.repository.RoomRepository; @@ -68,6 +64,9 @@ public void createCoupon( final long totalPoints = couponMakeRequest.totalPoints(); pointService.validatePoint(memberId, totalPoints); + // 업주의 보유 포인트 차감 + PointUsage pointUsage = pointService.usePointForCoupon(memberId, totalPoints); + List couponRooms = couponMakeRequest.rooms(); List coupons = new ArrayList<>(); List couponIssuances = new ArrayList<>(); @@ -101,20 +100,14 @@ public void createCoupon( log.info("신규 쿠폰 발급: {}, memberId: {}", quantity, memberId); } // 5. 쿠폰 발급 내역 배열 생성 - couponIssuances.add(createCouponIssuance(room, coupon, quantity, amount)); + couponIssuances.add(createCouponIssuance(room, coupon, pointUsage, quantity, amount)); } // 6. 생성된 쿠폰 저장 couponRepository.saveAll(coupons); // 7. 생성된 쿠폰 발급 내역 저장 couponIssuanceRepository.saveAll(couponIssuances); - // 8. 업주의 보유 포인트 차감 - // todo: 도메인이 다른 서비스를 트랜잭션 안에서 호출하는 게 좋은 설계일까 고민해 보기. - pointService.usePointForCoupon( - memberId, couponIssuances, totalPoints - ); - - // 9. 포인트 사용 이력 전달 + // 8. 포인트 사용 이력 전달 // Todo: 포인트 사용 내역 Point 도메인에 전달하기 log.info("쿠폰 발급 성공. 금액: {}", totalPoints); } @@ -152,6 +145,9 @@ public void addonCoupon(final CouponAddRequest couponAddRequest, final long memb final long totalPoints = couponAddRequest.totalPoints(); pointService.validatePoint(memberId, totalPoints); + // 2. 업주의 보유 포인트 차감 + PointUsage pointUsage = pointService.usePointForCoupon(memberId, totalPoints); + List addCoupons = new ArrayList<>(); List addCouponIssuances = new ArrayList<>(); @@ -166,19 +162,14 @@ public void addonCoupon(final CouponAddRequest couponAddRequest, final long memb int quantity = coupons.buyQuantity(); int amount = coupons.eachPoint(); - addCouponIssuances.add((createCouponIssuance(room, coupon,quantity,amount))); + addCouponIssuances.add( + (createCouponIssuance(room, coupon, pointUsage, quantity, amount))); } } couponRepository.saveAll(addCoupons); - couponIssuanceRepository.saveAll(addCouponIssuances); - // 2. 업주의 보유 포인트 차감 - pointService.usePointForCoupon( - memberId, addCouponIssuances, totalPoints - ); - // Todo: 포인트 사용 내역 Point 도메인에 전달하기 log.info("쿠폰 추가 발급 성공. 금액: {}", totalPoints); } @@ -290,12 +281,14 @@ private Coupon updateCouponStock(final Coupon coupon, final int quantity) { private CouponIssuance createCouponIssuance( final Room room, final Coupon coupon, + final PointUsage pointUsage, final int quantity, final int amount ) { return CouponIssuance.builder() .room(room) .coupon(coupon) + .pointUsage(pointUsage) .quantity(quantity) .amount(amount) .build(); From 828edaaf1d454ab7c8eab2c9e66361066f41f033 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 03:05:11 +0900 Subject: [PATCH 21/45] =?UTF-8?q?#177=20refactor:=20=ED=95=84=EB=93=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20dsl=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/repository/PointUsageCustomRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageCustomRepositoryImpl.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageCustomRepositoryImpl.java index 7e9ef760..c705b254 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageCustomRepositoryImpl.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageCustomRepositoryImpl.java @@ -29,7 +29,7 @@ private List getPointUsages( Point point, YearMonth rangeDate ) { return query.selectFrom(qPointUsage) - .where(qPointUsage.pointId.eq(point.getId()) + .where(qPointUsage.point.eq(point) .and(eqChargeDate(rangeDate)) ) .fetch(); From 7d57af7985d5c70e55ec41129ebafa1cd85b6e25 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 03:58:41 +0900 Subject: [PATCH 22/45] =?UTF-8?q?#177=20refactor:=20Status=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20PointCharges=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20dsl=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PointChargesCustomRepository.java | 4 +- .../PointChargesCustomRepositoryImpl.java | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java index 8db2a78d..120235b4 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java @@ -7,8 +7,8 @@ public interface PointChargesCustomRepository { - Long sumChargePointByPaidStatus(Point point); + Long sumTotalPointByStatus(Point point); - List findByPointAndRefundableAndRangeDate(Point point, + List findByPointByStatusAndRangeDate(Point point, YearMonth rangeDate); } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java index c4a88efa..b21e4901 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java @@ -19,34 +19,39 @@ public class PointChargesCustomRepositoryImpl implements PointChargesCustomRepos private final QPointCharges qPointCharges = QPointCharges.pointCharges; @Override - public Long sumChargePointByPaidStatus(Point point) { - return query.select(qPointCharges.chargePoint.sum()) - .from(qPointCharges) - .where(isPointPaidStatus(point)) - .fetchFirst(); - } + public Long sumTotalPointByStatus(Point point) { + return sumTotalPaidPoint(point) + sumTotalRemainedPoint(point); - @Override - public List findByPointAndRefundableAndRangeDate( - Point point, YearMonth rangeDate - ) { - List result = getPointCharges(point, rangeDate); - return result; } - private List getPointCharges( + @Override + public List findByPointByStatusAndRangeDate( Point point, YearMonth rangeDate ) { return query.selectFrom(qPointCharges) - .where(isPointPaidStatus(point) + .where(isPointAvailableStatus(point) .and(eqChargeDate(rangeDate)) ) .fetch(); } - private BooleanExpression isPointPaidStatus(Point point) { + private Long sumTotalPaidPoint(Point point){ + return query.select(qPointCharges.chargePoint.sum().nullif(0L)) + .from(qPointCharges) + .where(qPointCharges.pointStatus.eq(PointStatus.PAID)) + .fetchFirst(); + } + + private Long sumTotalRemainedPoint(Point point){ + return query.select(qPointCharges.remainPoint.sum().nullif(0L)) + .from(qPointCharges) + .where(qPointCharges.pointStatus.eq(PointStatus.REMAINED)) + .fetchFirst(); + } + + private BooleanExpression isPointAvailableStatus(Point point) { return qPointCharges.point.eq(point) - .and(qPointCharges.pointStatus.eq(PointStatus.PAID)); + .and(qPointCharges.pointStatus.in(PointStatus.PAID, PointStatus.REMAINED)); } private BooleanExpression eqChargeDate(YearMonth rangeDate) { From 4f5b37dba334f140836a6ec8b85af1df70c32b05 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 04:01:14 +0900 Subject: [PATCH 23/45] =?UTF-8?q?#177=20feat:=20PointCharges=20=EC=97=94?= =?UTF-8?q?=ED=84=B0=ED=8B=B0=EC=97=90=20remain=20=EA=B0=92=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=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 --- .../upjuyanolja/domain/point/entity/PointCharges.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCharges.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCharges.java index 429ad753..b4338064 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCharges.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/entity/PointCharges.java @@ -100,4 +100,9 @@ public void updateRefundable(boolean refundable) { this.refundable = refundable; } + public void updateRemainPoint(long remainPoint) { + this.remainPoint = remainPoint; + } + + } From a5298ba501fc6633442f69ebbf59e8afd4c9d862 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 04:31:14 +0900 Subject: [PATCH 24/45] =?UTF-8?q?#177=20fix:=20sum=EC=97=90=EC=84=9C=20nul?= =?UTF-8?q?l=20=EB=B0=98=ED=99=98=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PointChargesCustomRepository.java | 4 ++- .../PointChargesCustomRepositoryImpl.java | 27 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java index 120235b4..319f05b3 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepository.java @@ -7,7 +7,9 @@ public interface PointChargesCustomRepository { - Long sumTotalPointByStatus(Point point); + Long sumTotalPaidPoint(Point point); + + Long sumTotalRemainedPoint(Point point); List findByPointByStatusAndRangeDate(Point point, YearMonth rangeDate); diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java index b21e4901..3e158790 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointChargesCustomRepositoryImpl.java @@ -19,9 +19,19 @@ public class PointChargesCustomRepositoryImpl implements PointChargesCustomRepos private final QPointCharges qPointCharges = QPointCharges.pointCharges; @Override - public Long sumTotalPointByStatus(Point point) { - return sumTotalPaidPoint(point) + sumTotalRemainedPoint(point); + public Long sumTotalPaidPoint(Point point){ + return query.select(qPointCharges.chargePoint.sum()) + .from(qPointCharges) + .where(qPointCharges.pointStatus.eq(PointStatus.PAID)) + .fetchFirst(); + } + @Override + public Long sumTotalRemainedPoint(Point point){ + return query.select(qPointCharges.remainPoint.sum()) + .from(qPointCharges) + .where(qPointCharges.pointStatus.eq(PointStatus.REMAINED)) + .fetchFirst(); } @Override @@ -35,19 +45,6 @@ public List findByPointByStatusAndRangeDate( .fetch(); } - private Long sumTotalPaidPoint(Point point){ - return query.select(qPointCharges.chargePoint.sum().nullif(0L)) - .from(qPointCharges) - .where(qPointCharges.pointStatus.eq(PointStatus.PAID)) - .fetchFirst(); - } - - private Long sumTotalRemainedPoint(Point point){ - return query.select(qPointCharges.remainPoint.sum().nullif(0L)) - .from(qPointCharges) - .where(qPointCharges.pointStatus.eq(PointStatus.REMAINED)) - .fetchFirst(); - } private BooleanExpression isPointAvailableStatus(Point point) { return qPointCharges.point.eq(point) From 78964ebbc8f320dbf1bce26542dd1bceb4789573 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 05:41:26 +0900 Subject: [PATCH 25/45] =?UTF-8?q?#177=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EA=B2=B0=EC=A0=9C=20http=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/service/PointService.java | 84 ++++++++++++------- 1 file changed, 52 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index 9b409e74..5d0bce07 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -1,7 +1,6 @@ package com.backoffice.upjuyanolja.domain.point.service; -import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; import com.backoffice.upjuyanolja.domain.coupon.exception.InsufficientPointsException; import com.backoffice.upjuyanolja.domain.member.service.MemberGetService; import com.backoffice.upjuyanolja.domain.point.dto.request.PointChargeRequest; @@ -24,7 +23,6 @@ import com.backoffice.upjuyanolja.domain.point.exception.TossApiErrorException; import com.backoffice.upjuyanolja.domain.point.exception.WrongRefundInfoException; import com.backoffice.upjuyanolja.domain.point.repository.PointChargesRepository; -import com.backoffice.upjuyanolja.domain.point.repository.PointCouponIssuanceRepository; import com.backoffice.upjuyanolja.domain.point.repository.PointRefundsRepository; import com.backoffice.upjuyanolja.domain.point.repository.PointRepository; import com.backoffice.upjuyanolja.domain.point.repository.PointUsageRepository; @@ -58,7 +56,6 @@ public class PointService { private final PointChargesRepository pointChargesRepository; private final PointRefundsRepository pointRefundsRepository; private final PointUsageRepository pointUsageRepository; - private final PointCouponIssuanceRepository pointCouponIssuanceRepository; private final MemberGetService memberGetService; private final ObjectMapper objectMapper; @@ -137,7 +134,7 @@ public void refundPoint(Long chargeId) { TossResponse tossResponse = getTossRefundResponse(pointCharges.getPaymentKey()); validatePointRefund(pointCharges); - updateChargePointRefundStatus(pointCharges); + updateChargePointStatus(pointCharges, PointStatus.CANCELED); updateTotalPointBalance(pointCharges.getPoint()); createPointRefund(pointCharges, tossResponse); @@ -152,30 +149,13 @@ public void validatePoint(final Long memberId, final long requestPointBalance) { } } - public void usePointForCoupon( - final Long memberId, final List couponIssuances, final long couponPrice - ) { + public PointUsage usePointForCoupon(final Long memberId, final long totalPrice) { Point memberPoint = getMemberPoint(memberId); - List pointCharges = - pointChargesRepository.findByPointId(memberPoint.getId()); - - long resultPoint = 0; + PointUsage resultPointUsage = createPointUsage(memberPoint, totalPrice); - for (PointCharges pointCharge : pointCharges) { - if (pointCharge.getPointStatus() != PointStatus.PAID || - pointCharge.getPointStatus() != PointStatus.REMAINED) { - continue; - } - resultPoint += pointCharge.getChargePoint(); - createPointUsage(memberPoint, pointCharge.getChargePoint()); - updateChargePointUseStatus(pointCharge); - if (resultPoint >= couponPrice) { - break; - } - } + useChargePointForCoupon(totalPrice, memberPoint.getId(), memberPoint); - resultPoint = memberPoint.getTotalPointBalance() - couponPrice; - memberPoint.updatePointBalance(resultPoint); + return resultPointUsage; } private Point getMemberPoint(Long memberId) { @@ -243,7 +223,7 @@ private PointUsage createPointUsage( } private long getTotalChargePoint(Point point, YearMonth rangeDate) { - return pointChargesRepository.findByPointAndRefundableAndRangeDate( + return pointChargesRepository.findByPointByStatusAndRangeDate( point, rangeDate ).stream() .mapToLong(PointCharges::getChargePoint) @@ -259,18 +239,55 @@ private long getTotalUsePoint(Point point, YearMonth rangeDate) { } private void updateTotalPointBalance(Point point) { - long totalPoint = Optional.of(pointChargesRepository.sumChargePointByPaidStatus(point)) - .orElse(0L); + long totalPoint = + Optional.ofNullable(pointChargesRepository.sumTotalPaidPoint(point)).orElse(0L) + + Optional.ofNullable(pointChargesRepository.sumTotalRemainedPoint(point)).orElse(0L); point.updatePointBalance(totalPoint); pointRepository.save(point); } - private void updateChargePointRefundStatus(PointCharges pointCharges) { - pointCharges.updatePointStatus(PointStatus.CANCELED); + private void updateChargePointStatus(PointCharges pointCharges, PointStatus pointStatus) { + pointCharges.updatePointStatus(pointStatus); + pointCharges.updateRefundable(false); + } + + private void updateChargeRemainPoint(PointCharges pointCharges, long totalPrice) { + long remainPoint = pointCharges.getChargePoint() - totalPrice; + pointCharges.updateRemainPoint(remainPoint); + pointChargesRepository.save(pointCharges); } - private void updateChargePointUseStatus(PointCharges pointCharges) { - pointCharges.updatePointStatus(PointStatus.USED); + private void useChargePointForCoupon(long totalPrice, Long pointChargeId, Point memberPoint) { + List pointCharges = + pointChargesRepository.findByPointId(pointChargeId); + long resultPoint = memberPoint.getTotalPointBalance(); + + for (PointCharges pointCharge : pointCharges) { + if (resultPoint >= totalPrice) { + break; + } + + switch (pointCharge.getPointStatus()) { + case PAID: + resultPoint += pointCharge.getChargePoint(); + if (pointCharge.getChargePoint() > totalPrice) { + updateChargePointStatus(pointCharge, PointStatus.REMAINED); + updateChargeRemainPoint(pointCharge, totalPrice); + } + updateChargePointStatus(pointCharge, PointStatus.USED); + break; + case REMAINED: + resultPoint += pointCharge.getRemainPoint(); + if (totalPrice >= resultPoint) { + updateChargePointStatus(pointCharge, PointStatus.USED); + updateChargeRemainPoint(pointCharge, pointCharge.getRemainPoint()); + } + updateChargeRemainPoint(pointCharge, (resultPoint - totalPrice)); + break; + } + + } + updateTotalPointBalance(memberPoint); } private PointChargeReceiptResponse getPointChargeReceiptResponse( @@ -304,12 +321,15 @@ private List getPointChargeCategoryAndType(PointCharges pointCharges) { case PAID: results.add(PointCategory.CHARGE.getDescription()); results.add(PointType.POINT.getDescription()); + break; case CANCELED: results.add(PointCategory.REFUND.getDescription()); results.add(PointType.REFUND.getDescription()); + break; case USED: results.add(PointCategory.USE.getDescription()); results.add(PointType.POINT.getDescription()); + break; } return results; From f7f74c203aab4f301baf4404be85f66afd869053 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 11:35:34 +0900 Subject: [PATCH 26/45] =?UTF-8?q?#192=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AC=EC=9A=A9=20=EB=82=B4=EC=97=AD=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PointUsageCouponReceiptResponse.java | 25 ++++++++++++++ .../PointUsageDetailReceiptResponse.java | 21 ++++++++++++ .../response/PointUsageDetailResponse.java | 34 +++++++++++++++++++ .../dto/response/PointUsagePageResponse.java | 28 +++++++++++++++ .../response/PointUsageReceiptResponse.java | 26 ++++++++++++++ 5 files changed, 134 insertions(+) create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageCouponReceiptResponse.java create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailReceiptResponse.java create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailResponse.java create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsagePageResponse.java create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageReceiptResponse.java diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageCouponReceiptResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageCouponReceiptResponse.java new file mode 100644 index 00000000..8755f4b0 --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageCouponReceiptResponse.java @@ -0,0 +1,25 @@ +package com.backoffice.upjuyanolja.domain.point.dto.response; + +import com.backoffice.upjuyanolja.domain.coupon.entity.Coupon; +import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; +import lombok.Builder; + +@Builder +public record PointUsageCouponReceiptResponse( + String name, + int count, + int totalPrice +) { + + public static PointUsageCouponReceiptResponse of( + CouponIssuance couponIssuance + ) { + Coupon coupon = couponIssuance.getCoupon(); + + return PointUsageCouponReceiptResponse.builder() + .name(coupon.getDiscount() + "원 쿠폰 | " + coupon.getDiscount() / 10 + "p") + .count(couponIssuance.getQuantity()) + .totalPrice(couponIssuance.getAmount()) + .build(); + } +} diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailReceiptResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailReceiptResponse.java new file mode 100644 index 00000000..f879e01e --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailReceiptResponse.java @@ -0,0 +1,21 @@ +package com.backoffice.upjuyanolja.domain.point.dto.response; + +import java.util.List; +import lombok.Builder; + +@Builder +public record PointUsageDetailReceiptResponse( + String room, + List coupons + +) { + + public static PointUsageDetailReceiptResponse of( + String room, List coupons + ) { + return PointUsageDetailReceiptResponse.builder() + .room(room) + .coupons(coupons) + .build(); + } +} diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailResponse.java new file mode 100644 index 00000000..a8cb395f --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailResponse.java @@ -0,0 +1,34 @@ +package com.backoffice.upjuyanolja.domain.point.dto.response; + +import com.backoffice.upjuyanolja.domain.point.entity.PointCharges; +import lombok.Builder; + +@Builder +public record PointUsageDetailResponse( + long id, + String category, + String type, + String status, + String name, + long trade, + long amount, + PointUsageReceiptResponse receipt + +) { + + public static PointUsageDetailResponse of( + PointCharges pointCharges, String category, String type, + PointUsageReceiptResponse receipt + ) { + return PointUsageDetailResponse.builder() + .id(pointCharges.getId()) + .category(category) + .type(type) + .status(pointCharges.getPointStatus().getDescription()) + .name("할인 쿠폰 구매") + .trade(pointCharges.getChargePoint()) + .amount(pointCharges.getChargePoint()) + .receipt(receipt) + .build(); + } +} diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsagePageResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsagePageResponse.java new file mode 100644 index 00000000..c106f1c6 --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsagePageResponse.java @@ -0,0 +1,28 @@ +package com.backoffice.upjuyanolja.domain.point.dto.response; + +import java.util.List; +import lombok.Builder; +import org.springframework.data.domain.Page; + +@Builder +public record PointUsagePageResponse( + int pageNum, + int pageSize, + int totalPages, + long totalElements, + boolean isLast, + List histories + +) { + + public static PointUsagePageResponse of(Page responsePage) { + return PointUsagePageResponse.builder() + .pageNum(responsePage.getNumber() + 1) + .pageSize(responsePage.getSize()) + .totalPages(responsePage.getTotalPages()) + .totalElements(responsePage.getTotalElements()) + .isLast(responsePage.isLast()) + .histories(responsePage.getContent()) + .build(); + } +} diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageReceiptResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageReceiptResponse.java new file mode 100644 index 00000000..b89fa988 --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageReceiptResponse.java @@ -0,0 +1,26 @@ +package com.backoffice.upjuyanolja.domain.point.dto.response; + +import java.util.List; +import lombok.Builder; + +@Builder +public record PointUsageReceiptResponse( + String orderId, + String tradeAt, + String accommodationName, + List orders + +) { + + public static PointUsageReceiptResponse of( + String orderId, String tradeAt, + String accommodationName, List orders + ) { + return PointUsageReceiptResponse.builder() + .orderId(orderId) + .tradeAt(tradeAt) + .accommodationName(accommodationName) + .orders(orders) + .build(); + } +} From 79aadb262edcbefdc4698ce82278e0cdb0bf05ae Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 13:23:52 +0900 Subject: [PATCH 27/45] =?UTF-8?q?#192=20feat:=20CouponIssuance=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=B0=98=ED=99=98=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=ED=8F=AC=ED=95=A8=ED=95=9C=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/CouponIssuanceRepository.java | 4 ++++ .../service/CouponIssuanceGetService.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponIssuanceGetService.java diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponIssuanceRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponIssuanceRepository.java index 311cb315..d92f05af 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponIssuanceRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/repository/CouponIssuanceRepository.java @@ -1,8 +1,12 @@ package com.backoffice.upjuyanolja.domain.coupon.repository; import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; +import com.backoffice.upjuyanolja.domain.point.entity.PointUsage; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; public interface CouponIssuanceRepository extends JpaRepository { + List findByPointUsage(PointUsage pointUsage); + } diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponIssuanceGetService.java b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponIssuanceGetService.java new file mode 100644 index 00000000..28d86efb --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/coupon/service/CouponIssuanceGetService.java @@ -0,0 +1,20 @@ +package com.backoffice.upjuyanolja.domain.coupon.service; + +import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; +import com.backoffice.upjuyanolja.domain.coupon.repository.CouponIssuanceRepository; +import com.backoffice.upjuyanolja.domain.point.entity.PointUsage; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class CouponIssuanceGetService { + + private final CouponIssuanceRepository couponIssuanceRepository; + + public List getCouponIssuanceByPointUsage(PointUsage pointUsage) { + return couponIssuanceRepository.findByPointUsage(pointUsage); + } + +} From 54ae49a609d6ae9349a338b87118e25e02718eb2 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 13:24:15 +0900 Subject: [PATCH 28/45] =?UTF-8?q?#192=20feat:=20RoomId=EB=A1=9C=20Accommod?= =?UTF-8?q?ation=20=EC=B0=BE=EB=8A=94=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 --- .../service/AccommodationCommandService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationCommandService.java b/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationCommandService.java index ebdf12fd..34f81575 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationCommandService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationCommandService.java @@ -196,7 +196,8 @@ private String getMainCouponName(Long accommodationId) { public AccommodationDetailResponse findAccommodationWithRooms( Long accommodationId, LocalDate startDate, LocalDate endDate ) { - Accommodation accommodation = findAccommodationById(accommodationId); + Accommodation accommodation = accommodationQueryUseCase.getAccommodationById( + accommodationId); List filterRooms = getFilteredRoomsByDate( accommodation.getRooms(), startDate, endDate @@ -216,13 +217,12 @@ room, getDiscountPrice(room), ); } - private Accommodation findAccommodationById(Long accommodationId) { - Accommodation accommodation = - accommodationRepository.findById(accommodationId) - .orElseThrow(AccommodationNotFoundException::new); - return accommodation; + @Transactional(readOnly = true) + public Accommodation findAccommodationByRoomId(long roomId) { + return roomQueryService.findRoomById(roomId).getAccommodation(); } + private int getDiscountPrice(Room room) { return couponService.getSortedTotalCouponResponseInRoom(room) .stream() From 322052e01f463d8dd2eacb7e8d8a85c688eb13e5 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 13:25:52 +0900 Subject: [PATCH 29/45] =?UTF-8?q?#192=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=A9=EC=A0=84=20=EB=82=B4=EC=97=AD=EC=97=90?= =?UTF-8?q?=EB=8A=94=20=EC=97=86=EB=8A=94=20description=20=ED=95=84?= =?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 --- .../response/PointUsageDetailResponse.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailResponse.java index a8cb395f..0892ce7d 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailResponse.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageDetailResponse.java @@ -1,6 +1,6 @@ package com.backoffice.upjuyanolja.domain.point.dto.response; -import com.backoffice.upjuyanolja.domain.point.entity.PointCharges; +import com.backoffice.upjuyanolja.domain.point.entity.PointUsage; import lombok.Builder; @Builder @@ -10,6 +10,7 @@ public record PointUsageDetailResponse( String type, String status, String name, + String description, long trade, long amount, PointUsageReceiptResponse receipt @@ -17,17 +18,18 @@ public record PointUsageDetailResponse( ) { public static PointUsageDetailResponse of( - PointCharges pointCharges, String category, String type, - PointUsageReceiptResponse receipt + PointUsage pointUsage, String description, + long trade, long amount, PointUsageReceiptResponse receipt ) { return PointUsageDetailResponse.builder() - .id(pointCharges.getId()) - .category(category) - .type(type) - .status(pointCharges.getPointStatus().getDescription()) + .id(pointUsage.getId()) + .category("사용") + .type("쿠폰") + .status("구매 확정") .name("할인 쿠폰 구매") - .trade(pointCharges.getChargePoint()) - .amount(pointCharges.getChargePoint()) + .description(description) + .trade(trade) + .amount(amount) .receipt(receipt) .build(); } From b30599cedcb35267c5556c3afd27f0e8b80122e7 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 13:47:37 +0900 Subject: [PATCH 30/45] =?UTF-8?q?#192=20refactor:=20=EA=B0=92=20=ED=95=A0?= =?UTF-8?q?=EB=8B=B9=20=EB=A1=9C=EC=A7=81=EC=9D=84=20dto=EA=B0=80=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=ED=95=98=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 --- .../response/PointUsageCouponReceiptResponse.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageCouponReceiptResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageCouponReceiptResponse.java index 8755f4b0..5e7f458d 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageCouponReceiptResponse.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointUsageCouponReceiptResponse.java @@ -1,7 +1,5 @@ package com.backoffice.upjuyanolja.domain.point.dto.response; -import com.backoffice.upjuyanolja.domain.coupon.entity.Coupon; -import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; import lombok.Builder; @Builder @@ -12,14 +10,12 @@ public record PointUsageCouponReceiptResponse( ) { public static PointUsageCouponReceiptResponse of( - CouponIssuance couponIssuance + String name, int count, int totalPrice ) { - Coupon coupon = couponIssuance.getCoupon(); - return PointUsageCouponReceiptResponse.builder() - .name(coupon.getDiscount() + "원 쿠폰 | " + coupon.getDiscount() / 10 + "p") - .count(couponIssuance.getQuantity()) - .totalPrice(couponIssuance.getAmount()) + .name(name) + .count(count) + .totalPrice(totalPrice) .build(); } } From dc753b37d33396c5f2270b996a6182caab3c5fa0 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 13:48:25 +0900 Subject: [PATCH 31/45] =?UTF-8?q?#192=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EB=82=B4=EC=97=AD=20=EC=A1=B0=ED=9A=8C=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=B0=98=ED=99=98=20repo=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/repository/PointUsageRepository.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageRepository.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageRepository.java index cbe4f5be..f1ab05f0 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageRepository.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/repository/PointUsageRepository.java @@ -1,9 +1,13 @@ package com.backoffice.upjuyanolja.domain.point.repository; import com.backoffice.upjuyanolja.domain.point.entity.PointUsage; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; public interface PointUsageRepository extends JpaRepository, PointUsageCustomRepository { + Page findPageByPointId(Long pointId, Pageable pageable); + } From a8cac024dce39e865fe766f3fda0cffd41edfe3d Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 14:35:49 +0900 Subject: [PATCH 32/45] =?UTF-8?q?#192=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EB=82=B4=EC=97=AD=20=EC=A1=B0=ED=9A=8C=20api=20url?= =?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 --- .../domain/point/controller/PointController.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java index a81b0488..29de7c6d 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java @@ -5,6 +5,7 @@ import com.backoffice.upjuyanolja.domain.point.dto.response.PointChargeResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointSummaryResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointTotalBalanceResponse; +import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsagePageResponse; import com.backoffice.upjuyanolja.domain.point.service.PointService; import com.backoffice.upjuyanolja.global.security.SecurityUtil; import jakarta.validation.Valid; @@ -86,6 +87,19 @@ public ResponseEntity getDetailChargePoints( return ResponseEntity.status(HttpStatus.OK).body(response); } + @GetMapping("/usages") + public ResponseEntity getUsagePoints( + @PageableDefault(page = 0, size = 4) Pageable pageable + ) { + log.info("Get /api/points/usages"); + + PointUsagePageResponse response = pointService.getPointUsagePageResponse( + securityUtil.getCurrentMemberId(), pageable + ); + + return ResponseEntity.status(HttpStatus.OK).body(response); + } + @PostMapping("/charges") public ResponseEntity chargePoint( @Valid @RequestBody PointChargeRequest request From 53550138dff7bf5a1f7fd3ec3018659c0d1439a7 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 14:36:11 +0900 Subject: [PATCH 33/45] =?UTF-8?q?#192=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AC=EC=9A=A9=20=EB=82=B4=EC=97=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/service/PointService.java | 164 ++++++++++++++++-- 1 file changed, 153 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index 5d0bce07..3199521d 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -1,7 +1,11 @@ package com.backoffice.upjuyanolja.domain.point.service; +import com.backoffice.upjuyanolja.domain.accommodation.service.AccommodationCommandService; +import com.backoffice.upjuyanolja.domain.coupon.entity.Coupon; +import com.backoffice.upjuyanolja.domain.coupon.entity.CouponIssuance; import com.backoffice.upjuyanolja.domain.coupon.exception.InsufficientPointsException; +import com.backoffice.upjuyanolja.domain.coupon.service.CouponIssuanceGetService; import com.backoffice.upjuyanolja.domain.member.service.MemberGetService; import com.backoffice.upjuyanolja.domain.point.dto.request.PointChargeRequest; import com.backoffice.upjuyanolja.domain.point.dto.response.PointChargeDetailResponse; @@ -10,6 +14,11 @@ import com.backoffice.upjuyanolja.domain.point.dto.response.PointChargeResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointSummaryResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointTotalBalanceResponse; +import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsageCouponReceiptResponse; +import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsageDetailReceiptResponse; +import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsageDetailResponse; +import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsagePageResponse; +import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsageReceiptResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.TossResponse; import com.backoffice.upjuyanolja.domain.point.entity.Point; import com.backoffice.upjuyanolja.domain.point.entity.PointCategory; @@ -26,6 +35,7 @@ import com.backoffice.upjuyanolja.domain.point.repository.PointRefundsRepository; import com.backoffice.upjuyanolja.domain.point.repository.PointRepository; import com.backoffice.upjuyanolja.domain.point.repository.PointUsageRepository; +import com.backoffice.upjuyanolja.domain.room.entity.Room; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.net.URI; @@ -38,7 +48,11 @@ import java.util.ArrayList; import java.util.Base64; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; +import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; @@ -57,7 +71,10 @@ public class PointService { private final PointRefundsRepository pointRefundsRepository; private final PointUsageRepository pointUsageRepository; + private final AccommodationCommandService accommodationCommandService; + private final CouponIssuanceGetService couponIssuanceGetService; private final MemberGetService memberGetService; + private final ObjectMapper objectMapper; @Value("${point.toss.url}") @@ -89,14 +106,6 @@ public PointTotalBalanceResponse getPointTotalBalanceResponse(Long memberId) { return PointTotalBalanceResponse.of(memberPoint.getTotalPointBalance()); } - @Transactional(readOnly = true) - public PointChargeResponse getDetailChargePointResponse(Long chargeId) { - PointCharges detailchargePoint = pointChargesRepository.findById(chargeId) - .orElseThrow(PointNotFoundException::new); - - return PointChargeResponse.of(detailchargePoint); - } - @Transactional(readOnly = true) public PointChargePageResponse getPointChargePageResponse(Long memberId, Pageable pageable) { Long pointId = getMemberPoint(memberId).getId(); @@ -106,9 +115,10 @@ public PointChargePageResponse getPointChargePageResponse(Long memberId, Pageabl return PointChargePageResponse.of(new PageImpl<>( pointCharges.stream() .map(pointCharge -> PointChargeDetailResponse.of( - pointCharge, getPointChargeCategoryAndType(pointCharge).get(0), - getPointChargeCategoryAndType(pointCharge).get(1), - getPointChargeReceiptResponse(pointCharge)) + pointCharge, getPointChargeCategoryAndType(pointCharge).get(0), + getPointChargeCategoryAndType(pointCharge).get(1), + getPointChargeReceiptResponse(pointCharge) + ) ) .toList(), pageable, @@ -117,6 +127,58 @@ pointCharge, getPointChargeCategoryAndType(pointCharge).get(0), ); } + @Transactional(readOnly = true) + public PointChargeResponse getDetailChargePointResponse(Long chargeId) { + PointCharges detailchargePoint = pointChargesRepository.findById(chargeId) + .orElseThrow(PointNotFoundException::new); + + return PointChargeResponse.of(detailchargePoint); + } + + @Transactional(readOnly = true) + public PointUsagePageResponse getPointUsagePageResponse(Long memberId, Pageable pageable) { + Long pointId = getMemberPoint(memberId).getId(); + Page pointUsages = pointUsageRepository.findPageByPointId(pointId, + pageable); + + return PointUsagePageResponse.of(new PageImpl<>( + pointUsages.stream() + .map(pointUsage -> { + List couponIssuances = + couponIssuanceGetService.getCouponIssuanceByPointUsage(pointUsage); + if(couponIssuances.isEmpty()){ + return PointUsageDetailResponse.builder().build(); + } + Map> couponIssuancesMap = + createCouponIssuancesMap(couponIssuances); + CouponIssuance selectCouponIssuance = couponIssuances.get(0); + String accommodationName = + accommodationCommandService + .findAccommodationByRoomId(selectCouponIssuance.getRoom().getId()) + .getName(); + + return PointUsageDetailResponse.of( + pointUsage, + getPointUsageDescription( + selectCouponIssuance, couponIssuancesMap.keySet().size(), + accommodationName + ), + getPointUsageTrade(couponIssuances), + pointUsage.getOrderPrice(), + getPointUsageReceiptResponse( + pointUsage, accommodationName, + couponIssuancesMap, couponIssuances + ) + ); + } + ) + .toList(), + pageable, + pointUsages.getTotalElements() + ) + ); + } + public PointChargeResponse chargePoint(Long memberId, PointChargeRequest request) { Point memberPoint = getMemberPoint(memberId); TossResponse tossResponse = getTossChargeResponse(request); @@ -296,6 +358,7 @@ private PointChargeReceiptResponse getPointChargeReceiptResponse( switch (pointCharges.getPointStatus()) { case PAID: case USED: + case REMAINED: return PointChargeReceiptResponse.of( pointCharges.getOrderName(), pointCharges.getChargeDate().toString(), @@ -335,6 +398,85 @@ private List getPointChargeCategoryAndType(PointCharges pointCharges) { } + private Map> createCouponIssuancesMap( + List couponIssuances + ) { + return couponIssuances.stream() + .collect(Collectors.groupingBy( + couponIssuance -> couponIssuance.getRoom(), + Collectors.mapping( + couponIssuance -> couponIssuance.getCoupon(), + Collectors.toList() + ) + )); + } + + private String getPointUsageDescription( + CouponIssuance couponIssuance, int size, String accommodationName + ) { + StringBuilder stringBuilder = new StringBuilder(); + + if (size > 2) { + stringBuilder.append( + couponIssuance.getRoom().getName() + " 외 " + String.valueOf(size - 1) + "건" + ); + + } else { + stringBuilder.append(couponIssuance.getRoom().getName()); + } + + stringBuilder.append(" | " + accommodationName); + + return stringBuilder.toString(); + } + + private long getPointUsageTrade(List couponIssuancesMap) { + return couponIssuancesMap.stream() + .mapToLong(CouponIssuance::getQuantity) + .sum(); + } + + private PointUsageReceiptResponse getPointUsageReceiptResponse( + PointUsage pointUsages, String accommodationName, + Map> couponIssuancesMap, List couponIssuances + ) { + return PointUsageReceiptResponse.of( + getPointUsageReceiptOrderId(), pointUsages.getOrderDate().toString(), + accommodationName, getPointUsageDetailReceiptResponse(couponIssuancesMap, couponIssuances) + ); + } + + private String getPointUsageReceiptOrderId() { + return "O-" + ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE); + } + + private List getPointUsageDetailReceiptResponse( + Map> couponIssuanceMaps, List couponIssuances + ) { + return couponIssuanceMaps.entrySet ().stream () + .map(entry -> PointUsageDetailReceiptResponse.of( + entry.getKey().getName(), + getPointUsageCouponReceiptResponse(couponIssuances) + ) + ) + .toList(); + } + + private List getPointUsageCouponReceiptResponse( + List couponIssuances) { + return couponIssuances.stream() + .map(couponIssuance -> { + Coupon coupon = couponIssuance.getCoupon(); + return PointUsageCouponReceiptResponse.of( + coupon.getDiscount() + "원 쿠폰 | " + coupon.getDiscount() / 10 + "p", + couponIssuance.getQuantity(), + couponIssuance.getAmount() + ); + } + ) + .toList(); + } + private String createTossAuthorizations() { String authorizations; From 7e361ca4f669cb993d0c3e398330defd8d55bd0f Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 14:36:34 +0900 Subject: [PATCH 34/45] =?UTF-8?q?#192=20test:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=82=AC=EC=9A=A9=20=EB=82=B4=EC=97=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20http=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../point/select/point-getUsagePoint.http | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getUsagePoint.http diff --git a/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getUsagePoint.http b/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getUsagePoint.http new file mode 100644 index 00000000..6770cd8a --- /dev/null +++ b/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getUsagePoint.http @@ -0,0 +1,18 @@ +POST http://localhost:8080/api/auth/owners/signin +Content-Type: application/json + +{ + "email": "{{email}}", + "password": "{{password}}" +} + +> {% + client.log(response.body.accessToken); + client.global.set("access_token",response.body.accessToken) +%} + +### + +GET http://localhost:8080/api/points/usages +Accept: application/json +Authorization: Bearer {{access_token}} \ No newline at end of file From f159898a79484c86d4f6a471c5e85907865ce428 Mon Sep 17 00:00:00 2001 From: chaewon12 Date: Sat, 27 Jan 2024 15:07:27 +0900 Subject: [PATCH 35/45] =?UTF-8?q?#152=20fix:=20=EC=9E=AC=EA=B3=A0=20?= =?UTF-8?q?=EC=A1=B0=EC=9E=91=20=EC=88=9C=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 --- .../service/ReservationService.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/reservation/service/ReservationService.java b/src/main/java/com/backoffice/upjuyanolja/domain/reservation/service/ReservationService.java index 94e4f6c8..e63f861a 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/reservation/service/ReservationService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/reservation/service/ReservationService.java @@ -68,13 +68,6 @@ public void create(Member currentMember, CreateReservationRequest request) { List roomStocks = getRoomStock(room, request.getStartDate(), request.getEndDate()); - /* - * 객실 재고 수정 - * */ - for (RoomStock roomStock : roomStocks) { - stockService.decreaseRoomStock(roomStock.getId()); //lock - } - /* * 쿠폰 유효성 및 재고 검증 * request.getCouponId() = null 인 경우 스킵 @@ -89,6 +82,17 @@ public void create(Member currentMember, CreateReservationRequest request) { } } + // 할인 금액 계산 + int totalAmount = getValidTotalAmount(request.getTotalPrice(), + room.getPrice().getOffWeekDaysMinFee(), coupon); + + /* + * 객실 재고 수정 + * */ + for (RoomStock roomStock : roomStocks) { + stockService.decreaseRoomStock(roomStock.getId()); //lock + } + /* * 쿠폰 재고 수정 * */ @@ -96,10 +100,6 @@ public void create(Member currentMember, CreateReservationRequest request) { stockService.decreaseCouponStock(coupon.getId()); //lock } - // 할인 금액 계산 - int totalAmount = getValidTotalAmount(request.getTotalPrice(), - room.getPrice().getOffWeekDaysMinFee(), coupon); - /* * 예약 및 결제 저장 * */ From 0e36a6c4eee749dfb356bb68d57936526d8da163 Mon Sep 17 00:00:00 2001 From: JeongUijeong Date: Sat, 27 Jan 2024 15:37:31 +0900 Subject: [PATCH 36/45] =?UTF-8?q?fix:=20=EC=83=81=EC=9C=84=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=EB=8F=84=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/accommodation/service/AccommodationQueryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationQueryService.java b/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationQueryService.java index bbd0108f..24b211c3 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationQueryService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/accommodation/service/AccommodationQueryService.java @@ -80,7 +80,7 @@ public boolean existsOwnershipByMemberAndAccommodation(Member member, @Override @Transactional(readOnly = true) public Category getCategoryByName(String name) { - return categoryRepository.findCategoryByName(name) + return categoryRepository.findCategoryByNameAndIdGreaterThan(name, 4L) .orElseThrow(WrongCategoryException::new); } From e4b5bbcff956f931ab986779e5f06d1ac65874fc Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 16:15:36 +0900 Subject: [PATCH 37/45] =?UTF-8?q?#192=20test:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=84=EC=B2=B4=20=EB=82=B4=EC=97=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20http=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...etTotal.http => point-getTotalBalance.http} | 0 .../point/select/point-getTotalPoint.http | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) rename src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/{point-getTotal.http => point-getTotalBalance.http} (100%) create mode 100644 src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalPoint.http diff --git a/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotal.http b/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalBalance.http similarity index 100% rename from src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotal.http rename to src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalBalance.http diff --git a/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalPoint.http b/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalPoint.http new file mode 100644 index 00000000..02612a81 --- /dev/null +++ b/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalPoint.http @@ -0,0 +1,18 @@ +POST http://localhost:8080/api/auth/owners/signin +Content-Type: application/json + +{ + "email": "{{email}}", + "password": "{{password}}" +} + +> {% + client.log(response.body.accessToken); + client.global.set("access_token",response.body.accessToken) +%} + +### + +GET http://localhost:8080/api/points/total +Accept: application/json +Authorization: Bearer {{access_token}} \ No newline at end of file From 986c2b378afd5db10f96e57a4d507b9811824aa4 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 16:16:17 +0900 Subject: [PATCH 38/45] =?UTF-8?q?#192=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=84=EC=B2=B4=20=EB=82=B4=EC=97=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=9D=91=EB=8B=B5=20dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/PointTotalDetailResponse.java | 55 +++++++++++++++++++ .../dto/response/PointTotalPageResponse.java | 28 ++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalDetailResponse.java create mode 100644 src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalPageResponse.java diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalDetailResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalDetailResponse.java new file mode 100644 index 00000000..686e87eb --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalDetailResponse.java @@ -0,0 +1,55 @@ +package com.backoffice.upjuyanolja.domain.point.dto.response; + +import java.time.LocalDateTime; +import lombok.Builder; + +@Builder +public record PointTotalDetailResponse( + long id, + String category, + String type, + String status, + String name, + String description, + long trade, + long amount, + LocalDateTime date, + Object receipt + +) { + + public static PointTotalDetailResponse of( + String category, String type, String status, + String name, String description, long trade, + long amount, LocalDateTime date, Object receipt + ) { + return PointTotalDetailResponse.builder() + .category(category) + .type(type) + .status(status) + .name(name) + .description(description) + .trade(trade) + .amount(amount) + .date(date) + .receipt(receipt) + .build(); + } + + public static PointTotalDetailResponse from( + long id, PointTotalDetailResponse pointTotalDetailResponse + ) { + return PointTotalDetailResponse.builder() + .id(id) + .category(pointTotalDetailResponse.category) + .type(pointTotalDetailResponse.type) + .status(pointTotalDetailResponse.status) + .name(pointTotalDetailResponse.name) + .description(pointTotalDetailResponse.description) + .trade(pointTotalDetailResponse.trade) + .amount(pointTotalDetailResponse.amount) + .date(pointTotalDetailResponse.date) + .receipt(pointTotalDetailResponse.receipt) + .build(); + } +} diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalPageResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalPageResponse.java new file mode 100644 index 00000000..06681376 --- /dev/null +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalPageResponse.java @@ -0,0 +1,28 @@ +package com.backoffice.upjuyanolja.domain.point.dto.response; + +import java.util.List; +import lombok.Builder; +import org.springframework.data.domain.Page; + +@Builder +public record PointTotalPageResponse( + int pageNum, + int pageSize, + int totalPages, + long totalElements, + boolean isLast, + List histories + +) { + + public static PointTotalPageResponse of(Page responsePage) { + return PointTotalPageResponse.builder() + .pageNum(responsePage.getNumber() + 1) + .pageSize(responsePage.getSize()) + .totalPages(responsePage.getTotalPages()) + .totalElements(responsePage.getTotalElements()) + .isLast(responsePage.isLast()) + .histories(responsePage.getContent()) + .build(); + } +} From 63d540249ababfc8bc05cac576d0fd98fd9e9fe1 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 16:17:01 +0900 Subject: [PATCH 39/45] =?UTF-8?q?#192=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=84=EC=B2=B4=20=EB=82=B4=EC=97=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20api=20url=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20totalP?= =?UTF-8?q?oint=20=EC=A1=B0=ED=9A=8C=20url=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../point/controller/PointController.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java index 29de7c6d..cb3c2969 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java @@ -5,6 +5,7 @@ import com.backoffice.upjuyanolja.domain.point.dto.response.PointChargeResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointSummaryResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointTotalBalanceResponse; +import com.backoffice.upjuyanolja.domain.point.dto.response.PointTotalPageResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsagePageResponse; import com.backoffice.upjuyanolja.domain.point.service.PointService; import com.backoffice.upjuyanolja.global.security.SecurityUtil; @@ -52,9 +53,9 @@ public ResponseEntity getPointSummary( return ResponseEntity.status(HttpStatus.OK).body(response); } - @GetMapping("/total") + @GetMapping("/totalBalance") public ResponseEntity getPointTotalBalance() { - log.info("GET /api/points/total"); + log.info("GET /api/points/totalBalance"); PointTotalBalanceResponse response = pointService.getPointTotalBalanceResponse( securityUtil.getCurrentMemberId() @@ -100,6 +101,19 @@ public ResponseEntity getUsagePoints( return ResponseEntity.status(HttpStatus.OK).body(response); } + @GetMapping("/total") + public ResponseEntity getTotalPoints( + @PageableDefault(page = 0, size = 4) Pageable pageable + ) { + log.info("Get /api/points/total"); + + PointTotalPageResponse response = pointService.getTotalPointPageResponse( + securityUtil.getCurrentMemberId(), pageable + ); + + return ResponseEntity.status(HttpStatus.OK).body(response); + } + @PostMapping("/charges") public ResponseEntity chargePoint( @Valid @RequestBody PointChargeRequest request From 8926b121d22141fccb00303687504c432a6d375c Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 16:18:37 +0900 Subject: [PATCH 40/45] =?UTF-8?q?#192=20feat:=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=84=EC=B2=B4=20=EB=82=B4=EC=97=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/service/PointService.java | 130 +++++++++++++----- 1 file changed, 95 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index 3199521d..c0a63ebb 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -14,6 +14,8 @@ import com.backoffice.upjuyanolja.domain.point.dto.response.PointChargeResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointSummaryResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointTotalBalanceResponse; +import com.backoffice.upjuyanolja.domain.point.dto.response.PointTotalDetailResponse; +import com.backoffice.upjuyanolja.domain.point.dto.response.PointTotalPageResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsageCouponReceiptResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsageDetailReceiptResponse; import com.backoffice.upjuyanolja.domain.point.dto.response.PointUsageDetailResponse; @@ -42,11 +44,13 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Base64; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -142,39 +146,90 @@ public PointUsagePageResponse getPointUsagePageResponse(Long memberId, Pageable pageable); return PointUsagePageResponse.of(new PageImpl<>( - pointUsages.stream() - .map(pointUsage -> { - List couponIssuances = - couponIssuanceGetService.getCouponIssuanceByPointUsage(pointUsage); - if(couponIssuances.isEmpty()){ - return PointUsageDetailResponse.builder().build(); + pointUsages.stream() + .map(pointUsage -> { + List couponIssuances = + couponIssuanceGetService.getCouponIssuanceByPointUsage(pointUsage); + if (couponIssuances.isEmpty()) { + return PointUsageDetailResponse.builder().build(); + } + Map> couponIssuancesMap = + createCouponIssuancesMap(couponIssuances); + CouponIssuance selectCouponIssuance = couponIssuances.get(0); + String accommodationName = + accommodationCommandService + .findAccommodationByRoomId(selectCouponIssuance.getRoom().getId()) + .getName(); + + return PointUsageDetailResponse.of( + pointUsage, + getPointUsageDescription( + selectCouponIssuance, couponIssuancesMap.keySet().size(), + accommodationName + ), + getPointUsageTrade(couponIssuances), + pointUsage.getOrderPrice(), + getPointUsageReceiptResponse( + pointUsage, accommodationName, + couponIssuancesMap, couponIssuances + ) + ); } - Map> couponIssuancesMap = - createCouponIssuancesMap(couponIssuances); - CouponIssuance selectCouponIssuance = couponIssuances.get(0); - String accommodationName = - accommodationCommandService - .findAccommodationByRoomId(selectCouponIssuance.getRoom().getId()) - .getName(); - - return PointUsageDetailResponse.of( - pointUsage, - getPointUsageDescription( - selectCouponIssuance, couponIssuancesMap.keySet().size(), - accommodationName - ), - getPointUsageTrade(couponIssuances), - pointUsage.getOrderPrice(), - getPointUsageReceiptResponse( - pointUsage, accommodationName, - couponIssuancesMap, couponIssuances - ) - ); - } - ) - .toList(), - pageable, - pointUsages.getTotalElements() + ) + .toList(), + pageable, + pointUsages.getTotalElements() + ) + ); + } + + @Transactional(readOnly = true) + public PointTotalPageResponse getTotalPointPageResponse(Long memberId, Pageable pageable) { + Long pointId = getMemberPoint(memberId).getId(); + PointChargePageResponse chargePageResponse = getPointChargePageResponse(memberId, + pageable); + PointUsagePageResponse usagePageResponse = getPointUsagePageResponse(memberId, pageable); + List pointTotalDetailResponses = new ArrayList<>(); + List result = new ArrayList<>(); + long id = 1; + + for (PointChargeDetailResponse charge : chargePageResponse.histories()) { + pointTotalDetailResponses.add(PointTotalDetailResponse.of( + charge.category(), + charge.type(), + charge.status(), + charge.name(), + "", + charge.trade(), + charge.amount(), + LocalDateTime.parse(charge.receipt().tradeAt()), + charge.receipt() + )); + } + for (PointUsageDetailResponse usage : usagePageResponse.histories()) { + pointTotalDetailResponses.add(PointTotalDetailResponse.of( + usage.category(), + usage.type(), + usage.status(), + usage.name(), + usage.description(), + usage.trade(), + usage.amount(), + LocalDateTime.parse(usage.receipt().tradeAt()), + usage.receipt() + )); + } + pointTotalDetailResponses.sort(Comparator.comparing(PointTotalDetailResponse::date)); + for (PointTotalDetailResponse response :pointTotalDetailResponses) { + result.add(PointTotalDetailResponse.from(id++,response)); + } + + + return PointTotalPageResponse.of( + new PageImpl<>( + result, + pageable, + result.size() ) ); } @@ -393,6 +448,10 @@ private List getPointChargeCategoryAndType(PointCharges pointCharges) { results.add(PointCategory.USE.getDescription()); results.add(PointType.POINT.getDescription()); break; + case REMAINED: + results.add(PointCategory.CHARGE.getDescription()); + results.add(PointType.POINT.getDescription()); + break; } return results; @@ -442,7 +501,8 @@ private PointUsageReceiptResponse getPointUsageReceiptResponse( ) { return PointUsageReceiptResponse.of( getPointUsageReceiptOrderId(), pointUsages.getOrderDate().toString(), - accommodationName, getPointUsageDetailReceiptResponse(couponIssuancesMap, couponIssuances) + accommodationName, + getPointUsageDetailReceiptResponse(couponIssuancesMap, couponIssuances) ); } @@ -453,9 +513,9 @@ private String getPointUsageReceiptOrderId() { private List getPointUsageDetailReceiptResponse( Map> couponIssuanceMaps, List couponIssuances ) { - return couponIssuanceMaps.entrySet ().stream () + return couponIssuanceMaps.entrySet().stream() .map(entry -> PointUsageDetailReceiptResponse.of( - entry.getKey().getName(), + entry.getKey().getName(), getPointUsageCouponReceiptResponse(couponIssuances) ) ) From 2877d78909eaece9f8821b0e0adb1c7e7d6a1534 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 16:53:00 +0900 Subject: [PATCH 41/45] =?UTF-8?q?fix:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EB=82=B4=EC=97=AD=EA=B3=BC=20=EA=B2=B9?= =?UTF-8?q?=EC=B9=98=EB=8A=94=20=EC=A0=84=EC=B2=B4=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EA=B8=88=EC=95=A1=20=EC=A1=B0=ED=9A=8C=20url=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 --- .../upjuyanolja/domain/point/controller/PointController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java index cb3c2969..8fc8b353 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java @@ -55,7 +55,7 @@ public ResponseEntity getPointSummary( @GetMapping("/totalBalance") public ResponseEntity getPointTotalBalance() { - log.info("GET /api/points/totalBalance"); + log.info("GET /api/points/total-balance"); PointTotalBalanceResponse response = pointService.getPointTotalBalanceResponse( securityUtil.getCurrentMemberId() From afc7c326fda90e6c874c81ad96dec37d3956ae9d Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 16:53:55 +0900 Subject: [PATCH 42/45] =?UTF-8?q?fix:=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EB=82=B4=EC=97=AD=EA=B3=BC=20=EA=B2=B9?= =?UTF-8?q?=EC=B9=98=EB=8A=94=20=EC=A0=84=EC=B2=B4=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EA=B8=88=EC=95=A1=20=EC=A1=B0=ED=9A=8C=20url=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=EC=9D=84=20log=EB=A7=8C=20=ED=95=98=EA=B3=A0?= =?UTF-8?q?=20Get=EC=97=90=EB=8A=94=20=EC=95=88=20=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../upjuyanolja/domain/point/controller/PointController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java index 8fc8b353..2db11897 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/controller/PointController.java @@ -53,7 +53,7 @@ public ResponseEntity getPointSummary( return ResponseEntity.status(HttpStatus.OK).body(response); } - @GetMapping("/totalBalance") + @GetMapping("/total-balance") public ResponseEntity getPointTotalBalance() { log.info("GET /api/points/total-balance"); From 3bd9bd4c70652c62a640f0c97557ad9749f62d40 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 18:28:32 +0900 Subject: [PATCH 43/45] =?UTF-8?q?refactor:=20=EB=82=A0=EC=A7=9C=EB=A5=BC?= =?UTF-8?q?=20String=20=ED=98=95=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC=ED=95=B4=EC=84=9C=20=EB=8B=A4=EB=A3=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../point/dto/response/PointChargeResponse.java | 3 ++- .../point/dto/response/PointTotalDetailResponse.java | 4 ++-- .../domain/point/service/PointService.java | 12 +++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointChargeResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointChargeResponse.java index 4398b767..8ed66f64 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointChargeResponse.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointChargeResponse.java @@ -1,6 +1,7 @@ package com.backoffice.upjuyanolja.domain.point.dto.response; import com.backoffice.upjuyanolja.domain.point.entity.PointCharges; +import java.time.format.DateTimeFormatter; import lombok.Builder; @Builder @@ -16,7 +17,7 @@ public static PointChargeResponse of( ) { return PointChargeResponse.builder() .orderId(pointCharges.getOrderName()) - .tradeAt(pointCharges.getChargeDate().toString()) + .tradeAt(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(pointCharges.getChargeDate())) .orderName(pointCharges.getChargePoint()+"원") .amount(pointCharges.getChargePoint()) .build(); diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalDetailResponse.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalDetailResponse.java index 686e87eb..b7f35966 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalDetailResponse.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/dto/response/PointTotalDetailResponse.java @@ -13,7 +13,7 @@ public record PointTotalDetailResponse( String description, long trade, long amount, - LocalDateTime date, + String date, Object receipt ) { @@ -21,7 +21,7 @@ public record PointTotalDetailResponse( public static PointTotalDetailResponse of( String category, String type, String status, String name, String description, long trade, - long amount, LocalDateTime date, Object receipt + long amount, String date, Object receipt ) { return PointTotalDetailResponse.builder() .category(category) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index c0a63ebb..c3d0203e 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -48,6 +48,7 @@ import java.time.LocalDateTime; import java.time.YearMonth; import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Base64; import java.util.Comparator; @@ -202,7 +203,7 @@ public PointTotalPageResponse getTotalPointPageResponse(Long memberId, Pageable "", charge.trade(), charge.amount(), - LocalDateTime.parse(charge.receipt().tradeAt()), + charge.receipt().tradeAt(), charge.receipt() )); } @@ -215,7 +216,7 @@ public PointTotalPageResponse getTotalPointPageResponse(Long memberId, Pageable usage.description(), usage.trade(), usage.amount(), - LocalDateTime.parse(usage.receipt().tradeAt()), + usage.receipt().tradeAt(), usage.receipt() )); } @@ -416,14 +417,14 @@ private PointChargeReceiptResponse getPointChargeReceiptResponse( case REMAINED: return PointChargeReceiptResponse.of( pointCharges.getOrderName(), - pointCharges.getChargeDate().toString(), + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(pointCharges.getChargeDate()), pointCharges.getChargePoint() ); case CANCELED: PointRefunds pointRefund = pointRefundsRepository.findByPointCharges(pointCharges); return PointChargeReceiptResponse.of( pointCharges.getOrderName(), - pointRefund.getRefundDate().toString(), + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(pointRefund.getRefundDate()), pointCharges.getChargePoint() ); default: @@ -500,7 +501,8 @@ private PointUsageReceiptResponse getPointUsageReceiptResponse( Map> couponIssuancesMap, List couponIssuances ) { return PointUsageReceiptResponse.of( - getPointUsageReceiptOrderId(), pointUsages.getOrderDate().toString(), + getPointUsageReceiptOrderId(), + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(pointUsages.getOrderDate()), accommodationName, getPointUsageDetailReceiptResponse(couponIssuancesMap, couponIssuances) ); From 87d4768e774dad81caf3cefb458ad84d8a71c8fd Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 18:35:46 +0900 Subject: [PATCH 44/45] =?UTF-8?q?test:=20total-balance=20http=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20url=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 --- .../httpTest/point/select/point-getTotalBalance.http | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalBalance.http b/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalBalance.http index f07902e6..8c20a816 100644 --- a/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalBalance.http +++ b/src/test/java/com/backoffice/upjuyanolja/httpTest/point/select/point-getTotalBalance.http @@ -13,6 +13,6 @@ Content-Type: application/json ### -GET http://localhost:8080/api/points/total +GET http://localhost:8080/api/points/total-balance Accept: application/json Authorization: Bearer {{access_token}} \ No newline at end of file From 96e22790bebc0c2116e998ea6ca738c728c8abd6 Mon Sep 17 00:00:00 2001 From: HyunA Date: Sat, 27 Jan 2024 20:40:24 +0900 Subject: [PATCH 45/45] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=20=EC=BF=A0?= =?UTF-8?q?=ED=8F=B0=EC=9D=84=20=EB=B3=B4=EC=97=AC=EC=A4=84=20=EB=95=8C=20?= =?UTF-8?q?=ED=95=B4=EB=8B=B9=20=ED=95=98=EB=8A=94=20room=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EA=B1=B8=EB=9F=AC=EC=95=BC=20=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/point/service/PointService.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java index c0a63ebb..9d548220 100644 --- a/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java +++ b/src/main/java/com/backoffice/upjuyanolja/domain/point/service/PointService.java @@ -44,7 +44,6 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; -import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; import java.time.ZonedDateTime; @@ -53,7 +52,6 @@ import java.util.Comparator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Optional; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; @@ -220,11 +218,10 @@ public PointTotalPageResponse getTotalPointPageResponse(Long memberId, Pageable )); } pointTotalDetailResponses.sort(Comparator.comparing(PointTotalDetailResponse::date)); - for (PointTotalDetailResponse response :pointTotalDetailResponses) { - result.add(PointTotalDetailResponse.from(id++,response)); + for (PointTotalDetailResponse response : pointTotalDetailResponses) { + result.add(PointTotalDetailResponse.from(id++, response)); } - return PointTotalPageResponse.of( new PageImpl<>( result, @@ -516,15 +513,16 @@ private List getPointUsageDetailReceiptResponse return couponIssuanceMaps.entrySet().stream() .map(entry -> PointUsageDetailReceiptResponse.of( entry.getKey().getName(), - getPointUsageCouponReceiptResponse(couponIssuances) + getPointUsageCouponReceiptResponse(entry.getKey(), couponIssuances) ) ) .toList(); } private List getPointUsageCouponReceiptResponse( - List couponIssuances) { + Room room, List couponIssuances) { return couponIssuances.stream() + .filter(couponIssuance -> couponIssuance.getRoom().equals(room)) .map(couponIssuance -> { Coupon coupon = couponIssuance.getCoupon(); return PointUsageCouponReceiptResponse.of(