< Summary

Information
Class: LGDXRobotCloud.API.Services.Automation.TriggerRetryService
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Services/Automation/TriggerRetryService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 62
Coverable lines: 62
Total lines: 91
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%2040%
GetTriggerRetriesAsync()100%210%
GetTriggerRetryAsync()0%620%
DeleteTriggerRetryAsync()100%210%
RetryTriggerRetryAsync()0%4260%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Services/Automation/TriggerRetryService.cs

#LineLine coverage
 1using LGDXRobotCloud.API.Exceptions;
 2using LGDXRobotCloud.Data.DbContexts;
 3using LGDXRobotCloud.Data.Models.Business.Automation;
 4using LGDXRobotCloud.Utilities.Helpers;
 5using Microsoft.EntityFrameworkCore;
 6
 7namespace LGDXRobotCloud.API.Services.Automation;
 8
 9public interface ITriggerRetryService
 10{
 11  Task<(IEnumerable<TriggerRetryListBusinessModel>, PaginationHelper)> GetTriggerRetriesAsync(int pageNumber, int pageSi
 12  Task<TriggerRetryBusinessModel> GetTriggerRetryAsync(int triggerRetryId);
 13  Task<bool> DeleteTriggerRetryAsync(int triggerRetryId);
 14  Task RetryTriggerRetryAsync(int triggerRetryId);
 15}
 16
 017public class TriggerRetryService (
 018  ITriggerService triggerService,
 019  LgdxContext context
 020) : ITriggerRetryService
 21{
 022  private readonly ITriggerService _triggerService = triggerService ?? throw new ArgumentNullException(nameof(triggerSer
 023  private readonly LgdxContext _context = context ?? throw new ArgumentNullException(nameof(context));
 24
 25  public async Task<(IEnumerable<TriggerRetryListBusinessModel>, PaginationHelper)> GetTriggerRetriesAsync(int pageNumbe
 026  {
 027    var triggerRetries = await _context.TriggerRetries.AsNoTracking()
 028      .Include(tr => tr.Trigger)
 029      .Include(tr => tr.AutoTask)
 030      .AsSplitQuery()
 031      .Select(tr => new TriggerRetryListBusinessModel {
 032        Id = tr.Id,
 033        TriggerId = tr.TriggerId,
 034        TriggerName = tr.Trigger.Name,
 035        AutoTaskId = tr.AutoTaskId,
 036        AutoTaskName = tr.AutoTask.Name,
 037        CreatedAt = tr.CreatedAt
 038      })
 039      .OrderBy(t => t.Id)
 040      .Skip(pageSize * (pageNumber - 1))
 041      .Take(pageSize)
 042      .ToListAsync();
 043      var itemCount = triggerRetries.Count;
 044      var PaginationHelper = new PaginationHelper(itemCount, pageNumber, pageSize);
 045      return (triggerRetries, PaginationHelper);
 046  }
 47
 48  public async Task<TriggerRetryBusinessModel> GetTriggerRetryAsync(int triggerRetryId)
 049  {
 050    return await _context.TriggerRetries.AsNoTracking()
 051      .Where(tr => tr.Id == triggerRetryId)
 052      .Include(tr => tr.Trigger)
 053      .Include(tr => tr.AutoTask)
 054      .Select(tr => new TriggerRetryBusinessModel {
 055        Id = tr.Id,
 056        TriggerId = tr.TriggerId,
 057        TriggerName = tr.Trigger.Name,
 058        TriggerUrl = tr.Trigger.Url,
 059        TriggerHttpMethodId = tr.Trigger.HttpMethodId,
 060        AutoTaskId = tr.AutoTaskId,
 061        AutoTaskName = tr.AutoTask.Name,
 062        Body = tr.Body,
 063        CreatedAt = tr.CreatedAt
 064      })
 065      .FirstOrDefaultAsync()
 066        ?? throw new LgdxNotFound404Exception();
 067  }
 68
 69  public async Task<bool> DeleteTriggerRetryAsync(int triggerRetryId)
 070  {
 071    return await _context.TriggerRetries.Where(tr => tr.Id == triggerRetryId)
 072      .ExecuteDeleteAsync() >= 1;
 073  }
 74
 75  public async Task RetryTriggerRetryAsync(int triggerRetryId)
 076  {
 077    var triggerRetry = await _context.TriggerRetries.AsNoTracking()
 078      .Where(tr => tr.Id == triggerRetryId)
 079      .FirstOrDefaultAsync() ?? throw new LgdxNotFound404Exception();
 80
 081    var autoTask = await _context.AutoTasks.AsNoTracking()
 082      .Where(at => at.Id == triggerRetry.AutoTaskId)
 083      .FirstOrDefaultAsync() ?? throw new LgdxValidation400Expection(nameof(triggerRetry.AutoTaskId), "AutoTask ID is in
 84
 085    var trigger = await _context.Triggers.AsNoTracking()
 086      .Where(t => t.Id == triggerRetry.TriggerId)
 087      .FirstOrDefaultAsync() ?? throw new LgdxValidation400Expection(nameof(triggerRetry.TriggerId), "Trigger ID is inva
 88
 089    await _triggerService.RetryTriggerAsync(autoTask, trigger, triggerRetry.Body);
 090  }
 91}