diff --git a/GanjooRazor/GanjooRazor.csproj b/GanjooRazor/GanjooRazor.csproj index cf5944e5..52211c15 100644 --- a/GanjooRazor/GanjooRazor.csproj +++ b/GanjooRazor/GanjooRazor.csproj @@ -4,10 +4,6 @@ net5.0-windows - - - - diff --git a/GanjooRazor/Pages/Index.cshtml.cs b/GanjooRazor/Pages/Index.cshtml.cs index 2a3525a0..d777d6f6 100644 --- a/GanjooRazor/Pages/Index.cshtml.cs +++ b/GanjooRazor/Pages/Index.cshtml.cs @@ -12,8 +12,10 @@ using RMuseum.Models.Auth.Memory; using RMuseum.Models.Ganjoor; using RMuseum.Models.Ganjoor.ViewModels; using RMuseum.Models.GanjoorAudio.ViewModels; +using RMuseum.Services; using RSecurityBackend.Models.Auth.Memory; using RSecurityBackend.Models.Auth.ViewModels; +using RSecurityBackend.Services; using System; using System.Collections.Generic; using System.Linq; @@ -35,7 +37,14 @@ namespace GanjooRazor.Pages /// /// IMemoryCache /// - protected readonly IMemoryCache _memoryCache; + private readonly IMemoryCache _memoryCache; + + /// + /// IAppUserService instance + /// + private readonly IAppUserService _appUserService; + + private readonly IGanjoorService _ganjoorService; /// /// HttpClient instance @@ -47,10 +56,15 @@ namespace GanjooRazor.Pages /// /// /// - public IndexModel(IConfiguration configuration, IMemoryCache memoryCache, HttpClient httpClient) + /// + /// + /// + public IndexModel(IConfiguration configuration, IMemoryCache memoryCache, IAppUserService appUserService, IGanjoorService ganjoorService, HttpClient httpClient) { _configuration = configuration; _memoryCache = memoryCache; + _appUserService = appUserService; + _ganjoorService = ganjoorService; _httpClient = httpClient; } diff --git a/GanjooRazor/Pages/_HashiehaPage.cshtml.cs b/GanjooRazor/Pages/_HashiehaPage.cshtml.cs index d272be07..fa97f519 100644 --- a/GanjooRazor/Pages/_HashiehaPage.cshtml.cs +++ b/GanjooRazor/Pages/_HashiehaPage.cshtml.cs @@ -1,14 +1,10 @@ using DNTPersianUtils.Core; using Microsoft.AspNetCore.Mvc.RazorPages; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using RMuseum.Models.Auth.ViewModel; using RMuseum.Models.Ganjoor.ViewModels; +using RSecurityBackend.Models.Auth.ViewModels; using RSecurityBackend.Models.Generic; using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; using System.Threading.Tasks; namespace GanjooRazor.Pages @@ -27,15 +23,22 @@ namespace GanjooRazor.Pages pageNumber = int.Parse(Request.Query["page"]); } - string url = $"{APIRoot.Url}/api/ganjoor/comments?PageNumber={pageNumber}&PageSize=20"; + string filterUserId = Request.Query["userid"]; string htmlText = ""; if (!string.IsNullOrEmpty(filterUserId)) { - var responseUserProfile = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/user/profile/{filterUserId}"); - responseUserProfile.EnsureSuccessStatusCode(); + RServiceResult userInfo = await _appUserService.GetUserInformation(Guid.Parse(filterUserId)); - GanjoorUserPublicProfile profile = JsonConvert.DeserializeObject(await responseUserProfile.Content.ReadAsStringAsync()); + GanjoorUserPublicProfile profile = new GanjoorUserPublicProfile() + { + Id = (Guid)userInfo.Result.Id, + NickName = userInfo.Result.NickName, + Bio = userInfo.Result.Bio, + Website = userInfo.Result.Website, + RImageId = userInfo.Result.RImageId + }; + ViewData["Title"] = $"گنجور » حاشیه‌های {profile.NickName}"; @@ -61,24 +64,21 @@ namespace GanjooRazor.Pages htmlText += $"
{Environment.NewLine}"; - url += $"&filterUserId={filterUserId}"; + } - - - var response = await _httpClient.GetAsync(url); - - if (!response.IsSuccessStatusCode) + var commentsRes = await _ganjoorService.GetRecentComments(new PagingParameterModel() { - LastError = await response.Content.ReadAsStringAsync(); - return; - } + PageNumber = pageNumber, + PageSize = 20 + }, + string.IsNullOrEmpty(filterUserId) ? Guid.Empty : Guid.Parse(filterUserId), true); - response.EnsureSuccessStatusCode(); + PaginationMetadata paginationMetadata = commentsRes.Result.PagingMeta; + GanjoorCommentFullViewModel[] comments = commentsRes.Result.Items; - - foreach (var comment in JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject>()) + foreach (var comment in comments) { htmlText += $"
{comment.HtmlComment}{Environment.NewLine}" + $"

{comment.AuthorName} در {comment.CommentDate.ToFriendlyPersianDateTextify()} دربارهٔ {comment.Poem.Title}" + @@ -87,42 +87,36 @@ namespace GanjooRazor.Pages htmlText += "

"; - string paginnationMetadata = response.Headers.GetValues("paging-headers").FirstOrDefault(); - if (!string.IsNullOrEmpty(paginnationMetadata)) + string queryFilterUserId = string.IsNullOrEmpty(filterUserId) ? "" : $"&userid={filterUserId}"; + + if (paginationMetadata.totalPages > 1) { - PaginationMetadata paginationMetadata = JsonConvert.DeserializeObject(paginnationMetadata); + GanjoorPage.Title += $" - صفحهٔ {pageNumber.ToPersianNumbers()}"; + ViewData["Title"] += $" - صفحهٔ {pageNumber.ToPersianNumbers()}"; - string queryFilterUserId = string.IsNullOrEmpty(filterUserId) ? "" : $"&userid={filterUserId}"; - - if (paginationMetadata.totalPages > 1) + if (paginationMetadata.currentPage > 3) { - GanjoorPage.Title += $" - صفحهٔ {pageNumber.ToPersianNumbers()}"; - ViewData["Title"] += $" - صفحهٔ {pageNumber.ToPersianNumbers()}"; - - if (paginationMetadata.currentPage > 3) + htmlText += $"[صفحهٔ اول] …"; + } + for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++) + { + if (i >= 1 && i <= paginationMetadata.totalPages) { - htmlText += $"[صفحهٔ اول] …"; - } - for (int i = (paginationMetadata.currentPage - 2); i <= (paginationMetadata.currentPage + 2); i++) - { - if (i >= 1 && i <= paginationMetadata.totalPages) + htmlText += " ["; + if (i == paginationMetadata.currentPage) { - htmlText += " ["; - if (i == paginationMetadata.currentPage) - { - htmlText += i.ToPersianNumbers(); - } - else - { - htmlText += $"{i.ToPersianNumbers()}"; - } - htmlText += "] "; + htmlText += i.ToPersianNumbers(); } + else + { + htmlText += $"{i.ToPersianNumbers()}"; + } + htmlText += "] "; } - if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2)) - { - htmlText += $"… [صفحهٔ آخر]"; - } + } + if (paginationMetadata.totalPages > (paginationMetadata.currentPage + 2)) + { + htmlText += $"… [صفحهٔ آخر]"; } }