Initial implementation of voice works scanning.
This commit is contained in:
@@ -4,10 +4,10 @@ namespace JSMR.Infrastructure.Data.Repositories.VoiceWorks;
|
||||
|
||||
public static class MySqlBooleanQuery
|
||||
{
|
||||
// Main entry
|
||||
public static string Normalize(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input)) return string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return string.Empty;
|
||||
|
||||
// Split into top-level tokens by spaces (not inside quotes/parentheses)
|
||||
var tokens = SplitTopLevel(input.Trim(), ' ');
|
||||
@@ -16,7 +16,12 @@ public static class MySqlBooleanQuery
|
||||
foreach (var raw in tokens)
|
||||
{
|
||||
var t = raw.Trim();
|
||||
if (t.Length == 0) continue;
|
||||
|
||||
if (t.Length == 0)
|
||||
continue;
|
||||
|
||||
if (t is "|")
|
||||
continue;
|
||||
|
||||
// Preserve explicit boolean operators user may already supply
|
||||
if (t[0] == '-' || t[0] == '+')
|
||||
@@ -63,7 +68,7 @@ public static class MySqlBooleanQuery
|
||||
var orParts = SplitTopLevel(token, '|')
|
||||
.Select(p => NormalizeOrAtom(p.Trim()))
|
||||
.Where(p => p.Length > 0);
|
||||
return "(" + string.Join("|", orParts) + ")";
|
||||
return "(" + string.Join(" ", orParts) + ")";
|
||||
}
|
||||
|
||||
// Plain atom -> as-is
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using JSMR.Application.VoiceWorks.Commands.SetFavorite;
|
||||
using JSMR.Application.VoiceWorks.Ports;
|
||||
using JSMR.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JSMR.Infrastructure.Data.Repositories.VoiceWorks;
|
||||
|
||||
public class VoiceWorkWriter(AppDbContext context) : IVoiceWorkWriter
|
||||
{
|
||||
public async Task<SetVoiceWorkFavoriteResponse> SetFavoriteAsync(SetVoiceWorkFavoriteRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
VoiceWork voiceWork = await GetVoiceWorkAsync(request.VoiceWorkId, cancellationToken);
|
||||
voiceWork.Favorite = request.IsFavorite;
|
||||
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new SetVoiceWorkFavoriteResponse(request.VoiceWorkId, request.IsFavorite);
|
||||
}
|
||||
|
||||
private async Task<VoiceWork> GetVoiceWorkAsync(int voiceWorkId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await context.VoiceWorks.FirstOrDefaultAsync(voiceWork => voiceWork.VoiceWorkId == voiceWorkId, cancellationToken)
|
||||
?? throw new KeyNotFoundException($"Voice Work {voiceWorkId} not found.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user