-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDashboardFacade.java
42 lines (37 loc) · 1.69 KB
/
DashboardFacade.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
package com.cruru.dashboard.service.facade;
import com.cruru.applyform.controller.dto.ApplyFormCreateRequest;
import com.cruru.applyform.domain.ApplyForm;
import com.cruru.applyform.service.ApplyFormService;
import com.cruru.dashboard.controller.dto.DashboardCreateRequest;
import com.cruru.dashboard.domain.Dashboard;
import com.cruru.dashboard.service.DashboardService;
import com.cruru.question.controller.dto.QuestionCreateRequest;
import com.cruru.question.service.QuestionService;
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 DashboardFacade {
private final DashboardService dashboardService;
private final ApplyFormService applyFormService;
private final QuestionService questionService;
@Transactional
public long create(long clubId, DashboardCreateRequest request) {
Dashboard createdDashboard = dashboardService.create(clubId);
ApplyForm applyForm = applyFormService.create(toApplyFormCreateRequest(request), createdDashboard);
List<QuestionCreateRequest> questionRequests = request.questions();
questionRequests.forEach(questionCreateRequest -> questionService.create(questionCreateRequest, applyForm));
return createdDashboard.getId();
}
private ApplyFormCreateRequest toApplyFormCreateRequest(DashboardCreateRequest request) {
return new ApplyFormCreateRequest(
request.title(),
request.postingContent(),
request.startDate(),
request.dueDate()
);
}
}