using AutoMapper; using MediatR; using Sufi.Demo.PeopleDirectory.Application.Contracts.Repositories; using Sufi.Demo.PeopleDirectory.Application.Contracts.Services; using Sufi.Demo.PeopleDirectory.Domain.Entities.Misc; using Sufi.Demo.PeopleDirectory.Shared.Wrapper; namespace Sufi.Demo.PeopleDirectory.Application.Features.Contacts.Queries.GetAll { public class GetAllContactsQuery : IRequest>> { } public class GetAllContactsQueryHandler( IUnitOfWork unitOfWork, IMapper mapper, IAppCache appCache ) : IRequestHandler>> { public async Task>> Handle(GetAllContactsQuery request, CancellationToken cancellationToken) { Task> allContactsFunc() => unitOfWork.Repository().GetAllAsync(); var allContacts = await appCache.GetOrAddAsync( "contact_all", async token => await allContactsFunc(), absoluteExpireTime: TimeSpan.FromMinutes(2), tags: ["contacts"] ); var mappedContacts = mapper.Map>(allContacts); return await Result>.SuccessAsync(mappedContacts); } } }