Spaces:
Runtime error
Runtime error
Download src/SCM.Infrastructure/Persistence/Repositories/CroquiRepository.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/CroquiRepository.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Infrastructure/Persistence/Repositories/CroquiRepository.cs
-
curl -L -o CroquiRepository.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Infrastructure/Persistence/Repositories/CroquiRepository.cs
2.01 kB
| using System.Data; | |
| using Dapper; | |
| using SCM.Application.Common; | |
| using SCM.Domain.Qualidade; | |
| namespace SCM.Infrastructure.Persistence.Repositories; | |
| public sealed class CroquiRepository : ICroquiRepository | |
| { | |
| private readonly IUnitOfWork _uow; | |
| public CroquiRepository(IUnitOfWork uow) => _uow = uow; | |
| private IDbConnection Conn => _uow.Connection; | |
| private IDbTransaction? Tx => _uow.CurrentTransaction; | |
| public async Task<bool> RelatorioExistsAsync(Guid relatorioTecnicoId, CancellationToken ct = default) | |
| { | |
| var count = await Conn.ExecuteScalarAsync<long>(new CommandDefinition( | |
| "SELECT COUNT(*) FROM relatorios_tecnicos WHERE id = @Id", new { Id = relatorioTecnicoId }, Tx, cancellationToken: ct)); | |
| return count > 0; | |
| } | |
| public async Task<IReadOnlyList<Croqui>> GetByRelatorioAsync(Guid relatorioTecnicoId, CancellationToken ct = default) | |
| { | |
| const string sql = """ | |
| SELECT id, relatorio_tecnico_id, titulo, ordem, nome_imagem, tamanho_imagem | |
| FROM croquis WHERE relatorio_tecnico_id = @Id ORDER BY ordem | |
| """; | |
| var rows = await Conn.QueryAsync<Croqui>( | |
| new CommandDefinition(sql, new { Id = relatorioTecnicoId }, Tx, cancellationToken: ct)); | |
| return rows.ToList(); | |
| } | |
| public async Task AddAsync(Croqui c, CancellationToken ct = default) | |
| { | |
| const string sql = """ | |
| INSERT INTO croquis (id, relatorio_tecnico_id, titulo, ordem, nome_imagem, tamanho_imagem) | |
| VALUES (@Id, @RelatorioTecnicoId, @Titulo, @Ordem, @NomeImagem, @TamanhoImagem) | |
| """; | |
| await Conn.ExecuteAsync(new CommandDefinition(sql, c, Tx, cancellationToken: ct)); | |
| } | |
| public async Task<bool> DeleteAsync(Guid id, CancellationToken ct = default) | |
| { | |
| var affected = await Conn.ExecuteAsync(new CommandDefinition( | |
| "DELETE FROM croquis WHERE id = @Id", new { Id = id }, Tx, cancellationToken: ct)); | |
| return affected > 0; | |
| } | |
| } | |