base_model.py bug fix
patchnotes_controller.py post and get endpoint done
This commit is contained in:
parent
464930cee5
commit
ace005248d
|
|
@ -23,3 +23,4 @@
|
||||||
#!docs/README.md
|
#!docs/README.md
|
||||||
openapi_server/controllers/patchnotes_controller.py
|
openapi_server/controllers/patchnotes_controller.py
|
||||||
openapi_server/__main__.py
|
openapi_server/__main__.py
|
||||||
|
openapi_server/encoder.py
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ git_push.sh
|
||||||
openapi_server/__init__.py
|
openapi_server/__init__.py
|
||||||
openapi_server/controllers/__init__.py
|
openapi_server/controllers/__init__.py
|
||||||
openapi_server/controllers/security_controller.py
|
openapi_server/controllers/security_controller.py
|
||||||
openapi_server/encoder.py
|
|
||||||
openapi_server/models/__init__.py
|
openapi_server/models/__init__.py
|
||||||
openapi_server/models/base_model.py
|
openapi_server/models/base_model.py
|
||||||
openapi_server/models/patch_notes.py
|
openapi_server/models/patch_notes.py
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,50 @@
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from bson import json_util
|
from bson import json_util
|
||||||
from flask import Response
|
from flask import Response
|
||||||
|
|
||||||
|
from openapi_server import util
|
||||||
|
from openapi_server.__main__ import collection
|
||||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
def patchnotes_date_get1(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]]
|
||||||
|
"""
|
||||||
|
logging.error(type(date))
|
||||||
|
|
||||||
|
try:
|
||||||
|
formatted_date = datetime.strptime(date, '%Y-%m-%d')
|
||||||
|
logging.error(formatted_date)
|
||||||
|
except ValueError:
|
||||||
|
logging.error("Not valid date")
|
||||||
|
|
||||||
|
try:
|
||||||
|
formatted_date = formatted_date.strftime('%Y-%m-%d')
|
||||||
|
logging.error('formatted date:' + str(formatted_date))
|
||||||
|
logging.info("valid date")
|
||||||
|
except ValueError:
|
||||||
|
logging.error("Not valid date")
|
||||||
|
|
||||||
|
date = util.deserialize_date(date)
|
||||||
|
logging.error('date:' + str(date))
|
||||||
|
query = {
|
||||||
|
'date': {'$gte': date.strftime('%Y-%m-%d')}
|
||||||
|
}
|
||||||
|
results = list(collection.find(query))
|
||||||
|
logging.error('results:' + str(results))
|
||||||
|
return Response(json_util.dumps(f'all unseen patchnotes: {results}'), mimetype='application/json', status=200)
|
||||||
|
|
||||||
|
|
||||||
def patchnotes_date_get(date): # noqa: E501
|
def patchnotes_date_get(date): # noqa: E501
|
||||||
"""patchnotes_date_get
|
"""patchnotes_date_get
|
||||||
|
|
||||||
|
|
@ -17,17 +55,18 @@ def patchnotes_date_get(date): # noqa: E501
|
||||||
|
|
||||||
:rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]]
|
:rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]]
|
||||||
"""
|
"""
|
||||||
# TODO Implement this:
|
query = {
|
||||||
|
'date': {'$gte': date}
|
||||||
# try:
|
}
|
||||||
# formatted_date = response_data.strftime('%Y-%m-%d')
|
results = []
|
||||||
# logging.error(formatted_date)
|
for entry in collection.find(query):
|
||||||
# logging.info("valid date")
|
patch_note = PatchNotes.from_dict(entry)
|
||||||
# except ValueError:
|
results.append(patch_note.to_dict())
|
||||||
# logging.error("Not valid date")
|
return Response(
|
||||||
return date
|
json_util.dumps(results),
|
||||||
# _date = util.deserialize_date(date)
|
mimetype='application/json',
|
||||||
# return 'do some magic!'
|
status=200,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def patchnotes_patch_iddelete(patch_id): # noqa: E501
|
def patchnotes_patch_iddelete(patch_id): # noqa: E501
|
||||||
|
|
@ -44,7 +83,7 @@ def patchnotes_patch_iddelete(patch_id): # noqa: E501
|
||||||
return 'do some magic!'
|
return 'do some magic!'
|
||||||
|
|
||||||
|
|
||||||
def patchnotes_post(body): # TODO _date to date change
|
def patchnotes_post(body): # TODO _date to date change
|
||||||
"""patchnotes_post
|
"""patchnotes_post
|
||||||
|
|
||||||
creates new Patch notes # noqa: E501
|
creates new Patch notes # noqa: E501
|
||||||
|
|
@ -71,7 +110,7 @@ def patchnotes_post(body): # TODO _date to date change
|
||||||
}
|
}
|
||||||
logging.error('patch_notes_type:' + str(type(patch_notes)))
|
logging.error('patch_notes_type:' + str(type(patch_notes)))
|
||||||
logging.error('patch notes' + str(patch_notes))
|
logging.error('patch notes' + str(patch_notes))
|
||||||
#posted_patch_id = collection.insert_one(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',
|
return Response(json_util.dumps(f'patch with ID: {patch_notes} was created'), mimetype='application/json',
|
||||||
status=200)
|
status=200)
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
import typing
|
import typing
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from openapi_server import util
|
from openapi_server import util
|
||||||
|
|
||||||
|
|
@ -28,23 +29,26 @@ class Model:
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
for attr in self.openapi_types:
|
for attr, _ in self.openapi_types.items():
|
||||||
value = getattr(self, attr)
|
value = getattr(self, attr)
|
||||||
|
dict_attr = self.attribute_map[attr]
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
result[attr] = list(map(
|
result[dict_attr] = list(map(
|
||||||
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
|
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
|
||||||
value
|
value
|
||||||
))
|
))
|
||||||
elif hasattr(value, "to_dict"):
|
elif hasattr(value, "to_dict"):
|
||||||
result[attr] = value.to_dict()
|
result[dict_attr] = value.to_dict()
|
||||||
elif isinstance(value, dict):
|
elif isinstance(value, dict):
|
||||||
result[attr] = dict(map(
|
result[dict_attr] = dict(map(
|
||||||
lambda item: (item[0], item[1].to_dict())
|
lambda item: (item[0], item[1].to_dict())
|
||||||
if hasattr(item[1], "to_dict") else item,
|
if hasattr(item[1], "to_dict") else item,
|
||||||
value.items()
|
value.items()
|
||||||
))
|
))
|
||||||
|
elif isinstance(value, datetime):
|
||||||
|
result[dict_attr] = value.isoformat()
|
||||||
else:
|
else:
|
||||||
result[attr] = value
|
result[dict_attr] = value
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue