105 lines
3.5 KiB
C#
105 lines
3.5 KiB
C#
using LCU.API.Collections.CollectionsApi.Exceptions;
|
|
using LCU.API.Collections.CollectionsApi.Services;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Serilog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LCU.API.Collections.CollectionsApi.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class CaseController : ControllerBase
|
|
{
|
|
private readonly ICaseService _caseService;
|
|
|
|
public CaseController(ICaseService caseService)
|
|
{
|
|
_caseService = caseService;
|
|
}
|
|
|
|
// GET: api/case/123
|
|
[HttpGet("{caseId}", Name = "GetCaseByCaseId")]
|
|
[ProducesResponseType(typeof(CollectionsApiLib.Models.TemenosCase), 200)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> GetCaseByCaseId([Required] int caseId)
|
|
{
|
|
try
|
|
{
|
|
if (caseId <= 0)
|
|
{
|
|
return BadRequest("Invalid Case ID");
|
|
}
|
|
|
|
var result = await _caseService.GetCaseByIdAsync(caseId);
|
|
return Ok(result);
|
|
}
|
|
catch (NotFoundException nfe)
|
|
{
|
|
return NotFound(nfe.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Error Executing GetTemenosCaseByCaseId ");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
// GET: api/case/CaseByNo/54444-143
|
|
[HttpGet("CaseByNo/{caseNo}", Name = "GetCaseByCaseNo")]
|
|
[ProducesResponseType(typeof(CollectionsApiLib.Models.TemenosCase), 200)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> GetCaseByCaseNo([Required] string caseNo)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrWhiteSpace(caseNo))
|
|
{
|
|
return BadRequest("Invalid Case No");
|
|
}
|
|
|
|
var result = await _caseService.GetCaseByCaseNoAsync(caseNo);
|
|
return Ok(result);
|
|
}
|
|
catch (NotFoundException nfe)
|
|
{
|
|
return NotFound(nfe.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Error Executing GetTemenosCaseByCaseId ");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
// GET: api/case/history/5444
|
|
[HttpGet("{caseId}/history", Name = "GetHistoryByCaseId")]
|
|
[ProducesResponseType(typeof(IReadOnlyCollection<CollectionsApiLib.Models.TemenosHistory>), 200)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<IActionResult> GetHistoryByCaseId([Required] int caseId)
|
|
{
|
|
try
|
|
{
|
|
|
|
var result = await _caseService.GetHistoryByAccountIdAsync(caseId);
|
|
return Ok(result);
|
|
}
|
|
catch (NotFoundException nfe)
|
|
{
|
|
return NotFound(nfe.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Error Executing GetTemenosCaseByCaseId ");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
}
|
|
}
|