-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeamService.java
More file actions
50 lines (41 loc) · 1.63 KB
/
TeamService.java
File metadata and controls
50 lines (41 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package system.design.interview.domain.team;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import system.design.interview.domain.team.dto.request.TeamCreateRequest;
import system.design.interview.domain.team.dto.request.TeamUpdateRequest;
import system.design.interview.domain.team.dto.response.TeamResponse;
import java.util.List;
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class TeamService {
private final TeamCacheableRepository teamCacheableRepository;
@Transactional
public Long createTeam(TeamCreateRequest request) {
Team team = Team.builder()
.name(request.getName())
.build();
Team savedTeam = teamCacheableRepository.save(team);
return savedTeam.getId();
}
public List<TeamResponse> findAll() {
return teamCacheableRepository.findAll()
.stream()
.map(TeamResponse::from)
.toList();
}
@Transactional
public void updateTeam(Long teamId, TeamUpdateRequest request) {
teamCacheableRepository.update(teamId, request.getName())
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 팀입니다."));
}
@Transactional
public void deleteMemberById(Long teamId) {
teamCacheableRepository.deleteById(teamId);
}
public Team findById(Long teamId) {
return teamCacheableRepository.findById(teamId)
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 팀입니다."));
}
}