admin api packaging

This commit is contained in:
Rory&
2025-12-14 23:18:35 +01:00
parent a4527d166a
commit 4534d4dbf5
124 changed files with 2250 additions and 268 deletions
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Spacebar.AdminApi.Extensions;
using Spacebar.AdminApi.Models;
using Spacebar.AdminApi.Services;
using Spacebar.Db.Contexts;
using Spacebar.Db.Models;
using Spacebar.RabbitMqUtilities;
namespace Spacebar.AdminApi.Controllers.Media;
[ApiController]
[Route("/media/user")]
public class UserMediaController(ILogger<UserMediaController> logger, SpacebarDbContext db, RabbitMQService mq, AuthenticationService auth, IServiceProvider sp) : ControllerBase {
[HttpGet("{userId}/attachments")]
public async IAsyncEnumerable<Attachment> GetAttachmentsByUser(string userId) {
(await auth.GetCurrentUser(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
var db2 = sp.CreateScope().ServiceProvider.GetService<SpacebarDbContext>();
var attachments = db.Attachments
// .IgnoreAutoIncludes()
.Where(x => x.Message!.AuthorId == userId)
.AsAsyncEnumerable();
await foreach (var attachment in attachments) {
attachment.Message = await db2.Messages.FindAsync(attachment.MessageId);
// attachment.Message.Author = await db2.Users.FindAsync(attachment.Message.AuthorId);
yield return attachment;
}
}
}