Add Api.Contracts
This commit is contained in:
parent
374ee606f8
commit
a2e335e0a4
@ -0,0 +1,20 @@
|
||||
using Nocr.TextMatcher.AppServices.Contracts.TextMatches;
|
||||
|
||||
namespace Nocr.TextMatcher.Api.Contracts.TextMatches.Dto;
|
||||
|
||||
public sealed class TextMatchData
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
public long UserId { get; set; }
|
||||
|
||||
public long? ChatId { get; set; }
|
||||
|
||||
public string ChatUsername { get; set; }
|
||||
|
||||
public string Template { get; set; }
|
||||
|
||||
public TextMatchRule Rule { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedDateTime { get; set; }
|
||||
}
|
||||
@ -6,5 +6,9 @@ namespace Nocr.TextMatcher.Api.Contracts.TextMatches;
|
||||
[BasePath(WebRoutes.TextMatches.Path)]
|
||||
public interface ITextMatchesController
|
||||
{
|
||||
[Post]
|
||||
Task<long> Create([Body] CreateTextMatchRequest request, CancellationToken cancellationToken = default);
|
||||
|
||||
[Get(WebRoutes.TextMatches.ByUserId)]
|
||||
Task<TextMatchData[]> GetByUserId([Path] long userId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@ -7,5 +7,7 @@ public static class WebRoutes
|
||||
public static class TextMatches
|
||||
{
|
||||
public const string Path = BasePath + "/" + "text-matches";
|
||||
|
||||
public const string ByUserId = "by-user-id/{userId}";
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Nocr.TextMatcher.Api.Contracts\Nocr.TextMatcher.Api.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Nocr.TextMatcher.AppServices.Contracts\Nocr.TextMatcher.AppServices.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Nocr.TextMatcher.Async.Api.Contracts\Nocr.TextMatcher.Async.Api.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Nocr.TextMatcher.Core\Nocr.TextMatcher.Core.csproj" />
|
||||
|
||||
@ -7,4 +7,6 @@ public interface ITextMatchRepository
|
||||
Task Delete(long id, CancellationToken cancellationToken = default);
|
||||
|
||||
Task<IReadOnlyCollection<TextMatch>> Get(CancellationToken cancellationToken = default);
|
||||
|
||||
Task<IReadOnlyCollection<TextMatch>> GetByUserId(long userId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
using Nocr.TextMatcher.Api.Contracts.TextMatches.Dto;
|
||||
using Nocr.TextMatcher.AppServices.Contracts.TextMatches;
|
||||
|
||||
namespace Nocr.TextMatcher.AppServices.TextMatches.Repositories;
|
||||
@ -43,4 +44,9 @@ public sealed class InMemoryTextMatchRepository : ITextMatchRepository
|
||||
{
|
||||
return Task.FromResult<IReadOnlyCollection<TextMatch>>(_textMatches);
|
||||
}
|
||||
|
||||
public Task<IReadOnlyCollection<TextMatch>> GetByUserId(long userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.FromResult<IReadOnlyCollection<TextMatch>>(_textMatches.Where(x => x.UserId == userId).ToArray());
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
using Nocr.TextMatcher.Api.Contracts.TextMatches.Dto;
|
||||
using Nocr.TextMatcher.AppServices.Contracts.TextMatches;
|
||||
|
||||
namespace Nocr.TextMatcher.AppServices.TextMatches.Services;
|
||||
@ -10,4 +11,6 @@ public interface ITextMatchService
|
||||
Task Delete(long id, CancellationToken cancellationToken = default);
|
||||
|
||||
Task<IReadOnlyCollection<TextMatch>> Get(CancellationToken cancellationToken = default);
|
||||
|
||||
Task<IReadOnlyCollection<TextMatchData>> GetByUserId(long userId, CancellationToken cancellationToken);
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
using Nocr.TextMatcher.Api.Contracts.TextMatches.Dto;
|
||||
using Nocr.TextMatcher.AppServices.Contracts.TextMatches;
|
||||
using Nocr.TextMatcher.AppServices.TextMatches.Repositories;
|
||||
using Nocr.TextMatcher.Async.Api.Contracts;
|
||||
@ -46,4 +47,19 @@ public sealed class TextMatchService : ITextMatchService
|
||||
{
|
||||
return _repository.Get(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<TextMatchData>> GetByUserId(long userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var matches = await _repository.GetByUserId(userId, cancellationToken);
|
||||
return matches.Select(x => new TextMatchData
|
||||
{
|
||||
Id = x.Id,
|
||||
ChatId = x.ChatId,
|
||||
ChatUsername = x.ChatUsername,
|
||||
Template = x.Template,
|
||||
UserId = x.UserId,
|
||||
Rule = x.Rule,
|
||||
CreatedDateTime = x.CreatedDateTime
|
||||
}).ToArray();
|
||||
}
|
||||
}
|
||||
@ -22,4 +22,10 @@ public class TextMatchController : ControllerBase
|
||||
return _textMatchService.Create(request.UserId, request.ChatUsername, request.Template, request.Rule,
|
||||
request.ChatId, cancellationToken);
|
||||
}
|
||||
|
||||
[HttpGet(WebRoutes.TextMatches.ByUserId)]
|
||||
public Task<IReadOnlyCollection<TextMatchData>> GetByUserId([FromRoute] long userId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return _textMatchService.GetByUserId(userId, cancellationToken);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user