Ejemplo n.º 1
0
        public async Task <IActionResult> Update([FromRoute] Guid contactInfoId, [FromBody] UpdateContactInfoRequest contactInfoRequest)
        {
            var isOwner = await _contactInfoService.CheckUserForOwnership(contactInfoId, HttpContext.GetCurrentUserId());

            if (!isOwner)
            {
                return(BadRequest(new { error = "You are not the owner of this contact info" }));
            }

            var updatedContactInfo = new ContactInfo
            {
                Id      = contactInfoId,
                Content = contactInfoRequest.Content,
                Type    = contactInfoRequest.Type
            };

            var updated = await _contactInfoService.UpdateAsync(updatedContactInfo);

            if (updated)
            {
                await _redisCacheService
                .DeleteCachedResponseAsync(
                    new string[]
                {
                    HttpContext.Request.Path,
                    APIRoutes.ContactInfoControllerRoutes.GetAll
                });

                return(Ok(updatedContactInfo));
            }

            return(NotFound());
        }