patchnotes post done
This commit is contained in:
parent
07d201d3ae
commit
464930cee5
|
|
@ -21,6 +21,8 @@
|
|||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
||||
gen/openapi_server/controllers/patchnotes_controller.py
|
||||
gen/openapi_server/__main__.py
|
||||
gen/openapi_server/encoder.py
|
||||
gen/openapi_server/controllers
|
||||
gen/openapi_server/test
|
||||
gen/openapi_server
|
||||
|
|
|
|||
|
|
@ -93,6 +93,10 @@ components:
|
|||
date:
|
||||
title: date
|
||||
type: string
|
||||
required:
|
||||
- "title"
|
||||
- "changes"
|
||||
- "date"
|
||||
user:
|
||||
example:
|
||||
lastSeenDate: 2025-01-02
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
FROM python:3-alpine
|
||||
|
||||
RUN mkdir -p /usr/src/app
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY requirements.txt /usr/src/app/
|
||||
|
||||
RUN pip3 install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . /usr/src/app
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENTRYPOINT ["python3"]
|
||||
|
||||
CMD ["-m", "openapi_server"]
|
||||
|
|
@ -6,7 +6,7 @@ import connexion
|
|||
from openapi_server import encoder
|
||||
from pymongo import MongoClient
|
||||
|
||||
client = MongoClient(host='mongodb://localhost:27017/')
|
||||
client = MongoClient(host='mongodb://host.docker.internal:27017/')
|
||||
db = client["MainDB"]
|
||||
collection = db['patch_notes']
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,10 @@
|
|||
import logging
|
||||
|
||||
import connexion
|
||||
from typing import Dict
|
||||
from typing import Tuple
|
||||
from typing import Union
|
||||
import uuid
|
||||
|
||||
from bson import json_util
|
||||
from flask import Response
|
||||
from pymongo import MongoClient
|
||||
|
||||
from openapi_server.__main__ import collection
|
||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||
from openapi_server import util
|
||||
|
||||
|
||||
|
||||
def patchnotes_date_get(date): # noqa: E501
|
||||
|
|
@ -52,22 +44,34 @@ def patchnotes_patch_iddelete(patch_id): # noqa: E501
|
|||
return 'do some magic!'
|
||||
|
||||
|
||||
def patchnotes_post(body=None): # TODO done for now
|
||||
def patchnotes_post(body): # TODO _date to date change
|
||||
"""patchnotes_post
|
||||
|
||||
creates new Patch notes # noqa: E501
|
||||
|
||||
:param patch_notes:
|
||||
: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]]
|
||||
"""
|
||||
patch_notes = body
|
||||
logging.error('patch notes' + str(patch_notes))
|
||||
if patch_notes is None:
|
||||
if body is None:
|
||||
return Response(json_util.dumps({'error': 'No patch notes provided'}), status=400)
|
||||
# Insert the document into the MongoDB collection
|
||||
posted_patch_id = collection.insert_one(patch_notes)
|
||||
pn = PatchNotes.from_dict(body)
|
||||
logging.error('patch_notes_type:' + str(type(pn)))
|
||||
logging.error('patch notes' + str(pn))
|
||||
|
||||
return Response(json_util.dumps(f'patch with ID: {posted_patch_id} was created'), mimetype='application/json',
|
||||
patch_notes_uuid = uuid.uuid4()
|
||||
|
||||
patch_notes = {
|
||||
'patchID': str(patch_notes_uuid),
|
||||
'title': pn.title,
|
||||
'changes': pn.changes,
|
||||
'date': pn._date,
|
||||
}
|
||||
logging.error('patch_notes_type:' + str(type(patch_notes)))
|
||||
logging.error('patch notes' + str(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',
|
||||
status=200)
|
||||
|
|
@ -15,4 +15,4 @@ class JSONEncoder(ConnexionJSONEncoder):
|
|||
attr = o.attribute_map[attr]
|
||||
dikt[attr] = value
|
||||
return dikt
|
||||
return ConnexionJSONEncoder.default(self, o)
|
||||
return ConnexionJSONEncoder.default(self, o)
|
||||
|
|
|
|||
|
|
@ -93,6 +93,8 @@ class PatchNotes(Model):
|
|||
:param title: The title of this PatchNotes.
|
||||
:type title: str
|
||||
"""
|
||||
if title is None:
|
||||
raise ValueError("Invalid value for `title`, must not be `None`") # noqa: E501
|
||||
|
||||
self._title = title
|
||||
|
||||
|
|
@ -114,6 +116,8 @@ class PatchNotes(Model):
|
|||
:param changes: The changes of this PatchNotes.
|
||||
:type changes: str
|
||||
"""
|
||||
if changes is None:
|
||||
raise ValueError("Invalid value for `changes`, must not be `None`") # noqa: E501
|
||||
|
||||
self._changes = changes
|
||||
|
||||
|
|
@ -135,5 +139,7 @@ class PatchNotes(Model):
|
|||
:param _date: The _date of this PatchNotes.
|
||||
:type _date: str
|
||||
"""
|
||||
if _date is None:
|
||||
raise ValueError("Invalid value for `_date`, must not be `None`") # noqa: E501
|
||||
|
||||
self.__date = _date
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ info:
|
|||
title: announcementService
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: http://127.0.0.1:8080/api
|
||||
- url: /
|
||||
paths:
|
||||
/patchnotes:
|
||||
post:
|
||||
|
|
@ -102,6 +102,10 @@ components:
|
|||
date:
|
||||
title: date
|
||||
type: string
|
||||
required:
|
||||
- changes
|
||||
- date
|
||||
- title
|
||||
title: patch_notes
|
||||
user:
|
||||
example:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class BaseTestCase(TestCase):
|
|||
|
||||
def create_app(self):
|
||||
logging.getLogger('connexion.operation').setLevel('ERROR')
|
||||
app = connexion.App(__name__ , specification_dir='../openapi/')
|
||||
app = connexion.App(__name__, specification_dir='../openapi/')
|
||||
app.app.json_encoder = JSONEncoder
|
||||
app.add_api('openapi.yaml', pythonic_params=True, base_path='/api')
|
||||
app.add_api('openapi.yaml', pythonic_params=True)
|
||||
return app.app
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
connexion[swagger-ui, flask, uvicorn] >= 3.2.0
|
||||
werkzeug == 3.1.3
|
||||
connexion[swagger-ui] >= 2.6.0; python_version>="3.6"
|
||||
# 2.3 is the last version that supports python 3.4-3.5
|
||||
connexion[swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4"
|
||||
# prevent breaking dependencies from advent of connexion>=3.0
|
||||
connexion[swagger-ui] <= 2.14.2; python_version>"3.4"
|
||||
# connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug
|
||||
# we must peg werkzeug versions below to fix connexion
|
||||
# https://github.com/zalando/connexion/pull/1044
|
||||
werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4"
|
||||
swagger-ui-bundle >= 0.0.2
|
||||
python_dateutil >= 2.6.0
|
||||
setuptools >= 21.0.0
|
||||
Flask >= 3.1.0
|
||||
Flask-PyMongo >= 3.0.1
|
||||
pymongo >= 4.11.3
|
||||
Flask == 2.1.1
|
||||
|
|
|
|||
Loading…
Reference in New Issue