limit to one playout per channel (#164)

This commit is contained in:
Jason Dove
2021-04-11 05:55:26 -05:00
committed by GitHub
parent 993293c104
commit 34fbfce0a5
4 changed files with 26 additions and 4 deletions
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Repositories;
using LanguageExt;
@@ -12,8 +14,13 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
public class ChannelRepository : IChannelRepository
{
private readonly TvContext _dbContext;
private readonly IDbConnection _dbConnection;
public ChannelRepository(TvContext dbContext) => _dbContext = dbContext;
public ChannelRepository(TvContext dbContext, IDbConnection dbConnection)
{
_dbContext = dbContext;
_dbConnection = dbConnection;
}
public async Task<Channel> Add(Channel channel)
{
@@ -81,5 +88,10 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
_dbContext.Channels.Remove(channel);
await _dbContext.SaveChangesAsync();
}
public Task<int> CountPlayouts(int channelId) =>
_dbConnection.QuerySingleAsync<int>(
@"SELECT COUNT(*) FROM Playout WHERE ChannelId = @ChannelId",
new { ChannelId = channelId });
}
}