divan/DiwanRazor/Pages/Quotes.cshtml.cs
Anas Rashid 020b010483 Urdu public pages, batch 2 (#2): auth, errors, map, FAQ, similar poems, people pages, page titles
- translate remaining public views and page-model strings (titles, messages, relation names)
- Urdu stopword list for word-frequency stats (replaces Persian list)
- error pages: drop list of alternative Ganjoor services

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 00:22:09 +02:00

89 lines
3.5 KiB
C#

using DiwanRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OutputCaching;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using RMuseum.Models.Diwan.ViewModels;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
namespace DiwanRazor.Pages
{
[OutputCache(PolicyName = "DiwanPublicPage")]
public class QuotesModel : LoginPartialEnabledPageModel
{
private readonly PoetCacheService _poetCache;
public QuotesModel(HttpClient httpClient, IConfiguration configuration, PoetCacheService poetCache) : base(httpClient, configuration)
{
_poetCache = poetCache;
}
public string LastError { get; set; }
public List<DiwanPoetViewModel> Poets { get; set; }
public DiwanPoetViewModel Poet { get; set; }
public List<DiwanQuotedPoemViewModel> ClaimedQuotes { get; set; }
public List<DiwanQuotedPoemViewModel> Quotes { get; set; }
public async Task<IActionResult> OnGetAsync()
{
var maintenanceResult = TryGetMaintenanceModeResult();
if (maintenanceResult != null)
{
return maintenanceResult;
}
InitializeCommonPageState();
var (poetsOk, poets, poetsError) = await _poetCache.GetPoetsAsync(EditorCacheBypass);
if (!poetsOk)
{
LastError = poetsError;
return Page();
}
Poets = poets;
if (!string.IsNullOrEmpty(Request.Query["p"]))
{
// Fetched by URL slug rather than id, and returns the "complete" poet shape rather
// than the list shape - different enough from PoetCacheService's GetPoetAsync(id)
// that it stays a direct call here rather than being folded into that service.
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/diwan/poet?url=/{Request.Query["p"]}");
if (!response.IsSuccessStatusCode)
{
LastError = await ReadErrorMessageAsync(response);
return Page();
}
Poet = JObject.Parse(await response.Content.ReadAsStringAsync()).ToObject<DiwanPoetCompleteViewModel>().Poet;
Poet.ImageUrl = $"{APIRoot.InternetUrl}{Poet.ImageUrl}";
}
var url = $"{APIRoot.Url}/api/diwan/quoted?published=true";
if (Poet != null)
{
url += $"&poetId={Poet.Id}";
}
var responseQuotes = await _httpClient.GetAsync(url + "&claimed=false");
if (!responseQuotes.IsSuccessStatusCode)
{
LastError = await ReadErrorMessageAsync(responseQuotes);
return Page();
}
Quotes = JArray.Parse(await responseQuotes.Content.ReadAsStringAsync()).ToObject<List<DiwanQuotedPoemViewModel>>();
var responseClaimedQuotes = await _httpClient.GetAsync(url + "&claimed=true");
if (!responseClaimedQuotes.IsSuccessStatusCode)
{
LastError = await ReadErrorMessageAsync(responseClaimedQuotes);
return Page();
}
ClaimedQuotes = JArray.Parse(await responseClaimedQuotes.Content.ReadAsStringAsync()).ToObject<List<DiwanQuotedPoemViewModel>>();
ViewData["Title"] = Poet == null ? "شعرا کے اقتباسات" : $"اقتباسات اور متعلقہ اشعار {Poet.Nickname}";
return Page();
}
}
}