Create GetMemberByDisplayName()

This commit is contained in:
Fiona 2020-06-22 21:06:14 +10:00
parent 6fa76e85c4
commit 2de6d399ce
2 changed files with 12 additions and 0 deletions

View File

@ -149,6 +149,12 @@ namespace PluralKit.Core {
/// </para> /// </para>
/// <returns>The <see cref="PKMember"/> with the given name, or null if no member was found.</returns> /// <returns>The <see cref="PKMember"/> with the given name, or null if no member was found.</returns>
Task<PKMember> GetMemberByName(PKSystem system, string name); Task<PKMember> GetMemberByName(PKSystem system, string name);
/// <summary>
/// Gets a member by its display name within one system.
/// </summary>
/// <returns>The <see cref="PKMember"/> with the given name, or null if no member was found.</returns>
Task<PKMember> GetMemberByDisplayName(PKSystem system, string name);
/// <summary> /// <summary>
/// Gets all members inside a given system. /// Gets all members inside a given system.

View File

@ -141,6 +141,12 @@ namespace PluralKit.Core {
return await conn.QueryFirstOrDefaultAsync<PKMember>("select * from members where lower(name) = lower(@Name) and system = @SystemID", new { Name = name, SystemID = system.Id }); return await conn.QueryFirstOrDefaultAsync<PKMember>("select * from members where lower(name) = lower(@Name) and system = @SystemID", new { Name = name, SystemID = system.Id });
} }
public async Task<PKMember> GetMemberByDisplayName(PKSystem system, string name) {
// QueryFirst, since members can (in rare cases) share display names
using (var conn = await _conn.Obtain())
return await conn.QueryFirstOrDefaultAsync<PKMember>("select * from members where lower(display_name) = lower(@Name) and system = @SystemID", new { Name = name, SystemID = system.Id });
}
public IAsyncEnumerable<PKMember> GetSystemMembers(PKSystem system, bool orderByName) public IAsyncEnumerable<PKMember> GetSystemMembers(PKSystem system, bool orderByName)
{ {
var sql = "select * from members where system = @SystemID"; var sql = "select * from members where system = @SystemID";