diff --git a/backend/app/api/v1/tasks.py b/backend/app/api/v1/tasks.py index 0d587ca8..92ee9b8e 100644 --- a/backend/app/api/v1/tasks.py +++ b/backend/app/api/v1/tasks.py @@ -39,8 +39,8 @@ def generate_task(request: protocol_schema.TaskRequest) -> protocol_schema.Task: detail="Invalid request type.", ) logger.info(f"Generated {task=}.") - if request.user_id is not None: - task.addressed_users = [request.user_id] + if request.user is not None: + task.addressed_users = [request.user] return task @@ -112,21 +112,21 @@ def post_interaction( match (type(interaction)): case protocol_schema.TextReplyToPost: logger.info( - f"Frontend reports text reply to {interaction.post_id=} with {interaction.text=} by {interaction.user_id=}." + f"Frontend reports text reply to {interaction.post_id=} with {interaction.text=} by {interaction.user=}." ) # here we would store the text reply in the database return protocol_schema.TaskDone( reply_to_post_id=interaction.user_post_id, - addressed_users=[interaction.user_id], + addressed_users=[interaction.user], ) case protocol_schema.PostRating: logger.info( - f"Frontend reports rating of {interaction.post_id=} with {interaction.rating=} by {interaction.user_id=}." + f"Frontend reports rating of {interaction.post_id=} with {interaction.rating=} by {interaction.user=}." ) # here we would store the rating in the database return protocol_schema.TaskDone( reply_to_post_id=interaction.post_id, - addressed_users=[interaction.user_id], + addressed_users=[interaction.user], ) case _: raise HTTPException( diff --git a/backend/app/schemas/protocol.py b/backend/app/schemas/protocol.py index 34ef571f..e72a7388 100644 --- a/backend/app/schemas/protocol.py +++ b/backend/app/schemas/protocol.py @@ -13,11 +13,16 @@ class TaskRequestType(str, enum.Enum): rate_summary = "rate_summary" +class User(BaseModel): + id: str + name: str + + class TaskRequest(BaseModel): """The frontend asks the backend for a task.""" type: TaskRequestType = TaskRequestType.generic - user_id: Optional[str] = None + user: Optional[User] = None class Task(BaseModel): @@ -25,7 +30,7 @@ class Task(BaseModel): id: UUID = pydantic.Field(default_factory=uuid4) type: str - addressed_users: Optional[list[str]] = None + addressed_users: Optional[list[User]] = None class TaskResponse(BaseModel): @@ -81,10 +86,10 @@ AnyTask = Union[ class Interaction(BaseModel): - """An interaction is a message from the frontend to the backend.""" + """An interaction is a user-generated action in the frontend.""" type: str - user_id: str + user: User class TextReplyToPost(Interaction): diff --git a/text-frontend/__main__.py b/text-frontend/__main__.py index 5810d436..0029031f 100644 --- a/text-frontend/__main__.py +++ b/text-frontend/__main__.py @@ -38,7 +38,7 @@ def main(backend_url: str, api_key: str): "post_id": "1234", "user_post_id": "5678", "text": summary, - "user_id": "1234", + "user": {"id": "1234", "name": "John Doe"}, }, ) tasks.append(new_task) @@ -60,7 +60,7 @@ def main(backend_url: str, api_key: str): "type": "post_rating", "post_id": "1234", "rating": rating, - "user_id": "1234", + "user": {"id": "1234", "name": "John Doe"}, }, ) tasks.append(new_task)