40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
package fr.la_banquise.backend.rest;
|
|
|
|
import fr.la_banquise.backend.services.DockerService;
|
|
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("/containers")
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
public class ContainerResource {
|
|
|
|
@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();
|
|
}
|
|
}
|
|
|
|
@DELETE
|
|
@Path("/{id}")
|
|
public Response remove(@PathParam("id") String id) {
|
|
try {
|
|
dockerService.stopAndRemove(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();
|
|
}
|
|
}
|
|
} |