Home timeline endpoint
This commit is contained in:
parent
763327292a
commit
81c705d519
4 changed files with 34 additions and 0 deletions
|
@ -446,6 +446,19 @@ fn ApiConn(comptime DbConn: type) type {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn homeTimeline(self: *Self, args: TimelineArgs) !TimelineResult {
|
||||
if (self.user_id == null) return error.NoToken;
|
||||
|
||||
var all_args = std.mem.zeroInit(services.notes.QueryArgs, args);
|
||||
all_args.followed_by = self.user_id;
|
||||
const result = try services.notes.query(self.db, all_args, self.arena.allocator());
|
||||
return TimelineResult{
|
||||
.items = result.items,
|
||||
.prev_page = TimelineArgs.from(result.prev_page),
|
||||
.next_page = TimelineArgs.from(result.next_page),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn queryFollowers(self: *Self, user_id: Uuid, args: FollowerQueryArgs) !FollowerQueryResult {
|
||||
var all_args = std.mem.zeroInit(services.follows.QueryArgs, args);
|
||||
all_args.following_id = user_id;
|
||||
|
|
|
@ -70,6 +70,7 @@ pub const QueryArgs = struct {
|
|||
created_before: ?DateTime = null,
|
||||
created_after: ?DateTime = null,
|
||||
community_id: ?Uuid = null,
|
||||
followed_by: ?Uuid = null,
|
||||
|
||||
prev: ?struct {
|
||||
id: Uuid,
|
||||
|
@ -95,6 +96,12 @@ pub fn query(db: anytype, args: QueryArgs, alloc: std.mem.Allocator) !QueryResul
|
|||
\\
|
||||
);
|
||||
|
||||
if (args.followed_by != null) try builder.appendSlice(
|
||||
\\ JOIN follow ON
|
||||
\\ follow.follower_id = $7 AND follow.following_id = note.author_id
|
||||
\\
|
||||
);
|
||||
|
||||
if (args.created_before != null) try builder.andWhere("note.created_at < $1");
|
||||
if (args.created_after != null) try builder.andWhere("note.created_at > $2");
|
||||
if (args.prev != null) {
|
||||
|
@ -128,6 +135,7 @@ pub fn query(db: anytype, args: QueryArgs, alloc: std.mem.Allocator) !QueryResul
|
|||
prev_id,
|
||||
args.community_id,
|
||||
max_items,
|
||||
args.followed_by,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ const routes = .{
|
|||
streaming.streaming,
|
||||
timelines.global,
|
||||
timelines.local,
|
||||
timelines.home,
|
||||
follows.create,
|
||||
follows.query_followers,
|
||||
follows.query_following,
|
||||
|
|
|
@ -26,3 +26,15 @@ pub const local = struct {
|
|||
try controller_utils.paginate(srv.community, path, results, res, req.allocator);
|
||||
}
|
||||
};
|
||||
|
||||
pub const home = struct {
|
||||
pub const method = .GET;
|
||||
pub const path = "/timelines/home";
|
||||
|
||||
pub const Query = api.TimelineArgs;
|
||||
|
||||
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
||||
const results = try srv.homeTimeline(req.query);
|
||||
try controller_utils.paginate(srv.community, path, results, res, req.allocator);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue