-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathShelvesComplianceController.cs
More file actions
82 lines (75 loc) · 3.33 KB
/
Copy pathShelvesComplianceController.cs
File metadata and controls
82 lines (75 loc) · 3.33 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Contoso.CognitivePipeline.API.Helpers;
using Contoso.CognitivePipeline.SharedModels.Models;
using Contoso.SB.API.Abstractions;
using Contoso.SB.API.BusinessLogic;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Contoso.CognitivePipeline.API.Controllers
{
[Route("api/shelvescompliance")]
public class ShelvesComplianceController : ControllerBase
{
public const ClassificationType docType = ClassificationType.StoreShelf;
IStorageRepository storageRepository;
IDocumentDBRepository<SmartDoc> docRepository;
IDocumentDBRepository<User> userRepository;
INewCognitiveRequest<SmartDoc> newReqService;
public ShelvesComplianceController(IStorageRepository storage, IDocumentDBRepository<SmartDoc> documentDBRepository, IDocumentDBRepository<User> uRepository, INewCognitiveRequest<SmartDoc> newAsyncReq)
{
storageRepository = storage;
docRepository = documentDBRepository;
userRepository = uRepository;
newReqService = newAsyncReq;
}
/// <summary>
/// Check the health of the service
/// </summary>
/// <returns>The status message</returns>
[HttpGet]
[ProducesResponseType(200)]
public IActionResult Get()
{
return Ok("{\"status\": \"" + this.GetType().Name + " working...\"}");
}
/// <summary>
/// Submit a new Document file to be processed by the Cognitive Pipeline
/// </summary>
/// <returns>The result of document after processing</returns>
/// <param name="ownerId">Document Owner Id (like EmployeeId or CustomerId)</param>
/// <param name="isAsync">Flag to indicate if operations need to execute immediately or will be queued</param>
/// <param name="doc">The binary of the document being processed</param>
/// <param name="isMinimum">Flag to optimize the output by removing additions details from the results.</param>
[HttpPost("{ownerId}")]
[ProducesResponseType(200, Type = typeof(ShelfCompliance))]
[ProducesResponseType(400)]
[Consumes("multipart/form-data")]
public async Task<IActionResult> SubmitDoc(string ownerId, [FromForm] IFormFile doc, [FromHeader] bool isAsync = false, [FromHeader] bool isMinimum = true)
{
NewRequest<SmartDoc> newReq = null;
string result = null;
try
{
newReq = await ClassificationRequestHelper.CreateNewRequest(
ownerId, isAsync, doc, docType, storageRepository, docRepository, userRepository);
result = await newReqService.SendNewRequest(newReq, newReq.RequestItem.Id, isAsync);
}
catch (Exception ex)
{
return new BadRequestObjectResult(ex.Message);
}
//Reduce the size of the payload if isMinimum = true
if (isMinimum)
{
var output = JsonConvert.DeserializeObject<ShelfCompliance>(result);
output.OptimizeSmartDoc(isMinimum);
result = JsonConvert.SerializeObject(output);
}
return Ok(result);
}
}
}