Added Genre and Year models, Genre and Year Context, Genre and Year Stores, Genre and Year skeleton APIControllers #41 and #42
This commit is contained in:
@@ -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<GenreController> _logger;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public GenreController(ILogger<GenreController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region HTTP Routes
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Get()
|
||||||
|
{
|
||||||
|
var genres = new List<Genre>();
|
||||||
|
|
||||||
|
return Ok(genres);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public IActionResult Get(int id)
|
||||||
|
{
|
||||||
|
var genre = new Genre
|
||||||
|
{
|
||||||
|
GenreId = id
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(genre);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<YearController> _logger;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public YearController(ILogger<YearController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region HTTP Routes
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Get()
|
||||||
|
{
|
||||||
|
var yearValues = new List<Year>();
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public IActionResult Get(int id)
|
||||||
|
{
|
||||||
|
var year = new Year
|
||||||
|
{
|
||||||
|
YearId = id
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(year);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
using MySql.Data.MySqlClient;
|
using MySql.Data.MySqlClient;
|
||||||
//using NLog;
|
|
||||||
|
|
||||||
using Icarus.Models;
|
using Icarus.Models;
|
||||||
|
|
||||||
@@ -12,7 +11,6 @@ namespace Icarus.Models.Context
|
|||||||
public class AlbumStoreContext : BaseStoreContext
|
public class AlbumStoreContext : BaseStoreContext
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
//private static Logger _logger = NLog.LogManager.GetCurrentClassLogger();
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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<Genre> Genres { get; set; }
|
||||||
|
|
||||||
|
public GenreContext(DbContextOptions<GenreContext> options)
|
||||||
|
: base(options)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Entity<Genre>()
|
||||||
|
.ToTable("Genre");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<Year> YearValues { get; set; }
|
||||||
|
|
||||||
|
public YearContext(DbContextOptions<YearContext> options)
|
||||||
|
: base(options)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Entity<Year>()
|
||||||
|
.ToTable("Year");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<Song> Songs { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<Song> Songs { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -98,6 +98,7 @@ namespace Icarus
|
|||||||
|
|
||||||
var connString = Configuration.GetConnectionString("DefaultConnection");
|
var connString = Configuration.GetConnectionString("DefaultConnection");
|
||||||
|
|
||||||
|
// TODO: Add the Genre and Year stores #41 and #42.
|
||||||
services.Add(new ServiceDescriptor(typeof(MusicStoreContext),
|
services.Add(new ServiceDescriptor(typeof(MusicStoreContext),
|
||||||
new MusicStoreContext(Configuration
|
new MusicStoreContext(Configuration
|
||||||
.GetConnectionString("DefaultConnection"))));
|
.GetConnectionString("DefaultConnection"))));
|
||||||
@@ -118,6 +119,7 @@ namespace Icarus
|
|||||||
services.AddDbContext<AlbumContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<AlbumContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<ArtistContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<ArtistContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<UserContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<UserContext>(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.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
|||||||
Reference in New Issue
Block a user