mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
fix: sort recent recipes by created_at instead of date_added (#1417)
* added staticmethod decorators to avoid mypy error * exposed created and updated timestamps to schema * changed default sort from date_added to created_at * explicitely sort recent recipes by created_at * removed static method and replaced w/ type: ignore
This commit is contained in:
parent
8b054fd945
commit
efffe26a19
@ -97,7 +97,7 @@ export const useRecipes = (all = false, fetchRecipes = true) => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
async function refreshRecipes() {
|
async function refreshRecipes() {
|
||||||
const { data } = await api.recipes.getAll(start, end, { loadFood: true });
|
const { data } = await api.recipes.getAll(start, end, { loadFood: true, orderBy: "created_at" });
|
||||||
if (data) {
|
if (data) {
|
||||||
recipes.value = data;
|
recipes.value = data;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ class RepositoryRecipes(RepositoryGeneric[Recipe, RecipeModel]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def summary(
|
def summary(
|
||||||
self, group_id, start=0, limit=99999, load_foods=False, order_by="date_added", order_descending=True
|
self, group_id, start=0, limit=99999, load_foods=False, order_by="created_at", order_descending=True
|
||||||
) -> Any:
|
) -> Any:
|
||||||
args = [
|
args = [
|
||||||
joinedload(RecipeModel.recipe_category),
|
joinedload(RecipeModel.recipe_category),
|
||||||
@ -106,11 +106,11 @@ class RepositoryRecipes(RepositoryGeneric[Recipe, RecipeModel]):
|
|||||||
if order_by:
|
if order_by:
|
||||||
order_attr = getattr(RecipeModel, order_by)
|
order_attr = getattr(RecipeModel, order_by)
|
||||||
else:
|
else:
|
||||||
order_attr = RecipeModel.date_added
|
order_attr = RecipeModel.created_at
|
||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.logger.info(f'Attempted to sort by unknown sort property "{order_by}"; ignoring')
|
self.logger.info(f'Attempted to sort by unknown sort property "{order_by}"; ignoring')
|
||||||
order_attr = RecipeModel.date_added
|
order_attr = RecipeModel.created_at
|
||||||
|
|
||||||
if order_descending:
|
if order_descending:
|
||||||
order_attr = order_attr.desc()
|
order_attr = order_attr.desc()
|
||||||
|
@ -83,6 +83,9 @@ class RecipeSummary(MealieModel):
|
|||||||
date_added: Optional[datetime.date]
|
date_added: Optional[datetime.date]
|
||||||
date_updated: Optional[datetime.datetime]
|
date_updated: Optional[datetime.datetime]
|
||||||
|
|
||||||
|
created_at: Optional[datetime.datetime]
|
||||||
|
update_at: Optional[datetime.datetime]
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
|
||||||
@ -163,7 +166,7 @@ class Recipe(RecipeSummary):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@validator("slug", always=True, pre=True, allow_reuse=True)
|
@validator("slug", always=True, pre=True, allow_reuse=True)
|
||||||
def validate_slug(slug: str, values):
|
def validate_slug(slug: str, values): # type: ignore
|
||||||
if not values.get("name"):
|
if not values.get("name"):
|
||||||
return slug
|
return slug
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user