-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from robert-cronin/feature/implement-data-model
Implement and verify data model, test system refactor / general organization improvements.
- Loading branch information
Showing
57 changed files
with
2,560 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,3 +79,6 @@ server.pid | |
|
||
# Huggingface | ||
models_cache/ | ||
|
||
# Embedding models | ||
**/models--** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from fastapi import APIRouter, Depends, HTTPException | ||
from sqlalchemy.orm import Session | ||
from typing import List | ||
from odr_core.crud import content_event as content_event_crud | ||
from odr_core.schemas.content import ContentEvent, ContentEventCreate, ContentEventUpdate | ||
from odr_core.database import get_db | ||
from odr_api.api.auth.auth_provider import AuthProvider | ||
from odr_core.models.content import ContentStatus | ||
|
||
router = APIRouter(tags=["content_events"]) | ||
|
||
|
||
@router.post("/content/{content_id}/events/", response_model=ContentEvent) | ||
def create_content_event( | ||
content_id: int, | ||
event: ContentEventCreate, | ||
db: Session = Depends(get_db), | ||
current_user=Depends(AuthProvider()) | ||
): | ||
event.content_id = content_id | ||
event.set_by = current_user.id | ||
return content_event_crud.create_content_event(db=db, event=event) | ||
|
||
|
||
@router.get("/content/{content_id}/events/{event_id}", response_model=ContentEvent) | ||
def read_content_event( | ||
content_id: int, | ||
event_id: int, | ||
db: Session = Depends(get_db) | ||
): | ||
db_event = content_event_crud.get_content_event(db, event_id=event_id) | ||
if db_event is None or db_event.content_id != content_id: | ||
raise HTTPException(status_code=404, detail="Content event not found") | ||
return db_event | ||
|
||
|
||
@router.get("/content/{content_id}/events/", response_model=List[ContentEvent]) | ||
def read_content_events( | ||
content_id: int, | ||
skip: int = 0, | ||
limit: int = 100, | ||
db: Session = Depends(get_db) | ||
): | ||
events = content_event_crud.get_content_events(db, content_id=content_id, skip=skip, limit=limit) | ||
return events | ||
|
||
|
||
@router.put("/content/{content_id}/events/{event_id}", response_model=ContentEvent) | ||
def update_content_event( | ||
content_id: int, | ||
event_id: int, | ||
event: ContentEventUpdate, | ||
db: Session = Depends(get_db), | ||
current_user=Depends(AuthProvider()) | ||
): | ||
db_event = content_event_crud.update_content_event(db, event_id=event_id, event=event) | ||
if db_event is None or db_event.content_id != content_id: | ||
raise HTTPException(status_code=404, detail="Content event not found") | ||
return db_event | ||
|
||
|
||
@router.delete("/content/{content_id}/events/{event_id}", response_model=bool) | ||
def delete_content_event( | ||
content_id: int, | ||
event_id: int, | ||
db: Session = Depends(get_db), | ||
current_user=Depends(AuthProvider()) | ||
): | ||
success = content_event_crud.delete_content_event(db, event_id=event_id) | ||
if not success: | ||
raise HTTPException(status_code=404, detail="Content event not found") | ||
return success | ||
|
||
|
||
@router.get("/content/{content_id}/status", response_model=ContentStatus) | ||
def get_content_status( | ||
content_id: int, | ||
db: Session = Depends(get_db) | ||
): | ||
status = content_event_crud.get_latest_content_status(db, content_id=content_id) | ||
if status is None: | ||
raise HTTPException(status_code=404, detail="Content not found or no status events") | ||
return status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
modules/odr_core/odr_core/crud/annotation/annotation_report.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from sqlalchemy.orm import Session | ||
from odr_core.models.annotation import AnnotationReport | ||
from odr_core.schemas.annotation import AnnotationReportCreate, AnnotationReportUpdate | ||
|
||
|
||
def create_annotation_report(db: Session, report: AnnotationReportCreate) -> AnnotationReport: | ||
db_report = AnnotationReport(**report.model_dump()) | ||
db.add(db_report) | ||
db.commit() | ||
db.refresh(db_report) | ||
return db_report | ||
|
||
|
||
def get_annotation_report(db: Session, report_id: int) -> AnnotationReport | None: | ||
return db.query(AnnotationReport).filter(AnnotationReport.id == report_id).first() | ||
|
||
|
||
def get_annotation_reports(db: Session, annotation_id: int, skip: int = 0, limit: int = 100): | ||
return db.query(AnnotationReport).filter(AnnotationReport.annotation_id == annotation_id).offset(skip).limit(limit).all() | ||
|
||
|
||
def update_annotation_report(db: Session, report_id: int, report: AnnotationReportUpdate) -> AnnotationReport | None: | ||
db_report = db.query(AnnotationReport).filter(AnnotationReport.id == report_id).first() | ||
if db_report: | ||
update_data = report.model_dump(exclude_unset=True) | ||
for key, value in update_data.items(): | ||
setattr(db_report, key, value) | ||
db.commit() | ||
db.refresh(db_report) | ||
return db_report | ||
|
||
|
||
def delete_annotation_report(db: Session, report_id: int) -> bool: | ||
db_report = db.query(AnnotationReport).filter(AnnotationReport.id == report_id).first() | ||
if db_report: | ||
db.delete(db_report) | ||
db.commit() | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from sqlalchemy.orm import Session | ||
from odr_core.models.content import ContentEvents, ContentStatus | ||
from odr_core.schemas.content import ContentEventCreate, ContentEventUpdate | ||
from typing import List, Optional | ||
|
||
|
||
def create_content_event(db: Session, event: ContentEventCreate) -> ContentEvents: | ||
db_event = ContentEvents(**event.model_dump()) | ||
db.add(db_event) | ||
db.commit() | ||
db.refresh(db_event) | ||
return db_event | ||
|
||
|
||
def get_content_event(db: Session, event_id: int) -> Optional[ContentEvents]: | ||
return db.query(ContentEvents).filter(ContentEvents.id == event_id).first() | ||
|
||
|
||
def get_content_events(db: Session, content_id: int, skip: int = 0, limit: int = 100) -> List[ContentEvents]: | ||
return db.query(ContentEvents).filter(ContentEvents.content_id == content_id).offset(skip).limit(limit).all() | ||
|
||
|
||
def update_content_event(db: Session, event_id: int, event: ContentEventUpdate) -> Optional[ContentEvents]: | ||
db_event = get_content_event(db, event_id) | ||
if db_event: | ||
update_data = event.model_dump(exclude_unset=True) | ||
for key, value in update_data.items(): | ||
setattr(db_event, key, value) | ||
db.commit() | ||
db.refresh(db_event) | ||
return db_event | ||
|
||
|
||
def delete_content_event(db: Session, event_id: int) -> bool: | ||
db_event = get_content_event(db, event_id) | ||
if db_event: | ||
db.delete(db_event) | ||
db.commit() | ||
return True | ||
return False | ||
|
||
|
||
def get_latest_content_status(db: Session, content_id: int) -> Optional[ContentStatus]: | ||
latest_event = db.query(ContentEvents).filter(ContentEvents.content_id | ||
== content_id).order_by(ContentEvents.created_at.desc()).first() | ||
return latest_event.status if latest_event else None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from sqlalchemy.orm import Session | ||
from odr_core.models.content import ContentReport | ||
from odr_core.schemas.content_report import ContentReportCreate, ContentReportUpdate | ||
from typing import List, Optional | ||
|
||
|
||
def create_content_report(db: Session, report: ContentReportCreate) -> ContentReport: | ||
db_report = ContentReport(**report.model_dump()) | ||
db.add(db_report) | ||
db.commit() | ||
db.refresh(db_report) | ||
return db_report | ||
|
||
|
||
def get_content_report(db: Session, report_id: int) -> Optional[ContentReport]: | ||
return db.query(ContentReport).filter(ContentReport.id == report_id).first() | ||
|
||
|
||
def get_content_reports(db: Session, skip: int = 0, limit: int = 100) -> List[ContentReport]: | ||
return db.query(ContentReport).offset(skip).limit(limit).all() | ||
|
||
|
||
def update_content_report(db: Session, report_id: int, report: ContentReportUpdate) -> Optional[ContentReport]: | ||
db_report = db.query(ContentReport).filter(ContentReport.id == report_id).first() | ||
if db_report: | ||
update_data = report.model_dump(exclude_unset=True) | ||
for key, value in update_data.items(): | ||
setattr(db_report, key, value) | ||
db.commit() | ||
db.refresh(db_report) | ||
return db_report | ||
|
||
|
||
def delete_content_report(db: Session, report_id: int) -> bool: | ||
db_report = db.query(ContentReport).filter(ContentReport.id == report_id).first() | ||
if db_report: | ||
db.delete(db_report) | ||
db.commit() | ||
return True | ||
return False |
Oops, something went wrong.