31
31
import java .util .Date ;
32
32
import java .util .List ;
33
33
import java .util .Locale ;
34
+ import java .util .Optional ;
34
35
import java .util .Set ;
35
36
36
37
// FIXME: move stamps related methods to separate interface (#88)
@@ -53,7 +54,7 @@ public class SeriesServiceImpl implements SeriesService {
53
54
@ Override
54
55
@ Transactional
55
56
@ PreAuthorize (HasAuthority .CREATE_SERIES )
56
- public Integer add (AddSeriesDto dto , Integer userId , boolean userCanAddComments ) {
57
+ public Integer add (AddSeriesDto dto , Integer userId ) {
57
58
Validate .isTrue (dto != null , "DTO must be non null" );
58
59
Validate .isTrue (dto .getQuantity () != null , "Quantity must be non null" );
59
60
Validate .isTrue (dto .getPerforated () != null , "Perforated property must be non null" );
@@ -79,15 +80,6 @@ public Integer add(AddSeriesDto dto, Integer userId, boolean userCanAddComments)
79
80
series .setSolovyovPrice (dto .getSolovyovPrice ());
80
81
series .setZagorskiPrice (dto .getZagorskiPrice ());
81
82
82
- if (userCanAddComments && dto .getComment () != null ) {
83
- Validate .isTrue (
84
- !dto .getComment ().trim ().isEmpty (),
85
- "Comment must be non empty"
86
- );
87
-
88
- series .setComment (dto .getComment ());
89
- }
90
-
91
83
Date now = new Date ();
92
84
series .setCreatedAt (now );
93
85
series .setUpdatedAt (now );
@@ -123,17 +115,26 @@ public Integer add(AddSeriesDto dto, Integer userId, boolean userCanAddComments)
123
115
@ Override
124
116
@ Transactional
125
117
@ PreAuthorize (HasAuthority .ADD_COMMENTS_TO_SERIES )
126
- public void addComment (Integer seriesId , String comment ) {
118
+ public void addComment (Integer seriesId , String comment , Integer userId ) {
127
119
Validate .isTrue (seriesId != null , "Series id must be non null" );
128
120
Validate .isTrue (comment != null , "Comment must be non null" );
129
121
Validate .isTrue (!comment .trim ().isEmpty (), "Comment must be non empty" );
122
+ Validate .isTrue (userId != null , "User id must be non null" );
130
123
131
- // We don't touch updated_at/updated_by fields because:
132
- // - a comment is a meta information that is visible only by admins.
133
- // From user's point of view, this field doesn't exist
124
+ // We don't need to modify series.updated_at/updated_by fields because:
125
+ // - a comment is a meta information that is invisible publicly
134
126
// - updated_at field is used by logic for sitemap.xml generation
135
127
// and we don't want to affect this
136
- seriesDao .addComment (seriesId , comment );
128
+ AddCommentDbDto dto = new AddCommentDbDto ();
129
+ dto .setSeriesId (seriesId );
130
+ dto .setUserId (userId );
131
+ dto .setComment (comment );
132
+
133
+ Date now = new Date ();
134
+ dto .setCreatedAt (now );
135
+ dto .setUpdatedAt (now );
136
+
137
+ seriesDao .addComment (dto );
137
138
138
139
log .info ("Series #{}: a comment has been added" , seriesId );
139
140
}
@@ -307,12 +308,18 @@ public Integer findQuantityById(Integer seriesId) {
307
308
@ Transactional (readOnly = true )
308
309
public SeriesDto findFullInfoById (
309
310
Integer seriesId ,
311
+ Integer userId ,
310
312
String lang ,
311
313
boolean userCanSeeHiddenImages ) {
312
314
313
315
Validate .isTrue (seriesId != null , "Series id must be non null" );
314
316
315
- SeriesFullInfoDto seriesBaseInfo = seriesDao .findByIdAsSeriesFullInfo (seriesId , lang );
317
+ // @todo #1505 Don't load a series comment for anonymous users
318
+ SeriesFullInfoDto seriesBaseInfo = seriesDao .findByIdAsSeriesFullInfo (
319
+ seriesId ,
320
+ Optional .ofNullable (userId ).orElse (0 ),
321
+ lang
322
+ );
316
323
if (seriesBaseInfo == null ) {
317
324
return null ;
318
325
}
0 commit comments