feat(EnvelopeReceiverService): Status-Filteroption zu ReadByUserAsync hinzugefügt, um die Ergebnisse nach Status zu filtern

This commit is contained in:
Developer 02 2024-09-06 16:31:49 +02:00
parent 2e32559132
commit 01856b61ef
7 changed files with 38 additions and 13 deletions

View File

@ -11,6 +11,6 @@ namespace EnvelopeGenerator.Application.Contracts
Task<DataResult<EnvelopeDto>> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withHistory = false, bool withDocumentReceiverElement = false, bool withUser = false, bool withAll = false);
Task<DataResult<IEnumerable<EnvelopeDto>>> ReadByUserAsync(int userId);
Task<DataResult<IEnumerable<EnvelopeDto>>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[]ignore_statuses);
}
}

View File

@ -33,9 +33,9 @@ namespace EnvelopeGenerator.Application.Services
return Result.Success(readDto);
}
public async Task<DataResult<IEnumerable<EnvelopeDto>>> ReadByUserAsync(int userId)
public async Task<DataResult<IEnumerable<EnvelopeDto>>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses)
{
var users = await _repository.ReadByUserAsync(userId: userId);
var users = await _repository.ReadByUserAsync(userId: userId, min_status: min_status, max_status: max_status, ignore_statuses: ignore_statuses);
var readDto = _mapper.MapOrThrow<IEnumerable<EnvelopeDto>>(users);
return Result.Success(readDto);
}

View File

@ -70,6 +70,6 @@ export class EnvelopeTableComponent implements AfterViewInit {
private readonly erService: EnvelopeReceiverService = inject(EnvelopeReceiverService);
async ngAfterViewInit() {
this.data = await this.eService.getEnvelopeAsync();
this.data = await this.eService.getEnvelopeAsync(this.options);
}
}

View File

@ -14,11 +14,20 @@ export class EnvelopeService {
this.url = `${api_url}/envelope`;
}
public getEnvelope(): Observable<any> {
return this.http.get(this.url);
public getEnvelope(options?: { min_status?: number; max_status?: number; ignore_status?: number[] }): Observable<any> {
let params = new HttpParams();
if (options) {
if (options.min_status)
params = params.set('min_status', options.min_status.toString());
if (options.max_status)
params = params.set('max_status', options.max_status.toString());
if (options.ignore_status)
params = params.set('ignore_status', options.ignore_status.join(','));
}
return this.http.get(this.url, { params });
}
public async getEnvelopeAsync(): Promise<any> {
return await firstValueFrom(this.getEnvelope());
public async getEnvelopeAsync(options?: { min_status?: number; max_status?: number; ignore_status?: number[] }): Promise<any> {
return await firstValueFrom(this.getEnvelope(options));
}
}

View File

@ -21,12 +21,15 @@ namespace EnvelopeGenerator.GeneratorAPI.Controllers
[Authorize]
[HttpGet]
public async Task<IActionResult> GetCurrentAsync()
public async Task<IActionResult> GetCurrentAsync(
[FromQuery] int? min_status = null,
[FromQuery] int? max_status = null,
[FromQuery] params int[] ignore_statuses)
{
try
{
if (User.GetId() is int intId)
return await _envelopeService.ReadByUserAsync(intId).ThenAsync(
return await _envelopeService.ReadByUserAsync(intId, min_status: min_status, max_status: max_status, ignore_statuses: ignore_statuses).ThenAsync(
Success: Ok,
Fail: IActionResult (msg, ntc) =>
{

View File

@ -9,6 +9,6 @@ namespace EnvelopeGenerator.Infrastructure.Contracts
Task<Envelope?> ReadByUuidAsync(string uuid, bool withDocuments = false, bool withHistory = false, bool withDocumentReceiverElement = false, bool withUser = false, bool withAll = false);
Task<IEnumerable<Envelope>> ReadByUserAsync(int userId);
Task<IEnumerable<Envelope>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses);
}
}

View File

@ -46,7 +46,20 @@ namespace EnvelopeGenerator.Infrastructure.Repositories
return await query.FirstOrDefaultAsync();
}
public async Task<IEnumerable<Envelope>> ReadByUserAsync(int userId) => await _dbSet.AsNoTracking()
.Where(e => e.UserId == userId).ToListAsync();
public async Task<IEnumerable<Envelope>> ReadByUserAsync(int userId, int? min_status = null, int? max_status = null, params int[] ignore_statuses)
{
var query = _dbSet.AsNoTracking().Where(e => e.UserId == userId);
if (min_status is not null)
query = query.Where(e => e.Status >= min_status);
if (max_status is not null)
query = query.Where(e => e.Status <= max_status);
foreach (var ignore_status in ignore_statuses)
query = query.Where(e => e.Status != ignore_status);
return await query.ToListAsync();
}
}
}