[backend/api] Add instance staff endpoint

This commit is contained in:
pancakes 2024-11-13 14:57:04 +10:00 committed by Iceshrimp development
parent b6dddd9439
commit 28b3b56646
2 changed files with 50 additions and 0 deletions

View 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 };
}
}

View 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; }
}