-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rename image tags table * add adding tags feature
- Loading branch information
Showing
12 changed files
with
155 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ns/20240309103014_AddImageTag.Designer.cs → ...ns/20240309213631_AddImageTag.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
ImageHosting.Storage/Extensions/DependencyInjection/QueryableExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace ImageHosting.Storage.Extensions.DependencyInjection; | ||
|
||
public static class QueryableExtensions | ||
{ | ||
public static async Task<HashSet<TSource>> ToHashSetAsync<TSource>( | ||
this IQueryable<TSource> source, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var set = new HashSet<TSource>(); | ||
await foreach (var element in source.AsAsyncEnumerable().WithCancellation(cancellationToken) | ||
.ConfigureAwait(false)) | ||
{ | ||
set.Add(element); | ||
} | ||
|
||
return set; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
ImageHosting.Storage/Features/Images/Handlers/AddTagsHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using ImageHosting.Persistence.DbContexts; | ||
using ImageHosting.Persistence.ValueTypes; | ||
using ImageHosting.Storage.Features.Images.Exceptions; | ||
using ImageHosting.Storage.Features.Images.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace ImageHosting.Storage.Features.Images.Handlers; | ||
|
||
public interface IAddTagsHandler | ||
{ | ||
Task<AddTagsResponse> AddAsync(ImageId id, IEnumerable<string> tags, | ||
CancellationToken cancellationToken = default); | ||
} | ||
|
||
public class AddTagsHandler(IImageHostingDbContext dbContext) : IAddTagsHandler | ||
{ | ||
public async Task<AddTagsResponse> AddAsync(ImageId id, IEnumerable<string> tags, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var image = await dbContext.Images | ||
.Include(i => i.Tags) | ||
.AsSplitQuery() | ||
.FirstOrDefaultAsync(i => i.Id == id, cancellationToken); | ||
if (image is null) | ||
{ | ||
throw new ImageMetadataNotFoundException(id); | ||
} | ||
|
||
image.AddTags(tags); | ||
|
||
await dbContext.SaveChangesAsync(cancellationToken); | ||
return new AddTagsResponse | ||
{ | ||
Tags = image.Tags.Select(t => t.TagName).ToList() | ||
}; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
ImageHosting.Storage/Features/Images/Models/AddTagsCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ImageHosting.Storage.Features.Images.Models; | ||
|
||
public class AddTagsCommand | ||
{ | ||
public required IEnumerable<string> Tags { get; init; } | ||
} |
8 changes: 8 additions & 0 deletions
8
ImageHosting.Storage/Features/Images/Models/AddTagsResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace ImageHosting.Storage.Features.Images.Models; | ||
|
||
public class AddTagsResponse | ||
{ | ||
public required IEnumerable<string> Tags { get; init; } | ||
} |