function to update Patches has been added

This commit is contained in:
Justin Weins 2025-04-07 13:36:35 +02:00
parent a13081cd71
commit 608959df07
6 changed files with 93 additions and 6 deletions

View File

@ -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

View File

@ -24,6 +24,27 @@ paths:
"400":
description: bad payload
/patchnotes/{patchID}:
put:
tags:
- Patchnotes
description: Updates one Patch
parameters:
- in: path
name: patchID
required: true
schema:
format: uuid
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/patch_notes'
responses:
"200":
description: patch updated
"404":
description: no patch found
delete:
tags:
- Patchnotes

View File

@ -21,7 +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

View File

@ -6,6 +6,7 @@ README.md
git_push.sh
openapi_server/__init__.py
openapi_server/controllers/__init__.py
openapi_server/controllers/patchnotes_controller.py
openapi_server/controllers/security_controller.py
openapi_server/models/__init__.py
openapi_server/models/patch_notes.py

View File

@ -1,17 +1,15 @@
import logging
import uuid
from datetime import datetime
from xxlimited_35 import error
from bson import json_util
from connexion import ProblemException
from connexion.lifecycle import ConnexionResponse
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
def patchnotes_date_get(date): # noqa: E501
"""patchnotes_date_get
@ -51,7 +49,7 @@ def patchnotes_patch_iddelete(patch_id): # noqa: E501
deletes one Patch note # noqa: E501
:param patch_id:
:param patch_id:
:type patch_id: str
:type patch_id: str
@ -72,6 +70,47 @@ def patchnotes_patch_iddelete(patch_id): # noqa: E501
)
def patchnotes_patch_idput(patch_id, body): # noqa: E501
"""patchnotes_patch_idput
Updates one Patch # noqa: E501
:param body:
:param patch_id:
:type patch_id: str
:type patch_id: str
:rtype: Union[None, Tuple[None, int], Tuple[None, int, Dict[str, str]]
"""
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,
)
query_filter = {'patchID': patch_id}
updated_post = {'$set':
{
'title': pn.title,
'changes': pn.changes,
'date': date_str
}
}
result = collection.update_one(query_filter, updated_post)
if result.modified_count == 0:
raise ProblemException(
title="Not found",
detail="No document has been deleted",
status=404,
)
logging.error(result)
return Response("Document was updated", status=200, mimetype='application/json')
def patchnotes_post(body):
"""patchnotes_post
@ -114,3 +153,4 @@ def patchnotes_post(body):
patch_note = patch_note_obj.to_dict()
return Response(json_util.dumps(patch_note), mimetype='application/json',
status=200)

View File

@ -76,6 +76,31 @@ paths:
tags:
- Patchnotes
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
put:
description: Updates one Patch
operationId: patchnotes_patch_idput
parameters:
- explode: false
in: path
name: patchID
required: true
schema:
format: uuid
type: string
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/patch_notes'
responses:
"200":
description: patch updated
"404":
description: no patch found
tags:
- Patchnotes
x-openapi-router-controller: openapi_server.controllers.patchnotes_controller
components:
schemas:
patch_notes: