public async Task <ActionResult> PostBookChapter(BookChapter chapter)
    {
        if (chapter is null)
        {
            return(BadRequest());
        }
        await _chapterService.AddAsync(chapter);

        return(CreatedAtRoute(nameof(GetBookChapterById), new { id = chapter.Id }, chapter));
    }
    public override async Task <AddBookChapterResponse> AddBookChapter(AddBookChapterRequest request, ServerCallContext context)
    {
        var bookChapter = request.Chapter.ToBookChapter();
        await _bookChapterService.AddAsync(bookChapter);

        AddBookChapterResponse response = new()
        {
            Chapter = bookChapter.ToGRPCChapter()
        };

        return(response);
    }
    public async Task <HttpResponseData> AddChapterAsync(
        [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "chapters")] HttpRequestData req,
        FunctionContext executionContext)
    {
        var logger = executionContext.GetLogger("BooksService");

        logger.LogInformation("Function AddChapter invoked.");

        var chapter = await req.ReadFromJsonAsync <BookChapter>();

        if (chapter is null)
        {
            logger.LogError("invalid chapter received");
            return(req.CreateResponse(HttpStatusCode.BadRequest));
        }
        var response = req.CreateResponse(HttpStatusCode.OK);
        await _bookChapterService.AddAsync(chapter);

        await response.WriteAsJsonAsync(chapter);

        return(response);
    }