Skip to content

Commit a5d9895

Browse files
TD-3918 RequestSupportTicketController - refactor (Controller-Service-Repository pattern)
1 parent ce6e2b2 commit a5d9895

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

DigitalLearningSolutions.Web/Controllers/Support/RequestSupportTicketController.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
namespace DigitalLearningSolutions.Web.Controllers.Support
33
{
4-
using DigitalLearningSolutions.Data.DataServices.UserDataService;
5-
using DigitalLearningSolutions.Data.DataServices;
64
using DigitalLearningSolutions.Web.Helpers;
75
using DigitalLearningSolutions.Web.Models.Enums;
86
using Microsoft.AspNetCore.Mvc;
@@ -32,26 +30,26 @@ namespace DigitalLearningSolutions.Web.Controllers.Support
3230
public class RequestSupportTicketController : Controller
3331
{
3432
private readonly IConfiguration configuration;
35-
private readonly IUserDataService userDataService;
36-
private readonly ICentresDataService centresDataService;
33+
private readonly IUserService userService;
34+
private readonly ICentresService centresService;
3735
private readonly IWebHostEnvironment webHostEnvironment;
38-
private readonly IRequestSupportTicketDataService requestSupportTicketDataService;
36+
private readonly IRequestSupportTicketService requestSupportTicketService;
3937
private readonly IFreshdeskService freshdeskService;
4038
private readonly IMultiPageFormService multiPageFormService;
4139
string uploadDir = string.Empty;
4240
public RequestSupportTicketController(IConfiguration configuration
43-
, IUserDataService userDataService
44-
, ICentresDataService centresDataService
41+
, IUserService userService
42+
, ICentresService centresService
4543
, IWebHostEnvironment webHostEnvironment
46-
, IRequestSupportTicketDataService requestSupportTicketDataService
44+
, IRequestSupportTicketService requestSupportTicketService
4745
, IFreshdeskService freshdeskService
4846
, IMultiPageFormService multiPageFormService)
4947
{
5048
this.configuration = configuration;
51-
this.userDataService = userDataService;
52-
this.centresDataService = centresDataService;
49+
this.userService = userService;
50+
this.centresService = centresService;
5351
this.webHostEnvironment = webHostEnvironment;
54-
this.requestSupportTicketDataService = requestSupportTicketDataService;
52+
this.requestSupportTicketService = requestSupportTicketService;
5553
this.freshdeskService = freshdeskService;
5654
this.multiPageFormService = multiPageFormService;
5755
uploadDir = Path.Combine(webHostEnvironment.WebRootPath, "Uploads\\");
@@ -65,18 +63,18 @@ public IActionResult Index(DlsSubApplication dlsSubApplication)
6563
configuration.GetCurrentSystemBaseUrl()
6664
);
6765
var centreId = User.GetCentreIdKnownNotNull();
68-
var userName = userDataService.GetUserDisplayName(User.GetUserId() ?? 0);
69-
var userCentreEmail = requestSupportTicketDataService.GetUserCentreEmail(User.GetUserId() ?? 0, centreId);
66+
var userName = userService.GetUserDisplayName(User.GetUserId() ?? 0);
67+
var userCentreEmail = requestSupportTicketService.GetUserCentreEmail(User.GetUserId() ?? 0, centreId);
7068
var adminUserID = User.GetAdminId();
71-
var centreName = centresDataService.GetCentreName(centreId);
69+
var centreName = centresService.GetCentreName(centreId);
7270
setupRequestSupportData(userName, userCentreEmail, adminUserID ?? 0, centreName);
7371
return View("Request", model);
7472
}
7573

7674
[Route("/{dlsSubApplication}/RequestSupport/TypeofRequest")]
7775
public IActionResult TypeofRequest(DlsSubApplication dlsSubApplication)
7876
{
79-
var requestTypes = requestSupportTicketDataService.GetRequestTypes();
77+
var requestTypes = requestSupportTicketService.GetRequestTypes();
8078
var data = multiPageFormService.GetMultiPageFormData<RequestSupportTicketData>(
8179
MultiPageFormDataFeature.AddCustomWebForm("RequestSupportTicketCWF"),
8280
TempData
@@ -89,7 +87,7 @@ public IActionResult TypeofRequest(DlsSubApplication dlsSubApplication)
8987
[Route("/{dlsSubApplication}/RequestSupport/setRequestType")]
9088
public IActionResult setRequestType(DlsSubApplication dlsSubApplication, RequestTypeViewModel RequestTypemodel, int requestType)
9189
{
92-
var requestTypes = requestSupportTicketDataService.GetRequestTypes();
90+
var requestTypes = requestSupportTicketService.GetRequestTypes();
9391
var reqType = requestTypes.ToList().Where(x => x.ID == requestType)
9492
.Select(ticketRequestTypes => new { ticketRequestTypes.RequestTypes, ticketRequestTypes.FreshdeskRequestTypes }).FirstOrDefault();
9593

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.Support;
3+
using System.Collections.Generic;
4+
5+
namespace DigitalLearningSolutions.Web.Services
6+
{
7+
public interface IRequestSupportTicketService
8+
{
9+
IEnumerable<RequestType> GetRequestTypes();
10+
string? GetUserCentreEmail(int userId, int centreId);
11+
12+
}
13+
public class RequestSupportTicketService : IRequestSupportTicketService
14+
{
15+
private readonly IRequestSupportTicketDataService requestSupportTicketDataService;
16+
public RequestSupportTicketService(IRequestSupportTicketDataService requestSupportTicketDataService)
17+
{
18+
this.requestSupportTicketDataService = requestSupportTicketDataService;
19+
}
20+
public IEnumerable<RequestType> GetRequestTypes()
21+
{
22+
return requestSupportTicketDataService.GetRequestTypes();
23+
}
24+
25+
public string? GetUserCentreEmail(int userId, int centreId)
26+
{
27+
return requestSupportTicketDataService.GetUserCentreEmail(userId, centreId);
28+
}
29+
}
30+
}

DigitalLearningSolutions.Web/Services/UserService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ string registrationConfirmationHash
145145
int? GetUserIdFromUsername(string username);
146146
int GetDelegateCountWithAnswerForPrompt(int centreId, int promptNumber);
147147
List<AdminUser> GetAdminUsersByCentreId(int centreId);
148+
string GetUserDisplayName(int userId);
149+
148150
}
149151

150152
public class UserService : IUserService
@@ -802,5 +804,10 @@ public List<AdminUser> GetAdminUsersByCentreId(int centreId)
802804
{
803805
return userDataService.GetAdminUsersByCentreId(centreId);
804806
}
807+
808+
public string GetUserDisplayName(int userId)
809+
{
810+
return userDataService.GetUserDisplayName(userId);
811+
}
805812
}
806813
}

DigitalLearningSolutions.Web/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ private static void RegisterServices(IServiceCollection services)
475475
services.AddScoped<ICentreApplicationsService, CentreApplicationsService>();
476476
services.AddScoped<ICentreSelfAssessmentsService, CentreSelfAssessmentsService>();
477477
services.AddScoped<IUserFeedbackService, UserFeedbackService>();
478+
services.AddScoped<IRequestSupportTicketService, RequestSupportTicketService>();
478479
}
479480

480481
private static void RegisterDataServices(IServiceCollection services)

0 commit comments

Comments
 (0)