Skip to content

Commit

Permalink
Merge pull request #177 from BraunRudolf/add_delete_site
Browse files Browse the repository at this point in the history
Add delete site
  • Loading branch information
peterdudfield authored Jun 27, 2024
2 parents cd368d7 + 0820b9d commit 173b155
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pv_site_api/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Main API Routes"""

import os
import time
import uuid
Expand All @@ -17,7 +18,7 @@
from pvsite_datamodel.read.status import get_latest_status
from pvsite_datamodel.read.user import get_user_by_email
from pvsite_datamodel.write.generation import insert_generation_values
from pvsite_datamodel.write.user_and_site import create_site
from pvsite_datamodel.write.user_and_site import create_site, delete_site
from sqlalchemy.orm import Session

import pv_site_api
Expand Down Expand Up @@ -339,6 +340,30 @@ def post_site_info(
return site_to_pydantic(site)


@app.delete("/sites/delete/{site_uuid}", tags=["Sites"])
def delete_site_info(
site_uuid: str,
session: Session = Depends(get_session),
auth: dict = Depends(auth),
):
"""
### This route allows a user to delte a site.
"""

if is_fake():
print(f"Got {fake_site_uuid} to delete it.")
return {"message": "Site deleted successfully"}

# check user has access to site
check_user_has_access_to_site(session=session, auth=auth, site_uuid=site_uuid)

# delete site
message = delete_site(session=session, site_uuid=site_uuid)

return message


# get_pv_actual: the client can read pv data from the past
@app.get("/sites/{site_uuid}/pv_actual", response_model=MultiplePVActual, tags=["Generation"])
@cache_response
Expand Down
8 changes: 8 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Test for main app """

import json
from datetime import datetime, timezone

Expand Down Expand Up @@ -45,3 +46,10 @@ def test_post_pv_actual(client, fake):

response = client.post("/sites/fff-fff-fff/pv_actual", json=obj)
assert response.status_code == 200


def test_delete_site(client, fake):
response = client.delete("/sites/delete/fff-fff-fff")

assert response.json()["message"] == "Site deleted successfully"
assert response.status_code == 200

0 comments on commit 173b155

Please sign in to comment.