Make setting of id explicit for modified repositories

This commit is contained in:
René Pfeuffer
2018-07-05 13:07:43 +02:00
parent cad793322c
commit 0bbc58b978
3 changed files with 13 additions and 7 deletions

View File

@@ -68,7 +68,7 @@ public class RepositoryCollectionResource {
@ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created repository")) @ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created repository"))
public Response create(RepositoryDto repositoryDto) throws IOException, RepositoryException { public Response create(RepositoryDto repositoryDto) throws IOException, RepositoryException {
return adapter.create(repositoryDto, return adapter.create(repositoryDto,
() -> dtoToRepositoryMapper.map(repositoryDto), () -> dtoToRepositoryMapper.map(repositoryDto, null),
repository -> resourceLinks.repository().self(repository.getNamespace(), repository.getName())); repository -> resourceLinks.repository().self(repository.getNamespace(), repository.getName()));
} }
} }

View File

@@ -1,7 +1,10 @@
package sonia.scm.api.v2.resources; package sonia.scm.api.v2.resources;
import org.mapstruct.AfterMapping;
import org.mapstruct.Context;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import sonia.scm.repository.Repository; import sonia.scm.repository.Repository;
@Mapper @Mapper
@@ -13,6 +16,10 @@ public abstract class RepositoryDtoToRepositoryMapper {
@Mapping(target = "publicReadable", ignore = true) @Mapping(target = "publicReadable", ignore = true)
@Mapping(target = "healthCheckFailures", ignore = true) @Mapping(target = "healthCheckFailures", ignore = true)
@Mapping(target = "permissions", ignore = true) @Mapping(target = "permissions", ignore = true)
public abstract Repository map(RepositoryDto repositoryDto); public abstract Repository map(RepositoryDto repositoryDto, @Context String id);
@AfterMapping
void updateId(@MappingTarget Repository repository, @Context String id) {
repository.setId(id);
}
} }

View File

@@ -92,11 +92,10 @@ public class RepositoryResource {
}) })
@TypeHint(TypeHint.NO_CONTENT.class) @TypeHint(TypeHint.NO_CONTENT.class)
public Response update(@PathParam("namespace") String namespace, @PathParam("name") String name, RepositoryDto repositoryDto) { public Response update(@PathParam("namespace") String namespace, @PathParam("name") String name, RepositoryDto repositoryDto) {
return adapter.update(() -> manager.getByNamespace(namespace, name), existing -> { return adapter.update(
Repository repository = dtoToRepositoryMapper.map(repositoryDto); () -> manager.getByNamespace(namespace, name),
repository.setId(existing.getId()); existing -> dtoToRepositoryMapper.map(repositoryDto, existing.getId())
return repository; );
});
} }
@Path("tags/") @Path("tags/")