Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions backend/crud.py

This file was deleted.

20 changes: 0 additions & 20 deletions backend/database.py

This file was deleted.

56 changes: 13 additions & 43 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
from fastapi import FastAPI, Depends, HTTPException
from fastapi import FastAPI
from pydantic import BaseModel
from sqlalchemy.orm import Session

from fastapi.middleware.cors import CORSMiddleware
import requests

# from . import crud, models, schemas
# from .database import SessionLocal, engine
import crud, models, schemas
from database import SessionLocal, engine

# Initialize tables; generally, Alembic is a tool meant for initializing DBs and migrations.
# But, for now we can use this
models.Base.metadata.create_all(bind=engine)

app = FastAPI()

Expand All @@ -28,51 +19,30 @@
allow_headers=["*"],
)

# Dependancy
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()

class Food2(BaseModel):
id:str
class Food(BaseModel):
name:str


# grocery_list = [
# {"name":"oranges"},
# {"name":"bread"}
# ]
grocery_list = [
{"name":"oranges"},
{"name":"bread"}
]

## Endpoints
@app.get("/")
async def welcome():
return "Who's Hungry!"


@app.get("/groceries", response_model = list[schemas.Food])
def get_groceries_list(skip: int = 0, limit: int = 50, db: Session = Depends(get_db)):
grocery_list = crud.get_grocery_list(db, skip, limit=limit)
@app.get("/groceries")
async def get_groceries_list():
return grocery_list

@app.post('/add', response_model = schemas.Food)
def add_to_grocery_list(food:schemas.FoodCreate, db: Session = Depends(get_db)):
return crud.add_to_grocery_list(db=db, food=food)


# @app.get("/groceries")
# async def get_groceries_list():
# return grocery_list

# @app.post('/add')
# async def add_item(item:Food):
# grocery_list.append(item)
# return "Added " + item.name
@app.post('/add')
async def add_item(item:Food):
grocery_list.append(item)
return "Added " + item.name

@app.get('/recipes')
async def find_recipes(item:Food2): #schemas.Food
async def find_recipes(item:Food):
result = []
response = find_by_ingredients(item.name)

Expand Down
10 changes: 0 additions & 10 deletions backend/models.py

This file was deleted.

15 changes: 0 additions & 15 deletions backend/schemas.py

This file was deleted.

17 changes: 1 addition & 16 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"awesome-typescript-loader": "^5.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"react-scripts": "5.0.1",
"source-map-loader": "^4.0.0",
"typescript": "^4.7.4",
"web-vitals": "^2.1.4"
Expand Down Expand Up @@ -42,8 +42,5 @@
"last 1 safari version"
]
},
"proxy": "http://localhost:8000",
"devDependencies": {
"@types/uuid": "^8.3.4"
}
"proxy":"http://localhost:8000"
}
16 changes: 2 additions & 14 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import React from 'react';
import List from './components/List';
import Recipe from './components/Recipe';
import { isTemplateExpression } from 'typescript';
import {v4 as uuid} from 'uuid';

export default function App() {

Expand All @@ -23,23 +22,14 @@ export default function App() {
function onClose(){
setAddModalIsOpen(false);
console.log('canceled');

// const myuuid = uuid();
// console.log('Your UUID is:' + myuuid);
// console.log(typeof myuuid);

}
function onAdd(foodName: string){
fetch('http://localhost:3000/add',{
method:'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
"id":uuid(),
"name":foodName
}),
// body: JSON.stringify({"name":foodName}),
body: JSON.stringify({"name":foodName}),
})
.then(data => {
console.log('Success', data)
Expand All @@ -51,14 +41,12 @@ export default function App() {
}

async function fetchFoodList() {
console.log("about to fetch some food...");
const response = await fetch('http://localhost:3000/groceries', {
method:'GET',
headers: {
'accept': 'application/json',
}
});
console.log("got some food...", response);
const newList: FoodObj[] = await response.json();
console.log('newList', newList);
const newFoodList: FoodList = {
Expand Down Expand Up @@ -102,7 +90,7 @@ export default function App() {

React.useEffect(() => {
fetchFoodList();
}, [foodList]);
}, [addModalIsOpen]);

return (
<div className="App">
Expand Down