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
37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
using PrivaPub.ClientModels;
|
|
using PrivaPub.ClientModels.Social;
|
|
using PrivaPub.Domain.Social;
|
|
using PrivaPub.Extensions;
|
|
using PrivaPub.Resources;
|
|
|
|
namespace PrivaPub.Controllers.ClientToServer
|
|
{
|
|
[ApiController,
|
|
Route(ApiPaths.Social.Prefix),
|
|
Authorize(Policy = Policies.IsUser)]
|
|
public class SocialController(
|
|
IFollowService follows,
|
|
IStringLocalizer<GenericRes> localizer) : ControllerBase
|
|
{
|
|
[HttpPost, Route(ApiPaths.Social.POST_Follow)]
|
|
public async Task<IActionResult> Follow(FollowForm form, CancellationToken token) =>
|
|
!ModelState.IsValid ? Invalid() : Answer(await follows.Follow(User.GetUserId(), form, token));
|
|
|
|
[HttpPost, Route(ApiPaths.Social.POST_Unfollow)]
|
|
public async Task<IActionResult> Unfollow(FollowForm form, CancellationToken token) =>
|
|
!ModelState.IsValid ? Invalid() : Answer(await follows.Unfollow(User.GetUserId(), form, token));
|
|
|
|
[HttpGet, Route(ApiPaths.Social.GET_Following)]
|
|
public async Task<IActionResult> Following([FromQuery] string avatarId, CancellationToken token) =>
|
|
Answer(await follows.Followings(User.GetUserId(), avatarId, token));
|
|
|
|
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
|
|
|
|
IActionResult Answer(WebResult result) => result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
|
|
}
|
|
}
|