def put(self, deposit_id):
        """
            Update deposit details by deposit id
        """
        args = self.reqparse.parse_args(strict=True)

        user = User.query.filter_by(username=auth.username()).first()
        deposit = Deposit.query.filter_by(id=deposit_id, user=user.id)

        if not deposit:
            app.logger.error("Invalid deposit id : {0}".format(deposit_id))
            raise ApiException("Invalid deposit id")

        update_values = {k: v for k, v in args.items() if v}
        deposit.update(update_values)

        db.session.commit()

        updated_deposit = Deposit.query.filter_by(id=deposit_id,
                                                  user=user.id).first()

        return make_response(
            jsonify({
                'data': marshal(updated_deposit, DepositSchema),
                'message': None,
                'status': 'success'
            }))
Beispiel #2
0
    def post(self):
        """
            Deposit amount along with other meta information of transaction
        """
        args = self.reqparse.parse_args()

        # Make sure all parameters are present
        if any([not v for k, v in args.items()]):
            raise RequirementParameterMissing(args)

        user = User.query.filter_by(username=auth.username()).first()

        deposit_item = {
            'country': args.country,
            'city': args.city,
            'currency': args.currency,
            'amount': args.amount,
            'user': user.id
        }

        app.logger.debug("Adding deposit for user : {0}".format(deposit_item))

        deposit = Deposit(**deposit_item)
        db.session.add(deposit)
        db.session.commit()

        deposit_item.update({'id': deposit.id})

        return make_response(
            jsonify({
                'data': deposit_item,
                'message': 'Deposited!',
                'status': 'success'
            }), 201)
Beispiel #3
0
def get_tasks():
    user = service.check_login(
        auth.username())  # Если существует возвращает объект User
    if user is None:
        return server_error('user`s none')
    tasks = service.get_tasks(user)
    return make_response(
        jsonify({'tasks': [task.to_dict() for task in tasks]}), 200)
Beispiel #4
0
def delete_user() -> object:
    result = service.delete_user(auth.username())
    if result[0] == 1:
        return not_found(result[1])
    elif result[0] == 2:
        return server_error(result[1])
    response = {'status': 200, 'message': result[1]}
    return make_response(jsonify(response))
Beispiel #5
0
def get_task(task_id: int):
    user = service.check_login(
        auth.username())  # Если существует возвращает объект User
    if user is None:
        return server_error('user`s none')
    task = service.get_task(user, task_id)
    if task is None:
        return not_found(f'task {task_id} was not found')
    return make_response(jsonify(task.to_dict()), 200)
Beispiel #6
0
def done_task(task_id: int) -> object:
    user = service.check_login(
        auth.username())  # Если существует возвращает объект User
    task = service.done_task(user, task_id)
    if task[0] == 1:
        return not_found(task[1])
    elif task[0] == 2:
        return server_error(task[1])
    response = {'status': 200, 'message': task[1], 'task': task[2].to_dict()}
    return make_response(jsonify(response), 200)
Beispiel #7
0
    def get(self):
        """
            Fetches all deposits done by the user
        """

        user = User.query.filter_by(username=auth.username()).first()

        app.logger.debug("Fetched details for user with username : {0}".format(
            auth.username()))

        data = Deposit.query.filter_by(user=user.id)

        data = [marshal(deposit, DepositSchema) for deposit in data]

        return make_response(
            jsonify({
                'data': data,
                'message': None,
                'status': 'success'
            }))
 def post(self):
     # Übersetzer: von Request zu Python übersetzt
     parser = reqparse.RequestParser()
     # Die Argumente username und email müssen vorhanden sein
     parser.add_argument('text', type=str)
     #ID des aktuell-eingeloggten Users wird verwendet.
     id = User.query.filter_by(username=auth.username()).first().id
     # Fügt das Objekt in die Datenbank hinzu
     db.session.add(
         Message(text=parser.parse_args().text,
                 owner=id,
                 forumPost=parser.parse_args().forumPost))
     db.session.commit()
     # Returned etwas
     return 'success', 200
    def get(self, deposit_id):
        """
            Fetches deposit information by deposit id
        """
        user = User.query.filter_by(username=auth.username()).first()
        deposit = Deposit.query.filter_by(id=deposit_id, user=user.id).first()

        if not deposit:
            app.logger.error("Invalid deposit id : {0}".format(deposit_id))
            raise ApiException("Invalid deposit id.")

        return jsonify({
            'data': marshal(deposit, DepositSchema),
            'message': None,
            'status': 'success'
        })
Beispiel #10
0
def finish_event(event_id):
    uid = User.query.filter(
        User.username == auth.username().lower()).with_entities(
            User.uid).scalar()
    time = request.args.get('time') or '00:00:00'
    score = request.args.get('score')
    h, m, s = time.split(':')
    event_stat = EventStat(uid,
                           event_id,
                           hours=h,
                           minutes=m,
                           seconds=s,
                           score=score)
    db.session.add(event_stat)
    db.session.commit()
    e = Event.query.get(event_id)
    return gdumps(e)
Beispiel #11
0
def create_task() -> object:
    user = service.check_login(
        auth.username())  # Если существует возвращает объект User
    data = request.get_json() or {}
    if not data:
        return bad_request('missing json request')
    elif 'title' not in data:
        return bad_request('the title field is missing')
    elif 'description' not in data:
        return bad_request('the description field is missing')
    elif 'deadline' not in data:
        return bad_request('the deadline field is missing')
    task = service.create_task(data, user)
    if task[0] == 1:
        return bad_request(task[1])
    elif task[0] == 2:
        return server_error(task[1])
    response = {'status': 201, 'task': task[2].to_dict()}
    return make_response(jsonify(response), 201)
    def delete(self, deposit_id):
        """
            Delete deposit entry by deposit_id
        """
        user = User.query.filter_by(username=auth.username()).first()
        deposit = Deposit.query.filter_by(id=deposit_id, user=user.id).first()

        if not deposit:
            app.logger.error("Invalid deposit id : {0}".format(deposit_id))
            raise ApiException("Invalid deposit id")

        db.session.delete(deposit)
        db.session.commit()

        return jsonify({
            'data':
            None,
            'message':
            "Deleted deposit with id : {0}".format(deposit_id),
            'status':
            'success'
        })
Beispiel #13
0
def get_my_events():
    user = User.query.filter(User.username == auth.username().lower()).first()
    return '[' + ','.join(gdumps(e) for e in user.saved_events) + ']'
Beispiel #14
0
def remove_my_event(eid):
    user = User.query.filter(User.username == auth.username().lower()).first()
    e = Event.query.get(eid)
    user.saved_events.remove(e)
    db.session.commit()
    return '[' + ','.join(gdumps(e) for e in user.saved_events) + ']'
Beispiel #15
0
def parse_view():
    request_query = request.form['query']

    return jsonify({"cards": ctrl.get_learning_mode_data(request_query, auth.username())})
Beispiel #16
0
def index():
    return "Hello, {}!".format(auth.username())
Beispiel #17
0
 def get(self):
     return "Hello, %s!" % auth.username()
Beispiel #18
0
def secret():
    return "Hello, %s!" % auth.username()