patchnotes post done

This commit is contained in:
2025-03-26 12:55:09 +01:00
parent 07d201d3ae
commit 464930cee5
10 changed files with 69 additions and 28 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ import connexion
from openapi_server import encoder
from pymongo import MongoClient
client = MongoClient(host='mongodb://localhost:27017/')
client = MongoClient(host='mongodb://host.docker.internal:27017/')
db = client["MainDB"]
collection = db['patch_notes']
@@ -1,18 +1,10 @@
import logging
import connexion
from typing import Dict
from typing import Tuple
from typing import Union
import uuid
from bson import json_util
from flask import Response
from pymongo import MongoClient
from openapi_server.__main__ import collection
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
from openapi_server import util
def patchnotes_date_get(date): # noqa: E501
@@ -52,22 +44,34 @@ def patchnotes_patch_iddelete(patch_id): # noqa: E501
return 'do some magic!'
def patchnotes_post(body=None): # TODO done for now
def patchnotes_post(body): # TODO _date to date change
"""patchnotes_post
creates new Patch notes # noqa: E501
:param patch_notes:
:param body:
:param patch_notes:
:type patch_notes: dict | bytes
:rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]]
"""
patch_notes = body
logging.error('patch notes' + str(patch_notes))
if patch_notes is None:
if body is None:
return Response(json_util.dumps({'error': 'No patch notes provided'}), status=400)
# Insert the document into the MongoDB collection
posted_patch_id = collection.insert_one(patch_notes)
pn = PatchNotes.from_dict(body)
logging.error('patch_notes_type:' + str(type(pn)))
logging.error('patch notes' + str(pn))
return Response(json_util.dumps(f'patch with ID: {posted_patch_id} was created'), mimetype='application/json',
patch_notes_uuid = uuid.uuid4()
patch_notes = {
'patchID': str(patch_notes_uuid),
'title': pn.title,
'changes': pn.changes,
'date': pn._date,
}
logging.error('patch_notes_type:' + str(type(patch_notes)))
logging.error('patch notes' + str(patch_notes))
#posted_patch_id = collection.insert_one(patch_notes)
return Response(json_util.dumps(f'patch with ID: {patch_notes} was created'), mimetype='application/json',
status=200)
+1 -1
View File
@@ -15,4 +15,4 @@ class JSONEncoder(ConnexionJSONEncoder):
attr = o.attribute_map[attr]
dikt[attr] = value
return dikt
return ConnexionJSONEncoder.default(self, o)
return ConnexionJSONEncoder.default(self, o)
+6
View File
@@ -93,6 +93,8 @@ class PatchNotes(Model):
:param title: The title of this PatchNotes.
:type title: str
"""
if title is None:
raise ValueError("Invalid value for `title`, must not be `None`") # noqa: E501
self._title = title
@@ -114,6 +116,8 @@ class PatchNotes(Model):
:param changes: The changes of this PatchNotes.
:type changes: str
"""
if changes is None:
raise ValueError("Invalid value for `changes`, must not be `None`") # noqa: E501
self._changes = changes
@@ -135,5 +139,7 @@ class PatchNotes(Model):
:param _date: The _date of this PatchNotes.
:type _date: str
"""
if _date is None:
raise ValueError("Invalid value for `_date`, must not be `None`") # noqa: E501
self.__date = _date
+5 -1
View File
@@ -4,7 +4,7 @@ info:
title: announcementService
version: 1.0.0
servers:
- url: http://127.0.0.1:8080/api
- url: /
paths:
/patchnotes:
post:
@@ -102,6 +102,10 @@ components:
date:
title: date
type: string
required:
- changes
- date
- title
title: patch_notes
user:
example:
+2 -2
View File
@@ -10,7 +10,7 @@ class BaseTestCase(TestCase):
def create_app(self):
logging.getLogger('connexion.operation').setLevel('ERROR')
app = connexion.App(__name__ , specification_dir='../openapi/')
app = connexion.App(__name__, specification_dir='../openapi/')
app.app.json_encoder = JSONEncoder
app.add_api('openapi.yaml', pythonic_params=True, base_path='/api')
app.add_api('openapi.yaml', pythonic_params=True)
return app.app