Rename plurals
This commit is contained in:
parent
ebab422869
commit
9e03f707dc
12 changed files with 28 additions and 28 deletions
6
db.py
6
db.py
|
|
@ -4,14 +4,14 @@ async def connect() -> aiosqlite.Connection:
|
|||
return await aiosqlite.connect('your_database.db')
|
||||
|
||||
async def create():
|
||||
import product.db as product_db
|
||||
import products.db as product_db
|
||||
conn = await connect()
|
||||
await product_db.create(conn)
|
||||
|
||||
import recipe.db as recipe_db
|
||||
import recipes.db as recipe_db
|
||||
await recipe_db.create(conn)
|
||||
|
||||
import person.db as person_db
|
||||
import persons.db as person_db
|
||||
await person_db.create(conn)
|
||||
|
||||
import meals.db as meals_db
|
||||
|
|
|
|||
32
main.py
32
main.py
|
|
@ -1,5 +1,5 @@
|
|||
import sqlite3
|
||||
import product, recipe, db, meals
|
||||
import products, recipes, db, meals
|
||||
import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
|
@ -28,8 +28,8 @@ async def get_db():
|
|||
await sql_db.close()
|
||||
|
||||
@app.get("/recipes/parse")
|
||||
async def parse_recipe_handler(url: str, conn: sqlite3.Connection = Depends(get_db)) -> recipe.Recipe:
|
||||
parsed = await recipe.parse_recipe(conn, url)
|
||||
async def parse_recipe_handler(url: str, conn: sqlite3.Connection = Depends(get_db)) -> recipes.Recipe:
|
||||
parsed = await recipes.parse_recipe(conn, url)
|
||||
if not parsed:
|
||||
return JSONResponse(status_code=400, content={'message': 'Recipe not found'})
|
||||
return parsed
|
||||
|
|
@ -39,9 +39,9 @@ async def parse_ingredients(lines: Annotated[
|
|||
List[str],
|
||||
Query(alias="ingredients",
|
||||
title="Array of ingredients to parse")],
|
||||
conn: sqlite3.Connection = Depends(get_db)) -> List[recipe.Ingredient]:
|
||||
ingredients = recipe.parse_ingredient_from_nlp(lines)
|
||||
recipe.match_existing_products(conn, ingredients)
|
||||
conn: sqlite3.Connection = Depends(get_db)) -> List[recipes.Ingredient]:
|
||||
ingredients = recipes.parse_ingredient_from_nlp(lines)
|
||||
recipes.match_existing_products(conn, ingredients)
|
||||
return ingredients
|
||||
|
||||
class ProductUrl(BaseModel):
|
||||
|
|
@ -49,23 +49,23 @@ class ProductUrl(BaseModel):
|
|||
tags: List[str] = []
|
||||
|
||||
@app.post("/products/")
|
||||
async def create_product(url: ProductUrl, conn: sqlite3.Connection = Depends(get_db)) -> product.Product:
|
||||
return await product.get_or_create(conn, url.url, url.tags)
|
||||
async def create_product(url: ProductUrl, conn: sqlite3.Connection = Depends(get_db)) -> products.Product:
|
||||
return await products.get_or_create(conn, url.url, url.tags)
|
||||
|
||||
async def load_full_recipe(conn: sqlite3.Connection, id: int) -> recipe.Recipe:
|
||||
r = await recipe.find_recipe_by_id(conn, id)
|
||||
async def load_full_recipe(conn: sqlite3.Connection, id: int) -> recipes.Recipe:
|
||||
r = await recipes.find_recipe_by_id(conn, id)
|
||||
if not r:
|
||||
return None
|
||||
|
||||
r.ingredients = []
|
||||
async for ingredient in recipe.find_ingredients_by_recipe_id(conn, id):
|
||||
ingredient.product = await product.find_product_by_id(conn, ingredient.product_id)
|
||||
async for ingredient in recipes.find_ingredients_by_recipe_id(conn, id):
|
||||
ingredient.product = await products.find_product_by_id(conn, ingredient.product_id)
|
||||
r.ingredients.append(ingredient)
|
||||
|
||||
return r
|
||||
|
||||
@app.get("/recipes/{recipe_id}")
|
||||
async def get_recipe(recipe_id: int, conn: sqlite3.Connection = Depends(get_db)) -> recipe.Recipe:
|
||||
async def get_recipe(recipe_id: int, conn: sqlite3.Connection = Depends(get_db)) -> recipes.Recipe:
|
||||
r = await load_full_recipe(conn, recipe_id)
|
||||
if not r:
|
||||
return JSONResponse(status_code=404, content={'message': 'Recipe not found'})
|
||||
|
|
@ -73,7 +73,7 @@ async def get_recipe(recipe_id: int, conn: sqlite3.Connection = Depends(get_db))
|
|||
return r
|
||||
|
||||
@app.post('/recipes/')
|
||||
async def create_recipe(item: recipe.Recipe, conn: sqlite3.Connection = Depends(get_db)) -> recipe.Recipe:
|
||||
async def create_recipe(item: recipes.Recipe, conn: sqlite3.Connection = Depends(get_db)) -> recipes.Recipe:
|
||||
if not item.ingredients:
|
||||
return JSONResponse(status_code=400, content={'message': 'Recipe must have at least one ingredient'})
|
||||
|
||||
|
|
@ -81,11 +81,11 @@ async def create_recipe(item: recipe.Recipe, conn: sqlite3.Connection = Depends(
|
|||
if not ingredient.product:
|
||||
return JSONResponse(status_code=400, content={'message': 'Ingredient must have a product'})
|
||||
|
||||
await recipe.insert_recipe(conn, item)
|
||||
await recipes.insert_recipe(conn, item)
|
||||
for ingredient in item.ingredients:
|
||||
ingredient.recipe_id = item.id
|
||||
ingredient.product_id = ingredient.product.id
|
||||
await recipe.insert_ingredient(conn, ingredient)
|
||||
await recipes.insert_ingredient(conn, ingredient)
|
||||
await conn.commit()
|
||||
|
||||
return item
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from typing import List, ClassVar
|
||||
from pydantic import BaseModel
|
||||
from person import Person
|
||||
from persons import Person
|
||||
|
||||
import datetime
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
from person.db import Person
|
||||
1
persons/__init__.py
Normal file
1
persons/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from persons.db import Person
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
|
||||
from product.db import Product, find_product_by_tag, find_product_by_product_id, insert_product, get_tags, add_tag, find_product_by_id
|
||||
from product.scraping import scrape_woolies_data, get_product_id, get_product_details_url
|
||||
from products.db import Product, find_product_by_tag, find_product_by_product_id, insert_product, get_tags, add_tag, find_product_by_id
|
||||
from products.scraping import scrape_woolies_data, get_product_id, get_product_details_url
|
||||
|
||||
from typing import List
|
||||
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
from product import Product
|
||||
from recipe.db import Recipe, Ingredient, insert_recipe, insert_ingredient, find_recipe_by_id, find_ingredients_by_recipe_id
|
||||
from recipe.scraping import scrape_recipe
|
||||
from products import Product
|
||||
from recipes.db import Recipe, Ingredient, insert_recipe, insert_ingredient, find_recipe_by_id, find_ingredients_by_recipe_id
|
||||
from recipes.scraping import scrape_recipe
|
||||
|
||||
from ingredient_parser import parse_multiple_ingredients
|
||||
from typing import List
|
||||
from product import find_product_by_tag
|
||||
from products import find_product_by_tag
|
||||
|
||||
import json, units
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import aiosqlite
|
||||
|
||||
from product import Product
|
||||
from products import Product
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing import List, ClassVar, Optional
|
||||
Loading…
Reference in a new issue