-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCursoService.java
More file actions
40 lines (32 loc) · 1.2 KB
/
CursoService.java
File metadata and controls
40 lines (32 loc) · 1.2 KB
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
package br.com.openenade.api.curso;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import br.com.openenade.api.exceptions.ResourceNotFound;
import br.com.openenade.api.modalidade.Modalidade;
@Service
public class CursoService {
@Autowired
private CursoRepository repository;
public Curso addCurso(Curso curso) {
return this.repository.save(curso);
}
public List<Curso> getAll() {
return this.repository.findAll();
}
public Curso getByCodigo(Long codigo, Modalidade modalidade) {
CursoId cursoId = new CursoId(codigo, modalidade);
Optional<Curso> optCurso = this.repository.findById(cursoId);
if (optCurso.isPresent()) {
return optCurso.get();
} else {
throw new ResourceNotFound("Cannot find Curso with Codigo [" + Long.toString(codigo)
+ "] and Modalidade [" + modalidade.getValue() + "]");
}
}
public void deleteById(CursoId cursoId) {
this.getByCodigo(cursoId.getCodigoArea(), cursoId.getModalidade());
this.repository.deleteById(cursoId);
}
}