mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +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"))
|
@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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/")
|
||||||
|
|||||||
Reference in New Issue
Block a user