Projects (GanjooRazor -> DiwanRazor, GanjoorService.sln -> DiwanService.sln), files, folders, classes, namespaces, settings, API routes (/api/diwan) and DB tables (Diwan*). 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>
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using RMuseum.Models.Diwan.ViewModels;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DiwanRazor.Pages
|
|
{
|
|
/// <summary>
|
|
/// random couplet (diwan: rendered from our own API instead of upstream's external c.ganjoor.net widget)
|
|
/// </summary>
|
|
public class RandomModel : PageModel
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly HttpClient _httpClient;
|
|
|
|
public RandomModel(IConfiguration configuration, HttpClient httpClient)
|
|
{
|
|
_configuration = configuration;
|
|
_httpClient = httpClient;
|
|
}
|
|
|
|
/// <summary>
|
|
/// random poem, null when the API is unreachable or empty
|
|
/// </summary>
|
|
public DiwanPoemCompleteViewModel Poem { get; set; }
|
|
|
|
public async Task OnGetAsync()
|
|
{
|
|
ViewData["TrackingScript"] = _configuration["TrackingScript"];
|
|
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/diwan/poem/random?poetId=0");
|
|
if (response.IsSuccessStatusCode)
|
|
Poem = JsonConvert.DeserializeObject<DiwanPoemCompleteViewModel>(await response.Content.ReadAsStringAsync());
|
|
}
|
|
}
|
|
}
|