diff --git a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Commands/Handlers/UpdateStudentHandler.cs b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Commands/Handlers/UpdateStudentHandler.cs index 60cf8e1a..fc327c52 100644 --- a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Commands/Handlers/UpdateStudentHandler.cs +++ b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Commands/Handlers/UpdateStudentHandler.cs @@ -2,7 +2,6 @@ using MiniSpace.Services.Students.Application.Dto; using MiniSpace.Services.Students.Application.Events; using MiniSpace.Services.Students.Application.Exceptions; -using MiniSpace.Services.Students.Application.Services; using MiniSpace.Services.Students.Core.Entities; using MiniSpace.Services.Students.Core.Repositories; using System; @@ -10,6 +9,7 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using MiniSpace.Services.Students.Application.Services; namespace MiniSpace.Services.Students.Application.Commands.Handlers { @@ -20,8 +20,7 @@ public class UpdateStudentHandler : ICommandHandler private readonly IEventMapper _eventMapper; private readonly IMessageBroker _messageBroker; - public UpdateStudentHandler(IStudentRepository studentRepository, IAppContext appContext, - IEventMapper eventMapper, IMessageBroker messageBroker) + public UpdateStudentHandler(IStudentRepository studentRepository, IAppContext appContext, IEventMapper eventMapper, IMessageBroker messageBroker) { _studentRepository = studentRepository; _appContext = appContext; @@ -31,34 +30,23 @@ public UpdateStudentHandler(IStudentRepository studentRepository, IAppContext ap public async Task HandleAsync(UpdateStudent command, CancellationToken cancellationToken = default) { - // Log the command received var commandJson = JsonSerializer.Serialize(command); Console.WriteLine($"Received UpdateStudent command: {commandJson}"); var student = await _studentRepository.GetAsync(command.StudentId); - if (student is null) + if (student == null) { throw new StudentNotFoundException(command.StudentId); } - var identity = _appContext.Identity; - if (identity.IsAuthenticated && identity.Id != student.Id && !identity.IsAdmin) - { - throw new UnauthorizedStudentAccessException(command.StudentId, identity.Id); - } + student.Update(command.FirstName, command.LastName, command.Description, command.EmailNotifications, command.ContactEmail, command.PhoneNumber, command.Country, command.City, command.DateOfBirth); + + student.UpdateEducation(command.Education.Select(e => new Education( + e.OrganizationId, e.InstitutionName, e.Degree, e.StartDate, e.EndDate, e.Description))); - student.Update(command.FirstName, - command.LastName, - command.Description, - command.EmailNotifications, - command.ContactEmail, - command.PhoneNumber, - command.Country, - command.City, - command.DateOfBirth); + student.UpdateWork(command.Work.Select(w => new Work( + w.OrganizationId, w.Company, w.Position, w.StartDate, w.EndDate, w.Description))); - student.UpdateEducation(command.Education.Select(e => new Education(e.InstitutionName, e.Degree, e.StartDate, e.EndDate, e.Description))); - student.UpdateWork(command.Work.Select(w => new Work(w.Company, w.Position, w.StartDate, w.EndDate, w.Description))); student.UpdateLanguages(command.Languages.Select(l => (Language)Enum.Parse(typeof(Language), l))); student.UpdateInterests(command.Interests.Select(i => (Interest)Enum.Parse(typeof(Interest), i))); @@ -80,6 +68,7 @@ public async Task HandleAsync(UpdateStudent command, CancellationToken cancellat student.Description, student.Education.Select(e => new EducationDto { + OrganizationId = e.OrganizationId, InstitutionName = e.InstitutionName, Degree = e.Degree, StartDate = e.StartDate, @@ -88,6 +77,7 @@ public async Task HandleAsync(UpdateStudent command, CancellationToken cancellat }).ToList(), student.Work.Select(w => new WorkDto { + OrganizationId = w.OrganizationId, Company = w.Company, Position = w.Position, StartDate = w.StartDate, diff --git a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Commands/Handlers/UpdateUserNotificationPreferencesHandler.cs b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Commands/Handlers/UpdateUserNotificationPreferencesHandler.cs index 8cd8a03c..daa8f3e8 100644 --- a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Commands/Handlers/UpdateUserNotificationPreferencesHandler.cs +++ b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Commands/Handlers/UpdateUserNotificationPreferencesHandler.cs @@ -24,7 +24,6 @@ public async Task HandleAsync(UpdateUserNotificationPreferences command, Cancell var commandJson = JsonSerializer.Serialize(command); Console.WriteLine($"Received UpdateUserNotificationPreferences command: {commandJson}"); - // Create the updated NotificationPreferences object, including new properties var notificationPreferences = new NotificationPreferences( command.SystemLogin, command.InterestBasedEvents, diff --git a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Dto/EducationDto.cs b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Dto/EducationDto.cs index ef7b07c5..66ecff39 100644 --- a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Dto/EducationDto.cs +++ b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Dto/EducationDto.cs @@ -7,6 +7,7 @@ namespace MiniSpace.Services.Students.Application.Dto [ExcludeFromCodeCoverage] public class EducationDto { + public Guid OrganizationId { get; set; } public string InstitutionName { get; set; } public string Degree { get; set; } public DateTime StartDate { get; set; } diff --git a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Dto/WorkDto.cs b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Dto/WorkDto.cs index a7a7114d..53466230 100644 --- a/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Dto/WorkDto.cs +++ b/MiniSpace.Services.Students/src/MiniSpace.Services.Students.Application/Dto/WorkDto.cs @@ -7,6 +7,7 @@ namespace MiniSpace.Services.Students.Application.Dto [ExcludeFromCodeCoverage] public class WorkDto { + public Guid OrganizationId { get; set; } public string Company { get; set; } public string Position { get; set; } public DateTime StartDate { get; set; }