Make REST UserGroups by ID use Projectable

This commit is contained in:
Jordan Dominion
2025-08-17 20:19:16 -04:00
parent 62d7e4f56c
commit ee16ff44db
2 changed files with 41 additions and 1 deletions
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Response;
namespace Tgstation.Server.Host.Controllers.Transformers
{
/// <summary>
/// <see cref="Models.ITransformer{TInput, TOutput}"/> for <see cref="Models.UserGroup"/>s to <see cref="UserGroupResponse"/>s.
/// </summary>
sealed class UserGroupResponseTransformer : Models.TransformerBase<Models.UserGroup, UserGroupResponse>
{
/// <summary>
/// Initializes a new instance of the <see cref="UserGroupResponseTransformer"/> class.
/// </summary>
public UserGroupResponseTransformer()
: base(
BuildSubProjection<
Models.PermissionSet,
IEnumerable<Models.User>,
PermissionSet,
List<UserName>,
PermissionSetTransformer,
Models.CollectionTransformer<Models.User, UserName, UserNameTransformer>>(
(model, permissionSet, users) => new UserGroupResponse
{
Id = model.Id,
Name = model.Name,
PermissionSet = permissionSet,
Users = users,
},
model => model.PermissionSet,
model => model.Users))
{
}
}
}
@@ -13,6 +13,7 @@ using Tgstation.Server.Api.Models.Request;
using Tgstation.Server.Api.Models.Response;
using Tgstation.Server.Host.Authority;
using Tgstation.Server.Host.Controllers.Results;
using Tgstation.Server.Host.Controllers.Transformers;
using Tgstation.Server.Host.Database;
using Tgstation.Server.Host.Models;
using Tgstation.Server.Host.Security;
@@ -129,7 +130,9 @@ namespace Tgstation.Server.Host.Controllers
[ProducesResponseType(typeof(UserGroupResponse), 200)]
[ProducesResponseType(typeof(ErrorMessageResponse), 410)]
public ValueTask<IActionResult> GetId(long id, CancellationToken cancellationToken)
=> userGroupAuthority.InvokeTransformable<UserGroup, UserGroupResponse>(this, authority => authority.GetId(id, true, cancellationToken));
=> userGroupAuthority.InvokeTransformable<UserGroup, UserGroupResponse, UserGroupResponseTransformer>(
this,
authority => authority.GetId<UserGroupResponse>(id, cancellationToken));
/// <summary>
/// Lists all <see cref="UserGroup"/>s.