various functionality added

This commit is contained in:
2025-03-11 23:15:15 +01:00
parent 3f769df850
commit acd957f0da
13 changed files with 188 additions and 42 deletions

View File

@@ -1,23 +1,27 @@
package nl.veenm.paypoint.resource;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import jakarta.json.JsonNumber;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import nl.veenm.paypoint.domain.Appointment;
import nl.veenm.paypoint.service.AppointmentService;
import org.eclipse.microprofile.jwt.JsonWebToken;
import java.util.List;
@Path("/api/appointments")
@Path("/appointments")
@RolesAllowed({"ADMIN", "USER"})
public class AppointmentResource {
@Inject
AppointmentService appointmentService;
@Inject
JsonWebToken jwt;
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Appointment> getAppointments() {
@@ -28,8 +32,11 @@ public class AppointmentResource {
@Produces(MediaType.APPLICATION_JSON)
@Path("/date")
public List<Appointment> getAppointmentsByDate(@QueryParam("start") String start) {
return appointmentService.getAppointmentsByDate(start);
JsonNumber companyIdJson = jwt.getClaim("company_id");
Long companyId = companyIdJson.longValue();
return appointmentService.getAppointmentsByDate(start, companyId);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/recent/{id}")
@@ -47,8 +54,9 @@ public class AppointmentResource {
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addAppointment(Appointment appointment) {
System.out.println(appointment);
appointmentService.add(appointment);
JsonNumber companyIdJson = jwt.getClaim("company_id");
Long companyId = companyIdJson.longValue();
appointmentService.add(appointment, companyId);
return Response.ok().build();
}