[backend/web] Add "likes" endpoint

This commit is contained in:
Lilian 2024-09-26 21:07:52 +02:00
parent 9b07868a60
commit 3a4738d1fd
No known key found for this signature in database

View file

@ -4,6 +4,7 @@ using System.Net;
using System.Net.Mime;
using AsyncKeyedLock;
using Iceshrimp.Backend.Controllers.Shared.Attributes;
using Iceshrimp.Backend.Controllers.Shared.Schemas;
using Iceshrimp.Backend.Controllers.Web.Renderers;
using Iceshrimp.Backend.Core.Database;
using Iceshrimp.Backend.Core.Database.Tables;
@ -211,6 +212,29 @@ public class NoteController(
return new ValueResponse(success ? --note.LikeCount : note.LikeCount);
}
[HttpGet("{id}/likes")]
[Authenticate]
[Authorize]
[ProducesResults(HttpStatusCode.OK)]
[ProducesErrors(HttpStatusCode.NotFound)]
public async Task<IEnumerable<UserResponse>> GetNoteLikes(string id)
{
var user = HttpContext.GetUser();
var note = await db.Notes
.Where(p => p.Id == id)
.EnsureVisibleFor(user)
.FirstOrDefaultAsync() ??
throw GracefulException.NotFound("Note not found");
var users = await db.NoteLikes
.Where(p => p.Note == note)
.Include(p => p.User.UserProfile)
.Select(p => p.User)
.ToListAsync();
return await userRenderer.RenderMany(users);
}
[HttpPost("{id}/renote")]
[Authenticate]