Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
neophyte57 committed Sep 17, 2024
1 parent 9db273f commit 31cd9db
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Serilog;

using Prime.Configuration.Auth;
using Prime.Models;
using Prime.Models.Api;
using Prime.Services;
using Prime.HttpClients.Mail;
using Newtonsoft.Json.Serialization;

namespace Prime.Controllers
{
Expand Down Expand Up @@ -174,16 +177,26 @@ public async Task<ActionResult> GetGpid()
[ProducesResponseType(typeof(ApiResultResponse<GpidDetailLookup>), StatusCodes.Status200OK)]
public async Task<ActionResult> GetGpidDetail()
{
string accessToken = await HttpContext.GetTokenAsync("access_token");
JwtPayload jwtPayload = new JwtSecurityToken(accessToken).Payload;
string authorizedParty = jwtPayload.Azp;
var logId = await _vendorAPILogService.CreateLogAsync(authorizedParty, Request.Path.Value, null);

var result = new GpidDetailLookup();
var enrollee = await _enrolleeService.GetActiveGpidDetailAsync(User.GetPrimeUsername());
if (enrollee != null)
{
return Ok(_mapper.Map(enrollee, result));
_mapper.Map(enrollee, result);
await _vendorAPILogService.UpdateLogAsync(logId, SerializeObjectForLog(result));
var enrolleeStub = await _enrolleeService.GetEnrolleeStubAsync(User.GetPrimeUsername());
await _businessEventService.CreateEnrolleeEventAsync(enrolleeStub.Id,
$"First-time provisioning API (aka GetGpidDetail) returned data to calling entity {TranslateAuthorizedParty(authorizedParty)}");
return Ok(result);
}

return Ok(enrollee);
}


// POST: api/provisioner-access/gpid-lookup
/// <summary>
/// Gets the enrollee licence information by providing GPID, Firstname, Lastname and Care Setting code.
Expand Down Expand Up @@ -274,5 +287,23 @@ private static string SerializeObjectForLog(object obj)
};
return JsonConvert.SerializeObject(obj, serializerSettings);
}

/// <summary>
/// Translate given to something PRIME administrator would understand
/// </summary>
/// <param name="authorizedParty"></param>
/// <returns></returns>
private string TranslateAuthorizedParty(string authorizedParty)
{
switch (authorizedParty)
{
case "PRIME-POS-GPID":
return "Medinet";
case "PRIME-APPLICATION-LOCAL":
return "PRIME (testing)";
default:
return "N/A";
}
}
}
}
}

0 comments on commit 31cd9db

Please sign in to comment.