-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: add api to retrieve the latest data for server and client sdks (
#275) * get latest data for server & client sdk * fix * pr feedback
- Loading branch information
1 parent
c97109f
commit d431153
Showing
3 changed files
with
105 additions
and
40 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,59 @@ | ||
using Domain.EndUsers; | ||
using Domain.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Api.Public; | ||
|
||
public class SdkController : PublicApiControllerBase | ||
{ | ||
private readonly IDataSyncService _dataSyncService; | ||
|
||
public SdkController(IDataSyncService dataSyncService) | ||
{ | ||
_dataSyncService = dataSyncService; | ||
} | ||
|
||
[HttpGet("server/latest-all")] | ||
public async Task<IActionResult> GetServerSideSdkPayloadAsync() | ||
{ | ||
if (!Authenticated) | ||
{ | ||
return Unauthorized(); | ||
} | ||
|
||
var payload = await _dataSyncService.GetServerSdkPayloadAsync(EnvId, 0); | ||
|
||
var bootstrap = new | ||
{ | ||
messageType = "data-sync", | ||
data = payload | ||
}; | ||
|
||
return new JsonResult(bootstrap); | ||
} | ||
|
||
[HttpPost("client/latest-all")] | ||
public async Task<IActionResult> GetClientSdkPayloadAsync(EndUser endUser) | ||
{ | ||
if (!Authenticated) | ||
{ | ||
return Unauthorized(); | ||
} | ||
|
||
if (!endUser.IsValid()) | ||
{ | ||
return BadRequest("invalid end user"); | ||
} | ||
|
||
var payload = await _dataSyncService.GetClientSdkPayloadAsync(EnvId, endUser, 0); | ||
|
||
var bootstrap = payload.FeatureFlags.Select(x => new | ||
{ | ||
x.Id, | ||
x.Variation, | ||
x.VariationType | ||
}); | ||
|
||
return new JsonResult(bootstrap); | ||
} | ||
} |
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