mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
Make setting of id explicit for modified repositories
This commit is contained in:
@@ -68,7 +68,7 @@ public class RepositoryCollectionResource {
|
||||
@ResponseHeaders(@ResponseHeader(name = "Location", description = "uri to the created repository"))
|
||||
public Response create(RepositoryDto repositoryDto) throws IOException, RepositoryException {
|
||||
return adapter.create(repositoryDto,
|
||||
() -> dtoToRepositoryMapper.map(repositoryDto),
|
||||
() -> dtoToRepositoryMapper.map(repositoryDto, null),
|
||||
repository -> resourceLinks.repository().self(repository.getNamespace(), repository.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
@Mapper
|
||||
@@ -13,6 +16,10 @@ public abstract class RepositoryDtoToRepositoryMapper {
|
||||
@Mapping(target = "publicReadable", ignore = true)
|
||||
@Mapping(target = "healthCheckFailures", 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,11 +92,10 @@ public class RepositoryResource {
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
public Response update(@PathParam("namespace") String namespace, @PathParam("name") String name, RepositoryDto repositoryDto) {
|
||||
return adapter.update(() -> manager.getByNamespace(namespace, name), existing -> {
|
||||
Repository repository = dtoToRepositoryMapper.map(repositoryDto);
|
||||
repository.setId(existing.getId());
|
||||
return repository;
|
||||
});
|
||||
return adapter.update(
|
||||
() -> manager.getByNamespace(namespace, name),
|
||||
existing -> dtoToRepositoryMapper.map(repositoryDto, existing.getId())
|
||||
);
|
||||
}
|
||||
|
||||
@Path("tags/")
|
||||
|
||||
Reference in New Issue
Block a user