FactSheetController.cs 1.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using PDFGenerator.Renderers;
using FactSheetModel = PDFGenerator.Models.FactSheet.FactSheet;

namespace PDFGenerator.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class FactSheetController : ControllerBase
    {
        private ILogger<FactSheetController> Logger { get; }

        public FactSheetController(ILogger<FactSheetController> logger)
        {
            Logger = logger;
        }

        /// <summary>
        /// Say hello!
        /// </summary>
        /// <returns>"Hello"</returns>
        [HttpGet("Hello")]
        public string Get()
        {
            return "Hello";
        }

        /// <summary>
        /// Generates the PDF for a factSheet.
        /// </summary>
        /// <param name="factSheet">FactSheet for which the PDF should be rendered.</param>
        /// <returns>PDF document as byte array.</returns>
        [HttpPost("RenderFactSheet")]
        [RequestSizeLimit(100000000)]
        public byte[] RenderFactSheet([FromBody] FactSheetModel factSheet)
        {
            Logger.Log(LogLevel.Debug, "Start rendering pdf for the Fact Sheet.");

            IRenderer Renderer = new FactSheetRenderer(factSheet);
            byte[] file = Renderer.Render();

            Logger.Log(LogLevel.Debug, "Finished rendering pdf for the Fact Sheet.");
            return file;
        }
    }
}