Spaces:
Runtime error
Runtime error
Download src/SCM.Infrastructure/Persistence/Repositories/LinhaBaseRepository.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/LinhaBaseRepository.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Infrastructure/Persistence/Repositories/LinhaBaseRepository.cs
-
curl -L -o LinhaBaseRepository.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/LinhaBaseRepository.cs
2.45 kB
| using System.Data; | |
| using Dapper; | |
| using SCM.Application.Common; | |
| using SCM.Application.Medicao; | |
| using SCM.Domain.Medicao; | |
| namespace SCM.Infrastructure.Persistence.Repositories; | |
| public sealed class LinhaBaseRepository : ILinhaBaseRepository | |
| { | |
| private readonly IUnitOfWork _uow; | |
| public LinhaBaseRepository(IUnitOfWork uow) => _uow = uow; | |
| private IDbConnection Conn => _uow.Connection; | |
| private IDbTransaction? Tx => _uow.CurrentTransaction; | |
| public async Task<IReadOnlyList<LinhaBasePonto>> GetByEapAsync(Guid eapId, CancellationToken ct = default) | |
| { | |
| const string sql = """ | |
| SELECT id, eap_id, semana, data, percentual, origem | |
| FROM eap_linha_base_pontos WHERE eap_id = @Id ORDER BY semana | |
| """; | |
| var rows = await Conn.QueryAsync<LinhaBasePonto>( | |
| new CommandDefinition(sql, new { Id = eapId }, Tx, cancellationToken: ct)); | |
| return rows.ToList(); | |
| } | |
| public async Task<bool> EapExistsAsync(Guid eapId, CancellationToken ct = default) | |
| { | |
| const string sql = "SELECT COUNT(*) FROM eaps WHERE id = @Id"; | |
| var count = await Conn.ExecuteScalarAsync<long>( | |
| new CommandDefinition(sql, new { Id = eapId }, Tx, cancellationToken: ct)); | |
| return count > 0; | |
| } | |
| public async Task ReplaceAsync(Guid eapId, IReadOnlyList<LinhaBasePonto> pontos, CancellationToken ct = default) | |
| { | |
| await Conn.ExecuteAsync(new CommandDefinition( | |
| "DELETE FROM eap_linha_base_pontos WHERE eap_id = @Id", | |
| new { Id = eapId }, Tx, cancellationToken: ct)); | |
| const string sql = """ | |
| INSERT INTO eap_linha_base_pontos (id, eap_id, semana, data, percentual, origem) | |
| VALUES (@Id, @EapId, @Semana, @Data, @Percentual, @Origem) | |
| """; | |
| foreach (var p in pontos) | |
| await Conn.ExecuteAsync(new CommandDefinition(sql, new | |
| { | |
| p.Id, p.EapId, p.Semana, p.Data, p.Percentual, p.Origem | |
| }, Tx, cancellationToken: ct)); | |
| } | |
| public async Task<bool> DeletePontoAsync(Guid eapId, int semana, CancellationToken ct = default) | |
| { | |
| const string sql = "DELETE FROM eap_linha_base_pontos WHERE eap_id = @EapId AND semana = @Semana"; | |
| var affected = await Conn.ExecuteAsync(new CommandDefinition( | |
| sql, new { EapId = eapId, Semana = semana }, Tx, cancellationToken: ct)); | |
| return affected > 0; | |
| } | |
| } | |