Cleaning up code convention inconsistencies

This commit is contained in:
amazing-username
2019-07-04 15:57:43 -04:00
parent bc209c2363
commit ada8fa79d3
21 changed files with 396 additions and 426 deletions
+15 -16
View File
@@ -8,25 +8,24 @@ using Icarus.Authorization;
namespace Icarus.Authorization.Handlers namespace Icarus.Authorization.Handlers
{ {
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement> public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
{
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement)
{ {
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
HasScopeRequirement requirement) {
{ return Task.CompletedTask;
if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer)) }
{
return Task.CompletedTask;
}
var scopes = context.User.FindFirst(c => c.Type == "scope" && var scopes = context.User.FindFirst(c =>
c.Issuer == requirement.Issuer).Value.Split(' '); c.Type == "scope" && c.Issuer == requirement.Issuer).Value.Split(' ');
if (scopes.Any(s => s == requirement.Scope)) if (scopes.Any(s => s == requirement.Scope))
{ {
context.Succeed(requirement); context.Succeed(requirement);
} }
return Task.CompletedTask; return Task.CompletedTask;
}
} }
}
} }
+10 -10
View File
@@ -4,16 +4,16 @@ using Microsoft.AspNetCore.Authorization;
namespace Icarus.Authorization namespace Icarus.Authorization
{ {
public class HasScopeRequirement : IAuthorizationRequirement public class HasScopeRequirement : IAuthorizationRequirement
{
public string Issuer { get; }
public string Scope { get; }
public HasScopeRequirement(string scope, string issuer)
{ {
public string Issuer { get; } Scope = scope ?? throw new ArgumentNullException(nameof(scope));
public string Scope { get; } Issuer = issuer ?? throw new ArgumentNullException(nameof(issuer));
public HasScopeRequirement(string scope, string issuer)
{
Scope = scope ?? throw new ArgumentNullException(nameof(scope));
Issuer = issuer ?? throw new ArgumentNullException(nameof(issuer));
}
} }
}
} }
+10 -12
View File
@@ -10,18 +10,16 @@ using Icarus.Models;
namespace Icarus.Database.Contexts namespace Icarus.Database.Contexts
{ {
public class AlbumContext : DbContext public class AlbumContext : DbContext
{
public DbSet<Album> Albums { get; set; }
public AlbumContext(DbContextOptions<AlbumContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
public DbSet<Album> Albums { get; set; } modelBuilder.Entity<Album>()
.ToTable("Album");
public AlbumContext(DbContextOptions<AlbumContext> options)
: base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Album>()
.ToTable("Album");
}
} }
}
} }
+10 -12
View File
@@ -10,18 +10,16 @@ using Icarus.Models;
namespace Icarus.Database.Contexts namespace Icarus.Database.Contexts
{ {
public class ArtistContext : DbContext public class ArtistContext : DbContext
{
public DbSet<Artist> Artists { get; set; }
public ArtistContext(DbContextOptions<ArtistContext> options) : base (options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
public DbSet<Artist> Artists { get; set; } modelBuilder.Entity<Artist>()
.ToTable("Artist");
public ArtistContext(DbContextOptions<ArtistContext> options)
: base (options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Artist>()
.ToTable("Artist");
}
} }
}
} }
+9 -12
View File
@@ -10,18 +10,15 @@ using Icarus.Models;
namespace Icarus.Database.Contexts namespace Icarus.Database.Contexts
{ {
public class GenreContext : DbContext public class GenreContext : DbContext
{
public DbSet<Genre> Genres { get; set; }
public GenreContext(DbContextOptions<GenreContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
public DbSet<Genre> Genres { get; set; } modelBuilder.Entity<Genre>()
.ToTable("Genre");
public GenreContext(DbContextOptions<GenreContext> options)
: base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Genre>()
.ToTable("Genre");
}
} }
}
} }
+45 -47
View File
@@ -10,59 +10,57 @@ using Icarus.Models;
namespace Icarus.Database.Contexts namespace Icarus.Database.Contexts
{ {
public class SongContext : DbContext public class SongContext : DbContext
{ {
public DbSet<Song> Songs { get; set; } public DbSet<Song> Songs { get; set; }
public SongContext(DbContextOptions<SongContext> options) public SongContext(DbContextOptions<SongContext> options) : base(options) { }
: base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.ToTable("Song"); .ToTable("Song");
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.HasOne(s => s.Album) .HasOne(s => s.Album)
.WithMany(al => al.Songs) .WithMany(al => al.Songs)
.HasForeignKey(s => s.AlbumId) .HasForeignKey(s => s.AlbumId)
.OnDelete(DeleteBehavior.SetNull); .OnDelete(DeleteBehavior.SetNull);
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.HasOne(sa => sa.SongArtist) .HasOne(sa => sa.SongArtist)
.WithMany(ar => ar.Songs) .WithMany(ar => ar.Songs)
.HasForeignKey(s => s.ArtistId) .HasForeignKey(s => s.ArtistId)
.OnDelete(DeleteBehavior.SetNull); .OnDelete(DeleteBehavior.SetNull);
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.HasOne(s => s.SongGenre) .HasOne(s => s.SongGenre)
.WithMany(gnr => gnr.Songs) .WithMany(gnr => gnr.Songs)
.HasForeignKey(s => s.GenreId) .HasForeignKey(s => s.GenreId)
.OnDelete(DeleteBehavior.SetNull); .OnDelete(DeleteBehavior.SetNull);
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.HasOne(s => s.SongYear) .HasOne(s => s.SongYear)
.WithMany(yr => yr.Songs) .WithMany(yr => yr.Songs)
.HasForeignKey(s => s.YearId) .HasForeignKey(s => s.YearId)
.OnDelete(DeleteBehavior.SetNull); .OnDelete(DeleteBehavior.SetNull);
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.Property(s => s.Year) .Property(s => s.Year)
.IsRequired(false); .IsRequired(false);
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.Property(s => s.YearId) .Property(s => s.YearId)
.IsRequired(false); .IsRequired(false);
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.Property(s => s.GenreId) .Property(s => s.GenreId)
.IsRequired(false); .IsRequired(false);
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.Property(s => s.ArtistId) .Property(s => s.ArtistId)
.IsRequired(false); .IsRequired(false);
modelBuilder.Entity<Song>() modelBuilder.Entity<Song>()
.Property(s => s.AlbumId) .Property(s => s.AlbumId)
.IsRequired(false); .IsRequired(false);
} }
} }
} }
+14 -16
View File
@@ -10,23 +10,21 @@ using Icarus.Models;
namespace Icarus.Database.Contexts namespace Icarus.Database.Contexts
{ {
public class UserContext : DbContext public class UserContext : DbContext
{ {
public DbSet<User> Users { get; set; } public DbSet<User> Users { get; set; }
public UserContext(DbContextOptions<UserContext> options) public UserContext(DbContextOptions<UserContext> options) : base(options) { }
: base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<User>() modelBuilder.Entity<User>()
.ToTable("User"); .ToTable("User");
modelBuilder.Entity<User>() modelBuilder.Entity<User>()
.Property(u => u.LastLogin).IsRequired(false); .Property(u => u.LastLogin).IsRequired(false);
modelBuilder.Entity<User>() modelBuilder.Entity<User>()
.Property(u => u.DateCreated).HasDefaultValue(DateTime.Now); .Property(u => u.DateCreated).HasDefaultValue(DateTime.Now);
} }
} }
} }
+10 -12
View File
@@ -10,18 +10,16 @@ using Icarus.Models;
namespace Icarus.Database.Contexts namespace Icarus.Database.Contexts
{ {
public class YearContext : DbContext public class YearContext : DbContext
{
public DbSet<Year> YearValues { get; set; }
public YearContext(DbContextOptions<YearContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
public DbSet<Year> YearValues { get; set; } modelBuilder.Entity<Year>()
.ToTable("Year");
public YearContext(DbContextOptions<YearContext> options)
: base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Year>()
.ToTable("Year");
}
} }
}
} }
+14 -14
View File
@@ -6,19 +6,19 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class Album public class Album
{ {
[JsonProperty("id")] [JsonProperty("id")]
public int AlbumId { get; set; } public int AlbumId { get; set; }
[JsonProperty("title")] [JsonProperty("title")]
public string Title { get; set; } public string Title { get; set; }
[JsonProperty("album_artist")] [JsonProperty("album_artist")]
public string AlbumArtist { get; set; } public string AlbumArtist { get; set; }
[JsonProperty("song_count")] [JsonProperty("song_count")]
[NotMapped] [NotMapped]
public int SongCount { get; set; } public int SongCount { get; set; }
[JsonIgnore] [JsonIgnore]
public List<Song> Songs { get; set; } public List<Song> Songs { get; set; }
} }
} }
+12 -12
View File
@@ -6,17 +6,17 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class Artist public class Artist
{ {
[JsonProperty("id")] [JsonProperty("id")]
public int ArtistId { get; set; } public int ArtistId { get; set; }
[JsonProperty("name")] [JsonProperty("name")]
public string Name { get; set; } public string Name { get; set; }
[JsonProperty("song_count")] [JsonProperty("song_count")]
[NotMapped] [NotMapped]
public int SongCount { get; set; } public int SongCount { get; set; }
[JsonIgnore] [JsonIgnore]
public List<Song> Songs { get; set; } public List<Song> Songs { get; set; }
} }
} }
+5 -5
View File
@@ -4,9 +4,9 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class BaseResult public class BaseResult
{ {
[JsonProperty("message")] [JsonProperty("message")]
public string Message { get; set; } public string Message { get; set; }
} }
} }
+12 -12
View File
@@ -6,17 +6,17 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class Genre public class Genre
{ {
[JsonProperty("id")] [JsonProperty("id")]
public int GenreId { get; set; } public int GenreId { get; set; }
[JsonProperty("genre")] [JsonProperty("genre")]
public string GenreName { get; set; } public string GenreName { get; set; }
[JsonProperty("song_count")] [JsonProperty("song_count")]
[NotMapped] [NotMapped]
public int SongCount { get; set; } public int SongCount { get; set; }
[JsonIgnore] [JsonIgnore]
public List<Song> Songs { get; set; } public List<Song> Songs { get; set; }
} }
} }
+13 -13
View File
@@ -4,17 +4,17 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class LoginResult : BaseResult public class LoginResult : BaseResult
{ {
[JsonProperty("id")] [JsonProperty("id")]
public int UserId { get; set; } public int UserId { get; set; }
[JsonProperty("username")] [JsonProperty("username")]
public string Username { get; set; } public string Username { get; set; }
[JsonProperty("token")] [JsonProperty("token")]
public string Token { get; set; } public string Token { get; set; }
[JsonProperty("token_type")] [JsonProperty("token_type")]
public string TokenType { get; set; } public string TokenType { get; set; }
[JsonProperty("expiration")] [JsonProperty("expiration")]
public int Expiration { get; set; } public int Expiration { get; set; }
} }
} }
+7 -7
View File
@@ -4,11 +4,11 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class RegisterResult : BaseResult public class RegisterResult : BaseResult
{ {
[JsonProperty("username")] [JsonProperty("username")]
public string Username { get; set; } public string Username { get; set; }
[JsonProperty("successfully_registered")] [JsonProperty("successfully_registered")]
public bool SuccessfullyRegistered { get; set; } public bool SuccessfullyRegistered { get; set; }
} }
} }
+37 -37
View File
@@ -5,45 +5,45 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class Song public class Song
{ {
[JsonProperty("id")] [JsonProperty("id")]
public int Id { get; set; } public int Id { get; set; }
[JsonProperty("title")] [JsonProperty("title")]
public string Title { get; set; } public string Title { get; set; }
[JsonProperty("album")] [JsonProperty("album")]
public string AlbumTitle { get; set; } public string AlbumTitle { get; set; }
[JsonProperty("artist")] [JsonProperty("artist")]
public string Artist { get; set; } public string Artist { get; set; }
[JsonProperty("year")] [JsonProperty("year")]
public int? Year { get; set; } public int? Year { get; set; }
[JsonProperty("genre")] [JsonProperty("genre")]
public string Genre { get; set; } public string Genre { get; set; }
[JsonProperty("duration")] [JsonProperty("duration")]
public int Duration { get; set; } public int Duration { get; set; }
[JsonProperty("filename")] [JsonProperty("filename")]
public string Filename { get; set; } public string Filename { get; set; }
[JsonProperty("song_path")] [JsonProperty("song_path")]
public string SongPath { get; set; } public string SongPath { get; set; }
[JsonIgnore] [JsonIgnore]
public Album Album { get; set; } public Album Album { get; set; }
[JsonIgnore] [JsonIgnore]
public int? AlbumId { get; set; } public int? AlbumId { get; set; }
[JsonIgnore] [JsonIgnore]
public Artist SongArtist { get; set; } public Artist SongArtist { get; set; }
[JsonIgnore] [JsonIgnore]
public int? ArtistId { get; set; } public int? ArtistId { get; set; }
[JsonIgnore] [JsonIgnore]
public Genre SongGenre { get; set; } public Genre SongGenre { get; set; }
[JsonIgnore] [JsonIgnore]
public int? GenreId { get; set; } public int? GenreId { get; set; }
[JsonIgnore] [JsonIgnore]
public Year SongYear { get; set; } public Year SongYear { get; set; }
[JsonIgnore] [JsonIgnore]
public int? YearId { get; set; } public int? YearId { get; set; }
} }
} }
+6 -6
View File
@@ -3,10 +3,10 @@ using System.Text;
namespace Icarus.Models namespace Icarus.Models
{ {
public class SongData public class SongData
{ {
public int Id { get; set; } public int Id { get; set; }
public byte[] Data { get; set; } public byte[] Data { get; set; }
public int SongId { get; set; } public int SongId { get; set; }
} }
} }
+7 -7
View File
@@ -4,11 +4,11 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class SongResult public class SongResult
{ {
[JsonProperty("message")] [JsonProperty("message")]
public string Message { get; set; } public string Message { get; set; }
[JsonProperty("song_title")] [JsonProperty("song_title")]
public string SongTitle { get; set; } public string SongTitle { get; set; }
} }
} }
+25 -25
View File
@@ -4,29 +4,29 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class User public class User
{ {
[JsonProperty("id")] [JsonProperty("id")]
public int Id { get; set; } public int Id { get; set; }
[JsonProperty("username")] [JsonProperty("username")]
public string Username { get; set; } public string Username { get; set; }
[JsonProperty("nickname")] [JsonProperty("nickname")]
public string Nickname { get; set; } public string Nickname { get; set; }
[JsonProperty("password")] [JsonProperty("password")]
public string Password { get; set; } public string Password { get; set; }
[JsonProperty("email")] [JsonProperty("email")]
public string Email { get; set; } public string Email { get; set; }
[JsonProperty("phone_number")] [JsonProperty("phone_number")]
public string PhoneNumber { get; set; } public string PhoneNumber { get; set; }
[JsonProperty("first_name")] [JsonProperty("first_name")]
public string Firstname { get; set; } public string Firstname { get; set; }
[JsonProperty("last_name")] [JsonProperty("last_name")]
public string Lastname { get; set; } public string Lastname { get; set; }
[JsonProperty("email_verified")] [JsonProperty("email_verified")]
public bool EmailVerified { get; set; } public bool EmailVerified { get; set; }
[JsonProperty("date_created")] [JsonProperty("date_created")]
public DateTime DateCreated { get; set; } public DateTime DateCreated { get; set; }
[JsonProperty("last_login")] [JsonProperty("last_login")]
public DateTime? LastLogin { get; set; } public DateTime? LastLogin { get; set; }
} }
} }
+12 -12
View File
@@ -6,17 +6,17 @@ using Newtonsoft.Json;
namespace Icarus.Models namespace Icarus.Models
{ {
public class Year public class Year
{ {
[JsonProperty("id")] [JsonProperty("id")]
public int YearId { get; set; } public int YearId { get; set; }
[JsonProperty("year")] [JsonProperty("year")]
public int YearValue { get; set; } public int YearValue { get; set; }
[JsonProperty("song_count")] [JsonProperty("song_count")]
[NotMapped] [NotMapped]
public int SongCount { get; set; } public int SongCount { get; set; }
[JsonIgnore] [JsonIgnore]
public List<Song> Songs { get; set; } public List<Song> Songs { get; set; }
} }
} }
+29 -30
View File
@@ -12,37 +12,36 @@ using NLog.Web;
namespace Icarus namespace Icarus
{ {
public class Program public class Program
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
try try
{ {
logger.Debug("init main"); logger.Debug("init main");
CreateWebHostBuilder(args).Build().Run(); CreateWebHostBuilder(args).Build().Run();
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.Error(ex, "An error occurred"); logger.Error(ex, "An error occurred");
throw; throw;
} }
finally finally
{ {
NLog.LogManager.Shutdown(); NLog.LogManager.Shutdown();
} }
} }
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args) WebHost.CreateDefaultBuilder(args).UseStartup<Startup>()
.UseStartup<Startup>() .UseUrls("http://localhost:5002")
.UseUrls("http://localhost:5002") .ConfigureLogging(logging =>
.ConfigureLogging(logging => {
{ logging.ClearProviders();
logging.ClearProviders(); logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); })
}) .UseNLog();
.UseNLog() ;
} }
} }
+94 -109
View File
@@ -29,140 +29,125 @@ using Icarus.Database.Repositories;
namespace Icarus namespace Icarus
{ {
public class Startup public class Startup
{ {
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration)
{ {
Configuration = configuration; Configuration = configuration;
} }
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSingleton<IConfiguration>(Configuration); services.AddSingleton<IConfiguration>(Configuration);
string domain = $"https://{Configuration["Auth0:Domain"]}/"; string domain = $"https://{Configuration["Auth0:Domain"]}/";
services.AddAuthentication(options => services.AddAuthentication(options =>
{ {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options => }).AddJwtBearer(options =>
{ {
options.Authority = domain; options.Authority = domain;
options.Audience = Configuration["Auth0:ApiIdentifier"]; options.Audience = Configuration["Auth0:ApiIdentifier"];
}); });
services.AddAuthorization(options => services.AddAuthorization(options =>
{ {
options.AddPolicy("download:songs", policy => options.AddPolicy("download:songs", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("download:songs", domain)));
.Add(new HasScopeRequirement("download:songs", domain)));
options.AddPolicy("upload:songs", policy => options.AddPolicy("upload:songs", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("upload:songs", domain)));
.Add(new HasScopeRequirement("upload:songs", domain)));
options.AddPolicy("delete:songs", policy => options.AddPolicy("delete:songs", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("delete:songs", domain)));
.Add(new HasScopeRequirement("delete:songs", domain)));
options.AddPolicy("read:song_details", policy => options.AddPolicy("read:song_details", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("read:song_details", domain)));
.Add(new HasScopeRequirement("read:song_details", domain)));
options.AddPolicy("update:songs", policy => options.AddPolicy("update:songs", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("update:songs", domain)));
.Add(new HasScopeRequirement("update:songs", domain)));
options.AddPolicy("read:artists", policy => options.AddPolicy("read:artists", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("read:artists", domain)));
.Add(new HasScopeRequirement("read:artists", domain)));
options.AddPolicy("read:albums", policy => options.AddPolicy("read:albums", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("read:albums", domain)));
.Add(new HasScopeRequirement("read:albums", domain)));
options.AddPolicy("read:genre", policy => options.AddPolicy("read:genre", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("read:genre", domain)));
.Add(new HasScopeRequirement("read:genre", domain)));
options.AddPolicy("read:year", policy => options.AddPolicy("read:year", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("read:year", domain)));
.Add(new HasScopeRequirement("read:year", domain)));
options.AddPolicy("stream:songs", policy => options.AddPolicy("stream:songs", policy =>
policy policy.Requirements
.Requirements .Add(new HasScopeRequirement("stream:songs", domain)));
.Add(new HasScopeRequirement("stream:songs", domain))); });
});
services.AddSingleton<IAuthorizationHandler, HasScopeHandler>(); services.AddSingleton<IAuthorizationHandler, HasScopeHandler>();
var connString = Configuration.GetConnectionString("DefaultConnection"); var connString = Configuration.GetConnectionString("DefaultConnection");
services.Add(new ServiceDescriptor(typeof(SongRepository), services.Add(new ServiceDescriptor(typeof(SongRepository),
new SongRepository(Configuration new SongRepository(Configuration.GetConnectionString("DefaultConnection"))));
.GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(AlbumRepository), services.Add(new ServiceDescriptor(typeof(AlbumRepository),
new AlbumRepository(Configuration new AlbumRepository(Configuration.GetConnectionString("DefaultConnection"))));
.GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(ArtistRepository), services.Add(new ServiceDescriptor(typeof(ArtistRepository),
new ArtistRepository(Configuration new ArtistRepository(Configuration.GetConnectionString("DefaultConnection"))));
.GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(GenreRepository), services.Add(new ServiceDescriptor(typeof(GenreRepository),
new GenreRepository(Configuration new GenreRepository(Configuration.GetConnectionString("DefaultConnection"))));
.GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(YearRepository), services.Add(new ServiceDescriptor(typeof(YearRepository),
new YearRepository(Configuration new YearRepository(Configuration.GetConnectionString("DefaultConnection"))));
.GetConnectionString("DefaultConnection"))));
services.Add(new ServiceDescriptor(typeof(UserRepository), services.Add(new ServiceDescriptor(typeof(UserRepository),
new UserRepository(Configuration new UserRepository(Configuration.GetConnectionString("DefaultConnection"))));
.GetConnectionString("DefaultConnection"))));
services.AddDbContext<SongContext>(options => options.UseMySQL(connString)); services.AddDbContext<SongContext>(options => options.UseMySQL(connString));
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));
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString)); services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
services.AddDbContext<YearContext>(options => options.UseMySQL(connString)); services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // Called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{ {
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
else else
{ {
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days.
app.UseHsts(); // You may want to change this for production scenarios
} app.UseHsts();
}
app.UseAuthentication(); app.UseAuthentication();
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseMvc(); app.UseMvc();
} }
} }
} }