MCPcopy Create free account
hub / github.com/StarKhan6368/threaddit / get_posts

Function get_posts

backend/threaddit/posts/routes.py:17–43  ·  view source on GitHub ↗
(feed_name)

Source from the content-addressed store, hash-verified

15
16@posts.route("/posts/<feed_name>", methods=["GET"])
17def 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"])

Callers

nothing calls this directly

Calls 2

get_filtersFunction · 0.90
as_dictMethod · 0.45

Tested by

no test coverage detected