Skip to content

Commit

Permalink
azure modify
Browse files Browse the repository at this point in the history
  • Loading branch information
hasanmd91 committed Jan 25, 2024
1 parent dbcd844 commit 2df5ca5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Ecom.WebAPI.Migrations
{
/// <inheritdoc />
public partial class createdatabase : Migration
public partial class initialdatabase : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down
2 changes: 1 addition & 1 deletion Ecom.WebAPI/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5137",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
6 changes: 5 additions & 1 deletion Ecom.WebAPI/src/Database/DataBaseContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ecom.Core.src.Entity;
using Ecom.Core.src.Enum;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Npgsql;
Expand Down Expand Up @@ -38,9 +39,12 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasPostgresEnum<Role>();
modelBuilder.HasPostgresEnum<OrderStatus>();
modelBuilder.Entity<User>(entity => entity.Property(e => e.Role).HasColumnType("role"));
modelBuilder.Entity<Order>(entity => entity.Property(e => e.OrderStatus).HasColumnType("order_status"));
modelBuilder.Entity<User>().HasIndex(u => u.Email).IsUnique();
modelBuilder.Entity<Category>().HasIndex(c => c.Name).IsUnique();

modelBuilder.Entity<User>().HasMany(p => p.Orders).WithOne(u => u.User).OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<User>().HasMany(r => r.Reviews).WithOne(u => u.User).OnDelete(DeleteBehavior.Cascade);

Expand Down
11 changes: 1 addition & 10 deletions Ecom.WebAPI/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@
builder.Services.AddSingleton<IAuthorizationHandler, ReviewAdminOrOwnerHandeler>();
builder.Services.AddSingleton<IAuthorizationHandler, ReviewOwnerHandeler>();


var dataSourceBuilder = new NpgsqlDataSourceBuilder(builder.Configuration.GetConnectionString("Store"));
var dataSourceBuilder = new NpgsqlDataSourceBuilder(builder.Configuration.GetConnectionString("Ilh"));
dataSourceBuilder.MapEnum<Role>();
dataSourceBuilder.MapEnum<OrderStatus>();
var dataSource = dataSourceBuilder.Build();

builder.Services.AddAutoMapper(typeof(MapperProfile).Assembly);
builder.Services.AddDbContext<DataBaseContext>(options => options.UseNpgsql(dataSource));


// Add JWT authentication
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(
o =>
Expand All @@ -84,7 +82,6 @@
};
});


builder.Services.AddAuthorization(policy =>
{
policy.AddPolicy("OrderAdminOrOwnerPolicy", policy => policy.Requirements.Add(new AdminOrOwnerRequirement()));
Expand All @@ -94,11 +91,9 @@

});


var app = builder.Build();

app.UseMiddleware<ExceptionHandeler>();

app.UseCors(options =>
{
options
Expand All @@ -107,7 +102,6 @@
.AllowAnyHeader();
});


app.UseSwagger();
app.UseSwaggerUI(c =>
{
Expand All @@ -121,9 +115,6 @@
app.UseSwagger();
app.UseSwaggerUI();
}



app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
Expand Down

0 comments on commit 2df5ca5

Please sign in to comment.