Beispiel #1
0
 def add_single_card_to_collection(self,
                                   single_card=Card(),
                                   card_inside=None) -> bool:
     if single_card not in self.instance.cards:
         single_card.cardsCollection = self.instance
         if card_inside is not None:
             single_card.cardInside = card_inside
         Session.add_and_commit(single_card)
         return True
     return False
    def add_new_user(username: str, email: str, password_hash: str):
        user = User()
        user.userName = username
        user.userEmail = email
        user.userPasswordHash = password_hash

        Session.add_and_commit(user)
        user_context = UserContext(user)

        return user_context
Beispiel #3
0
 def __init__(self, collection=None, holder_instance=None):
     super(CardsCollectionContext, self).__init__()
     if collection is None:
         if holder_instance is not None:
             collection = CardsCollection()
             collection.user = holder_instance
             Session.add_and_commit(collection)
         else:
             logging.error("Can't create object without a ref")
     self.instance = collection
 def __init__(self, collection, card=None, card_inside=None):
     super(CardContext, self).__init__()
     if card is None:
         if card_inside is None:
             card = Card()
             card_inside = CardInside()
             card.cardsCollection = collection
         card.cardInside = card_inside.json()
         Session.add_and_commit(card)
     self.instance = card
Beispiel #5
0
    def get_user_collections_json(user_id, page: int, size: int):
        data = Session.query(CardsCollection) \
            .filter(CardsCollection.holderID == user_id) \
            .paginate(page=page, per_page=size, max_per_page=size)

        res = {"total": data.pages, "items": []}
        for obj in data.items:
            res["items"].append(obj.json())
        return res
Beispiel #6
0
    def get_all_collections_json(page: int, size: int):
        data = Session.query(CardsCollection).paginate(page=page,
                                                       per_page=size,
                                                       max_per_page=size)

        res = {"total": data.pages, "items": []}
        for obj in data.items:
            res["items"].append(obj.json())
        return res
Beispiel #7
0
    def get_all_collections_with_field_liked(user_id, page: int, size: int):
        data = Session.query(CardsCollection).paginate(page=page,
                                                       per_page=size)

        list_of_liked = []
        liked = CardsCollectionContext.get_user_liked_collections(user_id)
        for collection in liked:
            list_of_liked.append(collection.collectionID)

        res = {"total": data.pages, "items": []}
        for obj in data.items:
            obj_json = obj.json()
            if obj.collectionID in list_of_liked:
                obj_json["is_liked"] = True
            else:
                obj_json['is_liked'] = False

            res["items"].append(obj_json)
        return res
Beispiel #8
0
 def get_single_card_by_id(card_id: int) -> Union[CardContext, bool]:
     card = Session.query(Card) \
         .filter(Card.cardID == card_id) \
         .first()
     return CardContext(card.collectionID, card) \
         if card is not None else False
Beispiel #9
0
 def get_only_watched_cards_of_collection(self, user_id):
     return Session.query(Card).join(CardWatched) \
         .filter(Card.collectionID == self.instance.collectionID,
                 CardWatched.userID == user_id).all()
 def get_user_instance_by_id(uid: int):
     user = Session.query(User).filter(User.userID == uid).first()
     return UserContext(user) if user else None
 def exists_by_username(user_name: str) -> bool:
     return Session.query(User).filter(User.userName == user_name).first() is not None
 def set_user_info(self, info: str):
     self.instance.userInfo = info
     Session.commit()
Beispiel #13
0
 def set_name(self, collection_name: str):
     self.instance.collectionName = collection_name
     Session.commit()
Beispiel #14
0
 def set_description(self, description: str):
     self.instance.collectionDescription = description
     Session.commit()
Beispiel #15
0
 def delete_from_user_favorite(user_id, collection_id):
     user_liked = Session.query(UserLikedCollection).filter(
         UserLikedCollection.collectionID == collection_id).filter(
             UserLikedCollection.userID == user_id).first()
     Session.del_and_commit(user_liked)
Beispiel #16
0
 def add_to_user_favorite(user_id, collection_id):
     user_liked_collection = UserLikedCollection()
     user_liked_collection.collectionID = collection_id
     user_liked_collection.userID = user_id
     Session.add_and_commit(user_liked_collection)
Beispiel #17
0
 def delete_collection(collection_id):
     Session.del_and_commit(
         CardsCollectionContext.get_collection_by_id(collection_id))
     return True
Beispiel #18
0
 def get_collection_by_id(collection_id: int):
     collection = Session.query(CardsCollection) \
         .filter(CardsCollection.collectionID == collection_id) \
         .first()
     return collection
 def set_username(self, username: str):
     self.instance.userName = username
     Session.commit()
Beispiel #20
0
 def get_collection_by_id_json(collection_id):
     collection = Session.query(CardsCollection) \
         .filter(CardsCollection.collectionID == collection_id) \
         .first()
     return collection.json() or None
 def set_password_hash(self, new_password_hash: str):
     self.instance.userPasswordHash = new_password_hash
     Session.commit()
 def get_user_instance_by_email(email: str):
     user = Session.query(User).filter(User.userEmail == email).first()
     return UserContext(user) if user else None
 def exists_by_email(email: str) -> bool:
     return Session.query(User).filter(User.userEmail == email).first() is not None
 def add_card_to_watched(self, user: User):
     if user in User.query.all():
         card_watched = CardWatched()
         card_watched.cardID = self.instance.cardID
         card_watched.userID = user.userID
         Session.add_and_commit(card_watched)
 def get_user_instance_by_username(username: str):
     user = Session.query(User).filter(User.userName == username).first()
     return UserContext(user) if user else None
 def get_card_by_id(card_id):
     return Session.query(Card).filter(Card.cardID == card_id).first()
Beispiel #27
0
 def delete_single_card_from_collection(single_card_id):
     Session.del_and_commit(CardContext.get_card_by_id(single_card_id))
 def change_card_inside(self, new_inside: dict) -> bool:
     if new_inside:
         self.instance.cardInside = new_inside
         Session.commit()
     return new_inside is not None