From 2717c801d5d3b6e523fd8b65aa5eac72822cbe21 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sun, 23 Apr 2023 18:28:19 +0330 Subject: [PATCH] docs: #379 api for retrieving list of books --- RMuseum/Controllers/GanjoorController.cs | 20 ++++++++++++++ .../Ganjoor/ViewModels/GanjoorCatViewModel.cs | 1 - RMuseum/RMuseum.xml | 18 +++++++++++++ RMuseum/Services/IGanjoorService.cs | 6 +++++ .../Services/Implementation/GanjoorService.cs | 27 +++++++++++++++++++ 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index b08a52f2..81854b50 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -513,6 +513,26 @@ namespace RMuseum.Controllers } } + /// + /// list of books + /// + /// + [HttpGet] + [Route("books")] + [AllowAnonymous] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorCatViewModel[]))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task GetBooksAsync() + { + var books = await _ganjoorService.GetBooksAsync(); + if(!string.IsNullOrEmpty(books.ExceptionString)) + { + return BadRequest(books.ExceptionString); + } + return Ok(books); + } + /// /// batch rename cat poems /// diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs index bd7f9043..ae5cea1f 100644 --- a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs +++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCatViewModel.cs @@ -1,5 +1,4 @@ using Microsoft.AspNetCore.Http; -using RSecurityBackend.Models.Image; using System; using System.Collections.Generic; diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index fef1eecf..f9d7c8f8 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -996,6 +996,12 @@ only RImageId field is valid + + + list of books + + + batch rename cat poems @@ -12520,6 +12526,12 @@ + + + get list of books + + + get page by url @@ -15706,6 +15718,12 @@ + + + get list of books + + + get cat by id diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 4bc74a35..f7be0ee5 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -73,6 +73,12 @@ namespace RMuseum.Services /// Task> SetCategoryExtraInfo(int catId, string bookName, Guid? imageId, bool sumUpSubsGeoLocations, string mapName); + /// + /// get list of books + /// + /// + Task> GetBooksAsync(); + /// /// get page by url /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 24098e89..1b46dc6f 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -245,6 +245,33 @@ namespace RMuseum.Services.Implementation return new RServiceResult(null, exp.ToString()); } } + + /// + /// get list of books + /// + /// + public async Task> GetBooksAsync() + { + try + { + return new RServiceResult + ( + await _context.GanjoorCategories.AsNoTracking().Where(c => !string.IsNullOrEmpty(c.BookName)).OrderBy(c => c.BookName) + .Select(c => new GanjoorCatViewModel() + { + BookName = c.BookName, + FullUrl = c.FullUrl, + RImageId = c.RImageId + } + ) + .ToArrayAsync() + ); + } + catch (Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } /// /// get cat by id