예제 #1
0
        public IActionResult Delete([FromQuery] DeletePromptDto promptDto)
        {
            try
            {
                if (_httpContextAccessor.GetCurrentUserId() != promptDto.AuthorId)
                {
                    throw new UnauthorizedAccessException("You are not authorized to delete the specified prompt.");
                }

                var result = _promptService.Delete(promptDto.PromptId, promptDto.AuthorId);

                if (result)
                {
                    return(Ok());
                }
                else
                {
                    return(NoContent());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Encountered exception while attempting to delete prompt.  Message: {ex.Message}");
                Console.WriteLine(ex.StackTrace);
                return(BadRequest(new ErrorResponseDto(ex)));
            }
        }