Implement controllers
This commit is contained in:
34
api-customer/src/controllers/AuthController.py
Normal file
34
api-customer/src/controllers/AuthController.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from board_mate.auth import *
|
||||
from flask import jsonify, request
|
||||
from pydantic import StrictStr
|
||||
|
||||
|
||||
class AuthController:
|
||||
def __init__(self, app):
|
||||
self._register_routes(app)
|
||||
self.config = Configuration(host="https://192.168.15.120:8000")
|
||||
self.config.verify_ssl = False
|
||||
|
||||
def _register_routes(self, app):
|
||||
app.add_url_rule("/client/auth", view_func=self.auth, methods=['POST'])
|
||||
|
||||
def auth(self):
|
||||
try:
|
||||
received_data = request.get_json()
|
||||
with ApiClient(self.config) as client:
|
||||
auth_api = AuthApi(client)
|
||||
|
||||
auth_request = AuthRequestDto(
|
||||
username=StrictStr(received_data["username"]),
|
||||
key=StrictStr(received_data["key"]),
|
||||
)
|
||||
|
||||
response = auth_api.login(auth_request_dto=auth_request)
|
||||
print("Success:", response.success)
|
||||
print("Message:", response.message)
|
||||
print("Data:", response.data)
|
||||
return jsonify(response), 200
|
||||
except Exception as e:
|
||||
print(f"Exception when calling AuthAPI->login: {e}")
|
||||
return jsonify(response), 500
|
||||
|
||||
33
api-customer/src/controllers/ClientController.py
Normal file
33
api-customer/src/controllers/ClientController.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from board_mate.client import Configuration, ApiClient, ClientApi, ClientDto, ApiException
|
||||
from flask import jsonify
|
||||
from pydantic import StrictStr
|
||||
|
||||
|
||||
class GameController:
|
||||
def __init__(self, app):
|
||||
self._register_routes(app)
|
||||
self.config = Configuration(host="https://192.168.15.120:8000")
|
||||
self.config.verify_ssl = False
|
||||
|
||||
def _register_routes(self, app):
|
||||
app.add_url_rule("/client/create", view_func=self.create, methods=['POST'])
|
||||
|
||||
def create(self):
|
||||
with ApiClient(self.config) as api_client:
|
||||
client_api = ClientApi(api_client)
|
||||
|
||||
new_client = ClientDto(
|
||||
name=StrictStr("Alice Example"),
|
||||
username=StrictStr("alice123"),
|
||||
)
|
||||
|
||||
try:
|
||||
response = client_api.create(client_dto=new_client)
|
||||
print("Success:", response.success)
|
||||
print("Message:", response.message)
|
||||
print("Data:", response.data)
|
||||
return jsonify(response), 200
|
||||
except ApiException as e:
|
||||
print(f"Exception when calling ClientApi->create: {e}")
|
||||
return jsonify(response), 500
|
||||
|
||||
Reference in New Issue
Block a user