using Foxnouns.Backend.Database; using Foxnouns.Backend.Database.Models; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; namespace Foxnouns.Backend.Services; public class UserRendererService(DatabaseContext db, MemberRendererService memberRendererService) { public async Task RenderUserAsync(User user, User? selfUser = null, bool renderMembers = true) { renderMembers = renderMembers && (!user.ListHidden || selfUser?.Id == user.Id); var members = renderMembers ? await db.Members.Where(m => m.UserId == user.Id).ToListAsync() : []; return new UserResponse( user.Id, user.Username, user.DisplayName, user.Bio, user.MemberTitle, user.Avatar, user.Links, user.Names, user.Pronouns, user.Fields, renderMembers ? members.Select(memberRendererService.RenderPartialMember) : null); } public record UserResponse( Snowflake Id, string Username, string? DisplayName, string? Bio, string? MemberTitle, string? AvatarUrl, string[] Links, IEnumerable Names, IEnumerable Pronouns, IEnumerable Fields, [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] IEnumerable? Members ); }