PostVo.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package space.anyi.serve.entity.post;
  2. import io.swagger.v3.oas.annotations.media.Schema;
  3. import java.math.BigDecimal;
  4. import java.time.LocalDateTime;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. @Schema(description = "帖子响应视图")
  8. public class PostVo {
  9. private String id;
  10. private String expertId;
  11. private String expertName;
  12. private String expertAvatar;
  13. private String title;
  14. private String contentIntro;
  15. private String contentPaid;
  16. private BigDecimal price;
  17. private String hitStatus;
  18. private Integer viewCount;
  19. private Boolean isPublic;
  20. private Boolean isPaid;
  21. private LocalDateTime publishTime;
  22. private LocalDateTime expireTime;
  23. public static PostVo from(Post post) {
  24. if (post == null) return null;
  25. PostVo vo = new PostVo();
  26. vo.setId(post.getId().toString());
  27. vo.setExpertId(post.getExpertId().toString());
  28. vo.setTitle(post.getTitle());
  29. vo.setContentIntro(post.getContentIntro());
  30. vo.setContentPaid(post.getContentPaid());
  31. vo.setPrice(post.getPrice());
  32. vo.setHitStatus(post.getHitStatus());
  33. vo.setViewCount(post.getViewCount());
  34. vo.setPublishTime(post.getPublishTime());
  35. vo.setExpireTime(post.getExpireTime());
  36. vo.setIsPublic(LocalDateTime.now().isAfter(post.getExpireTime()));
  37. return vo;
  38. }
  39. public static List<PostVo> from(List<Post> list) {
  40. List<PostVo> res = new ArrayList<>();
  41. for (Post p : list) res.add(from(p));
  42. return res;
  43. }
  44. public String getId() { return id; }
  45. public void setId(String id) { this.id = id; }
  46. public String getExpertId() { return expertId; }
  47. public void setExpertId(String expertId) { this.expertId = expertId; }
  48. public String getExpertName() { return expertName; }
  49. public void setExpertName(String expertName) { this.expertName = expertName; }
  50. public String getExpertAvatar() { return expertAvatar; }
  51. public void setExpertAvatar(String expertAvatar) { this.expertAvatar = expertAvatar; }
  52. public String getTitle() { return title; }
  53. public void setTitle(String title) { this.title = title; }
  54. public String getContentIntro() { return contentIntro; }
  55. public void setContentIntro(String contentIntro) { this.contentIntro = contentIntro; }
  56. public String getContentPaid() { return contentPaid; }
  57. public void setContentPaid(String contentPaid) { this.contentPaid = contentPaid; }
  58. public BigDecimal getPrice() { return price; }
  59. public void setPrice(BigDecimal price) { this.price = price; }
  60. public String getHitStatus() { return hitStatus; }
  61. public void setHitStatus(String hitStatus) { this.hitStatus = hitStatus; }
  62. public Integer getViewCount() { return viewCount; }
  63. public void setViewCount(Integer viewCount) { this.viewCount = viewCount; }
  64. public Boolean getIsPublic() { return isPublic; }
  65. public void setIsPublic(Boolean isPublic) { this.isPublic = isPublic; }
  66. public Boolean getIsPaid() { return isPaid; }
  67. public void setIsPaid(Boolean isPaid) { this.isPaid = isPaid; }
  68. public LocalDateTime getPublishTime() { return publishTime; }
  69. public void setPublishTime(LocalDateTime publishTime) { this.publishTime = publishTime; }
  70. public LocalDateTime getExpireTime() { return expireTime; }
  71. public void setExpireTime(LocalDateTime expireTime) { this.expireTime = expireTime; }
  72. }