import logging import uuid from bson import json_util from flask import Response from openapi_server.models.patch_notes import PatchNotes # noqa: E501 def patchnotes_date_get(date): # noqa: E501 """patchnotes_date_get returns list of all unseen Patch notes from the user # noqa: E501 :param date: :type date: str :rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]] """ # TODO Implement this: # try: # formatted_date = response_data.strftime('%Y-%m-%d') # logging.error(formatted_date) # logging.info("valid date") # except ValueError: # logging.error("Not valid date") return date # _date = util.deserialize_date(date) # return 'do some magic!' def patchnotes_patch_iddelete(patch_id): # noqa: E501 """patchnotes_patch_iddelete deletes one Patch note # noqa: E501 :param patch_id: :type patch_id: str :type patch_id: str :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] """ return 'do some magic!' def patchnotes_post(body): # TODO _date to date change """patchnotes_post creates new Patch notes # noqa: E501 :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]] """ if body is None: return Response(json_util.dumps({'error': 'No patch notes provided'}), status=400) pn = PatchNotes.from_dict(body) logging.error('patch_notes_type:' + str(type(pn))) logging.error('patch notes' + str(pn)) 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)