#35 api for transferring recitation ownership
This commit is contained in:
parent
7a09d7ad1b
commit
105aae9333
@ -550,15 +550,46 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result.Items);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transfer Recitations Ownership
|
||||
/// </summary>
|
||||
/// <param name="targetEmailAddress"></param>
|
||||
/// <param name="artistName"></param>
|
||||
/// <returns>number of transfered items</returns>
|
||||
|
||||
[HttpPut("chown")]
|
||||
[Authorize(Policy = RMuseumSecurableItem.AudioNarrationEntityShortName + ":" + RMuseumSecurableItem.ImportOperationShortName)]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(int))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(string))]
|
||||
public async Task<IActionResult> TransferRecitationsOwnership(string targetEmailAddress, string artistName)
|
||||
{
|
||||
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
var userSearchResult = await _appUserService.FindUserByEmail(targetEmailAddress);
|
||||
if (!string.IsNullOrEmpty(userSearchResult.ExceptionString))
|
||||
return BadRequest(userSearchResult);
|
||||
if (userSearchResult.Result == null)
|
||||
return NotFound();
|
||||
|
||||
var resExec = await _audioService.TransferRecitationsOwnership(loggedOnUserId, (Guid)userSearchResult.Result.Id, artistName);
|
||||
if (!string.IsNullOrEmpty(resExec.ExceptionString))
|
||||
return BadRequest(resExec.ExceptionString);
|
||||
|
||||
return Ok(resExec.Result);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="audioService"></param>
|
||||
/// <param name="userPermissionChecker"></param>
|
||||
public RecitationController(IRecitationService audioService, IUserPermissionChecker userPermissionChecker)
|
||||
/// <param name="appUserService"></param>
|
||||
public RecitationController(IRecitationService audioService, IUserPermissionChecker userPermissionChecker, IAppUserService appUserService)
|
||||
{
|
||||
_audioService = audioService;
|
||||
_userPermissionChecker = userPermissionChecker;
|
||||
_appUserService = appUserService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -571,5 +602,10 @@ namespace RMuseum.Controllers
|
||||
/// </summary>
|
||||
protected IUserPermissionChecker _userPermissionChecker;
|
||||
|
||||
/// <summary>
|
||||
/// IAppUserService instance
|
||||
/// </summary>
|
||||
protected IAppUserService _appUserService;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -833,12 +833,21 @@
|
||||
<param name="finished"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.RecitationController.#ctor(RMuseum.Services.IRecitationService,RSecurityBackend.Services.IUserPermissionChecker)">
|
||||
<member name="M:RMuseum.Controllers.RecitationController.TransferRecitationsOwnership(System.String,System.String)">
|
||||
<summary>
|
||||
Transfer Recitations Ownership
|
||||
</summary>
|
||||
<param name="targetEmailAddress"></param>
|
||||
<param name="artistName"></param>
|
||||
<returns>number of transfered items</returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.RecitationController.#ctor(RMuseum.Services.IRecitationService,RSecurityBackend.Services.IUserPermissionChecker,RSecurityBackend.Services.IAppUserService)">
|
||||
<summary>
|
||||
constructor
|
||||
</summary>
|
||||
<param name="audioService"></param>
|
||||
<param name="userPermissionChecker"></param>
|
||||
<param name="appUserService"></param>
|
||||
</member>
|
||||
<member name="F:RMuseum.Controllers.RecitationController._audioService">
|
||||
<summary>
|
||||
@ -850,6 +859,11 @@
|
||||
IUserPermissionChecker instance
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:RMuseum.Controllers.RecitationController._appUserService">
|
||||
<summary>
|
||||
IAppUserService instance
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RMuseum.Controllers.RImageController">
|
||||
<summary>
|
||||
Generic Image Provider
|
||||
@ -5138,6 +5152,15 @@
|
||||
<param name="finished"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.RecitationService.TransferRecitationsOwnership(System.Guid,System.Guid,System.String)">
|
||||
<summary>
|
||||
Transfer Recitations Ownership
|
||||
</summary>
|
||||
<param name="currentOwenerId"></param>
|
||||
<param name="newOwnerId"></param>
|
||||
<param name="artistName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:RMuseum.Services.Implementation.RecitationService.Configuration">
|
||||
<summary>
|
||||
Configuration
|
||||
@ -5444,6 +5467,15 @@
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IRecitationService.TransferRecitationsOwnership(System.Guid,System.Guid,System.String)">
|
||||
<summary>
|
||||
Transfer Recitations Ownership
|
||||
</summary>
|
||||
<param name="currentOwenerId"></param>
|
||||
<param name="newOwnerId"></param>
|
||||
<param name="artistName"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IRecitationService.GetUploads(RSecurityBackend.Models.Generic.PagingParameterModel,System.Guid)">
|
||||
<summary>
|
||||
Get uploads descending by upload time
|
||||
|
||||
@ -142,6 +142,15 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> DeleteUserNarrationProfiles(Guid id, Guid userId);
|
||||
|
||||
/// <summary>
|
||||
/// Transfer Recitations Ownership
|
||||
/// </summary>
|
||||
/// <param name="currentOwenerId"></param>
|
||||
/// <param name="newOwnerId"></param>
|
||||
/// <param name="artistName"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<int>> TransferRecitationsOwnership(Guid currentOwenerId, Guid newOwnerId, string artistName);
|
||||
|
||||
/// <summary>
|
||||
/// Get uploads descending by upload time
|
||||
/// </summary>
|
||||
|
||||
@ -1430,6 +1430,32 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transfer Recitations Ownership
|
||||
/// </summary>
|
||||
/// <param name="currentOwenerId"></param>
|
||||
/// <param name="newOwnerId"></param>
|
||||
/// <param name="artistName"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<int>> TransferRecitationsOwnership(Guid currentOwenerId, Guid newOwnerId, string artistName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var recitations = await _context.Recitations.Where(r => r.OwnerId == currentOwenerId && r.AudioArtist == artistName).ToListAsync();
|
||||
foreach(Recitation recitation in recitations)
|
||||
{
|
||||
recitation.OwnerId = newOwnerId;
|
||||
}
|
||||
_context.Recitations.UpdateRange(recitations);
|
||||
await _context.SaveChangesAsync();
|
||||
return new RServiceResult<int>(recitations.Count);
|
||||
}
|
||||
catch(Exception exp)
|
||||
{
|
||||
return new RServiceResult<int>(0, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configuration
|
||||
/// </summary>
|
||||
|
||||
@ -40,20 +40,20 @@
|
||||
"UploadLimit": "52428800"
|
||||
},
|
||||
"AudioMySqlServer": {
|
||||
"Server": "185.8.175.123",
|
||||
"Username": "ganjoor_wuser",
|
||||
"Password": "6Uy^gjjUjj889nN",
|
||||
"Database": "ganjoor_adab",
|
||||
"2ndDatabase": "ganjoor_audio",
|
||||
"2ndUsername": "ganjoor_audio",
|
||||
"2ndPassword": "ytTA8mbFRo"
|
||||
"Server": "localhost",
|
||||
"Username": "root",
|
||||
"Password": "",
|
||||
"Database": "adab",
|
||||
"2ndDatabase": "audio",
|
||||
"2ndUsername": "audio",
|
||||
"2ndPassword": ""
|
||||
},
|
||||
"AudioSFPServer": {
|
||||
"Host": "185.8.175.123",
|
||||
"Host": "localhost",
|
||||
"Port": "22",
|
||||
"Username": "ganjoor",
|
||||
"Password": "$693#400%aPo@a",
|
||||
"RootPath": "/home/ganjoor/domains/ganjoor.net/public_html"
|
||||
"Username": "root",
|
||||
"Password": "",
|
||||
"RootPath": "/home"
|
||||
},
|
||||
"AudioUploadService": {
|
||||
"TempUploadPath": "C:\\tempaudio",
|
||||
|
||||
@ -2043,6 +2043,13 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Services.IAppUserService.FindUserByEmail(System.String)">
|
||||
<summary>
|
||||
Find User By Email
|
||||
</summary>
|
||||
<param name="email"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:RSecurityBackend.Services.IAppUserService.AdministratorRoleName">
|
||||
<summary>
|
||||
Administrator role name
|
||||
@ -2355,6 +2362,13 @@
|
||||
<param name="clientIPAddress"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Services.Implementation.AppUserService.FindUserByEmail(System.String)">
|
||||
<summary>
|
||||
Find User By Email
|
||||
</summary>
|
||||
<param name="email"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Services.Implementation.AppUserService.DeleteTenant">
|
||||
<summary>
|
||||
delete tenant
|
||||
|
||||
@ -239,6 +239,13 @@ namespace RSecurityBackend.Services
|
||||
/// <returns></returns>
|
||||
RServiceResult<bool> DeleteTenant();
|
||||
|
||||
/// <summary>
|
||||
/// Find User By Email
|
||||
/// </summary>
|
||||
/// <param name="email"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<PublicRAppUser>> FindUserByEmail(string email);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Administrator role name
|
||||
|
||||
@ -1245,6 +1245,26 @@ namespace RSecurityBackend.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find User By Email
|
||||
/// </summary>
|
||||
/// <param name="email"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<PublicRAppUser>> FindUserByEmail(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
RAppUser user = await _userManager.FindByEmailAsync(email);
|
||||
if (user == null)
|
||||
return new RServiceResult<PublicRAppUser>(null);
|
||||
return new RServiceResult<PublicRAppUser>(new PublicRAppUser(user));
|
||||
}
|
||||
catch(Exception exp)
|
||||
{
|
||||
return new RServiceResult<PublicRAppUser>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// delete tenant
|
||||
|
||||
Loading…
Reference in New Issue
Block a user