Изображения в услугах, поиске, возможность открыть карточку услуги

This commit is contained in:
Халимов Рустам
2026-03-06 23:14:39 +03:00
parent 420a86b92f
commit f5e20c1fb2
16 changed files with 480 additions and 11 deletions
@@ -0,0 +1,48 @@
using System.Text.Json;
using MediatR;
using Nashel.BuildingBlocks.Application.Abstractions;
using Nashel.Modules.Catalog.Domain.Aggregates;
using Nashel.Modules.Catalog.Domain.Repositories;
using Nashel.Modules.Catalog.Domain.ValueObjects;
namespace Nashel.Modules.Catalog.Application.Commands;
public record UpdateOfferCommand(
Guid OfferId,
string Title,
string Description,
decimal PriceAmount,
int PriceType, // 0-Fixed, 1-Hourly, 2-Negotiable
Dictionary<string, string>? Attributes,
List<string>? Images) : IRequest<bool>;
public class UpdateOfferCommandHandler : IRequestHandler<UpdateOfferCommand, bool>
{
private readonly IOfferRepository _repository;
private readonly ICurrentUserService _currentUser;
public UpdateOfferCommandHandler(IOfferRepository repository, ICurrentUserService currentUser)
{
_repository = repository;
_currentUser = currentUser;
}
public async Task<bool> Handle(UpdateOfferCommand request, CancellationToken cancellationToken)
{
var offer = await _repository.GetByIdAsync(request.OfferId, cancellationToken);
if (offer == null) throw new Exception("Offer not found");
if (offer.PerformerId != _currentUser.UserId)
throw new UnauthorizedAccessException("Not your offer");
var price = new Price(request.PriceAmount, (Nashel.Modules.Catalog.Domain.Enums.OfferType)request.PriceType);
var jsonAttrs = request.Attributes != null && request.Attributes.Count > 0
? JsonDocument.Parse(JsonSerializer.Serialize(request.Attributes))
: null;
offer.Update(request.Title, request.Description, price, jsonAttrs, request.Images);
await _repository.UpdateAsync(offer, cancellationToken);
return true;
}
}