PUT/DELETE API برای پروفایلهای خوانش
This commit is contained in:
parent
402ccdea9f
commit
a909a7e6eb
@ -175,6 +175,52 @@ namespace RMuseum.Controllers
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a narration profile
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("profile")]
|
||||
[Authorize]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(UserNarrationProfileViewModel))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.Forbidden, Type = typeof(string))]
|
||||
|
||||
public async Task<IActionResult> UpdateUserNarrationProfiles([FromBody] UserNarrationProfileViewModel profile)
|
||||
{
|
||||
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
|
||||
profile.UserId = loggedOnUserId;
|
||||
|
||||
var res = await _audioService.UpdateUserNarrationProfiles(profile);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
return BadRequest(res.ExceptionString);
|
||||
|
||||
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a narration profile
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpDelete("profile/{id}")]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(bool))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.Forbidden)]
|
||||
public async Task<IActionResult> DeleteUserNarrationProfiles(Guid id)
|
||||
{
|
||||
Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
|
||||
RServiceResult<bool> res = await _audioService.DeleteUserNarrationProfiles(id, loggedOnUserId);
|
||||
if (!string.IsNullOrEmpty(res.ExceptionString))
|
||||
{
|
||||
return BadRequest(res.ExceptionString);
|
||||
}
|
||||
return Ok(res.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
|
||||
@ -654,6 +654,20 @@
|
||||
<param name="profile"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.AudioNarrationController.UpdateUserNarrationProfiles(RMuseum.Models.GanjoorAudio.ViewModels.UserNarrationProfileViewModel)">
|
||||
<summary>
|
||||
Update a narration profile
|
||||
</summary>
|
||||
<param name="profile"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.AudioNarrationController.DeleteUserNarrationProfiles(System.Guid)">
|
||||
<summary>
|
||||
Delete a narration profile
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Controllers.AudioNarrationController.#ctor(RMuseum.Services.IAudioNarrationService,RSecurityBackend.Services.IUserPermissionChecker)">
|
||||
<summary>
|
||||
constructor
|
||||
@ -3566,6 +3580,21 @@
|
||||
<param name="profile"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IAudioNarrationService.UpdateUserNarrationProfiles(RMuseum.Models.GanjoorAudio.ViewModels.UserNarrationProfileViewModel)">
|
||||
<summary>
|
||||
Update a narration profile
|
||||
</summary>
|
||||
<param name="profile"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.IAudioNarrationService.DeleteUserNarrationProfiles(System.Guid,System.Guid)">
|
||||
<summary>
|
||||
Delete a narration profile
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:RMuseum.Services.Implementation.ArtifactService">
|
||||
<summary>
|
||||
IArtifactService implementation
|
||||
@ -4337,6 +4366,21 @@
|
||||
<param name="profile"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.UpdateUserNarrationProfiles(RMuseum.Models.GanjoorAudio.ViewModels.UserNarrationProfileViewModel)">
|
||||
<summary>
|
||||
Update a narration profile
|
||||
</summary>
|
||||
<param name="profile"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RMuseum.Services.Implementation.AudioNarrationService.DeleteUserNarrationProfiles(System.Guid,System.Guid)">
|
||||
<summary>
|
||||
Delete a narration profile
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="userId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="P:RMuseum.Services.Implementation.AudioNarrationService.Configuration">
|
||||
<summary>
|
||||
Configuration
|
||||
|
||||
@ -72,6 +72,21 @@ namespace RMuseum.Services
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<UserNarrationProfileViewModel>> AddUserNarrationProfiles(UserNarrationProfileViewModel profile);
|
||||
|
||||
/// <summary>
|
||||
/// Update a narration profile
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<UserNarrationProfileViewModel>> UpdateUserNarrationProfiles(UserNarrationProfileViewModel profile);
|
||||
|
||||
/// <summary>
|
||||
/// Delete a narration profile
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> DeleteUserNarrationProfiles(Guid id, Guid userId);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -485,7 +485,7 @@ namespace RMuseum.Services.Implementation
|
||||
o.IsDefault = false;
|
||||
_context.UserNarrationProfiles.Update(o);
|
||||
}
|
||||
await _context.UserNarrationProfiles.AddAsync(p);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(new UserNarrationProfileViewModel(p));
|
||||
}
|
||||
@ -495,6 +495,76 @@ namespace RMuseum.Services.Implementation
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a narration profile
|
||||
/// </summary>
|
||||
/// <param name="profile"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<UserNarrationProfileViewModel>> UpdateUserNarrationProfiles(UserNarrationProfileViewModel profile)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var p = await _context.UserNarrationProfiles.Where(p => p.Id == profile.Id).SingleOrDefaultAsync();
|
||||
|
||||
if (p.UserId != profile.UserId)
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(null, "permission error");
|
||||
|
||||
p.ArtistName = profile.ArtistName;
|
||||
p.ArtistUrl = profile.ArtistUrl;
|
||||
p.AudioSrc = profile.AudioSrc;
|
||||
p.AudioSrcUrl = profile.AudioSrcUrl;
|
||||
p.FileSuffixWithoutDash = profile.FileSuffixWithoutDash;
|
||||
p.IsDefault = profile.IsDefault;
|
||||
|
||||
_context.UserNarrationProfiles.Update(p);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
if (p.IsDefault)
|
||||
{
|
||||
foreach (var o in _context.UserNarrationProfiles.Where(o => o.Id != p.Id && o.IsDefault).Select(o => o))
|
||||
{
|
||||
o.IsDefault = false;
|
||||
_context.UserNarrationProfiles.Update(o);
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(new UserNarrationProfileViewModel(p));
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<UserNarrationProfileViewModel>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a narration profile
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> DeleteUserNarrationProfiles(Guid id, Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var p = await _context.UserNarrationProfiles.Where(p => p.Id == id).SingleOrDefaultAsync();
|
||||
|
||||
if (p.UserId != userId)
|
||||
return new RServiceResult<bool>(false);
|
||||
|
||||
_context.UserNarrationProfiles.Remove(p);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configuration
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user