diff --git a/api/endpoints/editsalamander.py b/api/endpoints/editsalamander.py index 38f24a30adae4651f88cedaaf09665154896ea3c..310e7e8baf14e431966e3802a7b37f76afa2841c 100644 --- a/api/endpoints/editsalamander.py +++ b/api/endpoints/editsalamander.py @@ -12,6 +12,13 @@ from path_constants import _ACCESS_DATABASE from image_encoder.image_encoder import * import cv2 +""" +Endpoint for editing salamanders. +GET: Gets a specific salamanders original and processed image, and all its data. +PUT: Edits a specific salamander with new data like sex, species, location etc. +DELETE: Deletes a specific salamander from the system. +""" + class EditSalamander(Resource): decorators = [limiter.limit("60/minute")] @@ -41,7 +48,6 @@ class EditSalamander(Resource): height, width, _ = image.shape desired_long_side = 320 - scaling_factor = 1 if width > height: scaling_factor = desired_long_side / width @@ -145,7 +151,7 @@ class EditSalamander(Resource): if "location" in data and "new_location" in data and "new_sex" in data and "new_species" in data: if data['location'] != data['new_location'] or salamander.sex != data[ - 'new_sex'] or salamander.species != data['new_species']: + 'new_sex'] or salamander.species != data['new_species']: salamander_path = os.path.join("images", data['location'], salamander.species, salamander.sex, str(salamander.id)) new_path_to_images = os.path.join("images", data['new_location'], data['new_species'], diff --git a/api/endpoints/findsalamanderinfo.py b/api/endpoints/findsalamanderinfo.py index b13813abb7612eb16130ef9a375d4a7babe96f2c..e18ae1410a145718340024fa9c9ccf4a08adbb84 100644 --- a/api/endpoints/findsalamanderinfo.py +++ b/api/endpoints/findsalamanderinfo.py @@ -8,11 +8,14 @@ from api import limiter from image_encoder.image_encoder import * from path_constants import image_type import glob -# import mimetypes ALLOWED_EXTENSIONS = ['jpg', 'png', 'jpeg'] +""" +Endpoint for processing the salamanders abdominal pattern. +POST: Receives an image of a salamander, processes it, and returns the processed image back to the user. +""" + -# findSalamanderInfo endpoint class FindSalamanderInfo(Resource): decorators = [limiter.limit("5/minute")] @@ -53,7 +56,6 @@ class FindSalamanderInfo(Resource): def allowed_image(filename): - # return mimetypes.guess_extension(filename).lower() in ALLOWED_EXTENSIONS return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS diff --git a/api/endpoints/location.py b/api/endpoints/location.py index 38ca11215d9094a8dc2a7f19cecfd2b3e5cb0155..776d0bcfa3b4e4e37f33d1675c65af01091eab4b 100644 --- a/api/endpoints/location.py +++ b/api/endpoints/location.py @@ -1,19 +1,25 @@ from flask import request, jsonify from flask_restful import Resource from flask_jwt_extended import jwt_required, get_jwt_identity - from api import db, limiter from api.models.dbmodels import Location, Salamander, User import re import os from api.endpoints.matchsalamander import sanitize_int_str from path_constants import _ACCESS_DATABASE - LATITUDE_REGEX = "^(\\+|-)?(?:90(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\\.[0-9]{1,6})?))$" LONGITUDE_REGEX = "^(\\+|-)?(?:180(?:(?:\\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\\.[0-9]{1,6})?))$" -# location endpoint +""" +Endpoint for creating, updating, getting and deleting locations in the system. +GET: Returns all data about all locations to the user. +POST: Creates a new location with radius, name, longitude and latitude. +PUT: For editing a location. Change its name or radius. +DELETE: For deleting a specific location. This can only be done if the location does not contain a salamander. +""" + + class LocationEndpoint(Resource): decorators = [limiter.limit("60/minute")] @@ -121,6 +127,7 @@ class LocationEndpoint(Resource): return jsonify({"message": "user not admin", "status": 400}) +# creates the folder structure when a location is registered def create_directory_folders(location): dir_smooth_male = "images/" + location + "/smooth_newt/" + "male/" dir_smooth_female = "images/" + location + "/smooth_newt/" + "female/" diff --git a/api/endpoints/login.py b/api/endpoints/login.py index 7e529e88207f6533dae8bdd75755109a65c16c31..2cdcc2fc24467f26ecc7a793041065f63f670bad 100644 --- a/api/endpoints/login.py +++ b/api/endpoints/login.py @@ -5,6 +5,13 @@ from api.models.dbmodels import User from api import bcrypt, db, limiter +""" +Endpoint for logging in to the system. +POST: Checks if the email and password matches. Returns a JSON Web Token to the user that requested the login. +This JWT contains the users ID encrypted in it, so the server knows who sends request to other endpoints. +""" + + class Login(Resource): decorators = [limiter.limit("3/minute")] diff --git a/api/endpoints/manageuser.py b/api/endpoints/manageuser.py index 034dd11227f175c08cf6ae5b89409e0fcf377bf2..a1776b456cf9f725486be7f97b5dd3f77c6108a0 100644 --- a/api/endpoints/manageuser.py +++ b/api/endpoints/manageuser.py @@ -7,6 +7,15 @@ from random import choice from string import ascii_lowercase, digits +""" +Endpoint for administrators to manage users. +GET: Get all users in the system. +POST: Change a users access rights. The admin can update them to admin, remove admin or remove all access rights. +PUT: Is used if a user forgets their password. The admin can reset it, so that the user can login and change it at a +later point. +""" + + class AdminManageUser(Resource): decorators = [limiter.limit("60/minute")] diff --git a/api/endpoints/matchsalamander.py b/api/endpoints/matchsalamander.py index eb11b8e10e1bab2bb9f900ee53e6be3bbd89202c..298b9162cb746603ca42b264284ea944553ccb2b 100644 --- a/api/endpoints/matchsalamander.py +++ b/api/endpoints/matchsalamander.py @@ -14,6 +14,13 @@ APPROVED_SEX = ["male", "female", "juvenile"] APPROVED_SPECIES = ["smooth_newt", "northern_crested_newt"] +""" +Endpoint for matching a newly registered salamander with the once in the database. +POST: Matched the processed image of the salamander pattern with the once in the database. +It only matches females and males, not juveniles. +""" + + # matchSalamander endpoint class MatchSalamander(Resource): decorators = [limiter.limit("5/minute")] diff --git a/api/endpoints/pendingusers.py b/api/endpoints/pendingusers.py index adeb9c7420d080fcbadf2303bd4cee8dd1caab11..25af0c40e3c4d5e302cb1d2f64c0ea520da18401 100644 --- a/api/endpoints/pendingusers.py +++ b/api/endpoints/pendingusers.py @@ -5,6 +5,13 @@ from api import db, limiter from flask_jwt_extended import get_jwt_identity, jwt_required +""" +Endpoint for administrators to accept newly created users. +GET: Gets all pending users in the system. +POST: For either accepting or denying a users access permissions. If the user is not accepted, it will be deleted. +""" + + class AdminPendingUsers(Resource): decorators = [limiter.limit("60/minute")] diff --git a/api/endpoints/salamander.py b/api/endpoints/salamander.py index 576bc4302c5c9d38341875b5269f91d6007d4290..5240d29ca7e7918518a21a7b08d08cfd4d4a49c5 100644 --- a/api/endpoints/salamander.py +++ b/api/endpoints/salamander.py @@ -4,15 +4,17 @@ from flask_restful import Resource from api import db, limiter from api.models.dbmodels import Location, User, Salamander import os -import cv2 import glob import cv2 -import base64 from image_encoder.image_encoder import * from path_constants import _ACCESS_DATABASE +""" +Endpoint for getting all original images of a specific salamander. +GET: Gets all the images based on a salamanders ID. +""" + -# get all images on a specific salamander based on id class SalamanderEndpoint(Resource): decorators = [limiter.limit("60/minute")] @@ -34,11 +36,10 @@ class SalamanderEndpoint(Resource): image = cv2.imread(path) - #scaling to set size + # scaling to set size height, width, _ = image.shape desired_long_side = 320 - scaling_factor = 1 if width > height: scaling_factor = desired_long_side / width diff --git a/api/endpoints/salamanders.py b/api/endpoints/salamanders.py index 7275f2c9313869bc76525c895f1f9546dc71c3f6..fbb28d62b24697653e08df04376e266d382308bb 100644 --- a/api/endpoints/salamanders.py +++ b/api/endpoints/salamanders.py @@ -5,7 +5,12 @@ from api import db, limiter from api.models.dbmodels import Location, User, Salamander, SalamanderGrowth from path_constants import _ACCESS_DATABASE -# get all salamanders on a specific location +""" +Endpoint for for getting data about all salamanders in a specific location. +GET: Gets all salamanders and their data based on a specific location. +""" + + class SalamandersEndpoint(Resource): decorators = [limiter.limit("60/minute")] diff --git a/api/endpoints/user.py b/api/endpoints/user.py index ce36f821a306f941f77564e36a13201fe2d04d85..e9d667a0bc2a12b8cbdaeb65a23232a3344b99e2 100644 --- a/api/endpoints/user.py +++ b/api/endpoints/user.py @@ -8,6 +8,13 @@ from api.forms.userforms import RegistrationForm, DeleteUserForm EMAIL_REGEX = "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$" +""" +Endpoint for creating a new user, deleting a user and edit a user. +POST: For creating a new user with email, name, password and confirm password. +PUT: For editing a user. Either edit name, email or password. +DELETE: For deleting a user. An administrator cannot delete their own account. +""" + class UserEndpoint(Resource): decorators = [limiter.limit("30/minute")] diff --git a/api/endpoints/verifypassword.py b/api/endpoints/verifypassword.py index d2bf15896b4619c97b85e9a7a6e3572a7d0acb82..94b6f23d8716e97f3f7c4c5155ac34d95ae7cff8 100644 --- a/api/endpoints/verifypassword.py +++ b/api/endpoints/verifypassword.py @@ -5,6 +5,12 @@ from flask_jwt_extended import get_jwt_identity, jwt_required from api.models.dbmodels import User +""" +Endpoint to verify a users password. +POST: Checks that the password that the user typed in is correct. +""" + + class VerifyPassword(Resource): decorators = [limiter.limit("30/minute")]