-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDashboardService.java
51 lines (42 loc) · 1.85 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
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.cruru.dashboard.service;
import com.cruru.applicant.domain.Applicant;
import com.cruru.applicant.domain.repository.ApplicantRepository;
import com.cruru.applyform.domain.repository.ApplyFormRepository;
import com.cruru.club.domain.Club;
import com.cruru.dashboard.domain.Dashboard;
import com.cruru.dashboard.domain.DashboardApplyFormDto;
import com.cruru.dashboard.domain.repository.DashboardRepository;
import com.cruru.dashboard.exception.DashboardNotFoundException;
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 ProcessRepository processRepository;
private final ApplicantRepository applicantRepository;
private final ApplyFormRepository applyFormRepository;
@Transactional
public Dashboard create(Club club) {
Dashboard savedDashboard = dashboardRepository.save(new Dashboard(club));
List<Process> initProcesses = ProcessFactory.createInitProcesses(savedDashboard);
processRepository.saveAll(initProcesses);
return savedDashboard;
}
public Dashboard findById(Long id) {
return dashboardRepository.findById(id)
.orElseThrow(DashboardNotFoundException::new);
}
public List<DashboardApplyFormDto> findAllByClub(long clubId) {
return applyFormRepository.findAllByClub(clubId);
}
public List<Applicant> findAllApplicants(Dashboard dashboard) {
return applicantRepository.findAllByDashboard(dashboard);
}
}