using Domain.Entities.Forum.Boards; using SharedKernel.Extensions; using Application.Abstractions.Messaging; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; namespace Admin.Pages.Forum.Board.Meta; public class GeneralModel(IMediator mediator) : PageModel { public int BoardID { get; set; } public List<(int ID, string Name)> BoardList { get; set; } = []; public string? QueryString { get; set; } [BindProperty] public InputModel Input { get; set; } = new(); public sealed class InputModel { public int ID { get; set; } public int BoardID { get; set; } public bool AllowUpdateProtection { get; set; } public ushort UpdateProtectionDays { get; set; } public bool AllowDeleteProtection { get; set; } public ushort DeleteProtectionDays { get; set; } public bool EnableFileDownLog { get; set; } public bool EnableLinkClickLog { get; set; } public bool EnablePostUpdateLog { get; set; } } public async Task OnGetAsync(int id, CancellationToken ct) { BoardID = id; QueryString = Request.QueryString.ToString(); var boards = await mediator.Send(new SearchBoards.Query(null, null, 1, 100), ct); BoardList = [..boards.List.Select(c => (c.ID, c.Name))]; var metaResult = await mediator.Send(new GetBoardMeta.Query(id), ct); if (metaResult.IsFailure) { TempData["ErrorMessages"] = metaResult.Error.Description; return; } var meta = metaResult.Value; Input = new InputModel { ID = meta.ID, BoardID = meta.BoardID, AllowUpdateProtection = meta.General.AllowUpdateProtection, UpdateProtectionDays = meta.General.UpdateProtectionDays, AllowDeleteProtection = meta.General.AllowDeleteProtection, DeleteProtectionDays = meta.General.DeleteProtectionDays, EnableFileDownLog = meta.General.EnableFileDownLog, EnableLinkClickLog = meta.General.EnableLinkClickLog, EnablePostUpdateLog = meta.General.EnablePostUpdateLog }; } public async Task OnPostAsync(CancellationToken ct) { if (!ModelState.IsValid) { TempData["ErrorMessages"] = ModelState.GetErrorMessages(); return Redirect($"/Forum/Board/Meta/General/{Input.BoardID}{Request.QueryString}"); } var result = await mediator.Send(new UpdateBoardMeta.Command( Input.ID, Input.BoardID, null, null, null, null, new BoardMetaGeneral { AllowUpdateProtection = Input.AllowUpdateProtection, UpdateProtectionDays = Input.UpdateProtectionDays, AllowDeleteProtection = Input.AllowDeleteProtection, DeleteProtectionDays = Input.DeleteProtectionDays, EnableFileDownLog = Input.EnableFileDownLog, EnableLinkClickLog = Input.EnableLinkClickLog, EnablePostUpdateLog = Input.EnablePostUpdateLog }, null, null, null, null ), ct); if (result.IsFailure) { TempData["ErrorMessages"] = result.Error.Description; } else { TempData["SuccessMessage"] = "일반 설정이 저장되었습니다."; } return Redirect($"/Forum/Board/Meta/General/{Input.BoardID}{Request.QueryString}"); } }