16
16
import org .springframework .jms .core .JmsTemplate ;
17
17
import org .springframework .stereotype .Service ;
18
18
import org .springframework .transaction .annotation .Transactional ;
19
+ import org .springframework .transaction .support .TransactionTemplate ;
19
20
import org .springframework .web .multipart .MultipartFile ;
20
21
21
22
import java .util .ArrayList ;
26
27
@ Service
27
28
@ Slf4j
28
29
@ RequiredArgsConstructor
29
- @ Transactional
30
30
public class ArticleService {
31
31
32
32
private static final ReceivedFile .FileGroup FILE_GROUP = ReceivedFile .FileGroup .NOTE_ATTACHMENT ;
@@ -36,6 +36,7 @@ public class ArticleService {
36
36
private final CommentRepository commentRepo ;
37
37
private final ContentCheckService contentCheckService ;
38
38
private final WebsocketHandler websocketHandler ;
39
+ private final TransactionTemplate transactionTemplate ;
39
40
40
41
public Article createArticle (ArticleCreateDto dto ) {
41
42
@@ -54,15 +55,16 @@ public Article createArticle(ArticleCreateDto dto) {
54
55
article .getAttachedFiles ().addAll (files );
55
56
article .setStatus (ArticleStatus .UNDER_AUTO_REVIEW );
56
57
57
- articleRepository .save (article );
58
-
59
- contentCheckService .sendForAutoContentReview (article );
58
+ transactionTemplate .executeWithoutResult (status -> {
59
+ articleRepository .save (article );
60
+ contentCheckService .sendForAutoContentReview (article );
61
+ });
60
62
61
63
return article ;
62
64
}
63
65
66
+ //single update statement - no transaction required
64
67
public Article update (ArticleEditDto dto ) {
65
-
66
68
Optional <Article > articleOpt = articleRepository .findWithFilesAndUserById (dto .getId ());
67
69
return articleOpt .map (article -> {
68
70
ArticleMapper .INSTANCE .createToEntity (dto , article );
@@ -142,12 +144,13 @@ public UUID findCreatedByUserIdById(Long articleId) {
142
144
return articleRepository .findCreatedByUserIdById (articleId );
143
145
}
144
146
145
- @ Transactional
146
147
public Optional <Article > handleReview (ArticleReviewResultDto dto ) {
147
148
return articleRepository .findWithModifiedUserByIdAndStatus (dto .getId (), ArticleStatus .FLAGGED_FOR_MANUAL_REVIEW )
148
149
.map (n -> {
149
- n .setStatus (dto .getVerdict ());
150
- articleRepository .save (n );
150
+ transactionTemplate .executeWithoutResult (txSt -> {
151
+ n .setStatus (dto .getVerdict ());
152
+ articleRepository .save (n );
153
+ });
151
154
websocketHandler .sendToUser (n .getLastModifiedByUser ().getUsername (), "Your article with title " + n .getTitle () + " has been " + (dto .getVerdict () == ArticleStatus .PUBLISHED ? "approved from manual review." : "rejected from manual review." ));
152
155
return n ;
153
156
});
0 commit comments