2026-04-11 21:36:05 +02:00

29 lines
1.0 KiB
C#

using AutoMapper;
using OnlyPrompt.Backend.ApiModels.Auth;
using OnlyPrompt.Backend.ApiModels.UserProfile;
using OnlyPrompt.Backend.Database.Models;
namespace OnlyPrompt.Backend.Utils
{
public static class AutoMapperSetup
{
public static void Setup(IMapperConfigurationExpression config)
{
config.CreateMap<UserModel, ApiUser>()
.MapCtorParamFrom(x => x.Id, x => x.Id)
.MapCtorParamFrom(x => x.UserName, x => x.UserName)
.MapCtorParamFrom(x => x.Roles, x => x.Roles)
.MapCtorParamFrom(x => x.Email, x => x.Email);
config.CreateMap<UserProfileModel, ApiUserProfile>()
.MapCtorParamFrom(x => x.DisplayName, x => x.DisplayName)
.MapCtorParamFrom(x => x.Slug, x => x.Slug)
.MapCtorParamFrom(x => x.Bio, x => x.Bio)
.MapCtorParamFrom(x => x.AvatarUrl, x => x.AvatarUrl)
.MapCtorParamFrom(x => x.Specialities, x => x.Specialities)
.MapCtorParamFrom(x => x.AverageRating, x => x.User.Prompts.Average(p => p.Reviews.Average(r => r.Rating)))
.MapCtorParamFrom(x => x.Subscribers, x => x.User.Subscribers.Count());
}
}
}