Fixed item creation when there is no image attached
This commit is contained in:
@@ -15,6 +15,8 @@ public record ItemEntry
|
|||||||
|
|
||||||
public int State { get; set; } = 0;
|
public int State { get; set; } = 0;
|
||||||
|
|
||||||
|
public Guid? ImageId { get; set; }
|
||||||
|
|
||||||
public BlobEntry? Image { get; set; }
|
public BlobEntry? Image { get; set; }
|
||||||
|
|
||||||
public required string Category { get; set; }
|
public required string Category { get; set; }
|
||||||
|
|||||||
@@ -31,11 +31,12 @@ public class WalletContext(DbContextOptions<WalletContext> options) :
|
|||||||
.WithOne()
|
.WithOne()
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
modelBuilder.Entity<ItemEntry>()
|
modelBuilder.Entity<ItemEntry>().
|
||||||
.HasOne(x => x.Image)
|
HasOne(i => i.Image)
|
||||||
.WithOne()
|
.WithOne()
|
||||||
.HasForeignKey<ItemEntry>()
|
.HasForeignKey<ItemEntry>(i => i.ImageId)
|
||||||
.IsRequired(false);
|
.IsRequired(false)
|
||||||
|
.OnDelete(DeleteBehavior.Restrict);
|
||||||
|
|
||||||
modelBuilder.Entity<BlobEntry>()
|
modelBuilder.Entity<BlobEntry>()
|
||||||
.HasKey(x => x.Id);
|
.HasKey(x => x.Id);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class ConfirmCreateItemHandler(IMediator mediator,
|
|||||||
|
|
||||||
await mediator.Handle<CreateEventArgs<(Guid, string, string, IImageDescriptor?,
|
await mediator.Handle<CreateEventArgs<(Guid, string, string, IImageDescriptor?,
|
||||||
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string, IImageDescriptor?,
|
ItemConfiguration)>, bool>(new CreateEventArgs<(Guid, string, string, IImageDescriptor?,
|
||||||
ItemConfiguration)>((id, name, category, imageDescriptor, itemConfiguration)));
|
ItemConfiguration)>((id, name, category, imageDescriptor ?? default, itemConfiguration)));
|
||||||
|
|
||||||
publisher.Publish(Changed.As<Item>());
|
publisher.Publish(Changed.As<Item>());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ public class CreateItemHandler(IImageWriter imageWriter,
|
|||||||
public async Task<bool> Handle(CreateEventArgs<(Guid, string, string, IImageDescriptor?, ItemConfiguration)> args,
|
public async Task<bool> Handle(CreateEventArgs<(Guid, string, string, IImageDescriptor?, ItemConfiguration)> args,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (args.Sender is (Guid id, string name, string category, IImageDescriptor imageDescriptor, ItemConfiguration configuration))
|
(Guid id, string name, string category, IImageDescriptor? imageDescriptor, ItemConfiguration configuration) = args.Sender;
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string content = JsonSerializer.Serialize(configuration);
|
string content = JsonSerializer.Serialize(configuration);
|
||||||
@@ -23,7 +22,7 @@ public class CreateItemHandler(IImageWriter imageWriter,
|
|||||||
|
|
||||||
if (imageDescriptor is not null)
|
if (imageDescriptor is not null)
|
||||||
{
|
{
|
||||||
using MemoryStream memoryStream = new MemoryStream();
|
using MemoryStream memoryStream = new();
|
||||||
imageWriter.Write(imageDescriptor, memoryStream);
|
imageWriter.Write(imageDescriptor, memoryStream);
|
||||||
thumbData = memoryStream.ToArray();
|
thumbData = memoryStream.ToArray();
|
||||||
}
|
}
|
||||||
@@ -65,7 +64,6 @@ public class CreateItemHandler(IImageWriter imageWriter,
|
|||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user