using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using PodNoms.Api.Models; namespace PodNoms.Api.Persistence { public interface IPodcastRepository : IRepository { Task GetAsync(string id, string slug); Task> GetAllForUserAsync(string userId); } public class PodcastRepository : GenericRepository, IPodcastRepository { public PodcastRepository(PodNomsDbContext context, ILogger logger) : base(context, logger) { } public async Task GetAsync(string id, string slug) { var ret = await GetAll() .Where(p => p.Slug == slug && p.AppUser.Id == id) .Include(p => p.PodcastEntries) .Include(p => p.AppUser) .FirstOrDefaultAsync(); return ret; } public async Task> GetAllForUserAsync(string userId) { var ret = GetAll() .Where(u => u.AppUser.Id == userId) .Include(p => p.AppUser) .OrderByDescending(p => p.Id); return await ret.ToListAsync(); } } }