GCR deployment testing in progress - content type issue still remaining.

This commit is contained in:
2026-05-05 14:42:03 +05:00
parent 40fe69ed65
commit f8112f897e
22 changed files with 348 additions and 2431 deletions
+13 -5
View File
@@ -1,5 +1,7 @@
using Immediate.Apis.Shared;
using Immediate.Handlers.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Htmx.ApiDemo.Templates;
@@ -21,9 +23,14 @@ public sealed class Greeting : GreetingBase
[MapGet("/greet/{username}/{count?}/{id?}")]
public static partial class GetGreetingHandler
{
public record Query(string Username, int? Count, Guid? Id);
public class Query
{
[FromRoute] public string Username { get; set; } = default!;
[FromRoute] public string? Count { get; set; }
[FromRoute] public string? Id { get; set; }
}
private static ValueTask HandleAsync(
private static ValueTask<IResult> HandleAsync(
Query query,
IHttpContextAccessor httpContextAccessor,
CancellationToken token)
@@ -31,8 +38,9 @@ public static partial class GetGreetingHandler
var context = httpContextAccessor.HttpContext
?? throw new InvalidOperationException("HttpContext is not available.");
var template = new Greeting { Username = query.Username, Count = query.Count + 1 ?? 0, GreetingId = query.Id ?? Guid.NewGuid() };
context.WriteHtmxBody(template);
return ValueTask.CompletedTask;
var count = int.TryParse(query.Count, out var parsedCount) ? parsedCount + 1 : 0;
var greetingId = Guid.TryParse(query.Id, out var parsedId) ? parsedId : Guid.NewGuid();
var template = new Greeting { Username = query.Username, Count = count, GreetingId = greetingId };
return ValueTask.FromResult<IResult>(context.WriteHtmxBody(template));
}
}
+13 -18
View File
@@ -2,6 +2,7 @@ using Htmx.ApiDemo.Data;
using Immediate.Apis.Shared;
using Immediate.Handlers.Shared;
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Htmx.ApiDemo.Templates;
@@ -31,9 +32,9 @@ public sealed class Login : LoginBase
[MapGet("/login")]
public static partial class GetLoginHandler
{
public record Query;
public class Query;
private static ValueTask HandleAsync(
private static ValueTask<IResult> HandleAsync(
Query _,
IHttpContextAccessor httpContextAccessor,
IAntiforgery antiforgery,
@@ -43,14 +44,10 @@ public static partial class GetLoginHandler
?? throw new InvalidOperationException("HttpContext is not available.");
if (ctx.User.Identity?.IsAuthenticated == true)
{
ctx.Response.Redirect("/");
return ValueTask.CompletedTask;
}
return ValueTask.FromResult<IResult>(new HtmxResult("/"));
var afTokens = antiforgery.GetAndStoreTokens(ctx);
ctx.WriteHtmxPage(new Login(afToken: afTokens.RequestToken), title: "Sign in", appName: "HtmxApp", pageTitle: "Sign in");
return ValueTask.CompletedTask;
return ValueTask.FromResult<IResult>(ctx.WriteHtmxPage(new Login(afToken: afTokens.RequestToken), title: "Sign in", appName: "HtmxApp", pageTitle: "Sign in"));
}
}
@@ -59,12 +56,13 @@ public static partial class GetLoginHandler
[MapPost("/login")]
public static partial class PostLoginHandler
{
public record Command(
[property: FromForm] string Email,
[property: FromForm] string Password
);
public class Command
{
[FromForm] public string Email { get; set; } = default!;
[FromForm] public string Password { get; set; } = default!;
}
private static async ValueTask HandleAsync(
private static async ValueTask<IResult> HandleAsync(
[AsParameters] Command command,
IHttpContextAccessor httpContextAccessor,
IAntiforgery antiforgery,
@@ -77,12 +75,9 @@ public static partial class PostLoginHandler
var (success, error) = await authService.LoginAsync(command.Email, command.Password);
if (success)
{
ctx.Response.Redirect("/");
return;
}
return new HtmxResult("/");
var afTokens = antiforgery.GetAndStoreTokens(ctx);
ctx.WriteHtmxPage(new Login(error, afToken: afTokens.RequestToken), title: "Sign in", appName: "HtmxApp", pageTitle: "Sign in");
return ctx.WriteHtmxPage(new Login(error, afToken: afTokens.RequestToken), title: "Sign in", appName: "HtmxApp", pageTitle: "Sign in");
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ public static partial class PostLogoutHandler
{
// Empty command — [AsParameters] ensures form content-type is accepted
// and antiforgery token in the form is validated by the middleware.
public record Command;
public class Command;
private static async ValueTask HandleAsync(
[AsParameters] Command _,
+4 -5
View File
@@ -2,6 +2,7 @@ using Htmx.ApiDemo;
using Htmx.ApiDemo.Templates.Components;
using Immediate.Apis.Shared;
using Immediate.Handlers.Shared;
using Microsoft.AspNetCore.Http;
namespace Htmx.ApiDemo.Templates;
@@ -73,9 +74,9 @@ public sealed class MainLayout : MainLayoutBase
[MapGet("/")]
public static partial class GetIndexHandler
{
public record Command;
public class Command;
private static ValueTask HandleAsync(
private static ValueTask<IResult> HandleAsync(
Command command,
IHttpContextAccessor httpContextAccessor,
CancellationToken token)
@@ -84,8 +85,6 @@ public static partial class GetIndexHandler
?? throw new InvalidOperationException("HttpContext is not available.");
var greet = new Greeting { Username = "Enciphered", Count = 0, GreetingId = Guid.NewGuid() };
context.WriteHtmxPage(greet, title: "Home", appName: "HtmxApp", pageTitle: "Home");
return ValueTask.CompletedTask;
return ValueTask.FromResult<IResult>(context.WriteHtmxPage(greet, title: "Home", appName: "HtmxApp", pageTitle: "Home"));
}
}
+16 -22
View File
@@ -2,6 +2,7 @@ using Htmx.ApiDemo.Data;
using Immediate.Apis.Shared;
using Immediate.Handlers.Shared;
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Htmx.ApiDemo.Templates;
@@ -31,9 +32,9 @@ public sealed class Register : RegisterBase
[MapGet("/register")]
public static partial class GetRegisterHandler
{
public record Query;
public class Query;
private static ValueTask HandleAsync(
private static ValueTask<IResult> HandleAsync(
Query _,
IHttpContextAccessor httpContextAccessor,
IAntiforgery antiforgery,
@@ -43,14 +44,10 @@ public static partial class GetRegisterHandler
?? throw new InvalidOperationException("HttpContext is not available.");
if (ctx.User.Identity?.IsAuthenticated == true)
{
ctx.Response.Redirect("/");
return ValueTask.CompletedTask;
}
return ValueTask.FromResult<IResult>(new HtmxResult("/"));
var afTokens = antiforgery.GetAndStoreTokens(ctx);
ctx.WriteHtmxPage(new Register(afToken: afTokens.RequestToken), title: "Register", appName: "HtmxApp", pageTitle: "Create account");
return ValueTask.CompletedTask;
return ValueTask.FromResult<IResult>(ctx.WriteHtmxPage(new Register(afToken: afTokens.RequestToken), title: "Register", appName: "HtmxApp", pageTitle: "Create account"));
}
}
@@ -59,14 +56,15 @@ public static partial class GetRegisterHandler
[MapPost("/register")]
public static partial class PostRegisterHandler
{
public record Command(
[property: FromForm] string Email,
[property: FromForm] string Password,
[property: FromForm] string ConfirmPassword,
[property: FromForm] string? DisplayName
);
public class Command
{
[FromForm] public string Email { get; set; } = default!;
[FromForm] public string Password { get; set; } = default!;
[FromForm] public string ConfirmPassword { get; set; } = default!;
[FromForm] public string? DisplayName { get; set; }
}
private static async ValueTask HandleAsync(
private static async ValueTask<IResult> HandleAsync(
[AsParameters] Command command,
IHttpContextAccessor httpContextAccessor,
IAntiforgery antiforgery,
@@ -79,21 +77,17 @@ public static partial class PostRegisterHandler
if (command.Password != command.ConfirmPassword)
{
var afTokens1 = antiforgery.GetAndStoreTokens(ctx);
ctx.WriteHtmxPage(new Register("Passwords do not match.", afToken: afTokens1.RequestToken),
return ctx.WriteHtmxPage(new Register("Passwords do not match.", afToken: afTokens1.RequestToken),
title: "Register", appName: "HtmxApp", pageTitle: "Create account");
return;
}
var (success, error) = await authService.RegisterAsync(command.Email, command.Password, command.DisplayName);
if (success)
{
ctx.Response.Redirect("/");
return;
}
return new HtmxResult("/");
var afTokens2 = antiforgery.GetAndStoreTokens(ctx);
ctx.WriteHtmxPage(new Register(error, afToken: afTokens2.RequestToken),
return ctx.WriteHtmxPage(new Register(error, afToken: afTokens2.RequestToken),
title: "Register", appName: "HtmxApp", pageTitle: "Create account");
}
}
+4 -5
View File
@@ -1,6 +1,7 @@
using Htmx.ApiDemo.Templates.Components;
using Immediate.Apis.Shared;
using Immediate.Handlers.Shared;
using Microsoft.AspNetCore.Http;
namespace Htmx.ApiDemo.Templates;
@@ -370,9 +371,9 @@ public sealed class UiDemo : UiDemoBase
[MapGet("/ui-demo")]
public static partial class GetUiDemoHandler
{
public record Query;
public class Query;
private static ValueTask HandleAsync(
private static ValueTask<IResult> HandleAsync(
Query query,
IHttpContextAccessor httpContextAccessor,
CancellationToken token)
@@ -381,8 +382,6 @@ public static partial class GetUiDemoHandler
?? throw new InvalidOperationException("HttpContext is not available.");
var page = new UiDemo();
context.WriteHtmxPage(page, title: "UI Demo", appName: "HtmxApp", pageTitle: "UI Components");
return ValueTask.CompletedTask;
return ValueTask.FromResult<IResult>(context.WriteHtmxPage(page, title: "UI Demo", appName: "HtmxApp", pageTitle: "UI Components"));
}
}