mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
[~] API Routes upgrade
This commit is contained in:
parent
bbff1b0f88
commit
afb35cc79a
18
api.py
18
api.py
@ -1,5 +1,6 @@
|
||||
import http
|
||||
from typing import Dict
|
||||
from enum import Enum
|
||||
from typing import Dict, Optional
|
||||
|
||||
from flask import Flask, Response, jsonify, request
|
||||
from flask_cors import CORS
|
||||
@ -11,6 +12,11 @@ CORS(app)
|
||||
cors = CORS(app, origins=['*'])
|
||||
|
||||
|
||||
class ActionType(Enum):
|
||||
ACCOUNT_CREATE = '/AccountCreate'
|
||||
SERVER_CREATE = '/ServerCreate'
|
||||
|
||||
|
||||
def generic_response_maker(status_code: http.HTTPStatus) -> tuple[Response, int]:
|
||||
match status_code:
|
||||
case http.HTTPStatus.CREATED:
|
||||
@ -35,6 +41,16 @@ def generic_response_maker(status_code: http.HTTPStatus) -> tuple[Response, int]
|
||||
return message, status_code.value
|
||||
|
||||
|
||||
def parse_and_validate_request(required_keys: set) -> Optional[dict]:
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
raise Exception("Empty request body.")
|
||||
missing_keys = required_keys - set(data.keys())
|
||||
if missing_keys:
|
||||
raise Exception("Missing keys: {}".format(missing_keys))
|
||||
return data
|
||||
|
||||
|
||||
@app.route('/AccountCreate', methods=['POST'])
|
||||
def account_create() -> tuple[Response, int]:
|
||||
data: Dict[str, str] = request.get_json()
|
||||
|
Loading…
Reference in New Issue
Block a user