-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB2CNotes
More file actions
55 lines (54 loc) · 3.38 KB
/
B2CNotes
File metadata and controls
55 lines (54 loc) · 3.38 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
// Sample: https://localhost:44315/api/applications?takeRows=3
[HttpGet]
public async Task<ActionResult<InputModels.Application[]>> GetApplications(int skipRows = Misc.Constants.ZERO,
int takeRows = Misc.Constants.TWENTY) =>
await TryCatch.SanitiseInput<int, int, Option<Error>>
((_skipRows, _takeRows) => // Check/Validate supplied Input Data, act accordingly.
{
if (_takeRows >= Misc.Constants.THREE && _takeRows <= Misc.Constants.TWO_FIFTY_FIVE
&& _skipRows >= Misc.Constants.ZERO)
{
return new None<Error>();
}
return new B2CBroker.Data.Errors.InvalidInput(Misc.Constants.Error_InvalidInputLengthForTakeAndSkip);
},
(e, l) => // Exception occured while parsing/sanitising supplied input data, handle and revert to cleint.
{
return new B2CBroker.Data.Errors.InvalidInput(Misc.Constants.Error_InvalidInput);
},
() =>
{
// Finally Block.
},
skipRows, takeRows)
.ProcessOnNoneAsync<Error, ActionResult>
((e) => // We have encountered Sanitisation Error, return the Information to Client.
{
string _errorMessage = e is B2CBroker.Data.Errors.InvalidInput
? e is B2CBroker.Data.Errors.InvalidInput i
? i._reason
: Misc.Constants.Message_ApplicationNotFound
: Misc.Constants.Message_ApplicationNotFound;
return Task.FromResult((ActionResult)base.BadRequest(_errorMessage));
},
async () => // Real Code - Goes in this Async Lambda.
(await TryCatch.ProcessBusinessTaskAsync<Either<Error, B2CBroker.Domain.Application[]>>
(
// Business Method to Run, when validation Succeeds.
_orchestrator.GetApplications(string.Empty, FetchCurrentAuthenticatedUser(),
_repo, Misc.Constants.FALSE, skipRows, takeRows),
(e, l) =>
{ // We have encountered exception in one of the Business Method(s)/Layers, relay sophisticated information back to client.
return new B2CBroker.Data.Errors.NoDataFound(Misc.Constants.Message_NoDataFound);
},
() =>
{
// Finally Block.
})
.ConfigureAwait(Misc.Constants.FALSE))
.Map(r => r != null
? (ActionResult)Ok(_mapper.Map<InputModels.Application[]>(r))
: (ActionResult)base.NotFound(Misc.Constants.Message_NoDataFound))
.Reduce(_ => base.NotFound(Misc.Constants.Message_NoDataFound),
error => error is B2CBroker.Data.Errors.ApplicationNotFound)
.Reduce(_ => (ActionResult)InternalServerError()));