aboutsummaryrefslogtreecommitdiff
path: root/API
diff options
context:
space:
mode:
Diffstat (limited to 'API')
-rw-r--r--API/API.csproj3
-rw-r--r--API/Database/DbRepository.cs4
-rw-r--r--API/Database/DevHiveContext.cs8
-rw-r--r--API/Startup.cs100
4 files changed, 70 insertions, 45 deletions
diff --git a/API/API.csproj b/API/API.csproj
index 401d5bc..63231c1 100644
--- a/API/API.csproj
+++ b/API/API.csproj
@@ -7,8 +7,9 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.0" NoWarn="NU1605"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.0" NoWarn="NU1605"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3"/>
- <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0"/>
+ <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0"/>
+ <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Models\Models.csproj"/>
diff --git a/API/Database/DbRepository.cs b/API/Database/DbRepository.cs
new file mode 100644
index 0000000..a166682
--- /dev/null
+++ b/API/Database/DbRepository.cs
@@ -0,0 +1,4 @@
+namespace API.Database
+{
+
+} \ No newline at end of file
diff --git a/API/Database/DevHiveContext.cs b/API/Database/DevHiveContext.cs
index 6f2a20c..6db137a 100644
--- a/API/Database/DevHiveContext.cs
+++ b/API/Database/DevHiveContext.cs
@@ -4,9 +4,9 @@ using Models.Classes;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
-namespace Database
+namespace API.Database
{
- public class DevHiveContext : IdentityDbContext<User<int>, IdentityRole<int>, int>
+ public class DevHiveContext : IdentityDbContext<User, IdentityRole<int>, int>
{
public DevHiveContext(DbContextOptions options)
: base(options) { }
@@ -16,8 +16,8 @@ namespace Database
protected override void OnModelCreating(ModelBuilder builder)
{
- // builder.Entity<User>()
- // .HasKey(x => x.Id);
+ builder.Entity<User>()
+ .HasKey(x => x.Id);
base.OnModelCreating(builder);
}
diff --git a/API/Startup.cs b/API/Startup.cs
index cd2c39a..9257c0e 100644
--- a/API/Startup.cs
+++ b/API/Startup.cs
@@ -1,51 +1,71 @@
+using API.Database;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Identity;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
+using Models.Classes;
namespace API
{
public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
-
- 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.AddControllers();
-
- services.AddSwaggerGen(c =>
- {
- c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
- });
- }
-
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- app.UseSwagger();
- app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
- }
-
- app.UseHttpsRedirection();
- app.UseRouting();
-
- app.UseAuthorization();
-
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllers();
- });
- }
- }
+ {
+ public Startup(IConfiguration configuration)
+ {
+ Configuration = configuration;
+ }
+
+ 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.AddControllers();
+
+ services.AddDbContext<DevHiveContext>(options =>
+ options.UseNpgsql(Configuration.GetConnectionString("DEV")))
+ .AddAuthentication()
+ .AddJwtBearer();
+
+ services.AddIdentity<User, IdentityRole<int>>();
+ //services.AddAuthentication();
+
+ services.Configure<IdentityOptions>(options =>
+ {
+ options.User.RequireUniqueEmail = true;
+
+ // options.Password.RequiredLength = 5;
+ });
+
+ services.AddSwaggerGen(c =>
+ {
+ c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" });
+ });
+ }
+
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+ if (env.IsDevelopment())
+ {
+ app.UseDeveloperExceptionPage();
+ app.UseSwagger();
+ app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1"));
+ }
+
+ app.UseHttpsRedirection();
+ app.UseRouting();
+
+ app.UseAuthentication();
+ app.UseAuthorization();
+
+ app.UseEndpoints(endpoints =>
+ {
+ endpoints.MapControllers();
+ });
+ }
+ }
}