Example #1
0
        public async Task <ActionResult <Notebook> > GetNotebookAsync([FromHeader] string authorization, [FromQuery] int?id)
        {
            if (authorization == null)
            {
                return(ErrorResponse.Failure <Notebook>(ErrorCodes.MissingToken, "Missing token"));
            }

            try
            {
                if (!await CheckTokenAsync(authorization))
                {
                    return(ErrorResponse.Failure <Notebook>(ErrorCodes.InvalidToken, "Invalid or expired token"));
                }

                if (id == null)
                {
                    return(ErrorResponse.Failure <Notebook>(ErrorCodes.MissingParameter, $"Parameter { nameof(id) } is missing"));
                }

                return((await notebooks.GetAsync(id.Value)).ToWebNotebook());
            }
            catch (Exception e)
            {
                return(ErrorResponse.Failure <Notebook>(ErrorCodes.GeneralFailure, e));
            }
        }