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

52 lines
2.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>
2024-12-15 21:20:27 +01:00
using Astral.Core.Constants;
2024-12-11 21:36:30 +01:00
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))
2024-12-14 17:31:17 +01:00
.ForMember(dest => dest.UserRole, opt => opt.MapFrom(src => src.Role.ToString()));
2024-12-11 21:36:30 +01:00
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));
2024-12-15 21:20:27 +01:00
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));
2024-12-11 21:36:30 +01:00
}
}