Skip to content
Snippets Groups Projects

Sprint/2020 20

Merged Marcel Nellesen requested to merge Sprint/2020-20 into master
7 files
+ 51
49
Compare changes
  • Side-by-side
  • Inline

Files

using Coscine.ApiCommons;
using Coscine.Configuration;
using Coscine.ApiCommons.Factories;
using Coscine.Configuration;
using Coscine.Database.DataModel;
using Coscine.Database.DataModel;
using Coscine.Database.Models;
using Coscine.Database.Models;
using Coscine.NotificationChannelBase;
using Coscine.NotificationChannelBase;
using Coscine.NotificationConfiguration;
using Coscine.NotificationConfiguration;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;
using Stubble.Core.Builders;
using Stubble.Core.Builders;
 
using Stubble.Core.Loaders;
using System;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection;
@@ -47,15 +45,14 @@ namespace Coscine.Api.NotificationBus.Controllers
@@ -47,15 +45,14 @@ namespace Coscine.Api.NotificationBus.Controllers
}
}
[HttpPost("[controller]/sendAsync")]
[HttpPost("[controller]/sendAsync")]
public IActionResult SendAsync([FromBody] NotificationParameterObject notificationParameterObject)
public async Task<IActionResult> SendAsync([FromBody] NotificationParameterObject notificationParameterObject)
{
{
SendNotifications(notificationParameterObject);
await SendNotifications(notificationParameterObject);
return Ok();
return Ok();
}
}
private async Task SendNotifications(NotificationParameterObject notificationParameterObject)
private async Task SendNotifications(NotificationParameterObject notificationParameterObject)
{
{
List<User> users = GetUsers(notificationParameterObject.UserIds);
Project project = GetProject(notificationParameterObject.ProjectId);
Project project = GetProject(notificationParameterObject.ProjectId);
var action = notificationParameterObject.Action;
var action = notificationParameterObject.Action;
ActionObject actionObject = _notificationConfiguration.GetAction(action);
ActionObject actionObject = _notificationConfiguration.GetAction(action);
@@ -84,7 +81,7 @@ namespace Coscine.Api.NotificationBus.Controllers
@@ -84,7 +81,7 @@ namespace Coscine.Api.NotificationBus.Controllers
}
}
// for every available user
// for every available user
foreach (User user in users)
foreach (User user in notificationParameterObject.Users)
{
{
JObject messageData = FillTemplate(channelName, actionObject, notificationParameterObject.Args, user, project);
JObject messageData = FillTemplate(channelName, actionObject, notificationParameterObject.Args, user, project);
@@ -114,7 +111,11 @@ namespace Coscine.Api.NotificationBus.Controllers
@@ -114,7 +111,11 @@ namespace Coscine.Api.NotificationBus.Controllers
}
}
var template = (JObject)(action.Template[channelName][language]);
var template = (JObject)(action.Template[channelName][language]);
var stubble = new StubbleBuilder().Build();
var stubble = new StubbleBuilder()
 
.Configure(settings =>
 
{
 
settings.SetPartialTemplateLoader(new DictionaryLoader(_notificationConfiguration.GetPartialsForChannel(channelName, language)));
 
}).Build();
var dict = new Dictionary<string, object>();
var dict = new Dictionary<string, object>();
if (requestArgs["placeholder"] != null)
if (requestArgs["placeholder"] != null)
@@ -130,7 +131,6 @@ namespace Coscine.Api.NotificationBus.Controllers
@@ -130,7 +131,6 @@ namespace Coscine.Api.NotificationBus.Controllers
}
}
return template;
return template;
}
}
private List<User> GetUsers(List<string> userIds)
private List<User> GetUsers(List<string> userIds)
Loading