Skip to content

Commit 7d1fe9c

Browse files
committed
PR feedback and Swagger docs updates
1 parent c1eb93c commit 7d1fe9c

12 files changed

+52
-49
lines changed

src/Umbraco.Cms.Integrations.Search.Algolia/AlgoliaComposer.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Algolia.Search.Models.Search;
22
using Microsoft.Extensions.DependencyInjection;
3-
3+
using Microsoft.OpenApi.Models;
4+
using Swashbuckle.AspNetCore.SwaggerGen;
45
using Umbraco.Cms.Core.Composing;
56
using Umbraco.Cms.Core.DependencyInjection;
67
using Umbraco.Cms.Core.Notifications;
@@ -37,6 +38,19 @@ public void Compose(IUmbracoBuilder builder)
3738
builder.Services.AddScoped<IAlgoliaSearchPropertyIndexValueFactory, AlgoliaSearchPropertyIndexValueFactory>();
3839

3940
builder.AddAlgoliaConverters();
41+
42+
// Generate Swagger documentation for Algolia Search API
43+
builder.Services.Configure<SwaggerGenOptions>(options =>
44+
{
45+
options.SwaggerDoc(
46+
Constants.ManagementApi.GroupName,
47+
new OpenApiInfo
48+
{
49+
Title = Constants.ManagementApi.ApiTitle,
50+
Version = "Latest",
51+
Description = $"Describes the {Constants.ManagementApi.ApiTitle} available for handling indices."
52+
});
53+
});
4054
}
4155

4256
}

src/Umbraco.Cms.Integrations.Search.Algolia/Api/Management/Controllers/BuildIndexController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Algolia.Search.Models.Search;
2+
using Asp.Versioning;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.Extensions.Logging;
45
using System.Text.Json;
@@ -13,6 +14,7 @@
1314

1415
namespace Umbraco.Cms.Integrations.Search.Algolia.Api.Management.Controllers
1516
{
17+
[ApiVersion("1.0")]
1618
public class BuildIndexController : SearchControllerBase
1719
{
1820
public BuildIndexController(
@@ -69,11 +71,12 @@ public async Task<IActionResult> BuildIndex([FromBody] IndexConfiguration indexC
6971

7072
var result = await IndexService.PushData(index.Name, payload);
7173

72-
return new JsonResult(result);
74+
return Ok(result);
7375
}
7476
catch (Exception ex)
7577
{
76-
return new JsonResult(Result.Fail(ex.Message));
78+
Logger.LogError(ex, ex.Message);
79+
throw;
7780
}
7881
}
7982
}

src/Umbraco.Cms.Integrations.Search.Algolia/Api/Management/Controllers/DeleteIndexController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Algolia.Search.Models.Search;
2+
using Asp.Versioning;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.Extensions.Logging;
45
using Umbraco.Cms.Core.Routing;
@@ -11,6 +12,7 @@
1112

1213
namespace Umbraco.Cms.Integrations.Search.Algolia.Api.Management.Controllers
1314
{
15+
[ApiVersion("1.0")]
1416
public class DeleteIndexController : SearchControllerBase
1517
{
1618
public DeleteIndexController(
@@ -47,11 +49,12 @@ public async Task<IActionResult> DeleteIndex(int id)
4749

4850
await IndexService.DeleteIndex(indexName);
4951

50-
return new JsonResult(Result.Ok());
52+
return Ok(Result.Ok());
5153
}
5254
catch (Exception ex)
5355
{
54-
return new JsonResult(Result.Fail(ex.Message));
56+
Logger.LogError(ex, ex.Message);
57+
throw;
5558
}
5659
}
5760

src/Umbraco.Cms.Integrations.Search.Algolia/Api/Management/Controllers/GetContentTypesController.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
namespace Umbraco.Cms.Integrations.Search.Algolia.Api.Management.Controllers
1818
{
1919
[ApiVersion("1.0")]
20-
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
2120
public class GetContentTypesController : SearchControllerBase
2221
{
2322
private readonly IContentTypeService _contentTypeService;
@@ -106,7 +105,7 @@ public IActionResult GetContentTypes(int? id)
106105
});
107106
}
108107

109-
return new JsonResult(list);
108+
return Ok(list);
110109
}
111110

112111
}

src/Umbraco.Cms.Integrations.Search.Algolia/Api/Management/Controllers/GetIndexByIdController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Algolia.Search.Models.Search;
2+
using Asp.Versioning;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.Extensions.Logging;
45
using System.Text.Json;
@@ -13,6 +14,7 @@
1314

1415
namespace Umbraco.Cms.Integrations.Search.Algolia.Api.Management.Controllers
1516
{
17+
[ApiVersion("1.0")]
1618
public class GetIndexByIdController : SearchControllerBase
1719
{
1820
public GetIndexByIdController(
@@ -51,7 +53,7 @@ public IActionResult GetIndexById(int id)
5153
ContentData = JsonSerializer.Deserialize<IEnumerable<ContentTypeDto>>(index.SerializedData)
5254
};
5355

54-
return new JsonResult(indexConfiguration);
56+
return Ok(indexConfiguration);
5557
}
5658
}
5759
}

src/Umbraco.Cms.Integrations.Search.Algolia/Api/Management/Controllers/GetIndicesController.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
namespace Umbraco.Cms.Integrations.Search.Algolia.Api.Management.Controllers
1818
{
1919
[ApiVersion("1.0")]
20-
[ApiExplorerSettings(GroupName = Constants.ManagementApi.GroupName)]
2120
public class GetIndicesController : SearchControllerBase
2221
{
2322
public GetIndicesController(
@@ -46,14 +45,16 @@ public GetIndicesController(
4645

4746
[HttpGet("index")]
4847
[ProducesResponseType(typeof(IEnumerable<IndexConfiguration>), StatusCodes.Status200OK)]
49-
public IEnumerable<IndexConfiguration> GetIndices()
48+
public IActionResult GetIndices()
5049
{
51-
return IndexStorage.Get().Select(p => new IndexConfiguration
50+
var indices = IndexStorage.Get().Select(p => new IndexConfiguration
5251
{
5352
Id = p.Id,
5453
Name = p.Name,
5554
ContentData = JsonSerializer.Deserialize<IEnumerable<ContentTypeDto>>(p.SerializedData)
5655
});
56+
57+
return Ok(indices);
5758
}
5859
}
5960
}

src/Umbraco.Cms.Integrations.Search.Algolia/Api/Management/Controllers/SaveIndexController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Algolia.Search.Models.Search;
2+
using Asp.Versioning;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.Extensions.Logging;
45
using System.Text.Json;
@@ -12,6 +13,7 @@
1213

1314
namespace Umbraco.Cms.Integrations.Search.Algolia.Api.Management.Controllers
1415
{
16+
[ApiVersion("1.0")]
1517
public class SaveIndexController : SearchControllerBase
1618
{
1719
public SaveIndexController(
@@ -56,11 +58,12 @@ public async Task<IActionResult> SaveIndex([FromBody] IndexConfiguration index)
5658
? Result.Ok()
5759
: await IndexService.PushData(index.Name);
5860

59-
return new JsonResult(result);
61+
return Ok(result);
6062
}
6163
catch (Exception ex)
6264
{
63-
return new JsonResult(Result.Fail(ex.Message));
65+
Logger.LogError(ex, ex.Message);
66+
throw;
6467
}
6568
}
6669
}

src/Umbraco.Cms.Integrations.Search.Algolia/Api/Management/Controllers/SearchControllerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Umbraco.Cms.Integrations.Search.Algolia.Api.Management.Controllers
2020
[BackOfficeRoute($"{Constants.ManagementApi.RootPath}/v{{version:apiVersion}}/search")]
2121
[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)]
2222
[MapToApi(Constants.ManagementApi.GroupName)]
23-
public abstract class SearchControllerBase
23+
public abstract class SearchControllerBase : Controller
2424
{
2525
protected IAlgoliaIndexService IndexService { get; }
2626

src/Umbraco.Cms.Integrations.Search.Algolia/Api/Management/Controllers/SearchIndexController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Algolia.Search.Models.Search;
2+
using Asp.Versioning;
23
using Microsoft.AspNetCore.Mvc;
34
using Microsoft.Extensions.Logging;
45
using Umbraco.Cms.Core.Routing;
@@ -11,6 +12,7 @@
1112

1213
namespace Umbraco.Cms.Integrations.Search.Algolia.Api.Management.Controllers
1314
{
15+
[ApiVersion("1.0")]
1416
public class SearchIndexController : SearchControllerBase
1517
{
1618
public SearchIndexController(
@@ -51,7 +53,7 @@ public IActionResult Search(int indexId, string query)
5153
Hits = searchResults.Hits.Select(p => p.Data.ToDictionary(x => x.Key, y => y.Value.ToString())).ToList()
5254
};
5355

54-
return new JsonResult(response);
56+
return Ok(response);
5557
}
5658
}
5759
}

src/Umbraco.Cms.Integrations.Search.Algolia/Api/Management/Controllers/TimeDashboardControllerBase.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)