Пример #1
0
def delete_alarm_id(alarmID):
    data = DataRepository.delete_alarm(alarmID)
    if data is not None:
        if data > 0:
            return jsonify(alarmID=alarmID, status="success"), 200
        else:
            return jsonify(status=data), 204
    else:
        return jsonify(status="error"), 404
Пример #2
0
def get_alarm_by_id(userid, alarmid):
    if request.method == "GET":
        data = DataRepository.get_alarm_by_userid(userid, alarmid)
        return jsonify(data), 200
    elif request.method == "PUT":
        js = request.get_json()
        data = DataRepository.update_alarm(userid, alarmid, js['name'],
                                           js['starttime'], js['duration'],
                                           js['days'])
        return jsonify(data), 201
    elif request.method == "DELETE":
        data = DataRepository.delete_alarm(alarmid, userid)
        return jsonify(data), 201
Пример #3
0
def get_alarm(alarmid):
    if request.method == 'GET':
        s = DataRepository.get_alarm(alarmid)
        s['time'] = str(s['time'])
        weekdays = DataRepository.get_alarm_weekdays(s['idalarm'])
        s['weekdays'] = []
        for i in range(len(weekdays)):
            s['weekdays'].append(weekdays[i]['weekday'] - 1)
        return jsonify(s), 200
    elif request.method == 'PUT':
        gegevens = DataRepository.json_or_formdata(request)
        data = DataRepository.change_alarm(gegevens['idalarm'],
                                           gegevens['idsound'],
                                           gegevens['time'],
                                           gegevens['enabled'])
        DataRepository.set_weekdays(gegevens['idalarm'], gegevens['weekdays'])
        print("changing alarm")
        return jsonify(id=data), 200
    elif request.method == 'DELETE':
        s = DataRepository.delete_alarm(alarmid)
        print("deleting alarm")
        return jsonify(s), 200