35 lines
999 B
Java
35 lines
999 B
Java
package enseirb.myinpulse.service.database;
|
|
|
|
import enseirb.myinpulse.model.Report;
|
|
import enseirb.myinpulse.repository.ReportRepository;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.server.ResponseStatusException;
|
|
|
|
import java.util.Optional;
|
|
|
|
@Service
|
|
public class ReportService {
|
|
private final ReportRepository reportRepository;
|
|
|
|
@Autowired
|
|
ReportService(ReportRepository reportRepository) {
|
|
this.reportRepository = reportRepository;
|
|
}
|
|
|
|
Report getReportById(int id) {
|
|
Optional<Report> report = reportRepository.findById(id);
|
|
if (report.isEmpty()) {
|
|
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce compte rendu n'existe pas");
|
|
}
|
|
return report.get();
|
|
}
|
|
|
|
// TODO: do some validation
|
|
void saveReport(Report report) {
|
|
reportRepository.save(report);
|
|
}
|
|
}
|