51 lines
2.5 KiB
C#
51 lines
2.5 KiB
C#
// <copyright file="AutomapperProfile.cs" company="alveus.dev">
|
|
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
|
|
// </copyright>
|
|
|
|
using Astral.Core.Constants;
|
|
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.Role.ToString()));
|
|
|
|
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));
|
|
|
|
CreateMap<UserLocationHeartbeatDto, UserPresence>()
|
|
.ForMember(
|
|
dest => dest.Availability,
|
|
opt => opt.MapFrom((src, dest) =>
|
|
Enum.TryParse(src.Availability, true, out Discoverability discoverability)
|
|
? discoverability
|
|
: Discoverability.None))
|
|
.ForMember(dest => dest.Connected, opt => opt.MapFrom(src => src.Connected))
|
|
.ForMember(dest => dest.Path, opt => opt.MapFrom(src => src.Path))
|
|
.ForMember(dest => dest.DomainId, opt => opt.MapFrom(src => src.DomainId))
|
|
.ForMember(dest => dest.NetworkAddress, opt => opt.MapFrom(src => src.NetworkAddress))
|
|
.ForMember(dest => dest.NetworkPort, opt => opt.MapFrom(src => src.NetworkPort))
|
|
.ForMember(dest => dest.NodeId, opt => opt.MapFrom(src => src.NodeId))
|
|
.ForMember(dest => dest.PlaceId, opt => opt.MapFrom(src => src.PlaceId));
|
|
}
|
|
}
|