#102: Moving Models and constants to their own library (#104)

* #102: Moving Models and constants to their own library

* #102: Updated sln file

* #102: Updated README to include step install migration tool
This commit was merged in pull request #104.
This commit is contained in:
KD
2024-08-05 20:05:57 -04:00
committed by GitHub
parent 8900afdfd2
commit a89580ac70
52 changed files with 53 additions and 25 deletions
+71
View File
@@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Icarus.Models;
using Icarus.Database.Contexts;
namespace Icarus.Controllers.V1;
[Route("api/v1/genre")]
[ApiController]
[Authorize]
public class GenreController : BaseController
{
#region Fields
private readonly ILogger<GenreController>? _logger;
private string? _connectionString;
#endregion
#region Properties
#endregion
#region Constructors
public GenreController(ILogger<GenreController> logger, IConfiguration config)
{
_logger = logger;
_config = config;
_connectionString = _config.GetConnectionString("DefaultConnection");
}
#endregion
#region HTTP Routes
[HttpGet]
public IActionResult GetGenres()
{
var genreStore = new GenreContext(_connectionString!);
var genres = genreStore!.Genres!.ToList();
if (genres.Count > 0)
{
return Ok(genres);
}
else
{
return NotFound(new List<Genre>());
}
}
[HttpGet("{id}")]
public IActionResult GetGenre(int id)
{
var genre = new Genre { Id = id };
var genreStore = new GenreContext(_connectionString!);
if (genreStore.DoesRecordExist(genre))
{
genre = genreStore.RetrieveRecord(genre);
return Ok(genre);
}
else
{
return NotFound(new Genre());
}
}
#endregion
}