78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Collections.RepoApi.Configuration;
|
|
using LCU.API.Collections.RepoApi.Exceptions;
|
|
using LCU.API.Collections.RepoApi.Services;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.FeatureManagement.Mvc;
|
|
using Serilog;
|
|
|
|
namespace LCU.API.Collections.RepoApi.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[FeatureGate(FeatureFlags.EnableControllers)]
|
|
public class RepoCompanySelectionController : RepoControllerBase
|
|
{
|
|
private readonly IRepoCompanySelectionService _repoCompanySelectionService;
|
|
|
|
public RepoCompanySelectionController(
|
|
IRepoCompanySelectionService repoCompanySelectionService,
|
|
IHttpContextAccessor httpContextAccessor) :
|
|
base(httpContextAccessor)
|
|
{
|
|
_repoCompanySelectionService = repoCompanySelectionService;
|
|
}
|
|
|
|
// GET: api/RepoCompanySelection
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(IEnumerable<RepoCompanySelection>), 200)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<ActionResult> Get()
|
|
{
|
|
try
|
|
{
|
|
var repoCompanySelections = await _repoCompanySelectionService.ListAllAsync();
|
|
return Ok(repoCompanySelections);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
|
|
// GET: api/RepoCompanySelection/5
|
|
[HttpGet("{id}", Name = "GetRepoCompanySelectionById")]
|
|
[ProducesResponseType(typeof(RepoCompanySelection), 200)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[ProducesResponseType(typeof(string), 404)]
|
|
[ProducesResponseType(500)]
|
|
public async Task<ActionResult> Get(int id)
|
|
{
|
|
try
|
|
{
|
|
if (id <= 0)
|
|
{
|
|
return BadRequest("Invalid ID");
|
|
}
|
|
|
|
var repoCompanySelection = await _repoCompanySelectionService.GetAsync(id);
|
|
return Ok(repoCompanySelection);
|
|
}
|
|
catch (NotFoundException nfe)
|
|
{
|
|
return NotFound(nfe.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure in {GetType().Name} at {GetInvokerAsyncMethodName()}");
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
}
|
|
}
|
|
}
|