From 6f1328e508fc046d6a2932c76f67adb700649e37 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 22 May 2025 09:43:58 +0330 Subject: [PATCH] display stats of visits for categories and poems #481 --- GanjooRazor/GanjooRazor.csproj | 1 + .../Models/Kontor/PageVisitsViewModel.cs | 18 ++++++++++ GanjooRazor/Pages/Index.cshtml.cs | 26 ++++++++++++++ GanjooRazor/Pages/_GanjoorPagePartial.cshtml | 30 ++++++++++++++++ GanjooRazor/Pages/_TopVisitsPartial.cshtml | 36 +++++++++++++++++++ GanjooRazor/Pages/_TopVisitsPartial.cshtml.cs | 10 ++++++ GanjooRazor/wwwroot/js/bk.js | 25 +++++++++++++ 7 files changed, 146 insertions(+) create mode 100644 GanjooRazor/Models/Kontor/PageVisitsViewModel.cs create mode 100644 GanjooRazor/Pages/_TopVisitsPartial.cshtml create mode 100644 GanjooRazor/Pages/_TopVisitsPartial.cshtml.cs diff --git a/GanjooRazor/GanjooRazor.csproj b/GanjooRazor/GanjooRazor.csproj index dc05a4cb..82d19056 100644 --- a/GanjooRazor/GanjooRazor.csproj +++ b/GanjooRazor/GanjooRazor.csproj @@ -12,6 +12,7 @@ + diff --git a/GanjooRazor/Models/Kontor/PageVisitsViewModel.cs b/GanjooRazor/Models/Kontor/PageVisitsViewModel.cs new file mode 100644 index 00000000..35e6c502 --- /dev/null +++ b/GanjooRazor/Models/Kontor/PageVisitsViewModel.cs @@ -0,0 +1,18 @@ +namespace KontorService.Models.Reporting.ViewModels +{ + public class PageVisitsViewModel + { + /// + /// url + /// + public string Url { get; set; } + /// + /// title + /// + public string? Title { get; set; } + /// + /// visits + /// + public int Visits { get; set; } + } +} diff --git a/GanjooRazor/Pages/Index.cshtml.cs b/GanjooRazor/Pages/Index.cshtml.cs index daee1227..098b7af2 100644 --- a/GanjooRazor/Pages/Index.cshtml.cs +++ b/GanjooRazor/Pages/Index.cshtml.cs @@ -1,4 +1,5 @@ using GanjooRazor.Utils; +using KontorService.Models.Reporting.ViewModels; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ModelBinding; @@ -1597,6 +1598,31 @@ namespace GanjooRazor.Pages }; } + public async Task OnGetTopVisitsAsync(string url) + { + url = $"https://ganjoor.net/{url}"; + var apiUrl = $"https://track.kntr.ir/api/reporting/toppages/1/ganjoor.net?parentUrl={WebUtility.UrlEncode(url)}&count=20"; + var topVisitsResponse = await _httpClient.GetAsync(apiUrl); + + if (!topVisitsResponse.IsSuccessStatusCode) + { + return null; + } + var topVisits = JsonConvert.DeserializeObject(await topVisitsResponse.Content.ReadAsStringAsync()); + + return new PartialViewResult() + { + ViewName = "_TopVisitsPartial", + ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) + { + Model = new _TopVisitsPartialModel() + { + Visits = topVisits + } + } + }; + } + } } \ No newline at end of file diff --git a/GanjooRazor/Pages/_GanjoorPagePartial.cshtml b/GanjooRazor/Pages/_GanjoorPagePartial.cshtml index 3a1a9d98..edf6f951 100644 --- a/GanjooRazor/Pages/_GanjoorPagePartial.cshtml +++ b/GanjooRazor/Pages/_GanjoorPagePartial.cshtml @@ -269,6 +269,7 @@ } +