#203 adding TranslationController

This commit is contained in:
Hamid Reza Mohammadi 2021-09-10 21:29:56 +04:30
parent 58734cfd91
commit 94d7dc17e9
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,44 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RMuseum.Models.Auth.Memory;
using RMuseum.Models.Ganjoor;
using RMuseum.Services;
using System;
using System.Net;
using System.Threading.Tasks;
namespace RMuseum.Controllers
{
[Produces("application/json")]
[Route("api/translations")]
public class TranslationController : Controller
{
/// <summary>
/// add new langauge
/// </summary>
/// <param name="lang"></param>
/// <returns></returns>
[HttpPost]
[Authorize(Policy = RMuseumSecurableItem.GanjoorEntityShortName + ":" + RMuseumSecurableItem.Translations)]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorLanguage))]
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
[ProducesResponseType((int)HttpStatusCode.Unauthorized)]
public async Task<IActionResult> AddLanguageAsync([FromBody] GanjoorLanguage lang)
{
var res = await _translationService.AddLanguageAsync(lang.Name, lang.RightToLeft);
if (!string.IsNullOrEmpty(res.ExceptionString))
return BadRequest(res.ExceptionString);
return Ok(res.Result);
}
/// <summary>
/// translation service
/// </summary>
private readonly IGanjoorTranslationService _translationService;
public TranslationController(IGanjoorTranslationService translationService)
{
_translationService = translationService;
}
}
}

View File

@ -93,6 +93,10 @@ namespace RMuseum.Models.Auth.Memory
/// </summary>
public const string Donations = "donations";
/// <summary>
/// translations
/// </summary>
public const string Translations = "translations";
/// <summary>
/// list of forms and their permissions
@ -167,6 +171,7 @@ namespace RMuseum.Models.Auth.Memory
new SecurableItemOperation(ModifyOperationShortName, "ویرایش محتوا", false),
new SecurableItemOperation(Banners, "مدیریت آگاهی‌ها", false),
new SecurableItemOperation(Donations, "مدیریت کمکهای مالی", false),
new SecurableItemOperation(Translations, "ترجمه", false),
}
},

View File

@ -1634,6 +1634,18 @@
</summary>
<param name="bannersService"></param>
</member>
<member name="M:RMuseum.Controllers.TranslationController.AddLanguageAsync(RMuseum.Models.Ganjoor.GanjoorLanguage)">
<summary>
add new langauge
</summary>
<param name="lang"></param>
<returns></returns>
</member>
<member name="F:RMuseum.Controllers.TranslationController._translationService">
<summary>
translation service
</summary>
</member>
<member name="T:RMuseum.DbContext.RMuseumDbContext">
<summary>
Museum Database Context
@ -2803,6 +2815,11 @@
donations
</summary>
</member>
<member name="F:RMuseum.Models.Auth.Memory.RMuseumSecurableItem.Translations">
<summary>
translations
</summary>
</member>
<member name="P:RMuseum.Models.Auth.Memory.RMuseumSecurableItem.Items">
<summary>
list of forms and their permissions