feat: watchlist commands
This commit is contained in:
parent
56af787e57
commit
b56a71e105
4 changed files with 167 additions and 2 deletions
|
|
@ -33,12 +33,43 @@ public class WatchlistRepository(ILogger logger, DatabaseConnection conn)
|
|||
)
|
||||
).ToList();
|
||||
|
||||
public async Task<Watchlist?> GetWatchlistEntryAsync(Snowflake guildId, Snowflake userId) =>
|
||||
public async Task<Watchlist?> GetEntryAsync(Snowflake guildId, Snowflake userId) =>
|
||||
await conn.QueryFirstOrDefaultAsync<Watchlist>(
|
||||
"select * from watchlists where guild_id = @GuildId and user_id = @UserId",
|
||||
new { GuildId = guildId.Value, UserId = userId.Value }
|
||||
);
|
||||
|
||||
public async Task<Watchlist> CreateEntryAsync(
|
||||
Snowflake guildId,
|
||||
Snowflake userId,
|
||||
Snowflake moderatorId,
|
||||
string reason
|
||||
) =>
|
||||
await conn.QueryFirstAsync<Watchlist>(
|
||||
"""
|
||||
insert into watchlists (guild_id, user_id, added_at, moderator_id, reason)
|
||||
values (@GuildId, @UserId, now(), @ModeratorId, @Reason)
|
||||
on conflict (guild_id, user_id) do update
|
||||
set moderator_id = @ModeratorId, added_at = now(), reason = @Reason
|
||||
returning *
|
||||
""",
|
||||
new
|
||||
{
|
||||
GuildId = guildId.Value,
|
||||
UserId = userId.Value,
|
||||
ModeratorId = moderatorId.Value,
|
||||
Reason = reason,
|
||||
}
|
||||
);
|
||||
|
||||
public async Task<bool> RemoveEntryAsync(Snowflake guildId, Snowflake userId) =>
|
||||
(
|
||||
await conn.ExecuteAsync(
|
||||
"delete from watchlists where guild_id = @GuildId and user_id = @UserId",
|
||||
new { GuildId = guildId.Value, UserId = userId.Value }
|
||||
)
|
||||
) != 0;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
conn.Dispose();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue