(feed_name)
| 15 | |
| 16 | @posts.route("/posts/<feed_name>", methods=["GET"]) |
| 17 | def get_posts(feed_name): |
| 18 | limit = request.args.get("limit", default=20, type=int) |
| 19 | offset = request.args.get("offset", default=0, type=int) |
| 20 | sortby = request.args.get("sortby", default="top", type=str) |
| 21 | duration = request.args.get("duration", default="alltime", type=str) |
| 22 | try: |
| 23 | sortBy, durationBy = get_filters(sortby=sortby, duration=duration) |
| 24 | except Exception: |
| 25 | return jsonify({"message": "Invalid Request"}), 400 |
| 26 | if feed_name == "home" and current_user.is_authenticated: |
| 27 | threads = [subscription.subthread.id for subscription in Subscription.query.filter_by(user_id=current_user.id)] |
| 28 | elif feed_name == "all": |
| 29 | threads = (thread.id for thread in SubthreadInfo.query.order_by(SubthreadInfo.members_count.desc()).limit(25)) |
| 30 | elif feed_name == "popular": |
| 31 | threads = (thread.id for thread in SubthreadInfo.query.order_by(SubthreadInfo.posts_count.desc()).limit(25)) |
| 32 | else: |
| 33 | return jsonify({"message": "Invalid Request"}), 400 |
| 34 | post_list = [ |
| 35 | pinfo.as_dict(cur_user=current_user.id if current_user.is_authenticated else None) |
| 36 | for pinfo in PostInfo.query.filter(PostInfo.thread_id.in_(threads)) |
| 37 | .order_by(sortBy) |
| 38 | .filter(durationBy) |
| 39 | .limit(limit) |
| 40 | .offset(offset) |
| 41 | .all() |
| 42 | ] |
| 43 | return jsonify(post_list), 200 |
| 44 | |
| 45 | |
| 46 | @posts.route("/post/<pid>", methods=["GET"]) |
nothing calls this directly
no test coverage detected