refactoring

This commit is contained in:
Hamid Reza Mohammadi 2026-07-13 16:10:41 +03:30
parent b60d798801
commit b3acb99d50
2 changed files with 638 additions and 856 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RMuseum.Models.Ganjoor;
using RMuseum.Models.Ganjoor.ViewModels;
using RMuseum.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@ -15,41 +11,33 @@ namespace GanjooRazor.Pages
{
public partial class IndexModel : LoginPartialEnabledPageModel
{
public async Task<ActionResult> OnGetSimilarPoemsPartialAsync(int poemId, int skip, string prosodyMetre, string rhymeLetters, string poemFullUrl, int sectionIndex)
public async Task<IActionResult> OnGetSimilarPoemsPartialAsync(int poemId, int skip, string prosodyMetre, string rhymeLetters, string poemFullUrl, int sectionIndex)
{
string url = $"{APIRoot.Url}/api/ganjoor/section/{poemId}/{sectionIndex}/related?skip={skip}&itemsCount=21";
var response = await _httpClient.GetAsync(url);
if (!response.IsSuccessStatusCode)
return BadRequest(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
return BadRequest(await ReadErrorMessageAsync(response));
var relatedSections = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorCachedRelatedSection>>();
return new PartialViewResult()
return Partial("_SimiPartialView", new _SimiPartialViewModel()
{
ViewName = "_SimiPartialView",
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
{
Model = new _SimiPartialViewModel()
{
RelatedSections = relatedSections.ToArray(),
Rhythm = prosodyMetre,
RhymeLetters = rhymeLetters,
Skip = skip,
PoemId = poemId,
PoemFullUrl = poemFullUrl,
SectionIndex = sectionIndex
}
}
};
RelatedSections = relatedSections.ToArray(),
Rhythm = prosodyMetre,
RhymeLetters = rhymeLetters,
Skip = skip,
PoemId = poemId,
PoemFullUrl = poemFullUrl,
SectionIndex = sectionIndex
});
}
public async Task<ActionResult> OnGetSimilarPoemsFromPoetPartialAsync(int poetId, string prosodyMetre, string rhymeLetters, string skipPoemFullUrl1, string skipPoemFullUrl2)
public async Task<IActionResult> OnGetSimilarPoemsFromPoetPartialAsync(int poetId, string prosodyMetre, string rhymeLetters, string skipPoemFullUrl1, string skipPoemFullUrl2)
{
string url = $"{APIRoot.Url}/api/ganjoor/poems/similar?metre={prosodyMetre}&rhyme={rhymeLetters}&poetId={poetId}";
var response = await _httpClient.GetAsync(url);
if (!response.IsSuccessStatusCode)
return BadRequest(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
List<GanjoorPoemCompleteViewModel> selectedPoems = new List<GanjoorPoemCompleteViewModel>();
List<int> poetMorePoemsLikeThisCount = new List<int>();
return BadRequest(await ReadErrorMessageAsync(response));
var poems = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorPoemCompleteViewModel>>();
if (poems.Any(p => p.FullUrl == skipPoemFullUrl1))
poems.RemoveAll(p => p.FullUrl == skipPoemFullUrl1); //TODO: fix errors here
@ -61,17 +49,10 @@ namespace GanjooRazor.Pages
poem.HtmlText = GanjoorPoemTools.GetPoemHtmlExcerpt(poem.HtmlText);
}
return new PartialViewResult()
return Partial("_SimiPartialFromPoetView", new _SimiPartialFromPoetViewModel()
{
ViewName = "_SimiPartialFromPoetView",
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
{
Model = new _SimiPartialFromPoetViewModel()
{
Poems = poems,
}
}
};
Poems = poems,
});
}
}
}