[backend/api] Add instance staff endpoint
This commit is contained in:
parent
b6dddd9439
commit
28b3b56646
2 changed files with 50 additions and 0 deletions
40
Iceshrimp.Backend/Controllers/Web/InstanceController.cs
Normal file
40
Iceshrimp.Backend/Controllers/Web/InstanceController.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System.Net;
|
||||
using System.Net.Mime;
|
||||
using Iceshrimp.Backend.Controllers.Shared.Attributes;
|
||||
using Iceshrimp.Backend.Controllers.Web.Renderers;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Extensions;
|
||||
using Iceshrimp.Backend.Core.Middleware;
|
||||
using Iceshrimp.Shared.Schemas.Web;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
|
||||
namespace Iceshrimp.Backend.Controllers.Web;
|
||||
|
||||
[ApiController]
|
||||
[EnableRateLimiting("sliding")]
|
||||
[Route("/api/iceshrimp/instance")]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
public class InstanceController(DatabaseContext db, UserRenderer userRenderer) : ControllerBase
|
||||
{
|
||||
[HttpGet("staff")]
|
||||
[Authenticate]
|
||||
[Authorize]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
public async Task<StaffResponse> GetStaff()
|
||||
{
|
||||
var admins = db.Users
|
||||
.Where(p => p.IsAdmin == true)
|
||||
.OrderBy(p => p.UsernameLower);
|
||||
var adminList = await userRenderer.RenderMany(admins)
|
||||
.ToListAsync();
|
||||
|
||||
var moderators = db.Users
|
||||
.Where(p => p.IsAdmin == false && p.IsModerator == true)
|
||||
.OrderBy(p => p.UsernameLower);
|
||||
var moderatorList = await userRenderer.RenderMany(moderators)
|
||||
.ToListAsync();
|
||||
|
||||
return new StaffResponse { Admins = adminList, Moderators = moderatorList };
|
||||
}
|
||||
}
|
10
Iceshrimp.Shared/Schemas/Web/InstanceResponse.cs
Normal file
10
Iceshrimp.Shared/Schemas/Web/InstanceResponse.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace Iceshrimp.Shared.Schemas.Web;
|
||||
|
||||
// TODO: Instance Response for /api/iceshrimp/instance
|
||||
public class InstanceResponse { }
|
||||
|
||||
public class StaffResponse
|
||||
{
|
||||
public required List<UserResponse> Admins { get; set; }
|
||||
public required List<UserResponse> Moderators { get; set; }
|
||||
}
|
Loading…
Add table
Reference in a new issue