2021-01-18 15:20:15 -09:00
|
|
|
from db.db_setup import generate_session
|
2021-02-02 20:42:58 -09:00
|
|
|
from fastapi import APIRouter, Depends
|
|
|
|
|
from services.settings_services import SiteSettings
|
2021-01-18 15:20:15 -09:00
|
|
|
from sqlalchemy.orm.session import Session
|
2021-01-29 19:31:24 -08:00
|
|
|
from utils.post_webhooks import post_webhooks
|
2020-12-24 16:37:38 -09:00
|
|
|
from utils.snackbar import SnackResponse
|
|
|
|
|
|
2021-01-30 17:25:05 -09:00
|
|
|
router = APIRouter(prefix="/api/site-settings", tags=["Settings"])
|
2020-12-24 16:37:38 -09:00
|
|
|
|
2021-02-02 20:42:58 -09:00
|
|
|
|
|
|
|
|
@router.get("")
|
2021-01-18 15:20:15 -09:00
|
|
|
def get_main_settings(db: Session = Depends(generate_session)):
|
2021-01-07 19:54:49 -09:00
|
|
|
""" Returns basic site settings """
|
2020-12-24 16:37:38 -09:00
|
|
|
|
2021-01-18 15:20:15 -09:00
|
|
|
return SiteSettings.get_site_settings(db)
|
2020-12-24 16:37:38 -09:00
|
|
|
|
|
|
|
|
|
2021-02-02 20:42:58 -09:00
|
|
|
@router.post("/webhooks/test")
|
2021-01-15 21:46:35 -09:00
|
|
|
def test_webhooks():
|
2021-01-07 19:54:49 -09:00
|
|
|
""" Run the function to test your webhooks """
|
2020-12-24 16:37:38 -09:00
|
|
|
|
|
|
|
|
return post_webhooks()
|
|
|
|
|
|
|
|
|
|
|
2021-02-02 20:42:58 -09:00
|
|
|
@router.put("")
|
2021-01-19 15:51:36 -09:00
|
|
|
def update_settings(data: SiteSettings, db: Session = Depends(generate_session)):
|
2020-12-24 16:37:38 -09:00
|
|
|
""" Returns Site Settings """
|
2021-01-19 15:51:36 -09:00
|
|
|
data.update(db)
|
2021-01-15 21:46:35 -09:00
|
|
|
# try:
|
|
|
|
|
# data.update()
|
|
|
|
|
# except:
|
|
|
|
|
# raise HTTPException(
|
|
|
|
|
# status_code=400, detail=SnackResponse.error("Unable to Save Settings")
|
|
|
|
|
# )
|
2020-12-24 16:37:38 -09:00
|
|
|
|
|
|
|
|
return SnackResponse.success("Settings Updated")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|