From a43bc306bfcfd261eb01ebe9c1b90eef2a8a9d83 Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Thu, 18 Jul 2024 13:33:30 -0700 Subject: [PATCH] old stuff --- linguaphoto/crud/transcriptions.py | 17 ++++++++++++++ linguaphoto/db.py | 11 +++++++++ linguaphoto/model.py | 37 +++++++++--------------------- 3 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 linguaphoto/crud/transcriptions.py diff --git a/linguaphoto/crud/transcriptions.py b/linguaphoto/crud/transcriptions.py new file mode 100644 index 0000000..e08cc03 --- /dev/null +++ b/linguaphoto/crud/transcriptions.py @@ -0,0 +1,17 @@ +"""Defines CRUD interface for transcriptions API.""" + +import asyncio +import uuid +from io import BytesIO + +from PIL import Image + +from linguaphoto.crud.base import BaseCrud +from linguaphoto.settings import settings + + + + +class ImagesCrud(BaseCrud): + async def add_image_transcription(self, transcription_id: uuid.UUID, image_id: uuid.UUID, img: Image.Image) -> None: + asdf diff --git a/linguaphoto/db.py b/linguaphoto/db.py index 52831e7..eeb1d2f 100644 --- a/linguaphoto/db.py +++ b/linguaphoto/db.py @@ -61,6 +61,17 @@ async def create_tables(crud: Crud | None = None, deletion_protection: bool = Fa ], deletion_protection=deletion_protection, ), + crud._create_dynamodb_table( + name="Transcriptions", + keys=[ + ("transcription_id", "S", "HASH"), + ], + gsis=[ + ("userIndex", "user_id", "S", "HASH"), + ("imagesIndex", "image_id", "S", "HASH"), + ], + deletion_protection=deletion_protection, + ), ) diff --git a/linguaphoto/model.py b/linguaphoto/model.py index cbc571f..8fdee87 100644 --- a/linguaphoto/model.py +++ b/linguaphoto/model.py @@ -16,13 +16,6 @@ class User(BaseModel): user_id: str # Primary key email: str - @classmethod - def from_uuid(cls, user_id: uuid.UUID, email: str) -> "User": - return cls(user_id=str(user_id), email=email) - - def to_uuid(self) -> uuid.UUID: - return uuid.UUID(self.user_id) - class ApiKey(BaseModel): """Stored in Redis rather than DynamoDB.""" @@ -37,28 +30,20 @@ def from_api_key(cls, api_key: uuid.UUID, user_id: uuid.UUID, lifetime: int) -> return cls(api_key_hash=api_key_hash, user_id=str(user_id), lifetime=lifetime) -class Bom(BaseModel): - part_id: str - quantity: int - - class Image(BaseModel): - caption: str + image_id: str # Primary key + user_id: str url: str -class Robot(BaseModel): - robot_id: str # Primary key - owner: str - name: str - description: str - bom: list[Bom] - images: list[Image] +class Transcription(BaseModel): + transcript: str + pinyin: str + translation: str -class Part(BaseModel): - part_id: str # Primary key - part_name: str - owner: str - description: str - images: list[Image] +class Transcriptions(BaseModel): + transcript_id: str # Primary key + image_id: str + user_id: str + transcriptions: list[Transcription]