diff --git a/api-customer/api-resources/message-components/.openapi-generator/FILES b/api-customer/api-resources/message-components/.openapi-generator/FILES index 6e0a7649..1064e715 100644 --- a/api-customer/api-resources/message-components/.openapi-generator/FILES +++ b/api-customer/api-resources/message-components/.openapi-generator/FILES @@ -16,12 +16,14 @@ board_mate/message/models/__init__.py board_mate/message/models/message_dto.py board_mate/message/models/message_post_request_dto.py board_mate/message/models/response_body_list_message_dto.py +board_mate/message/models/response_body_string.py board_mate/message/py.typed board_mate/message/rest.py docs/MessageApi.md docs/MessageDto.md docs/MessagePostRequestDto.md docs/ResponseBodyListMessageDto.md +docs/ResponseBodyString.md git_push.sh pyproject.toml requirements.txt @@ -33,4 +35,5 @@ test/test_message_api.py test/test_message_dto.py test/test_message_post_request_dto.py test/test_response_body_list_message_dto.py +test/test_response_body_string.py tox.ini diff --git a/api-customer/api-resources/message-components/README.md b/api-customer/api-resources/message-components/README.md index 474e1eb7..aca918a5 100644 --- a/api-customer/api-resources/message-components/README.md +++ b/api-customer/api-resources/message-components/README.md @@ -95,6 +95,7 @@ Class | Method | HTTP request | Description - [MessageDto](docs/MessageDto.md) - [MessagePostRequestDto](docs/MessagePostRequestDto.md) - [ResponseBodyListMessageDto](docs/ResponseBodyListMessageDto.md) + - [ResponseBodyString](docs/ResponseBodyString.md) diff --git a/api-customer/api-resources/message-components/board_mate/message/__init__.py b/api-customer/api-resources/message-components/board_mate/message/__init__.py index 8bb5ae38..2e8c7619 100644 --- a/api-customer/api-resources/message-components/board_mate/message/__init__.py +++ b/api-customer/api-resources/message-components/board_mate/message/__init__.py @@ -34,3 +34,4 @@ from board_mate.message.exceptions import ApiException from board_mate.message.models.message_dto import MessageDto from board_mate.message.models.message_post_request_dto import MessagePostRequestDto from board_mate.message.models.response_body_list_message_dto import ResponseBodyListMessageDto +from board_mate.message.models.response_body_string import ResponseBodyString diff --git a/api-customer/api-resources/message-components/board_mate/message/api/message_api.py b/api-customer/api-resources/message-components/board_mate/message/api/message_api.py index 6952428c..ba985eab 100644 --- a/api-customer/api-resources/message-components/board_mate/message/api/message_api.py +++ b/api-customer/api-resources/message-components/board_mate/message/api/message_api.py @@ -20,10 +20,10 @@ from pydantic import validate_arguments, ValidationError from pydantic import StrictInt, StrictStr -from typing import List, Optional +from typing import Optional from board_mate.message.models.message_post_request_dto import MessagePostRequestDto -from board_mate.message.models.response_body_list_message_dto import ResponseBodyListMessageDto +from board_mate.message.models.response_body_string import ResponseBodyString from board_mate.message.api_client import ApiClient from board_mate.message.api_response import ApiResponse @@ -46,7 +46,7 @@ class MessageApi: self.api_client = api_client @validate_arguments - def history(self, client_id : StrictStr, top : Optional[StrictInt] = None, **kwargs) -> List[ResponseBodyListMessageDto]: # noqa: E501 + def history(self, client_id : StrictStr, top : Optional[StrictInt] = None, **kwargs) -> ResponseBodyString: # noqa: E501 """GET message/history/{clientId} # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -68,7 +68,7 @@ class MessageApi: :return: Returns the result object. If the method is called asynchronously, returns the request thread. - :rtype: List[ResponseBodyListMessageDto] + :rtype: ResponseBodyString """ kwargs['_return_http_data_only'] = True if '_preload_content' in kwargs: @@ -112,7 +112,7 @@ class MessageApi: :return: Returns the result object. If the method is called asynchronously, returns the request thread. - :rtype: tuple(List[ResponseBodyListMessageDto], status_code(int), headers(HTTPHeaderDict)) + :rtype: tuple(ResponseBodyString, status_code(int), headers(HTTPHeaderDict)) """ _params = locals() @@ -171,7 +171,7 @@ class MessageApi: _auth_settings = [] # noqa: E501 _response_types_map = { - '200': "List[ResponseBodyListMessageDto]", + '200': "ResponseBodyString", } return self.api_client.call_api( @@ -192,7 +192,7 @@ class MessageApi: _request_auth=_params.get('_request_auth')) @validate_arguments - def post_message(self, message_post_request_dto : MessagePostRequestDto, **kwargs) -> str: # noqa: E501 + def post_message(self, message_post_request_dto : MessagePostRequestDto, **kwargs) -> ResponseBodyString: # noqa: E501 """POST message/send # noqa: E501 This method makes a synchronous HTTP request by default. To make an @@ -212,7 +212,7 @@ class MessageApi: :return: Returns the result object. If the method is called asynchronously, returns the request thread. - :rtype: str + :rtype: ResponseBodyString """ kwargs['_return_http_data_only'] = True if '_preload_content' in kwargs: @@ -254,7 +254,7 @@ class MessageApi: :return: Returns the result object. If the method is called asynchronously, returns the request thread. - :rtype: tuple(str, status_code(int), headers(HTTPHeaderDict)) + :rtype: tuple(ResponseBodyString, status_code(int), headers(HTTPHeaderDict)) """ _params = locals() @@ -316,7 +316,7 @@ class MessageApi: _auth_settings = [] # noqa: E501 _response_types_map = { - '200': "str", + '200': "ResponseBodyString", } return self.api_client.call_api( diff --git a/api-customer/api-resources/message-components/board_mate/message/models/__init__.py b/api-customer/api-resources/message-components/board_mate/message/models/__init__.py index 7961613e..5eb5bcd0 100644 --- a/api-customer/api-resources/message-components/board_mate/message/models/__init__.py +++ b/api-customer/api-resources/message-components/board_mate/message/models/__init__.py @@ -17,3 +17,4 @@ from board_mate.message.models.message_dto import MessageDto from board_mate.message.models.message_post_request_dto import MessagePostRequestDto from board_mate.message.models.response_body_list_message_dto import ResponseBodyListMessageDto +from board_mate.message.models.response_body_string import ResponseBodyString diff --git a/api-customer/api-resources/message-components/board_mate/message/models/response_body_string.py b/api-customer/api-resources/message-components/board_mate/message/models/response_body_string.py new file mode 100644 index 00000000..e5f9e8fb --- /dev/null +++ b/api-customer/api-resources/message-components/board_mate/message/models/response_body_string.py @@ -0,0 +1,75 @@ +# coding: utf-8 + +""" + boardmate_api API + + boardmate_api API + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + + +from typing import Optional +from pydantic import BaseModel, StrictBool, StrictStr + +class ResponseBodyString(BaseModel): + """ + ResponseBodyString + """ + data: Optional[StrictStr] = None + message: Optional[StrictStr] = None + success: Optional[StrictBool] = None + __properties = ["data", "message", "success"] + + class Config: + """Pydantic configuration""" + allow_population_by_field_name = True + validate_assignment = True + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.dict(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> ResponseBodyString: + """Create an instance of ResponseBodyString from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self): + """Returns the dictionary representation of the model using alias""" + _dict = self.dict(by_alias=True, + exclude={ + }, + exclude_none=True) + return _dict + + @classmethod + def from_dict(cls, obj: dict) -> ResponseBodyString: + """Create an instance of ResponseBodyString from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return ResponseBodyString.parse_obj(obj) + + _obj = ResponseBodyString.parse_obj({ + "data": obj.get("data"), + "message": obj.get("message"), + "success": obj.get("success") + }) + return _obj + + diff --git a/api-customer/api-resources/message-components/docs/MessageApi.md b/api-customer/api-resources/message-components/docs/MessageApi.md index 29e3a1d4..34a9e3e4 100644 --- a/api-customer/api-resources/message-components/docs/MessageApi.md +++ b/api-customer/api-resources/message-components/docs/MessageApi.md @@ -9,7 +9,7 @@ Method | HTTP request | Description # **history** -> List[ResponseBodyListMessageDto] history(client_id, top=top) +> ResponseBodyString history(client_id, top=top) GET message/history/{clientId} @@ -19,7 +19,7 @@ GET message/history/{clientId} import time import os import board_mate.message -from board_mate.message.models.response_body_list_message_dto import ResponseBodyListMessageDto +from board_mate.message.models.response_body_string import ResponseBodyString from board_mate.message.rest import ApiException from pprint import pprint @@ -57,7 +57,7 @@ Name | Type | Description | Notes ### Return type -[**List[ResponseBodyListMessageDto]**](ResponseBodyListMessageDto.md) +[**ResponseBodyString**](ResponseBodyString.md) ### Authorization @@ -76,7 +76,7 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **post_message** -> str post_message(message_post_request_dto) +> ResponseBodyString post_message(message_post_request_dto) POST message/send @@ -87,6 +87,7 @@ import time import os import board_mate.message from board_mate.message.models.message_post_request_dto import MessagePostRequestDto +from board_mate.message.models.response_body_string import ResponseBodyString from board_mate.message.rest import ApiException from pprint import pprint @@ -122,7 +123,7 @@ Name | Type | Description | Notes ### Return type -**str** +[**ResponseBodyString**](ResponseBodyString.md) ### Authorization diff --git a/api-customer/api-resources/message-components/docs/ResponseBodyString.md b/api-customer/api-resources/message-components/docs/ResponseBodyString.md new file mode 100644 index 00000000..d668a3ee --- /dev/null +++ b/api-customer/api-resources/message-components/docs/ResponseBodyString.md @@ -0,0 +1,30 @@ +# ResponseBodyString + + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**data** | **str** | | [optional] +**message** | **str** | | [optional] +**success** | **bool** | | [optional] + +## Example + +```python +from board_mate.message.models.response_body_string import ResponseBodyString + +# TODO update the JSON string below +json = "{}" +# create an instance of ResponseBodyString from a JSON string +response_body_string_instance = ResponseBodyString.from_json(json) +# print the JSON string representation of the object +print ResponseBodyString.to_json() + +# convert the object into a dict +response_body_string_dict = response_body_string_instance.to_dict() +# create an instance of ResponseBodyString from a dict +response_body_string_form_dict = response_body_string.from_dict(response_body_string_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/api-customer/api-resources/message-components/test/test_response_body_string.py b/api-customer/api-resources/message-components/test/test_response_body_string.py new file mode 100644 index 00000000..ee324103 --- /dev/null +++ b/api-customer/api-resources/message-components/test/test_response_body_string.py @@ -0,0 +1,54 @@ +# coding: utf-8 + +""" + boardmate_api API + + boardmate_api API + + The version of the OpenAPI document: 1.0.0 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest +import datetime + +from board_mate.message.models.response_body_string import ResponseBodyString # noqa: E501 + +class TestResponseBodyString(unittest.TestCase): + """ResponseBodyString unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> ResponseBodyString: + """Test ResponseBodyString + include_option is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `ResponseBodyString` + """ + model = ResponseBodyString() # noqa: E501 + if include_optional: + return ResponseBodyString( + data = '', + message = '', + success = True + ) + else: + return ResponseBodyString( + ) + """ + + def testResponseBodyString(self): + """Test ResponseBodyString""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/api-customer/api-resources/message-endpoint.yaml b/api-customer/api-resources/message-endpoint.yaml index 38ae939a..10dd8bd2 100644 --- a/api-customer/api-resources/message-endpoint.yaml +++ b/api-customer/api-resources/message-endpoint.yaml @@ -5,6 +5,7 @@ info: version: "1.0.0" servers: - url: "https://boardmate_api" + paths: /message/send: post: @@ -24,7 +25,7 @@ paths: content: '*/*': schema: - type: "string" + $ref: "#/components/schemas/ResponseBodyString" /message/history/{clientId}: get: @@ -45,19 +46,29 @@ paths: type: "integer" format: "int32" default: "20" - responses: "200": description: "OK" content: '*/*': schema: - type: "array" - items: - $ref: "#/components/schemas/ResponseBodyListMessageDto" + $ref: "#/components/schemas/ResponseBodyString" components: schemas: + ResponseBodyString: + type: "object" + properties: + data: + type: "string" + nullable: true + message: + type: "string" + nullable: true + success: + type: "boolean" + nullable: false + MessagePostRequestDto: type: "object" properties: @@ -73,19 +84,19 @@ components: nullable: true ResponseBodyListMessageDto: - type: "object" - properties: - data: - type: array - items: - $ref: "#/components/schemas/MessageDto" - nullable: true - message: - type: "string" - nullable: true - success: - type: "boolean" - nullable: false + type: "object" + properties: + data: + type: array + items: + $ref: "#/components/schemas/MessageDto" + nullable: true + message: + type: "string" + nullable: true + success: + type: "boolean" + nullable: false MessageDto: type: "object" @@ -95,5 +106,8 @@ components: nullable: true timestamp: type: "integer" - format: "int32" - nullable: true \ No newline at end of file + format: "int64" + nullable: true + Void: + type: "object" + properties: { } \ No newline at end of file diff --git a/api-customer/src/controllers/message_controller.py b/api-customer/src/controllers/message_controller.py index 5789dd7a..16d758ca 100644 --- a/api-customer/src/controllers/message_controller.py +++ b/api-customer/src/controllers/message_controller.py @@ -1,5 +1,6 @@ -from board_mate.message import Configuration +from board_mate.message import Configuration, ApiClient, MessageDto, MessageApi, MessagePostRequestDto from flask import jsonify, request +from pydantic import StrictStr from src.models.AuthData import AuthData from src.services.mqtt_service import MQTTService @@ -8,7 +9,6 @@ import json class MessageController: - _mqtt_service : MQTTService = None _client_id : MQTTService = None _auth_data : AuthData = None @@ -22,12 +22,23 @@ class MessageController: def send(self): try : - req = request.get_json() - msg = req["message"] - payload = json.dumps({"content" : msg}) - print(payload) - self._mqtt_service.publish(f"/chat/${self._auth_data.get_client_id()}/message", payload) - return jsonify({"success" : True, "message": "An error occurred"}), 500 + with ApiClient(self.config) as api: + req = request.get_json() + content = req["content"] + timestamp = req["timestamp"] + payload = json.dumps({"content": content, "timestamp": timestamp}) + print(payload) + message_api = MessageApi(api) + + new_message = MessagePostRequestDto( + content=content, + timeStamp=timestamp, + clientId=StrictStr(self._auth_data.get_client_id()) + ) + + message_api.post_message(new_message) + + return jsonify({"success" : True, "message": None}), 200 except Exception as e: print(e) return jsonify({"success" : False, "message" : "An error occurred"}), 500 \ No newline at end of file