diff --git a/server_side/api/app.py b/server_side/api/app.py index 0f69c6f..f9fc734 100644 --- a/server_side/api/app.py +++ b/server_side/api/app.py @@ -28,6 +28,7 @@ if __name__ == '__main__': api.add_resource(utility.Resources, '/resources', '/resources/') api.add_resource(denunciation.Alert, '/denunciation', '/denunciation/') + api.add_resource(denunciation.Denounce, '/denounce', '/denounce/') api.add_resource(navigation.Transit, '/transit', '/transit/') diff --git a/server_side/api/modules/databases/denunciations.json b/server_side/api/modules/databases/denunciations.json new file mode 100644 index 0000000..df2f122 --- /dev/null +++ b/server_side/api/modules/databases/denunciations.json @@ -0,0 +1,11 @@ +[ + { + "reporter": "9vard12ty0ad2yvwp3q53rsf3h43r2vq", + "info": "There is a fire", + "priority": 8, + "location": { + "latitude": 39.9404, + "longitude": 32.9101 + } + } +] \ No newline at end of file diff --git a/server_side/api/modules/denunciation.py b/server_side/api/modules/denunciation.py index 31c6b2c..19fe87c 100644 --- a/server_side/api/modules/denunciation.py +++ b/server_side/api/modules/denunciation.py @@ -26,3 +26,28 @@ class Alert(Resource): return {"success":True} else: return {"success":False,"penalty":"{}".format(100*(20-trust))} + +class Denounce(Resource): + def post(self): + args = request.form + reporter = args['id'] + denunciation_info = args['info'] + denunciation_priority = args['priority'] + denunciation_location = { + "latitude": args['latitude'], + "longitude": args['longitude'] + } + + denunciation = { + 'reporter': reporter, + 'info': denunciation_info, + 'priority': denunciation_priority, + 'location': denunciation_location + } + + denunciations.append(denunciation) + + with open(db_path, 'w') as f: + json.dump(denunciations, f, indent=4) + + return denunciation