package fr.la_banquise.backend.rest; import fr.la_banquise.backend.services.DockerService; import io.quarkus.security.jpa.Roles; import jakarta.annotation.security.RolesAllowed; import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; import java.util.Map; @Path("/docker") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class DockerResource { @Inject DockerService dockerService; /*@POST @Path("/nginx") public Response launchNginx() { try { String id = dockerService.createAndStartNginx(); return Response.ok(Map.of("containerId", id, "status", "running")) .build(); } catch (Exception e) { return Response.status(500) .entity(Map.of("error", e.getMessage())) .build(); } } @POST @Path("/create") public Response createContainer(@QueryParam("name") String name, @QueryParam("port") int port) { try { String id = dockerService.createContainer(name, port); return Response.ok(Map.of("containerId", id)).build(); } catch (Exception e) { return Response.status(500) .entity(Map.of("error", e.getMessage())) .build(); } }*/ @GET @RolesAllowed("ROOT") @Path("/all") public Response listContainers() { try { return Response.ok(dockerService.listAllContainers()).build(); } catch (Exception e) { return Response.status(500) .entity(Map.of("error", e.getMessage())) .build(); } } @POST @RolesAllowed("ROOT") @Path("/start") public Response start(@QueryParam("id") String id) { try { dockerService.start(id); return Response.ok(Map.of("containerId", id, "status", "Running")) .build(); } catch (Exception e) { return Response.status(500) .entity(Map.of("error", e.getMessage())) .build(); } } @POST @RolesAllowed("ROOT") @Path("/stop") public Response stop(@QueryParam("id") String id) { try { dockerService.stop(id); return Response.ok(Map.of("containerId", id, "status", "removed")) .build(); } catch (Exception e) { return Response.status(500) .entity(Map.of("error", e.getMessage())) .build(); } } @DELETE @RolesAllowed("ROOT") @Path("/remove") public Response remove(@QueryParam("id") String id) { try { dockerService.remove(id); return Response.ok(Map.of("containerId", id, "status", "removed")) .build(); } catch (Exception e) { return Response.status(500) .entity(Map.of("error", e.getMessage())) .build(); } } }