mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-03 18:53:17 -05:00 
			
		
		
		
	account for slugs or recipes when constructing user favorites
This commit is contained in:
		@@ -107,7 +107,7 @@ class UserOut(UserBase):
 | 
				
			|||||||
    group_slug: str
 | 
					    group_slug: str
 | 
				
			||||||
    tokens: list[LongLiveTokenOut] | None = None
 | 
					    tokens: list[LongLiveTokenOut] | None = None
 | 
				
			||||||
    cache_key: str
 | 
					    cache_key: str
 | 
				
			||||||
    favorite_recipes: Annotated[list[str] | None, Field(validate_default=True)] = []
 | 
					    favorite_recipes: Annotated[list[str], Field(validate_default=True)] = []
 | 
				
			||||||
    model_config = ConfigDict(from_attributes=True)
 | 
					    model_config = ConfigDict(from_attributes=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
@@ -119,8 +119,18 @@ class UserOut(UserBase):
 | 
				
			|||||||
        return [joinedload(User.group), joinedload(User.favorite_recipes), joinedload(User.tokens)]
 | 
					        return [joinedload(User.group), joinedload(User.favorite_recipes), joinedload(User.tokens)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @field_validator("favorite_recipes", mode="before")
 | 
					    @field_validator("favorite_recipes", mode="before")
 | 
				
			||||||
    def convert_favorite_recipes_to_slugs(cls, v):
 | 
					    def convert_favorite_recipes_to_slugs(cls, v: list[str | RecipeSummary] | None):
 | 
				
			||||||
        return [recipe.slug for recipe in v] if v else v
 | 
					        if not v:
 | 
				
			||||||
 | 
					            return []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        slugs: list[str] = []
 | 
				
			||||||
 | 
					        for recipe in v:
 | 
				
			||||||
 | 
					            if isinstance(recipe, str):
 | 
				
			||||||
 | 
					                slugs.append(recipe)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                slugs.append(recipe.slug)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return slugs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class UserPagination(PaginationBase):
 | 
					class UserPagination(PaginationBase):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user