def update_collection( *, _: bool = Depends(is_authenticated), repository: CollectionRepository = Depends(get_collection_repository), id: int, collection_update: CollectionUpdate): db_collection: DBCollection = or_404(repository.get(id)) updated: DBCollection = repository.update( db_collection, collection_update.dict(skip_defaults=True)) return updated
def update_collection( *, _: bool = Depends(is_authenticated), repository: CollectionRepository = Depends(get_collection_repository), id: int, collection_update: CollectionUpdate, ): db_collection: DBCollection = or_404(repository.get(id)) updated: DBCollection = repository.update( db_collection, collection_update.dict(exclude_unset=True)) return updated.to_model()
def create_keyword( *, _: bool = Depends(is_authenticated), repository: KeywordRepository = Depends(get_keyword_repository), collection_repository: CollectionRepository = Depends( get_collection_repository), keyword: KeywordCreate): collection: Optional[DBCollection] = collection_repository.get( keyword.collection_id) if not collection: raise HTTPException(status_code=400, detail='Collection does not exist') db_keyword: DBKeyword = DBKeyword(**keyword.dict()) return repository.add(db_keyword)
def base_doc_view(request: Request, repository: CollectionRepository, collection_id: int, keyword_id: Optional[int] = None): collection = or_404(repository.get(collection_id)) collections = repository.get_all() context = { "request": request, "collection": collection, "keyword_id": keyword_id, "hierarchy": collections, "version": version } return templates.TemplateResponse("library.html", context)
def get_collection( *, repository: CollectionRepository = Depends(get_collection_repository), id: int): collection: Optional[DBCollection] = repository.get(id) return or_404(collection)