Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def get_user_instance_by_email(email: str):
     user = Session.query(User).filter(User.userEmail == email).first()
     return UserContext(user) if user else None
Ejemplo n.º 5
0
 def get_user_instance_by_username(username: str):
     user = Session.query(User).filter(User.userName == username).first()
     return UserContext(user) if user else None
Ejemplo n.º 6
0
 def get_user_instance_by_id(uid: int):
     user = Session.query(User).filter(User.userID == uid).first()
     return UserContext(user) if user else None
Ejemplo n.º 7
0
 def exists_by_email(email: str) -> bool:
     return Session.query(User).filter(User.userEmail == email).first() is not None
Ejemplo n.º 8
0
 def exists_by_username(user_name: str) -> bool:
     return Session.query(User).filter(User.userName == user_name).first() is not None
Ejemplo n.º 9
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
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
 def get_collection_by_id_json(collection_id):
     collection = Session.query(CardsCollection) \
         .filter(CardsCollection.collectionID == collection_id) \
         .first()
     return collection.json() or None
Ejemplo n.º 12
0
 def get_collection_by_id(collection_id: int):
     collection = Session.query(CardsCollection) \
         .filter(CardsCollection.collectionID == collection_id) \
         .first()
     return collection
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
 def get_card_by_id(card_id):
     return Session.query(Card).filter(Card.cardID == card_id).first()