-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
555 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Pds.Api.AppStart | ||
{ | ||
public static class AuthenticationExtensions | ||
{ | ||
private const string CorsPolicy = "PdsCorsPolicy"; | ||
|
||
public static void AddAuth0Authentication(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
services.AddAuthentication(options => | ||
{ | ||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | ||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | ||
}).AddJwtBearer(options => | ||
{ | ||
options.Authority = configuration["Auth0:Authority"]; | ||
options.Audience = configuration["Auth0:ApiIdentifier"]; | ||
}); | ||
} | ||
|
||
public static void AddPdsCorsPolicy(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
services.AddCors(options => | ||
{ | ||
options.AddPolicy(CorsPolicy, | ||
builder => builder.WithOrigins(configuration.GetSection("AllowedOrigins").Get<List<string>>().ToArray()) | ||
.AllowAnyMethod() | ||
.AllowAnyHeader()); | ||
}); | ||
} | ||
|
||
public static void UsePdsCorsPolicy(this IApplicationBuilder app) | ||
{ | ||
app.UseCors("PdsUiPolicy"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Pds.Data; | ||
|
||
namespace Pds.Api.AppStart | ||
{ | ||
public static class DatabaseContextExtensions | ||
{ | ||
public static void AddSqlContext(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
var connectionString = configuration.GetConnectionString("DefaultConnection"); | ||
services.AddDbContext<ApplicationDbContext>(o => o.UseSqlServer(connectionString)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.OpenApi.Models; | ||
using Pds.Data; | ||
|
||
namespace Pds.Api.AppStart | ||
{ | ||
public static class SwaggerExtensions | ||
{ | ||
public static void AddCustomSwagger(this IServiceCollection services) | ||
{ | ||
services.AddSwaggerGen(swagger => | ||
{ | ||
swagger.SwaggerDoc("v1", new OpenApiInfo | ||
{ | ||
Version = "v1", | ||
Title = "Pds.Api", | ||
Description = "People Discovery System API" | ||
}); | ||
swagger.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme | ||
{ | ||
Description = | ||
"JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"", | ||
Name = "Authorization", | ||
In = ParameterLocation.Header, | ||
Type = SecuritySchemeType.ApiKey, | ||
Scheme = "Bearer" | ||
}); | ||
swagger.AddSecurityRequirement(new OpenApiSecurityRequirement() | ||
{ | ||
{ | ||
new OpenApiSecurityScheme | ||
{ | ||
Reference = new OpenApiReference | ||
{ | ||
Type = ReferenceType.SecurityScheme, | ||
Id = "Bearer" | ||
}, | ||
Scheme = "oauth2", | ||
Name = "Bearer", | ||
In = ParameterLocation.Header, | ||
}, | ||
new List<string>() | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
public static void UseCustomSwaggerUI(this IApplicationBuilder app) | ||
{ | ||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Pds.Api v1")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Pds.Data.Entities; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Pds.Data | ||
{ | ||
public class ApplicationDbContext : DbContext | ||
{ | ||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options){} | ||
|
||
public DbSet<Person> Persons { get; set; } | ||
public DbSet<Resource> Resources { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder builder) | ||
{ | ||
UpdateStructure(builder); | ||
base.OnModelCreating(builder); | ||
} | ||
|
||
private void UpdateStructure(ModelBuilder modelBuilder) | ||
{ | ||
// Place for specific fluent properties | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace Pds.Data.Entities | ||
{ | ||
public abstract class EntityBase | ||
{ | ||
public Guid ID { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
using Pds.Data.Enums; | ||
|
||
namespace Pds.Data.Entities | ||
{ | ||
public class Person : EntityBase | ||
{ | ||
[Required] | ||
[Column(TypeName = "varchar(300)")] | ||
public string FirstName { get; set; } | ||
|
||
[Required] | ||
[Column(TypeName = "varchar(300)")] | ||
public string LastName { get; set; } | ||
|
||
[Required] | ||
[Column(TypeName = "varchar(300)")] | ||
public string ThirdName { get; set; } | ||
|
||
public string Info { get; set; } | ||
|
||
public int Rate { get; set; } | ||
|
||
public PersonStatus Status { get; set; } | ||
|
||
public DateTime CreatedAt { get; set; } | ||
|
||
public DateTime? UpdatedAt { get; set; } | ||
|
||
public DateTime? ArchivedAt { get; set; } | ||
|
||
public DateTime? UnarchivedAt { get; set; } | ||
|
||
public ICollection<Resource> Resources { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
|
||
namespace Pds.Data.Entities | ||
{ | ||
public class Resource : EntityBase | ||
{ | ||
public string Name { get; set; } | ||
|
||
public string Url { get; set; } | ||
|
||
public DateTime CreatedAt { get; set; } | ||
|
||
public DateTime? UpdatedAt { get; set; } | ||
|
||
public Person Person { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Pds.Data.Enums | ||
{ | ||
public enum PersonStatus | ||
{ | ||
Archived = 0, | ||
Active = 1 | ||
} | ||
} |
Oops, something went wrong.