diff --git a/Controllers/GenreController.cs b/Controllers/GenreController.cs new file mode 100644 index 0000000..bec2980 --- /dev/null +++ b/Controllers/GenreController.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; + +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +using Icarus.Models; +using Icarus.Models.Context; + +namespace Icarus.Controllers +{ + // TODO: Implement Genre API functionality #41 + [Route("api/genre")] + [ApiController] + public class GenreController : ControllerBase + { + #region Fields + private readonly ILogger _logger; + #endregion + + + #region Properties + #endregion + + + #region Constructors + public GenreController(ILogger logger) + { + _logger = logger; + } + #endregion + + + #region HTTP Routes + [HttpGet] + public IActionResult Get() + { + var genres = new List(); + + return Ok(genres); + } + + [HttpGet("{id}")] + public IActionResult Get(int id) + { + var genre = new Genre + { + GenreId = id + }; + + return Ok(genre); + } + #endregion + } +} diff --git a/Controllers/YearController.cs b/Controllers/YearController.cs new file mode 100644 index 0000000..e2bce75 --- /dev/null +++ b/Controllers/YearController.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; + +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +using Icarus.Models; +using Icarus.Models.Context; + +namespace Icarus.Controller +{ + // TODO: Implemnt Year API functionality #42 + [Route("api/year")] + [ApiController] + public class YearController : ControllerBase + { + #region Fields + private readonly ILogger _logger; + #endregion + + + #region Properties + #endregion + + + #region Constructors + public YearController(ILogger logger) + { + _logger = logger; + } + #endregion + + + #region HTTP Routes + [HttpGet] + public IActionResult Get() + { + var yearValues = new List(); + + return Ok(); + } + + [HttpGet("{id}")] + public IActionResult Get(int id) + { + var year = new Year + { + YearId = id + }; + + return Ok(year); + } + #endregion + } +} diff --git a/Models/Context/AlbumStoreContext.cs b/Models/Context/AlbumStoreContext.cs index 44968f6..7697dce 100644 --- a/Models/Context/AlbumStoreContext.cs +++ b/Models/Context/AlbumStoreContext.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Globalization; using MySql.Data.MySqlClient; -//using NLog; using Icarus.Models; @@ -12,7 +11,6 @@ namespace Icarus.Models.Context public class AlbumStoreContext : BaseStoreContext { #region Fields - //private static Logger _logger = NLog.LogManager.GetCurrentClassLogger(); #endregion diff --git a/Models/Context/GenreContext.cs b/Models/Context/GenreContext.cs new file mode 100644 index 0000000..08c8ebe --- /dev/null +++ b/Models/Context/GenreContext.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +using Microsoft.EntityFrameworkCore; +using MySql.Data; +using MySql.Data.EntityFrameworkCore.Extensions; +using MySql.Data.MySqlClient; + +using Icarus.Models; + +namespace Icarus.Models.Context +{ + public class GenreContext : DbContext + { + public DbSet Genres { get; set; } + + public GenreContext(DbContextOptions options) + : base(options) + { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .ToTable("Genre"); + } + } +} diff --git a/Models/Context/GenreStoreContext.cs b/Models/Context/GenreStoreContext.cs new file mode 100644 index 0000000..6f23986 --- /dev/null +++ b/Models/Context/GenreStoreContext.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Globalization; + +using MySql.Data.MySqlClient; + +using Icarus.Models; + +namespace Icarus.Models.Context +{ + // TODO: Implement Genre store #41 + public class GenreStoreContext : BaseStoreContext + { + #region Fields + #endregion + + + #region Properties + #endregion + + + #region Constructors + public GenreStoreContext(string connectionString) + { + _connectionString = connectionString; + } + #endregion + + + #region Methods + #endregion + } +} diff --git a/Models/Context/YearContext.cs b/Models/Context/YearContext.cs new file mode 100644 index 0000000..f11114a --- /dev/null +++ b/Models/Context/YearContext.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +using Microsoft.EntityFrameworkCore; +using MySql.Data; +using MySql.Data.EntityFrameworkCore.Extensions; +using MySql.Data.MySqlClient; + +using Icarus.Models; + +namespace Icarus.Models.Context +{ + public class YearContext : DbContext + { + public DbSet YearValues { get; set; } + + public YearContext(DbContextOptions options) + : base(options) + { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .ToTable("Year"); + } + } +} diff --git a/Models/Context/YearStoreContext.cs b/Models/Context/YearStoreContext.cs new file mode 100644 index 0000000..dcef60b --- /dev/null +++ b/Models/Context/YearStoreContext.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Globalization; + +using MySql.Data.MySqlClient; + +using Icarus.Models; + +namespace Icarus.Models.Context +{ + // TODO: Implement Year store #42 + public class YearStoreContext : BaseStoreContext + { + #region Fields + #endregion + + + #region Properties + #endregion + + + #region Constructors + public YearStoreContext(string connectionString) + { + _connectionString = connectionString; + } + #endregion + + + #region Methods + #endregion + } +} diff --git a/Models/Genre.cs b/Models/Genre.cs new file mode 100644 index 0000000..f915e9c --- /dev/null +++ b/Models/Genre.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +using Newtonsoft.Json; + +namespace Icarus.Models +{ + public class Genre + { + [JsonProperty("id")] + public int GenreId { get; set; } + [JsonProperty("genre")] + public string GenreName { get; set; } + [JsonProperty("song_count")] + public int SongCount { get; set; } + + [JsonIgnore] + public List Songs { get; set; } + } +} diff --git a/Models/Year.cs b/Models/Year.cs new file mode 100644 index 0000000..9223eaa --- /dev/null +++ b/Models/Year.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +using Newtonsoft.Json; + +namespace Icarus.Models +{ + public class Year + { + [JsonProperty("id")] + public int YearId { get; set; } + [JsonProperty("year")] + public int YearValue { get; set; } + [JsonProperty("song_count")] + public int SongCount { get; set; } + + [JsonIgnore] + public List Songs { get; set; } + } +} diff --git a/Startup.cs b/Startup.cs index c6123a0..932f32b 100644 --- a/Startup.cs +++ b/Startup.cs @@ -98,6 +98,7 @@ namespace Icarus var connString = Configuration.GetConnectionString("DefaultConnection"); + // TODO: Add the Genre and Year stores #41 and #42. services.Add(new ServiceDescriptor(typeof(MusicStoreContext), new MusicStoreContext(Configuration .GetConnectionString("DefaultConnection")))); @@ -118,6 +119,7 @@ namespace Icarus services.AddDbContext(options => options.UseMySQL(connString)); services.AddDbContext(options => options.UseMySQL(connString)); services.AddDbContext(options => options.UseMySQL(connString)); + // TODO: Add the Genre and Year contexts #41 and #42 } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.