Skip to content

Commit abf4a17

Browse files
committed
refactor: 낙관적락 로직 수정
1 parent 4e1b574 commit abf4a17

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/main/java/store/lastdance/service/analysis/AnalysisV2CommandServiceImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import store.lastdance.domain.analysis.FeedbackType;
99
import store.lastdance.exception.CustomException;
1010
import store.lastdance.exception.ErrorCode;
11+
import store.lastdance.repository.analysis.ExpenseAnalysisHistoryRepository;
1112
import store.lastdance.service.analysis.validator.AnalysisHistoryValidator;
1213

1314
import java.util.UUID;
@@ -18,6 +19,7 @@
1819
public class AnalysisV2CommandServiceImpl implements AnalysisV2CommandService {
1920

2021
private final AnalysisHistoryValidator analysisHistoryValidator;
22+
private final ExpenseAnalysisHistoryRepository expenseAnalysisHistoryRepository;
2123

2224
@Override
2325
public FeedbackType toggleFeedback(Long historyId, UUID userId, FeedbackType type) {
@@ -29,15 +31,16 @@ public FeedbackType toggleFeedback(Long historyId, UUID userId, FeedbackType typ
2931
boolean isUp = (type == FeedbackType.UP);
3032
boolean isDown = (type == FeedbackType.DOWN);
3133

32-
// 현재 상태와 같은 버튼을 다시 누르면 피드백 취소
33-
if ((isUp && Boolean.TRUE.equals(history.getUp())) || (isDown && Boolean.TRUE.equals(history.getDown()))) {
34+
boolean cancel = (isUp && Boolean.TRUE.equals(history.getUp())) || (isDown && Boolean.TRUE.equals(history.getDown()));
35+
if (cancel) {
3436
history.feedback(null, null);
35-
return null;
3637
} else {
37-
// 새로운 피드백 설정
3838
history.feedback(isUp, isDown);
39-
return type;
4039
}
40+
41+
expenseAnalysisHistoryRepository.saveAndFlush(history);
42+
return cancel ? null : type;
43+
4144
} catch (OptimisticLockingFailureException e) {
4245
throw new CustomException(ErrorCode.OPTIMISTIC_LOCK_FAILURE);
4346
}

0 commit comments

Comments
 (0)