73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
import logging
|
|
|
|
import connexion
|
|
from typing import Dict
|
|
from typing import Tuple
|
|
from typing import Union
|
|
|
|
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
|
|
"""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=None): # TODO done for now
|
|
"""patchnotes_post
|
|
|
|
creates new Patch notes # noqa: E501
|
|
|
|
: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:
|
|
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)
|
|
|
|
return Response(json_util.dumps(f'patch with ID: {posted_patch_id} was created'), mimetype='application/json',
|
|
status=200) |