Convert Projects module to MediatR commands/queries

Replaces IProjectService/ProjectService. IProjectMemberService is
left in place for now — ProjectMembersController still depends on it
until the next task converts it too.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-14 08:47:02 +07:00
co-authored by Claude Sonnet 5
parent 3a926e8693
commit 7e265805c3
12 changed files with 208 additions and 151 deletions
@@ -0,0 +1,35 @@
using AutoMapper;
using MediatR;
using Mws.Application.Common;
using Mws.Domain.Projects;
namespace Mws.Application.Projects;
public record UpdateProjectCommand(Guid UserId, Guid ProjectId, UpdateProjectRequest Request) : IRequest<ProjectDto>;
public class UpdateProjectHandler(IUnitOfWork uow, IMapper mapper) : IRequestHandler<UpdateProjectCommand, ProjectDto>
{
public async Task<ProjectDto> Handle(UpdateProjectCommand command, CancellationToken ct)
{
var project = await ProjectAccess.GetForUserOrThrowAsync(uow, command.UserId, command.ProjectId, ct);
if (MemberRole.Owner != await uow.Projects.GetMemberRoleAsync(command.ProjectId, command.UserId, ct))
{
throw new ForbiddenException("Only the project owner can update the project");
}
var request = command.Request;
if (string.IsNullOrWhiteSpace(request.Name))
{
throw new BadRequestException("Project name is required");
}
project.Name = request.Name.Trim();
project.Description = request.Description;
project.Status = request.Status;
project.UpdatedAt = DateTime.UtcNow;
await uow.SaveChangesAsync(ct);
return mapper.Map<ProjectDto>(project);
}
}