-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExtractionController.cs
More file actions
92 lines (82 loc) · 3.55 KB
/
ExtractionController.cs
File metadata and controls
92 lines (82 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Microsoft.AspNetCore.Mvc;
using Quipu.ParameterizationExtractor.WebApi.Models;
using Quipu.ParameterizationExtractor.WebApi.Services;
namespace Quipu.ParameterizationExtractor.WebApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class ExtractionController : ControllerBase
{
private readonly IExtractionService _extractionService;
private readonly ILogger<ExtractionController> _logger;
public ExtractionController(IExtractionService extractionService, ILogger<ExtractionController> logger)
{
_extractionService = extractionService;
_logger = logger;
}
/// <summary>
/// </summary>
[HttpPost("extract")]
public async Task<IActionResult> ExtractAsync([FromBody] ExtractionRequest request, CancellationToken cancellationToken = default)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_logger.LogInformation("Received extraction request for config type: {ConfigType}", request.ConfigType);
var result = await _extractionService.ProcessExtractionAsync(request, cancellationToken);
if (!result.Success)
{
return BadRequest(new { error = result.ErrorMessage });
}
return File(result.ZipFileContent!, "application/zip", result.FileName);
}
/// <summary>
/// </summary>
[HttpGet("health")]
public IActionResult Health()
{
return Ok(new { status = "healthy", timestamp = DateTime.UtcNow });
}
/// <summary>
/// </summary>
[HttpGet("formats")]
public IActionResult GetFormats()
{
var formats = new
{
supported_formats = new[] { "DSL", "JSON", "XML" },
examples = new
{
dsl = @"for script ""example"" take from ""Users"" where ""Active = 1"" consider FK for ""Users"" and UniqueColumns ""Id"" build sql with asIs",
json = new
{
scripts = new[]
{
new
{
scriptName = "example",
rootRecords = new[]
{
new { tableName = "Users", where = "Active = 1", processingOrder = 0 }
},
tablesToProcess = new[]
{
new
{
tableName = "Users",
uniqueColumns = new[] { "Id" },
extractStrategy = "FK",
sqlBuildOptions = new[] { "AsIsInserts" }
}
}
}
}
},
xml = @"<Package><Scripts><SourceForScript ScriptName=""example""><RootRecords><RecordsToExtract TableName=""Users"" Where=""Active = 1"" ProcessingOrder=""0"" /></RootRecords><TablesToProcess><TableToExtract TableName=""Users""><UniqueColumns><string>Id</string></UniqueColumns></TableToExtract></TablesToProcess></SourceForScript></Scripts></Package>"
}
};
return Ok(formats);
}
}
}