Skip to content

Commit 9d6e083

Browse files
committed
new image upload fix
1 parent 355368f commit 9d6e083

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/Application/UserImages/AddImage/AddUserImageCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public async Task<Result<Guid>> Handle(AddUserImageCommand command, Cancellation
3636
{
3737
Id = Guid.NewGuid(),
3838
UserId = user.Id,
39-
ImageUrl = command.ImageUrl,
39+
ImageUrl = command.ImageUrl.ToString(),
4040
CreatedAt = dateTimeProvider.UtcNow
4141
};
4242

src/Application/UserImages/ImageUpload/UploadUserImageCommandHandler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Application.Abstractions.Messaging;
66
using Domain.Images;
77
using Domain.Users;
8+
using MediatR;
89
using Microsoft.EntityFrameworkCore;
910
using Microsoft.EntityFrameworkCore.Metadata;
1011
using SharedKernel;
@@ -32,20 +33,20 @@ public async Task<Result<Guid>> Handle(UploadUserImageCommand command, Cancellat
3233
return Result.Failure<Guid>(UserErrors.NotFound(command.UserId));
3334
}
3435

35-
var image = new UserImage
36+
var userImage = new UserImage
3637
{
3738
Id = Guid.NewGuid(),
3839
UserId = user.Id,
3940
ImageData = command.ImageData,
40-
ImageUrl = command.ImageUrl,
41+
ImageUrl = command.ImageUrl.ToString(),
4142
CreatedAt = dateTimeProvider.UtcNow
4243
};
4344

4445
// Step 3: Add to DB and save
45-
context.UserImages.Add(image);
46+
context.UserImages.Add(userImage);
4647
await context.SaveChangesAsync(cancellationToken);
4748

4849
// Step 4: Return result
49-
return Result.Success(image.Id);
50+
return Result.Success(userImage.Id);
5051
}
5152
}

src/Domain/Images/UserImage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public sealed class UserImage : Entity
88
{
99
public Guid Id { get; set; }
1010
public Guid UserId { get; set; }
11-
public Uri? ImageUrl { get; set; } = null!;
11+
public string? ImageUrl { get; set; } = null!;
1212
public byte[]? ImageData { get; set; }
1313
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
1414
// public User? User { get; set; } // Navigation property

src/Web.Api/Endpoints/UserImages/UploadImageData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void MapEndpoint(IEndpointRouteBuilder app)
4444
{
4545
UserId = request.UserId,
4646
ImageData = memoryStream.ToArray(),
47-
ImageUrl = cloudinaryUrl.ToString()
47+
ImageUrl = cloudinaryUrl
4848
};
4949

5050
Result<Guid> result = await sender.Send(command, cancellationToken);

0 commit comments

Comments
 (0)