Skip to content

Commit

Permalink
chore: create method to get tasks from user
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrzn committed Jul 9, 2024
1 parent ae09394 commit 7c23118
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
30 changes: 28 additions & 2 deletions autotx/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def start(self, prompt: str, address: str, chain_id: int, app_user_id: str, prev

return models.Task(
id=result.data[0]["id"],
app_user_id=app_user_id,
prompt=prompt,
address=address,
chain_id=chain_id,
Expand Down Expand Up @@ -130,7 +129,6 @@ def get(self, task_id: str) -> models.Task | None:

return models.Task(
id=task_data["id"],
app_user_id=task_data["app_user_id"],
prompt=task_data["prompt"],
address=task_data["address"],
chain_id=task_data["chain_id"],
Expand All @@ -152,6 +150,34 @@ def get_all(self) -> list[models.Task]:

tasks = []

for task_data in result.data:
tasks.append(
models.Task(
id=task_data["id"],
prompt=task_data["prompt"],
address=task_data["address"],
chain_id=task_data["chain_id"],
created_at=task_data["created_at"],
updated_at=task_data["updated_at"],
running=task_data["running"],
error=task_data["error"],
messages=json.loads(task_data["messages"]),
logs=[models.TaskLog(**log) for log in json.loads(task_data["logs"])] if task_data["logs"] else None,
intents=[load_intent(intent) for intent in json.loads(task_data["intents"])],
previous_task_id=task_data["previous_task_id"],
feedback=task_data["feedback"]
)
)

return tasks

def get_from_user(self, app_user_id: str) -> list[models.Task]:
client = get_db_client("public")

result = client.table("tasks").select("*").eq("app_id", self.app_id).eq("app_user_id", app_user_id).execute()

tasks = []

for task_data in result.data:
tasks.append(
models.Task(
Expand Down
2 changes: 0 additions & 2 deletions autotx/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from datetime import datetime

from autotx.intents import Intent
from autotx.transactions import TransactionBase

class TaskLog(BaseModel):
type: str
Expand All @@ -12,7 +11,6 @@ class TaskLog(BaseModel):

class Task(BaseModel):
id: str
app_user_id: str
prompt: str
address: str
chain_id: int
Expand Down
3 changes: 1 addition & 2 deletions autotx/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def get_user_tasks(
user_id: str, authorization: Annotated[str | None, Header()] = None
) -> dict[str, list[Any]]:
(app, app_user) = authorize_app_and_user(authorization, user_id)
tasks = db.TasksRepository(app_id=app.id).get_all()
tasks = db.TasksRepository(app_id=app.id).get_from_user(app_user.id)
user_tasks = [
{
"id": task.id,
Expand All @@ -309,7 +309,6 @@ def get_user_tasks(
"intents": task.intents,
}
for task in tasks
if task.app_user_id == app_user.id
]
user_submitted_transactions = [
batch for batch in db.get_submitted_transactions_from_user(app.id, app_user.id)
Expand Down

0 comments on commit 7c23118

Please sign in to comment.