-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDashboardService.java
38 lines (31 loc) · 1.37 KB
/
DashboardService.java
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
package com.cruru.dashboard.service;
import com.cruru.club.domain.Club;
import com.cruru.club.domain.repository.ClubRepository;
import com.cruru.club.exception.ClubNotFoundException;
import com.cruru.dashboard.domain.Dashboard;
import com.cruru.dashboard.domain.repository.DashboardRepository;
import com.cruru.process.domain.Process;
import com.cruru.process.domain.ProcessFactory;
import com.cruru.process.domain.repository.ProcessRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class DashboardService {
private final DashboardRepository dashboardRepository;
private final ClubRepository clubRepository;
private final ProcessRepository processRepository;
@Transactional
public Dashboard create(long clubId) {
Club club = clubRepository.findById(clubId)
.orElseThrow(ClubNotFoundException::new);
Dashboard savedDashboard = dashboardRepository.save(new Dashboard(club));
Process firstProcess = ProcessFactory.createFirstOf(savedDashboard);
Process lastProcess = ProcessFactory.createLastOf(savedDashboard);
processRepository.saveAll(List.of(firstProcess, lastProcess));
return savedDashboard;
}
}