Skip to content

Commit f1bc3f4

Browse files
authored
Merge pull request #2708 from TechnologyEnhancedLearning/Develop/feature/TD-3920-ConfigurationController-refactor
TD-3920-ConfigurationController - refactor
2 parents 5c44e74 + 45abf36 commit f1bc3f4

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Centre/Configuration/CentreConfigurationControllerTests.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
{
33
using System;
44
using System.Globalization;
5-
using DigitalLearningSolutions.Data.DataServices;
65
using DigitalLearningSolutions.Data.Models.Certificates;
7-
using DigitalLearningSolutions.Data.Models.External.Maps;
6+
using DigitalLearningSolutions.Data.Models.External.Maps;
87
using DigitalLearningSolutions.Web.Controllers.TrackingSystem.Centre.Configuration;
98
using DigitalLearningSolutions.Web.Helpers.ExternalApis;
109
using DigitalLearningSolutions.Web.Services;
@@ -22,7 +21,7 @@
2221

2322
public class CentreConfigurationControllerTests
2423
{
25-
private readonly ICentresDataService centresDataService = A.Fake<ICentresDataService>();
24+
private readonly ICentresService centresService = A.Fake<ICentresService>();
2625

2726
private readonly IImageResizeService imageResizeService = A.Fake<IImageResizeService>();
2827

@@ -39,7 +38,7 @@ public void Setup()
3938
certificateService = A.Fake<ICertificateService>();
4039
controller =
4140
new ConfigurationController(
42-
centresDataService,
41+
centresService,
4342
mapsApiHelper,
4443
logger,
4544
imageResizeService,
@@ -49,7 +48,7 @@ public void Setup()
4948
.WithMockUser(true);
5049

5150
A.CallTo(
52-
() => centresDataService.UpdateCentreWebsiteDetails(
51+
() => centresService.UpdateCentreWebsiteDetails(
5352
A<int>._,
5453
A<string>._,
5554
A<double>._,
@@ -68,7 +67,7 @@ public void Setup()
6867
[TearDown]
6968
public void Cleanup()
7069
{
71-
Fake.ClearRecordedCalls(centresDataService);
70+
Fake.ClearRecordedCalls(centresService);
7271
Fake.ClearRecordedCalls(mapsApiHelper);
7372
Fake.ClearRecordedCalls(logger);
7473
Fake.ClearRecordedCalls(imageResizeService);
@@ -126,7 +125,7 @@ public void EditCentreDetailsPostSave_without_previewing_signature_image_fails_v
126125

127126
// Then
128127
A.CallTo(
129-
() => centresDataService.UpdateCentreDetails(
128+
() => centresService.UpdateCentreDetails(
130129
A<int>._,
131130
A<string>._,
132131
A<string>._,
@@ -156,7 +155,7 @@ public void EditCentreDetailsPostSave_without_previewing_logo_image_fails_valida
156155

157156
// Then
158157
A.CallTo(
159-
() => centresDataService.UpdateCentreDetails(
158+
() => centresService.UpdateCentreDetails(
160159
A<int>._,
161160
A<string>._,
162161
A<string>._,
@@ -199,7 +198,7 @@ public void EditCentreDetailsPost_updates_centre_and_redirects_with_successful_s
199198

200199
// Then
201200
result.Should().BeRedirectToActionResult().WithActionName("Index");
202-
A.CallTo(() => centresDataService.UpdateCentreDetails(2, null, model.BannerText, null, null))
201+
A.CallTo(() => centresService.UpdateCentreDetails(2, null, model.BannerText, null, null))
203202
.MustHaveHappenedOnceExactly();
204203
}
205204

@@ -307,7 +306,7 @@ public void EditCentreWebsiteDetails_should_show_save_coordinates_when_postcode_
307306
// Then
308307
result.Should().BeRedirectToActionResult().WithActionName("Index");
309308
A.CallTo(
310-
() => centresDataService.UpdateCentreWebsiteDetails(
309+
() => centresService.UpdateCentreWebsiteDetails(
311310
A<int>._,
312311
"AA123",
313312
latitude,
@@ -341,7 +340,7 @@ public void PreviewCertificate_returns_view_when_service_returns_object()
341340
{
342341
// Given
343342
var centre = CentreTestHelper.GetDefaultCentre();
344-
A.CallTo(() => centresDataService.GetCentreDetailsById(centre.CentreId)).Returns(centre);
343+
A.CallTo(() => centresService.GetCentreDetailsById(centre.CentreId)).Returns(centre);
345344
var certificateInformation = CertificateTestHelper.GetDefaultCertificate();
346345
//var certificateInformation = new CertificateInformation(
347346
// 0,

DigitalLearningSolutions.Web/Controllers/TrackingSystem/Centre/Configuration/ConfigurationController.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.Centre.Configuration
22
{
3-
using DigitalLearningSolutions.Data.DataServices;
43
using DigitalLearningSolutions.Data.Enums;
54
using DigitalLearningSolutions.Web.Attributes;
65
using DigitalLearningSolutions.Web.Extensions;
@@ -21,21 +20,21 @@ namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.Centre.Configu
2120
[Route("/TrackingSystem/Centre/Configuration")]
2221
public class ConfigurationController : Controller
2322
{
24-
private readonly ICentresDataService centresDataService;
23+
private readonly ICentresService centresService;
2524
private readonly ILogger<ConfigurationController> logger;
2625
private readonly IMapsApiHelper mapsApiHelper;
2726
private readonly IImageResizeService imageResizeService;
2827
private ICertificateService certificateService;
2928

3029
public ConfigurationController(
31-
ICentresDataService centresDataService,
30+
ICentresService centresService,
3231
IMapsApiHelper mapsApiHelper,
3332
ILogger<ConfigurationController> logger,
3433
IImageResizeService imageResizeService,
3534
ICertificateService certificateService
3635
)
3736
{
38-
this.centresDataService = centresDataService;
37+
this.centresService = centresService;
3938
this.mapsApiHelper = mapsApiHelper;
4039
this.logger = logger;
4140
this.imageResizeService = imageResizeService;
@@ -46,7 +45,7 @@ public IActionResult Index()
4645
{
4746
var centreId = User.GetCentreIdKnownNotNull();
4847

49-
var centreDetails = centresDataService.GetCentreDetailsById(centreId)!;
48+
var centreDetails = centresService.GetCentreDetailsById(centreId)!;
5049

5150
var model = new CentreConfigurationViewModel(centreDetails);
5251

@@ -59,7 +58,7 @@ public IActionResult EditCentreManagerDetails()
5958
{
6059
var centreId = User.GetCentreIdKnownNotNull();
6160

62-
var centreDetails = centresDataService.GetCentreDetailsById(centreId)!;
61+
var centreDetails = centresService.GetCentreDetailsById(centreId)!;
6362

6463
var model = new EditCentreManagerDetailsViewModel(centreDetails);
6564

@@ -77,7 +76,7 @@ public IActionResult EditCentreManagerDetails(EditCentreManagerDetailsViewModel
7776

7877
var centreId = User.GetCentreIdKnownNotNull();
7978

80-
centresDataService
79+
centresService
8180
.UpdateCentreManagerDetails(centreId, model.FirstName!, model.LastName!, model.Email!, model.Telephone);
8281

8382
return RedirectToAction("Index");
@@ -89,7 +88,7 @@ public IActionResult EditCentreWebsiteDetails()
8988
{
9089
var centreId = User.GetCentreIdKnownNotNull();
9190

92-
var centreDetails = centresDataService.GetCentreDetailsById(centreId)!;
91+
var centreDetails = centresService.GetCentreDetailsById(centreId)!;
9392

9493
var model = new EditCentreWebsiteDetailsViewModel(centreDetails);
9594

@@ -129,7 +128,7 @@ public IActionResult EditCentreWebsiteDetails(EditCentreWebsiteDetailsViewModel
129128

130129
var centreId = User.GetCentreIdKnownNotNull();
131130

132-
centresDataService.UpdateCentreWebsiteDetails(
131+
centresService.UpdateCentreWebsiteDetails(
133132
centreId,
134133
model.CentrePostcode,
135134
latitude,
@@ -152,7 +151,7 @@ public IActionResult EditCentreDetails()
152151
{
153152
var centreId = User.GetCentreIdKnownNotNull();
154153

155-
var centreDetails = centresDataService.GetCentreDetailsById(centreId)!;
154+
var centreDetails = centresService.GetCentreDetailsById(centreId)!;
156155

157156
var model = new EditCentreDetailsViewModel(centreDetails);
158157

@@ -209,7 +208,7 @@ private IActionResult EditCentreDetailsPostSave(EditCentreDetailsViewModel model
209208

210209
var centreId = User.GetCentreIdKnownNotNull();
211210

212-
centresDataService.UpdateCentreDetails(
211+
centresService.UpdateCentreDetails(
213212
centreId,
214213
model.NotifyEmail,
215214
model.BannerText!,

DigitalLearningSolutions.Web/Services/CentresService.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ void UpdateCentreManagerDetails(
4444
IEnumerable<(int, string)> GetCentresForDelegateSelfRegistrationAlphabetical();
4545
(bool autoRegistered, string? autoRegisterManagerEmail) GetCentreAutoRegisterValues(int centreId);
4646
Centre? GetCentreDetailsById(int centreId);
47+
void UpdateCentreWebsiteDetails(
48+
int centreId,
49+
string postcode,
50+
double latitude,
51+
double longitude,
52+
string? telephone,
53+
string email,
54+
string? openingHours,
55+
string? webAddress,
56+
string? organisationsCovered,
57+
string? trainingVenues,
58+
string? otherInformation
59+
);
60+
void UpdateCentreDetails(
61+
int centreId,
62+
string? notifyEmail,
63+
string bannerText,
64+
byte[]? centreSignature,
65+
byte[]? centreLogo
66+
);
4767
}
4868

4969
public class CentresService : ICentresService
@@ -154,5 +174,15 @@ public void UpdateCentreManagerDetails(int centreId, string firstName, string la
154174
{
155175
return centresDataService.GetCentreDetailsById(centreId);
156176
}
177+
178+
public void UpdateCentreWebsiteDetails(int centreId, string postcode, double latitude, double longitude, string? telephone, string email, string? openingHours, string? webAddress, string? organisationsCovered, string? trainingVenues, string? otherInformation)
179+
{
180+
centresDataService.UpdateCentreWebsiteDetails(centreId, postcode, latitude, longitude, telephone, email, openingHours, webAddress, organisationsCovered, trainingVenues, otherInformation);
181+
}
182+
183+
public void UpdateCentreDetails(int centreId, string? notifyEmail, string bannerText, byte[]? centreSignature, byte[]? centreLogo)
184+
{
185+
centresDataService.UpdateCentreDetails(centreId, notifyEmail, bannerText, centreSignature, centreLogo);
186+
}
157187
}
158188
}

0 commit comments

Comments
 (0)