EvaluationReportController.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
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>
Sebastian Drenckberg's avatar
Sebastian Drenckberg committed
21
        /// <returns>"Hello"</returns>
22
23
24
25
26
27
28
        [HttpGet("Hello")]
        public string Get()
        {
            return "Hello";
        }

        /// <summary>
Sebastian Drenckberg's avatar
Sebastian Drenckberg committed
29
        /// Generates the PDF for an evaluation report.
30
31
        /// </summary>
        /// <param name="evaluationReport">Evaluation report for which the PDF should be rendered.</param>
32
        /// <returns>PDF document as byte array.</returns>
33
        [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;
        }
    }
}