Skip to content

Commit

Permalink
(#433) users: add organizationId to dtos
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintAngeLs committed Oct 12, 2024
1 parent 8cd095f commit 2ebb5d9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
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;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using MiniSpace.Services.Students.Application.Services;

namespace MiniSpace.Services.Students.Application.Commands.Handlers
{
Expand All @@ -20,8 +20,7 @@ public class UpdateStudentHandler : ICommandHandler<UpdateStudent>
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;
Expand All @@ -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)));

Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 2ebb5d9

Please sign in to comment.