Skip to content

Commit

Permalink
feat: add_training_event with subcategory (#79)
Browse files Browse the repository at this point in the history
* InsertTrainingEvent method #78

* removed unused imports

* fixed type errors

* added type def to event_rows

* fixed .append() call syntax

* made requested changes regarding id formatting

* fixed Ruff CI errors
  • Loading branch information
SenneDrent authored Dec 8, 2023
1 parent 9443e80 commit 85d169a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/apiserver/data/api/trainings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from datetime import date
from schema.model.model import C_EVENTS_CATEGORY, C_EVENTS_DATE, C_EVENTS_DESCRIPTION, C_EVENTS_ID, CLASS_EVENTS_TABLE, CLASS_ID
from sqlalchemy.ext.asyncio import AsyncConnection
from store.db import LiteralDict, insert_many

async def add_training_event(
conn: AsyncConnection,
classification_id: int,
categories: list[str],
event_date: date,
description: str = "",
) -> list[str]:
"""breaks up a training into their subcategories and insert them into the class_events table.
event_id will be created in the form of: "training[yyyy/dd/mm][category]"
we make the assumption that there are no two trainings in a day"""
idList = []
event_rows: list[LiteralDict] = []
for subCategory in categories:
subEventId = f'training{event_date.isoformat()}{subCategory}'
idList.append(subEventId)

event_row: LiteralDict = {
C_EVENTS_ID: subEventId,
CLASS_ID: classification_id,
C_EVENTS_CATEGORY: subCategory,
C_EVENTS_DATE: event_date,
C_EVENTS_DESCRIPTION: description,
}
event_rows.append(event_row)
await insert_many(conn, CLASS_EVENTS_TABLE, event_rows)

return idList

0 comments on commit 85d169a

Please sign in to comment.