Skip to content

Commit

Permalink
feat: delete site
Browse files Browse the repository at this point in the history
Add code from backend to delete site (frontend is already implemented)

Reviewed-by: andriac
[Refs_ticket]: #5 , #6
  • Loading branch information
andriacap committed Apr 20, 2023
1 parent f02522f commit a71ad54
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions backend/gn_module_monitoring/routes/site.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from flask import request
from flask.json import jsonify
from geonature.core.gn_commons.schemas import ModuleSchema
from geonature.utils.env import db
from sqlalchemy.orm import Load, joinedload
from werkzeug.datastructures import MultiDict

from geonature.core.gn_commons.schemas import ModuleSchema

from gn_module_monitoring.blueprint import blueprint
from gn_module_monitoring.config.repositories import get_config
from gn_module_monitoring.monitoring.models import BibTypeSite, TMonitoringSites, TNomenclatures, TMonitoringModules
from gn_module_monitoring.monitoring.models import (
BibTypeSite,
TMonitoringModules,
TMonitoringSites,
TNomenclatures,
)
from gn_module_monitoring.monitoring.schemas import BibTypeSiteSchema, MonitoringSitesSchema
from gn_module_monitoring.routes.monitoring import create_or_update_object_api_sites_sites_group
from gn_module_monitoring.utils.routes import (
Expand Down Expand Up @@ -88,12 +93,14 @@ def get_sites():
page=page,
)


@blueprint.route("/sites/<int:id_base_site>", methods=["GET"])
def get_site_by_id(id_base_site):
site = TMonitoringSites.query.get_or_404(id_base_site)
schema = MonitoringSitesSchema()
return schema.dump(site)


@blueprint.route("/sites/geometries", methods=["GET"])
def get_all_site_geometries():
params = MultiDict(request.args)
Expand Down Expand Up @@ -144,3 +151,12 @@ def post_sites():
customConfig.update(post_data["dataComplement"][keys]["config"])
get_config(module_code, force=True, customSpecConfig=customConfig)
return create_or_update_object_api_sites_sites_group(module_code, object_type), 201


@blueprint.route("/sites/<int:_id>", methods=["DELETE"])
def delete_site(_id):
item_schema = MonitoringSitesSchema()
item = TMonitoringSites.find_by_id(_id)
TMonitoringSites.query.filter_by(id_g=_id).delete()
db.session.commit()
return item_schema.dump(item), 201

0 comments on commit a71ad54

Please sign in to comment.