docs: #275 GanjoorPoetSuggestedSpecLinesController, GET API for a poet

This commit is contained in:
Hamid Reza Mohammadi 2022-01-29 20:04:03 +03:30
parent 5a5497e0fd
commit 70051fb60e
4 changed files with 105 additions and 17 deletions

View File

@ -0,0 +1,47 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RMuseum.Models.Ganjoor.ViewModels;
using RMuseum.Services;
using System.Net;
using System.Threading.Tasks;
namespace RMuseum.Controllers
{
[Produces("application/json")]
[Route("api/poetspecs")]
public class GanjoorPoetSuggestedSpecLinesController : Controller
{
/// <summary>
/// returns list of suggested spec lines for a poet
/// </summary>
/// <param name="id">poet id</param>
/// <returns></returns>
[HttpGet("poet/{id}")]
[AllowAnonymous]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoetSuggestedSpecLineViewModel[]))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
public async Task<IActionResult> GetPoetSuggestedSpecLinesAsync(int id)
{
var res = await _ganjoorService.GetPoetSuggestedSpecLinesAsync(id);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok(res.Result);
}
/// <summary>
/// Ganjoor Service
/// </summary>
protected readonly IGanjoorService _ganjoorService;
/// <summary>
/// constructor
/// </summary>
/// <param name="ganjoorService"></param>
public GanjoorPoetSuggestedSpecLinesController(IGanjoorService ganjoorService)
{
_ganjoorService = ganjoorService;
}
}
}

View File

@ -1499,6 +1499,24 @@
<param name="memoryCache"></param>
<param name="configuration"></param>
</member>
<member name="M:RMuseum.Controllers.GanjoorPoetSuggestedSpecLinesController.GetPoetSuggestedSpecLinesAsync(System.Int32)">
<summary>
returns list of suggested spec lines for a poet
</summary>
<param name="id">poet id</param>
<returns></returns>
</member>
<member name="F:RMuseum.Controllers.GanjoorPoetSuggestedSpecLinesController._ganjoorService">
<summary>
Ganjoor Service
</summary>
</member>
<member name="M:RMuseum.Controllers.GanjoorPoetSuggestedSpecLinesController.#ctor(RMuseum.Services.IGanjoorService)">
<summary>
constructor
</summary>
<param name="ganjoorService"></param>
</member>
<member name="M:RMuseum.Controllers.GeoLocationController.GetLocationsAsync">
<summary>
get all locations
@ -10438,13 +10456,18 @@
<param name="metre"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.GetPoetSuggestedSpecLinesAsync(System.Int32,System.Nullable{System.Guid},System.Boolean)">
<member name="M:RMuseum.Services.IGanjoorService.GetPoetSuggestedSpecLinesAsync(System.Int32)">
<summary>
return list of suggested spec lines
</summary>
<param name="poetId"></param>
<param name="userId"></param>
<param name="includeUnpublished"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.GetPoetSuggestedSpecLineAsync(System.Int32)">
<summary>
returns specfic suggested line for poet
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.IGanjoorService.AddPoetSuggestedSpecLinesAsync(RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetSuggestedSpecLineViewModel)">
@ -11855,13 +11878,18 @@
</summary>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoetSuggestedSpecLinesAsync(System.Int32,System.Nullable{System.Guid},System.Boolean)">
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoetSuggestedSpecLinesAsync(System.Int32)">
<summary>
return list of suggested spec lines
</summary>
<param name="poetId"></param>
<param name="userId"></param>
<param name="includeUnpublished"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.GetPoetSuggestedSpecLineAsync(System.Int32)">
<summary>
returns specfic suggested line for poet
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.AddPoetSuggestedSpecLinesAsync(RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetSuggestedSpecLineViewModel)">

View File

@ -739,17 +739,15 @@ namespace RMuseum.Services
/// return list of suggested spec lines
/// </summary>
/// <param name="poetId"></param>
/// <param name="userId"></param>
/// <param name="includeUnpublished"></param>
/// <returns></returns>
Task<RServiceResult<GanjoorPoetSuggestedSpecLineViewModel[]>> GetPoetSuggestedSpecLinesAsync(int poetId, Guid? userId, bool includeUnpublished);
Task<RServiceResult<GanjoorPoetSuggestedSpecLineViewModel[]>> GetPoetSuggestedSpecLinesAsync(int poetId);
/// <summary>
/// returns specfic suggested line for poet
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<RServiceResult<GanjoorPoetSuggestedSpecLineViewModel>> GetPoetSuggestedSpecLinesAsync(int id);
Task<RServiceResult<GanjoorPoetSuggestedSpecLineViewModel>> GetPoetSuggestedSpecLineAsync(int id);
/// <summary>
/// add a suggestion for poets spec lines

View File

@ -1,6 +1,8 @@
using Microsoft.EntityFrameworkCore;
using RMuseum.Models.Auth.Memory;
using RMuseum.Models.Ganjoor;
using RMuseum.Models.Ganjoor.ViewModels;
using RSecurityBackend.Models.Auth.Memory;
using RSecurityBackend.Models.Generic;
using System;
using System.Data;
@ -18,10 +20,8 @@ namespace RMuseum.Services.Implementation
/// return list of suggested spec lines
/// </summary>
/// <param name="poetId"></param>
/// <param name="userId"></param>
/// <param name="includeUnpublished"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorPoetSuggestedSpecLineViewModel[]>> GetPoetSuggestedSpecLinesAsync(int poetId, Guid? userId, bool includeUnpublished)
public async Task<RServiceResult<GanjoorPoetSuggestedSpecLineViewModel[]>> GetPoetSuggestedSpecLinesAsync(int poetId)
{
return new RServiceResult<GanjoorPoetSuggestedSpecLineViewModel[]>
(
@ -30,9 +30,7 @@ namespace RMuseum.Services.Implementation
(
r => r.PoetId == poetId
&&
(includeUnpublished || r.Published == true)
&&
(userId == null || r.SuggestedById == userId)
r.Published == true
)
.OrderBy(r => r.LineOrder)
.Select
@ -56,7 +54,7 @@ namespace RMuseum.Services.Implementation
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<RServiceResult<GanjoorPoetSuggestedSpecLineViewModel>> GetPoetSuggestedSpecLinesAsync(int id)
public async Task<RServiceResult<GanjoorPoetSuggestedSpecLineViewModel>> GetPoetSuggestedSpecLineAsync(int id)
{
try
{
@ -110,6 +108,23 @@ namespace RMuseum.Services.Implementation
await _context.SaveChangesAsync();
model.Published = false;
model.Id = dbModel.Id;
var moderators = await _appUserService.GetUsersHavingPermission(RMuseumSecurableItem.GanjoorEntityShortName, SecurableItem.ModifyOperationShortName);
if (string.IsNullOrEmpty(moderators.ExceptionString)) //if not, do nothing!
{
var poet = await _context.GanjoorPoets.AsNoTracking().Where(p => p.Id == model.PoetId).SingleAsync();
foreach (var moderator in moderators.Result)
{
await _notificationService.PushNotification
(
(Guid)moderator.Id,
"ثبت مشخصات جدید برای شاعر",
$"درخواستی برای ثبت مشخصات جدید برای «{poet.Nickname}» ثبت شده است. در صورت تمایل به بررسی، بخش مربوط به شاعر را <a href=\"/photos\">اینجا</a> ببینید.{ Environment.NewLine}" +
$"توجه فرمایید که اگر کاربر دیگری که دارای مجوز بررسی مشخصات است پیش از شما به آن رسیدگی کرده باشد آن را در صف نخواهید دید."
);
}
}
return new RServiceResult<GanjoorPoetSuggestedSpecLineViewModel>(model);
}
catch (Exception exp)