Skip to content

Commit 792f851

Browse files
committed
♻️ refactor: transactional 메서드별 관리로 수정
1 parent 522bdf8 commit 792f851

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
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
@@ -17,11 +17,9 @@
1717
import com.nextcloudlab.kickytime.user.entity.RoleEnum;
1818
import com.nextcloudlab.kickytime.user.entity.User;
1919
import com.nextcloudlab.kickytime.user.repository.UserRepository;
20-
21-
import jakarta.transaction.Transactional;
20+
import org.springframework.transaction.annotation.Transactional;
2221

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/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)