astral-api/Astral.Services/Profiles/AutomapperProfile.cs

36 lines
1.5 KiB
C#
Raw Normal View History

2024-12-11 21:36:30 +01:00
// <copyright file="AutomapperProfile.cs" company="alveus.dev">
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
// </copyright>
using Astral.Core.Entities;
using Astral.Services.Dtos;
using AutoMapper;
namespace Astral.Services.Profiles;
/// <summary>
/// Profile for AutoMapper.
/// </summary>
public class AutomapperProfile : Profile
{
/// <summary>
/// Initializes a new instance of the <see cref="AutomapperProfile" /> class.
/// </summary>
public AutomapperProfile()
{
CreateMap<User, UserDto>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.RegistrationDate, opt => opt.MapFrom(src => src.CreatedAt))
.ForMember(dest => dest.RegistrationDateTicks, opt => opt.MapFrom(src => src.CreatedAt.Ticks))
.ForMember(dest => dest.UserRole, opt => opt.MapFrom(src => src.UserRole));
CreateMap<UserGroup, UserGroupDto>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.CreationDate, opt => opt.MapFrom(src => src.CreatedAt))
.ForMember(dest => dest.CreationDateTicks, opt => opt.MapFrom(src => src.CreatedAt.Ticks))
.ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Title))
.ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Description))
.ForMember(dest => dest.Internal, opt => opt.MapFrom(src => src.Internal));
}
}