Skip to content

Commit 5d4c8ee

Browse files
authored
Merge pull request #2700 from TechnologyEnhancedLearning/Develop/feature/TD-3925-SystemNotificationsController-refactor
TD-3925-SystemNotificationsController - refactor
2 parents 8813e05 + c954d0d commit 5d4c8ee

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Centre/SystemNotificationControllerTests.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
using System;
44
using System.Collections.Generic;
5-
using DigitalLearningSolutions.Data.DataServices;
65
using DigitalLearningSolutions.Data.Models;
76
using DigitalLearningSolutions.Data.Utilities;
87
using DigitalLearningSolutions.Web.Controllers.TrackingSystem.Centre;
@@ -23,18 +22,18 @@ public class SystemNotificationControllerTests
2322
private HttpRequest httpRequest = null!;
2423
private HttpResponse httpResponse = null!;
2524
private ISearchSortFilterPaginateService searchSortFilterPaginateService = null!;
26-
private ISystemNotificationsDataService systemNotificationsDataService = null!;
25+
private ISystemNotificationsService systemNotificationsService = null!;
2726

2827
[SetUp]
2928
public void Setup()
3029
{
3130
httpRequest = A.Fake<HttpRequest>();
3231
httpResponse = A.Fake<HttpResponse>();
33-
systemNotificationsDataService = A.Fake<ISystemNotificationsDataService>();
32+
systemNotificationsService = A.Fake<ISystemNotificationsService>();
3433
searchSortFilterPaginateService = A.Fake<ISearchSortFilterPaginateService>();
3534
controller =
3635
new SystemNotificationsController(
37-
systemNotificationsDataService,
36+
systemNotificationsService,
3837
clockUtility,
3938
searchSortFilterPaginateService
4039
)
@@ -51,7 +50,7 @@ public void Index_sets_cookie_when_unacknowledged_notifications_exist()
5150
var testDate = new DateTime(2021, 8, 23);
5251
A.CallTo(() => clockUtility.UtcNow).Returns(testDate);
5352
var expectedExpiry = testDate.AddHours(24);
54-
A.CallTo(() => systemNotificationsDataService.GetUnacknowledgedSystemNotifications(A<int>._))
53+
A.CallTo(() => systemNotificationsService.GetUnacknowledgedSystemNotifications(A<int>._))
5554
.Returns(new List<SystemNotification> { SystemNotificationTestHelper.GetDefaultSystemNotification() });
5655

5756
// When
@@ -80,7 +79,7 @@ public void Post_acknowledges_notification_and_redirects()
8079
// Then
8180
using (new AssertionScope())
8281
{
83-
A.CallTo(() => systemNotificationsDataService.AcknowledgeNotification(1, 7)).MustHaveHappened();
82+
A.CallTo(() => systemNotificationsService.AcknowledgeNotification(1, 7)).MustHaveHappened();
8483
result.Should().BeRedirectToActionResult().WithControllerName("SystemNotifications")
8584
.WithActionName("Index");
8685
}
@@ -93,7 +92,7 @@ public void Index_deletes_cookie_if_one_exists_for_user_and_no_unacknowledged_no
9392
A.CallTo(() => httpRequest.Cookies).Returns(
9493
ControllerContextHelper.SetUpFakeRequestCookieCollection(SystemNotificationCookieHelper.CookieName, "7")
9594
);
96-
A.CallTo(() => systemNotificationsDataService.GetUnacknowledgedSystemNotifications(A<int>._))
95+
A.CallTo(() => systemNotificationsService.GetUnacknowledgedSystemNotifications(A<int>._))
9796
.Returns(new List<SystemNotification>());
9897

9998
// When
@@ -110,7 +109,7 @@ public void Index_does_not_delete_cookie_if_one_exists_for_someone_other_than_cu
110109
A.CallTo(() => httpRequest.Cookies).Returns(
111110
ControllerContextHelper.SetUpFakeRequestCookieCollection(SystemNotificationCookieHelper.CookieName, "8")
112111
);
113-
A.CallTo(() => systemNotificationsDataService.GetUnacknowledgedSystemNotifications(A<int>._))
112+
A.CallTo(() => systemNotificationsService.GetUnacknowledgedSystemNotifications(A<int>._))
114113
.Returns(new List<SystemNotification>());
115114

116115
// When
@@ -128,7 +127,7 @@ public void Index_does_not_delete_cookie_if_one_does_not_exist()
128127
A.CallTo(() => httpRequest.Cookies).Returns(
129128
A.Fake<IRequestCookieCollection>()
130129
);
131-
A.CallTo(() => systemNotificationsDataService.GetUnacknowledgedSystemNotifications(A<int>._))
130+
A.CallTo(() => systemNotificationsService.GetUnacknowledgedSystemNotifications(A<int>._))
132131
.Returns(new List<SystemNotification>());
133132

134133
// When

DigitalLearningSolutions.Web/Controllers/TrackingSystem/Centre/SystemNotificationsController.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.Centre
22
{
33
using System.Linq;
4-
using DigitalLearningSolutions.Data.DataServices;
54
using DigitalLearningSolutions.Data.Enums;
65
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
76
using DigitalLearningSolutions.Data.Utilities;
@@ -23,15 +22,15 @@ public class SystemNotificationsController : Controller
2322
{
2423
private readonly IClockUtility clockUtility;
2524
private readonly ISearchSortFilterPaginateService searchSortFilterPaginateService;
26-
private readonly ISystemNotificationsDataService systemNotificationsDataService;
25+
private readonly ISystemNotificationsService systemNotificationsService;
2726

2827
public SystemNotificationsController(
29-
ISystemNotificationsDataService systemNotificationsDataService,
28+
ISystemNotificationsService systemNotificationsService,
3029
IClockUtility clockUtility,
3130
ISearchSortFilterPaginateService searchSortFilterPaginateService
3231
)
3332
{
34-
this.systemNotificationsDataService = systemNotificationsDataService;
33+
this.systemNotificationsService = systemNotificationsService;
3534
this.clockUtility = clockUtility;
3635
this.searchSortFilterPaginateService = searchSortFilterPaginateService;
3736
}
@@ -42,7 +41,7 @@ public IActionResult Index(int page = 1)
4241
{
4342
var adminId = User.GetAdminId()!.Value;
4443
var unacknowledgedNotifications =
45-
systemNotificationsDataService.GetUnacknowledgedSystemNotifications(adminId).ToList();
44+
systemNotificationsService.GetUnacknowledgedSystemNotifications(adminId).ToList();
4645

4746
if (unacknowledgedNotifications.Count > 0)
4847
{
@@ -74,7 +73,7 @@ public IActionResult Index(int page = 1)
7473
public IActionResult AcknowledgeNotification(int systemNotificationId, int page)
7574
{
7675
var adminId = User.GetAdminId()!.Value;
77-
systemNotificationsDataService.AcknowledgeNotification(systemNotificationId, adminId);
76+
systemNotificationsService.AcknowledgeNotification(systemNotificationId, adminId);
7877

7978
return RedirectToAction("Index", "SystemNotifications", new { page });
8079
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using DigitalLearningSolutions.Data.DataServices;
2+
using DigitalLearningSolutions.Data.Models;
3+
using System.Collections.Generic;
4+
5+
namespace DigitalLearningSolutions.Web.Services
6+
{
7+
public interface ISystemNotificationsService
8+
{
9+
public IEnumerable<SystemNotification> GetUnacknowledgedSystemNotifications(int adminId);
10+
11+
public void AcknowledgeNotification(int notificationId, int adminId);
12+
}
13+
public class SystemNotificationsService : ISystemNotificationsService
14+
{
15+
private readonly ISystemNotificationsDataService systemNotificationsDataService;
16+
public SystemNotificationsService(ISystemNotificationsDataService systemNotificationsDataService)
17+
{
18+
this.systemNotificationsDataService = systemNotificationsDataService;
19+
}
20+
public void AcknowledgeNotification(int notificationId, int adminId)
21+
{
22+
systemNotificationsDataService.AcknowledgeNotification(notificationId, adminId);
23+
}
24+
25+
public IEnumerable<SystemNotification> GetUnacknowledgedSystemNotifications(int adminId)
26+
{
27+
return systemNotificationsDataService.GetUnacknowledgedSystemNotifications(adminId);
28+
}
29+
}
30+
}

DigitalLearningSolutions.Web/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ private static void RegisterServices(IServiceCollection services)
452452
services.AddScoped<IStoreAspService, StoreAspService>();
453453
services.AddScoped<ISupervisorDelegateService, SupervisorDelegateService>();
454454
services.AddScoped<ISupervisorService, SupervisorService>();
455+
services.AddScoped<ISystemNotificationsService, SystemNotificationsService>();
455456
services.AddScoped<IDashboardInformationService, DashboardInformationService>();
456457
services.AddScoped<ITrackerService, TrackerService>();
457458
services.AddScoped<ITrackerActionService, TrackerActionService>();

0 commit comments

Comments
 (0)