33from config import logger as logging
44from schemas .api import API
55from utils .deps import get_current_user
6- from schemas .statuspage import StatusPageList , StatusPage , StatusPageList , AddStatusPageResponse , SaveStatusPageRequest
6+ from schemas .statuspage import StatusPageList , StatusPage , AddStatusPageResponse , AddStatusPageRequest , SaveStatusPageRequest , SaveStatusPageResponse , DeleteStatusPageResponse
77
88router = APIRouter (redirect_slashes = True )
99
@@ -30,17 +30,12 @@ async def get_status_page(slug: str, cur_user: API = Depends(get_current_user)):
3030 logging .fatal (e )
3131 raise HTTPException (500 , str (e ))
3232
33- from fastapi import Query
3433
3534@router .post ("" , response_model = AddStatusPageResponse , description = "Add a status page" )
36- async def add_status_page (
37- slug : str = Query (...),
38- title : str = Query (...),
39- cur_user : API = Depends (get_current_user ),
40- ):
35+ async def add_status_page (status_page_data : AddStatusPageRequest , cur_user : API = Depends (get_current_user )):
4136 api : UptimeKumaApi = cur_user ['api' ]
4237 try :
43- return api .add_status_page (slug , title )
38+ return api .add_status_page (status_page_data . slug , status_page_data . title )
4439 except UptimeKumaException as e :
4540 logging .error (e )
4641 raise HTTPException (400 , str (e ))
@@ -49,18 +44,15 @@ async def add_status_page(
4944 raise HTTPException (500 , str (e ))
5045
5146
52-
53- @router .put ("/{slug}" , description = "Save a status page" )
47+ @router .post ("/{slug}" ,response_model = SaveStatusPageResponse , description = "Save a status page" )
5448async def save_status_page (
5549 slug : str = Path (...),
5650 status_page_data : SaveStatusPageRequest = Body (...),
5751 cur_user : API = Depends (get_current_user ),
58- ):
59- print ("--------DEBUG----------" )
60- print (slug )
61- print ("--------DEBUG----------" )
52+ ):
6253 api : UptimeKumaApi = cur_user ['api' ]
6354 try :
55+ print (status_page_data .id )
6456 return api .save_status_page (
6557 slug ,
6658 id = status_page_data .id ,
@@ -84,18 +76,19 @@ async def save_status_page(
8476 logging .fatal (e )
8577 raise HTTPException (500 , str (e ))
8678
87- @router .delete ("/{slug}" , description = "Delete a status page" )
88- async def delete_status_page (slug :str = Path (...), cur_user : API = Depends (get_current_user )):
79+ @router .delete ("/{slug}" , response_model = DeleteStatusPageResponse , description = "Delete a status page" )
80+ async def delete_status_page (slug : str = Path (...), cur_user : API = Depends (get_current_user )):
8981 api : UptimeKumaApi = cur_user ['api' ]
90- print ("--------DEBUG----------" )
91- print (slug )
92- print ("--------DEBUG----------" )
9382 try :
94- api .delete_status_page (slug )
95- return {"detail" : f"Status page '{ slug } ' successfully deleted." }
83+ return api .delete_status_page (slug )
84+ #Catch type error...which is actually a success, go figgure. {"detail":"'NoneType' object has no attribute 'values'"}
85+ except TypeError as e :
86+ if "NoneType" in str (e ):
87+ logging .info ("Status page deleted successfully" )
88+ return {"status" : "success" }
9689 except UptimeKumaException as e :
9790 logging .error (e )
9891 raise HTTPException (404 , str (e ))
9992 except Exception as e :
10093 logging .fatal (e )
101- raise HTTPException (500 , str (e ))
94+ raise HTTPException (500 , str (e ))
0 commit comments