Exemplo n.º 1
0
def copy_collection_from(
    user: InternalUserDTO, src_collection_uuid: UUID, dst_collection_uuid: UUID,
) -> CollectionDTO:
    try:
        src_collection = Collection.find_readable_or_fail(user, src_collection_uuid)
    except ModelNotFoundError:
        raise PermissionError()

    copy_items_by_collection_uuid(src_collection_uuid, dst_collection_uuid)
    src_collection.session.commit()
    collection = Collection.find_readable_or_fail(user, dst_collection_uuid)
    return to_model(collection, CollectionDTO)
Exemplo n.º 2
0
def copy_collection_to_new(
    user: InternalUserDTO, src_collection_uuid: UUID, dst_collection_dto: CollectionDTO,
) -> CollectionDTO:
    try:
        src_collection = Collection.find_readable_or_fail(user, src_collection_uuid)
    except ModelNotFoundError:
        raise PermissionError()

    dst_collection_dto.provider_uuid = user.provider_uuid
    dst_collection = Collection.create(**dst_collection_dto.to_dict())
    copy_items_by_collection_uuid(src_collection_uuid, dst_collection.uuid)
    src_collection.session.commit()
    return to_model(dst_collection, CollectionDTO)
Exemplo n.º 3
0
def get_collection_by_uuid(
    user: InternalUserDTO, collection_uuid: UUID
) -> CollectionDTO:
    collection = Collection.find_readable_or_fail(user, collection_uuid)
    return to_model(collection, CollectionDTO)