Beispiel #1
0
 def delete(id_meal_type):
     mt = MealType.query.filter(Meal.id_meal_type==id_meal_type)
     
     if mt.delete() == 1:
         db.session.commit()
     else:
         raise ErrorCodeException(ErrorCode.MEALTYPE_DOESNT_EXISTS)
Beispiel #2
0
 def delete(date,id_location,id_meal_type):
     m = Meal.query.filter(Meal.date==date,Meal.id_location==id_location,Meal.id_meal_type==id_meal_type)
     
     if m.delete() == 1:
         db.session.commit()
     else:
         raise ErrorCodeException(ErrorCode.MEAL_DOESNT_EXISTS)
Beispiel #3
0
    def delete(id_user):
        u = User.query.filter(User.id_user == id_user)

        if u.delete() == 1:
            db.session.commit()
        else:
            raise ErrorCodeException(ErrorCode.USER_DOESNT_EXISTS)
Beispiel #4
0
    def delete(id_ticket):
        t = TicketType.query.filter(TicketType.id_ticket == id_ticket)

        if t.delete() == 1:
            db.session.commit()
        else:
            raise ErrorCodeException(ErrorCode.TICKETTYPE_DOESNT_EXISTS)
Beispiel #5
0
 def delete(id_location):
     l = Location.query.filter(Location.id_location==id_location)
     
     if l.delete() == 1:
         db.session.commit()
     else:
         raise ErrorCodeException(ErrorCode.LOCATION_DOESNT_EXISTS)
Beispiel #6
0
 def add_transaction(transaction):
     e = Transaction.query.filter_by(id_transaction=transaction.id_transaction, id_ticket=transaction.id_ticket).first()
     if e != None:
         raise ErrorCodeException(ErrorCode.TRANSACTION_EXISTS)
     
     db.session.add(transaction)
     db.session.commit()
Beispiel #7
0
 def add_meal_type(meal_type):
     try:
         MealType.get_meal_type(meal_type.id_meal_type)
     except ErrorCodeException:
         db.session.add(meal_type)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.MEALTYPE_EXISTS)
Beispiel #8
0
 def add_user(user):
     try:
         User.get_user(user.id_user)
     except ErrorCodeException:
         db.session.add(user)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.USER_EXISTS)
Beispiel #9
0
def set_as_used(id_ticket, id_user):

    t = Ticket.get_ticket(id_ticket)
    if t == None:
        raise ErrorCodeException(ErrorCode.TICKET_DOESNT_EXISTS)

    if t.id_user != id_user:
        raise ErrorCodeException(ErrorCode.TICKET_DOESNT_BELONG_TO_USER)

    if User.get_user(id_user) == None:
        raise ErrorCodeException(ErrorCode.USER_DOESNT_EXISTS)

    if t.used == True:
        raise ErrorCodeException(ErrorCode.TICKET_ALREADY_USED)
    t.set_used()

    History.add_entry(History(id_ticket=unhexlify(id_ticket), id_user=id_user))
Beispiel #10
0
    def delete(id_ticket):

        t = Ticket.query.filter(Ticket.id_ticket == unhexlify(id_ticket))

        if t.delete() == 1:
            db.session.commit()
        else:
            raise ErrorCodeException(ErrorCode.TICKET_DOESNT_EXISTS)
Beispiel #11
0
 def add_ticket(ticket):
     try:
         Ticket.get_ticket(hexlify(ticket.id_ticket).decode('ascii'))
     except ErrorCodeException:
         db.session.add(ticket)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.TICKET_EXISTS)
Beispiel #12
0
 def add_location(location):
     try:
         Location.get_location(location.id_location)
     except ErrorCodeException:
         db.session.add(location)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.LOCATION_EXISTS)
Beispiel #13
0
 def add_meal(meal):
     try:
         Meal.get_meal(meal.date,meal.id_location,meal.id_meal_type)
     except ErrorCodeException:
         db.session.add(meal)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.MEAL_EXISTS)
Beispiel #14
0
 def add_type(type):
     try:
         TicketType.get_type(type.type)
     except ErrorCodeException as ec:
         db.session.add(type)
         db.session.commit()
         return
     raise ErrorCodeException(ErrorCode.TICKETTYPE_EXISTS)
Beispiel #15
0
def params_validation(rgxs, params):
    for param, rgx in zip(params, rgxs):
        if re.match(rgx, param) == None:
            raise ErrorCodeException(ErrorCode.INVALID_PARAMETER)
Beispiel #16
0
 def get_transaction(id_transaction,id_ticket):
     e = Transaction.query.filter_by(id_transaction=id_transaction,id_ticket=unhexlify(id_ticket)).first()
     if e == None:
         raise ErrorCodeException(ErrorCode.TRANSACTION_DOESNT_EXISTS)
     return e
Beispiel #17
0
 def get_user(id_user):
     u = User.query.filter_by(id_user=id_user).first()
     if u == None:
         raise ErrorCodeException(ErrorCode.USER_DOESNT_EXISTS)
     return u
Beispiel #18
0
 def get_type(type):
     tt = TicketType.query.filter_by(type=type).first()
     if tt == None:
         raise ErrorCodeException(ErrorCode.TICKETTYPE_DOESNT_EXISTS)
     return tt
Beispiel #19
0
 def get_by_name(name):
     mt = MealType.query.filter_by(name=name).first()
     if mt == None:
         raise ErrorCodeException(ErrorCode.MEALTYPE_DOESNT_EXISTS)
     return mt
Beispiel #20
0
 def get_meal_type(id_meal_type):
     mt = MealType.query.filter_by(id_meal_type=id_meal_type).first()
     if mt == None:
         raise ErrorCodeException(ErrorCode.MEALTYPE_DOESNT_EXISTS)
     return mt
Beispiel #21
0
 def get_location(id_location):
     l = Location.query.filter_by(id_location=id_location).first()
     if l == None:
         raise ErrorCodeException(ErrorCode.LOCATION_DOESNT_EXISTS)
     return l
Beispiel #22
0
 def get_meal(date,id_location,id_meal_type):
     m = Meal.query.filter_by(date=date,id_location=id_location,id_meal_type=id_meal_type).first()
     if m == None:
         raise ErrorCodeException(ErrorCode.MEAL_DOESNT_EXISTS)
     return m
Beispiel #23
0
 def get_by_name(name):
     l = Location.query.filter_by(name=name).first()
     if l == None:
         raise ErrorCodeException(ErrorCode.LOCATION_DOESNT_EXISTS)
     return l
Beispiel #24
0
 def get_ticket(id_ticket):
     t = Ticket.query.filter_by(id_ticket=unhexlify(id_ticket)).first()
     if t == None:
         raise ErrorCodeException(ErrorCode.TICKET_DOESNT_EXISTS)
     return t