feat: recipe timeline backend api (#1685)

* added recipe_timeline_events table to db

* added schema and routes for recipe timeline events

* added missing mixin and fixed update schema

* added tests

* adjusted migration revision tree

* updated alembic revision test

* added initial timeline event for new recipes

* added additional tests

* added event bus support

* renamed event_dt to timestamp

* add timeline_events to ignore list

* run code-gen

* use new test routes implementation

* use doc string syntax

* moved event type enum from db to schema

Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com>
This commit is contained in:
Michael Genson
2022-11-01 03:12:26 -05:00
committed by GitHub
parent 714a080ecb
commit 6ee64535df
19 changed files with 639 additions and 6 deletions

View File

@@ -64,6 +64,7 @@ class EventDocumentType(Enum):
shopping_list_item = "shopping_list_item"
recipe = "recipe"
recipe_bulk_report = "recipe_bulk_report"
recipe_timeline_event = "recipe_timeline_event"
tag = "tag"
@@ -123,6 +124,12 @@ class EventRecipeBulkReportData(EventDocumentDataBase):
report_id: UUID4
class EventRecipeTimelineEventData(EventDocumentDataBase):
document_type = EventDocumentType.recipe_timeline_event
recipe_slug: str
recipe_timeline_event_id: UUID4
class EventTagData(EventDocumentDataBase):
document_type = EventDocumentType.tag
tag_id: UUID4

View File

@@ -1,5 +1,6 @@
import json
import shutil
from datetime import datetime
from pathlib import Path
from shutil import copytree, rmtree
from typing import Union
@@ -13,6 +14,7 @@ from mealie.schema.recipe.recipe import CreateRecipe, Recipe
from mealie.schema.recipe.recipe_ingredient import RecipeIngredient
from mealie.schema.recipe.recipe_settings import RecipeSettings
from mealie.schema.recipe.recipe_step import RecipeStep
from mealie.schema.recipe.recipe_timeline_events import RecipeTimelineEventCreate, TimelineEventType
from mealie.schema.user.user import GroupInDB, PrivateUser
from mealie.services._base_service import BaseService
from mealie.services.recipe.recipe_data_service import RecipeDataService
@@ -132,7 +134,19 @@ class RecipeService(BaseService):
else:
data.settings = RecipeSettings()
return self.repos.recipes.create(data)
new_recipe = self.repos.recipes.create(data)
# create first timeline entry
timeline_event_data = RecipeTimelineEventCreate(
user_id=new_recipe.user_id,
recipe_id=new_recipe.id,
subject="Recipe Created",
event_type=TimelineEventType.system,
timestamp=new_recipe.created_at or datetime.now(),
)
self.repos.recipe_timeline_events.create(timeline_event_data)
return new_recipe
def create_from_zip(self, archive: UploadFile, temp_path: Path) -> Recipe:
"""