From ada8fa79d3a8617c4c340f78fb7ae0fba1ee06ab Mon Sep 17 00:00:00 2001 From: amazing-username Date: Thu, 4 Jul 2019 15:57:43 -0400 Subject: [PATCH] Cleaning up code convention inconsistencies --- Authorization/Handlers/HasScopeHandler.cs | 31 ++-- Authorization/HasScopeRequirement.cs | 20 +-- Database/Contexts/AlbumContext.cs | 22 ++- Database/Contexts/ArtistContext.cs | 22 ++- Database/Contexts/GenreContext.cs | 21 +-- Database/Contexts/SongContext.cs | 92 +++++----- Database/Contexts/UserContext.cs | 30 ++-- Database/Contexts/YearContext.cs | 22 ++- Models/Album.cs | 28 +-- Models/Artist.cs | 24 +-- Models/BaseResult.cs | 10 +- Models/Genre.cs | 24 +-- Models/LoginResult.cs | 26 +-- Models/RegisterResult.cs | 14 +- Models/Song.cs | 74 ++++---- Models/SongData.cs | 12 +- Models/SongResult.cs | 14 +- Models/User.cs | 50 +++--- Models/Year.cs | 24 +-- Program.cs | 59 ++++--- Startup.cs | 203 ++++++++++------------ 21 files changed, 396 insertions(+), 426 deletions(-) diff --git a/Authorization/Handlers/HasScopeHandler.cs b/Authorization/Handlers/HasScopeHandler.cs index ca3be48..7c50cf4 100644 --- a/Authorization/Handlers/HasScopeHandler.cs +++ b/Authorization/Handlers/HasScopeHandler.cs @@ -8,25 +8,24 @@ using Icarus.Authorization; namespace Icarus.Authorization.Handlers { - public class HasScopeHandler : AuthorizationHandler + public class HasScopeHandler : AuthorizationHandler + { + protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement) { - protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, - HasScopeRequirement requirement) - { - if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer)) - { - 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" && - c.Issuer == requirement.Issuer).Value.Split(' '); + var scopes = context.User.FindFirst(c => + c.Type == "scope" && c.Issuer == requirement.Issuer).Value.Split(' '); - if (scopes.Any(s => s == requirement.Scope)) - { - context.Succeed(requirement); - } + if (scopes.Any(s => s == requirement.Scope)) + { + context.Succeed(requirement); + } - return Task.CompletedTask; - } + return Task.CompletedTask; } + } } diff --git a/Authorization/HasScopeRequirement.cs b/Authorization/HasScopeRequirement.cs index 819b7f7..d62bda5 100644 --- a/Authorization/HasScopeRequirement.cs +++ b/Authorization/HasScopeRequirement.cs @@ -4,16 +4,16 @@ using Microsoft.AspNetCore.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; } - public string Scope { get; } - - - public HasScopeRequirement(string scope, string issuer) - { - Scope = scope ?? throw new ArgumentNullException(nameof(scope)); - Issuer = issuer ?? throw new ArgumentNullException(nameof(issuer)); - } + Scope = scope ?? throw new ArgumentNullException(nameof(scope)); + Issuer = issuer ?? throw new ArgumentNullException(nameof(issuer)); } + } } diff --git a/Database/Contexts/AlbumContext.cs b/Database/Contexts/AlbumContext.cs index e367e8b..640cb23 100644 --- a/Database/Contexts/AlbumContext.cs +++ b/Database/Contexts/AlbumContext.cs @@ -10,18 +10,16 @@ using Icarus.Models; namespace Icarus.Database.Contexts { - public class AlbumContext : DbContext + public class AlbumContext : DbContext + { + public DbSet Albums { get; set; } + + public AlbumContext(DbContextOptions options) : base(options) { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) { - public DbSet Albums { get; set; } - - public AlbumContext(DbContextOptions options) - : base(options) - { } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity() - .ToTable("Album"); - } + modelBuilder.Entity() + .ToTable("Album"); } + } } diff --git a/Database/Contexts/ArtistContext.cs b/Database/Contexts/ArtistContext.cs index 0acda95..fa2afcb 100644 --- a/Database/Contexts/ArtistContext.cs +++ b/Database/Contexts/ArtistContext.cs @@ -10,18 +10,16 @@ using Icarus.Models; namespace Icarus.Database.Contexts { - public class ArtistContext : DbContext + public class ArtistContext : DbContext + { + public DbSet Artists { get; set; } + + public ArtistContext(DbContextOptions options) : base (options) { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) { - public DbSet Artists { get; set; } - - public ArtistContext(DbContextOptions options) - : base (options) - { } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity() - .ToTable("Artist"); - } + modelBuilder.Entity() + .ToTable("Artist"); } + } } diff --git a/Database/Contexts/GenreContext.cs b/Database/Contexts/GenreContext.cs index 0393fae..ceb137e 100644 --- a/Database/Contexts/GenreContext.cs +++ b/Database/Contexts/GenreContext.cs @@ -10,18 +10,15 @@ using Icarus.Models; namespace Icarus.Database.Contexts { - public class GenreContext : DbContext + public class GenreContext : DbContext + { + public DbSet Genres { get; set; } + public GenreContext(DbContextOptions options) : base(options) { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) { - public DbSet Genres { get; set; } - - public GenreContext(DbContextOptions options) - : base(options) - { } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity() - .ToTable("Genre"); - } + modelBuilder.Entity() + .ToTable("Genre"); } + } } diff --git a/Database/Contexts/SongContext.cs b/Database/Contexts/SongContext.cs index 08c6359..1a70a88 100644 --- a/Database/Contexts/SongContext.cs +++ b/Database/Contexts/SongContext.cs @@ -10,59 +10,57 @@ using Icarus.Models; namespace Icarus.Database.Contexts { - public class SongContext : DbContext - { - public DbSet Songs { get; set; } + public class SongContext : DbContext + { + public DbSet Songs { get; set; } - public SongContext(DbContextOptions options) - : base(options) - { } + public SongContext(DbContextOptions options) : base(options) { } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity() - .ToTable("Song"); + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .ToTable("Song"); - modelBuilder.Entity() - .HasOne(s => s.Album) - .WithMany(al => al.Songs) - .HasForeignKey(s => s.AlbumId) - .OnDelete(DeleteBehavior.SetNull); + modelBuilder.Entity() + .HasOne(s => s.Album) + .WithMany(al => al.Songs) + .HasForeignKey(s => s.AlbumId) + .OnDelete(DeleteBehavior.SetNull); - modelBuilder.Entity() - .HasOne(sa => sa.SongArtist) - .WithMany(ar => ar.Songs) - .HasForeignKey(s => s.ArtistId) - .OnDelete(DeleteBehavior.SetNull); + modelBuilder.Entity() + .HasOne(sa => sa.SongArtist) + .WithMany(ar => ar.Songs) + .HasForeignKey(s => s.ArtistId) + .OnDelete(DeleteBehavior.SetNull); - modelBuilder.Entity() - .HasOne(s => s.SongGenre) - .WithMany(gnr => gnr.Songs) - .HasForeignKey(s => s.GenreId) - .OnDelete(DeleteBehavior.SetNull); + modelBuilder.Entity() + .HasOne(s => s.SongGenre) + .WithMany(gnr => gnr.Songs) + .HasForeignKey(s => s.GenreId) + .OnDelete(DeleteBehavior.SetNull); - modelBuilder.Entity() - .HasOne(s => s.SongYear) - .WithMany(yr => yr.Songs) - .HasForeignKey(s => s.YearId) - .OnDelete(DeleteBehavior.SetNull); + modelBuilder.Entity() + .HasOne(s => s.SongYear) + .WithMany(yr => yr.Songs) + .HasForeignKey(s => s.YearId) + .OnDelete(DeleteBehavior.SetNull); - modelBuilder.Entity() - .Property(s => s.Year) - .IsRequired(false); - modelBuilder.Entity() - .Property(s => s.YearId) - .IsRequired(false); - modelBuilder.Entity() - .Property(s => s.GenreId) - .IsRequired(false); - modelBuilder.Entity() - .Property(s => s.ArtistId) - .IsRequired(false); - modelBuilder.Entity() - .Property(s => s.AlbumId) - .IsRequired(false); - } - } + modelBuilder.Entity() + .Property(s => s.Year) + .IsRequired(false); + modelBuilder.Entity() + .Property(s => s.YearId) + .IsRequired(false); + modelBuilder.Entity() + .Property(s => s.GenreId) + .IsRequired(false); + modelBuilder.Entity() + .Property(s => s.ArtistId) + .IsRequired(false); + modelBuilder.Entity() + .Property(s => s.AlbumId) + .IsRequired(false); + } + } } diff --git a/Database/Contexts/UserContext.cs b/Database/Contexts/UserContext.cs index 80e1177..313b34e 100644 --- a/Database/Contexts/UserContext.cs +++ b/Database/Contexts/UserContext.cs @@ -10,23 +10,21 @@ using Icarus.Models; namespace Icarus.Database.Contexts { - public class UserContext : DbContext - { - public DbSet Users { get; set; } + public class UserContext : DbContext + { + public DbSet Users { get; set; } - public UserContext(DbContextOptions options) - : base(options) - { } + public UserContext(DbContextOptions options) : base(options) { } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity() - .ToTable("User"); - modelBuilder.Entity() - .Property(u => u.LastLogin).IsRequired(false); - modelBuilder.Entity() - .Property(u => u.DateCreated).HasDefaultValue(DateTime.Now); - } - } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .ToTable("User"); + modelBuilder.Entity() + .Property(u => u.LastLogin).IsRequired(false); + modelBuilder.Entity() + .Property(u => u.DateCreated).HasDefaultValue(DateTime.Now); + } + } } diff --git a/Database/Contexts/YearContext.cs b/Database/Contexts/YearContext.cs index 134d55e..7074468 100644 --- a/Database/Contexts/YearContext.cs +++ b/Database/Contexts/YearContext.cs @@ -10,18 +10,16 @@ using Icarus.Models; namespace Icarus.Database.Contexts { - public class YearContext : DbContext + public class YearContext : DbContext + { + public DbSet YearValues { get; set; } + + public YearContext(DbContextOptions options) : base(options) { } + + protected override void OnModelCreating(ModelBuilder modelBuilder) { - public DbSet YearValues { get; set; } - - public YearContext(DbContextOptions options) - : base(options) - { } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity() - .ToTable("Year"); - } + modelBuilder.Entity() + .ToTable("Year"); } + } } diff --git a/Models/Album.cs b/Models/Album.cs index 0d3c9f2..7a120b0 100644 --- a/Models/Album.cs +++ b/Models/Album.cs @@ -6,19 +6,19 @@ using Newtonsoft.Json; namespace Icarus.Models { - public class Album - { - [JsonProperty("id")] - public int AlbumId { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - [JsonProperty("album_artist")] - public string AlbumArtist { get; set; } - [JsonProperty("song_count")] - [NotMapped] - public int SongCount { get; set; } + public class Album + { + [JsonProperty("id")] + public int AlbumId { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("album_artist")] + public string AlbumArtist { get; set; } + [JsonProperty("song_count")] + [NotMapped] + public int SongCount { get; set; } - [JsonIgnore] - public List Songs { get; set; } - } + [JsonIgnore] + public List Songs { get; set; } + } } diff --git a/Models/Artist.cs b/Models/Artist.cs index 807d3e4..dee0d6a 100644 --- a/Models/Artist.cs +++ b/Models/Artist.cs @@ -6,17 +6,17 @@ using Newtonsoft.Json; namespace Icarus.Models { - public class Artist - { - [JsonProperty("id")] - public int ArtistId { get; set; } - [JsonProperty("name")] - public string Name { get; set; } - [JsonProperty("song_count")] - [NotMapped] - public int SongCount { get; set; } + public class Artist + { + [JsonProperty("id")] + public int ArtistId { get; set; } + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("song_count")] + [NotMapped] + public int SongCount { get; set; } - [JsonIgnore] - public List Songs { get; set; } - } + [JsonIgnore] + public List Songs { get; set; } + } } diff --git a/Models/BaseResult.cs b/Models/BaseResult.cs index f66f0f6..2b3ef1a 100644 --- a/Models/BaseResult.cs +++ b/Models/BaseResult.cs @@ -4,9 +4,9 @@ using Newtonsoft.Json; namespace Icarus.Models { - public class BaseResult - { - [JsonProperty("message")] - public string Message { get; set; } - } + public class BaseResult + { + [JsonProperty("message")] + public string Message { get; set; } + } } diff --git a/Models/Genre.cs b/Models/Genre.cs index c6913c6..7ba1ada 100644 --- a/Models/Genre.cs +++ b/Models/Genre.cs @@ -6,17 +6,17 @@ 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")] - [NotMapped] - public int SongCount { get; set; } + public class Genre + { + [JsonProperty("id")] + public int GenreId { get; set; } + [JsonProperty("genre")] + public string GenreName { get; set; } + [JsonProperty("song_count")] + [NotMapped] + public int SongCount { get; set; } - [JsonIgnore] - public List Songs { get; set; } - } + [JsonIgnore] + public List Songs { get; set; } + } } diff --git a/Models/LoginResult.cs b/Models/LoginResult.cs index 3a48b5b..ef08a26 100644 --- a/Models/LoginResult.cs +++ b/Models/LoginResult.cs @@ -4,17 +4,17 @@ using Newtonsoft.Json; namespace Icarus.Models { - public class LoginResult : BaseResult - { - [JsonProperty("id")] - public int UserId { get; set; } - [JsonProperty("username")] - public string Username { get; set; } - [JsonProperty("token")] - public string Token { get; set; } - [JsonProperty("token_type")] - public string TokenType { get; set; } - [JsonProperty("expiration")] - public int Expiration { get; set; } - } + public class LoginResult : BaseResult + { + [JsonProperty("id")] + public int UserId { get; set; } + [JsonProperty("username")] + public string Username { get; set; } + [JsonProperty("token")] + public string Token { get; set; } + [JsonProperty("token_type")] + public string TokenType { get; set; } + [JsonProperty("expiration")] + public int Expiration { get; set; } + } } diff --git a/Models/RegisterResult.cs b/Models/RegisterResult.cs index 055f397..31a8641 100644 --- a/Models/RegisterResult.cs +++ b/Models/RegisterResult.cs @@ -4,11 +4,11 @@ using Newtonsoft.Json; namespace Icarus.Models { - public class RegisterResult : BaseResult - { - [JsonProperty("username")] - public string Username { get; set; } - [JsonProperty("successfully_registered")] - public bool SuccessfullyRegistered { get; set; } - } + public class RegisterResult : BaseResult + { + [JsonProperty("username")] + public string Username { get; set; } + [JsonProperty("successfully_registered")] + public bool SuccessfullyRegistered { get; set; } + } } diff --git a/Models/Song.cs b/Models/Song.cs index 69620d5..d73815e 100644 --- a/Models/Song.cs +++ b/Models/Song.cs @@ -5,45 +5,45 @@ using Newtonsoft.Json; namespace Icarus.Models { - public class Song - { - [JsonProperty("id")] - public int Id { get; set; } - [JsonProperty("title")] - public string Title { get; set; } - [JsonProperty("album")] - public string AlbumTitle { get; set; } - [JsonProperty("artist")] - public string Artist { get; set; } - [JsonProperty("year")] - public int? Year { get; set; } - [JsonProperty("genre")] - public string Genre { get; set; } - [JsonProperty("duration")] - public int Duration { get; set; } - [JsonProperty("filename")] - public string Filename { get; set; } - [JsonProperty("song_path")] - public string SongPath { get; set; } + public class Song + { + [JsonProperty("id")] + public int Id { get; set; } + [JsonProperty("title")] + public string Title { get; set; } + [JsonProperty("album")] + public string AlbumTitle { get; set; } + [JsonProperty("artist")] + public string Artist { get; set; } + [JsonProperty("year")] + public int? Year { get; set; } + [JsonProperty("genre")] + public string Genre { get; set; } + [JsonProperty("duration")] + public int Duration { get; set; } + [JsonProperty("filename")] + public string Filename { get; set; } + [JsonProperty("song_path")] + public string SongPath { get; set; } - [JsonIgnore] - public Album Album { get; set; } - [JsonIgnore] - public int? AlbumId { get; set; } + [JsonIgnore] + public Album Album { get; set; } + [JsonIgnore] + public int? AlbumId { get; set; } - [JsonIgnore] - public Artist SongArtist { get; set; } - [JsonIgnore] - public int? ArtistId { get; set; } + [JsonIgnore] + public Artist SongArtist { get; set; } + [JsonIgnore] + public int? ArtistId { get; set; } - [JsonIgnore] - public Genre SongGenre { get; set; } - [JsonIgnore] - public int? GenreId { get; set; } + [JsonIgnore] + public Genre SongGenre { get; set; } + [JsonIgnore] + public int? GenreId { get; set; } - [JsonIgnore] - public Year SongYear { get; set; } - [JsonIgnore] - public int? YearId { get; set; } - } + [JsonIgnore] + public Year SongYear { get; set; } + [JsonIgnore] + public int? YearId { get; set; } + } } diff --git a/Models/SongData.cs b/Models/SongData.cs index f692092..ccef51e 100644 --- a/Models/SongData.cs +++ b/Models/SongData.cs @@ -3,10 +3,10 @@ using System.Text; namespace Icarus.Models { - public class SongData - { - public int Id { get; set; } - public byte[] Data { get; set; } - public int SongId { get; set; } - } + public class SongData + { + public int Id { get; set; } + public byte[] Data { get; set; } + public int SongId { get; set; } + } } diff --git a/Models/SongResult.cs b/Models/SongResult.cs index 8918c0e..5763b3c 100644 --- a/Models/SongResult.cs +++ b/Models/SongResult.cs @@ -4,11 +4,11 @@ using Newtonsoft.Json; namespace Icarus.Models { - public class SongResult - { - [JsonProperty("message")] - public string Message { get; set; } - [JsonProperty("song_title")] - public string SongTitle { get; set; } - } + public class SongResult + { + [JsonProperty("message")] + public string Message { get; set; } + [JsonProperty("song_title")] + public string SongTitle { get; set; } + } } diff --git a/Models/User.cs b/Models/User.cs index 3bfe261..9c289d0 100644 --- a/Models/User.cs +++ b/Models/User.cs @@ -4,29 +4,29 @@ using Newtonsoft.Json; namespace Icarus.Models { - public class User - { - [JsonProperty("id")] - public int Id { get; set; } - [JsonProperty("username")] - public string Username { get; set; } - [JsonProperty("nickname")] - public string Nickname { get; set; } - [JsonProperty("password")] - public string Password { get; set; } - [JsonProperty("email")] - public string Email { get; set; } - [JsonProperty("phone_number")] - public string PhoneNumber { get; set; } - [JsonProperty("first_name")] - public string Firstname { get; set; } - [JsonProperty("last_name")] - public string Lastname { get; set; } - [JsonProperty("email_verified")] - public bool EmailVerified { get; set; } - [JsonProperty("date_created")] - public DateTime DateCreated { get; set; } - [JsonProperty("last_login")] - public DateTime? LastLogin { get; set; } - } + public class User + { + [JsonProperty("id")] + public int Id { get; set; } + [JsonProperty("username")] + public string Username { get; set; } + [JsonProperty("nickname")] + public string Nickname { get; set; } + [JsonProperty("password")] + public string Password { get; set; } + [JsonProperty("email")] + public string Email { get; set; } + [JsonProperty("phone_number")] + public string PhoneNumber { get; set; } + [JsonProperty("first_name")] + public string Firstname { get; set; } + [JsonProperty("last_name")] + public string Lastname { get; set; } + [JsonProperty("email_verified")] + public bool EmailVerified { get; set; } + [JsonProperty("date_created")] + public DateTime DateCreated { get; set; } + [JsonProperty("last_login")] + public DateTime? LastLogin { get; set; } + } } diff --git a/Models/Year.cs b/Models/Year.cs index 0ca1db2..b4e855b 100644 --- a/Models/Year.cs +++ b/Models/Year.cs @@ -6,17 +6,17 @@ 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")] - [NotMapped] - public int SongCount { get; set; } + public class Year + { + [JsonProperty("id")] + public int YearId { get; set; } + [JsonProperty("year")] + public int YearValue { get; set; } + [JsonProperty("song_count")] + [NotMapped] + public int SongCount { get; set; } - [JsonIgnore] - public List Songs { get; set; } - } + [JsonIgnore] + public List Songs { get; set; } + } } diff --git a/Program.cs b/Program.cs index 814a3f8..6d088d6 100644 --- a/Program.cs +++ b/Program.cs @@ -12,37 +12,36 @@ using NLog.Web; namespace Icarus { - public class Program - { - public static void Main(string[] args) - { - var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); + public class Program + { + public static void Main(string[] args) + { + var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); - try - { - logger.Debug("init main"); - CreateWebHostBuilder(args).Build().Run(); - } - catch (Exception ex) - { - logger.Error(ex, "An error occurred"); - throw; - } - finally - { - NLog.LogManager.Shutdown(); - } - } + try + { + logger.Debug("init main"); + CreateWebHostBuilder(args).Build().Run(); + } + catch (Exception ex) + { + logger.Error(ex, "An error occurred"); + throw; + } + finally + { + NLog.LogManager.Shutdown(); + } + } - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup() - .UseUrls("http://localhost:5002") - .ConfigureLogging(logging => - { - logging.ClearProviders(); - logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); - }) - .UseNLog() ; + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args).UseStartup() + .UseUrls("http://localhost:5002") + .ConfigureLogging(logging => + { + logging.ClearProviders(); + logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); + }) + .UseNLog(); } } diff --git a/Startup.cs b/Startup.cs index 787c341..d7851ae 100644 --- a/Startup.cs +++ b/Startup.cs @@ -29,140 +29,125 @@ using Icarus.Database.Repositories; namespace Icarus { - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } + public class Startup + { + public Startup(IConfiguration 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. - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); - services.AddSingleton(Configuration); + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + services.AddSingleton(Configuration); - string domain = $"https://{Configuration["Auth0:Domain"]}/"; + string domain = $"https://{Configuration["Auth0:Domain"]}/"; - services.AddAuthentication(options => - { - options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - }).AddJwtBearer(options => - { - options.Authority = domain; - options.Audience = Configuration["Auth0:ApiIdentifier"]; - }); + services.AddAuthentication(options => + { + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + }).AddJwtBearer(options => + { + options.Authority = domain; + options.Audience = Configuration["Auth0:ApiIdentifier"]; + }); - services.AddAuthorization(options => - { - options.AddPolicy("download:songs", policy => - policy - .Requirements - .Add(new HasScopeRequirement("download:songs", domain))); + services.AddAuthorization(options => + { + options.AddPolicy("download:songs", policy => + policy.Requirements + .Add(new HasScopeRequirement("download:songs", domain))); - options.AddPolicy("upload:songs", policy => - policy - .Requirements - .Add(new HasScopeRequirement("upload:songs", domain))); + options.AddPolicy("upload:songs", policy => + policy.Requirements + .Add(new HasScopeRequirement("upload:songs", domain))); - options.AddPolicy("delete:songs", policy => - policy - .Requirements - .Add(new HasScopeRequirement("delete:songs", domain))); + options.AddPolicy("delete:songs", policy => + policy.Requirements + .Add(new HasScopeRequirement("delete:songs", domain))); - options.AddPolicy("read:song_details", policy => - policy - .Requirements - .Add(new HasScopeRequirement("read:song_details", domain))); + options.AddPolicy("read:song_details", policy => + policy.Requirements + .Add(new HasScopeRequirement("read:song_details", domain))); - options.AddPolicy("update:songs", policy => - policy - .Requirements - .Add(new HasScopeRequirement("update:songs", domain))); + options.AddPolicy("update:songs", policy => + policy.Requirements + .Add(new HasScopeRequirement("update:songs", domain))); - options.AddPolicy("read:artists", policy => - policy - .Requirements - .Add(new HasScopeRequirement("read:artists", domain))); + options.AddPolicy("read:artists", policy => + policy.Requirements + .Add(new HasScopeRequirement("read:artists", domain))); - options.AddPolicy("read:albums", policy => - policy - .Requirements - .Add(new HasScopeRequirement("read:albums", domain))); + options.AddPolicy("read:albums", policy => + policy.Requirements + .Add(new HasScopeRequirement("read:albums", domain))); - options.AddPolicy("read:genre", policy => - policy - .Requirements - .Add(new HasScopeRequirement("read:genre", domain))); + options.AddPolicy("read:genre", policy => + policy.Requirements + .Add(new HasScopeRequirement("read:genre", domain))); - options.AddPolicy("read:year", policy => - policy - .Requirements - .Add(new HasScopeRequirement("read:year", domain))); + options.AddPolicy("read:year", policy => + policy.Requirements + .Add(new HasScopeRequirement("read:year", domain))); - options.AddPolicy("stream:songs", policy => - policy - .Requirements - .Add(new HasScopeRequirement("stream:songs", domain))); - }); + options.AddPolicy("stream:songs", policy => + policy.Requirements + .Add(new HasScopeRequirement("stream:songs", domain))); + }); - services.AddSingleton(); + services.AddSingleton(); - var connString = Configuration.GetConnectionString("DefaultConnection"); + var connString = Configuration.GetConnectionString("DefaultConnection"); - services.Add(new ServiceDescriptor(typeof(SongRepository), - new SongRepository(Configuration - .GetConnectionString("DefaultConnection")))); + services.Add(new ServiceDescriptor(typeof(SongRepository), + new SongRepository(Configuration.GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(AlbumRepository), - new AlbumRepository(Configuration - .GetConnectionString("DefaultConnection")))); + services.Add(new ServiceDescriptor(typeof(AlbumRepository), + new AlbumRepository(Configuration.GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(ArtistRepository), - new ArtistRepository(Configuration - .GetConnectionString("DefaultConnection")))); + services.Add(new ServiceDescriptor(typeof(ArtistRepository), + new ArtistRepository(Configuration.GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(GenreRepository), - new GenreRepository(Configuration - .GetConnectionString("DefaultConnection")))); + services.Add(new ServiceDescriptor(typeof(GenreRepository), + new GenreRepository(Configuration.GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(YearRepository), - new YearRepository(Configuration - .GetConnectionString("DefaultConnection")))); + services.Add(new ServiceDescriptor(typeof(YearRepository), + new YearRepository(Configuration.GetConnectionString("DefaultConnection")))); - services.Add(new ServiceDescriptor(typeof(UserRepository), - new UserRepository(Configuration - .GetConnectionString("DefaultConnection")))); + services.Add(new ServiceDescriptor(typeof(UserRepository), + new UserRepository(Configuration.GetConnectionString("DefaultConnection")))); - services.AddDbContext(options => options.UseMySQL(connString)); - services.AddDbContext(options => options.UseMySQL(connString)); - services.AddDbContext(options => options.UseMySQL(connString)); - services.AddDbContext(options => options.UseMySQL(connString)); - services.AddDbContext(options => options.UseMySQL(connString)); - services.AddDbContext(options => options.UseMySQL(connString)); - } + services.AddDbContext(options => options.UseMySQL(connString)); + services.AddDbContext(options => options.UseMySQL(connString)); + services.AddDbContext(options => options.UseMySQL(connString)); + services.AddDbContext(options => options.UseMySQL(connString)); + services.AddDbContext(options => options.UseMySQL(connString)); + services.AddDbContext(options => options.UseMySQL(connString)); + } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); - } + // Called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + // The default HSTS value is 30 days. + // You may want to change this for production scenarios + app.UseHsts(); + } - app.UseAuthentication(); + app.UseAuthentication(); - app.UseHttpsRedirection(); - app.UseMvc(); - } - } + app.UseHttpsRedirection(); + app.UseMvc(); + } + } }