using Dpz.Core.EnumLibrary;

namespace Dpz.Core.Web.Controllers;

public class MumbleController(IMumbleService mumbleService) : Controller
{
    public async Task<IActionResult> Index(
        int pageIndex = 1,
        int pageSize = 10,
        CancellationToken cancellationToken = default
    )
    {
        this.SetTitle("日常碎碎念");
        ViewBag.Menu = MenuItem.Mumble;
        var list = await mumbleService.GetPagesAsync(
            pageIndex,
            pageSize,
            cancellationToken: cancellationToken
        );
        var data = await mumbleService.GetHistoryMumblesAsync(5, cancellationToken);
        return View(new MumbleIndexModel(list, data));
    }

    [HttpPost]
    public async Task<IActionResult> Like(string id, CancellationToken cancellationToken)
    {
        var talk = await mumbleService.LikeAsync(id, cancellationToken);
        return Json(new ResultInfo(talk?.Like));
    }

    [HttpGet]
    public async Task<IActionResult> Comment(
        string id = "",
        CancellationToken cancellationToken = default
    )
    {
        var talk = await mumbleService.FindAsync(id, cancellationToken);
        if (talk == null)
        {
            return NotFound();
        }

        this.SetTitle("碎碎念回复");
        ViewBag.Menu = MenuItem.Mumble;
        return View(talk);
    }
}
评论加载中...