Implement projectable GetId for UserGroup

This commit is contained in:
Jordan Dominion
2025-08-17 17:26:32 -04:00
parent 16b08b839f
commit 97435c68f0
2 changed files with 27 additions and 0 deletions
@@ -33,6 +33,16 @@ namespace Tgstation.Server.Host.Authority
[TgsAuthorize(AdministrationRights.ReadUsers)]
RequirementsGated<AuthorityResponse<UserGroup>> GetId(long id, bool includeJoins, CancellationToken cancellationToken);
/// <summary>
/// Gets the <see cref="UserGroup"/> with a given <paramref name="id"/>.
/// </summary>
/// <typeparam name="TResult">The result type after projection.</typeparam>
/// <param name="id">The <see cref="Api.Models.EntityId.Id"/> of the <see cref="UserGroup"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="RequirementsGated{TResult}"/> <see cref="Projectable{TQueried, TResult}"/> <see cref="User"/> for <typeparamref name="TResult"/>.</returns>
RequirementsGated<Projectable<UserGroup, TResult>> GetId<TResult>(long id, CancellationToken cancellationToken)
where TResult : notnull;
/// <summary>
/// Gets all registered <see cref="UserGroup"/>s.
/// </summary>
@@ -111,6 +111,23 @@ namespace Tgstation.Server.Host.Authority
return new AuthorityResponse<UserGroup>(userGroup);
});
/// <inheritdoc />
public RequirementsGated<Projectable<UserGroup, TResult>> GetId<TResult>(long id, CancellationToken cancellationToken)
where TResult : notnull
=> new(
() => Flag(AdministrationRights.ReadUsers),
() => Projectable<UserGroup, TResult>.Create(
QueryableImpl(true)
.Where(x => x.Id == id),
projectable =>
{
if (projectable == null)
return Gone<TResult>();
return new AuthorityResponse<TResult>(projectable.Result);
},
cancellationToken));
/// <inheritdoc />
public RequirementsGated<Projectable<UserGroup, TResult>> Read<TResult>(CancellationToken cancellationToken)
where TResult : notnull