EvaluationReportController.cs 1.38 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
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using PDFGenerator.Renderers;

namespace PDFGenerator.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class EvaluationReportController : ControllerBase
    {
        private readonly ILogger<EvaluationReportController> _logger;

        public EvaluationReportController(ILogger<EvaluationReportController> logger)
        {
            _logger = logger;
        }

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

        /// <summary>
        /// Generates the PDF report.
        /// </summary>
        /// <param name="evaluationReport">Evaluation report for which the PDF should be rendered.</param>
        /// <returns>the PDF document as byte array</returns>
        [HttpPost("RenderReport")]
Julia Dürselen's avatar
Julia Dürselen committed
34
        [RequestSizeLimit(100000000)]
35
36
37
38
39
40
41
42
43
44
45
46
        public byte[] RenderReport([FromBody] PDFGenerator.Models.EvaluationReport evaluationReport)
        {
            _logger.Log(LogLevel.Debug, "Start rendering pdf report.");

            IRenderer Renderer = new EvaluationReportRenderer(evaluationReport);
            byte[] file = Renderer.Render();

            _logger.Log(LogLevel.Debug, "Finished rendering pdf report.");
            return file;
        }
    }
}