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