tcc/FlaskAPI/controllers/simulation.py

31 lines
803 B
Python
Raw Normal View History

2023-10-29 22:01:13 +00:00
from flask import request, Blueprint, jsonify
simulation_blueprint = Blueprint('simulation_blueprint', __name__)
class SimulationController:
def __init__(self):
pass
def harmonic_progression(self, n):
sum = 0
for i in range(1, n):
sum += 1/i
return sum
2023-10-29 22:01:13 +00:00
def return_helloworld(self):
return jsonify(message="Hello World!")
simulation_controller = SimulationController()
@simulation_blueprint.route('/simulation/harmonic-progression', methods=['GET'])
def return_ok():
n = int(request.args.get('n'))
sum = simulation_controller.harmonic_progression(n)
return str(sum), 200
2023-10-29 22:01:13 +00:00
@simulation_blueprint.route('/simulation/json', methods=['GET'])
2023-10-30 23:34:20 +00:00
def return_helloworld():
2023-10-29 22:01:13 +00:00
return simulation_controller.return_helloworld(), 200