Build / Build (push) Successful in 35s
All 384 routes, the Mastodon API, the client API and the frozen federation paths, are read from one class with one nested class per controller. Their values are unchanged, checked one by one against the old literals; decePubClient keeps its own APIs class. Checked against GoToSocial in the pasture: 64 passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
47 lines
1.7 KiB
C#
47 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using PrivaPub.Api.Mastodon.Infrastructure;
|
|
using PrivaPub.Api.Mastodon.Mappers;
|
|
using PrivaPub.Domain.Privacy;
|
|
using PrivaPub.Domain.Statuses;
|
|
using PrivaPub.Models.Post;
|
|
using PrivaPub.StaticServices;
|
|
|
|
using PostEntity = PrivaPub.Models.Post.Post;
|
|
|
|
namespace PrivaPub.Api.Mastodon.Controllers
|
|
{
|
|
public class PollsController(
|
|
DbEntities dbEntities,
|
|
MastodonMapper mapper,
|
|
IPollService pollService) : MastodonController
|
|
{
|
|
[HttpGet(ApiPaths.Polls.GET_M_Get), Scope("read:statuses", requiresUser: false), AllowAnonymous]
|
|
public async Task<IActionResult> Get(string id, CancellationToken token)
|
|
{
|
|
var post = await Visible(id, token);
|
|
return post?.Poll == default ? NotFoundError() : Json(mapper.Poll(post, MyId, await pollService.OwnVotes(post.ID, MyId, token)));
|
|
}
|
|
|
|
[HttpPost(ApiPaths.Polls.POST_M_Vote), Scope("write:statuses")]
|
|
public async Task<IActionResult> Vote(string id, CancellationToken token)
|
|
{
|
|
var post = await Visible(id, token);
|
|
if (post?.Poll == default)
|
|
return NotFoundError();
|
|
var choices = Params.List("choices").Select(c => int.TryParse(c, out var index) ? index : -1).ToList();
|
|
var outcome = await pollService.Vote(Me, post, choices, token);
|
|
if (!outcome.Ok)
|
|
return Error(outcome.Status, outcome.Error);
|
|
return Json(mapper.Poll(outcome.Post, MyId, await pollService.OwnVotes(post.ID, MyId, token)));
|
|
}
|
|
|
|
async Task<PostEntity> Visible(string id, CancellationToken token)
|
|
{
|
|
var post = await dbEntities.Posts.Match(p => p.ID == id && !p.DeletedAt.HasValue).ExecuteFirstAsync(token);
|
|
return post != default && post.Visibility != PostVisibility.LocalGeo && await VisibilityPolicy.CanSee(post, MyId, token) ? post : default;
|
|
}
|
|
}
|
|
}
|