using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Text.Json.Serialization; using System.Threading.Tasks; using MongoDB.Bson; using MongoDB.Driver; using UGQDataAccess.Repository.Models; using UGQDatabase.Models; using static UGQDataAccess.Repository.Query.QuestContentQuery; namespace UGQDataAccess.Repository.Query; public static class AccountQuery { public class AllAccountQueryJoin : AccountEntity { public IEnumerable QuestContents { get; set; } = null!; public int QuestCount { get; set; } = 0; } public static Expression> AccountItemResultProjection = x => new AccountItemResult { UserGuid = x.UserGuid, Nickname = x.Nickname, AccountId = x.AccountId ?? "", AdditionalSlotCount = x.AdditionalSlotCount, GradeType = x.GradeType, CreatorPoint = x.CreatorPoint, CreatedAt = x.CreatedAt, QuestCount = x.QuestCount, }; public static PipelineDefinition allAccountPipeline( FilterDefinition filter, Expression> projection) { var lookupStage1 = new BsonDocument("$lookup", new BsonDocument { { "from", "QuestContent" }, { "localField", "UserGuid" }, { "foreignField", "UserGuid" }, { "pipeline", new BsonArray { new BsonDocument("$match", new BsonDocument("IsDeleted", false)) } }, { "as", "QuestContents" } }); var addFields1 = new BsonDocument("$addFields", new BsonDocument("QuestCount", new BsonDocument("$size", "$QuestContents"))); var pipeline = new EmptyPipelineDefinition() .Match(filter) .AppendStage(lookupStage1) .AppendStage(addFields1) .Project(projection); return pipeline; } }