using Dpz.Core.EnumLibrary;

namespace Dpz.Core.Web.Controllers;

public class SteamController(ISteamGameService steamGameService) : Controller
{
    public async Task<IActionResult> Index()
    {
        this.SetTitle("我的Steam游戏");
        var games = await steamGameService.GetGamesAsync();
        return View(games);
    }

    public async Task<IActionResult> Achievements(int? id = null)
    {
        if (id == null)
        {
            return NotFound();
        }

        var model = await steamGameService.GetGameAsync(id.Value);

        if (model == null)
        {
            return View(null);
        }

        var pageMetaPage = new VmPageMetadata
        {
            Description =
                "游戏成就:" + string.Join(",", model.Achievements.Select(x => x.DisplayName)),
            Keywords = [$"{model.Name},{model.Name}游戏成就"],
            Relations = ["Steam", "Achievements", id.Value.ToString()],
        };
        ViewData["PageMetadata"] = pageMetaPage;
        this.SetTitle($"{model.Name} 成就");
        return View(model);
    }

    [HttpGet, CheckAuthorize(Permissions = Permissions.System)]
    public async Task<IActionResult> ClearCache()
    {
        await steamGameService.RemoveByPrefixAsync();
        return RedirectToAction(nameof(Index));
    }
}
评论加载中...