Compare commits

..

3 Commits

Author SHA1 Message Date
a22d8becbb cspell settings (minor) 2024-05-02 20:45:29 +02:00
4f86361ee8 Additional swagger 2024-05-02 20:44:26 +02:00
aef6dd2761 Added password for redis 2024-03-28 21:22:23 +01:00
7 changed files with 66 additions and 3 deletions

View File

@ -8,6 +8,7 @@
"checkpw", "checkpw",
"jsonify", "jsonify",
"lastrowid", "lastrowid",
"rtype" "rtype",
"flasgger"
] ]
} }

View File

@ -1,7 +1,7 @@
from flask import jsonify, abort, request from flask import jsonify, abort, request
from flask_jwt_extended import jwt_required, get_jwt_identity from flask_jwt_extended import jwt_required, get_jwt_identity
from app.doc.product_swag import get_products_swagger, get_product_info_swagger from app.doc.product_swag import get_products_swagger, get_product_info_swagger, create_product_swagger
from flasgger import swag_from from flasgger import swag_from
@ -39,6 +39,7 @@ def get_product_info(id: int):
@bp_product.route('/create', methods=['POST']) @bp_product.route('/create', methods=['POST'])
@swag_from(create_product_swagger)
@jwt_required() @jwt_required()
def create_product_listing(): def create_product_listing():
user_id = get_jwt_identity() user_id = get_jwt_identity()

View File

@ -4,7 +4,7 @@ from flask import request, abort
from flasgger import swag_from from flasgger import swag_from
from app.doc.user_swag import login_swagger from app.doc.user_swag import login_swagger, logout_swagger, delete_swagger
from app.services.user_service import UserService from app.services.user_service import UserService
@ -36,6 +36,7 @@ def login():
return result, status_code return result, status_code
@bp_user.route('/logout', methods=['DELETE']) @bp_user.route('/logout', methods=['DELETE'])
@swag_from(logout_swagger)
@jwt_required() @jwt_required()
def logout(): def logout():
jwt = get_jwt() jwt = get_jwt()
@ -124,6 +125,7 @@ def update_password():
return result, status_code return result, status_code
@bp_user.route('/delete', methods=['DELETE']) @bp_user.route('/delete', methods=['DELETE'])
@swag_from(delete_swagger)
@jwt_required() @jwt_required()
def delete_user(): def delete_user():
user_id = get_jwt_identity() user_id = get_jwt_identity()

View File

@ -10,6 +10,7 @@ class MySqlConfig:
class RedisConfig: class RedisConfig:
REDIS_HOST = os.environ.get('REDIS_HOST') REDIS_HOST = os.environ.get('REDIS_HOST')
REDIS_PORT = os.environ.get('REDIS_PORT') REDIS_PORT = os.environ.get('REDIS_PORT')
REDIS_PASSWORD = os.environ.get('REDIS_PASSWORD')
class FlaskProduction: class FlaskProduction:
DEBUG = False DEBUG = False

View File

@ -44,3 +44,30 @@ get_product_info_swagger = {
"500": {"description": "Internal Server Error"} "500": {"description": "Internal Server Error"}
} }
} }
create_product_swagger = {
"methods": ["POST"],
"tags": ["Products"],
"security": [{"JWT": []}],
"parameters": [
{
"name": "name",
"in": "body",
"type": "string",
"description": "Name for the new product",
"required": True
},
{
"name": "price",
"in": "body",
"type": "float",
"description": "Price of the product",
"required": True
}
],
"responses": {
"200": {"description": "Successfully fetched product information"},
"400": {"description": "Bad Request - Invalid input or missing input"},
"500": {"description": "Internal Server Error"}
}
}

View File

@ -42,4 +42,34 @@ login_swagger = {
"description": "Password is incorrect" "description": "Password is incorrect"
} }
} }
}
logout_swagger = {
"methods": ["DELETE"],
"tags": ["User"],
"security": [{"JWT": []}],
"description": "Logs out the user via provided JWT token",
"parameters": [],
"responses":
{
"200":
{
"description": "User successfully logged out"
}
}
}
delete_swagger = {
"methods": ["DELETE"],
"tags": ["User"],
"security": [{"JWT": []}],
"description": "Deletes a user via JWT token",
"parameters": [],
"responses":
{
"200":
{
"description": "User successfully deleted out"
}
}
} }

View File

@ -15,6 +15,7 @@ db_connection = mysql.connector.connect(
jwt_redis_blocklist = redis.StrictRedis( jwt_redis_blocklist = redis.StrictRedis(
host=RedisConfig.REDIS_HOST, host=RedisConfig.REDIS_HOST,
port=RedisConfig.REDIS_PORT, port=RedisConfig.REDIS_PORT,
password=RedisConfig.REDIS_PASSWORD,
db=0, db=0,
decode_responses=True decode_responses=True
) )