feat(EnvelopeReceiverRepository): Optionale schreibgeschützte Eingabe als Schnittstellenimplementierung hinzugefügt.

- Standardmäßig ist schreibgeschützt falsch.
This commit is contained in:
Developer 02 2024-12-10 22:33:32 +01:00
parent 085f37de16
commit f0f1275e75
2 changed files with 25 additions and 22 deletions

View File

@ -5,19 +5,19 @@ namespace EnvelopeGenerator.Infrastructure.Contracts
{ {
public interface IEnvelopeReceiverRepository : ICRUDRepository<EnvelopeReceiver, (int Envelope, int Receiver)> public interface IEnvelopeReceiverRepository : ICRUDRepository<EnvelopeReceiver, (int Envelope, int Receiver)>
{ {
Task<IEnumerable<EnvelopeReceiver>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false); Task<IEnumerable<EnvelopeReceiver>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false, bool readOnly = false);
Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true); Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true, bool readOnly = false);
Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true); Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = false);
Task<string?> ReadAccessCodeAsync(string uuid, string signature); Task<string?> ReadAccessCodeAsync(string uuid, string signature, bool readOnly = false);
Task<int> CountAsync(string uuid, string signature); Task<int> CountAsync(string uuid, string signature);
Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId); Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId, bool readOnly = false);
Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId); Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId, bool readOnly = false);
Task<IEnumerable<EnvelopeReceiver>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses); Task<IEnumerable<EnvelopeReceiver>> ReadByUsernameAsync(string username, int? min_status = null, int? max_status = null, params int[] ignore_statuses);

View File

@ -11,9 +11,9 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
{ {
} }
private IQueryable<EnvelopeReceiver> ReadWhere(string? uuid = null, string? signature = null, bool withEnvelope = false, bool withReceiver = false) private IQueryable<EnvelopeReceiver> ReadWhere(string? uuid = null, string? signature = null, bool withEnvelope = false, bool withReceiver = false, bool readOnly = false)
{ {
var query = _dbSet.AsNoTracking(); var query = readOnly ? _dbSet.AsNoTracking() : _dbSet;
if (uuid is not null) if (uuid is not null)
query = query.Where(er => er.Envelope != null && er.Envelope.Uuid == uuid); query = query.Where(er => er.Envelope != null && er.Envelope.Uuid == uuid);
@ -32,31 +32,34 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
return query; return query;
} }
public async Task<IEnumerable<EnvelopeReceiver>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false) public async Task<IEnumerable<EnvelopeReceiver>> ReadByUuidAsync(string uuid, bool withEnvelope = true, bool withReceiver = false, bool readOnly = false)
=> await ReadWhere(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync(); => await ReadWhere(uuid: uuid, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).ToListAsync();
public async Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true) public async Task<IEnumerable<EnvelopeReceiver>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true, bool readOnly = false)
=> await ReadWhere(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver).ToListAsync(); => await ReadWhere(signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).ToListAsync();
public async Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true) public async Task<EnvelopeReceiver?> ReadByUuidSignatureAsync(string uuid, string signature, bool withEnvelope = true, bool withReceiver = true, bool readOnly = false)
=> await ReadWhere(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver).FirstOrDefaultAsync(); => await ReadWhere(uuid: uuid, signature: signature, withEnvelope: withEnvelope, withReceiver: withReceiver, readOnly: readOnly).FirstOrDefaultAsync();
public async Task<string?> ReadAccessCodeAsync(string uuid, string signature) public async Task<string?> ReadAccessCodeAsync(string uuid, string signature, bool readOnly = false)
=> await ReadWhere(uuid: uuid, signature: signature) => await ReadWhere(uuid: uuid, signature: signature, readOnly: readOnly)
.Select(er => er.AccessCode) .Select(er => er.AccessCode)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
public async Task<int> CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync(); public async Task<int> CountAsync(string uuid, string signature) => await ReadWhere(uuid: uuid, signature: signature).CountAsync();
public IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId) => _dbSet.AsNoTracking() private IQueryable<EnvelopeReceiver> ReadById(int envelopeId, int receiverId, bool readOnly = false)
.Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId); {
var query = readOnly ? _dbSet.AsNoTracking() : _dbSet;
return query.Where(er => er.EnvelopeId == envelopeId && er.ReceiverId == receiverId);
}
public async Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId) public async Task<EnvelopeReceiver?> ReadByIdAsync(int envelopeId, int receiverId, bool readOnly = false)
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId) => await ReadById(envelopeId: envelopeId, receiverId: receiverId, readOnly: readOnly)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
public async Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId) public async Task<string?> ReadAccessCodeByIdAsync(int envelopeId, int receiverId, bool readOnly = false)
=> await ReadById(envelopeId: envelopeId, receiverId: receiverId) => await ReadById(envelopeId: envelopeId, receiverId: receiverId, readOnly: readOnly)
.Select(er => er.AccessCode) .Select(er => er.AccessCode)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();