-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDashboardService.java
51 lines (41 loc) · 2 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.club.domain.Club;
import com.cruru.club.domain.repository.ClubRepository;
import com.cruru.club.exception.ClubNotFoundException;
import com.cruru.dashboard.controller.dto.DashboardCreateDto;
import com.cruru.dashboard.domain.Dashboard;
import com.cruru.dashboard.domain.repository.DashboardRepository;
import com.cruru.process.domain.Process;
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 static final Process DEFAULT_FIRST_PROCESS = new Process(1, "지원 접수", "지원자가 이력서를 제출하는 단계", null);
private static final Process DEFAULT_LAST_PROCESS = new Process(2, "합격", "지원자가 최종적으로 합격한 단계", null);
private final DashboardRepository dashboardRepository;
private final ClubRepository clubRepository;
private final ProcessRepository processRepository;
public Long create(long clubId, DashboardCreateDto request) {
Club club = clubRepository.findById(clubId).orElseThrow(ClubNotFoundException::new);
Dashboard savedDashboard = dashboardRepository.save(new Dashboard(request.name(), club));
Process firstProcess = new Process(
DEFAULT_FIRST_PROCESS.getSequence(),
DEFAULT_FIRST_PROCESS.getName(),
DEFAULT_FIRST_PROCESS.getDescription(),
savedDashboard
);
Process lastProcess = new Process(
DEFAULT_LAST_PROCESS.getSequence(),
DEFAULT_LAST_PROCESS.getName(),
DEFAULT_LAST_PROCESS.getDescription(),
savedDashboard
);
processRepository.saveAll(List.of(firstProcess, lastProcess));
return savedDashboard.getId();
}
}