-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathEvaluationService.java
58 lines (49 loc) · 2.19 KB
/
EvaluationService.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
52
53
54
55
56
57
58
package com.cruru.applicant.service;
import com.cruru.applicant.controller.request.EvaluationCreateRequest;
import com.cruru.applicant.controller.request.EvaluationUpdateRequest;
import com.cruru.applicant.domain.Applicant;
import com.cruru.applicant.domain.Evaluation;
import com.cruru.applicant.domain.repository.EvaluationRepository;
import com.cruru.applicant.exception.EvaluationNotFoundException;
import com.cruru.process.domain.Process;
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 EvaluationService {
private final EvaluationRepository evaluationRepository;
public Evaluation findById(Long evaluationId) {
return evaluationRepository.findById(evaluationId)
.orElseThrow(EvaluationNotFoundException::new);
}
@Transactional
public void create(EvaluationCreateRequest request, Process process, Applicant applicant) {
evaluationRepository.save(new Evaluation(request.score(), request.content(), process, applicant));
}
public List<Evaluation> findAllByProcessAndApplicant(Process process, Applicant applicant) {
return evaluationRepository.findAllByProcessAndApplicant(process, applicant);
}
@Transactional
public void update(EvaluationUpdateRequest request, Evaluation evaluation) {
if (changeExists(request, evaluation)) {
evaluationRepository.save(
new Evaluation(
evaluation.getId(),
request.score(),
request.content(),
evaluation.getProcess(),
evaluation.getApplicant()
)
);
}
}
private boolean changeExists(EvaluationUpdateRequest request, Evaluation evaluation) {
return !(evaluation.getContent().equals(request.content()) && evaluation.getScore().equals(request.score()));
}
public void deleteByProcess(long processId) {
evaluationRepository.deleteByProcessId(processId);
}
}