1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-08-05 13:35:23 +02:00

Refactor/conver to controllers (#923)

* add dependency injection for get_repositories

* convert events api to controller

* update generic typing

* add abstract controllers

* update test naming

* migrate admin services to controllers

* add additional admin route tests

* remove print

* add public shared dependencies

* add types

* fix typo

* add static variables for recipe json keys

* add coverage gutters config

* update controller routers

* add generic success response

* add category/tag/tool tests

* add token refresh test

* add coverage utilities

* covert comments to controller

* add todo

* add helper properties

* delete old service

* update test notes

* add unit test for pretty_stats

* remove dead code from post_webhooks

* update group routes to use controllers

* add additional group test coverage

* abstract common permission checks

* convert ingredient parser to controller

* update recipe crud to use controller

* remove dead-code

* add class lifespan tracker for debugging

* convert bulk export to controller

* migrate tools router to controller

* update recipe share to controller

* move customer router to _base

* ignore prints in flake8

* convert units and foods to new controllers

* migrate user routes to controllers

* centralize error handling

* fix invalid ref

* reorder fields

* update routers to share common handling

* update tests

* remove prints

* fix cookbooks delete

* fix cookbook get

* add controller for mealplanner

* cover report routes to controller

* remove __future__ imports

* remove dead code

* remove all base_http children and remove dead code
This commit is contained in:
Hayden 2022-01-13 13:06:52 -09:00 committed by GitHub
parent 5823a32daf
commit c4540f1395
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
164 changed files with 3111 additions and 3213 deletions

View file

@ -30,3 +30,4 @@ class CheckAppConfig(CamelModel):
email_ready: bool = False
ldap_ready: bool = False
base_url_set: bool = False
is_up_to_date: bool = False

View file

@ -12,50 +12,18 @@ class BackupOptions(BaseModel):
users: bool = True
notifications: bool = True
class Config:
schema_extra = {
"example": {
"recipes": True,
"settings": True,
"themes": True,
"groups": True,
"users": True,
}
}
class ImportJob(BackupOptions):
name: str
force: bool = False
rebase: bool = False
class Config:
schema_extra = {
"example": {
"name": "my_local_backup.zip",
"recipes": True,
"settings": True,
"themes": True,
"groups": True,
"users": True,
}
}
class CreateBackup(BaseModel):
tag: Optional[str]
options: BackupOptions
templates: Optional[List[str]]
class Config:
schema_extra = {
"example": {
"tag": "July 23rd 2021",
"options": BackupOptions(),
"template": ["recipes.md"],
}
}
class BackupFile(BaseModel):
name: str
@ -66,16 +34,3 @@ class BackupFile(BaseModel):
class AllBackups(BaseModel):
imports: List[BackupFile]
templates: List[str]
class Config:
schema_extra = {
"example": {
"imports": [
{
"name": "AutoBackup_12-1-2020.zip",
"date": datetime.now(),
}
],
"templates": ["recipes.md", "custom_template.md"],
}
}

View file

@ -9,13 +9,6 @@ from .restore import RecipeImport
class ChowdownURL(BaseModel):
url: str
class Config:
schema_extra = {
"example": {
"url": "https://chowdownrepo.com/repo",
}
}
class MigrationFile(BaseModel):
name: str

View file

@ -1,7 +1,5 @@
from uuid import UUID
from fastapi_camelcase import CamelModel
from pydantic import validator
from pydantic import UUID4, validator
from slugify import slugify
from ..recipe.recipe_category import CategoryBase, RecipeCategoryResponse
@ -25,16 +23,16 @@ class CreateCookBook(CamelModel):
return slug
class UpdateCookBook(CreateCookBook):
class SaveCookBook(CreateCookBook):
group_id: UUID4
class UpdateCookBook(SaveCookBook):
id: int
class SaveCookBook(CreateCookBook):
group_id: UUID
class ReadCookBook(UpdateCookBook):
group_id: UUID
group_id: UUID4
categories: list[CategoryBase] = []
class Config:
@ -42,7 +40,7 @@ class ReadCookBook(UpdateCookBook):
class RecipeCookBook(ReadCookBook):
group_id: UUID
group_id: UUID4
categories: list[RecipeCategoryResponse]
class Config:

View file

@ -1,5 +1,3 @@
from __future__ import annotations
import datetime
from pathlib import Path
from typing import Any, Optional

View file

@ -1,2 +1,2 @@
# GENERATED CODE - DO NOT MODIFY BY HAND
from .error_response import *
from .responses import *

View file

@ -15,3 +15,16 @@ class ErrorResponse(BaseModel):
in the same call, for use while providing details to a HTTPException
"""
return cls(message=message, exception=exception).dict()
class SuccessResponse(BaseModel):
message: str
error: bool = False
@classmethod
def respond(cls, message: str) -> dict:
"""
This method is an helper to create an obect and convert to a dictionary
in the same call, for use while providing details to a HTTPException
"""
return cls(message=message).dict()

View file

@ -0,0 +1 @@
from .recipe_keys import *

View file

@ -0,0 +1,136 @@
cook_time = "cookTime"
cooking_method = "cookingMethod"
nutrition = "nutrition"
recipe_category = "recipeCategory"
recipe_cuisine = "recipeCuisine"
recipe_ingredient = "recipeIngredient"
recipe_instructions = "recipeInstructions"
recipe_yield = "recipeYield"
suitable_for_diet = "suitableForDiet"
estimated_cost = "estimatedCost"
perform_time = "performTime"
prep_time = "prepTime"
step = "step"
supply = "supply"
tool = "tool"
total_time = "totalTime"
y_yield = "yield"
about = "about"
abstract = "abstract"
access_mode = "accessMode"
access_mode_sufficient = "accessModeSufficient"
accessibility_api = "accessibilityAPI"
accessibility_control = "accessibilityControl"
accessibility_feature = "accessibilityFeature"
accessibility_hazard = "accessibilityHazard"
accessibility_summary = "accessibilitySummary"
accountable_person = "accountablePerson"
acquire_license_page = "acquireLicensePage"
aggregate_rating = "aggregateRating"
alternative_headline = "alternativeHeadline"
archived_at = "archivedAt"
assesses = "assesses"
associated_media = "associatedMedia"
audience = "audience"
audio = "audio"
author = "author"
award = "award"
character = "character"
citation = "citation"
comment = "comment"
comment_count = "commentCount"
conditions_of_access = "conditionsOfAccess"
content_location = "contentLocation"
content_rating = "contentRating"
content_reference_time = "contentReferenceTime"
contributor = "contributor"
copyright_holder = "copyrightHolder"
copyright_notice = "copyrightNotice"
copyright_year = "copyrightYear"
correction = "correction"
country_of_origin = "countryOfOrigin"
creative_work_status = "creativeWorkStatus"
creator = "creator"
credit_text = "creditText"
date_created = "dateCreated"
date_created = "dateCreated"
date_modified = "dateModified"
date_published = "datePublished"
discussion_url = "discussionUrl"
edit_eidr = "editEIDR"
editor = "editor"
educational_alignment = "educationalAlignment"
educational_level = "educationalLevel"
educational_use = "educationalUse"
encoding = "encoding"
encoding_format = "encodingFormat"
example_of_work = "exampleOfWork"
expires = "expires"
funder = "funder"
genre = "genre"
has_part = "hasPart"
headline = "headline"
in_language = "inLanguage"
interaction_statistic = "interactionStatistic"
interactivity_type = "interactivityType"
interpreted_as_claim = "interpretedAsClaim"
is_accessible_for_free = "isAccessibleForFree"
is_based_on = "isBasedOn"
is_family_friendly = "isFamilyFriendly"
is_part_of = "isPartOf"
keywords = "keywords"
learning_resource_type = "learningResourceType"
license = "license"
location_created = "locationCreated"
main_entity = "mainEntity"
maintainer = "maintainer"
material = "material"
material_extent = "materialExtent"
mentions = "mentions"
offers = "offers"
pattern = "pattern"
position = "position"
producer = "producer"
provider = "provider"
publication = "publication"
publisher = "publisher"
publisher_imprint = "publisherImprint"
publishing_principles = "publishingPrinciples"
recorded_at = "recordedAt"
released_event = "releasedEvent"
review = "review"
schema_version = "schemaVersion"
sd_date_published = "sdDatePublished"
sd_license = "sdLicense"
sd_publisher = "sdPublisher"
size = "size"
source_organization = "sourceOrganization"
spatial = "spatial"
spatial_coverage = "spatialCoverage"
sponsor = "sponsor"
teaches = "teaches"
temporal = "temporal"
temporal_coverage = "temporalCoverage"
text = "text"
thumbnail_url = "thumbnailUrl"
time_required = "timeRequired"
translation_of_work = "translationOfWork"
translator = "translator"
typical_age_range = "typicalAgeRange"
usage_info = "usageInfo"
version = "version"
video = "video"
work_example = "workExample"
work_translation = "workTranslation"
additional_type = "additionalType"
alternate_name = "alternateName"
description = "description"
disambiguating_description = "disambiguatingDescription"
identifier = "identifier"
image = "image"
main_entity_of_page = "mainEntityOfPage"
name = "name"
potential_action = "potentialAction"
same_as = "sameAs"
subject_of = "subjectOf"
url = "url"