mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-22 04:27:19 +01:00
Clean up GraphQL username retrieval
This commit is contained in:
@@ -27,19 +27,14 @@ namespace Tgstation.Server.Host.GraphQL.Types
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="ValueTask"/> resulting in the queried <see cref="UserName"/>, if present.</returns>
|
||||
[TgsGraphQLAuthorize]
|
||||
public static async ValueTask<UserName?> GetUserName(
|
||||
public static ValueTask<UserName?> GetUserName(
|
||||
long id,
|
||||
[Service] IGraphQLAuthorityInvoker<IUserAuthority> userAuthority,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(userAuthority);
|
||||
var user = await userAuthority.InvokeTransformable<Models.User, User, UserGraphQLTransformer>(
|
||||
return userAuthority.InvokeTransformableAllowMissing<Models.User, UserName, UserNameGraphQLTransformer>(
|
||||
authority => authority.GetId(id, false, true, cancellationToken));
|
||||
|
||||
if (user == null)
|
||||
return null;
|
||||
|
||||
return new UserName(user);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,5 +46,12 @@ namespace Tgstation.Server.Host.GraphQL.Types
|
||||
: base(copy)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserName"/> class.
|
||||
/// </summary>
|
||||
public UserName()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace Tgstation.Server.Host.Models.Transformers
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="ITransformer{TInput, TOutput}"/> for <see cref="GraphQL.Types.UserName"/>s.
|
||||
/// </summary>
|
||||
sealed class UserNameGraphQLTransformer : TransformerBase<User, GraphQL.Types.UserName>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserNameGraphQLTransformer"/> class.
|
||||
/// </summary>
|
||||
public UserNameGraphQLTransformer()
|
||||
: base(model => new GraphQL.Types.UserName
|
||||
{
|
||||
Id = model.Id!.Value,
|
||||
Name = model.Name!,
|
||||
})
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ namespace Tgstation.Server.Host.Models
|
||||
/// <inheritdoc cref="Api.Models.Internal.UserModelBase" />
|
||||
public sealed class User : Api.Models.Internal.UserModelBase,
|
||||
ILegacyApiTransformable<UserResponse>,
|
||||
IApiTransformable<User, GraphQL.Types.User, UserGraphQLTransformer>
|
||||
IApiTransformable<User, GraphQL.Types.User, UserGraphQLTransformer>,
|
||||
IApiTransformable<User, GraphQL.Types.UserName, UserNameGraphQLTransformer>
|
||||
{
|
||||
/// <summary>
|
||||
/// Username used when creating jobs automatically.
|
||||
|
||||
Reference in New Issue
Block a user