[backend/web] Add "likes" endpoint
This commit is contained in:
parent
9b07868a60
commit
3a4738d1fd
1 changed files with 24 additions and 0 deletions
|
@ -4,6 +4,7 @@ using System.Net;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using AsyncKeyedLock;
|
using AsyncKeyedLock;
|
||||||
using Iceshrimp.Backend.Controllers.Shared.Attributes;
|
using Iceshrimp.Backend.Controllers.Shared.Attributes;
|
||||||
|
using Iceshrimp.Backend.Controllers.Shared.Schemas;
|
||||||
using Iceshrimp.Backend.Controllers.Web.Renderers;
|
using Iceshrimp.Backend.Controllers.Web.Renderers;
|
||||||
using Iceshrimp.Backend.Core.Database;
|
using Iceshrimp.Backend.Core.Database;
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
@ -212,6 +213,29 @@ public class NoteController(
|
||||||
return new ValueResponse(success ? --note.LikeCount : note.LikeCount);
|
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")]
|
[HttpPost("{id}/renote")]
|
||||||
[Authenticate]
|
[Authenticate]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
|
|
Loading…
Add table
Reference in a new issue