mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
Correct resource links and add tags link
This commit is contained in:
@@ -9,7 +9,10 @@ import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
@@ -21,12 +24,14 @@ public class RepositoryResource {
|
||||
|
||||
private final RepositoryManager manager;
|
||||
private final SingleResourceManagerAdapter<Repository, RepositoryDto, RepositoryException> adapter;
|
||||
private final Provider<TagRootResource> tagRootResource;
|
||||
|
||||
@Inject
|
||||
public RepositoryResource(RepositoryToRepositoryDtoMapper repositoryToDtoMapper, RepositoryManager manager) {
|
||||
public RepositoryResource(RepositoryToRepositoryDtoMapper repositoryToDtoMapper, RepositoryManager manager, Provider<TagRootResource> tagRootResource) {
|
||||
this.manager = manager;
|
||||
this.repositoryToDtoMapper = repositoryToDtoMapper;
|
||||
this.adapter = new SingleResourceManagerAdapter<>(manager);
|
||||
this.tagRootResource = tagRootResource;
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -43,4 +48,21 @@ public class RepositoryResource {
|
||||
public Response get(@PathParam("namespace") String namespace, @PathParam("name") String name) {
|
||||
return adapter.get(() -> manager.getByNamespace(namespace, name), repositoryToDtoMapper::map);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("")
|
||||
public Response delete(@PathParam("namespace") String namespace, @PathParam("name") String name) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("")
|
||||
public Response update(@PathParam("namespace") String namespace, @PathParam("name") String name) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Path("tags/")
|
||||
public TagRootResource tags() {
|
||||
return tagRootResource.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
if (RepositoryPermissions.modify(repository).isPermitted()) {
|
||||
linksBuilder.single(link("update", resourceLinks.repository().update(target.getNamespace(), target.getName())));
|
||||
}
|
||||
linksBuilder.single(link("tags", resourceLinks.tagCollection().self(target.getNamespace(), target.getName())));
|
||||
target.add(linksBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ class ResourceLinks {
|
||||
}
|
||||
|
||||
public RepositoryLinks repository() {
|
||||
return null;
|
||||
return new RepositoryLinks(uriInfoStore.get());
|
||||
}
|
||||
|
||||
static class RepositoryLinks {
|
||||
@@ -124,4 +124,20 @@ class ResourceLinks {
|
||||
return repositoryLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("update").parameters().href();
|
||||
}
|
||||
}
|
||||
|
||||
public TagCollectionLinks tagCollection() {
|
||||
return new TagCollectionLinks(uriInfoStore.get());
|
||||
}
|
||||
|
||||
static class TagCollectionLinks {
|
||||
private final LinkBuilder repositoryLinkBuilder;
|
||||
|
||||
private TagCollectionLinks(UriInfo uriInfo) {
|
||||
repositoryLinkBuilder = new LinkBuilder(uriInfo, RepositoryRootResource.class, RepositoryResource.class, TagRootResource.class, TagCollectionResource.class);
|
||||
}
|
||||
|
||||
String self(String namespace, String name) {
|
||||
return repositoryLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("tags").parameters().method("getTagCollectionResource").parameters().method("getAll").parameters().href();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
public class TagCollectionResource {
|
||||
@GET
|
||||
@Path("")
|
||||
public Response getAll(@DefaultValue("0") @QueryParam("page") int page,
|
||||
@DefaultValue("10") @QueryParam("pageSize") int pageSize,
|
||||
@QueryParam("sortBy") String sortBy,
|
||||
@DefaultValue("false") @QueryParam("desc") boolean desc) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
public class TagRootResource {
|
||||
|
||||
private final Provider<TagCollectionResource> tagCollectionResource;
|
||||
|
||||
@Inject
|
||||
public TagRootResource(Provider<TagCollectionResource> tagCollectionResource) {
|
||||
this.tagCollectionResource = tagCollectionResource;
|
||||
}
|
||||
|
||||
@Path("")
|
||||
public TagCollectionResource getTagCollectionResource() {
|
||||
return tagCollectionResource.get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user