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("clientapi/social"), Authorize(Policy = Policies.IsUser)] public class SocialController( IFollowService follows, IStringLocalizer localizer) : ControllerBase { [HttpPost, Route("/clientapi/follow")] public async Task Follow(FollowForm form, CancellationToken token) => !ModelState.IsValid ? Invalid() : Answer(await follows.Follow(User.GetUserId(), form, token)); [HttpPost, Route("/clientapi/unfollow")] public async Task Unfollow(FollowForm form, CancellationToken token) => !ModelState.IsValid ? Invalid() : Answer(await follows.Unfollow(User.GetUserId(), form, token)); [HttpGet, Route("/clientapi/following")] public async Task 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); } }