Projects (GanjooRazor -> DivanRazor, GanjoorService.sln -> DivanService.sln), files, folders, classes, namespaces, settings, API routes (/api/divan) and DB tables (Divan*). External addresses (ganjoor.net, github.com/ganjoor) unchanged. Migrations renamed consistently (no pending model changes); requires a fresh database. Upstream RUNNING_LOCALLY/SEMANTIC_SEARCH docs archived unmodified under docs/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.6 KiB
C#
89 lines
3.6 KiB
C#
using DivanRazor.Utils;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.OutputCaching;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json.Linq;
|
|
using RMuseum.Models.Divan.ViewModels;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DivanRazor.Pages
|
|
{
|
|
[OutputCache(PolicyName = "DivanPublicPage")]
|
|
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<DivanPoetViewModel> Poets { get; set; }
|
|
public DivanPoetViewModel Poet { get; set; }
|
|
public List<DivanQuotedPoemViewModel> ClaimedQuotes { get; set; }
|
|
public List<DivanQuotedPoemViewModel> 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/divan/poet?url=/{Request.Query["p"]}");
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
LastError = await ReadErrorMessageAsync(response);
|
|
return Page();
|
|
}
|
|
Poet = JObject.Parse(await response.Content.ReadAsStringAsync()).ToObject<DivanPoetCompleteViewModel>().Poet;
|
|
Poet.ImageUrl = $"{APIRoot.InternetUrl}{Poet.ImageUrl}";
|
|
}
|
|
|
|
var url = $"{APIRoot.Url}/api/divan/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<DivanQuotedPoemViewModel>>();
|
|
|
|
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<DivanQuotedPoemViewModel>>();
|
|
|
|
ViewData["Title"] = Poet == null ? "نقل قولهای شاعران" : $"نقل قولها و شعرهای مرتبط {Poet.Nickname}";
|
|
|
|
return Page();
|
|
}
|
|
}
|
|
}
|