Skip to content

Commit

Permalink
Merge pull request #83 from Tynab/develop
Browse files Browse the repository at this point in the history
semi
  • Loading branch information
Tynab committed Feb 1, 2024
2 parents 257b20d + dd9d99a commit 28856b3
Show file tree
Hide file tree
Showing 42 changed files with 237 additions and 311 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /yanlib
COPY ["lib/YANLib/YANLib.csproj", "lib/YANLib/"]
COPY ["host/YANLib.HttpApi.Host/YANLib.HttpApi.Host.csproj", "host/YANLib.HttpApi.Host/"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@

namespace YANLib.EntityFrameworkCore;

public class YANLibHttpApiHostMigrationsDbContext : AbpDbContext<YANLibHttpApiHostMigrationsDbContext>
public class YANLibHttpApiHostMigrationsDbContext(DbContextOptions<YANLibHttpApiHostMigrationsDbContext> options) : AbpDbContext<YANLibHttpApiHostMigrationsDbContext>(options)
{
public YANLibHttpApiHostMigrationsDbContext(DbContextOptions<YANLibHttpApiHostMigrationsDbContext> options) : base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

namespace YANLib.Middlewares;

public class UnauthorizedHandlerMiddleware
public class UnauthorizedHandlerMiddleware(RequestDelegate next)
{
private readonly RequestDelegate _next;
private readonly RequestDelegate _next = next;

public UnauthorizedHandlerMiddleware(RequestDelegate next) => _next = next;

public async ValueTask Invoke(HttpContext context)
public async Task Invoke(HttpContext context)
{
var writeCustomResponse = false;
var originalResponse = context.Response.Body;
Expand Down
33 changes: 17 additions & 16 deletions host/YANLib.HttpApi.Host/YANLib.HttpApi.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,45 @@
<Import Project="..\..\common.props" />

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>YANLib</RootNamespace>
<PreserveCompilationReferences>true</PreserveCompilationReferences>
<UserSecretsId>YANLib-4681b4fd-151f-4221-84a4-929d86723e4c</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
<DockerComposeProjectPath>..\..\docker-compose.dcproj</DockerComposeProjectPath>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="6.0.5" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="7.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="7.0.0" />
<PackageReference Include="DotNetCore.CAP" Version="6.2.1" />
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="6.2.1" />
<PackageReference Include="DotNetCore.CAP.Kafka" Version="6.2.1" />
<PackageReference Include="DotNetCore.CAP.MongoDB" Version="6.2.1" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="6.2.1" />
<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.26" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.26">
<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.23.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.15" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.15">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.1" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Elasticsearch" Version="9.0.3" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Volo.Abp.Autofac" Version="6.0.3" />
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="6.0.3" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="6.0.3" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.SqlServer" Version="6.0.3" />
<PackageReference Include="Volo.Abp.EventBus.Azure" Version="6.0.3" />
<PackageReference Include="Volo.Abp.EventBus.RabbitMQ" Version="6.0.3" />
<PackageReference Include="Volo.Abp.Http.Client" Version="6.0.3" />
<PackageReference Include="Volo.Abp.Swashbuckle" Version="6.0.3" />
<PackageReference Include="Volo.Abp.Autofac" Version="7.4.5" />
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="7.4.5" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="7.4.5" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.SqlServer" Version="7.4.5" />
<PackageReference Include="Volo.Abp.EventBus.Azure" Version="7.4.5" />
<PackageReference Include="Volo.Abp.EventBus.RabbitMQ" Version="7.4.5" />
<PackageReference Include="Volo.Abp.Http.Client" Version="7.4.5" />
<PackageReference Include="Volo.Abp.Swashbuckle" Version="7.4.5" />
</ItemGroup>

<ItemGroup>
Expand Down
134 changes: 67 additions & 67 deletions host/YANLib.HttpApi.Host/YANLibHttpApiHostModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
using static System.Convert;
using static System.StringSplitOptions;

//#if !DEBUG
//using Microsoft.AspNetCore.Authentication.JwtBearer;
//using Microsoft.AspNetCore.Http;
//using YANLib.Middlewares;
//using static Microsoft.OpenApi.Models.ParameterLocation;
//using static Microsoft.OpenApi.Models.SecuritySchemeType;
//using static System.Net.HttpStatusCode;
//using static System.Threading.Tasks.Task;
//#endif
#if DEBUG
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Http;
using YANLib.Middlewares;
using static Microsoft.OpenApi.Models.ParameterLocation;
using static Microsoft.OpenApi.Models.SecuritySchemeType;
using static System.Net.HttpStatusCode;
using static System.Threading.Tasks.Task;
#endif

namespace YANLib;

Expand Down Expand Up @@ -121,26 +121,26 @@ private static void ConfigureAuthentication(ServiceConfigurationContext context,
o.RequireHttpsMetadata = ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
o.Audience = configuration["AuthServer:ApiName"];
//#if !DEBUG
// o.Events = new JwtBearerEvents
// {
// OnMessageReceived = async c =>
// {
// string authorization = c.Request.Headers.Authorization;
// if (authorization == configuration["Authorization:Bearer"])
// {
// await CompletedTask;
// }
// else
// {
// c.Response.StatusCode = Unauthorized.ToInt();
// c.Response.ContentType = "application/json";
// await c.Response.WriteAsync("Access Denied");
// }
// }
// };
//#endif
#if DEBUG
o.Events = new JwtBearerEvents
{
OnMessageReceived = async c =>
{
string authorization = c.Request.Headers.Authorization;
if (authorization == configuration["Authorization:Bearer"])
{
await CompletedTask;
}
else
{
c.Response.StatusCode = Unauthorized.ToInt();
c.Response.ContentType = "application/json";
await c.Response.WriteAsync("Access Denied");
}
}
};
#endif
});

private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration)
Expand All @@ -165,29 +165,29 @@ private static void ConfigureSwaggerServices(ServiceConfigurationContext context
Version = "test"
});
//#if !DEBUG
// o.AddSecurityDefinition("Authorization", new OpenApiSecurityScheme
// {
// In = Header,
// Description = "Please insert JWT with Bearer into field",
// Name = "Authorization",
// Type = ApiKey
// });
// o.AddSecurityRequirement(new OpenApiSecurityRequirement
// {
// {
// new OpenApiSecurityScheme
// {
// Reference = new OpenApiReference
// {
// Id = "Authorization",
// Type = ReferenceType.SecurityScheme
// }
// }, new List<string>()
// }
// });
//#endif
#if DEBUG
o.AddSecurityDefinition("Authorization", new OpenApiSecurityScheme
{
In = Header,
Description = "Please insert JWT with Bearer into field",
Name = "Authorization",
Type = ApiKey
});
o.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Id = "Authorization",
Type = ReferenceType.SecurityScheme
}
}, new List<string>()
}
});
#endif
o.CustomSchemaIds(t => t.FullName.Replace("+", "."));
o.HideAbpEndpoints();
Expand Down Expand Up @@ -257,14 +257,17 @@ private static void ConfigureHealthChecks(ServiceConfigurationContext context, I
connectionString: configuration["ConnectionStrings:Default"],
name: "database",
failureStatus: Degraded,
tags: new string[] { "db", "sql", "sqlserver" }
tags: ["db", "sql", "sqlserver"]
);

public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();

_ = context.GetEnvironment().IsDevelopment() ? app.UseDeveloperExceptionPage() : app.UseHsts();
_ = app.UseAllElasticApm(context.GetConfiguration()); // required first
_ = Subscribe(new HttpDiagnosticsSubscriber()); // required second
_ = Subscribe(new EfCoreDiagnosticsSubscriber()); // required third
_ = app.UseHttpsRedirection();
_ = app.UseCorrelationId();
_ = app.UseStaticFiles();
Expand All @@ -277,6 +280,13 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
_ = o.AddSupportedUICultures("vi");
});

#if DEBUG
_ = app.UseMiddleware<UnauthorizedHandlerMiddleware>();
#endif

_ = app.UseCors();
_ = app.UseAuthentication();
_ = app.UseAuthorization();
_ = app.UseSwagger();

_ = app.UseAbpSwaggerUI(c =>
Expand All @@ -287,26 +297,16 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
c.OAuthScopes("YANLib");
});

_ = app.UseAuditing();
_ = app.UseAbpSerilogEnrichers();

_ = app.UseHealthChecks("/health", new HealthCheckOptions()
{
Predicate = _ => true,
ResponseWriter = WriteHealthCheckUIResponse
});

_ = app.UseCapDashboard();

//#if !DEBUG
// _ = app.UseMiddleware<UnauthorizedHandlerMiddleware>();
//#endif

_ = app.UseCors();
_ = app.UseAuthentication();
_ = app.UseAuthorization();
_ = app.UseAuditing();
_ = app.UseAbpSerilogEnrichers();
_ = app.UseConfiguredEndpoints();
_ = app.UseAllElasticApm(context.GetConfiguration());
_ = Subscribe(new HttpDiagnosticsSubscriber());
_ = Subscribe(new EfCoreDiagnosticsSubscriber());
_ = app.UseCapDashboard();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Localization;
using YANLib.Localization;
using static Volo.Abp.Localization.LocalizableString;

namespace YANLib.Permissions;

public class YANLibPermissionDefinitionProvider : PermissionDefinitionProvider
{
public override void Define(IPermissionDefinitionContext context) => context.AddGroup(YANLibPermissions.GroupName);
public override void Define(IPermissionDefinitionContext context)
{
var myGroup = context.AddGroup(YANLibPermissions.GroupName);
//Define your own permissions here. Example:
//myGroup.AddPermission(YANLibPermissions.MyPermission1, L("Permission:MyPermission1"));
}

private static LocalizableString L(string name) => Create<YANLibResource>(name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
public static class YANLibPermissions
{
public const string GroupName = "YANLib";

//Add your own permission names. Example:
//public const string MyPermission1 = GroupName + ".MyPermission1";
}
13 changes: 4 additions & 9 deletions src/YANLib.Application.Contracts/Requests/CertificateRequest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using System.ComponentModel.DataAnnotations;

namespace YANLib.Requests;
namespace YANLib.Requests;

public sealed class CertificateRequest
{
[Required]
public string Id { get; set; }
public required string Id { get; set; }

[Required]
public string Name { get; set; }
public required string Name { get; set; }

public double? GPA { get; set; }

[Required]
public string DeveloperId { get; set; }
public required string DeveloperId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace YANLib.Requests.Developer;

public sealed class DeveloperCreateRequest
{
[Required]
public string Name { get; set; }
public required string Name { get; set; }

public string Phone { get; set; }

[Required]
public string IdCard { get; set; }
public required string IdCard { get; set; }

[Required]
public int DeveloperTypeCode { get; set; }
public required int DeveloperTypeCode { get; set; }

public List<Certificate> Certificates { get; set; }

public sealed class Certificate
{
[Required]
public string Name { get; set; }
public required string Name { get; set; }

public double? GPA { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace YANLib.Requests.Developer;

Expand All @@ -15,8 +14,7 @@ public sealed class DeveloperUpdateRequest

public sealed class Certificate
{
[Required]
public string Name { get; set; }
public required string Name { get; set; }

public double? GPA { get; set; }
}
Expand Down
Loading

0 comments on commit 28856b3

Please sign in to comment.