public async Task <IActionResult> RequestPlatformDataUpdateNotification(PlatformDataUpdateRequestModel model, CancellationToken cancellationToken) { var uniqueUserIdentifier = _httpContextAccessor.HttpContext.User.Identity.Name; using var session = _documentStore.OpenAsyncSession(); var existingUser = await _userManager.GetUserByUniqueIdentifier(uniqueUserIdentifier, session, cancellationToken); var app = await _appManager.GetAppFromApplicationId(model.ApplicationId, session, cancellationToken); var platform = await _platformManager.GetPlatformByExternalId(model.PlatformId, session, cancellationToken); var platformConnectionInfo = _platformConnectionManager.GetPlatformConnectionInfo(existingUser, platform.Id); if (platformConnectionInfo.NotificationInfos.All(ni => ni.AppId != app.Id)) { //app not registered for notification. Throw. throw new AppNotRegisteredForNotificationsException( $"App with application id {app.ExternalId} is not registered for receiving notifications for platform with id {platform.Id} for user with id {existingUser.ExternalId}"); } await _appNotificationManager.NotifyPlatformConnectionDataUpdate(existingUser.Id, new List <string> { app.Id }, platform.Id, session, cancellationToken); return(new AcceptedResult()); }
public async Task <ActionResult <PlatformInfoViewModel> > GetPlatformInfo( [FromHeader(Name = "admin-key")] Guid adminKey, Guid platformId, CancellationToken cancellationToken) { ValidateAdminKey(adminKey); using var session = _documentStore.OpenAsyncSession(); var platform = await _platformManager.GetPlatformByExternalId(platformId, session, cancellationToken); return(new PlatformInfoViewModel(platform.ExternalId, platform.Name, platform.Description, platform.LogoUrl, platform.WebsiteUrl, platform.IsInactive, platform.AuthenticationMechanism)); }
public async Task <ActionResult <PlatformUserConnectionInfoViewModel> > GetPlatformUserConnectionStatus( Guid platformId, CancellationToken cancellationToken) { var uniqueUserIdentifier = _httpContextAccessor.HttpContext.User.Identity.Name; using var session = _documentStore.OpenAsyncSession(); var user = await _userManager.GetUserByUniqueIdentifier(uniqueUserIdentifier, session, cancellationToken); var platform = await _platformManager.GetPlatformByExternalId(platformId, session, cancellationToken); var connectionForPlatform = user.PlatformConnections.SingleOrDefault(pc => pc.ExternalPlatformId == platformId); if (connectionForPlatform != null) { var isConnected = !connectionForPlatform?.ConnectionInfo?.IsDeleted ?? false; return(new PlatformUserConnectionInfoViewModel(platform.ExternalId, platform.Name, platform.Description, platform.LogoUrl, platform.WebsiteUrl, isConnected, platform.AuthenticationMechanism, connectionForPlatform.ConnectionInfo?.DeleteReason, connectionForPlatform.LastSuccessfulDataFetch)); } return(new PlatformUserConnectionInfoViewModel(platform.ExternalId, platform.Name, platform.Description, platform.LogoUrl, platform.WebsiteUrl, false, platform.AuthenticationMechanism, null, null)); }