namespace NetinaShop.Api.Controller;

public class SearchController : ICarterModule
{
    public void AddRoutes(IEndpointRouteBuilder app)
    {
        var group = app.NewVersionedApi("Search").MapGroup("api/search");

        group.MapGet("", SearchAsync)
            .WithDisplayName("Search Async")
            .HasApiVersion(1.0);
    }

    private async Task<IResult> SearchAsync([FromQuery] string name, [FromServices] ISearchService searchService, CancellationToken cancellationToken)
        => TypedResults.Ok(await searchService.SearchAsync(name, cancellationToken));
}