11package com .dreamypatisiel .devdevdev .domain .entity ;
22
33import com .dreamypatisiel .devdevdev .domain .entity .embedded .Count ;
4+ import com .dreamypatisiel .devdevdev .domain .entity .embedded .Title ;
45import com .dreamypatisiel .devdevdev .domain .entity .embedded .Url ;
56import com .dreamypatisiel .devdevdev .domain .policy .TechArticlePopularScorePolicy ;
67import com .dreamypatisiel .devdevdev .elastic .domain .document .ElasticTechArticle ;
@@ -35,6 +36,8 @@ public class TechArticle extends BasicTime {
3536 @ GeneratedValue (strategy = GenerationType .IDENTITY )
3637 private Long id ;
3738
39+ private Title title ;
40+
3841 @ Embedded
3942 @ AttributeOverride (name = "count" ,
4043 column = @ Column (name = "view_total_count" )
@@ -75,9 +78,14 @@ public class TechArticle extends BasicTime {
7578 @ OneToMany (mappedBy = "techArticle" )
7679 private List <Bookmark > bookmarks = new ArrayList <>();
7780
81+ @ OneToMany (mappedBy = "techArticle" )
82+ private List <TechArticleRecommend > recommends = new ArrayList <>();
83+
7884 @ Builder
79- private TechArticle (Count viewTotalCount , Count recommendTotalCount , Count commentTotalCount , Count popularScore ,
85+ private TechArticle (Title title , Count viewTotalCount , Count recommendTotalCount , Count commentTotalCount ,
86+ Count popularScore ,
8087 Url techArticleUrl , Company company , String elasticId ) {
88+ this .title = title ;
8189 this .techArticleUrl = techArticleUrl ;
8290 this .viewTotalCount = viewTotalCount ;
8391 this .recommendTotalCount = recommendTotalCount ;
@@ -89,6 +97,7 @@ private TechArticle(Count viewTotalCount, Count recommendTotalCount, Count comme
8997
9098 public static TechArticle createTechArticle (ElasticTechArticle elasticTechArticle , Company company ) {
9199 TechArticle techArticle = TechArticle .builder ()
100+ .title (new Title (elasticTechArticle .getTitle ()))
92101 .techArticleUrl (new Url (elasticTechArticle .getTechArticleUrl ()))
93102 .viewTotalCount (new Count (elasticTechArticle .getViewTotalCount ()))
94103 .recommendTotalCount (new Count (elasticTechArticle .getRecommendTotalCount ()))
@@ -102,10 +111,11 @@ public static TechArticle createTechArticle(ElasticTechArticle elasticTechArticl
102111 return techArticle ;
103112 }
104113
105- public static TechArticle createTechArticle (Url techArticleUrl , Count viewTotalCount , Count recommendTotalCount ,
106- Count commentTotalCount ,
107- Count popularScore , String elasticId , Company company ) {
114+ public static TechArticle createTechArticle (Title title , Url techArticleUrl , Count viewTotalCount ,
115+ Count recommendTotalCount , Count commentTotalCount , Count popularScore ,
116+ String elasticId , Company company ) {
108117 return TechArticle .builder ()
118+ .title (title )
109119 .techArticleUrl (techArticleUrl )
110120 .viewTotalCount (viewTotalCount )
111121 .recommendTotalCount (recommendTotalCount )
@@ -127,6 +137,10 @@ public void changePopularScore(TechArticlePopularScorePolicy policy) {
127137 this .popularScore = this .calculatePopularScore (policy );
128138 }
129139
140+ private Count calculatePopularScore (TechArticlePopularScorePolicy policy ) {
141+ return policy .calculatePopularScore (this );
142+ }
143+
130144 public void changeCompany (Company company ) {
131145 company .getTechArticles ().add (this );
132146 this .company = company ;
@@ -136,15 +150,20 @@ public void incrementViewTotalCount() {
136150 this .viewTotalCount = Count .plusOne (this .viewTotalCount );
137151 }
138152
139- private Count calculatePopularScore (TechArticlePopularScorePolicy policy ) {
140- return policy .calculatePopularScore (this );
141- }
142-
143153 public void incrementCommentCount () {
144154 this .commentTotalCount = Count .plusOne (this .commentTotalCount );
145155 }
146156
147157 public void decrementCommentCount () {
148158 this .commentTotalCount = Count .minusOne (this .commentTotalCount );
149159 }
160+
161+
162+ public void incrementRecommendTotalCount () {
163+ this .recommendTotalCount = Count .plusOne (this .recommendTotalCount );
164+ }
165+
166+ public void decrementRecommendTotalCount () {
167+ this .recommendTotalCount = Count .minusOne (this .recommendTotalCount );
168+ }
150169}
0 commit comments