diff --git a/.openapi-generator-ignore b/.openapi-generator-ignore index ab5b235..dfcc906 100644 --- a/.openapi-generator-ignore +++ b/.openapi-generator-ignore @@ -23,7 +23,7 @@ #!docs/README.md gen/openapi_server/__main__.py gen/openapi_server/encoder.py -# gen/openapi_server/controllers +gen/openapi_server/controllers gen/openapi_server/test gen/openapi_server openapi_server/models/base_model.py diff --git a/announcement_service_spec.yaml b/announcement_service_spec.yaml index b3e0525..1bba363 100644 --- a/announcement_service_spec.yaml +++ b/announcement_service_spec.yaml @@ -23,6 +23,22 @@ paths: $ref: '#/components/schemas/patch_notes' "400": 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}: put: tags: diff --git a/gen/.openapi-generator-ignore b/gen/.openapi-generator-ignore index dbe31c3..1171898 100644 --- a/gen/.openapi-generator-ignore +++ b/gen/.openapi-generator-ignore @@ -21,8 +21,7 @@ #docs/*.md # Then explicitly reverse the ignore rule for a single file: #!docs/README.md -# openapi_server/controllers/patchnotes_controller.py +openapi_server/controllers/patchnotes_controller.py openapi_server/__main__.py openapi_server/encoder.py openapi_server/models/base_model.py -openapi_server/controllers/patchnotes_controller.py \ No newline at end of file diff --git a/gen/openapi_server/controllers/patchnotes_controller.py b/gen/openapi_server/controllers/patchnotes_controller.py index 4426e48..1e2bcc1 100644 --- a/gen/openapi_server/controllers/patchnotes_controller.py +++ b/gen/openapi_server/controllers/patchnotes_controller.py @@ -5,11 +5,11 @@ from datetime import datetime from bson import json_util from connexion import ProblemException from flask import Response +from __main__ import collection from openapi_server.__main__ import collection from openapi_server.models.patch_notes import PatchNotes # noqa: E501 - def patchnotes_date_get(date): # noqa: E501 """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]] """ - logging.error(type(date)) try: datetime.strptime(date, '%Y-%m-%d') # 2025-01-0 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", status=400, ) - logging.error('date:' + str(date)) query = { '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]] """ deleted_doc = collection.delete_one({'patchID': patch_id}) - logging.error(deleted_doc.deleted_count) if deleted_doc.deleted_count == 0: raise ProblemException( title="Not found", @@ -108,7 +105,6 @@ def patchnotes_patch_idput(patch_id, body): # noqa: E501 detail="No document has been deleted", status=404, ) - logging.error(result) 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', 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, + ) diff --git a/gen/openapi_server/openapi/openapi.yaml b/gen/openapi_server/openapi/openapi.yaml index 1b58eaa..2fb126b 100644 --- a/gen/openapi_server/openapi/openapi.yaml +++ b/gen/openapi_server/openapi/openapi.yaml @@ -7,6 +7,23 @@ servers: - url: / paths: /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: description: creates new Patch notes operationId: patchnotes_post diff --git a/gen/requirements.txt b/gen/requirements.txt index 964203c..f7e57e3 100644 --- a/gen/requirements.txt +++ b/gen/requirements.txt @@ -9,4 +9,5 @@ pymongo >= 4.11.3 connexion[swagger-ui, flask] >= 3.2.0 werkzeug == 3.1.3 swagger-ui-bundle >= 0.0.2 -uvicorn >= 0.21.1 \ No newline at end of file +uvicorn >= 0.21.1 +typing_extensions~=4.12.2 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 964203c..f7e57e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ pymongo >= 4.11.3 connexion[swagger-ui, flask] >= 3.2.0 werkzeug == 3.1.3 swagger-ui-bundle >= 0.0.2 -uvicorn >= 0.21.1 \ No newline at end of file +uvicorn >= 0.21.1 +typing_extensions~=4.12.2 \ No newline at end of file