Update message endpoint

This commit is contained in:
2026-01-02 17:19:22 +01:00
parent b4d9f8d9cf
commit 1b2cd919d1
11 changed files with 234 additions and 43 deletions

View File

@@ -16,12 +16,14 @@ board_mate/message/models/__init__.py
board_mate/message/models/message_dto.py board_mate/message/models/message_dto.py
board_mate/message/models/message_post_request_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_list_message_dto.py
board_mate/message/models/response_body_string.py
board_mate/message/py.typed board_mate/message/py.typed
board_mate/message/rest.py board_mate/message/rest.py
docs/MessageApi.md docs/MessageApi.md
docs/MessageDto.md docs/MessageDto.md
docs/MessagePostRequestDto.md docs/MessagePostRequestDto.md
docs/ResponseBodyListMessageDto.md docs/ResponseBodyListMessageDto.md
docs/ResponseBodyString.md
git_push.sh git_push.sh
pyproject.toml pyproject.toml
requirements.txt requirements.txt
@@ -33,4 +35,5 @@ test/test_message_api.py
test/test_message_dto.py test/test_message_dto.py
test/test_message_post_request_dto.py test/test_message_post_request_dto.py
test/test_response_body_list_message_dto.py test/test_response_body_list_message_dto.py
test/test_response_body_string.py
tox.ini tox.ini

View File

@@ -95,6 +95,7 @@ Class | Method | HTTP request | Description
- [MessageDto](docs/MessageDto.md) - [MessageDto](docs/MessageDto.md)
- [MessagePostRequestDto](docs/MessagePostRequestDto.md) - [MessagePostRequestDto](docs/MessagePostRequestDto.md)
- [ResponseBodyListMessageDto](docs/ResponseBodyListMessageDto.md) - [ResponseBodyListMessageDto](docs/ResponseBodyListMessageDto.md)
- [ResponseBodyString](docs/ResponseBodyString.md)
<a id="documentation-for-authorization"></a> <a id="documentation-for-authorization"></a>

View File

@@ -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_dto import MessageDto
from board_mate.message.models.message_post_request_dto import MessagePostRequestDto 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_list_message_dto import ResponseBodyListMessageDto
from board_mate.message.models.response_body_string import ResponseBodyString

View File

@@ -20,10 +20,10 @@ from pydantic import validate_arguments, ValidationError
from pydantic import StrictInt, StrictStr 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.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_client import ApiClient
from board_mate.message.api_response import ApiResponse from board_mate.message.api_response import ApiResponse
@@ -46,7 +46,7 @@ class MessageApi:
self.api_client = api_client self.api_client = api_client
@validate_arguments @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 """GET message/history/{clientId} # noqa: E501
This method makes a synchronous HTTP request by default. To make an This method makes a synchronous HTTP request by default. To make an
@@ -68,7 +68,7 @@ class MessageApi:
:return: Returns the result object. :return: Returns the result object.
If the method is called asynchronously, If the method is called asynchronously,
returns the request thread. returns the request thread.
:rtype: List[ResponseBodyListMessageDto] :rtype: ResponseBodyString
""" """
kwargs['_return_http_data_only'] = True kwargs['_return_http_data_only'] = True
if '_preload_content' in kwargs: if '_preload_content' in kwargs:
@@ -112,7 +112,7 @@ class MessageApi:
:return: Returns the result object. :return: Returns the result object.
If the method is called asynchronously, If the method is called asynchronously,
returns the request thread. returns the request thread.
:rtype: tuple(List[ResponseBodyListMessageDto], status_code(int), headers(HTTPHeaderDict)) :rtype: tuple(ResponseBodyString, status_code(int), headers(HTTPHeaderDict))
""" """
_params = locals() _params = locals()
@@ -171,7 +171,7 @@ class MessageApi:
_auth_settings = [] # noqa: E501 _auth_settings = [] # noqa: E501
_response_types_map = { _response_types_map = {
'200': "List[ResponseBodyListMessageDto]", '200': "ResponseBodyString",
} }
return self.api_client.call_api( return self.api_client.call_api(
@@ -192,7 +192,7 @@ class MessageApi:
_request_auth=_params.get('_request_auth')) _request_auth=_params.get('_request_auth'))
@validate_arguments @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 """POST message/send # noqa: E501
This method makes a synchronous HTTP request by default. To make an This method makes a synchronous HTTP request by default. To make an
@@ -212,7 +212,7 @@ class MessageApi:
:return: Returns the result object. :return: Returns the result object.
If the method is called asynchronously, If the method is called asynchronously,
returns the request thread. returns the request thread.
:rtype: str :rtype: ResponseBodyString
""" """
kwargs['_return_http_data_only'] = True kwargs['_return_http_data_only'] = True
if '_preload_content' in kwargs: if '_preload_content' in kwargs:
@@ -254,7 +254,7 @@ class MessageApi:
:return: Returns the result object. :return: Returns the result object.
If the method is called asynchronously, If the method is called asynchronously,
returns the request thread. returns the request thread.
:rtype: tuple(str, status_code(int), headers(HTTPHeaderDict)) :rtype: tuple(ResponseBodyString, status_code(int), headers(HTTPHeaderDict))
""" """
_params = locals() _params = locals()
@@ -316,7 +316,7 @@ class MessageApi:
_auth_settings = [] # noqa: E501 _auth_settings = [] # noqa: E501
_response_types_map = { _response_types_map = {
'200': "str", '200': "ResponseBodyString",
} }
return self.api_client.call_api( return self.api_client.call_api(

View File

@@ -17,3 +17,4 @@
from board_mate.message.models.message_dto import MessageDto 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.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_list_message_dto import ResponseBodyListMessageDto
from board_mate.message.models.response_body_string import ResponseBodyString

View File

@@ -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

View File

@@ -9,7 +9,7 @@ Method | HTTP request | Description
# **history** # **history**
> List[ResponseBodyListMessageDto] history(client_id, top=top) > ResponseBodyString history(client_id, top=top)
GET message/history/{clientId} GET message/history/{clientId}
@@ -19,7 +19,7 @@ GET message/history/{clientId}
import time import time
import os import os
import board_mate.message 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 board_mate.message.rest import ApiException
from pprint import pprint from pprint import pprint
@@ -57,7 +57,7 @@ Name | Type | Description | Notes
### Return type ### Return type
[**List[ResponseBodyListMessageDto]**](ResponseBodyListMessageDto.md) [**ResponseBodyString**](ResponseBodyString.md)
### Authorization ### 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) [[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** # **post_message**
> str post_message(message_post_request_dto) > ResponseBodyString post_message(message_post_request_dto)
POST message/send POST message/send
@@ -87,6 +87,7 @@ import time
import os import os
import board_mate.message import board_mate.message
from board_mate.message.models.message_post_request_dto import MessagePostRequestDto 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 board_mate.message.rest import ApiException
from pprint import pprint from pprint import pprint
@@ -122,7 +123,7 @@ Name | Type | Description | Notes
### Return type ### Return type
**str** [**ResponseBodyString**](ResponseBodyString.md)
### Authorization ### Authorization

View File

@@ -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)

View File

@@ -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()

View File

@@ -5,6 +5,7 @@ info:
version: "1.0.0" version: "1.0.0"
servers: servers:
- url: "https://boardmate_api" - url: "https://boardmate_api"
paths: paths:
/message/send: /message/send:
post: post:
@@ -24,7 +25,7 @@ paths:
content: content:
'*/*': '*/*':
schema: schema:
type: "string" $ref: "#/components/schemas/ResponseBodyString"
/message/history/{clientId}: /message/history/{clientId}:
get: get:
@@ -45,19 +46,29 @@ paths:
type: "integer" type: "integer"
format: "int32" format: "int32"
default: "20" default: "20"
responses: responses:
"200": "200":
description: "OK" description: "OK"
content: content:
'*/*': '*/*':
schema: schema:
type: "array" $ref: "#/components/schemas/ResponseBodyString"
items:
$ref: "#/components/schemas/ResponseBodyListMessageDto"
components: components:
schemas: schemas:
ResponseBodyString:
type: "object"
properties:
data:
type: "string"
nullable: true
message:
type: "string"
nullable: true
success:
type: "boolean"
nullable: false
MessagePostRequestDto: MessagePostRequestDto:
type: "object" type: "object"
properties: properties:
@@ -95,5 +106,8 @@ components:
nullable: true nullable: true
timestamp: timestamp:
type: "integer" type: "integer"
format: "int32" format: "int64"
nullable: true nullable: true
Void:
type: "object"
properties: { }

View File

@@ -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 flask import jsonify, request
from pydantic import StrictStr
from src.models.AuthData import AuthData from src.models.AuthData import AuthData
from src.services.mqtt_service import MQTTService from src.services.mqtt_service import MQTTService
@@ -8,7 +9,6 @@ import json
class MessageController: class MessageController:
_mqtt_service : MQTTService = None
_client_id : MQTTService = None _client_id : MQTTService = None
_auth_data : AuthData = None _auth_data : AuthData = None
@@ -22,12 +22,23 @@ class MessageController:
def send(self): def send(self):
try : try :
with ApiClient(self.config) as api:
req = request.get_json() req = request.get_json()
msg = req["message"] content = req["content"]
payload = json.dumps({"content" : msg}) timestamp = req["timestamp"]
payload = json.dumps({"content": content, "timestamp": timestamp})
print(payload) print(payload)
self._mqtt_service.publish(f"/chat/${self._auth_data.get_client_id()}/message", payload) message_api = MessageApi(api)
return jsonify({"success" : True, "message": "An error occurred"}), 500
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: except Exception as e:
print(e) print(e)
return jsonify({"success" : False, "message" : "An error occurred"}), 500 return jsonify({"success" : False, "message" : "An error occurred"}), 500