File size: 1,275 Bytes
b9c7f0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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();
        }
    }
}