Skip to content

Commit

Permalink
add PUT method
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheena Puthanpurayil committed Aug 25, 2021
1 parent 1eacb49 commit dfe9932
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:

charging_in_api:
c2_in_api:
build:
context: ./platform_in/
dockerfile: Dockerfile.prod
Expand Down
2 changes: 1 addition & 1 deletion nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
upstream ptf_incoming_api {
server charging_in_api:5002;
server c2_in_api:5002;
}

server {
Expand Down
42 changes: 40 additions & 2 deletions platform_in/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,46 @@ def ctx():
def hello_world():
return jsonify(health="ok")

@app.route("/c2/v1/<id>", methods=["POST"])
def postdata(id):
@app.route("/c2/v1/<id>", methods=["PUT"])
def putdata(id):

try:
# data = request.get_data()
data = request.get_data()
logging.info(f"put data goes like : {data[0:200]}")
logging.debug(f"put data in json : {json.loads(data)}")

# Asynchronously produce a message, the delivery report callback
# will be triggered from poll() above, or flush() below, when the message has
# been successfully delivered or failed permanently.

received_data = json.loads(data)


if "data" in received_data.keys():
#received measurement type data
key = received_data["n"]
elif "ref" in received_data.keys():
#received alarm or event type data
key = received_data["n"]

producer.send(
topic="test.sputhan",
key="",
value=request.get_json(),
)

return success_response_object, success_code

except Exception as e:
producer.flush()
logging.error("post data error", exc_info=True)
# elastic_apm.capture_exception()
return failure_response_object, failure_code


@app.route("/c2/v1", methods=["POST"])
def postdata():

try:
# data = request.get_data()
Expand Down

0 comments on commit dfe9932

Please sign in to comment.