feat(apiv2): database changes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
@@ -23,6 +24,9 @@ namespace PluralKit.Core
|
||||
new { hid = hid.ToLowerInvariant(), System = system }
|
||||
);
|
||||
|
||||
public Task<PKGroup?> GetGroupByGuid(IPKConnection conn, Guid guid) =>
|
||||
conn.QueryFirstOrDefaultAsync<PKGroup?>("select * from groups where uuid = @Uuid", new { Uuid = guid });
|
||||
|
||||
public Task<int> GetGroupMemberCount(IPKConnection conn, GroupId id, PrivacyLevel? privacyFilter = null)
|
||||
{
|
||||
var query = new StringBuilder("select count(*) from group_members");
|
||||
|
@@ -18,6 +18,9 @@ namespace PluralKit.Core
|
||||
new { Hid = hid.ToLower(), System = system }
|
||||
);
|
||||
|
||||
public Task<PKMember?> GetMemberByGuid(IPKConnection conn, Guid guid) =>
|
||||
conn.QuerySingleOrDefaultAsync<PKMember?>("select * from members where uuid = @Uuid", new { Uuid = guid });
|
||||
|
||||
public Task<PKMember?> GetMemberByName(IPKConnection conn, SystemId system, string name) =>
|
||||
conn.QueryFirstOrDefaultAsync<PKMember?>("select * from members where lower(name) = lower(@Name) and system = @SystemID", new { Name = name, SystemID = system });
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -12,7 +13,7 @@ namespace PluralKit.Core
|
||||
{
|
||||
public partial class ModelRepository
|
||||
{
|
||||
public async Task AddSwitch(IPKConnection conn, SystemId system, IReadOnlyCollection<MemberId> members)
|
||||
public async Task<PKSwitch> AddSwitch(IPKConnection conn, SystemId system, IReadOnlyCollection<MemberId> members)
|
||||
{
|
||||
// Use a transaction here since we're doing multiple executed commands in one
|
||||
await using var tx = await conn.BeginTransactionAsync();
|
||||
@@ -38,6 +39,7 @@ namespace PluralKit.Core
|
||||
await tx.CommitAsync();
|
||||
|
||||
_logger.Information("Created {SwitchId} in {SystemId}: {Members}", sw.Id, system, members);
|
||||
return sw;
|
||||
}
|
||||
public async Task EditSwitch(IPKConnection conn, SwitchId switchId, IReadOnlyCollection<MemberId> members)
|
||||
{
|
||||
@@ -95,6 +97,9 @@ namespace PluralKit.Core
|
||||
new { System = system });
|
||||
}
|
||||
|
||||
public Task<PKSwitch> GetSwitchByUuid(IPKConnection conn, Guid uuid) =>
|
||||
conn.QuerySingleOrDefaultAsync<PKSwitch>("select * from switches where uuid = @Uuid", new { Uuid = uuid });
|
||||
|
||||
public async Task<int> GetSwitchCount(IPKConnection conn, SystemId system)
|
||||
{
|
||||
return await conn.QuerySingleAsync<int>("select count(*) from switches where system = @Id", new { Id = system });
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -12,6 +13,9 @@ namespace PluralKit.Core
|
||||
public Task<PKSystem?> GetSystem(IPKConnection conn, SystemId id) =>
|
||||
conn.QueryFirstOrDefaultAsync<PKSystem?>("select * from systems where id = @id", new { id });
|
||||
|
||||
public Task<PKSystem?> GetSystemByGuid(IPKConnection conn, Guid id) =>
|
||||
conn.QueryFirstOrDefaultAsync<PKSystem?>("select * from systems where uuid = @id", new { id });
|
||||
|
||||
public Task<PKSystem?> GetSystemByAccount(IPKConnection conn, ulong accountId) =>
|
||||
conn.QuerySingleOrDefaultAsync<PKSystem?>(
|
||||
"select systems.* from systems, accounts where accounts.system = systems.id and accounts.uid = @Id",
|
||||
@@ -38,9 +42,13 @@ namespace PluralKit.Core
|
||||
return conn.QuerySingleAsync<int>(query.ToString(), new { Id = id });
|
||||
}
|
||||
|
||||
public Task<int> GetSystemGroupCount(IPKConnection conn, SystemId id) =>
|
||||
conn.QuerySingleAsync<int>("select count(*) from groups where system = @System", new { System = id });
|
||||
|
||||
public Task<int> GetSystemGroupCount(IPKConnection conn, SystemId id, PrivacyLevel? privacyFilter = null)
|
||||
{
|
||||
var query = new StringBuilder("select count(*) from groups where system = @Id");
|
||||
if (privacyFilter != null)
|
||||
query.Append($" and visibility = {(int)privacyFilter.Value}");
|
||||
return conn.QuerySingleAsync<int>(query.ToString(), new { Id = id });
|
||||
}
|
||||
public async Task<PKSystem> CreateSystem(IPKConnection conn, string? systemName = null, IPKTransaction? tx = null)
|
||||
{
|
||||
var system = await conn.QuerySingleAsync<PKSystem>(
|
||||
|
Reference in New Issue
Block a user