Currently when returning data for a GET or a LIST we get whole aggregate/s and then we map to the model this results in slow queries and huge amount of data fetched over the wire.
[ ] Specifications for listing should map to the model
[ ] Add get by id specification to map to the model
examples:
public class ListElectionRoundsSpecification : Specification<ElectionRoundAggregate, ElectionRoundBaseModel>
{
public ListElectionRoundsSpecification(List.Request request)
{
Query
.Search(x => x.Title, "%" + request.TitleFilter + "%", !string.IsNullOrEmpty(request.TitleFilter))
.Where(x => x.Status == request.Status, request.Status != null)
.Where(x => x.CountryId == request.CountryId, request.CountryId != null)
.ApplyOrdering(request)
.Paginate(request);
Query.Select(x => new ElectionRoundBaseModel
{
Id = x.Id,
Title = x.Title,
EnglishTitle = x.EnglishTitle,
StartDate = x.StartDate,
Status = x.Status,
CreatedOn = x.CreatedOn,
LastModifiedOn = x.LastModifiedOn
});
}
}
public class GetElectionRoundByIdSpecification : SingleResultSpecification<ElectionRoundAggregate, ElectionRoundModel>
{
public GetElectionRoundByIdSpecification(Guid id)
{
Query
.Where(x => x.Id == id)
.Include(x => x.MonitoringNgos)
.ThenInclude(x => x.Ngo)
.Include(x => x.MonitoringObservers)
.ThenInclude(x => x.Observer)
.Include(x => x.MonitoringObservers)
.ThenInclude(x => x.InviterNgo);
Query.Select(electionRound => new ElectionRoundModel
{
Id = electionRound.Id,
Title = electionRound.Title,
EnglishTitle = electionRound.EnglishTitle,
Status = electionRound.Status,
StartDate = electionRound.StartDate,
LastModifiedOn = electionRound.LastModifiedOn,
CreatedOn = electionRound.CreatedOn,
MonitoringObservers = electionRound.MonitoringObservers.Select(observer => new MonitoringObserverModel
{
ObserverId = observer.ObserverId,
Name = observer.Observer.Name,
Status = observer.Observer.Status
}).ToList(),
MonitoringNgos = electionRound.MonitoringNgos.Select(ngo => new MonitoringNgoModel
{
NgoId = ngo.NgoId,
Name = ngo.Ngo.Name,
Status = ngo.Ngo.Status
}).ToList()
});
}
}
Currently when returning data for a GET or a LIST we get whole aggregate/s and then we map to the model this results in slow queries and huge amount of data fetched over the wire.
examples: