Files
mixtape/zero.Demo/SetupController.cs
T

122 lines
3.3 KiB
C#
Raw Normal View History

2021-12-10 23:43:52 +01:00
using Microsoft.AspNetCore.Mvc;
2021-12-23 11:01:38 +01:00
using Raven.Client.Documents;
2021-12-10 23:43:52 +01:00
using Raven.Client.Documents.Indexes;
2021-12-22 15:41:11 +01:00
using System.Text.Json;
using zero.Configuration;
2021-12-10 23:43:52 +01:00
using zero.Context;
2021-12-22 16:36:18 +01:00
using zero.Localization;
2021-12-10 23:43:52 +01:00
using zero.Persistence;
using zero.Routing;
2021-12-23 08:38:01 +01:00
using zero.Stores;
2021-12-22 15:41:11 +01:00
using zero.Utils;
2021-12-10 23:43:52 +01:00
namespace zero.Demo.Controllers;
2021-12-22 16:36:18 +01:00
[ApiController]
2021-12-10 23:43:52 +01:00
public class SetupController : Controller
{
//ISetupApi Api;
//public SetupController(ISetupApi api)
//{
// Api = api;
//}
//[HttpGet]
//public async Task<IActionResult> Install([FromQuery] string password)
//{
// var result = await Api.Install(new SetupModel()
// {
// AppName = "switchcase",
// ContentRootPath = "O:/zero/zero.Web",
// Database = new SetupDatabaseModel()
// {
// Name = "switchcase",
// Url = "http://localhost:9800"
// },
// User = new SetupUserModel()
// {
// Email = "cee@live.at",
// Name = "Tobias Klika",
// Password = password
// }
// });
// return Json(result);
//}
2021-12-22 15:41:11 +01:00
[HttpGet("/api/setup/json")]
2021-12-23 11:01:38 +01:00
public async Task<IActionResult> TestJson([FromServices] IZeroStore store, [FromServices] IZeroOptions options)
2021-12-22 15:41:11 +01:00
{
2021-12-23 11:01:38 +01:00
using var session = store.Session();
var items = await session.Query<Integration>().ToListAsync();
JsonSerializerOptions opts = new();
opts.Converters.Add(new JsonFlavorVariantConverterFactory(options));
var json = JsonSerializer.Serialize(items, opts);
return Content(json, "application/json");
2021-12-22 16:36:18 +01:00
}
2021-12-23 11:01:38 +01:00
[HttpGet("/api/setup/json1")]
public async Task<IActionResult> TestJson1([FromServices] IZeroStore store, [FromServices] IZeroOptions options)
{
using var session = store.Session();
var items = await session.Query<Integration>().ToListAsync();
JsonSerializerOptions opts = new();
opts.Converters.Add(new JsonFlavorVariantConverterFactory(options));
return Json(items, opts);
}
//[HttpGet("/api/setup/json")]
//public async Task<IActionResult> TestJson([FromServices] ICountryStore store)
//{
// var countries = await store.Load(pageNumber: 1, pageSize: 10);
// var json = JsonSerializer.Serialize(countries);
// return Json(json, "application/json");
//}
2021-12-22 16:36:18 +01:00
[HttpPost("/api/setup/postjson")]
public IActionResult PostTestJson(Country country)
{
2021-12-23 08:38:01 +01:00
return Json(new { type = country.GetType().FullName, model = country });
2021-12-22 15:41:11 +01:00
}
2021-12-10 23:43:52 +01:00
2021-12-13 12:21:15 +01:00
[HttpGet("/api/setup/indexes")]
2021-12-10 23:43:52 +01:00
public async Task<IActionResult> Indexes([FromServices] IZeroStore store, [FromServices] IZeroContext context)
{
var indexes = context.Options.For<RavenOptions>().Indexes;
var builtIndexes = indexes.BuildAll(context.Options, store.Raven);
await IndexCreation.CreateIndexesAsync(builtIndexes, store.Raven, database: "laola");
await IndexCreation.CreateIndexesAsync(builtIndexes, store.Raven, database: "laola.hofbauer");
await IndexCreation.CreateIndexesAsync(builtIndexes, store.Raven, database: "laola.brothers");
return Json(new
{
indexes = true
});
}
2021-12-13 12:21:15 +01:00
[HttpGet("/api/setup/routes")]
2021-12-10 23:43:52 +01:00
public async Task<IActionResult> Routes([FromServices] IZeroStore store, [FromServices] IZeroContext context, [FromServices] IEnumerable<IRouteProvider> providers)
{
RouteBulkRefresher refresher = new(store, context, providers);
int routes = await refresher.RebuildAllRoutes();
return Json(new
{
routes = routes
});
}
}