From 402ccdea9feb1b272d22c4296046d0e532a95d9f Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Mon, 21 Sep 2020 21:23:42 +0330 Subject: [PATCH] =?UTF-8?q?POST=20API=20=D8=A8=D8=B1=D8=A7=DB=8C=20=D9=BE?= =?UTF-8?q?=D8=B1=D9=88=D9=81=D8=A7=DB=8C=D9=84=D9=87=D8=A7=DB=8C=20=D8=AE?= =?UTF-8?q?=D9=88=D8=A7=D9=86=D8=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AudioNarrationController.cs | 32 ++++++++++++++- RMuseum/RMuseum.xml | 27 +++++++++++++ RMuseum/Services/IAudioNarrationService.cs | 7 ++++ .../Implementation/AudioNarrationService.cs | 39 +++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/RMuseum/Controllers/AudioNarrationController.cs b/RMuseum/Controllers/AudioNarrationController.cs index 405c3a2a..71e9a64a 100644 --- a/RMuseum/Controllers/AudioNarrationController.cs +++ b/RMuseum/Controllers/AudioNarrationController.cs @@ -126,7 +126,11 @@ namespace RMuseum.Controllers return BadRequest(res.ExceptionString); } - [HttpGet("profiles")] + /// + /// Get User Profiles + /// + /// + [HttpGet("profile")] [Authorize] [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] @@ -145,6 +149,32 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// Add a narration profile + /// + /// + /// + [HttpPost("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 AddUserNarrationProfiles([FromBody]UserNarrationProfileViewModel profile) + { + Guid loggedOnUserId = new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + profile.UserId = loggedOnUserId; + + + var res = await _audioService.AddUserNarrationProfiles(profile); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + + + return Ok(res.Result); + } + /// /// constructor /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index ec1c9cd6..5d90ad2e 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -641,6 +641,19 @@ + + + Get User Profiles + + + + + + Add a narration profile + + + + constructor @@ -3546,6 +3559,13 @@ + + + Add a narration profile + + + + IArtifactService implementation @@ -4310,6 +4330,13 @@ + + + Add a narration profile + + + + Configuration diff --git a/RMuseum/Services/IAudioNarrationService.cs b/RMuseum/Services/IAudioNarrationService.cs index cc224cef..52d585b6 100644 --- a/RMuseum/Services/IAudioNarrationService.cs +++ b/RMuseum/Services/IAudioNarrationService.cs @@ -65,6 +65,13 @@ namespace RMuseum.Services /// Task> GetUserNarrationProfiles(Guid userId); + /// + /// Add a narration profile + /// + /// + /// + Task> AddUserNarrationProfiles(UserNarrationProfileViewModel profile); + } } diff --git a/RMuseum/Services/Implementation/AudioNarrationService.cs b/RMuseum/Services/Implementation/AudioNarrationService.cs index 6761fb68..0e78695c 100644 --- a/RMuseum/Services/Implementation/AudioNarrationService.cs +++ b/RMuseum/Services/Implementation/AudioNarrationService.cs @@ -456,6 +456,45 @@ namespace RMuseum.Services.Implementation } } + /// + /// Add a narration profile + /// + /// + /// + public async Task> AddUserNarrationProfiles(UserNarrationProfileViewModel profile) + { + try + { + var p = new UserNarrationProfile() + { + UserId = profile.UserId, + ArtistName = profile.ArtistName, + ArtistUrl = profile.ArtistUrl, + AudioSrc = profile.AudioSrc, + AudioSrcUrl = profile.AudioSrcUrl, + FileSuffixWithoutDash = profile.FileSuffixWithoutDash, + IsDefault = profile.IsDefault + }; + await _context.UserNarrationProfiles.AddAsync(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.UserNarrationProfiles.AddAsync(p); + } + return new RServiceResult(new UserNarrationProfileViewModel(p)); + } + catch (Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + /// /// Configuration ///