diff --git a/src/main/java/balancetalk/module/post/domain/Post.java b/src/main/java/balancetalk/module/post/domain/Post.java index 44acca933..903e2a5f2 100644 --- a/src/main/java/balancetalk/module/post/domain/Post.java +++ b/src/main/java/balancetalk/module/post/domain/Post.java @@ -7,13 +7,17 @@ import balancetalk.module.member.domain.Member; import balancetalk.module.report.domain.Report; import jakarta.persistence.*; -import jakarta.validation.constraints.*; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.PositiveOrZero; +import jakarta.validation.constraints.Size; import lombok.*; import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.Formula; + import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; -import org.hibernate.annotations.Formula; @Entity @Getter @@ -93,7 +97,7 @@ public long commentsCount() { } return comments.size(); } - + @PrePersist public void init() { this.views = 0L; @@ -115,4 +119,8 @@ public boolean hasDeadlineExpired() { public void increaseViews() { views++; } + + public boolean isClosed() { + return LocalDateTime.now().isAfter(deadline); + } } diff --git a/src/main/java/balancetalk/module/post/dto/PostResponse.java b/src/main/java/balancetalk/module/post/dto/PostResponse.java index 21cd23f6b..64e9e5019 100644 --- a/src/main/java/balancetalk/module/post/dto/PostResponse.java +++ b/src/main/java/balancetalk/module/post/dto/PostResponse.java @@ -1,6 +1,5 @@ package balancetalk.module.post.dto; -import balancetalk.module.ViewStatus; import balancetalk.module.file.domain.File; import balancetalk.module.member.domain.Member; import balancetalk.module.post.domain.BalanceOption; @@ -8,7 +7,10 @@ import balancetalk.module.post.domain.PostCategory; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; + import java.time.LocalDateTime; import java.util.Collections; import java.util.List; @@ -30,6 +32,9 @@ public class PostResponse { @Schema(description = "투료 종료 기한", example = "2024/12/25 15:30:00") private LocalDateTime deadline; + @Schema(description = "마감 여부", example = "true") + private Boolean isClosed; + @Schema(description = "게시글 조회수", example = "126") private long views; @@ -86,6 +91,7 @@ public static PostResponse fromEntity(Post post, Member member, boolean myLike, .id(post.getId()) .title(post.getTitle()) .deadline(post.getDeadline()) + .isClosed(post.isClosed()) .views(post.getViews()) // .viewStatus(post.getViewStatus()) .likesCount(post.likesCount()) @@ -140,11 +146,11 @@ private static Long getSelectedOptionId(Post post, Member member) { .orElse(null); } - private static int getTotalVotes (Post post){ - return Optional.ofNullable(post.getOptions()) - .map(options -> options.stream() - .mapToInt(option -> Optional.ofNullable(option.getVotes()).map(List::size).orElse(0)) - .sum()) - .orElse(0); + private static int getTotalVotes(Post post) { + return Optional.ofNullable(post.getOptions()) + .map(options -> options.stream() + .mapToInt(option -> Optional.ofNullable(option.getVotes()).map(List::size).orElse(0)) + .sum()) + .orElse(0); } }