package dev.dinauer.maven.app;

import dev.dinauer.maven.maven.core.GroupRepo;
import dev.dinauer.maven.maven.core.GroupId;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;

import java.util.List;

@Path("/groups")
public class GroupResource
{
    @Inject
    GroupRepo groupRepo;

    @GET
    public List<GroupId> get()
    {
        return groupRepo.listAll();
    }

    @GET
    @Path("/{id}")
    public GroupId get(@PathParam("id") String id)
    {
        return groupRepo.findById(id);
    }

    @DELETE
    @Path("/{id}")
    @Transactional
    public void delete(@PathParam("id") String id)
    {
        groupRepo.deleteById(id);
    }
}
