网站首页 网站源码
website
站点相关全部源代码,隐藏了一些关于服务器的信息
namespace Dpz.Core.Service.V4.Implements;

public class AudioService : IAudioService
{
    private readonly IRepository<Audio> _repository;
    private readonly IMapper _mapper;

    public AudioService(IRepository<Audio> repository,IMapper mapper)
    {
        _repository = repository;
        _mapper = mapper;
    }
    
    public async Task<VmAudio> AddAsync(VmAudio audio)
    {
        if (audio == null)
            throw new ArgumentNullException(nameof(audio));
        if (audio.Uploader == null)
            throw new ArgumentNullException(nameof(audio.Uploader));
        if (audio.AccessUrl == null)
            throw new ArgumentNullException(nameof(audio.AccessUrl));


        var entity = _mapper.Map<Audio>(audio);
        await _repository.InsertAsync(entity);
        return _mapper.Map<VmAudio>(entity);
    }

    public async Task<VmAudio?> FindAsync(string id)
    {
        return _mapper.Map<VmAudio>(await _repository.TryGetAsync(id));
    }

    public async Task<IPagedList<VmAudio>> GetPagesAsync(int pageIndex, int pageSize, VmUserInfo? uploader = null)
    {
        var predicate = _repository.SearchFor(x => true);
        if (uploader != null)
            predicate = predicate.Where(x => x.Uploader.Id == uploader.Id);
        return await predicate.OrderByDescending(x => x.UploadTime).ToPagedListAsync<Audio, VmAudio>(pageIndex, pageSize);
    }

    public async Task DeleteAsync(string id)
    {
        await _repository.TryDeleteAsync(id);
    }
}
loading