Ejemplo n.º 1
0
        public async Task <ActionResult <ManipulationResult <Right> > > PatchRightAsync([FromQuery] int?groupId,
                                                                                        [FromQuery] int?documentId, [FromBody] JsonPatchDocument <Right> rightPatch)
        {
            if (rightPatch is null)
            {
                return(BadRequest());
            }

            var userIdClaimed = HttpContext.User.Identity.GetUserIdClaim();

            if (userIdClaimed is null)
            {
                return(BadRequest());
            }

            if (groupId is null || documentId is null)
            {
                return(BadRequest("groupId and docId have to be specified"));
            }

            // create empty right ..
            var patchedRight = new Right();

            // .. and apply patch on it
            rightPatch.ApplyTo(patchedRight);

            if (!TryValidateModel(patchedRight))
            {
                return(BadRequest("Patch syntax invalid"));
            }

            var patchResult = await _rightService.UpdateRightAsync(userIdClaimed.Value, groupId.Value,
                                                                   documentId.Value, patchedRight);

            // tried to update a non updateable attribute
            if (patchResult is null)
            {
                return(BadRequest("Tried to update non updateable attributes"));
            }

            return(Ok(patchResult));
        }