PlotDirector/PlotLine/Controllers/WriterController.cs
2026-06-12 21:25:39 +01:00

65 lines
2.0 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using PlotLine.Services;
using PlotLine.ViewModels;
namespace PlotLine.Controllers;
[Authorize]
public sealed class WriterController(
IWriterWorkspaceService writerWorkspace,
IWritingScheduleService writingSchedule) : Controller
{
public async Task<IActionResult> Index(int? projectId)
{
var model = await writerWorkspace.GetDashboardAsync(projectId);
return View(model);
}
public async Task<IActionResult> Chapter(int id)
{
var model = await writerWorkspace.GetChapterWorkflowAsync(id);
return model is null ? NotFound() : View(model);
}
public async Task<IActionResult> SchedulePreview(int? writingPlanId)
{
var model = await writingSchedule.GetSchedulePreviewAsync(writingPlanId);
return View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> GenerateSchedule(int writingPlanId)
{
try
{
var items = await writingSchedule.GenerateSchedule(writingPlanId);
TempData["SchedulePreviewMessage"] = $"{items.Count} item{(items.Count == 1 ? "" : "s")} generated.";
}
catch (InvalidOperationException ex)
{
TempData["SchedulePreviewError"] = ex.Message;
}
return RedirectToAction(nameof(SchedulePreview), new { writingPlanId });
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteGeneratedSchedule(int writingPlanId)
{
await writingSchedule.DeleteScheduleAsync(writingPlanId);
TempData["SchedulePreviewMessage"] = "Generated schedule deleted.";
return RedirectToAction(nameof(SchedulePreview), new { writingPlanId });
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> SaveChapterGoal(ChapterGoalEditViewModel model)
{
await writerWorkspace.SaveChapterGoalAsync(model);
return RedirectToAction(nameof(Chapter), new { id = model.ChapterID });
}
}