def delete(self, activity_id: int): activity = Activity.query.filter_by( id=activity_id).first_or_404('Activity not found') if (wishlist := Wishlist.check_wishlist(activity.id, get_jwt_identity())): wishlist.delete_from_db() return {"message": "Activity remove from wishlist"}, 200
def post(self, activity_id: int): activity = Activity.query.filter_by( id=activity_id).first_or_404('Activity not found') if not Wishlist.check_wishlist(activity.id, get_jwt_identity()): wishlist = Wishlist(activity_id=activity.id, user_id=get_jwt_identity()) wishlist.save_to_db() return {"message": "Activity entered into the wishlist"}, 200 return {"message": "Activity already in wishlist"}, 200
def get(self): _activity_card_schema = ActivitySchema(exclude=("min_person","information","image2","image3","image4","description","duration", "pickup","include","created_at","updated_at","category")) visits = Visit.visit_popular_by(visit_type='view_activity',limit=5) raw_activity = [Activity.query.get(index) for index,value in visits] # if user login extract data and show wishlist on card data = _activity_card_schema.dump(raw_activity,many=True) if (current_user := get_jwt_identity()): for activity in data: activity['love'] = True if Wishlist.check_wishlist(activity['id'],current_user) else False
def get(self,slug: str): activity = Activity.query.filter_by(slug=slug).first_or_404('Activity not found') Visit.set_visit(ip=request.remote_addr,visitable_id=activity.id,visitable_type='view_activity') data = _activity_schema.dump(activity) # get wishlist,seen,discussion data data['seen'] = Visit.get_seen_activity(visit_type='view_activity',visit_id=activity.id) data['wishlist'] = Wishlist.query.filter_by(activity_id=activity.id).count() data['discussion'] = Comment.query.filter(Comment.commentable_id == activity.id, Comment.commentable_type == 'activity').count() if (current_user := get_jwt_identity()): data['love'] = True if Wishlist.check_wishlist(data['id'],current_user) else False
error_out=False) elif sort == 'expensive': activities = Activity.query.order_by( Activity.price.desc()).paginate(page, per_page, error_out=False) else: activities = Activity.query.paginate(page, per_page, error_out=False) # if user login extract data and show wishlist on card data = _activity_card_schema.dump(activities.items, many=True) if (current_user := get_jwt_identity()): for activity in data: activity['love'] = True if Wishlist.check_wishlist( activity['id'], current_user) else False result = dict(data=data, next_num=activities.next_num, prev_num=activities.prev_num, page=activities.page, iter_pages=[x for x in activities.iter_pages()]) return result, 200 class GetActivitySlug(Resource): @jwt_optional def get(self, slug: str): activity = Activity.query.filter_by( slug=slug).first_or_404('Activity not found') Visit.set_visit(ip=request.remote_addr,