-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add triggering anonymizer from endpoint
- Loading branch information
Showing
6 changed files
with
76 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using api.Controllers.Models; | ||
using api.Services; | ||
using api.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace api.Controllers; | ||
|
||
public class TriggerAnonymizerRequest | ||
{ | ||
public required string InspectionId { get; set; } | ||
public required Uri RawDataUri { get; set; } | ||
public required Uri AnonymizedUri { get; set; } | ||
} | ||
|
||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
public class AnonymizerController(AnonymizerService anonymizerService, IdaDbContext dbContext) : ControllerBase | ||
{ | ||
private readonly AnonymizerService anonymizerService = anonymizerService; | ||
private readonly IdaDbContext dbContext = dbContext; | ||
|
||
/// <summary> | ||
/// Triggers the anonymizer workflow. NB: Anonymizer workflow should normally be triggered by MQTT message | ||
/// </summary> | ||
[HttpPost] | ||
[Route("trigger-anonymizer")] | ||
[Authorize(Roles = Role.Any)] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> TriggerAnonymizer([FromBody] TriggerAnonymizerRequest request) | ||
{ | ||
var inspectionData = new InspectionData | ||
{ | ||
Id = Guid.NewGuid().ToString(), | ||
InspectionId = request.InspectionId, | ||
RawDataUri = request.RawDataUri, | ||
AnonymizedUri = request.AnonymizedUri, | ||
DateCreated = DateTime.UtcNow, | ||
AnonymizerWorkflowStatus = WorkflowStatus.NotStarted, | ||
AnalysisToBeRun = [], | ||
Analysis = [] | ||
}; | ||
|
||
dbContext.InspectionData.Add(inspectionData); | ||
await dbContext.SaveChangesAsync(); | ||
|
||
await anonymizerService.TriggerAnonymizerFunc(inspectionData); | ||
|
||
return Ok("Anonymizer workflow triggered successfully."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters