Further admin api work

This commit is contained in:
Emma [it/its]@Rory&
2025-04-10 17:12:53 +02:00
parent abb1b570a4
commit e1483e9f90
17 changed files with 642 additions and 20 deletions
@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Spacebar.AdminApi.Models;
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, IServiceProvider sp) : ControllerBase {
[HttpGet("{userId}/attachments")]
public async IAsyncEnumerable<Attachment> GetAttachmentsByUser(string userId) {
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;
}
}
}
@@ -146,6 +146,13 @@ public class UserController(ILogger<UserController> logger, SpacebarDbContext db
yield break;
}
user.Data = "{}";
user.Deleted = true;
user.Disabled = true;
user.Rights = 0;
db.Users.Update(user);
await db.SaveChangesAsync();
var factory = new ConnectionFactory {
Uri = new Uri("amqp://guest:guest@127.0.0.1/")
};