예제 #1
0
def get_friends_by_person(username=Depends(auth_wrapper)):
    try:
        with SQLITE_DB.atomic():
            person = PersonORM.select().where(
                PersonORM.username == username).get()
            friends_list = []

            query = (PersonORM.select().join(
                FriendsORM,
                on=FriendsORM.to_user).where(FriendsORM.from_user == person))

            for friend in query:
                friend_dict = {
                    "first_name": friend.first_name,
                    "last_name": friend.last_name,
                    "birthday": friend.birthday,
                    "username": friend.username,
                    "user_id": friend.user_id
                }

                friends_list.append(friend_dict)

            return friends_list

    except Exception as error:
        raise error
예제 #2
0
def get_token(login: AuthSchema):
    username, password = login.username, login.password

    try:
        with SQLITE_DB.atomic():
            query = Person.select().where(Person.username == username)
            for person in query:
                if bcrypt.checkpw(bytes(password, "UTF-8"),
                                  bytes(person.password, "UTF-8")):
                    jwt_token = jwt_encode(user=username)
                    return dict(access_token=jwt_token, token_type="bearer")

    except Exception:
        raise HTTPException(status_code=401, detail="Problem when logging in")
예제 #3
0
def make_transfer(transfer_schema: TransferSchema, username=Depends(auth_wrapper)):
    try:
        with SQLITE_DB.atomic():
            person = Person.select().where(Person.username == username).get()
            friend = Person.select().where(Person.user_id == transfer_schema.friend_id).get()
            card = Card.select().where(Card.card_id == transfer_schema.billing_card.card_id).get()

            BankStatement.create(
                user_id=person,
                friend_id=friend,
                value=transfer_schema.total_to_transfer,
                date=datetime.today().date(),
                from_card=card
            )
    except Exception as error:
        raise error
예제 #4
0
def add_card_to(card_schema: CardSchema, username=Depends(auth_wrapper)):
    try:
        with SQLITE_DB.atomic():
            query = PersonORM.select().where(PersonORM.username == username)
            for person in query:
                CardORM.create(card_id=card_schema.card_id,
                               title=card_schema.title,
                               PAN=card_schema.PAN,
                               expiry_mm=card_schema.expiry_mm,
                               expiry_yyyy=card_schema.expiry_yyyy,
                               security_code=card_schema.security_code,
                               date=card_schema.date,
                               owner=person)

    except Exception as error:
        raise error
    return dict(message="Card successfully registered")
예제 #5
0
def all_bank_statement(username=Depends(auth_wrapper)):
    try:
        with SQLITE_DB.atomic():
            bs_list = []
            query = BankStatementORM.select()
            for bs in query:
                person = PersonORM.select().where(
                    PersonORM.id == bs.user_id).get()
                friend = PersonORM.select().where(
                    PersonORM.id == bs.friend_id).get()
                card = CardORM.select().where(CardORM.id == bs.from_card).get()
                bs_dict = dict(user_id=person.user_id,
                               friend_id=friend.user_id,
                               value=bs.value,
                               date=bs.date,
                               from_card=card.card_id)
                bs_list.append(bs_dict)
            return bs_list
    except Exception as error:
        raise error
예제 #6
0
def bank_statement_by_userid(userid: str, username=Depends(auth_wrapper)):
    try:
        with SQLITE_DB.atomic():
            person = PersonORM.select().where(
                PersonORM.user_id == userid).get()
            query = BankStatementORM.select().where(
                BankStatementORM.user_id == person.id)
            bs_person_list = []
            for bs in query:
                friend = PersonORM.select().where(
                    PersonORM.id == bs.friend_id).get()
                card = CardORM.select().where(CardORM.id == bs.from_card).get()

                bs_dict = dict(user_id=person.user_id,
                               friend_id=friend.user_id,
                               value=bs.value,
                               date=bs.date,
                               from_card=card.card_id)
                bs_person_list.append(bs_dict)
            return bs_person_list
    except Exception as error:
        pass
예제 #7
0
def get_all_cards_by_person(username=Depends(auth_wrapper)):
    try:
        with SQLITE_DB.atomic():
            person = PersonORM.select().where(
                PersonORM.username == username).get()
            query = (CardORM.select().where(CardORM.owner == person))
            cards = []
            for card_row in query:
                card_dict = {
                    "card_id": card_row.card_id,
                    "title": card_row.title,
                    "PAN": card_row.PAN,
                    "expiry_mm": card_row.expiry_mm,
                    "expiry_yyyy": card_row.expiry_yyyy,
                    "security_code": card_row.security_code,
                    "date": card_row.date
                }
                cards.append(card_dict)

            return cards
    except Exception as error:
        raise error