added patchnotes_get function to return all patchnotes

This commit is contained in:
Justin Weins 2025-04-16 10:01:16 +02:00
parent 814dd4d2c2
commit d38e4e0f69
7 changed files with 104 additions and 10 deletions

View File

@ -23,7 +23,7 @@
#!docs/README.md #!docs/README.md
gen/openapi_server/__main__.py gen/openapi_server/__main__.py
gen/openapi_server/encoder.py gen/openapi_server/encoder.py
# gen/openapi_server/controllers gen/openapi_server/controllers
gen/openapi_server/test gen/openapi_server/test
gen/openapi_server gen/openapi_server
openapi_server/models/base_model.py openapi_server/models/base_model.py

View File

@ -23,6 +23,22 @@ paths:
$ref: '#/components/schemas/patch_notes' $ref: '#/components/schemas/patch_notes'
"400": "400":
description: bad payload description: bad payload
get:
description: returns list of all Patch notes
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/patch_notes'
description: returns list of all unseen Patch notes from the user
"404":
description: no Patch notes found
tags:
- Patchnotes
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
/patchnotes/{patchID}: /patchnotes/{patchID}:
put: put:
tags: tags:

View File

@ -21,8 +21,7 @@
#docs/*.md #docs/*.md
# Then explicitly reverse the ignore rule for a single file: # Then explicitly reverse the ignore rule for a single file:
#!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 openapi_server/encoder.py
openapi_server/models/base_model.py openapi_server/models/base_model.py
openapi_server/controllers/patchnotes_controller.py

View File

@ -5,11 +5,11 @@ from datetime import datetime
from bson import json_util from bson import json_util
from connexion import ProblemException from connexion import ProblemException
from flask import Response from flask import Response
from __main__ import collection
from openapi_server.__main__ import collection 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_get(date): # noqa: E501 def patchnotes_date_get(date): # noqa: E501
"""patchnotes_date_get """patchnotes_date_get
@ -20,7 +20,6 @@ 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]]
""" """
logging.error(type(date))
try: try:
datetime.strptime(date, '%Y-%m-%d') # 2025-01-0 datetime.strptime(date, '%Y-%m-%d') # 2025-01-0
except ValueError as e: except ValueError as e:
@ -29,7 +28,6 @@ def patchnotes_date_get(date): # noqa: E501
detail="The date is invalid. Needs to be in this Format YYYY-MM-DD", detail="The date is invalid. Needs to be in this Format YYYY-MM-DD",
status=400, status=400,
) )
logging.error('date:' + str(date))
query = { query = {
'patch_date': {'$gte': date} 'patch_date': {'$gte': date}
} }
@ -56,7 +54,6 @@ def patchnotes_patch_iddelete(patch_id): # noqa: E501
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]] :rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
""" """
deleted_doc = collection.delete_one({'patchID': patch_id}) deleted_doc = collection.delete_one({'patchID': patch_id})
logging.error(deleted_doc.deleted_count)
if deleted_doc.deleted_count == 0: if deleted_doc.deleted_count == 0:
raise ProblemException( raise ProblemException(
title="Not found", title="Not found",
@ -108,7 +105,6 @@ def patchnotes_patch_idput(patch_id, body): # noqa: E501
detail="No document has been deleted", detail="No document has been deleted",
status=404, status=404,
) )
logging.error(result)
return Response("Document was updated", status=200, mimetype='application/json') return Response("Document was updated", status=200, mimetype='application/json')
@ -156,3 +152,67 @@ def patchnotes_post(body):
return Response(json_util.dumps(patch_note), mimetype='application/json', return Response(json_util.dumps(patch_note), mimetype='application/json',
status=200) status=200)
def patchnotes_post(body):
"""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('error: No patch notes provided', status=400)
pn = PatchNotes.from_dict(body)
try:
date_obj = datetime.strptime(pn.patch_date, '%Y-%m-%d').date()
date_str = date_obj.strftime('%Y-%m-%d')
except ValueError as e:
raise ProblemException(
title="Bad Request",
detail="The date is invalid. Needs to be in this Format YYYY-MM-DD",
status=400,
)
patch_note = {
'patchID': str(uuid.uuid4()),
'title': pn.title,
'changes': pn.changes,
'version': pn.version,
'patch_date': date_str
}
collection.insert_one(patch_note)
patch_note_obj = PatchNotes.from_dict(patch_note)
patch_note = patch_note_obj.to_dict()
return Response(json_util.dumps(patch_note), mimetype='application/json',
status=200)
def patchnotes_get(): # noqa: E501
"""patchnotes_get
returns list of all Patch notes # noqa: E501
:rtype: Union[List[PatchNotes], Tuple[List[PatchNotes], int], Tuple[List[PatchNotes], int, Dict[str, str]]
"""
results = []
for entry in collection.find({}):
patch_note = PatchNotes.from_dict(entry)
results.append(patch_note.to_dict())
return Response(
json_util.dumps(results),
mimetype='application/json',
status=200,
)

View File

@ -7,6 +7,23 @@ servers:
- url: / - url: /
paths: paths:
/patchnotes: /patchnotes:
get:
description: returns list of all Patch notes
operationId: patchnotes_get
responses:
"200":
content:
application/json:
schema:
items:
$ref: '#/components/schemas/patch_notes'
type: array
description: returns list of all unseen Patch notes from the user
"404":
description: no Patch notes found
tags:
- Patchnotes
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
post: post:
description: creates new Patch notes description: creates new Patch notes
operationId: patchnotes_post operationId: patchnotes_post

View File

@ -9,4 +9,5 @@ pymongo >= 4.11.3
connexion[swagger-ui, flask] >= 3.2.0 connexion[swagger-ui, flask] >= 3.2.0
werkzeug == 3.1.3 werkzeug == 3.1.3
swagger-ui-bundle >= 0.0.2 swagger-ui-bundle >= 0.0.2
uvicorn >= 0.21.1 uvicorn >= 0.21.1
typing_extensions~=4.12.2

View File

@ -9,4 +9,5 @@ pymongo >= 4.11.3
connexion[swagger-ui, flask] >= 3.2.0 connexion[swagger-ui, flask] >= 3.2.0
werkzeug == 3.1.3 werkzeug == 3.1.3
swagger-ui-bundle >= 0.0.2 swagger-ui-bundle >= 0.0.2
uvicorn >= 0.21.1 uvicorn >= 0.21.1
typing_extensions~=4.12.2