-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproject_helloworld.py
More file actions
77 lines (60 loc) · 2.5 KB
/
project_helloworld.py
File metadata and controls
77 lines (60 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
"""Copyright (c) 2018-2024 mundialis GmbH & Co. KG.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Hello World class
"""
__license__ = "GPLv3"
__author__ = "Anika Weinmann"
__copyright__ = "Copyright 2024 mundialis GmbH & Co. KG"
__maintainer__ = "mundialis GmbH & Co. KG"
from typing import ClassVar
from actinia_cloudevent_plugin.model.response_models import SimpleResponseModel, SimpleStatusCodeResponseModel
from flask import jsonify, make_response, request
from flask.wrappers import Response
from flask_restful_swagger_2 import Resource, swagger
from actinia_cloudevent_plugin.apidocs import project_helloworld
from actinia_cloudevent_plugin.core.example import transform_input
class ProjectHelloWorld(Resource):
"""Returns 'Hello world with project/location!'."""
def __init__(self) -> None:
"""Project hello world class initialisation."""
self.msg = "Project: Hello world!"
@swagger.doc(project_helloworld.describe_project_hello_world_get_docs)
def get(self) -> Response:
"""Get 'Hello world!' as answer string."""
msg = f"{self.msg}"
return make_response(
jsonify(
SimpleResponseModel(
status="200",
message=msg,
),
),
200,
)
@swagger.doc(project_helloworld.describe_project_hello_world_post_docs)
def post(self):
"""Hello World post method with name from postbody."""
req_data = request.get_json(force=True)
if isinstance(req_data, dict) is False or "name" not in req_data:
return make_response("Missing name in JSON content", 400)
name = req_data["name"]
msg = f"{self.msg} {transform_input(name)}"
return make_response(
jsonify(
SimpleResponseModel(
status="200",
message=msg,
),
),
200,
)