Files
paypoint-backend/src/main/java/nl/veenm/paypoint/resource/AppointmentResource.java
2025-03-11 23:15:15 +01:00

77 lines
2.2 KiB
Java

package nl.veenm.paypoint.resource;
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("/appointments")
@RolesAllowed({"ADMIN", "USER"})
public class AppointmentResource {
@Inject
AppointmentService appointmentService;
@Inject
JsonWebToken jwt;
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Appointment> getAppointments() {
return appointmentService.getAllAppointments();
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/date")
public List<Appointment> getAppointmentsByDate(@QueryParam("start") String start) {
JsonNumber companyIdJson = jwt.getClaim("company_id");
Long companyId = companyIdJson.longValue();
return appointmentService.getAppointmentsByDate(start, companyId);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/recent/{id}")
public Appointment getMostRecentAppointment(@PathParam("id") Long userId) {
return appointmentService.getMostRecentByUserId(userId);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}")
public Appointment getAppointmentById(@PathParam("id") Long id) {
return appointmentService.getAppointment(id);
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addAppointment(Appointment appointment) {
JsonNumber companyIdJson = jwt.getClaim("company_id");
Long companyId = companyIdJson.longValue();
appointmentService.add(appointment, companyId);
return Response.ok().build();
}
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
public Response deleteAppointment(@QueryParam("id") Long id) {
appointmentService.delete(id);
return Response.ok().build();
}
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response updateAppointment(Appointment appointment) {
appointmentService.update(appointment);
return Response.ok().build();
}
}