API's met returns van objecten
Some checks failed
Docker Image CI / build-and-push (push) Failing after 20s
Docker Image CI / deploy (push) Has been skipped

This commit is contained in:
2025-03-22 16:55:46 +01:00
parent 2a50edc41d
commit 40f983980d
4 changed files with 18 additions and 15 deletions

View File

@@ -37,12 +37,15 @@ public class AppointmentResource {
return appointmentService.getAppointmentsByDate(start, companyId); return appointmentService.getAppointmentsByDate(start, companyId);
} }
@GET
@Produces(MediaType.APPLICATION_JSON) //TODO: Deze werkend maken
@Path("/recent/{id}")
public Appointment getMostRecentAppointment(@PathParam("id") Long userId) { // @GET
return appointmentService.getMostRecentByUserId(userId); // @Produces(MediaType.APPLICATION_JSON)
} // @Path("/recent/{id}")
// public Appointment getMostRecentAppointment(@PathParam("id") Long userId) {
// return appointmentService.getMostRecentByUserId(userId);
// }
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@@ -56,8 +59,7 @@ public class AppointmentResource {
public Response addAppointment(Appointment appointment) { public Response addAppointment(Appointment appointment) {
JsonNumber companyIdJson = jwt.getClaim("company_id"); JsonNumber companyIdJson = jwt.getClaim("company_id");
Long companyId = companyIdJson.longValue(); Long companyId = companyIdJson.longValue();
appointmentService.add(appointment, companyId); return Response.ok(appointmentService.add(appointment, companyId)).build();
return Response.ok().build();
} }
@DELETE @DELETE
@@ -70,7 +72,6 @@ public class AppointmentResource {
@PUT @PUT
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Response updateAppointment(Appointment appointment) { public Response updateAppointment(Appointment appointment) {
appointmentService.update(appointment); return Response.ok(appointmentService.update(appointment)).build();
return Response.ok().build();
} }
} }

View File

@@ -28,7 +28,6 @@ public class CustomerResource {
@POST @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response addCustomer(Customer customer) { public Response addCustomer(Customer customer) {
customerService.addCustomer(customer); return Response.ok(customerService.addCustomer(customer)).build();
return Response.ok().build();
} }
} }

View File

@@ -34,11 +34,12 @@ public class AppointmentService {
} }
@Transactional @Transactional
public void add(Appointment appointment, Long companyId) { public Appointment add(Appointment appointment, Long companyId) {
Company company = companyRepository.findById(companyId); Company company = companyRepository.findById(companyId);
appointment.setCompany(company); appointment.setCompany(company);
appointmentRepository.persist(appointment); appointmentRepository.persist(appointment);
emailService.stuurBevestiging(appointment); emailService.stuurBevestiging(appointment);
return appointment;
} }
@Transactional @Transactional
@@ -59,7 +60,7 @@ public class AppointmentService {
} }
@Transactional @Transactional
public void update(Appointment appointment) { public Appointment update(Appointment appointment) {
Appointment appointmentToUpdate = appointmentRepository.findById(appointment.getId()); Appointment appointmentToUpdate = appointmentRepository.findById(appointment.getId());
appointmentToUpdate.setTitle(appointment.getTitle()); appointmentToUpdate.setTitle(appointment.getTitle());
appointmentToUpdate.setStartDate(appointment.getStartDate()); appointmentToUpdate.setStartDate(appointment.getStartDate());
@@ -72,6 +73,7 @@ public class AppointmentService {
appointmentToUpdate.setDurationInMinutes(appointment.getDurationInMinutes()); appointmentToUpdate.setDurationInMinutes(appointment.getDurationInMinutes());
appointmentRepository.persist(appointmentToUpdate); appointmentRepository.persist(appointmentToUpdate);
emailService.stuurBewerking(appointmentToUpdate); emailService.stuurBewerking(appointmentToUpdate);
return appointmentToUpdate;
} }
@Transactional @Transactional

View File

@@ -28,7 +28,8 @@ public class CustomerService {
} }
@Transactional @Transactional
public void addCustomer(Customer customer) { public Customer addCustomer(Customer customer) {
customerRepository.persist(customer); customerRepository.persist(customer);
return customer;
} }
} }