From 97bd31933cf5fd20ec30d1374b0e4e35a4dc7a2e Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 4 Mar 2022 17:46:26 +0330 Subject: [PATCH] docs: #285 links for each FAQ item --- GanjooRazor/Pages/FAQ.cshtml | 53 ++++++++++++------- GanjooRazor/Pages/FAQ.cshtml.cs | 29 ++++++++-- RMuseum/Controllers/FAQController.cs | 19 ++++++- RMuseum/RMuseum.xml | 7 +++ .../GanjoorService-SitemapGenerator.cs | 1 + 5 files changed, 85 insertions(+), 24 deletions(-) diff --git a/GanjooRazor/Pages/FAQ.cshtml b/GanjooRazor/Pages/FAQ.cshtml index 671dd8f0..44747ab0 100644 --- a/GanjooRazor/Pages/FAQ.cshtml +++ b/GanjooRazor/Pages/FAQ.cshtml @@ -55,28 +55,45 @@
-

پرسش‌های متداول

- @foreach (var category in Model.PinnedItemsCategories) +

+ پرسش‌های متداول +

+ @if (Model.Question != null) { -
-

- @category.Title -

- @foreach (var item in category.Items) - { -
diff --git a/GanjooRazor/Pages/FAQ.cshtml.cs b/GanjooRazor/Pages/FAQ.cshtml.cs index 0ecb60b1..4039cf5f 100644 --- a/GanjooRazor/Pages/FAQ.cshtml.cs +++ b/GanjooRazor/Pages/FAQ.cshtml.cs @@ -21,6 +21,8 @@ namespace GanjooRazor.Pages public List PinnedItemsCategories { get; set; } + public FAQItem Question { get; set; } + private async Task preparePoets() { var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poets"); @@ -46,13 +48,30 @@ namespace GanjooRazor.Pages if (false == (await preparePoets())) return Page(); - var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/faq/pinned"); - if (!response.IsSuccessStatusCode) + if(!string.IsNullOrEmpty(Request.Query["id"])) { - LastError = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); - return Page(); + var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/faq/{Request.Query["id"]}"); + if (!response.IsSuccessStatusCode) + { + LastError = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); + if(string.IsNullOrEmpty(LastError)) + { + LastError = $"خطا در دریافت اطلاعات پرسش مد نظر - کد خظا = {response.StatusCode}"; + } + return Page(); + } + Question = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); + } + else + { + var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/faq/pinned"); + if (!response.IsSuccessStatusCode) + { + LastError = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); + return Page(); + } + PinnedItemsCategories = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject>(); } - PinnedItemsCategories = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject>(); return Page(); } diff --git a/RMuseum/Controllers/FAQController.cs b/RMuseum/Controllers/FAQController.cs index 2e69d1e2..fcac9312 100644 --- a/RMuseum/Controllers/FAQController.cs +++ b/RMuseum/Controllers/FAQController.cs @@ -181,7 +181,24 @@ namespace RMuseum.Controllers return Ok(res.Result); } - + /// + /// get published item by id + /// + /// + /// + [HttpGet("{id}")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(FAQItem))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + public async Task GetPublishedItemByIdAsync(int id) + { + var res = await _faqService.GetItemByIdAsync(id); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + if (!res.Result.Published) + return NotFound(); + return Ok(res.Result); + } /// /// add a new faq item diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index ddb34dde..771572bb 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -835,6 +835,13 @@ + + + get published item by id + + + + add a new faq item diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-SitemapGenerator.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-SitemapGenerator.cs index 5b4b60b2..e557545b 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-SitemapGenerator.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-SitemapGenerator.cs @@ -75,6 +75,7 @@ namespace RMuseum.Services.Implementation var urls = await context.GanjoorPages.Where(p => p.PoetId == null).OrderBy(p => p.Id).Select(p => p.FullUrl).ToListAsync(); urls.Add("/map"); urls.Add("/photos"); + urls.Add("/faq"); urls.Remove("/audioclip"); urls.Remove("/simi");