mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-29 05:25:30 -05:00
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:
@@ -18,6 +18,7 @@ from .ingredient import RecipeIngredient
|
||||
from .instruction import RecipeInstruction
|
||||
from .note import Note
|
||||
from .nutrition import Nutrition
|
||||
from .recipe_timeline import RecipeTimelineEvent
|
||||
from .settings import RecipeSettings
|
||||
from .shared import RecipeShareTokenModel
|
||||
from .tag import recipes_to_tags
|
||||
@@ -82,6 +83,10 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
"RecipeComment", back_populates="recipe", cascade="all, delete, delete-orphan"
|
||||
)
|
||||
|
||||
timeline_events: list[RecipeTimelineEvent] = orm.relationship(
|
||||
"RecipeTimelineEvent", back_populates="recipe", cascade="all, delete, delete-orphan"
|
||||
)
|
||||
|
||||
# Mealie Specific
|
||||
settings = orm.relationship("RecipeSettings", uselist=False, cascade="all, delete-orphan")
|
||||
tags = orm.relationship("Tag", secondary=recipes_to_tags, back_populates="recipes")
|
||||
@@ -117,6 +122,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
"recipe_instructions",
|
||||
"settings",
|
||||
"comments",
|
||||
"timeline_events",
|
||||
}
|
||||
|
||||
@validates("name")
|
||||
|
||||
38
mealie/db/models/recipe/recipe_timeline.py
Normal file
38
mealie/db/models/recipe/recipe_timeline.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from .._model_base import BaseMixins, SqlAlchemyBase
|
||||
from .._model_utils import auto_init
|
||||
from .._model_utils.guid import GUID
|
||||
|
||||
|
||||
class RecipeTimelineEvent(SqlAlchemyBase, BaseMixins):
|
||||
__tablename__ = "recipe_timeline_events"
|
||||
id = Column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
# Parent Recipe
|
||||
recipe_id = Column(GUID, ForeignKey("recipes.id"), nullable=False)
|
||||
recipe = relationship("RecipeModel", back_populates="timeline_events")
|
||||
|
||||
# Related User (Actor)
|
||||
user_id = Column(GUID, ForeignKey("users.id"), nullable=False)
|
||||
user = relationship("User", back_populates="recipe_timeline_events", single_parent=True, foreign_keys=[user_id])
|
||||
|
||||
# General Properties
|
||||
subject = Column(String, nullable=False)
|
||||
message = Column(String)
|
||||
event_type = Column(String)
|
||||
image = Column(String)
|
||||
|
||||
# Timestamps
|
||||
timestamp = Column(DateTime)
|
||||
|
||||
@auto_init()
|
||||
def __init__(
|
||||
self,
|
||||
timestamp=None,
|
||||
**_,
|
||||
) -> None:
|
||||
self.timestamp = timestamp or datetime.now()
|
||||
@@ -52,6 +52,7 @@ class User(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
tokens = orm.relationship(LongLiveToken, **sp_args)
|
||||
comments = orm.relationship("RecipeComment", **sp_args)
|
||||
recipe_timeline_events = orm.relationship("RecipeTimelineEvent", **sp_args)
|
||||
password_reset_tokens = orm.relationship("PasswordResetModel", **sp_args)
|
||||
|
||||
owned_recipes_id = Column(GUID, ForeignKey("recipes.id"))
|
||||
|
||||
Reference in New Issue
Block a user