Skip to content

Commit ad54cd9

Browse files
author
Rens van Moorsel
committed
Refactor: split up repositories and services
1 parent 23ce04a commit ad54cd9

28 files changed

Lines changed: 107 additions & 149 deletions

Backend/Controllers/Mails.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Backend.Controllers.DTOs;
22
using Backend.Interfaces;
3+
using Backend.Services.MailServices;
34
using Microsoft.AspNetCore.Authorization;
45
using Microsoft.AspNetCore.Mvc;
56

Backend/Docs/Migrations.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

Backend/Program.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
using Backend.Database;
2+
using Backend.Repositories;
23
using Backend.Services;
4+
using Backend.Services.AccountingToolServices;
5+
using Backend.Services.AuthServices;
6+
using Backend.Services.FileCompressServices;
7+
using Backend.Services.MailServices;
8+
using Backend.Services.MailSubscriptionServices;
9+
using Backend.Services.StorageServices;
310
using DotNetEnv;
411
using Mollie.Api;
512
using Microsoft.AspNetCore.Authentication.JwtBearer;
@@ -235,7 +242,7 @@
235242

236243
builder.Services.AddScoped<IStorageService, S3StorageService>();
237244
builder.Services.AddScoped<IFileCompressService, FileCompressService>();
238-
builder.Services.AddScoped<IPaymentValidationService, PaymentValidationService>();
245+
builder.Services.AddScoped<IPaymentValidationService, PaymentValidationRepository>();
239246
builder.Services.AddScoped<IPermissionService, PermissionService>();
240247

241248
string? mailProvider = Environment.GetEnvironmentVariable("MAIL_SERVICE");
@@ -283,23 +290,23 @@
283290
break;
284291
}
285292

286-
builder.Services.AddScoped<IActivityService, ActivityService>();
287-
builder.Services.AddScoped<IAnnouncementService, AnnouncementService>();
288-
builder.Services.AddScoped<IEnrollmentService, EnrollmentService>();
289-
builder.Services.AddScoped<IGroupMembershipService, GroupMembershipService>();
290-
builder.Services.AddScoped<IGroupService, GroupService>();
291-
builder.Services.AddScoped<IMemberService, MemberService>();
292-
builder.Services.AddScoped<IPaymentService, PaymentService>();
293+
builder.Services.AddScoped<IActivityService, ActivityRepository>();
294+
builder.Services.AddScoped<IAnnouncementService, AnnouncementRepository>();
295+
builder.Services.AddScoped<IEnrollmentService, EnrollmentRepository>();
296+
builder.Services.AddScoped<IGroupMembershipService, GroupMembershipRepository>();
297+
builder.Services.AddScoped<IGroupService, GroupRepository>();
298+
builder.Services.AddScoped<IMemberService, MemberRepository>();
299+
builder.Services.AddScoped<IPaymentService, PaymentRepository>();
293300
builder.Services.AddScoped<IPaymentWebhookService, PaymentWebhookService>();
294301
builder.Services.AddScoped<IPermissionService, PermissionService>();
295-
builder.Services.AddScoped<IProfilePictureService, ProfilePictureService>();
296-
builder.Services.AddScoped<IRoleAliasService, RoleAliasService>();
297-
builder.Services.AddScoped<IRoleService, RoleService>();
298-
builder.Services.AddScoped<IStudyEnrollmentService, StudyEnrollmentService>();
299-
builder.Services.AddScoped<IStudyService, StudyService>();
300-
builder.Services.AddScoped<ISpecificationAnswerService, SpecificationAnswerService>();
301-
builder.Services.AddScoped<ISettingsService, SettingsService>();
302-
builder.Services.AddScoped<IMailinglistService, MailinglistService>();
302+
builder.Services.AddScoped<IProfilePictureService, ProfilePictureRepository>();
303+
builder.Services.AddScoped<IRoleAliasService, RoleAliasRepository>();
304+
builder.Services.AddScoped<IRoleService, RoleRepository>();
305+
builder.Services.AddScoped<IStudyEnrollmentService, StudyEnrollmentRepository>();
306+
builder.Services.AddScoped<IStudyService, StudyRepository>();
307+
builder.Services.AddScoped<ISpecificationAnswerService, SpecificationAnswerRepository>();
308+
builder.Services.AddScoped<ISettingsService, SettingsRepository>();
309+
builder.Services.AddScoped<IMailinglistService, MailinglistRepository>();
303310

304311
builder.Services.AddScoped<ICreateNewBoardService, CreateNewBoardService>();
305312
builder.Services.AddHostedService<DatabaseSeeder>();

Backend/Services/ActivityService.cs renamed to Backend/Repositories/ActivityRepository.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,32 @@
55
using Backend.Projections;
66
using Backend.Validators;
77
using Backend.QueryExtensions;
8+
using Backend.Services.MailServices;
89
using Microsoft.AspNetCore.JsonPatch;
910
using Microsoft.EntityFrameworkCore;
1011
using System.Text;
1112
using Backend.Utils.DateTime;
1213

13-
namespace Backend.Services;
14+
namespace Backend.Repositories;
1415

1516
/// <summary>
1617
/// Implements activity management, poster handling, and enrollment exports.
1718
/// </summary>
18-
public class ActivityService : IActivityService
19+
public class ActivityRepository : IActivityService
1920
{
2021
private readonly PostgresDbContext _db;
2122
private readonly IStorageService _storageService;
2223
private readonly IFileCompressService _fileCompressor;
2324
private readonly IPermissionService _permissionService;
2425
private readonly IEnrollmentService _enrollmentService;
2526
private readonly AbstractMailService _mailService;
26-
private readonly ILogger<ActivityService> _logger;
27+
private readonly ILogger<ActivityRepository> _logger;
2728

2829
private readonly string[] _restrictedForEveryonePaths = new [] {"/id", "/posterFileName", "/posterPath", };
2930
private readonly string[] _restrictedPaths = new[] { "/vatRate", "/gLAccountId", "/costCenterId", "/costUnitId", "/paymentDeadline", "/showInKoala", "/enrollOpenDate", "/showOnWebsite", "/paymentDeadline", "/enrollOpenDate" };
3031

3132
/// <summary>
32-
/// Initializes a new instance of the ActivityService class with the specified database context, storage service, file compressor, permission service, enrollment service, mail service, and logger. The constructor sets up the necessary dependencies for managing activities, including database access for activity data, storage service for handling activity posters, file compressor for optimizing poster files, permission service for enforcing access control on activity operations, enrollment service for managing enrollments related to activities, mail service for sending notifications about activity-related events, and logging for monitoring activity management operations and troubleshooting any issues that may arise.
33+
/// Initializes a new instance of the ActivityRepository class with the specified database context, storage service, file compressor, permission service, enrollment service, mail service, and logger. The constructor sets up the necessary dependencies for managing activities, including database access for activity data, storage service for handling activity posters, file compressor for optimizing poster files, permission service for enforcing access control on activity operations, enrollment service for managing enrollments related to activities, mail service for sending notifications about activity-related events, and logging for monitoring activity management operations and troubleshooting any issues that may arise.
3334
/// </summary>
3435
/// <param name="db">The database context.</param>
3536
/// <param name="storageService">The storage service.</param>
@@ -38,14 +39,14 @@ public class ActivityService : IActivityService
3839
/// <param name="enrollmentService">The enrollment service.</param>
3940
/// <param name="mailService">The mail service.</param>
4041
/// <param name="logger">The logger.</param>
41-
public ActivityService(
42+
public ActivityRepository(
4243
PostgresDbContext db,
4344
IStorageService storageService,
4445
IFileCompressService fileCompressor,
4546
IPermissionService permissionService,
4647
IEnrollmentService enrollmentService,
4748
AbstractMailService mailService,
48-
ILogger<ActivityService> logger)
49+
ILogger<ActivityRepository> logger)
4950
{
5051
_db = db;
5152
_storageService = storageService;

Backend/Services/AnnouncementService.cs renamed to Backend/Repositories/AnnouncementRepository.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
using Microsoft.AspNetCore.JsonPatch;
88
using Microsoft.EntityFrameworkCore;
99

10-
namespace Backend.Services;
10+
namespace Backend.Repositories;
1111

1212
/// <summary>
1313
/// Implements announcement management operations.
1414
/// </summary>
15-
public class AnnouncementService : IAnnouncementService
15+
public class AnnouncementRepository : IAnnouncementService
1616
{
1717
private readonly PostgresDbContext _db;
1818
private readonly IPermissionService _permissionService;
19-
private readonly ILogger<AnnouncementService> _logger;
19+
private readonly ILogger<AnnouncementRepository> _logger;
2020

2121
/// <summary>
22-
/// Initializes a new instance of the AnnouncementService class with the specified database context, permission service, and logger. The constructor sets up the necessary dependencies for managing announcements, allowing the service to interact with the database for CRUD operations on announcements, perform permission checks to ensure that only authorized users can create, update, or delete announcements, and log important events and errors that occur during announcement management for monitoring and debugging purposes.
22+
/// Initializes a new instance of the AnnouncementRepository class with the specified database context, permission service, and logger. The constructor sets up the necessary dependencies for managing announcements, allowing the service to interact with the database for CRUD operations on announcements, perform permission checks to ensure that only authorized users can create, update, or delete announcements, and log important events and errors that occur during announcement management for monitoring and debugging purposes.
2323
/// </summary>
2424
/// <param name="db">The database context.</param>
2525
/// <param name="permissionService">The permission service.</param>
2626
/// <param name="logger">The logger.</param>
27-
public AnnouncementService(PostgresDbContext db, IPermissionService permissionService, ILogger<AnnouncementService> logger)
27+
public AnnouncementRepository(PostgresDbContext db, IPermissionService permissionService, ILogger<AnnouncementRepository> logger)
2828
{
2929
_db = db;
3030
_permissionService = permissionService;

Backend/Services/EnrollmentService.cs renamed to Backend/Repositories/EnrollmentRepository.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,37 @@
66
using Backend.Projections;
77
using Backend.Validators;
88
using Backend.QueryExtensions;
9+
using Backend.Services.MailServices;
910
using Microsoft.AspNetCore.JsonPatch;
1011
using Microsoft.EntityFrameworkCore;
1112

12-
namespace Backend.Services;
13+
namespace Backend.Repositories;
1314

1415
/// <summary>
1516
/// Implements enrollment workflows, including waiting-list promotion.
1617
/// </summary>
17-
public class EnrollmentService : IEnrollmentService
18+
public class EnrollmentRepository : IEnrollmentService
1819
{
1920
private readonly PostgresDbContext _db;
2021
private readonly IPermissionService _permissionService;
2122
private readonly IPaymentValidationService _paymentValidationService;
2223
private readonly AbstractMailService _mailService;
23-
private readonly ILogger<EnrollmentService> _logger;
24+
private readonly ILogger<EnrollmentRepository> _logger;
2425

2526
/// <summary>
26-
/// Initializes a new instance of the EnrollmentService class with the specified database context, permission service, payment validation service, mail service, and logger. The constructor sets up the necessary dependencies for managing enrollments, allowing the service to interact with the database for enrollment operations, perform permission checks to ensure that only authorized users can manage enrollments, validate payments when necessary, send emails related to enrollment actions, and log important events and errors that occur during enrollment management for monitoring and debugging purposes.
27+
/// Initializes a new instance of the EnrollmentRepository class with the specified database context, permission service, payment validation service, mail service, and logger. The constructor sets up the necessary dependencies for managing enrollments, allowing the service to interact with the database for enrollment operations, perform permission checks to ensure that only authorized users can manage enrollments, validate payments when necessary, send emails related to enrollment actions, and log important events and errors that occur during enrollment management for monitoring and debugging purposes.
2728
/// </summary>
2829
/// <param name="db">The database context.</param>
2930
/// <param name="permissionService">The permission service.</param>
3031
/// <param name="paymentValidationService">The payment validation service.</param>
3132
/// <param name="mailService">The mail service.</param>
3233
/// <param name="logger">The logger.</param>
33-
public EnrollmentService(
34+
public EnrollmentRepository(
3435
PostgresDbContext db,
3536
IPermissionService permissionService,
3637
IPaymentValidationService paymentValidationService,
3738
AbstractMailService mailService,
38-
ILogger<EnrollmentService> logger)
39+
ILogger<EnrollmentRepository> logger)
3940
{
4041
_db = db;
4142
_permissionService = permissionService;

Backend/Services/GroupMembershipService.cs renamed to Backend/Repositories/GroupMembershipRepository.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,30 @@
44
using Backend.Models.Domain;
55
using Backend.Validators;
66
using Backend.Projections;
7+
using Backend.Services;
78
using Microsoft.AspNetCore.JsonPatch;
89
using Microsoft.EntityFrameworkCore;
910

10-
namespace Backend.Services;
11+
namespace Backend.Repositories;
1112

1213
/// <summary>
1314
/// Implements group-membership management operations.
1415
/// </summary>
15-
public class GroupMembershipService : IGroupMembershipService
16+
public class GroupMembershipRepository : IGroupMembershipService
1617
{
1718
private readonly PostgresDbContext _db;
1819
private readonly IPermissionService _permissionService;
1920
private readonly AuthOutboxWorker _authOutboxWorker;
20-
private readonly ILogger<GroupMembershipService> _logger;
21+
private readonly ILogger<GroupMembershipRepository> _logger;
2122

2223
/// <summary>
23-
/// Initializes a new instance of the GroupMembershipService class with the specified dependencies. The constructor sets up the necessary services for managing group memberships, including database access, permission checks, integration with the authentication outbox worker for synchronizing membership changes with the configured auth system, and logging for monitoring group membership operations. This setup allows the GroupMembershipService to effectively handle creating, retrieving, updating, and deleting group memberships while ensuring that only authorized users can perform these actions and that any significant events are logged for auditing and debugging purposes.
24+
/// Initializes a new instance of the GroupMembershipRepository class with the specified dependencies. The constructor sets up the necessary services for managing group memberships, including database access, permission checks, integration with the authentication outbox worker for synchronizing membership changes with the configured auth system, and logging for monitoring group membership operations. This setup allows the GroupMembershipRepository to effectively handle creating, retrieving, updating, and deleting group memberships while ensuring that only authorized users can perform these actions and that any significant events are logged for auditing and debugging purposes.
2425
/// </summary>
2526
/// <param name="db">The database context.</param>
2627
/// <param name="permissionService">The permission service.</param>
2728
/// <param name="authOutboxWorker">The authentication outbox worker.</param>
2829
/// <param name="logger">The logger.</param>
29-
public GroupMembershipService(PostgresDbContext db, IPermissionService permissionService, AuthOutboxWorker authOutboxWorker, ILogger<GroupMembershipService> logger)
30+
public GroupMembershipRepository(PostgresDbContext db, IPermissionService permissionService, AuthOutboxWorker authOutboxWorker, ILogger<GroupMembershipRepository> logger)
3031
{
3132
_db = db;
3233
_permissionService = permissionService;

0 commit comments

Comments
 (0)