feat: finished implementing apiService functions
This commit is contained in:
@ -13,8 +13,14 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@ -95,7 +101,6 @@ public class SharedApiService {
|
||||
return project.getProjectAdministrator();
|
||||
}
|
||||
|
||||
// TODO
|
||||
public Iterable<Appointment> getAppointmentsByProjectId(long projectId, String mail) {
|
||||
if (!utilsService.isAllowedToCheckProject(mail, projectId)) {
|
||||
logger.warn(
|
||||
@ -123,9 +128,8 @@ public class SharedApiService {
|
||||
return appointments;
|
||||
}
|
||||
|
||||
//
|
||||
public void getPDFReport(long appointmentId, String mail)
|
||||
throws FileNotFoundException, DocumentException {
|
||||
throws DocumentException, URISyntaxException, IOException {
|
||||
long projectId =
|
||||
this.appointmentService
|
||||
.getAppointmentById(appointmentId)
|
||||
@ -202,9 +206,24 @@ public class SharedApiService {
|
||||
document.add(new Paragraph("\n"));
|
||||
|
||||
document.close();
|
||||
|
||||
// Replace uri with website address
|
||||
Files.copy(
|
||||
new URI(
|
||||
"http://localhost:8080/shared/projects/appointments/report/"
|
||||
+ appointmentId)
|
||||
.toURL()
|
||||
.openStream(),
|
||||
Paths.get("Report" + appointmentId + ".pdf"),
|
||||
StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
// delete file, we don't want to stock all reports on the server
|
||||
File file = new File("Report" + appointmentId + ".pdf");
|
||||
if (!file.delete()) {
|
||||
logger.warn("Failed to delete report {}", file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
public void createAppointmentRequest(Appointment appointment, String mail) {
|
||||
long projectId =
|
||||
appointment
|
||||
|
Reference in New Issue
Block a user