2022-11-14 09:03:11 +00:00
|
|
|
const api = @import("api");
|
|
|
|
const util = @import("util");
|
2022-11-15 05:38:08 +00:00
|
|
|
const controller_utils = @import("../../../controllers.zig").helpers;
|
2022-11-14 09:03:11 +00:00
|
|
|
|
|
|
|
const Uuid = util.Uuid;
|
|
|
|
|
|
|
|
pub const create = struct {
|
|
|
|
pub const method = .POST;
|
2022-11-27 01:52:30 +00:00
|
|
|
pub const path = "/users/:id/follow";
|
2022-11-14 09:03:11 +00:00
|
|
|
|
|
|
|
pub const Args = struct {
|
|
|
|
id: Uuid,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
|
|
|
try srv.follow(req.args.id);
|
|
|
|
|
|
|
|
try res.json(.created, .{});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-19 11:33:35 +00:00
|
|
|
pub const delete = struct {
|
|
|
|
pub const method = .DELETE;
|
2022-11-27 01:52:30 +00:00
|
|
|
pub const path = "/users/:id/follow";
|
2022-11-19 11:33:35 +00:00
|
|
|
|
|
|
|
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, .{});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-14 09:03:11 +00:00
|
|
|
pub const query_followers = struct {
|
|
|
|
pub const method = .GET;
|
2022-11-27 01:52:30 +00:00
|
|
|
pub const path = "/users/:id/followers";
|
2022-11-14 09:03:11 +00:00
|
|
|
|
|
|
|
pub const Args = struct {
|
|
|
|
id: Uuid,
|
|
|
|
};
|
|
|
|
|
2023-01-04 19:03:23 +00:00
|
|
|
pub const Query = api.follows.FollowingQueryArgs;
|
2022-11-14 09:03:11 +00:00
|
|
|
|
|
|
|
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
|
|
|
const results = try srv.queryFollowers(req.args.id, req.query);
|
|
|
|
|
2022-11-27 09:59:37 +00:00
|
|
|
try controller_utils.paginate(results, res, req.allocator);
|
2022-11-14 09:03:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const query_following = struct {
|
|
|
|
pub const method = .GET;
|
2022-11-27 01:52:30 +00:00
|
|
|
pub const path = "/users/:id/following";
|
2022-11-14 09:03:11 +00:00
|
|
|
|
|
|
|
pub const Args = struct {
|
|
|
|
id: Uuid,
|
|
|
|
};
|
|
|
|
|
2023-01-04 19:03:23 +00:00
|
|
|
pub const Query = api.follows.FollowerQueryArgs;
|
2022-11-14 09:03:11 +00:00
|
|
|
|
|
|
|
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
|
|
|
const results = try srv.queryFollowing(req.args.id, req.query);
|
|
|
|
|
2022-11-27 09:59:37 +00:00
|
|
|
try controller_utils.paginate(results, res, req.allocator);
|
2022-11-14 09:03:11 +00:00
|
|
|
}
|
|
|
|
};
|