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)
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)
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)
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)
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)
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()
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)
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)
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))
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)
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)
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)
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)
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)
def params_validation(rgxs, params): for param, rgx in zip(params, rgxs): if re.match(rgx, param) == None: raise ErrorCodeException(ErrorCode.INVALID_PARAMETER)
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
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
def get_type(type): tt = TicketType.query.filter_by(type=type).first() if tt == None: raise ErrorCodeException(ErrorCode.TICKETTYPE_DOESNT_EXISTS) return tt
def get_by_name(name): mt = MealType.query.filter_by(name=name).first() if mt == None: raise ErrorCodeException(ErrorCode.MEALTYPE_DOESNT_EXISTS) return mt
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
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
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
def get_by_name(name): l = Location.query.filter_by(name=name).first() if l == None: raise ErrorCodeException(ErrorCode.LOCATION_DOESNT_EXISTS) return l
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