Skip to content

Commit f9ce99e

Browse files
authored
Hotfix/serialization request fix (#350)
* Fixed the dashboard serialization on crud of tickers * fixed daashboard missing lockholder and locked at time on update * updated version for release
1 parent 1596f2d commit f9ce99e

File tree

9 files changed

+110
-239
lines changed

9 files changed

+110
-239
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PackageTags>ticker;queue;cron;time;scheduler;fire-and-forget</PackageTags>
99
<PackageIcon>icon.jpg</PackageIcon>
1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
11-
<Version>9.0.0-beta.13</Version>
11+
<Version>9.0.0-beta.14</Version>
1212
<LangVersion>latest</LangVersion>
1313
</PropertyGroup>
1414

src/TickerQ.Dashboard/Endpoints/DashboardEndpoints.cs

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Microsoft.AspNetCore.Routing;
1111
using TickerQ.Dashboard.Authentication;
1212
using TickerQ.Dashboard.Hubs;
13-
using TickerQ.Dashboard.Infrastructure;
1413
using TickerQ.Utilities;
1514
using TickerQ.Utilities.DashboardDtos;
1615
using TickerQ.Utilities.Entities;
@@ -317,25 +316,44 @@ private static async Task<IResult> CreateChainJobs<TTimeTicker, TCronTicker>(
317316

318317
private static async Task<IResult> UpdateTimeTicker<TTimeTicker, TCronTicker>(
319318
Guid id,
320-
TTimeTicker request,
321-
ITickerDashboardRepository<TTimeTicker, TCronTicker> repository,
319+
HttpContext context,
320+
ITimeTickerManager<TTimeTicker> timeTickerManager,
321+
DashboardOptionsBuilder dashboardOptions,
322322
CancellationToken cancellationToken)
323323
where TTimeTicker : TimeTickerEntity<TTimeTicker>, new()
324324
where TCronTicker : CronTickerEntity, new()
325325
{
326-
await repository.UpdateTimeTickerAsync(id, request, cancellationToken);
327-
return Results.Ok();
326+
// Read the raw JSON from request body
327+
using var reader = new StreamReader(context.Request.Body);
328+
var jsonString = await reader.ReadToEndAsync(cancellationToken);
329+
330+
// Use Dashboard-specific JSON options
331+
var timeTicker = JsonSerializer.Deserialize<TTimeTicker>(jsonString, dashboardOptions.DashboardJsonOptions);
332+
333+
// Ensure the ID matches
334+
timeTicker.Id = id;
335+
336+
var result = await timeTickerManager.UpdateAsync(timeTicker, cancellationToken);
337+
338+
return Results.Ok(new {
339+
success = result.IsSucceeded,
340+
message = result.IsSucceeded ? "Time ticker updated successfully" : "Failed to update time ticker"
341+
});
328342
}
329343

330344
private static async Task<IResult> DeleteTimeTicker<TTimeTicker, TCronTicker>(
331345
Guid id,
332-
ITickerDashboardRepository<TTimeTicker, TCronTicker> repository,
346+
ITimeTickerManager<TTimeTicker> timeTickerManager,
333347
CancellationToken cancellationToken)
334348
where TTimeTicker : TimeTickerEntity<TTimeTicker>, new()
335349
where TCronTicker : CronTickerEntity, new()
336350
{
337-
await repository.DeleteTimeTickerByIdAsync(id, cancellationToken);
338-
return Results.Ok();
351+
var result = await timeTickerManager.DeleteAsync(id, cancellationToken);
352+
353+
return Results.Ok(new {
354+
success = result.IsSucceeded,
355+
message = result.IsSucceeded ? "Time ticker deleted successfully" : "Failed to delete time ticker"
356+
});
339357
}
340358

341359
private static async Task<IResult> GetCronTickers<TTimeTicker, TCronTicker>(
@@ -431,26 +449,54 @@ private static async Task<IResult> GetCronTickerOccurrencesGraphData<TTimeTicker
431449
}
432450

433451
private static async Task<IResult> AddCronTicker<TTimeTicker, TCronTicker>(
434-
TCronTicker request,
435-
ITickerDashboardRepository<TTimeTicker, TCronTicker> repository,
452+
HttpContext context,
453+
ICronTickerManager<TCronTicker> cronTickerManager,
454+
DashboardOptionsBuilder dashboardOptions,
436455
CancellationToken cancellationToken)
437456
where TTimeTicker : TimeTickerEntity<TTimeTicker>, new()
438457
where TCronTicker : CronTickerEntity, new()
439458
{
440-
await repository.AddCronTickerAsync(request, cancellationToken);
441-
return Results.Ok();
459+
// Read the raw JSON from request body
460+
using var reader = new StreamReader(context.Request.Body);
461+
var jsonString = await reader.ReadToEndAsync(cancellationToken);
462+
463+
// Use Dashboard-specific JSON options
464+
var cronTicker = JsonSerializer.Deserialize<TCronTicker>(jsonString, dashboardOptions.DashboardJsonOptions);
465+
466+
var result = await cronTickerManager.AddAsync(cronTicker, cancellationToken);
467+
468+
return Results.Ok(new {
469+
success = result.IsSucceeded,
470+
message = result.IsSucceeded ? "Cron ticker added successfully" : "Failed to add cron ticker",
471+
tickerId = result.Result?.Id
472+
});
442473
}
443474

444475
private static async Task<IResult> UpdateCronTicker<TTimeTicker, TCronTicker>(
445476
Guid id,
446-
UpdateCronTickerRequest request,
447-
ITickerDashboardRepository<TTimeTicker, TCronTicker> repository,
477+
HttpContext context,
478+
ICronTickerManager<TCronTicker> cronTickerManager,
479+
DashboardOptionsBuilder dashboardOptions,
448480
CancellationToken cancellationToken)
449481
where TTimeTicker : TimeTickerEntity<TTimeTicker>, new()
450482
where TCronTicker : CronTickerEntity, new()
451483
{
452-
await repository.UpdateCronTickerAsync(id, request, cancellationToken);
453-
return Results.Ok();
484+
// Read the raw JSON from request body
485+
using var reader = new StreamReader(context.Request.Body);
486+
var jsonString = await reader.ReadToEndAsync(cancellationToken);
487+
488+
// Use Dashboard-specific JSON options
489+
var cronTicker = JsonSerializer.Deserialize<TCronTicker>(jsonString, dashboardOptions.DashboardJsonOptions);
490+
491+
// Ensure the ID matches
492+
cronTicker.Id = id;
493+
494+
var result = await cronTickerManager.UpdateAsync(cronTicker, cancellationToken);
495+
496+
return Results.Ok(new {
497+
success = result.IsSucceeded,
498+
message = result.IsSucceeded ? "Cron ticker updated successfully" : "Failed to update cron ticker"
499+
});
454500
}
455501

456502
private static async Task<IResult> RunCronTickerOnDemand<TTimeTicker, TCronTicker>(
@@ -466,13 +512,17 @@ private static async Task<IResult> RunCronTickerOnDemand<TTimeTicker, TCronTicke
466512

467513
private static async Task<IResult> DeleteCronTicker<TTimeTicker, TCronTicker>(
468514
Guid id,
469-
ITickerDashboardRepository<TTimeTicker, TCronTicker> repository,
515+
ICronTickerManager<TCronTicker> cronTickerManager,
470516
CancellationToken cancellationToken)
471517
where TTimeTicker : TimeTickerEntity<TTimeTicker>, new()
472518
where TCronTicker : CronTickerEntity, new()
473519
{
474-
await repository.DeleteCronTickerByIdAsync(id, cancellationToken);
475-
return Results.Ok();
520+
var result = await cronTickerManager.DeleteAsync(id, cancellationToken);
521+
522+
return Results.Ok(new {
523+
success = result.IsSucceeded,
524+
message = result.IsSucceeded ? "Cron ticker deleted successfully" : "Failed to delete cron ticker"
525+
});
476526
}
477527

478528
private static async Task<IResult> DeleteCronTickerOccurrence<TTimeTicker, TCronTicker>(

0 commit comments

Comments
 (0)