From 721bf7e61a5e6510fc78abc4197e82c7becfe8ca Mon Sep 17 00:00:00 2001 From: jaina heartles Date: Mon, 14 Nov 2022 20:25:59 -0800 Subject: [PATCH] Rename follower/followee --- src/api/lib.zig | 4 ++-- src/api/services/follows.zig | 26 +++++++++++++------------- src/api/services/notes.zig | 2 +- src/main/migrations.zig | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/api/lib.zig b/src/api/lib.zig index 008c4ee..ab19097 100644 --- a/src/api/lib.zig +++ b/src/api/lib.zig @@ -461,7 +461,7 @@ fn ApiConn(comptime DbConn: type) type { 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; + all_args.followee_id = user_id; const result = try services.follows.query(self.db, all_args, self.arena.allocator()); return FollowerQueryResult{ .items = result.items, @@ -472,7 +472,7 @@ fn ApiConn(comptime DbConn: type) type { pub fn queryFollowing(self: *Self, user_id: Uuid, args: FollowingQueryArgs) !FollowingQueryResult { var all_args = std.mem.zeroInit(services.follows.QueryArgs, args); - all_args.follower_id = user_id; + all_args.followed_by_id = user_id; const result = try services.follows.query(self.db, all_args, self.arena.allocator()); return FollowingQueryResult{ .items = result.items, diff --git a/src/api/services/follows.zig b/src/api/services/follows.zig index e7a431a..dc4f5c7 100644 --- a/src/api/services/follows.zig +++ b/src/api/services/follows.zig @@ -10,21 +10,21 @@ const DateTime = util.DateTime; pub const Follow = struct { id: Uuid, - follower_id: Uuid, - following_id: Uuid, + followed_by_id: Uuid, + followee_id: Uuid, created_at: DateTime, }; -pub fn create(db: anytype, follower_id: Uuid, following_id: Uuid, alloc: std.mem.Allocator) !void { - if (Uuid.eql(follower_id, following_id)) return error.SelfFollow; +pub fn create(db: anytype, followed_by_id: Uuid, followee_id: Uuid, alloc: std.mem.Allocator) !void { + if (Uuid.eql(followed_by_id, followee_id)) return error.SelfFollow; const now = DateTime.now(); const id = Uuid.randV4(util.getThreadPrng()); db.insert("follow", .{ .id = id, - .follower_id = follower_id, - .following_id = following_id, + .followed_by_id = followed_by_id, + .followee_id = followee_id, .created_at = now, }, alloc) catch |err| return switch (err) { error.ForeignKeyViolation => error.NotFound, @@ -46,8 +46,8 @@ pub const QueryArgs = struct { max_items: usize = 20, - follower_id: ?Uuid = null, - following_id: ?Uuid = null, + followed_by_id: ?Uuid = null, + followee_id: ?Uuid = null, order_by: OrderBy = .created_at, @@ -75,13 +75,13 @@ pub fn query(db: anytype, args: QueryArgs, alloc: std.mem.Allocator) !QueryResul defer builder.deinit(); try builder.appendSlice( - \\SELECT follow.id, follow.follower_id, follow.following_id, follow.created_at + \\SELECT follow.id, follow.followed_by_id, follow.followee_id, follow.created_at \\FROM follow \\ ); - if (args.follower_id != null) try builder.andWhere("follow.follower_id = $1"); - if (args.following_id != null) try builder.andWhere("follow.following_id = $2"); + if (args.followed_by_id != null) try builder.andWhere("follow.followed_by_id = $1"); + if (args.followee_id != null) try builder.andWhere("follow.followee_id = $2"); if (args.prev != null) { try builder.andWhere("(follow.id, follow.created_at)"); @@ -101,8 +101,8 @@ pub fn query(db: anytype, args: QueryArgs, alloc: std.mem.Allocator) !QueryResul const max_items = if (args.max_items > max_max_items) max_max_items else args.max_items; const query_args = .{ - args.follower_id, - args.following_id, + args.followed_by_id, + args.followee_id, if (args.prev) |p| p.id else null, if (args.prev) |p| p.order_val else null, max_items, diff --git a/src/api/services/notes.zig b/src/api/services/notes.zig index ad817a8..086a85a 100644 --- a/src/api/services/notes.zig +++ b/src/api/services/notes.zig @@ -98,7 +98,7 @@ 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 + \\ follow.followed_by_id = $7 AND follow.followee_id = note.author_id \\ ); diff --git a/src/main/migrations.zig b/src/main/migrations.zig index b35d4ee..89a63d3 100644 --- a/src/main/migrations.zig +++ b/src/main/migrations.zig @@ -195,12 +195,12 @@ const migrations: []const Migration = &.{ \\CREATE TABLE follow( \\ id UUID NOT NULL PRIMARY KEY, \\ - \\ follower_id UUID NOT NULL, - \\ following_id UUID NOT NULL, + \\ followed_by_id UUID NOT NULL, + \\ followee_id UUID NOT NULL, \\ \\ created_at TIMESTAMPTZ NOT NULL, \\ - \\ UNIQUE(follower_id, following_id) + \\ UNIQUE(followed_by_id, followee_id) \\); , .down = "DROP TABLE follow",