From 5dd93d80f97ba18fff8e40daf4e1e4d11328c0bb Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Mon, 22 Mar 2021 11:26:50 +0430 Subject: [PATCH] #98 user comments api --- RMuseum/Controllers/GanjoorController.cs | 36 ++++++++++++++++++++++++ RMuseum/RMuseum.xml | 7 +++++ 2 files changed, 43 insertions(+) diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index c33bac02..c3995659 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -515,6 +515,42 @@ namespace RMuseum.Controllers return Ok(comments.Result.Items); } + /// + /// get logged on users recent comments + /// + /// + /// + + [HttpGet] + [Route("comments/mine")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(IEnumerable))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + + public async Task GetMyRecentComments([FromQuery] PagingParameterModel paging) + { + Guid userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + Guid sessionId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "SessionId").Value); + RServiceResult sessionCheckResult = await _appUserService.SessionExists(userId, sessionId); + if (!string.IsNullOrEmpty(sessionCheckResult.ExceptionString)) + { + return StatusCode((int)HttpStatusCode.Forbidden); + } + + var comments = await _ganjoorService.GetRecentComments(paging, userId, false); + if (!string.IsNullOrEmpty(comments.ExceptionString)) + { + return BadRequest(comments.ExceptionString); + } + + // Paging Header + HttpContext.Response.Headers.Add("paging-headers", JsonConvert.SerializeObject(comments.Result.PagingMeta)); + + return Ok(comments.Result.Items); + } + /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index efe3f5cc..22538f3f 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -772,6 +772,13 @@ + + + get logged on users recent comments + + + + post new comment