refactor schema folders

This commit is contained in:
hay-kot
2021-08-01 19:24:33 -08:00
parent 0e8e2971d0
commit d67240d449
49 changed files with 109 additions and 60 deletions

View File

@@ -0,0 +1,6 @@
from .about import *
from .backup import *
from .migration import *
from .restore import *
from .settings import *
from .theme import *

View File

@@ -0,0 +1,25 @@
from pathlib import Path
from fastapi_camelcase import CamelModel
class AppStatistics(CamelModel):
total_recipes: int
total_users: int
total_groups: int
uncategorized_recipes: int
untagged_recipes: int
class AppInfo(CamelModel):
production: bool
version: str
demo_status: bool
class DebugInfo(AppInfo):
api_port: int
api_docs: bool
db_type: str
db_url: Path
default_group: str

View File

@@ -0,0 +1,81 @@
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel
class BackupOptions(BaseModel):
recipes: bool = True
settings: bool = True
pages: bool = True
themes: bool = True
groups: bool = True
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 BackupJob(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 LocalBackup(BaseModel):
name: str
date: datetime
class Imports(BaseModel):
imports: List[LocalBackup]
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

@@ -0,0 +1,31 @@
from datetime import datetime
from typing import List
from pydantic.main import BaseModel
from .restore import RecipeImport
class ChowdownURL(BaseModel):
url: str
class Config:
schema_extra = {
"example": {
"url": "https://chowdownrepo.com/repo",
}
}
class MigrationFile(BaseModel):
name: str
date: datetime
class Migrations(BaseModel):
type: str
files: List[MigrationFile] = []
class MigrationImport(RecipeImport):
pass

View File

@@ -0,0 +1,37 @@
from typing import Optional
from pydantic.main import BaseModel
class ImportBase(BaseModel):
name: str
status: bool
exception: Optional[str]
class RecipeImport(ImportBase):
slug: Optional[str]
class ThemeImport(ImportBase):
pass
class SettingsImport(ImportBase):
pass
class GroupImport(ImportBase):
pass
class UserImport(ImportBase):
pass
class CustomPageImport(ImportBase):
pass
class NotificationImport(ImportBase):
pass

View File

@@ -0,0 +1,58 @@
from typing import Optional
from fastapi_camelcase import CamelModel
from pydantic import validator
from slugify import slugify
from ..recipe.category import CategoryBase, RecipeCategoryResponse
class SiteSettings(CamelModel):
language: str = "en-US"
first_day_of_week: int = 0
show_recent: bool = True
cards_per_section: int = 9
categories: Optional[list[CategoryBase]] = []
class Config:
orm_mode = True
schema_extra = {
"example": {
"language": "en",
"firstDayOfWeek": 0,
"showRecent": True,
"categories": [
{"id": 1, "name": "thanksgiving", "slug": "thanksgiving"},
{"id": 2, "name": "homechef", "slug": "homechef"},
{"id": 3, "name": "potatoes", "slug": "potatoes"},
],
}
}
class CustomPageBase(CamelModel):
name: str
slug: Optional[str]
position: int
categories: list[RecipeCategoryResponse] = []
class Config:
orm_mode = True
@validator("slug", always=True, pre=True)
def validate_slug(slug: str, values):
name: str = values["name"]
calc_slug: str = slugify(name)
if slug != calc_slug:
slug = calc_slug
return slug
class CustomPageOut(CustomPageBase):
id: int
class Config:
orm_mode = True

View File

@@ -0,0 +1,39 @@
from typing import Optional
from pydantic import BaseModel
class Colors(BaseModel):
primary: str = "#E58325"
accent: str = "#00457A"
secondary: str = "#973542"
success: str = "#43A047"
info: str = "#1976D2"
warning: str = "#FF6F00"
error: str = "#EF5350"
class Config:
orm_mode = True
class SiteTheme(BaseModel):
id: Optional[int]
name: str = "default"
colors: Colors = Colors()
class Config:
orm_mode = True
schema_extra = {
"example": {
"name": "default",
"colors": {
"primary": "#E58325",
"accent": "#00457A",
"secondary": "#973542",
"success": "#5AB1BB",
"info": "#4990BA",
"warning": "#FF4081",
"error": "#EF5350",
},
}
}