Revize f2249f10
Přidáno uživatelem Vojtěch Bartička před asi 3 roky(ů)
Backend/Backend/Program.cs | ||
---|---|---|
9 | 9 |
using RestAPI.Middleware; |
10 | 10 |
using RestAPI.Utils; |
11 | 11 |
using Serilog; |
12 |
using AutoMapper; |
|
13 |
using Core.MapperProfiles; |
|
12 | 14 |
|
13 | 15 |
var builder = WebApplication.CreateBuilder(args); |
14 | 16 |
|
... | ... | |
57 | 59 |
// Database |
58 | 60 |
builder.Services.AddDbContext<DatabaseContext>(); |
59 | 61 |
|
62 |
// AutoMapper |
|
63 |
RegisterMappings.Register(builder); |
|
60 | 64 |
var app = builder.Build(); |
61 | 65 |
|
62 | 66 |
// Enable DateTime in PostgreSQL |
Backend/Backend/RestAPI.csproj | ||
---|---|---|
9 | 9 |
</PropertyGroup> |
10 | 10 |
|
11 | 11 |
<ItemGroup> |
12 |
<PackageReference Include="AutoMapper" Version="11.0.1" /> |
|
13 |
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" /> |
|
12 | 14 |
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.3" /> |
13 | 15 |
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.3"> |
14 | 16 |
<PrivateAssets>all</PrivateAssets> |
Backend/Core/Core.csproj | ||
---|---|---|
7 | 7 |
</PropertyGroup> |
8 | 8 |
|
9 | 9 |
<ItemGroup> |
10 |
<PackageReference Include="AutoMapper" Version="11.0.1" /> |
|
11 |
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" /> |
|
10 | 12 |
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" /> |
11 | 13 |
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.3" /> |
12 | 14 |
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.3" /> |
Backend/Core/MapperProfiles/DocumentProfileEF.cs | ||
---|---|---|
1 |
using AutoMapper; |
|
2 |
using Core.Entities; |
|
3 |
using Models.Documents; |
|
4 |
using System; |
|
5 |
using System.Collections.Generic; |
|
6 |
using System.Linq; |
|
7 |
using System.Text; |
|
8 |
using System.Threading.Tasks; |
|
9 |
|
|
10 |
namespace Core.MapperProfiles |
|
11 |
{ |
|
12 |
public class DocumentProfileEF : Profile |
|
13 |
{ |
|
14 |
public DocumentProfileEF() |
|
15 |
{ |
|
16 |
CreateMap<Document, DocumentListInfo>(); |
|
17 |
/*.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id)) |
|
18 |
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name)) |
|
19 |
.ForMember(dest => dest.Length, opt => opt.MapFrom(src => src.Length)) |
|
20 |
.ForMember(dest => dest.RequiredAnnotations, opt => opt.MapFrom(src => src.RequiredAnnotations));*/ |
|
21 |
|
|
22 |
} |
|
23 |
} |
|
24 |
} |
Backend/Core/MapperProfiles/RegisterMappings.cs | ||
---|---|---|
1 |
using Microsoft.AspNetCore.Builder; |
|
2 |
using System; |
|
3 |
using System.Collections.Generic; |
|
4 |
using System.Linq; |
|
5 |
using System.Text; |
|
6 |
using System.Threading.Tasks; |
|
7 |
using AutoMapper; |
|
8 |
using Microsoft.Extensions.DependencyInjection; |
|
9 |
|
|
10 |
namespace Core.MapperProfiles |
|
11 |
{ |
|
12 |
public class RegisterMappings |
|
13 |
{ |
|
14 |
public static void Register(WebApplicationBuilder builder) |
|
15 |
{ |
|
16 |
builder.Services.AddAutoMapper(typeof(UserProfileEF), typeof(DocumentProfileEF)); |
|
17 |
} |
|
18 |
} |
|
19 |
} |
Backend/Core/MapperProfiles/UserProfileEF.cs | ||
---|---|---|
1 |
using AutoMapper; |
|
2 |
using Core.Entities; |
|
3 |
using Models.Users; |
|
4 |
using System; |
|
5 |
using System.Collections.Generic; |
|
6 |
using System.Linq; |
|
7 |
using System.Text; |
|
8 |
using System.Threading.Tasks; |
|
9 |
|
|
10 |
namespace Core.MapperProfiles |
|
11 |
{ |
|
12 |
public class UserProfileEF : Profile |
|
13 |
{ |
|
14 |
public UserProfileEF() |
|
15 |
{ |
|
16 |
CreateMap<User, UserInfo>(); |
|
17 |
} |
|
18 |
} |
|
19 |
} |
Backend/Models/Models.csproj | ||
---|---|---|
6 | 6 |
<Nullable>enable</Nullable> |
7 | 7 |
</PropertyGroup> |
8 | 8 |
|
9 |
<ItemGroup> |
|
10 |
<PackageReference Include="AutoMapper" Version="11.0.1" /> |
|
11 |
</ItemGroup> |
|
12 |
|
|
9 | 13 |
</Project> |
Také k dispozici: Unified diff
Added AutoMapper, configured, added DTO mappings