create and put patchnote bugs fixed
This commit is contained in:
parent
ab26234c20
commit
bdf0466d79
|
|
@ -31,32 +31,41 @@ def create_patchnote(body): # noqa: E501
|
|||
:rtype: Union[PatchNotes, Tuple[PatchNotes, int], Tuple[PatchNotes, int, Dict[str, str]]
|
||||
"""
|
||||
patch_notes_input = body
|
||||
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,
|
||||
)
|
||||
if not body:
|
||||
return Response("No patch notes provided", status=400)
|
||||
|
||||
patch_note = {
|
||||
'patchID': str(uuid.uuid4()),
|
||||
'title': pn.title,
|
||||
'changes': pn.changes,
|
||||
'version': pn.version,
|
||||
'patch_date': date_str
|
||||
pn = PatchNotes.from_dict(body)
|
||||
|
||||
# --- Datum wahlweise als str oder date annehmen ---
|
||||
if isinstance(pn.patch_date, date):
|
||||
date_str = pn.patch_date.isoformat()
|
||||
else:
|
||||
try:
|
||||
date_str = datetime.strptime(pn.patch_date, "%Y-%m-%d").date().isoformat()
|
||||
except ValueError:
|
||||
raise ProblemException(
|
||||
title="Bad Request",
|
||||
detail="patch_date must be in format YYYY-MM-DD",
|
||||
status=400,
|
||||
)
|
||||
|
||||
patch_doc = {
|
||||
"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)
|
||||
collection.insert_one(patch_doc)
|
||||
patch_doc.pop("_id", None) # Mongo-internes Feld ausblenden
|
||||
|
||||
return Response(
|
||||
json_util.dumps(patch_doc),
|
||||
mimetype="application/json",
|
||||
status=201, # 201 Created
|
||||
headers={"Location": f"/api/patchnotes/{patch_doc['patchID']}"},
|
||||
)
|
||||
|
||||
|
||||
def delete_patchnote(patch_id): # noqa: E501
|
||||
|
|
@ -155,30 +164,45 @@ def update_patchnote(patch_id, body): # noqa: E501
|
|||
|
||||
:rtype: Union[PatchNotes, Tuple[PatchNotes, int], Tuple[PatchNotes, int, Dict[str, str]]
|
||||
"""
|
||||
if not body:
|
||||
return Response("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,
|
||||
)
|
||||
query_filter = {'patchID': patch_id}
|
||||
updated_post = {'$set':
|
||||
{
|
||||
'title': pn.title,
|
||||
'changes': pn.changes,
|
||||
'version': pn.version,
|
||||
'date': date_str
|
||||
}
|
||||
}
|
||||
result = collection.update_one(query_filter, updated_post)
|
||||
if result.modified_count == 0:
|
||||
|
||||
if isinstance(pn.patch_date, date):
|
||||
date_str = pn.patch_date.isoformat()
|
||||
else:
|
||||
try:
|
||||
date_str = datetime.strptime(pn.patch_date, "%Y-%m-%d").date().isoformat()
|
||||
except ValueError:
|
||||
raise ProblemException(
|
||||
title="Bad Request",
|
||||
detail="patch_date must be in format YYYY-MM-DD",
|
||||
status=400,
|
||||
)
|
||||
|
||||
result = collection.update_one(
|
||||
{"patchID": patch_id},
|
||||
{"$set": {
|
||||
"title": pn.title,
|
||||
"changes": pn.changes,
|
||||
"version": pn.version,
|
||||
"patch_date": date_str, # richtiger Feldname!
|
||||
}}
|
||||
)
|
||||
|
||||
if result.matched_count == 0:
|
||||
raise ProblemException(
|
||||
title="Not found",
|
||||
detail="No document has been deleted",
|
||||
detail="No document has been found",
|
||||
status=404,
|
||||
)
|
||||
return Response("Document was updated", status=200, mimetype='application/json')
|
||||
|
||||
doc = collection.find_one({"patchID": patch_id})
|
||||
doc.pop("_id", None)
|
||||
|
||||
return Response(
|
||||
json_util.dumps(doc),
|
||||
mimetype="application/json",
|
||||
status=200,
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue