2020-09-12 10:58:38 +00:00
|
|
|
from flask import request, jsonify
|
|
|
|
from walrus import Walrus
|
|
|
|
from time import time
|
|
|
|
|
|
|
|
import uuid
|
|
|
|
import struct
|
|
|
|
|
2020-09-12 17:51:47 +00:00
|
|
|
from . import app
|
2020-09-13 13:07:11 +00:00
|
|
|
from .countdown import Cache
|
2020-09-12 10:58:38 +00:00
|
|
|
|
2020-09-12 17:51:47 +00:00
|
|
|
@app.route('/api/v1/<uuid:id>', methods=['GET'])
|
2020-09-12 10:58:38 +00:00
|
|
|
def get_countdown(id):
|
2020-09-13 13:07:11 +00:00
|
|
|
cache = Cache.getInstance()
|
|
|
|
countdown = cache.get_countdown(id)
|
|
|
|
|
|
|
|
response = countdown
|
2020-09-12 10:58:38 +00:00
|
|
|
|
2020-09-13 13:07:11 +00:00
|
|
|
time_passed = time() - float(countdown['start'])
|
|
|
|
time_left = float(countdown['total']) - time_passed
|
|
|
|
response['left'] = time_left
|
|
|
|
response['roundtrip_start'] = request.args.get('roundtrip_start')
|
2020-09-12 10:58:38 +00:00
|
|
|
|
2020-09-13 13:07:11 +00:00
|
|
|
return response
|
2020-09-12 10:58:38 +00:00
|
|
|
|
2020-09-12 17:51:47 +00:00
|
|
|
@app.route('/api/v1', methods=['POST'])
|
2020-09-12 10:58:38 +00:00
|
|
|
def create_countdown():
|
2020-09-13 13:07:11 +00:00
|
|
|
cache = Cache.getInstance()
|
2020-09-12 10:58:38 +00:00
|
|
|
|
2020-09-13 13:07:11 +00:00
|
|
|
countdown = request.json
|
|
|
|
total = float(countdown['total'])
|
|
|
|
response = cache.add_countdown(total)
|
|
|
|
return response
|
|
|
|
|
|
|
|
@app.route('/api/v1/start/<uuid:id>', methods=['PATCH'])
|
|
|
|
def start_countdown(id):
|
|
|
|
cache = Cache.getInstance()
|
|
|
|
return cache.start_countdown(id)
|
|
|
|
|
|
|
|
@app.route('/api/v1/reset/<uuid:id>', methods=['PATCH'])
|
|
|
|
def reset_countdown(id):
|
|
|
|
cache = Cache.getInstance()
|
|
|
|
return cache.reset_countdown(id)
|
|
|
|
|
|
|
|
@app.route('/api/v1/stop/<uuid:id>', methods=['PATCH'])
|
|
|
|
def stop_countdown(id):
|
|
|
|
cache = Cache.getInstance()
|
|
|
|
return cache.stop_countdown(id)
|