Last active
September 17, 2019 09:13
-
-
Save belyaev-pa/c4a29da8ddaddf31a583738fdc57b270 to your computer and use it in GitHub Desktop.
test task for refactoring fome shit code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from project.strategies import container as strategies_container | |
from project.schemas import ScorePlayload | |
from altron.http import response, abort | |
from flask import request | |
@app.route('/strategies/<strategy>') | |
def get_strategy(strategy): | |
if strategies_container.has(strategy): | |
strategy = strategies_container.get(strategy) | |
else: | |
error = 'Неизвестное имя стратегии: ' + strategy | |
abort.not_found(error) # raise 404 | |
try: | |
payload = request.get_json(force=True, selint=True) | |
except BaseException: | |
error = 'payload get error' | |
abort.not_found(error) # raise 404 | |
if ScorePlayload().is_valid(payload): | |
pass | |
else: | |
msg = 'Input payload validation failed' | |
return response.bad_request(msg, data=payload) | |
score = strategy.get_score(payload) | |
return response.ok(data=score.normalize().to_dict()) | |
@app.route('/strategies/<strategy>', methods=['DELETE']) | |
def post_strategy(strategy): | |
if strategies_container.has(strategy): | |
strategy = strategies_container.get(strategy) | |
else: | |
error = 'Неизвестное имя стратегии: ' + strategy | |
abort.not_found(error) # raise 404 | |
strategies_container.remove(strategy) | |
return response.ok() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment