using System; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using Serilog; using Landmark.OLA.Models; using Landmark.OLA.Application.Services; namespace Landmark.OLA.Application.Controllers { [Route("api/GetPdf/")] [ApiController] public class PdfController : ControllerBase { private readonly IPdfService _pdfService; private readonly ApplicationControlConfiguration _appControlConfig; public PdfController(IOptions settings, IPdfService pdfService) { _pdfService = pdfService; _appControlConfig = settings.Value; } // Get: api/GetPdf/ImportantTerms [HttpGet("ImportantTerms")] [ProducesResponseType(200)] [ProducesResponseType(201)] [ProducesResponseType(400)] [ProducesResponseType(404)] [ProducesResponseType(500)] public IActionResult GetPdfImportantTerms() { try { var result = _pdfService.GetFileBytes(_appControlConfig.ImportantTermsPdfFilePath); var payload = new FileContentResult(result, "application/octet-stream"); return payload; } catch (ArgumentException ae) { Log.Error(ae, $"Request for bad file path for IMPORTANT TERMS OF OUR HOME EQUITY LINE OF CREDIT.pdf"); return BadRequest("File path not found"); } catch (Exception ex) { Log.Error(ex, $"Unexpected error retrieving file path IMPORTANT TERMS OF OUR HOME EQUITY LINE OF CREDIT.pdf"); return StatusCode(StatusCodes.Status500InternalServerError); } } // Get: api/GetPdf/WhatYouShouldKnow [HttpGet("WhatYouShouldKnow")] [ProducesResponseType(200)] [ProducesResponseType(201)] [ProducesResponseType(400)] [ProducesResponseType(404)] [ProducesResponseType(500)] public IActionResult GetPdfWhatYouShouldKnow() { try { var result = _pdfService.GetFileBytes(_appControlConfig.WhatYouShouldKnowPdfFilePath); var payload = new FileContentResult(result, "application/octet-stream"); return payload; } catch (ArgumentException ae) { Log.Error(ae, $"Request for bad file path What You Should Know About Home Equity Lines of Credit Revised 8-2022.pdf"); return BadRequest("File path not found"); } catch (Exception ex) { Log.Error(ex, $"Unexpected error retrieving file path What You Should Know About Home Equity Lines of Credit Revised 8-2022.pdf"); return StatusCode(StatusCodes.Status500InternalServerError); } } } }