Skip to content

Commit 6c82a2e

Browse files
authored
Merge pull request #80 from next-engineer/feature/79-transactional-update
♻️ refactor: transactional 메서드별 관리로 수정
2 parents 522bdf8 + 04167fc commit 6c82a2e

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

src/main/java/com/nextcloudlab/kickytime/match/service/MatchParticipantService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
@Service
1515
@RequiredArgsConstructor
16-
@Transactional(readOnly = true)
1716
public class MatchParticipantService {
1817

1918
private final MatchParticipantRepository matchParticipantRepository;
2019

20+
@Transactional(readOnly = true)
2121
public MyMatchesResponse getMyParticipant(String cognitoSub) {
2222

2323
List<MyMatchesResponse.MatchInfo> matches =

src/main/java/com/nextcloudlab/kickytime/match/service/MatchService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.stream.Collectors;
77

88
import org.springframework.stereotype.Service;
9+
import org.springframework.transaction.annotation.Transactional;
910

1011
import com.nextcloudlab.kickytime.match.dto.MatchCreateRequestDto;
1112
import com.nextcloudlab.kickytime.match.dto.MatchResponseDto;
@@ -18,10 +19,7 @@
1819
import com.nextcloudlab.kickytime.user.entity.User;
1920
import com.nextcloudlab.kickytime.user.repository.UserRepository;
2021

21-
import jakarta.transaction.Transactional;
22-
2322
@Service
24-
@Transactional
2523
public class MatchService {
2624

2725
private final MatchRepository matchRepository;
@@ -38,14 +36,15 @@ public MatchService(
3836
}
3937

4038
// 전체 경기 목록 조회
41-
@Transactional()
39+
@Transactional(readOnly = true)
4240
public List<MatchResponseDto> getAllMatches() {
4341
List<Match> matches = matchRepository.findAllByOrderByMatchDateTimeDesc();
4442

4543
return matches.stream().map(MatchResponseDto::new).collect(Collectors.toList());
4644
}
4745

4846
// 경기 개설
47+
@Transactional
4948
public void createMatch(MatchCreateRequestDto requestDto) {
5049
User user =
5150
userRepository
@@ -67,6 +66,7 @@ public void createMatch(MatchCreateRequestDto requestDto) {
6766
}
6867

6968
// 경기 참여 신청
69+
@Transactional
7070
public void joinMatch(Long matchId, String cognitoSub) {
7171
Match match =
7272
matchRepository
@@ -105,6 +105,7 @@ public void joinMatch(Long matchId, String cognitoSub) {
105105
}
106106

107107
// 경기 참여 취소(일반회원)
108+
@Transactional
108109
public void leaveMatch(Long matchId, String cognitoSub) {
109110
Match match =
110111
matchRepository
@@ -125,6 +126,7 @@ public void leaveMatch(Long matchId, String cognitoSub) {
125126
}
126127

127128
// 매치 삭제 기능
129+
@Transactional
128130
public void deleteMatchById(Long matchId) {
129131
if (!matchRepository.existsById(matchId)) {
130132
throw new IllegalArgumentException("해당 매치를 찾을 수 없습니다.");

src/main/java/com/nextcloudlab/kickytime/user/service/CognitoBackfillService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
import org.springframework.beans.factory.annotation.Value;
66
import org.springframework.stereotype.Service;
7+
import org.springframework.transaction.annotation.Transactional;
78

89
import com.nextcloudlab.kickytime.user.entity.User;
910
import com.nextcloudlab.kickytime.user.repository.UserRepository;
1011

11-
import jakarta.transaction.Transactional;
1212
import lombok.RequiredArgsConstructor;
1313
import lombok.extern.slf4j.Slf4j;
1414
import software.amazon.awssdk.services.cognitoidentityprovider.CognitoIdentityProviderClient;
@@ -24,10 +24,12 @@ public class CognitoBackfillService {
2424
@Value("${app.cognito.user-pool-id}")
2525
private String userPoolId;
2626

27+
@Transactional(readOnly = true)
2728
public BackfillReport backfillAllUsers() {
2829
return backfillReport();
2930
}
3031

32+
@Transactional
3133
public BackfillReport backfillReport() {
3234
int processed = 0, created = 0, updated = 0;
3335

src/main/java/com/nextcloudlab/kickytime/user/service/UserService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import org.springframework.http.HttpStatus;
44
import org.springframework.stereotype.Service;
5+
import org.springframework.transaction.annotation.Transactional;
56
import org.springframework.web.server.ResponseStatusException;
67

78
import com.nextcloudlab.kickytime.user.dto.UserDto;
89
import com.nextcloudlab.kickytime.user.entity.User;
910
import com.nextcloudlab.kickytime.user.repository.UserRepository;
1011

11-
import jakarta.transaction.Transactional;
1212
import lombok.RequiredArgsConstructor;
1313

1414
@Service
@@ -45,7 +45,7 @@ public User findOrCreateUser(
4545
});
4646
}
4747

48-
@Transactional
48+
@Transactional(readOnly = true)
4949
public UserDto getByCognitoSub(String cognitoSub) {
5050
User me =
5151
userRepository

0 commit comments

Comments
 (0)