EvaluationReportController.cs 1.47 KB
Newer Older
1
2
3
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using PDFGenerator.Renderers;
4
using EvaluationReportModel = PDFGenerator.Models.EvaluationReport.EvaluationReport;
5
6
7
8
9
10
11

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

        public EvaluationReportController(ILogger<EvaluationReportController> logger)
        {
16
            Logger = logger;
17
18
19
20
21
        }

        /// <summary>
        /// Say hello!
        /// </summary>
Sebastian Drenckberg's avatar
Sebastian Drenckberg committed
22
        /// <returns>"Hello"</returns>
23
24
25
26
27
28
29
        [HttpGet("Hello")]
        public string Get()
        {
            return "Hello";
        }

        /// <summary>
Sebastian Drenckberg's avatar
Sebastian Drenckberg committed
30
        /// Generates the PDF for an evaluation report.
31
32
        /// </summary>
        /// <param name="evaluationReport">Evaluation report for which the PDF should be rendered.</param>
33
        /// <returns>PDF document as byte array.</returns>
34
        [HttpPost("RenderReport")]
Julia Dürselen's avatar
Julia Dürselen committed
35
        [RequestSizeLimit(100000000)]
36
        public byte[] RenderReport([FromBody] EvaluationReportModel evaluationReport)
37
        {
38
            Logger.Log(LogLevel.Debug, "Start rendering pdf report.");
39
40
41
42

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

43
            Logger.Log(LogLevel.Debug, "Finished rendering pdf report.");
44
45
46
47
            return file;
        }
    }
}