Skip to content

Commit

Permalink
feat: 공모 테이블에 할인율과 상태 필드 추가 (#342)
Browse files Browse the repository at this point in the history
* refactor: Condition과 Status 이름 변경

* refactor: 사용하지 않는 DTO 제거

* feat: OfferingEntity에 칼럼 추가
  • Loading branch information
masonkimseoul authored Aug 14, 2024
1 parent d32a53d commit e036152
Show file tree
Hide file tree
Showing 15 changed files with 518 additions and 519 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public CommentRoomInfoResponse getCommentRoomInfo(Long offeringId, MemberEntity
OfferingEntity offering = offeringRepository.findById(offeringId)
.orElseThrow(() -> new MarketException(OfferingErrorCode.NOT_FOUND));
validateIsJoined(member, offering);
if (offering.isStatusGrouping() && offering.toOfferingStatus().isAutoConfirmed()) {
if (offering.isStatusGrouping() && offering.toOfferingCondition().isAutoConfirmed()) {
offering.moveStatus();
}
return new CommentRoomInfoResponse(offering, member);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,66 @@
package com.zzang.chongdae.offering.domain;

public enum OfferingCondition {
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;

FULL,
IMMINENT,
CONFIRMED,
AVAILABLE;
@Getter
@AllArgsConstructor
public class OfferingCondition {

public static OfferingCondition decideBy(OfferingStatus offeringStatus) {
if (offeringStatus.isManualConfirmed() || offeringStatus.isAutoConfirmed()
|| (offeringStatus.isDeadlineOver() && offeringStatus.isCountNotFull())) {
return CONFIRMED;
}
if (offeringStatus.isCountFull() && offeringStatus.isDeadlineNotOver()) {
return FULL;
}
if (offeringStatus.isCountAlmostFull() || offeringStatus.isDeadlineAlmostOver()) {
return IMMINENT;
private final LocalDateTime deadline;
private final int totalCount;
private final boolean isManualConfirmed;
private final int currentCount;

public OfferingStatus decideOfferingStatus() {
return OfferingStatus.decideBy(this);
}

public boolean isCountFull() {
return this.totalCount == this.currentCount;
}

public boolean isCountNotFull() {
return !isCountFull();
}

public boolean isCountAlmostFull() {
if (totalCount <= 3) {
return (totalCount - currentCount) < 2;
}
return AVAILABLE;
return (totalCount - currentCount) < 3;
}

public boolean isDeadlineAlmostOver() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime threshold = deadline.minusHours(6);
return threshold.isBefore(now) && now.isBefore(deadline); // deadline - 6 < now < deadline
}

public boolean isDeadlineOver() {
LocalDateTime now = LocalDateTime.now();
return now.isAfter(this.deadline) || now.isEqual(this.deadline);
}

public boolean isDeadlineNotOver() {
return LocalDateTime.now().isBefore(this.deadline);
}

public boolean isAutoConfirmed() {
return isCountFull() && isDeadlineOver();
}

public boolean isManualConfirmed() {
return isManualConfirmed;
}

public boolean isOpen() {
return this == AVAILABLE || this == IMMINENT;
OfferingStatus offeringStatus = decideOfferingStatus();
return offeringStatus.isOpen();
}

public boolean isClosed() {
return !isOpen();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public int calculateDividedPrice() {
public double calculateDiscountRate() {
return (double) (originPrice - totalPrice / totalCount) / originPrice;
}
// TODO : 소수점 밑 둘째 자리에서 반올림

public void validateOriginPrice() {
int dividedPrice = totalPrice / totalCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,27 @@
package com.zzang.chongdae.offering.domain;

import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
public enum OfferingStatus {

@Getter
@AllArgsConstructor
public class OfferingStatus {
FULL,
IMMINENT,
CONFIRMED,
AVAILABLE;

private final LocalDateTime deadline;
private final int totalCount;
private final boolean isManualConfirmed;
private final int currentCount;

public OfferingCondition decideOfferingCondition() {
return OfferingCondition.decideBy(this);
}

public boolean isCountFull() {
return this.totalCount == this.currentCount;
}

public boolean isCountNotFull() {
return !isCountFull();
}

public boolean isCountAlmostFull() {
if (totalCount <= 3) {
return (totalCount - currentCount) < 2;
public static OfferingStatus decideBy(OfferingCondition offeringCondition) {
if (offeringCondition.isManualConfirmed() || offeringCondition.isAutoConfirmed()
|| (offeringCondition.isDeadlineOver() && offeringCondition.isCountNotFull())) {
return CONFIRMED;
}
return (totalCount - currentCount) < 3;
}

public boolean isDeadlineAlmostOver() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime threshold = deadline.minusHours(6);
return threshold.isBefore(now) && now.isBefore(deadline); // deadline - 6 < now < deadline
}

public boolean isDeadlineOver() {
LocalDateTime now = LocalDateTime.now();
return now.isAfter(this.deadline) || now.isEqual(this.deadline);
}

public boolean isDeadlineNotOver() {
return LocalDateTime.now().isBefore(this.deadline);
}

public boolean isAutoConfirmed() {
return isCountFull() && isDeadlineOver();
}

public boolean isManualConfirmed() {
return isManualConfirmed;
if (offeringCondition.isCountFull() && offeringCondition.isDeadlineNotOver()) {
return FULL;
}
if (offeringCondition.isCountAlmostFull() || offeringCondition.isDeadlineAlmostOver()) {
return IMMINENT;
}
return AVAILABLE;
}

public boolean isOpen() {
OfferingCondition offeringCondition = decideOfferingCondition();
return offeringCondition.isOpen();
}

public boolean isClosed() {
return !isOpen();
return this == AVAILABLE || this == IMMINENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.zzang.chongdae.offering.domain.CommentRoomStatus;
import com.zzang.chongdae.offering.domain.OfferingMeeting;
import com.zzang.chongdae.offering.domain.OfferingPrice;
import com.zzang.chongdae.offering.domain.OfferingCondition;
import com.zzang.chongdae.offering.domain.OfferingStatus;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class OfferingEntity extends BaseTimeEntity {

private String meetingAddressDetail;

private String meetingAddressDong; // TODO: nullable?
private String meetingAddressDong;

@NotNull
@Positive
Expand All @@ -83,6 +84,13 @@ public class OfferingEntity extends BaseTimeEntity {
@Positive
private Integer originPrice;

@Positive
private Double discountRate;

@NotNull
@Enumerated(EnumType.STRING)
private OfferingStatus offeringStatus;

@NotNull
@Enumerated(EnumType.STRING)
private CommentRoomStatus roomStatus;
Expand All @@ -91,10 +99,11 @@ public OfferingEntity(MemberEntity member, String title, String description, Str
LocalDateTime deadline, String meetingAddress, String meetingAddressDetail,
String meetingAddressDong,
Integer totalCount, Integer currentCount, Boolean isManualConfirmed, Integer totalPrice,
Integer originPrice, CommentRoomStatus roomStatus) {
Integer originPrice, Double discountRate,
OfferingStatus offeringStatus, CommentRoomStatus roomStatus) {
this(null, member, title, description, thumbnailUrl, productUrl, deadline, meetingAddress,
meetingAddressDetail, meetingAddressDong, totalCount, currentCount, isManualConfirmed, totalPrice,
originPrice, roomStatus);
originPrice, discountRate, offeringStatus, roomStatus);
}

public void participate() {
Expand All @@ -118,8 +127,8 @@ public OfferingPrice toOfferingPrice() {
return new OfferingPrice(totalCount, totalPrice, originPrice);
}

public OfferingStatus toOfferingStatus() {
return new OfferingStatus(deadline, totalCount, isManualConfirmed, currentCount);
public OfferingCondition toOfferingCondition() {
return new OfferingCondition(deadline, totalCount, isManualConfirmed, currentCount);
}

public OfferingMeeting toOfferingMeeting() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.zzang.chongdae.offering.domain.OfferingFilter;
import com.zzang.chongdae.offering.domain.OfferingMeeting;
import com.zzang.chongdae.offering.domain.OfferingPrice;
import com.zzang.chongdae.offering.domain.OfferingStatus;
import com.zzang.chongdae.offering.domain.OfferingCondition;
import com.zzang.chongdae.offering.exception.OfferingErrorCode;
import com.zzang.chongdae.offering.repository.OfferingRepository;
import com.zzang.chongdae.offering.repository.entity.OfferingEntity;
Expand Down Expand Up @@ -46,10 +46,10 @@ public OfferingDetailResponse getOfferingDetail(Long offeringId, MemberEntity me
OfferingEntity offering = offeringRepository.findById(offeringId)
.orElseThrow(() -> new MarketException(OfferingErrorCode.NOT_FOUND));
OfferingPrice offeringPrice = offering.toOfferingPrice();
OfferingStatus offeringStatus = offering.toOfferingStatus();
OfferingCondition offeringCondition = offering.toOfferingCondition();
Boolean isProposer = offering.isProposedBy(member); // TODO: 추후 도메인으로 분리
Boolean isParticipated = offeringMemberRepository.existsByOfferingAndMember(offering, member);
return new OfferingDetailResponse(offering, offeringPrice, offeringStatus, isProposer, isParticipated);
return new OfferingDetailResponse(offering, offeringPrice, offeringCondition, isProposer, isParticipated);
}

public OfferingAllResponse getAllOffering(String filterName, String searchKeyword, Long lastId, Integer pageSize) {
Expand All @@ -59,8 +59,8 @@ public OfferingAllResponse getAllOffering(String filterName, String searchKeywor
return new OfferingAllResponse(offerings.stream()
.map(offering -> {
OfferingPrice offeringPrice = offering.toOfferingPrice();
OfferingStatus offeringStatus = offering.toOfferingStatus();
return new OfferingAllResponseItem(offering, offeringPrice, offeringStatus);
OfferingCondition offeringCondition = offering.toOfferingCondition();
return new OfferingAllResponseItem(offering, offeringPrice, offeringCondition);
})
.toList()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.zzang.chongdae.offering.service.dto;

import com.zzang.chongdae.offering.domain.OfferingCondition;
import com.zzang.chongdae.offering.domain.OfferingPrice;
import com.zzang.chongdae.offering.domain.OfferingStatus;
import com.zzang.chongdae.offering.domain.OfferingPrice;
import com.zzang.chongdae.offering.domain.OfferingCondition;
import com.zzang.chongdae.offering.repository.entity.OfferingEntity;

public record OfferingAllResponseItem(Long id,
Expand All @@ -13,21 +13,21 @@ public record OfferingAllResponseItem(Long id,
String thumbnailUrl,
Integer dividedPrice,
Integer originPrice,
OfferingCondition condition,
OfferingStatus status,
Boolean isOpen) {

public OfferingAllResponseItem(
OfferingEntity offering, OfferingPrice offeringPrice, OfferingStatus offeringStatus) {
OfferingEntity offering, OfferingPrice offeringPrice, OfferingCondition offeringCondition) {
this(offering.getId(),
offering.getTitle(),
offering.getMeetingAddressDong(),
offeringStatus.getCurrentCount(),
offeringCondition.getCurrentCount(),
offering.getTotalCount(),
offering.getThumbnailUrl(),
offeringPrice.calculateDividedPrice(),
offeringPrice.getOriginPrice(),
offeringStatus.decideOfferingCondition(),
offeringStatus.isOpen()
offeringCondition.decideOfferingStatus(),
offeringCondition.isOpen()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.zzang.chongdae.offering.service.dto;

import com.zzang.chongdae.offering.domain.OfferingCondition;
import com.zzang.chongdae.offering.domain.OfferingPrice;
import com.zzang.chongdae.offering.domain.OfferingStatus;
import com.zzang.chongdae.offering.domain.OfferingPrice;
import com.zzang.chongdae.offering.domain.OfferingCondition;
import com.zzang.chongdae.offering.repository.entity.OfferingEntity;
import java.time.LocalDateTime;

Expand All @@ -18,15 +18,15 @@ public record OfferingDetailResponse(Long id,
String thumbnailUrl,
Integer dividedPrice,
Integer totalPrice,
OfferingCondition condition,
OfferingStatus status,
Long memberId,
String nickname,
Boolean isProposer,
Boolean isParticipated) {

public OfferingDetailResponse(OfferingEntity offering,
OfferingPrice offeringPrice,
OfferingStatus offeringStatus,
OfferingCondition offeringCondition,
Boolean isProposer,
Boolean isParticipated) {
this(offering.getId(),
Expand All @@ -36,12 +36,12 @@ public OfferingDetailResponse(OfferingEntity offering,
offering.getMeetingAddressDetail(),
offering.getDescription(),
offering.getDeadline(),
offeringStatus.getCurrentCount(),
offeringCondition.getCurrentCount(),
offering.getTotalCount(),
offering.getThumbnailUrl(),
offeringPrice.calculateDividedPrice(),
offering.getTotalPrice(),
offeringStatus.decideOfferingCondition(),
offeringCondition.decideOfferingStatus(),
offering.getMember().getId(),
offering.getMember().getNickname(),
isProposer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.zzang.chongdae.offering.service.dto;

import static com.zzang.chongdae.offering.domain.CommentRoomStatus.GROUPING;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zzang.chongdae.member.repository.entity.MemberEntity;
import com.zzang.chongdae.offering.domain.CommentRoomStatus;
import com.zzang.chongdae.offering.domain.OfferingStatus;
import com.zzang.chongdae.offering.repository.entity.OfferingEntity;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down Expand Up @@ -41,6 +41,7 @@ public record OfferingSaveRequest(@NotBlank
public OfferingEntity toEntity(MemberEntity member) {
return new OfferingEntity(member, title, description, thumbnailUrl, productUrl, deadline, meetingAddress,
meetingAddressDetail, meetingAddressDong, totalCount, 1, false,
totalPrice, originPrice, GROUPING);
totalPrice, originPrice, 33.3, OfferingStatus.AVAILABLE, CommentRoomStatus.GROUPING);
// TODO : 각자 맡은 팀에서 계산하는 로직 생각하기, 객체로 빼서 만드셈~
}
}

This file was deleted.

Loading

0 comments on commit e036152

Please sign in to comment.