mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-26 14:37:44 +01:00
Make REST UserGroups by ID use Projectable
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user