Add unfollow endpoint
This commit is contained in:
parent
4e85c0225b
commit
252c12403a
4 changed files with 32 additions and 0 deletions
|
@ -492,6 +492,11 @@ fn ApiConn(comptime DbConn: type) type {
|
||||||
defer util.deepFree(self.arena.allocator(), result);
|
defer util.deepFree(self.arena.allocator(), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unfollow(self: *Self, followee: Uuid) !void {
|
||||||
|
const result = try services.follows.delete(self.db, self.user_id orelse return error.NoToken, followee, self.arena.allocator());
|
||||||
|
defer util.deepFree(self.arena.allocator(), result);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn getClusterMeta(self: *Self) !ClusterMeta {
|
pub fn getClusterMeta(self: *Self) !ClusterMeta {
|
||||||
return try self.db.queryRow(
|
return try self.db.queryRow(
|
||||||
ClusterMeta,
|
ClusterMeta,
|
||||||
|
|
|
@ -33,6 +33,17 @@ pub fn create(db: anytype, followed_by_id: Uuid, followee_id: Uuid, alloc: std.m
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete(db: anytype, followed_by_id: Uuid, followee_id: Uuid, alloc: std.mem.Allocator) !void {
|
||||||
|
// TODO: Measure count and report success
|
||||||
|
db.exec(
|
||||||
|
\\DELETE FROM follow
|
||||||
|
\\WHERE followed_by_id = $1 AND followee_id = $2
|
||||||
|
,
|
||||||
|
.{ followed_by_id, followee_id },
|
||||||
|
alloc,
|
||||||
|
) catch return error.DatabaseFailure;
|
||||||
|
}
|
||||||
|
|
||||||
const max_max_items = 100;
|
const max_max_items = 100;
|
||||||
|
|
||||||
pub const QueryArgs = struct {
|
pub const QueryArgs = struct {
|
||||||
|
|
|
@ -50,6 +50,7 @@ const routes = .{
|
||||||
timelines.local,
|
timelines.local,
|
||||||
timelines.home,
|
timelines.home,
|
||||||
follows.create,
|
follows.create,
|
||||||
|
follows.delete,
|
||||||
follows.query_followers,
|
follows.query_followers,
|
||||||
follows.query_following,
|
follows.query_following,
|
||||||
} ++ web.routes;
|
} ++ web.routes;
|
||||||
|
|
|
@ -19,6 +19,21 @@ pub const create = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const delete = struct {
|
||||||
|
pub const method = .DELETE;
|
||||||
|
pub const path = "/api/v0/users/:id/follow";
|
||||||
|
|
||||||
|
pub const Args = struct {
|
||||||
|
id: Uuid,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
||||||
|
try srv.unfollow(req.args.id);
|
||||||
|
|
||||||
|
try res.json(.ok, .{});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
pub const query_followers = struct {
|
pub const query_followers = struct {
|
||||||
pub const method = .GET;
|
pub const method = .GET;
|
||||||
pub const path = "/api/v0/users/:id/followers";
|
pub const path = "/api/v0/users/:id/followers";
|
||||||
|
|
Loading…
Reference in a new issue