netcore-blueprint 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BlueprintTemplate/Host.API/Extensions/ApplicationBuilderExtensions.cs +26 -0
- package/BlueprintTemplate/Host.API/Extensions/DatabaseExtensions.cs +37 -0
- package/BlueprintTemplate/Host.API/Extensions/ServiceCollectionExtensions.cs +54 -0
- package/BlueprintTemplate/Host.API/Extensions/ThirdPartyExtensions.cs +30 -0
- package/BlueprintTemplate/Host.API/Host.API.csproj +29 -0
- package/BlueprintTemplate/Host.API/Host.API.csproj.user +6 -0
- package/BlueprintTemplate/Host.API/Host.API.http +6 -0
- package/BlueprintTemplate/Host.API/Program.cs +25 -0
- package/BlueprintTemplate/Host.API/Properties/launchSettings.json +23 -0
- package/BlueprintTemplate/Host.API/appsettings.Development.json +8 -0
- package/BlueprintTemplate/Host.API/appsettings.json +15 -0
- package/BlueprintTemplate/ItemModule.API/Controllers/Public/ItemController.cs +65 -0
- package/BlueprintTemplate/ItemModule.API/ItemModule.API.csproj +26 -0
- package/BlueprintTemplate/ItemModule.API/Mappers/DtoItemMappingProfile.cs +26 -0
- package/BlueprintTemplate/ItemModule.Core/Dtos/Admin/ItemRequestDto.cs +8 -0
- package/BlueprintTemplate/ItemModule.Core/Dtos/Admin/ItemResponseDto.cs +8 -0
- package/BlueprintTemplate/ItemModule.Core/Entities/Item.cs +8 -0
- package/BlueprintTemplate/ItemModule.Core/Interfaces/API/IItemService.cs +9 -0
- package/BlueprintTemplate/ItemModule.Core/Interfaces/SPI/IItemInfra.cs +9 -0
- package/BlueprintTemplate/ItemModule.Core/ItemModule.Core.csproj +18 -0
- package/BlueprintTemplate/ItemModule.Core/Services/ItemService.cs +20 -0
- package/BlueprintTemplate/ItemModule.Infrastructure/Database/ItemConfiguration.cs +22 -0
- package/BlueprintTemplate/ItemModule.Infrastructure/Database/Seeder.cs +21 -0
- package/BlueprintTemplate/ItemModule.Infrastructure/ItemDependencyInjection.cs +27 -0
- package/BlueprintTemplate/ItemModule.Infrastructure/ItemModule.Infrastructure.csproj +14 -0
- package/BlueprintTemplate/ItemModule.Infrastructure/Services/MySQLItemInfra.cs +16 -0
- package/BlueprintTemplate/MyBlueprint.slnx +23 -0
- package/BlueprintTemplate/README.md +22 -0
- package/BlueprintTemplate/Shared.Core/Dtos/Requests/BaseRequestDto.cs +27 -0
- package/BlueprintTemplate/Shared.Core/Dtos/Responses/BaseResponseDto.cs +27 -0
- package/BlueprintTemplate/Shared.Core/Entities/BaseEntity.cs +15 -0
- package/BlueprintTemplate/Shared.Core/Enums/EntityStatus.cs +9 -0
- package/BlueprintTemplate/Shared.Core/Exceptions/Errors.cs +20 -0
- package/BlueprintTemplate/Shared.Core/Interfaces/API/IItemService.cs +14 -0
- package/BlueprintTemplate/Shared.Core/Interfaces/SPI/IItemInfra.cs +14 -0
- package/BlueprintTemplate/Shared.Core/Interfaces/SPI/IModuleSeeder.cs +9 -0
- package/BlueprintTemplate/Shared.Core/Interfaces/SPI/IRepositoryFactory.cs +7 -0
- package/BlueprintTemplate/Shared.Core/Models/Error.cs +69 -0
- package/BlueprintTemplate/Shared.Core/Models/ErrorDetail.cs +8 -0
- package/BlueprintTemplate/Shared.Core/Models/PagerData.cs +8 -0
- package/BlueprintTemplate/Shared.Core/Models/PagingParams.cs +8 -0
- package/BlueprintTemplate/Shared.Core/Services/ItemService.cs +53 -0
- package/BlueprintTemplate/Shared.Core/Shared.Core.csproj +13 -0
- package/BlueprintTemplate/Shared.Infrastructure/DbInitializer.cs +18 -0
- package/BlueprintTemplate/Shared.Infrastructure/Migrations/20260131121133_SeedInitialData.Designer.cs +123 -0
- package/BlueprintTemplate/Shared.Infrastructure/Migrations/20260131121133_SeedInitialData.cs +82 -0
- package/BlueprintTemplate/Shared.Infrastructure/Migrations/MyDbContextModelSnapshot.cs +120 -0
- package/BlueprintTemplate/Shared.Infrastructure/MyDbContext.cs +24 -0
- package/BlueprintTemplate/Shared.Infrastructure/Services/Mongo/MongoItemInfra.cs +117 -0
- package/BlueprintTemplate/Shared.Infrastructure/Services/MySQL/MySQLItemInfra.cs +132 -0
- package/BlueprintTemplate/Shared.Infrastructure/Services/RepositoryFactory.cs +36 -0
- package/BlueprintTemplate/Shared.Infrastructure/Shared.Infrastructure.csproj +28 -0
- package/BlueprintTemplate/Shared.Infrastructure/SharedDependencyInjection.cs +19 -0
- package/BlueprintTemplate/User.API/Controllers/Admin/UserController.cs +153 -0
- package/BlueprintTemplate/User.API/Mappers/DtoUserMappingProfile.cs +27 -0
- package/BlueprintTemplate/User.API/UserModule.API.csproj +26 -0
- package/BlueprintTemplate/User.Core/Dtos/Admin/UserRequestDto.cs +12 -0
- package/BlueprintTemplate/User.Core/Dtos/Admin/UserResponseDto.cs +12 -0
- package/BlueprintTemplate/User.Core/Entities/User.cs +13 -0
- package/BlueprintTemplate/User.Core/Enums/UserRole.cs +8 -0
- package/BlueprintTemplate/User.Core/Interfaces/API/IUserService.cs +9 -0
- package/BlueprintTemplate/User.Core/Interfaces/SPI/IUserInfra.cs +9 -0
- package/BlueprintTemplate/User.Core/Services/UserService.cs +20 -0
- package/BlueprintTemplate/User.Core/UserModule.Core.csproj +17 -0
- package/BlueprintTemplate/User.Infrastructure/Database/ItemConfiguration.cs +27 -0
- package/BlueprintTemplate/User.Infrastructure/Database/Seeder.cs +44 -0
- package/BlueprintTemplate/User.Infrastructure/Services/MySQLUserInfra.cs +16 -0
- package/BlueprintTemplate/User.Infrastructure/UserDependencyInjection.cs +22 -0
- package/BlueprintTemplate/User.Infrastructure/UserModule.Infrastructure.csproj +14 -0
- package/create.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
namespace Host.API.Extensions
|
|
2
|
+
{
|
|
3
|
+
public static class ApplicationBuilderExtensions
|
|
4
|
+
{
|
|
5
|
+
public static WebApplication UseApiMiddleware(this WebApplication app)
|
|
6
|
+
{
|
|
7
|
+
if (app.Environment.IsDevelopment())
|
|
8
|
+
{
|
|
9
|
+
app.UseSwagger();
|
|
10
|
+
app.UseSwaggerUI(c =>
|
|
11
|
+
{
|
|
12
|
+
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Host API v1");
|
|
13
|
+
c.RoutePrefix = "swagger";
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
app.UseCors("AllowAll");
|
|
18
|
+
app.UseHttpsRedirection();
|
|
19
|
+
app.UseAuthentication();
|
|
20
|
+
app.UseAuthorization();
|
|
21
|
+
app.MapControllers();
|
|
22
|
+
|
|
23
|
+
return app;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
using Microsoft.EntityFrameworkCore;
|
|
2
|
+
using Shared.Infrastructure;
|
|
3
|
+
|
|
4
|
+
namespace Host.API.Extensions
|
|
5
|
+
{
|
|
6
|
+
public static class DatabaseExtensions
|
|
7
|
+
{
|
|
8
|
+
public static IServiceCollection AddMySqlDatabase(
|
|
9
|
+
this IServiceCollection services,
|
|
10
|
+
IConfiguration configuration)
|
|
11
|
+
{
|
|
12
|
+
string? mySQLConnectionString =
|
|
13
|
+
configuration.GetConnectionString("MySQL");
|
|
14
|
+
|
|
15
|
+
if (!string.IsNullOrEmpty(mySQLConnectionString))
|
|
16
|
+
{
|
|
17
|
+
services.AddDbContext<MyDbContext>(options =>
|
|
18
|
+
options.UseMySql(
|
|
19
|
+
mySQLConnectionString,
|
|
20
|
+
ServerVersion.AutoDetect(mySQLConnectionString)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return services;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static void ApplyDatabaseMigrations(this WebApplication app)
|
|
27
|
+
{
|
|
28
|
+
if (!app.Environment.IsDevelopment())
|
|
29
|
+
return;
|
|
30
|
+
|
|
31
|
+
using var scope = app.Services.CreateScope();
|
|
32
|
+
var dbContext = scope.ServiceProvider.GetRequiredService<MyDbContext>();
|
|
33
|
+
dbContext.Database.Migrate();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
using ItemModule.API.Controllers.Public;
|
|
2
|
+
using ItemModule.Infrastructure;
|
|
3
|
+
using Shared.Infrastructure;
|
|
4
|
+
using UserModule.API.Controllers.Admin;
|
|
5
|
+
using UserModule.Infrastructure;
|
|
6
|
+
|
|
7
|
+
namespace Host.API.Extensions
|
|
8
|
+
{
|
|
9
|
+
public static class ServiceCollectionExtensions
|
|
10
|
+
{
|
|
11
|
+
public static IServiceCollection AddApiCore(
|
|
12
|
+
this IServiceCollection services,
|
|
13
|
+
IConfiguration configuration)
|
|
14
|
+
{
|
|
15
|
+
services.AddControllers()
|
|
16
|
+
.AddApplicationPart(typeof(UserController).Assembly)
|
|
17
|
+
.AddApplicationPart(typeof(ItemController).Assembly);
|
|
18
|
+
|
|
19
|
+
services.AddEndpointsApiExplorer();
|
|
20
|
+
services.AddSwaggerGen();
|
|
21
|
+
|
|
22
|
+
services.AddCors(options =>
|
|
23
|
+
{
|
|
24
|
+
options.AddPolicy("AllowAll", policy =>
|
|
25
|
+
{
|
|
26
|
+
policy.AllowAnyOrigin()
|
|
27
|
+
.AllowAnyHeader()
|
|
28
|
+
.AllowAnyMethod()
|
|
29
|
+
.WithExposedHeaders("X-WP-Total");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return services;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static IServiceCollection AddUserModule(this IServiceCollection services)
|
|
37
|
+
{
|
|
38
|
+
UserDependencyInjection.AddUserModuleInfra(services);
|
|
39
|
+
return services;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public static IServiceCollection AddItemModule(this IServiceCollection services)
|
|
43
|
+
{
|
|
44
|
+
ItemDependencyInjection.AddItemModuleInfra(services);
|
|
45
|
+
return services;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static IServiceCollection AddSharedModule(this IServiceCollection services)
|
|
49
|
+
{
|
|
50
|
+
SharedDependencyInjection.AddSharedInfrastructure(services);
|
|
51
|
+
return services;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
using Asp.Versioning;
|
|
2
|
+
using ItemModule.API.Mappers;
|
|
3
|
+
using UserModule.API.Mappers;
|
|
4
|
+
|
|
5
|
+
namespace Host.API.Extensions
|
|
6
|
+
{
|
|
7
|
+
public static class ThirdPartyExtensions
|
|
8
|
+
{
|
|
9
|
+
public static IServiceCollection AddThirdParty(this IServiceCollection services)
|
|
10
|
+
{
|
|
11
|
+
services.AddAutoMapper(
|
|
12
|
+
cfg => { },
|
|
13
|
+
typeof(DtoItemMappingProfile).Assembly,
|
|
14
|
+
typeof(DtoUserMappingProfile).Assembly
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
services.AddApiVersioning(opt =>
|
|
18
|
+
{
|
|
19
|
+
opt.DefaultApiVersion = new ApiVersion(1, 0);
|
|
20
|
+
opt.AssumeDefaultVersionWhenUnspecified = true;
|
|
21
|
+
opt.ReportApiVersions = true;
|
|
22
|
+
opt.ApiVersionReader =
|
|
23
|
+
ApiVersionReader.Combine(new UrlSegmentApiVersionReader());
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return services;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
2
|
+
|
|
3
|
+
<PropertyGroup>
|
|
4
|
+
<TargetFramework>net10.0</TargetFramework>
|
|
5
|
+
<Nullable>enable</Nullable>
|
|
6
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
7
|
+
</PropertyGroup>
|
|
8
|
+
|
|
9
|
+
<ItemGroup>
|
|
10
|
+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
|
|
11
|
+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
|
|
12
|
+
<PrivateAssets>all</PrivateAssets>
|
|
13
|
+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
14
|
+
</PackageReference>
|
|
15
|
+
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.0" />
|
|
16
|
+
</ItemGroup>
|
|
17
|
+
|
|
18
|
+
<ItemGroup>
|
|
19
|
+
<ProjectReference Include="..\ItemModule.API\ItemModule.API.csproj" />
|
|
20
|
+
<ProjectReference Include="..\ItemModule.Core\ItemModule.Core.csproj" />
|
|
21
|
+
<ProjectReference Include="..\ItemModule.Infrastructure\ItemModule.Infrastructure.csproj" />
|
|
22
|
+
<ProjectReference Include="..\Shared.Core\Shared.Core.csproj" />
|
|
23
|
+
<ProjectReference Include="..\Shared.Infrastructure\Shared.Infrastructure.csproj" />
|
|
24
|
+
<ProjectReference Include="..\User.API\UserModule.API.csproj" />
|
|
25
|
+
<ProjectReference Include="..\User.Core\UserModule.Core.csproj" />
|
|
26
|
+
<ProjectReference Include="..\User.Infrastructure\UserModule.Infrastructure.csproj" />
|
|
27
|
+
</ItemGroup>
|
|
28
|
+
|
|
29
|
+
</Project>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
using Host.API.Extensions;
|
|
2
|
+
|
|
3
|
+
var builder = WebApplication.CreateBuilder(args);
|
|
4
|
+
|
|
5
|
+
// Core
|
|
6
|
+
builder.Services.AddApiCore(builder.Configuration);
|
|
7
|
+
|
|
8
|
+
// Third-party
|
|
9
|
+
builder.Services.AddThirdParty();
|
|
10
|
+
|
|
11
|
+
// Modules
|
|
12
|
+
builder.Services.AddUserModule();
|
|
13
|
+
builder.Services.AddItemModule();
|
|
14
|
+
builder.Services.AddSharedModule();
|
|
15
|
+
|
|
16
|
+
// Database
|
|
17
|
+
builder.Services.AddMySqlDatabase(builder.Configuration);
|
|
18
|
+
|
|
19
|
+
var app = builder.Build();
|
|
20
|
+
|
|
21
|
+
app.UseApiMiddleware();
|
|
22
|
+
|
|
23
|
+
app.ApplyDatabaseMigrations();
|
|
24
|
+
|
|
25
|
+
app.Run();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/launchsettings.json",
|
|
3
|
+
"profiles": {
|
|
4
|
+
"http": {
|
|
5
|
+
"commandName": "Project",
|
|
6
|
+
"dotnetRunMessages": true,
|
|
7
|
+
"launchBrowser": false,
|
|
8
|
+
"applicationUrl": "http://localhost:5008",
|
|
9
|
+
"environmentVariables": {
|
|
10
|
+
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"https": {
|
|
14
|
+
"commandName": "Project",
|
|
15
|
+
"dotnetRunMessages": true,
|
|
16
|
+
"launchBrowser": false,
|
|
17
|
+
"applicationUrl": "https://localhost:7070;http://localhost:5008",
|
|
18
|
+
"environmentVariables": {
|
|
19
|
+
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ConnectionStrings": {
|
|
3
|
+
"MySql": "Server=localhost;Port=3306;Database=test16;User=root;Password=password;"
|
|
4
|
+
},
|
|
5
|
+
"Database": {
|
|
6
|
+
"Type": "mysql"
|
|
7
|
+
},
|
|
8
|
+
"Logging": {
|
|
9
|
+
"LogLevel": {
|
|
10
|
+
"Default": "Information",
|
|
11
|
+
"Microsoft.AspNetCore": "Warning"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"AllowedHosts": "*"
|
|
15
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
using AutoMapper;
|
|
2
|
+
using ItemModule.Core.Dtos.Admin;
|
|
3
|
+
using ItemModule.Core.Entities;
|
|
4
|
+
using ItemModule.Core.Interfaces.API;
|
|
5
|
+
using Microsoft.AspNetCore.Http;
|
|
6
|
+
using Microsoft.AspNetCore.Mvc;
|
|
7
|
+
using Microsoft.Extensions.Logging;
|
|
8
|
+
using Shared.Core.Shared.Models;
|
|
9
|
+
using System.Diagnostics;
|
|
10
|
+
|
|
11
|
+
namespace ItemModule.API.Controllers.Public
|
|
12
|
+
{
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// Item Controller
|
|
15
|
+
/// </summary>
|
|
16
|
+
[Route("rest/v{version:apiVersion}/items")]
|
|
17
|
+
[Produces("application/json")]
|
|
18
|
+
[ApiController]
|
|
19
|
+
public class ItemController : Controller
|
|
20
|
+
{
|
|
21
|
+
private readonly IMapper _mapper;
|
|
22
|
+
private ILogger _logger;
|
|
23
|
+
private readonly IItemService _itemService;
|
|
24
|
+
|
|
25
|
+
/// <summary>
|
|
26
|
+
/// Constructor
|
|
27
|
+
/// </summary>
|
|
28
|
+
/// <param name="logger"></param>
|
|
29
|
+
/// <param name="mapper"></param>
|
|
30
|
+
/// <param name="itemService"></param>
|
|
31
|
+
public ItemController(
|
|
32
|
+
ILogger<ItemController> logger,
|
|
33
|
+
IMapper mapper,
|
|
34
|
+
IItemService itemService)
|
|
35
|
+
{
|
|
36
|
+
_mapper = mapper;
|
|
37
|
+
_logger = logger;
|
|
38
|
+
_itemService = itemService;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// <summary>
|
|
42
|
+
/// Get items
|
|
43
|
+
/// </summary>
|
|
44
|
+
/// <param name="pagingParams"></param>
|
|
45
|
+
/// <returns></returns>
|
|
46
|
+
[HttpGet]
|
|
47
|
+
[ProducesResponseType(typeof(PagerData<ItemResponseDto>), StatusCodes.Status200OK)]
|
|
48
|
+
public async Task<IActionResult> GetItems([FromQuery] PagingParams pagingParams)
|
|
49
|
+
{
|
|
50
|
+
_logger.LogInformation($"Start getting items");
|
|
51
|
+
var stopwatch = Stopwatch.StartNew();
|
|
52
|
+
|
|
53
|
+
PagerData<Item> items = await _itemService.GetItemsAsync(pagingParams);
|
|
54
|
+
PagerData<ItemResponseDto> itemResponse = _mapper.Map<PagerData<ItemResponseDto>>(items);
|
|
55
|
+
|
|
56
|
+
// Add custom headers
|
|
57
|
+
Response.Headers.Append("X-WP-Total", items.TotalRecords.ToString());
|
|
58
|
+
|
|
59
|
+
stopwatch.Stop();
|
|
60
|
+
_logger.LogInformation($"Getting items done in {stopwatch.ElapsedMilliseconds}");
|
|
61
|
+
|
|
62
|
+
return Ok(itemResponse.Items);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
2
|
+
|
|
3
|
+
<PropertyGroup>
|
|
4
|
+
<TargetFramework>net10.0</TargetFramework>
|
|
5
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
6
|
+
<Nullable>enable</Nullable>
|
|
7
|
+
</PropertyGroup>
|
|
8
|
+
|
|
9
|
+
<ItemGroup>
|
|
10
|
+
<Folder Include="Controllers\Admin\" />
|
|
11
|
+
</ItemGroup>
|
|
12
|
+
|
|
13
|
+
<ItemGroup>
|
|
14
|
+
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.1" />
|
|
15
|
+
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.1" />
|
|
16
|
+
<PackageReference Include="AutoMapper" Version="16.0.0" />
|
|
17
|
+
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="10.0.2" />
|
|
18
|
+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.3.9" />
|
|
19
|
+
</ItemGroup>
|
|
20
|
+
|
|
21
|
+
<ItemGroup>
|
|
22
|
+
<ProjectReference Include="..\ItemModule.Core\ItemModule.Core.csproj" />
|
|
23
|
+
<ProjectReference Include="..\Shared.Core\Shared.Core.csproj" />
|
|
24
|
+
</ItemGroup>
|
|
25
|
+
|
|
26
|
+
</Project>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
using AutoMapper;
|
|
2
|
+
using ItemModule.Core.Dtos.Admin;
|
|
3
|
+
using ItemModule.Core.Entities;
|
|
4
|
+
using Shared.Core.Shared.Models;
|
|
5
|
+
|
|
6
|
+
namespace ItemModule.API.Mappers
|
|
7
|
+
{
|
|
8
|
+
/// <summary>
|
|
9
|
+
/// DtoItemMappingProfile
|
|
10
|
+
/// </summary>
|
|
11
|
+
public class DtoItemMappingProfile : Profile
|
|
12
|
+
{
|
|
13
|
+
/// <summary>
|
|
14
|
+
/// Constructor
|
|
15
|
+
/// </summary>
|
|
16
|
+
public DtoItemMappingProfile()
|
|
17
|
+
{
|
|
18
|
+
CreateMap<Item, ItemRequestDto>().ReverseMap();
|
|
19
|
+
|
|
20
|
+
CreateMap<PagerData<Item>, PagerData<ItemResponseDto>>().ReverseMap();
|
|
21
|
+
|
|
22
|
+
CreateMap<Item, ItemResponseDto>()
|
|
23
|
+
.ReverseMap();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
2
|
+
|
|
3
|
+
<PropertyGroup>
|
|
4
|
+
<TargetFramework>net10.0</TargetFramework>
|
|
5
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
6
|
+
<Nullable>enable</Nullable>
|
|
7
|
+
</PropertyGroup>
|
|
8
|
+
|
|
9
|
+
<ItemGroup>
|
|
10
|
+
<ProjectReference Include="..\Shared.Core\Shared.Core.csproj" />
|
|
11
|
+
</ItemGroup>
|
|
12
|
+
|
|
13
|
+
<ItemGroup>
|
|
14
|
+
<Folder Include="Dtos\Public\" />
|
|
15
|
+
<Folder Include="Enums\" />
|
|
16
|
+
</ItemGroup>
|
|
17
|
+
|
|
18
|
+
</Project>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
using ItemModule.Core.Entities;
|
|
2
|
+
using ItemModule.Core.Interfaces.API;
|
|
3
|
+
using ItemModule.Core.Interfaces.SPI;
|
|
4
|
+
using Microsoft.Extensions.Logging;
|
|
5
|
+
using Shared.Core.Interfaces.SPI;
|
|
6
|
+
using Shared.Core.Services;
|
|
7
|
+
|
|
8
|
+
namespace ItemModule.Core.Services
|
|
9
|
+
{
|
|
10
|
+
public class ItemService : ItemService<Item>, IItemService
|
|
11
|
+
{
|
|
12
|
+
private readonly IItemInfra _userInfra;
|
|
13
|
+
public ItemService(ILogger<ItemService> logger,
|
|
14
|
+
IRepositoryFactory<Item> repositoryFactory,
|
|
15
|
+
IItemInfra userInfra) : base(logger, repositoryFactory)
|
|
16
|
+
{
|
|
17
|
+
_userInfra = userInfra;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
using ItemModule.Core.Entities;
|
|
2
|
+
using Microsoft.EntityFrameworkCore;
|
|
3
|
+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
4
|
+
|
|
5
|
+
namespace ItemModule.Infrastructure.Database
|
|
6
|
+
{
|
|
7
|
+
internal class ItemConfiguration : IEntityTypeConfiguration<Item>
|
|
8
|
+
{
|
|
9
|
+
public void Configure(EntityTypeBuilder<Item> builder)
|
|
10
|
+
{
|
|
11
|
+
// Table
|
|
12
|
+
builder.ToTable("Items");
|
|
13
|
+
|
|
14
|
+
// Primary key
|
|
15
|
+
builder.HasKey(x => x.Id);
|
|
16
|
+
|
|
17
|
+
// BaseEntity (nếu có)
|
|
18
|
+
builder.Property(x => x.Id)
|
|
19
|
+
.IsRequired();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
using ItemModule.Core.Entities;
|
|
2
|
+
using Microsoft.EntityFrameworkCore;
|
|
3
|
+
using Shared.Core.Enums;
|
|
4
|
+
using Shared.Core.Interfaces.SPI;
|
|
5
|
+
|
|
6
|
+
namespace ItemModule.Infrastructure.Database
|
|
7
|
+
{
|
|
8
|
+
public class Seeder : IModuleSeeder
|
|
9
|
+
{
|
|
10
|
+
public void Seed(ModelBuilder modelBuilder)
|
|
11
|
+
{
|
|
12
|
+
modelBuilder.Entity<Item>().HasData(
|
|
13
|
+
new Item
|
|
14
|
+
{
|
|
15
|
+
Id = Guid.Parse("11111111-1111-1111-1111-111111111111"),
|
|
16
|
+
Status = EntityStatus.Active,
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
using ItemModule.Core.Interfaces.API;
|
|
2
|
+
using ItemModule.Core.Interfaces.SPI;
|
|
3
|
+
using ItemModule.Core.Services;
|
|
4
|
+
using ItemModule.Infrastructure.Database;
|
|
5
|
+
using ItemModule.Infrastructure.Services;
|
|
6
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
7
|
+
using Shared.Core.Interfaces.API;
|
|
8
|
+
using Shared.Core.Interfaces.SPI;
|
|
9
|
+
using Shared.Core.Services;
|
|
10
|
+
using Shared.Infrastructure.Services.MySQL;
|
|
11
|
+
|
|
12
|
+
namespace ItemModule.Infrastructure
|
|
13
|
+
{
|
|
14
|
+
public static class ItemDependencyInjection
|
|
15
|
+
{
|
|
16
|
+
public static IServiceCollection AddItemModuleInfra(
|
|
17
|
+
this IServiceCollection services)
|
|
18
|
+
{
|
|
19
|
+
services.AddScoped<IModuleSeeder, Seeder>();
|
|
20
|
+
services.AddScoped(typeof(IItemService<>), typeof(ItemService<>));
|
|
21
|
+
services.AddScoped(typeof(IItemInfra<>), typeof(MySQLItemInfra<>));
|
|
22
|
+
services.AddScoped<IItemInfra, MySQLItemInfra>();
|
|
23
|
+
services.AddScoped<IItemService, ItemService>();
|
|
24
|
+
return services;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
2
|
+
|
|
3
|
+
<PropertyGroup>
|
|
4
|
+
<TargetFramework>net10.0</TargetFramework>
|
|
5
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
6
|
+
<Nullable>enable</Nullable>
|
|
7
|
+
</PropertyGroup>
|
|
8
|
+
|
|
9
|
+
<ItemGroup>
|
|
10
|
+
<ProjectReference Include="..\ItemModule.Core\ItemModule.Core.csproj" />
|
|
11
|
+
<ProjectReference Include="..\Shared.Infrastructure\Shared.Infrastructure.csproj" />
|
|
12
|
+
</ItemGroup>
|
|
13
|
+
|
|
14
|
+
</Project>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
using ItemModule.Core.Entities;
|
|
2
|
+
using ItemModule.Core.Interfaces.SPI;
|
|
3
|
+
using Microsoft.Extensions.Logging;
|
|
4
|
+
using Shared.Infrastructure;
|
|
5
|
+
using Shared.Infrastructure.Services.MySQL;
|
|
6
|
+
|
|
7
|
+
namespace ItemModule.Infrastructure.Services
|
|
8
|
+
{
|
|
9
|
+
public class MySQLItemInfra : MySQLItemInfra<Item>, IItemInfra
|
|
10
|
+
{
|
|
11
|
+
public MySQLItemInfra(MyDbContext dbContext, ILogger<MySQLItemInfra> logger)
|
|
12
|
+
: base(dbContext, logger)
|
|
13
|
+
{
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<Solution>
|
|
2
|
+
<Folder Name="/Host/">
|
|
3
|
+
<Project Path="Host.API/Host.API.csproj" />
|
|
4
|
+
</Folder>
|
|
5
|
+
<Folder Name="/Modules/" />
|
|
6
|
+
<Folder Name="/Modules/ItemModule/">
|
|
7
|
+
<Project Path="ItemModule.API/ItemModule.API.csproj" Id="c57fa45b-2f29-43e5-b170-35ed55caec58" />
|
|
8
|
+
<Project Path="ItemModule.Core/ItemModule.Core.csproj" Id="d2c886fa-7941-46a2-bf70-c1bc63fe3ce4" />
|
|
9
|
+
<Project Path="ItemModule.Infrastructure/ItemModule.Infrastructure.csproj" Id="617cb286-de79-466b-b1bf-b103dfc716ec" />
|
|
10
|
+
</Folder>
|
|
11
|
+
<Folder Name="/Modules/UserModule/">
|
|
12
|
+
<Project Path="User.API/UserModule.API.csproj" />
|
|
13
|
+
<Project Path="User.Core/UserModule.Core.csproj" />
|
|
14
|
+
<Project Path="User.Infrastructure/UserModule.Infrastructure.csproj" />
|
|
15
|
+
</Folder>
|
|
16
|
+
<Folder Name="/Shared/">
|
|
17
|
+
<Project Path="Shared.Core/Shared.Core.csproj" />
|
|
18
|
+
<Project Path="Shared.Infrastructure/Shared.Infrastructure.csproj" />
|
|
19
|
+
</Folder>
|
|
20
|
+
<Folder Name="/Solution Items/">
|
|
21
|
+
<File Path="README.md" />
|
|
22
|
+
</Folder>
|
|
23
|
+
</Solution>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
5. Tạo mới 1 project từ module:
|
|
2
|
+
- Chạy câu lệnh blueprint
|
|
3
|
+
|
|
4
|
+
- Sửa connection string (nếu cần)
|
|
5
|
+
- dotnet restore
|
|
6
|
+
|
|
7
|
+
6. Tạo mới 1 module
|
|
8
|
+
- Copy lại thư mục item để thêm module mới
|
|
9
|
+
- Sửa lại tên và toàn bộ namespace
|
|
10
|
+
- Sửa lại các nội dung sau (Trong Host.API):
|
|
11
|
+
+ Đăng ký ở ServiceCollectionExtensions.cs:
|
|
12
|
+
. Controller: .AddApplicationPart(typeof(ItemController).Assembly);
|
|
13
|
+
. Injection: ItemDependencyInjection.AddItemModuleInfra(services);
|
|
14
|
+
+ Đăng ký Mapping ở ThirdPartyExtensions.cs: typeof(DtoItemMappingProfile).Assembly,
|
|
15
|
+
+ Gọi ở Program.cs: builder.Services.AddItemModule();
|
|
16
|
+
|
|
17
|
+
7. Mock Data
|
|
18
|
+
- Tools → NuGet Package Manager → Package Manager Console
|
|
19
|
+
- Default project: catalog.Infra
|
|
20
|
+
- Xóa Migration cũ
|
|
21
|
+
- Add-Migration SeedInitialData
|
|
22
|
+
- Update-Database
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
using Shared.Core.Enums;
|
|
2
|
+
|
|
3
|
+
namespace Shared.Core.Dtos.Requests
|
|
4
|
+
{
|
|
5
|
+
/// <summary>
|
|
6
|
+
/// BaseRequestDto
|
|
7
|
+
/// </summary>
|
|
8
|
+
public class BaseRequestDto
|
|
9
|
+
{
|
|
10
|
+
/// <summary>
|
|
11
|
+
/// Id
|
|
12
|
+
/// </summary>
|
|
13
|
+
public Guid? Id { get; set; }
|
|
14
|
+
/// <summary>
|
|
15
|
+
/// Status
|
|
16
|
+
/// </summary>
|
|
17
|
+
public EntityStatus? Status { get; set; }
|
|
18
|
+
/// <summary>
|
|
19
|
+
/// Date
|
|
20
|
+
/// </summary>
|
|
21
|
+
public DateTime? Date { get; set; }
|
|
22
|
+
/// <summary>
|
|
23
|
+
/// Modified
|
|
24
|
+
/// </summary>
|
|
25
|
+
public DateTime? Modified { get; set; }
|
|
26
|
+
}
|
|
27
|
+
}
|