FlowAPI / FlowAPI.Infrastructure /Repositories /SharedGraphRepository.cs
danylokhodus's picture
init
b9c7f0e
Raw
History Blame Contribute Delete
1.28 kB
using FlowAPI.Application.Interfaces;
using FlowAPI.Domain.Entities;
using FlowAPI.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace FlowAPI.Infrastructure.Repositories
{
public class SharedGraphRepository : GenericRepository<SharedGraph>, ISharedGraphRepository
{
public SharedGraphRepository(AppDbContext context) : base(context) { }
public async Task<IEnumerable<SharedGraph>> GetSharedGraphsByUserIdAsync(Guid userId)
{
return await _dbSet
.Include(s => s.Graph)
.Where(s => s.SharedWithUserId == userId)
.ToListAsync();
}
public async Task<SharedGraph?> GetShareAsync(Guid graphId, Guid sharedWithUserId)
{
return await _dbSet
.FirstOrDefaultAsync(s => s.GraphId == graphId && s.SharedWithUserId == sharedWithUserId);
}
public async Task<IEnumerable<SharedGraph>> GetSharesForGraphAsync(Guid graphId)
{
return await _dbSet
.Include(s => s.SharedWithUser)
.Where(s => s.GraphId == graphId)
.ToListAsync();
}
}
}