File tree Expand file tree Collapse file tree
apps/commerce-api/src/main/java/com/loopers/application/like Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,27 +23,26 @@ public class LikeFacade {
2323 public LikeInfo like (long userId , long productId ) {
2424 Optional <Like > existingLike = likeService .findLike (userId , productId );
2525
26-
2726 if (existingLike .isPresent ()) {
2827 Product product = productService .getProduct (productId );
2928 return LikeInfo .from (existingLike .get (), product .getLikeCount ());
3029 }
3130
3231 for (int i = 0 ; i < RETRY_COUNT ; i ++) {
3332 try {
33+ return transactionTemplate .execute (status -> {
34+ Like newLike = likeService .save (userId , productId );
35+ int updatedLikeCount = productService .increaseLikeCount (productId );
36+ return LikeInfo .from (newLike , updatedLikeCount );
37+ });
3438
35- Like newLike = likeService .save (userId , productId );
36- int updatedLikeCount = productService .increaseLikeCount (productId );
37-
38- return LikeInfo .from (newLike , updatedLikeCount );
3939 } catch (ObjectOptimisticLockingFailureException e ) {
4040 if (i == RETRY_COUNT - 1 ) {
4141 throw e ;
4242 }
4343 sleep (50 );
4444 }
4545 }
46-
4746 throw new IllegalStateException ("좋아요 처리 재시도 횟수를 초과했습니다." );
4847 }
4948
You can’t perform that action at this time.
0 commit comments