Rapportsystem API - of D03N
Hovedprosjekt FiV Programmering 20-24
Loading...
Searching...
No Matches
changeDataInRapport.py
Go to the documentation of this file.
1#Imports nessesary modules
2from flask_restx import Resource
3from flask import request
4from flask_jwt_extended import jwt_required, get_jwt_identity
5
6#imports os
7import os
8current_directory = os.getcwd()
9#imports sys
10import sys
11sys.path.append(os.path.join(current_directory))
12
13#imports custom modules
14from flask_jwt_extended import get_jwt_identity
15from Models import user_model as UM
16from Common.Requirements import valid_token as vt
17from Common.Requirements import leader_req as lr
18from Requests.dataHandler import dataChanger as dataChanger
19
20# create Disa route
22 @ns.route('/changeDataInRapport')
23
24 class change_data_class(Resource):
25 del_last_report_model = UM.update_table_data_model(ns)
26
27 #Documentation for swagger UI
28 @ns.doc('/changeDataInRapport',
29 description='Takes tablename and data -> updates last added report.',
30 responses={
31 200: 'OK',
32 400: 'Invalid Argument or faulty data',
33 500: 'Internal server error'
34 })
35
36 #Validates input
37 @ns.expect(del_last_report_model, validate=True)
38
39 #Requires valid JWT token authentication
40 @jwt_required()
41 @vt.require_valid_token
42 @lr.require_leader_account
43
44
45 #recives password data from user
46 def post(self):
47 data = request.get_json()
48 current_user = get_jwt_identity()
49
50 #gets data from request -> table & data
51 table_name = data['table_name']
52 data = data['data']
53
54 print("NOW: " + current_user["email"] + " is trying to change data from: " + table_name )
55
56 #checks if data is provided
57 if not data:
58 return {"Error": "No data provided"}
59
60 #Returns the result of the insertData function & inserts data into database
61 return {"Message":dataChanger.data_changer(table_name,data).changeData()}
62