This commit is contained in:
The Creature Conservancy
2025-03-17 18:32:33 -04:00
parent a2fc733529
commit 3521fdd033
2 changed files with 29 additions and 10 deletions

View File

@@ -22,11 +22,13 @@ db_conn = psycopg2.connect(dbname='codices',user='postgres',password='1597')
postgres_url = "http://localhost:5432" postgres_url = "http://localhost:5432"
@app.get("/") @app.get("/api/")
async def root(): async def root():
return {"message": "Hello World"} return {"message": "Hello World!"}
@app.get('/plants/all')
@app.get('/api/plants/all')
def get_plant_list(): def get_plant_list():
cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute('select * from plants.watering_status') cur.execute('select * from plants.watering_status')
@@ -35,20 +37,37 @@ def get_plant_list():
return results return results
@app.post('/plants/update')
def update_plant(data: Dict[str, Any]):
@app.post('/api/plants/update')
def update_plant(data: Dict[str, Any]):
flag_deleted = False flag_deleted = False
action = 'Watered' action = 'Watered'
if data['action'] == 'UNDO_WATER': if data['action'] == 'UNDO_WATER':
flag_deleted = True flag_deleted = True
value_place = (data['plant_name'], data['plant_location'], action, datetime.now().date(), flag_deleted) value_place = (data['plant_name'], data['plant_location'], action, datetime.now().date(), flag_deleted)
cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor) with db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute("INSERT INTO plants.care_transactions (plant_name, plant_location, action, record_date, flag_deleted) VALUES (%s, %s, %s, %s, %s)",value_place) cur.execute("INSERT INTO plants.care_transactions (plant_name, plant_location, action, record_date, flag_deleted) VALUES (%s, %s, %s, %s, %s)",value_place)
db_conn.commit() db_conn.commit()
cur.close() # cur.close()
# body = req.json() # Parse incoming JSON payload # body = req.json() # Parse incoming JSON payload
# print(body) # print(body)
return return_this = {'success':True}
logger.info(return_this)
return return_this
@app.post('/api/plants/inventory_update')
def update_plant(data: Dict[str, Any]):
value_place = (data['plant_name'], data['plant_location'], data['watering_interval_days'])
with db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute("INSERT INTO plants.inventory_transactions (plant_name, plant_location, watering_interval_days) values (%s, %s, %s)", value_place)
db_conn.commit()
# cur.close()
# body = req.json() # Parse incoming JSON payload
# print(body)
return_this = {'success':True}
logger.info(return_this)
return return_this