ActionConfigurationRepository.cs 2.09 KB
using Microsoft.EntityFrameworkCore;
using Rcs.Domain.Entities;
using Rcs.Domain.Enums;
using Rcs.Domain.Repositories;
using Rcs.Infrastructure.DB.MsSql;

namespace Rcs.Infrastructure.DB.Repositories
{
    public class ActionConfigurationRepository : Repository<ActionConfiguration>, IActionConfigurationRepository
    {
        public ActionConfigurationRepository(AppDbContext context) : base(context)
        {
        }

        public async Task<IEnumerable<ActionConfiguration>> GetByManufacturerAndTypeAsync(
            string manufacturer,
            RobotType robotType,
            ActionCategory actionCategory,
            CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(a => a.Manufacturer == manufacturer 
                    && a.RobotType == robotType 
                    && a.ActionCategory == actionCategory)
                .ToListAsync(cancellationToken);
        }

        public async Task<IEnumerable<ActionConfiguration>> GetEnabledByManufacturerAndTypeAsync(
            string manufacturer,
            RobotType robotType,
            CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Where(a => a.Manufacturer == manufacturer 
                    && a.RobotType == robotType 
                    && a.IsEnabled)
                .OrderBy(a => a.SortOrder)
                .ToListAsync(cancellationToken);
        }

        public async Task<ActionConfiguration?> GetByActionNameAsync(
            string actionName,
            CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .FirstOrDefaultAsync(a => a.ActionName == actionName, cancellationToken);
        }

        public async Task<ActionConfiguration?> GetWithParametersAsync(
            Guid actionConfigId,
            CancellationToken cancellationToken = default)
        {
            return await _dbSet
                .Include(a => a.Parameters)
                .FirstOrDefaultAsync(a => a.ActionConfigId == actionConfigId, cancellationToken);
        }
    }
}