-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
357 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from flask import jsonify, Blueprint | ||
from flask_jwt_extended import jwt_required, create_access_token, get_jwt_identity, create_refresh_token | ||
|
||
|
||
refresh_token_api = Blueprint('refresh_token_api', __name__) | ||
|
||
@refresh_token_api.route("/login", methods=["POST"]) | ||
def login(): | ||
access_token = create_access_token(identity="user") | ||
refresh_token = create_refresh_token(identity="user") | ||
return jsonify(access_token=access_token, refresh_token=refresh_token) | ||
|
||
|
||
@refresh_token_api.route("/refresh", methods=["POST"]) | ||
@jwt_required(refresh=True) | ||
def refresh(): | ||
identity = get_jwt_identity() | ||
access_token = create_access_token(identity=identity) | ||
return jsonify(access_token=access_token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import json | ||
from flask import jsonify, Blueprint, request | ||
import os | ||
import shutil | ||
from flask_jwt_extended import jwt_required | ||
|
||
spectra_layout_api = Blueprint('spectra_layout_api', __name__) | ||
script_dir = os.path.dirname(__file__) | ||
data_type_json_path = os.path.join(script_dir, '../lib/converter/jcamp/data_type.json') | ||
|
||
def load_data_types(): | ||
try: | ||
with open(data_type_json_path, 'r') as mapping_file: | ||
return json.load(mapping_file) | ||
except FileNotFoundError: | ||
example_json_path = os.path.join(script_dir, '../lib/converter/jcamp/data_type.json.example') | ||
shutil.copy(example_json_path, data_type_json_path) | ||
with open(data_type_json_path, 'r') as mapping_file: | ||
return json.load(mapping_file) | ||
|
||
def save_data_types(data_types): | ||
with open(data_type_json_path, 'w') as mapping_file: | ||
json.dump(data_types, mapping_file, indent=4) | ||
|
||
@spectra_layout_api.route('/api/v1/chemspectra/spectra_layouts', methods=['GET', 'PUT', 'DELETE']) | ||
@jwt_required() | ||
def update_or_fetch_mapping(): | ||
if request.method == 'GET': | ||
existing_data_types = load_data_types() | ||
return jsonify(existing_data_types["datatypes"]), 200 | ||
|
||
elif request.method == 'PUT': | ||
request_data = request.get_json() | ||
new_data_type_mapping = request_data.get("new_data_type") | ||
existing_data_types = load_data_types() | ||
|
||
for layout, data_type in new_data_type_mapping.items(): | ||
if data_type == '': | ||
return jsonify({"message": "Invalid Data Type"}), 400 | ||
elif layout in existing_data_types["datatypes"] and data_type not in existing_data_types['datatypes'][layout]: | ||
existing_data_types["datatypes"][layout].append(data_type) | ||
elif layout in existing_data_types["datatypes"] and data_type in existing_data_types['datatypes'][layout]: | ||
return jsonify({"message": f"Data type '{data_type}' already exists"}), 400 | ||
else: | ||
return jsonify({"message": f"Layout '{layout}' does not exist"}), 400 | ||
|
||
save_data_types(existing_data_types) | ||
return jsonify({"message": "Data type created successfully"}), 200 | ||
|
||
elif request.method == 'DELETE': | ||
request_data = request.get_json() | ||
data_type_mapping = request_data.get("data_type") | ||
existing_data_types = load_data_types() | ||
for layout, data_type in data_type_mapping.items(): | ||
if layout in existing_data_types["datatypes"]: | ||
if data_type in existing_data_types['datatypes'][layout]: | ||
existing_data_types['datatypes'][layout].remove(data_type) | ||
save_data_types(existing_data_types) | ||
return jsonify({"message": f"Data type '{data_type}' deleted successfully"}), 200 | ||
else: | ||
return jsonify({"message": f"Data type '{data_type}' not found in layout '{layout}'"}), 404 | ||
else: | ||
return jsonify({"message": f"Layout '{layout}' does not exist"}), 400 | ||
else: | ||
return jsonify({"message": "Method not allowed"}), 405 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"datatypes": { | ||
"NMR": ["NMR SPECTRUM", "NMRSPECTRUM"], | ||
"INFRARED": ["INFRARED SPECTRUM"], | ||
"RAMAN": ["RAMAN SPECTRUM"], | ||
"MS": ["MASS SPECTRUM"], | ||
"HPLC UVVIS": ["HPLC UV/VIS SPECTRUM", "HPLC UV-VIS"], | ||
"UVVIS": ["UV/VIS SPECTRUM", "UV-VIS", "ULTRAVIOLET SPECTRUM"], | ||
"THERMOGRAVIMETRIC ANALYSIS": ["THERMOGRAVIMETRIC ANALYSIS"], | ||
"X-RAY DIFFRACTION": ["X-RAY DIFFRACTION"], | ||
"CYCLIC VOLTAMMETRY": ["CYCLIC VOLTAMMETRY"], | ||
"SIZE EXCLUSION CHROMATOGRAPHY": ["SIZE EXCLUSION CHROMATOGRAPHY"], | ||
"CIRCULAR DICHROISM SPECTROSCOPY": ["CIRCULAR DICHROISM SPECTROSCOPY"], | ||
"SORPTION-DESORPTION MEASUREMENT": ["SORPTION-DESORPTION MEASUREMENT"], | ||
"Emissions": ["Emissions", "EMISSIONS", "FLUORESCENCE SPECTRUM", "FL SPECTRUM"], | ||
"DLS ACF": ["DLS ACF"], | ||
"DLS intensity": ["DLS INTENSITY", "DLS intensity"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"datatypes": { | ||
"NMR": ["NMR SPECTRUM", "NMRSPECTRUM"], | ||
"INFRARED": ["INFRARED SPECTRUM"], | ||
"RAMAN": ["RAMAN SPECTRUM"], | ||
"MS": ["MASS SPECTRUM"], | ||
"HPLC UVVIS": ["HPLC UV/VIS SPECTRUM", "HPLC UV-VIS"], | ||
"UVVIS": ["UV/VIS SPECTRUM", "UV-VIS", "ULTRAVIOLET SPECTRUM"], | ||
"THERMOGRAVIMETRIC ANALYSIS": ["THERMOGRAVIMETRIC ANALYSIS"], | ||
"X-RAY DIFFRACTION": ["X-RAY DIFFRACTION"], | ||
"CYCLIC VOLTAMMETRY": ["CYCLIC VOLTAMMETRY"], | ||
"SIZE EXCLUSION CHROMATOGRAPHY": ["SIZE EXCLUSION CHROMATOGRAPHY"], | ||
"CIRCULAR DICHROISM SPECTROSCOPY": ["CIRCULAR DICHROISM SPECTROSCOPY"], | ||
"SORPTION-DESORPTION MEASUREMENT": ["SORPTION-DESORPTION MEASUREMENT"], | ||
"Emissions": ["Emissions", "EMISSIONS", "FLUORESCENCE SPECTRUM", "FL SPECTRUM"], | ||
"DLS ACF": ["DLS ACF"], | ||
"DLS intensity": ["DLS INTENSITY", "DLS intensity"] | ||
} | ||
} |
Oops, something went wrong.