refactor: fully integrate Browser Client into main Web server
TaxBaik CI/CD / build-and-deploy (push) Failing after 48s
TaxBaik CI/CD / build-and-deploy (push) Failing after 48s
BREAKING CHANGE: Removed TaxBaik.Web.Client project (separate WASM app) Changes: - Migrated all Blazor components to TaxBaik.Web/Components/Admin - Migrated all Browser Client services to Components/Admin/Services - Updated Program.cs to use integrated components (same assembly) - Removed AddAdditionalAssemblies (no longer needed) - Updated _Imports.razor with correct namespaces Architecture: ✅ API-First: REST endpoints in TaxBaik.Web (ASP.NET Core) ✅ Client-Side: Blazor WASM components in TaxBaik.Web/Components ✅ Unified: Both API and UI served from single web server ✅ No separation: No separate client project Result: - Single deploy unit (TaxBaik.Web) - API served only from web server - Blazor renders client-side (prerender: false for protected pages) - Monolithic web app architecture Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>백원숙 세무회계 - 관리자</title>
|
||||
<base href="/taxbaik/" />
|
||||
<link rel="icon" type="image/svg+xml" href="/taxbaik/favicon.svg" />
|
||||
<link rel="alternate icon" href="/taxbaik/favicon.ico" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;700&display=swap" rel="stylesheet" />
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />
|
||||
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
|
||||
<script>
|
||||
window.taxbaikAdminBuildVersion = 'unknown';
|
||||
window.taxbaikAdminComponent = 'AdminApp';
|
||||
document.documentElement.classList.toggle(
|
||||
'admin-login-route',
|
||||
window.location.pathname.toLowerCase().endsWith('/admin/login'));
|
||||
</script>
|
||||
<link rel="stylesheet" href="css/admin.css" />
|
||||
<component type="typeof(HeadOutlet)" render-mode="InteractiveWebAssembly" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="components-reconnect-modal" class="admin-reconnect-modal">
|
||||
<div class="admin-reconnect-card">
|
||||
<strong>연결 재설정 중...</strong>
|
||||
<span>새로운 버전으로 업데이트되었습니다.</span>
|
||||
<span style="font-size: 0.85rem; margin-top: 0.5rem; opacity: 0.8;">자동으로 페이지를 새로고침합니다. 잠시만 기다려주세요.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="blazor-loading" class="blazor-loading-overlay">
|
||||
<div class="blazor-loading-spinner">
|
||||
<div class="spinner"></div>
|
||||
<p>로드 중...</p>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
// 로그인 화면은 prerender로 즉시 표시되므로 스피너가 필요 없다.
|
||||
// 그 외 인증 화면은 WASM 부팅이 끝날 때까지(AdminShell.OnAfterRenderAsync에서 hideLoading 호출)
|
||||
// 스피너를 "업데이트 스플래시"로 보여준다.
|
||||
if (!document.documentElement.classList.contains('admin-login-route')) {
|
||||
var loadingOverlay = document.getElementById('blazor-loading');
|
||||
if (loadingOverlay) loadingOverlay.classList.add('show');
|
||||
}
|
||||
</script>
|
||||
<MudThemeProvider @bind-IsDarkMode="isDarkMode" Theme="mudTheme" />
|
||||
<Routes />
|
||||
<script src="/taxbaik/_content/MudBlazor/MudBlazor.min.js"></script>
|
||||
<script src="/taxbaik/js/admin-session.js"></script>
|
||||
<script src="/taxbaik/_framework/blazor.webassembly.js"></script>
|
||||
<script>
|
||||
// admin-session.js 로드 완료 대기 후 초기화
|
||||
function initSession() {
|
||||
if (window.taxbaikAdminSession) {
|
||||
if (typeof window.taxbaikAdminSession.initErrorLogging === 'function') {
|
||||
window.taxbaikAdminSession.initErrorLogging();
|
||||
}
|
||||
if (typeof window.taxbaikAdminSession.bindLoginForm === 'function') {
|
||||
window.taxbaikAdminSession.bindLoginForm();
|
||||
}
|
||||
if (typeof window.taxbaikAdminSession.watchReconnect === 'function') {
|
||||
window.taxbaikAdminSession.watchReconnect();
|
||||
}
|
||||
} else {
|
||||
// admin-session.js가 아직 로드되지 않았으면 재시도
|
||||
setTimeout(initSession, 50);
|
||||
}
|
||||
}
|
||||
initSession();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@code {
|
||||
private bool isDarkMode = false;
|
||||
private MudTheme mudTheme = new()
|
||||
{
|
||||
Palette = new PaletteLight()
|
||||
{
|
||||
Primary = "#1976D2",
|
||||
PrimaryContrastText = "#FFFFFF",
|
||||
Secondary = "#2D9F7E",
|
||||
SecondaryContrastText = "#FFFFFF",
|
||||
Tertiary = "#FF8A50",
|
||||
TertiaryContrastText = "#FFFFFF",
|
||||
Surface = "#F5F7FA",
|
||||
Background = "#FFFFFF",
|
||||
BackgroundGrey = "#F8F9FB",
|
||||
DrawerBackground = "#FFFFFF",
|
||||
DrawerText = "#424242",
|
||||
AppbarBackground = "#FFFFFF",
|
||||
AppbarText = "#424242",
|
||||
TextPrimary = "#1A1A1A",
|
||||
TextSecondary = "#64748B",
|
||||
TextDisabled = "#94A3B8",
|
||||
ActionDefault = "#1976D2",
|
||||
ActionDisabled = "#BDBDBD",
|
||||
Divider = "#E2E8F0",
|
||||
DividerLight = "#F1F5F9",
|
||||
Error = "#DC2626",
|
||||
ErrorContrastText = "#FFFFFF",
|
||||
Warning = "#F59E0B",
|
||||
WarningContrastText = "#FFFFFF",
|
||||
Info = "#06B6D4",
|
||||
InfoContrastText = "#FFFFFF",
|
||||
Success = "#16A34A",
|
||||
SuccessContrastText = "#FFFFFF",
|
||||
},
|
||||
LayoutProperties = new LayoutProperties()
|
||||
{
|
||||
DefaultBorderRadius = "6px"
|
||||
},
|
||||
Typography = new Typography()
|
||||
{
|
||||
Default = new Default()
|
||||
{
|
||||
FontSize = ".8125rem",
|
||||
FontWeight = 400,
|
||||
LineHeight = 1.5
|
||||
},
|
||||
H1 = new H1()
|
||||
{
|
||||
FontSize = "1.75rem",
|
||||
FontWeight = 600,
|
||||
LineHeight = 1.2
|
||||
},
|
||||
H2 = new H2()
|
||||
{
|
||||
FontSize = "1.5rem",
|
||||
FontWeight = 600,
|
||||
LineHeight = 1.3
|
||||
},
|
||||
H3 = new H3()
|
||||
{
|
||||
FontSize = "1.25rem",
|
||||
FontWeight = 600,
|
||||
LineHeight = 1.3
|
||||
},
|
||||
H4 = new H4()
|
||||
{
|
||||
FontSize = "1.1rem",
|
||||
FontWeight = 600,
|
||||
LineHeight = 1.4
|
||||
},
|
||||
H5 = new H5()
|
||||
{
|
||||
FontSize = "0.95rem",
|
||||
FontWeight = 500,
|
||||
LineHeight = 1.4
|
||||
},
|
||||
H6 = new H6()
|
||||
{
|
||||
FontSize = "0.85rem",
|
||||
FontWeight = 500,
|
||||
LineHeight = 1.5
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
@using MudBlazor
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudText>정말로 삭제하시겠습니까?</MudText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@Cancel">취소</MudButton>
|
||||
<MudButton Color="Color.Error" OnClick="@Confirm">삭제</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] MudDialogInstance? MudDialog { get; set; }
|
||||
|
||||
void Cancel() => MudDialog?.Cancel();
|
||||
void Confirm() => MudDialog?.Close(DialogResult.Ok(true));
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
@using TaxBaik.Application.Services
|
||||
|
||||
<MudForm @ref="form">
|
||||
<MudTextField @bind-Value="model.CompanyCode" Label="회사 코드"
|
||||
Variant="Variant.Outlined" Class="mb-4" Required="true"
|
||||
HelperText="영문/숫자, 최대 50자" />
|
||||
|
||||
<MudTextField @bind-Value="model.CompanyName" Label="회사명"
|
||||
Variant="Variant.Outlined" Class="mb-4" Required="true" />
|
||||
|
||||
<MudTextField @bind-Value="model.ContactPerson" Label="담당자명"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="model.Phone" Label="전화번호"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="model.Email" Label="이메일"
|
||||
Variant="Variant.Outlined" Class="mb-4" InputType="InputType.Email" />
|
||||
|
||||
<MudTextField @bind-Value="model.Memo" Label="메모"
|
||||
Variant="Variant.Outlined" Lines="3" Class="mb-4" />
|
||||
|
||||
<MudCheckBox @bind-Checked="model.IsActive" Label="활성" Class="mb-4" />
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" @onclick="HandleSubmit">
|
||||
@ButtonText
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" @onclick="OnCancel">취소</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public string ButtonText { get; set; } = "저장";
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<CompanyFormModel> OnSubmit { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnCancel { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public CompanyFormModel? InitialData { get; set; }
|
||||
|
||||
private MudForm? form;
|
||||
private CompanyFormModel model = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
if (InitialData != null)
|
||||
{
|
||||
model = new CompanyFormModel
|
||||
{
|
||||
CompanyCode = InitialData.CompanyCode,
|
||||
CompanyName = InitialData.CompanyName,
|
||||
ContactPerson = InitialData.ContactPerson,
|
||||
Phone = InitialData.Phone,
|
||||
Email = InitialData.Email,
|
||||
Memo = InitialData.Memo,
|
||||
IsActive = InitialData.IsActive
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleSubmit()
|
||||
{
|
||||
if (form == null)
|
||||
return;
|
||||
|
||||
await form.Validate();
|
||||
if (!form.IsValid)
|
||||
return;
|
||||
|
||||
await OnSubmit.InvokeAsync(model);
|
||||
}
|
||||
|
||||
public class CompanyFormModel
|
||||
{
|
||||
public string CompanyCode { get; set; } = "";
|
||||
public string CompanyName { get; set; } = "";
|
||||
public string? ContactPerson { get; set; }
|
||||
public string? Phone { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public string? Memo { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
@using TaxBaik.Application.DTOs
|
||||
@using TaxBaik.Application.Services
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
|
||||
<MudForm @ref="form">
|
||||
<AdminFormSection Title="연락처" Description="고객 식별과 기본 회신 정보입니다." CssClass="mb-4">
|
||||
<MudTextField @bind-Value="model.Name" Label="이름"
|
||||
Variant="Variant.Outlined" Class="mb-4" Required="true" ReadOnly="@IsEditMode" />
|
||||
|
||||
<MudTextField @bind-Value="model.Phone" Label="전화번호 (예: 010-1234-5678)"
|
||||
Variant="Variant.Outlined" Class="mb-4" Required="true" ReadOnly="@IsEditMode" />
|
||||
|
||||
<MudTextField @bind-Value="model.Email" Label="이메일"
|
||||
Variant="Variant.Outlined" Class="mb-4" InputType="InputType.Email" ReadOnly="@IsEditMode" />
|
||||
</AdminFormSection>
|
||||
|
||||
<AdminFormSection Title="문의 내용" Description="@(IsEditMode ? "상태와 메모만 변경 가능합니다." : "운영 분류와 처리 메모를 함께 관리합니다.")" CssClass="mb-4">
|
||||
<CommonCodeSelect @bind-Value="model.ServiceType" Group="INQUIRY_SERVICE_TYPE" Label="문의 유형 *" Class="mb-4" Required="true" Disabled="@IsEditMode" Placeholder="문의 유형을 선택하세요" />
|
||||
|
||||
<MudTextField @bind-Value="model.Message" Label="문의 내용"
|
||||
Variant="Variant.Outlined" Lines="5" Class="mb-4" Required="true" ReadOnly="@IsEditMode" />
|
||||
|
||||
<CommonCodeSelect @bind-Value="model.Status" Group="INQUIRY_STATUS" Label="상태" Class="mb-4" Clearable="true" Placeholder="상태를 선택하세요" />
|
||||
|
||||
<MudTextField @bind-Value="model.AdminMemo" Label="관리 메모"
|
||||
Variant="Variant.Outlined" Lines="3" Class="mb-4" />
|
||||
</AdminFormSection>
|
||||
|
||||
<AdminFormActions SubmitText="@ButtonText"
|
||||
LoadingText="저장 중..."
|
||||
CancelText="취소"
|
||||
SubmitIcon="@Icons.Material.Filled.Save"
|
||||
OnSubmit="@HandleSubmit"
|
||||
OnCancel="@OnCancel"
|
||||
IsSubmitting="false" />
|
||||
</MudForm>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public string ButtonText { get; set; } = "저장";
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<InquiryFormModel> OnSubmit { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnCancel { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public InquiryFormModel? InitialData { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsEditMode { get; set; } = false;
|
||||
|
||||
private MudForm? form;
|
||||
private InquiryFormModel model = new();
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (InitialData != null)
|
||||
{
|
||||
model = new InquiryFormModel
|
||||
{
|
||||
Name = InitialData.Name,
|
||||
Phone = InitialData.Phone,
|
||||
Email = InitialData.Email,
|
||||
ServiceType = InitialData.ServiceType,
|
||||
Message = InitialData.Message,
|
||||
Status = InitialData.Status,
|
||||
AdminMemo = InitialData.AdminMemo
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task HandleSubmit()
|
||||
{
|
||||
if (form == null)
|
||||
return;
|
||||
|
||||
await form.Validate();
|
||||
if (!form.IsValid)
|
||||
return;
|
||||
|
||||
await OnSubmit.InvokeAsync(model);
|
||||
}
|
||||
|
||||
public class InquiryFormModel
|
||||
{
|
||||
public string Name { get; set; } = "";
|
||||
public string Phone { get; set; } = "";
|
||||
public string? Email { get; set; }
|
||||
public string ServiceType { get; set; } = "기타";
|
||||
public string Message { get; set; } = "";
|
||||
public string Status { get; set; } = "new";
|
||||
public string? AdminMemo { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<MudSimpleTable Striped="true" Dense="true" Class="admin-table mt-4">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>이름</th>
|
||||
<th>전화</th>
|
||||
<th>분야</th>
|
||||
<th>상태</th>
|
||||
<th>메시지</th>
|
||||
<th>날짜</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var inquiry in filteredInquiries)
|
||||
{
|
||||
<tr>
|
||||
<td>@inquiry.Name</td>
|
||||
<td>@inquiry.Phone</td>
|
||||
<td>@inquiry.ServiceType</td>
|
||||
<td>
|
||||
<MudChip Size="Size.Small" Color="@GetStatusColor(inquiry.Status)">
|
||||
@GetStatusLabel(inquiry.Status)
|
||||
</MudChip>
|
||||
</td>
|
||||
<td>@GetPreview(inquiry.Message)</td>
|
||||
<td>@inquiry.CreatedAt.ToString("yyyy-MM-dd")</td>
|
||||
<td>
|
||||
<MudButton Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary"
|
||||
Href="@($"/taxbaik/admin/inquiries/{inquiry.Id}")">보기</MudButton>
|
||||
<MudButton Size="Size.Small" Variant="Variant.Outlined" Color="Color.Info"
|
||||
Href="@($"/taxbaik/admin/inquiries/{inquiry.Id}/edit")">수정</MudButton>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</MudSimpleTable>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public IReadOnlyList<Domain.Entities.Inquiry> Inquiries { get; set; } = [];
|
||||
|
||||
[Parameter]
|
||||
public string Status { get; set; } = "";
|
||||
|
||||
private IReadOnlyList<Domain.Entities.Inquiry> filteredInquiries = [];
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (Inquiries == null || Inquiries.Count == 0)
|
||||
{
|
||||
filteredInquiries = [];
|
||||
return;
|
||||
}
|
||||
|
||||
filteredInquiries = string.IsNullOrEmpty(Status)
|
||||
? Inquiries
|
||||
: Inquiries.Where(x => x.Status == Status).ToList();
|
||||
}
|
||||
|
||||
private static string GetPreview(string message)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
return "-";
|
||||
|
||||
var trimmed = message.Trim();
|
||||
return trimmed.Length <= 30 ? trimmed : $"{trimmed[..30]}...";
|
||||
}
|
||||
|
||||
private static Color GetStatusColor(string status) => status switch
|
||||
{
|
||||
"new" => Color.Warning,
|
||||
"consulting" => Color.Info,
|
||||
"contracted" => Color.Success,
|
||||
"rejected" => Color.Error,
|
||||
"closed" => Color.Dark,
|
||||
_ => Color.Default
|
||||
};
|
||||
|
||||
private static string GetStatusLabel(string status) => InquiryStatusMapper.Labels.GetValueOrDefault(status, status);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@Body
|
||||
@@ -0,0 +1,6 @@
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
<AdminShell>
|
||||
<AdminTelemetryContext />
|
||||
@Body
|
||||
</AdminShell>
|
||||
@@ -0,0 +1,11 @@
|
||||
@page "/admin"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
@code {
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
NavigationManager.NavigateTo("/taxbaik/admin/dashboard", replace: true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
@page "/admin/announcements/create"
|
||||
@page "/admin/announcements/{Id:int}/edit"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Application.DTOs
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject IAnnouncementBrowserClient AnnouncementClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>@(Id.HasValue ? "공지 수정" : "공지 등록")</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Homepage</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">@(Id.HasValue ? "공지 수정" : "공지 등록")</MudText>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<MudPaper Class="admin-surface" Elevation="0">
|
||||
<MudForm @ref="form">
|
||||
<MudGrid>
|
||||
<MudItem xs="12">
|
||||
<MudTextField @bind-Value="model.Title"
|
||||
Label="제목"
|
||||
Variant="Variant.Outlined"
|
||||
Required="true"
|
||||
RequiredError="제목을 입력하세요."
|
||||
HelperText="홈페이지 상단 공지 바에 표시되는 텍스트입니다." />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudTextField @bind-Value="model.Content"
|
||||
Label="상세 내용 (선택)"
|
||||
Variant="Variant.Outlined"
|
||||
Lines="3"
|
||||
HelperText="부가 설명이 있을 경우 입력합니다. 없으면 제목만 표시됩니다." />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<CommonCodeSelect @bind-Value="model.DisplayType"
|
||||
Group="ANNOUNCEMENT_DISPLAY_TYPE"
|
||||
Label="유형"
|
||||
Class="mb-0" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudNumericField @bind-Value="model.SortOrder"
|
||||
Label="노출 순서"
|
||||
Variant="Variant.Outlined"
|
||||
HelperText="숫자가 클수록 먼저 표시됩니다." />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudDatePicker @bind-Date="startsAtDate"
|
||||
Label="게시 시작일 (비우면 즉시)"
|
||||
Variant="Variant.Outlined"
|
||||
DateFormat="yyyy-MM-dd"
|
||||
Clearable="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudDatePicker @bind-Date="endsAtDate"
|
||||
Label="게시 종료일 (비우면 무기한)"
|
||||
Variant="Variant.Outlined"
|
||||
DateFormat="yyyy-MM-dd"
|
||||
Clearable="true" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12">
|
||||
<MudSwitch @bind-Checked="model.IsActive"
|
||||
Label="@(model.IsActive ? "활성화 (홈페이지에 노출)" : "비활성화 (홈페이지 미노출)")"
|
||||
Color="Color.Primary" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
<div class="d-flex gap-2 mt-4">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Save"
|
||||
Disabled="isSaving"
|
||||
@onclick="SaveAsync">
|
||||
@(isSaving ? "저장 중..." : "저장")
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
@onclick="@(() => Navigation.NavigateTo("/taxbaik/admin/announcements"))">
|
||||
취소
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter] public int? Id { get; set; }
|
||||
|
||||
private MudForm? form;
|
||||
private bool isSaving;
|
||||
private DateTime? startsAtDate;
|
||||
private DateTime? endsAtDate;
|
||||
|
||||
private AnnouncementDto model = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (Id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var entity = await AnnouncementClient.GetByIdAsync(Id.Value);
|
||||
if (entity is null)
|
||||
{
|
||||
Navigation.NavigateTo("/taxbaik/admin/announcements");
|
||||
return;
|
||||
}
|
||||
model = new AnnouncementDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
Title = entity.Title,
|
||||
Content = entity.Content,
|
||||
DisplayType = entity.DisplayType,
|
||||
IsActive = entity.IsActive,
|
||||
SortOrder = entity.SortOrder
|
||||
};
|
||||
startsAtDate = entity.StartsAt?.ToLocalTime();
|
||||
endsAtDate = entity.EndsAt?.ToLocalTime();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Navigation.NavigateTo("/taxbaik/admin/announcements");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
if (form is null) return;
|
||||
await form.Validate();
|
||||
if (!form.IsValid) return;
|
||||
|
||||
isSaving = true;
|
||||
try
|
||||
{
|
||||
model.StartsAt = startsAtDate.HasValue
|
||||
? DateTime.SpecifyKind(startsAtDate.Value.Date, DateTimeKind.Local).ToUniversalTime()
|
||||
: null;
|
||||
model.EndsAt = endsAtDate.HasValue
|
||||
? DateTime.SpecifyKind(endsAtDate.Value.Date.AddDays(1).AddSeconds(-1), DateTimeKind.Local).ToUniversalTime()
|
||||
: null;
|
||||
|
||||
if (Id.HasValue)
|
||||
{
|
||||
var result = await AnnouncementClient.UpdateAsync(Id.Value, model);
|
||||
if (result != null)
|
||||
Snackbar.Add("공지사항이 저장되었습니다.", Severity.Success);
|
||||
else
|
||||
Snackbar.Add("저장 실패", Severity.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await AnnouncementClient.CreateAsync(model);
|
||||
if (result != null)
|
||||
Snackbar.Add("공지사항이 저장되었습니다.", Severity.Success);
|
||||
else
|
||||
Snackbar.Add("저장 실패", Severity.Error);
|
||||
}
|
||||
Navigation.NavigateTo("/taxbaik/admin/announcements");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isSaving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
@page "/admin/announcements"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.Domain.Entities
|
||||
@inject IAnnouncementBrowserClient AnnouncementClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>공지사항 관리</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Homepage</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">공지사항 관리</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">홈페이지 상단에 노출되는 공지사항을 등록하고 관리합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Add"
|
||||
Href="/taxbaik/admin/announcements/create">
|
||||
공지 등록
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
<div class="d-flex pa-4 gap-4 align-center">
|
||||
<MudTextField @bind-Value="searchQuery" Placeholder="공지사항 제목 검색..." Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="flex-grow-1" Immediate="true" Clearable="true" />
|
||||
</div>
|
||||
|
||||
<AdminDataPanel Loading="@(announcements is null)" SkeletonContent="@AnnouncementSkeleton">
|
||||
@if (announcements is null)
|
||||
{
|
||||
}
|
||||
else if (!FilteredAnnouncements.Any())
|
||||
{
|
||||
<div class="pa-6 text-center">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Campaign" Style="font-size:3rem; opacity:.3;" />
|
||||
<MudText Class="mt-2 text-muted">검색 조건에 맞는 공지사항이 없습니다.</MudText>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudSimpleTable Striped="true" Dense="true" Class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>제목</th>
|
||||
<th>유형</th>
|
||||
<th>상태</th>
|
||||
<th>게시 기간</th>
|
||||
<th>순서</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in FilteredAnnouncements)
|
||||
{
|
||||
<tr>
|
||||
<td>@item.Title</td>
|
||||
<td>
|
||||
<MudChip Size="Size.Small" Color="@GetTypeColor(item.DisplayType)">
|
||||
@GetTypeLabel(item.DisplayType)
|
||||
</MudChip>
|
||||
</td>
|
||||
<td>
|
||||
@if (IsCurrentlyActive(item))
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Success">노출 중</MudChip>
|
||||
}
|
||||
else if (!item.IsActive)
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Default">비활성</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Warning">기간 외</MudChip>
|
||||
}
|
||||
</td>
|
||||
<td class="small">
|
||||
@FormatPeriod(item)
|
||||
</td>
|
||||
<td>@item.SortOrder</td>
|
||||
<td>
|
||||
<MudButtonGroup Size="Size.Small" Variant="Variant.Outlined">
|
||||
<MudButton @onclick="@(() => Navigation.NavigateTo($"/taxbaik/admin/announcements/{item.Id}/edit"))">
|
||||
수정
|
||||
</MudButton>
|
||||
<MudButton Color="Color.Error" @onclick="@(() => DeleteAsync(item))">
|
||||
삭제
|
||||
</MudButton>
|
||||
</MudButtonGroup>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</MudSimpleTable>
|
||||
<MudText Typo="Typo.caption" Class="pa-2 text-muted">
|
||||
검색 결과 @(FilteredAnnouncements.Count())개 · 총 @(announcements.Count)개
|
||||
</MudText>
|
||||
}
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private List<Announcement>? announcements;
|
||||
private string searchQuery = "";
|
||||
|
||||
private RenderFragment AnnouncementSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 5);
|
||||
builder.AddAttribute(2, "Columns", 4);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
private IEnumerable<Announcement> FilteredAnnouncements => announcements?
|
||||
.Where(a => string.IsNullOrEmpty(searchQuery) ||
|
||||
a.Title.Contains(searchQuery, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(a => a.SortOrder) ?? Enumerable.Empty<Announcement>();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
announcements = [];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
announcements = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
announcements = (await AnnouncementClient.GetAllAsync()).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
announcements = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteAsync(Announcement item)
|
||||
{
|
||||
var confirmed = await DialogService.ShowMessageBox(
|
||||
"공지 삭제",
|
||||
$"'{item.Title}' 공지를 삭제하시겠습니까?",
|
||||
yesText: "삭제", cancelText: "취소");
|
||||
|
||||
if (confirmed != true) return;
|
||||
|
||||
try
|
||||
{
|
||||
var success = await AnnouncementClient.DeleteAsync(item.Id);
|
||||
if (success)
|
||||
{
|
||||
Snackbar.Add("공지사항이 삭제되었습니다.", Severity.Success);
|
||||
await LoadAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("삭제 실패", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsCurrentlyActive(Announcement a)
|
||||
{
|
||||
if (!a.IsActive) return false;
|
||||
var now = DateTime.UtcNow;
|
||||
if (a.StartsAt.HasValue && a.StartsAt > now) return false;
|
||||
if (a.EndsAt.HasValue && a.EndsAt < now) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string FormatPeriod(Announcement a)
|
||||
{
|
||||
var start = a.StartsAt?.ToLocalTime().ToString("MM/dd") ?? "즉시";
|
||||
var end = a.EndsAt?.ToLocalTime().ToString("MM/dd") ?? "무기한";
|
||||
return $"{start} ~ {end}";
|
||||
}
|
||||
|
||||
private static Color GetTypeColor(string type) => type switch
|
||||
{
|
||||
"urgent" => Color.Error,
|
||||
"banner" => Color.Warning,
|
||||
_ => Color.Info
|
||||
};
|
||||
|
||||
private static string GetTypeLabel(string type) => type switch
|
||||
{
|
||||
"urgent" => "긴급",
|
||||
"banner" => "배너",
|
||||
_ => "일반"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
@page "/admin/blog/create"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Application.DTOs
|
||||
@using TaxBaik.WasmClient.Components.Admin.Pages.Blog
|
||||
@inject IBlogBrowserClient BlogClient
|
||||
@inject ICategoryBrowserClient CategoryClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>새 포스트 작성</PageTitle>
|
||||
|
||||
<AdminCrudPageShell Title="새 포스트 작성"
|
||||
Eyebrow="Content"
|
||||
Subtitle="새로운 블로그 포스트를 작성합니다."
|
||||
Loading="@false"
|
||||
OnCancel="@GoBack">
|
||||
<MudPaper Class="pa-4 mt-4" Elevation="1">
|
||||
<BlogForm Model="model" Categories="categories" SubmitText="저장" OnSubmit="SavePost" OnCancel="GoBack" />
|
||||
</MudPaper>
|
||||
</AdminCrudPageShell>
|
||||
|
||||
@code {
|
||||
private IReadOnlyList<Domain.Entities.Category> categories = [];
|
||||
private BlogForm.BlogFormModel model = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
categories = await CategoryClient.GetAllAsync();
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
{
|
||||
Navigation.NavigateTo("/taxbaik/admin/blog");
|
||||
}
|
||||
|
||||
private async Task SavePost()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await BlogClient.CreateAsync(new CreateBlogPostDto
|
||||
{
|
||||
Title = model.Title,
|
||||
Content = model.Content,
|
||||
CategoryId = model.CategoryId,
|
||||
Tags = model.Tags,
|
||||
SeoTitle = model.SeoTitle,
|
||||
SeoDescription = model.SeoDescription,
|
||||
IsPublished = model.IsPublished
|
||||
});
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("포스트 저장에 실패했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("포스트가 저장되었습니다.", Severity.Success);
|
||||
Navigation.NavigateTo("/taxbaik/admin/blog");
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
Snackbar.Add(ex.Message, Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
@page "/admin/blog/{id:int}/edit"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Application.DTOs
|
||||
@using TaxBaik.WasmClient.Components.Admin.Pages.Blog
|
||||
@inject IBlogBrowserClient BlogClient
|
||||
@inject ICategoryBrowserClient CategoryClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
|
||||
<PageTitle>포스트 수정</PageTitle>
|
||||
|
||||
<AdminCrudPageShell Title="포스트 수정"
|
||||
Eyebrow="Content"
|
||||
Subtitle="블로그 포스트를 수정합니다."
|
||||
Loading="@isLoading"
|
||||
SkeletonContent="@EditorSkeleton"
|
||||
OnCancel="@GoBack">
|
||||
@if (post == null)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mt-4">포스트를 찾을 수 없습니다.</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudPaper Class="pa-4 mt-4" Elevation="1">
|
||||
<BlogForm Model="model" Categories="categories" SubmitText="저장" OnSubmit="SavePost" />
|
||||
<div class="mt-4">
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" @onclick="DeletePost">삭제</MudButton>
|
||||
</div>
|
||||
</MudPaper>
|
||||
}
|
||||
</AdminCrudPageShell>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
private TaxBaik.Application.DTOs.BlogPostResponseDto? post;
|
||||
private IReadOnlyList<Domain.Entities.Category> categories = [];
|
||||
private BlogForm.BlogFormModel model = new();
|
||||
private bool isLoading = true;
|
||||
|
||||
private RenderFragment EditorSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 5);
|
||||
builder.AddAttribute(2, "Columns", 3);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
post = await BlogClient.GetByIdAsync(Id);
|
||||
if (post != null)
|
||||
{
|
||||
categories = await CategoryClient.GetAllAsync();
|
||||
MapPostToModel(post);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"포스트 로드 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void MapPostToModel(TaxBaik.Application.DTOs.BlogPostResponseDto post)
|
||||
{
|
||||
model.Title = post.Title;
|
||||
model.Content = post.Content;
|
||||
model.CategoryId = post.CategoryId;
|
||||
model.Tags = post.Tags;
|
||||
model.SeoTitle = post.SeoTitle;
|
||||
model.SeoDescription = post.SeoDescription;
|
||||
model.IsPublished = post.IsPublished;
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
{
|
||||
Navigation.NavigateTo("/taxbaik/admin/blog");
|
||||
}
|
||||
|
||||
private async Task SavePost()
|
||||
{
|
||||
if (post == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var result = await BlogClient.UpdateAsync(post.Id, new CreateBlogPostDto
|
||||
{
|
||||
Title = model.Title,
|
||||
Content = model.Content,
|
||||
CategoryId = model.CategoryId,
|
||||
Tags = model.Tags,
|
||||
SeoTitle = model.SeoTitle,
|
||||
SeoDescription = model.SeoDescription,
|
||||
IsPublished = model.IsPublished
|
||||
});
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("저장 실패: 포스트를 저장하지 못했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("포스트가 저장되었습니다.", Severity.Success);
|
||||
Navigation.NavigateTo("/taxbaik/admin/blog");
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
Snackbar.Add(ex.Message, Severity.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeletePost()
|
||||
{
|
||||
if (post == null)
|
||||
return;
|
||||
|
||||
var result = await DialogService.ShowMessageBox(
|
||||
"포스트 삭제",
|
||||
"정말 삭제하시겠습니까? 이 작업은 취소할 수 없습니다.",
|
||||
"삭제", "취소");
|
||||
|
||||
if (result != true)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var deleted = await BlogClient.DeleteAsync(post.Id);
|
||||
if (!deleted)
|
||||
{
|
||||
Snackbar.Add("삭제 실패: 포스트를 삭제하지 못했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
Snackbar.Add("포스트가 삭제되었습니다.", Severity.Success);
|
||||
Navigation.NavigateTo("/taxbaik/admin/blog");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
@using TaxBaik.Application.DTOs
|
||||
@using TaxBaik.Domain.Entities
|
||||
|
||||
<MudForm @ref="form">
|
||||
<AdminFormSection Title="기본 정보" Description="제목과 카테고리, 발행 여부를 먼저 설정합니다." CssClass="mb-4">
|
||||
<MudTextField @bind-Value="Model.Title" Label="제목 *"
|
||||
Variant="Variant.Outlined" Class="mb-4" Required="true" RequiredError="제목을 입력하세요." Counter="100" MaxLength="100" />
|
||||
|
||||
<MudSelect T="int?" @bind-Value="Model.CategoryId" Label="카테고리 (선택 사항)"
|
||||
Variant="Variant.Outlined" Class="mb-4" Clearable="true">
|
||||
<MudSelectItem Value="@((int?)null)">분류 없음</MudSelectItem>
|
||||
@foreach (var category in Categories)
|
||||
{
|
||||
<MudSelectItem T="int?" Value="@((int?)category.Id)">@category.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudCheckBox @bind-Checked="Model.IsPublished" Label="즉시 발행" Class="mb-4" />
|
||||
</AdminFormSection>
|
||||
|
||||
<AdminFormSection Title="본문" Description="SEO와 실제 노출 본문을 함께 관리합니다." CssClass="mb-4">
|
||||
<MudTextField @bind-Value="Model.Content" Label="본문 내용 *"
|
||||
Variant="Variant.Outlined" Lines="16" Required="true" RequiredError="본문 내용을 입력하세요."
|
||||
Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="Model.Tags" Label="태그 (쉼표로 구분)"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="Model.SeoTitle" Label="SEO 제목"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="Model.SeoDescription" Label="SEO 설명"
|
||||
Variant="Variant.Outlined" Lines="3" Class="mb-4" />
|
||||
</AdminFormSection>
|
||||
|
||||
<AdminFormActions SubmitText="@SubmitText"
|
||||
LoadingText="저장 중..."
|
||||
CancelText="취소"
|
||||
SubmitIcon="@Icons.Material.Filled.Save"
|
||||
OnSubmit="@HandleSubmit"
|
||||
OnCancel="@OnCancel"
|
||||
IsSubmitting="false" />
|
||||
</MudForm>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public BlogFormModel Model { get; set; } = new();
|
||||
|
||||
[Parameter]
|
||||
public IReadOnlyList<Category> Categories { get; set; } = [];
|
||||
|
||||
[Parameter]
|
||||
public string SubmitText { get; set; } = "저장";
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnSubmit { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnCancel { get; set; }
|
||||
|
||||
private MudForm? form;
|
||||
|
||||
private async Task HandleSubmit()
|
||||
{
|
||||
if (form == null)
|
||||
return;
|
||||
|
||||
await form.Validate();
|
||||
if (!form.IsValid)
|
||||
return;
|
||||
|
||||
await OnSubmit.InvokeAsync();
|
||||
}
|
||||
|
||||
public class BlogFormModel
|
||||
{
|
||||
public string Title { get; set; } = "";
|
||||
public string Content { get; set; } = "";
|
||||
public int? CategoryId { get; set; }
|
||||
public string? Tags { get; set; }
|
||||
public string? SeoTitle { get; set; }
|
||||
public string? SeoDescription { get; set; }
|
||||
public bool IsPublished { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
@page "/admin/blog"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@inject IBlogBrowserClient BlogClient
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>블로그 관리</PageTitle>
|
||||
|
||||
<AdminPageHeader Title="블로그 관리" Eyebrow="Content" Subtitle="검색 유입 콘텐츠의 발행 상태와 성과를 관리합니다.">
|
||||
<ChildContent>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" StartIcon="@Icons.Material.Filled.Restore"
|
||||
OnClick="ToggleArchiveView">
|
||||
@(showArchived ? "전체 글 보기" : "숨김 글 보기")
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" StartIcon="@Icons.Material.Filled.Refresh"
|
||||
OnClick="Reload">
|
||||
새로고침
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.EditNote"
|
||||
Href="/taxbaik/admin/blog/create">새 포스트 작성</MudButton>
|
||||
</ChildContent>
|
||||
</AdminPageHeader>
|
||||
|
||||
<div class="d-flex pa-4 gap-4 align-center">
|
||||
<MudTextField @bind-Value="searchQuery" Placeholder="블로그 제목 또는 본문 검색..." Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="flex-grow-1" Immediate="true" Clearable="true" />
|
||||
</div>
|
||||
|
||||
<AdminDataPanel Loading="@isLoading">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween" Class="mb-3">
|
||||
<MudText Typo="Typo.subtitle1">@($"검색 결과 {FilteredPosts.Count()}개 / 전체 포스트 {totalPosts}개")</MudText>
|
||||
<MudText Typo="Typo.body2">페이지 @currentPage / @totalPages</MudText>
|
||||
</MudStack>
|
||||
|
||||
<MudDataGrid Items="@FilteredPosts" Striped="true" Hoverable="true" Class="admin-grid">
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.Title" Title="제목" />
|
||||
<PropertyColumn Property="x => x.IsPublished" Title="발행">
|
||||
<CellTemplate Context="cell">
|
||||
<MudCheckBox T="bool" Value="@cell.Item.IsPublished"
|
||||
ValueChanged="@(async (bool value) => await TogglePublish(cell.Item, value))" />
|
||||
</CellTemplate>
|
||||
</PropertyColumn>
|
||||
<PropertyColumn Property="x => x.ViewCount" Title="조회수" />
|
||||
<PropertyColumn Property="x => x.CreatedAt" Title="작성일" Format="yyyy-MM-dd" />
|
||||
<TemplateColumn>
|
||||
<CellTemplate Context="cell">
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Primary"
|
||||
Href="@($"/taxbaik/admin/blog/{cell.Item.Id}/edit")">수정하기</MudButton>
|
||||
@if (showArchived)
|
||||
{
|
||||
<MudButton Variant="Variant.Text" Size="Size.Small" Color="Color.Success"
|
||||
@onclick="@(async () => await RestorePost(cell.Item.Id))">복원</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Text" Size="Size.Small" Color="Color.Error"
|
||||
@onclick="@(async () => await DeletePost(cell.Item.Id))">삭제</MudButton>
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
|
||||
<MudStack Row="true" Justify="Justify.Center" Class="mt-4" Spacing="2">
|
||||
<MudButton Variant="Variant.Outlined" Disabled="@(currentPage <= 1 || isLoading)" @onclick="PreviousPage">이전</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Disabled="@(currentPage >= totalPages || isLoading)" @onclick="NextPage">다음</MudButton>
|
||||
</MudStack>
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private List<TaxBaik.Application.DTOs.BlogPostResponseDto> posts = [];
|
||||
private string searchQuery = "";
|
||||
private bool isLoading = true;
|
||||
private int currentPage = 1;
|
||||
private int totalPages = 1;
|
||||
private int totalPosts = 0;
|
||||
private bool showArchived;
|
||||
private const int PageSize = 20;
|
||||
|
||||
private IEnumerable<TaxBaik.Application.DTOs.BlogPostResponseDto> FilteredPosts => posts
|
||||
.Where(p => string.IsNullOrEmpty(searchQuery) ||
|
||||
p.Title.Contains(searchQuery, StringComparison.OrdinalIgnoreCase) ||
|
||||
(p.Content != null && p.Content.Contains(searchQuery, StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadPosts();
|
||||
}
|
||||
else
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadPosts()
|
||||
{
|
||||
isLoading = true;
|
||||
try
|
||||
{
|
||||
var result = showArchived
|
||||
? await BlogClient.GetArchivedPagedAsync(currentPage, PageSize)
|
||||
: await BlogClient.GetAdminPagedAsync(currentPage, PageSize);
|
||||
posts = result.Items.ToList();
|
||||
totalPosts = result.Total;
|
||||
totalPages = Math.Max(1, (int)Math.Ceiling(totalPosts / (double)PageSize));
|
||||
}
|
||||
catch
|
||||
{
|
||||
posts = [];
|
||||
totalPosts = 0;
|
||||
totalPages = 1;
|
||||
}
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private async Task PreviousPage()
|
||||
{
|
||||
if (currentPage <= 1)
|
||||
return;
|
||||
|
||||
currentPage--;
|
||||
await LoadPosts();
|
||||
}
|
||||
|
||||
private async Task NextPage()
|
||||
{
|
||||
if (currentPage >= totalPages)
|
||||
return;
|
||||
|
||||
currentPage++;
|
||||
await LoadPosts();
|
||||
}
|
||||
|
||||
private async Task TogglePublish(TaxBaik.Application.DTOs.BlogPostResponseDto post, bool isPublished)
|
||||
{
|
||||
var previous = post.IsPublished;
|
||||
post.IsPublished = isPublished;
|
||||
var result = await BlogClient.UpdateAsync(post.Id, new TaxBaik.Application.DTOs.CreateBlogPostDto
|
||||
{
|
||||
Title = post.Title,
|
||||
Content = post.Content,
|
||||
CategoryId = post.CategoryId,
|
||||
Tags = post.Tags,
|
||||
SeoTitle = post.SeoTitle,
|
||||
SeoDescription = post.SeoDescription,
|
||||
ThumbnailUrl = post.ThumbnailUrl,
|
||||
IsPublished = isPublished,
|
||||
AuthorId = post.AuthorId
|
||||
});
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
post.IsPublished = previous;
|
||||
Snackbar.Add("발행 상태 변경에 실패했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("발행 상태가 변경되었습니다.", Severity.Success);
|
||||
}
|
||||
|
||||
private async Task DeletePost(int postId)
|
||||
{
|
||||
var deleted = await BlogClient.DeleteAsync(postId);
|
||||
if (!deleted)
|
||||
{
|
||||
Snackbar.Add("포스트 삭제에 실패했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
Snackbar.Add("포스트가 삭제되었습니다.", Severity.Success);
|
||||
await LoadPosts();
|
||||
}
|
||||
|
||||
private async Task RestorePost(int postId)
|
||||
{
|
||||
var restored = await BlogClient.RestoreAsync(postId);
|
||||
if (!restored)
|
||||
{
|
||||
Snackbar.Add("포스트 복원에 실패했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("포스트가 복원되었습니다.", Severity.Success);
|
||||
await LoadPosts();
|
||||
}
|
||||
|
||||
private async Task ToggleArchiveView()
|
||||
{
|
||||
showArchived = !showArchived;
|
||||
currentPage = 1;
|
||||
await LoadPosts();
|
||||
}
|
||||
|
||||
private async Task Reload() => await LoadPosts();
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
@page "/admin/clients/{ClientId:int}"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.Web.Services.AdminClients
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject IClientBrowserClient ClientClient
|
||||
@inject IConsultingActivityBrowserClient ConsultingClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>고객 상세</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Client Details</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">고객 상세</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">고객 정보와 상담 이력을 관리합니다.</MudText>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@if (client == null)
|
||||
{
|
||||
<MudText>고객을 찾을 수 없습니다.</MudText>
|
||||
return;
|
||||
}
|
||||
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Class="mb-4" Spacing="2">
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack"
|
||||
@onclick="@(() => Navigation.NavigateTo("/taxbaik/admin/clients"))">
|
||||
목록으로
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Warning"
|
||||
StartIcon="@Icons.Material.Filled.Edit"
|
||||
Href="@($"/taxbaik/admin/clients/{ClientId}/edit")">
|
||||
수정
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="5">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" Class="mb-3">고객 정보</MudText>
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">이름</MudText>
|
||||
<MudText>@client.Name</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">상호</MudText>
|
||||
<MudText>@(client.CompanyName ?? "-")</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">연락처</MudText>
|
||||
<MudText>@(client.Phone ?? "-")</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">이메일</MudText>
|
||||
<MudText>@(client.Email ?? "-")</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">서비스</MudText>
|
||||
<MudText>@(client.ServiceType ?? "-")</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">사업자 유형</MudText>
|
||||
<MudText>@(client.TaxType ?? "-")</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">유입 경로</MudText>
|
||||
<MudText>@(client.Source ?? "-")</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">등록일</MudText>
|
||||
<MudText>@client.CreatedAt.ToLocalTime().ToString("yyyy-MM-dd")</MudText>
|
||||
</MudItem>
|
||||
@if (!string.IsNullOrWhiteSpace(client.Memo))
|
||||
{
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">메모</MudText>
|
||||
<MudText Style="white-space: pre-wrap;">@client.Memo</MudText>
|
||||
</MudItem>
|
||||
}
|
||||
</MudGrid>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" md="7">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween" Class="mb-3">
|
||||
<MudText Typo="Typo.h6">상담 이력</MudText>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
Size="Size.Small"
|
||||
OnClick="OpenAddConsultation">
|
||||
+ 상담 추가
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
@if (showAddForm)
|
||||
{
|
||||
<MudPaper Class="pa-3 mb-3" Outlined="true">
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudDatePicker @bind-Date="newDate" Label="상담일" DateFormat="yyyy-MM-dd" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<CommonCodeSelect @bind-Value="newServiceType" Group="CONSULTING_ACTIVITY_TYPE" Label="서비스 분야" Placeholder="선택" Clearable="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudTextField T="string" @bind-Value="newSummary" Label="상담 내용 *"
|
||||
Lines="3" Variant="Variant.Outlined" Required="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudSelect T="string" @bind-Value="newResult" Label="결과">
|
||||
<MudSelectItem Value="@("")">-</MudSelectItem>
|
||||
@foreach (var r in results)
|
||||
{
|
||||
<MudSelectItem Value="@r">@r</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudNumericField T="decimal?" @bind-Value="newFee" Label="수임료 (원)"
|
||||
Format="N0" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
<MudStack Row="true" Class="mt-2" Spacing="2">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="AddConsultation">저장</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" OnClick="@(() => showAddForm = false)">취소</MudButton>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
}
|
||||
|
||||
@if (consultations.Count == 0)
|
||||
{
|
||||
<MudText Color="Color.Secondary">상담 이력이 없습니다.</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudList T="string" Dense="true">
|
||||
@foreach (var c in consultations)
|
||||
{
|
||||
<MudListItem>
|
||||
<MudPaper Class="pa-3" Outlined="true" Style="width:100%">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Start" Justify="Justify.SpaceBetween">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary">
|
||||
@c.ConsultationDate.ToString("yyyy-MM-dd")
|
||||
@if (!string.IsNullOrEmpty(c.ServiceType)) { <text> · @c.ServiceType</text> }
|
||||
</MudText>
|
||||
<MudText Style="white-space: pre-wrap;" Class="mt-1">@c.Summary</MudText>
|
||||
@if (!string.IsNullOrEmpty(c.Result))
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Info" Class="mt-1">@c.Result</MudChip>
|
||||
}
|
||||
@if (c.Fee.HasValue)
|
||||
{
|
||||
<MudText Typo="Typo.caption" Color="Color.Secondary" Class="mt-1">
|
||||
수임료: @c.Fee.Value.ToString("N0")원
|
||||
</MudText>
|
||||
}
|
||||
</div>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||
Size="Size.Small" Color="Color.Error"
|
||||
OnClick="@(() => DeleteConsultation(c.Id))" />
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
</MudListItem>
|
||||
}
|
||||
</MudList>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public int ClientId { get; set; }
|
||||
|
||||
private Domain.Entities.Client? client;
|
||||
private List<Domain.Entities.Consultation> consultations = [];
|
||||
private static readonly string[] results = ["", "상담완료", "추가자료 요청", "견적발송", "계약전환", "보류"];
|
||||
|
||||
private bool showAddForm;
|
||||
private DateTime? newDate = DateTime.Today;
|
||||
private string newServiceType = "";
|
||||
private string newSummary = "";
|
||||
private string newResult = "";
|
||||
private decimal? newFee;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadAll();
|
||||
}
|
||||
|
||||
private async Task LoadAll()
|
||||
{
|
||||
client = await ClientClient.GetByIdAsync(ClientId);
|
||||
consultations = (await ConsultingClient.GetByClientIdAsync(ClientId))
|
||||
.Select(c => new Domain.Entities.Consultation
|
||||
{
|
||||
Id = c.Id,
|
||||
ClientId = c.ClientId,
|
||||
ConsultationDate = c.ActivityDate,
|
||||
ServiceType = c.ActivityType,
|
||||
Summary = c.Description,
|
||||
Result = null,
|
||||
Fee = null
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private void OpenAddConsultation()
|
||||
{
|
||||
showAddForm = true;
|
||||
newDate = DateTime.Today;
|
||||
newServiceType = "";
|
||||
newSummary = "";
|
||||
newResult = "";
|
||||
newFee = null;
|
||||
}
|
||||
|
||||
private async Task AddConsultation()
|
||||
{
|
||||
try
|
||||
{
|
||||
var newId = await ConsultingClient.CreateAsync(
|
||||
ClientId,
|
||||
string.IsNullOrWhiteSpace(newServiceType) ? "기타" : newServiceType,
|
||||
newDate?.ToUniversalTime() ?? DateTime.UtcNow,
|
||||
newSummary,
|
||||
null,
|
||||
null);
|
||||
|
||||
if (newId <= 0)
|
||||
throw new Exception("상담 생성 실패");
|
||||
|
||||
showAddForm = false;
|
||||
await LoadAll();
|
||||
Snackbar.Add("상담이 추가되었습니다.", Severity.Success);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
Snackbar.Add(ex.Message, Severity.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add(ex.Message, Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteConsultation(int id)
|
||||
{
|
||||
await ConsultingClient.DeleteAsync(id);
|
||||
await LoadAll();
|
||||
Snackbar.Add("삭제되었습니다.", Severity.Info);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
@page "/admin/clients/create"
|
||||
@page "/admin/clients/{Id:int}/edit"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Application.DTOs
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.Domain.Entities
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject IClientBrowserClient ClientClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>@(Id.HasValue ? "고객 수정" : "고객 등록")</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">CRM</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">@(Id.HasValue ? "고객 수정" : "고객 등록")</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Outlined" Href="/taxbaik/admin/clients"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack">목록으로</MudButton>
|
||||
</section>
|
||||
|
||||
<AdminEditorPanel Loading="@isLoading" SkeletonContent="@ClientEditSkeleton">
|
||||
@if (isLoading)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudForm @ref="form" @bind-IsValid="isValid">
|
||||
<MudGrid Spacing="3">
|
||||
@* 기본 정보 *@
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle1" Class="fw-bold mb-1">기본 정보</MudText>
|
||||
<MudDivider />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<MudTextField @bind-Value="dto.Name" Label="고객명 *" Required="true"
|
||||
RequiredError="고객명을 입력하세요." />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<MudTextField @bind-Value="dto.CompanyName" Label="회사명 (선택)" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<MudTextField @bind-Value="dto.Phone" Label="연락처"
|
||||
Placeholder="010-0000-0000" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<MudTextField @bind-Value="dto.Email" Label="이메일" InputType="InputType.Email" />
|
||||
</MudItem>
|
||||
|
||||
@* 세무 정보 *@
|
||||
<MudItem xs="12" Class="mt-2">
|
||||
<MudText Typo="Typo.subtitle1" Class="fw-bold mb-1">세무 정보</MudText>
|
||||
<MudDivider />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<CommonCodeSelect @bind-Value="dto.ServiceType" Group="CLIENT_SERVICE_TYPE" Label="서비스 유형" Clearable="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<CommonCodeSelect @bind-Value="dto.TaxType" Group="CLIENT_TAX_TYPE" Label="세금 유형" Clearable="true" />
|
||||
</MudItem>
|
||||
|
||||
@* 관리 정보 *@
|
||||
<MudItem xs="12" Class="mt-2">
|
||||
<MudText Typo="Typo.subtitle1" Class="fw-bold mb-1">관리 정보</MudText>
|
||||
<MudDivider />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<CommonCodeSelect @bind-Value="dto.Status" Group="CLIENT_STATUS" Label="상태 *" Required="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<CommonCodeSelect @bind-Value="dto.Source" Group="CLIENT_SOURCE" Label="유입 경로" Clearable="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudTextField @bind-Value="dto.Memo" Label="메모"
|
||||
Lines="4" AutoGrow="true"
|
||||
Placeholder="상담 배경, 특이사항, 중요 날짜 등 자유롭게 기록하세요" />
|
||||
</MudItem>
|
||||
|
||||
@* 저장 버튼 *@
|
||||
<MudItem xs="12" Class="d-flex gap-2 mt-2">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Save"
|
||||
OnClick="@SaveAsync" Disabled="@isSaving">
|
||||
@(isSaving ? "저장 중..." : "저장")
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Href="/taxbaik/admin/clients">
|
||||
취소
|
||||
</MudButton>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudForm>
|
||||
}
|
||||
</AdminEditorPanel>
|
||||
|
||||
@code {
|
||||
[Parameter] public int? Id { get; set; }
|
||||
|
||||
private MudForm form = null!;
|
||||
private CreateClientDto dto = new() { Status = "active" };
|
||||
private bool isValid;
|
||||
private bool isLoading = true;
|
||||
private bool isSaving;
|
||||
|
||||
private RenderFragment ClientEditSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 6);
|
||||
builder.AddAttribute(2, "Columns", 3);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (Id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = await ClientClient.GetByIdAsync(Id.Value);
|
||||
if (client is null)
|
||||
{
|
||||
Snackbar.Add("고객을 찾을 수 없습니다.", Severity.Error);
|
||||
Navigation.NavigateTo("/taxbaik/admin/clients");
|
||||
return;
|
||||
}
|
||||
dto = new CreateClientDto
|
||||
{
|
||||
Name = client.Name,
|
||||
CompanyName = client.CompanyName,
|
||||
Phone = client.Phone,
|
||||
Email = client.Email,
|
||||
ServiceType = client.ServiceType,
|
||||
TaxType = client.TaxType,
|
||||
Status = client.Status,
|
||||
Source = client.Source,
|
||||
Memo = client.Memo
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
Navigation.NavigateTo("/taxbaik/admin/clients");
|
||||
return;
|
||||
}
|
||||
}
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
await form.Validate();
|
||||
if (!isValid) return;
|
||||
|
||||
isSaving = true;
|
||||
try
|
||||
{
|
||||
if (Id.HasValue)
|
||||
{
|
||||
var result = await ClientClient.UpdateAsync(Id.Value, dto);
|
||||
if (result != null)
|
||||
Snackbar.Add("고객 정보가 수정되었습니다.", Severity.Success);
|
||||
else
|
||||
Snackbar.Add("수정에 실패했습니다.", Severity.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await ClientClient.CreateAsync(dto);
|
||||
if (result != null)
|
||||
Snackbar.Add("고객이 등록되었습니다.", Severity.Success);
|
||||
else
|
||||
Snackbar.Add("등록에 실패했습니다.", Severity.Error);
|
||||
}
|
||||
Navigation.NavigateTo("/taxbaik/admin/clients");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isSaving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
@page "/admin/clients"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.Domain.Entities
|
||||
@inject IClientBrowserClient ClientClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>고객 관리</PageTitle>
|
||||
|
||||
<AdminPageHeader Title="고객 관리" Eyebrow="CRM" Subtitle="고객 카드를 등록하고 상담 이력을 관리합니다.">
|
||||
<ChildContent>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.PersonAdd"
|
||||
Href="/taxbaik/admin/clients/create">
|
||||
고객 등록
|
||||
</MudButton>
|
||||
</ChildContent>
|
||||
</AdminPageHeader>
|
||||
|
||||
@* 검색/필터 바 *@
|
||||
<MudPaper Class="admin-surface mb-3 pa-3" Elevation="0">
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="5">
|
||||
<MudTextField @bind-Value="searchText" Label="검색 (이름·연락처·회사명)"
|
||||
Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
Immediate="false" OnKeyUp="@OnSearchKeyUp" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="3">
|
||||
<CommonCodeSelect @bind-Value="statusFilter" Group="CLIENT_STATUS" Label="상태" Placeholder="전체" Clearable="true" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="2" Class="d-flex align-center">
|
||||
<MudButton Variant="Variant.Outlined" OnClick="@SearchAsync" FullWidth="true">검색</MudButton>
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="2" Class="d-flex align-center">
|
||||
<MudButton Variant="Variant.Text" OnClick="@ResetAsync" FullWidth="true">초기화</MudButton>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudPaper>
|
||||
|
||||
<AdminDataPanel Loading="@(clients is null)" SkeletonContent="@ClientListSkeleton">
|
||||
@if (clients is null)
|
||||
{
|
||||
}
|
||||
else if (!clients.Any())
|
||||
{
|
||||
<AdminEmptyState Icon="@Icons.Material.Filled.PeopleAlt" Message="등록된 고객이 없습니다." />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudSimpleTable Striped="true" Dense="true" Class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>이름</th>
|
||||
<th>회사명</th>
|
||||
<th>연락처</th>
|
||||
<th>서비스</th>
|
||||
<th>세금 유형</th>
|
||||
<th>상태</th>
|
||||
<th>유입 경로</th>
|
||||
<th>등록일</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var c in clients)
|
||||
{
|
||||
<tr>
|
||||
<td><strong>@c.Name</strong></td>
|
||||
<td>@(c.CompanyName ?? "—")</td>
|
||||
<td>@(c.Phone ?? "—")</td>
|
||||
<td>
|
||||
@if (!string.IsNullOrEmpty(c.ServiceType))
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Primary">@c.ServiceType</MudChip>
|
||||
}
|
||||
</td>
|
||||
<td>@(c.TaxType ?? "—")</td>
|
||||
<td>
|
||||
@if (c.Status == "active")
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Success">활성</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Default">비활성</MudChip>
|
||||
}
|
||||
</td>
|
||||
<td>@(c.Source ?? "—")</td>
|
||||
<td class="small">@c.CreatedAt.ToLocalTime().ToString("yy.MM.dd")</td>
|
||||
<td>
|
||||
<MudButtonGroup Size="Size.Small" Variant="Variant.Outlined">
|
||||
<MudButton @onclick="@(() => Navigation.NavigateTo($"/taxbaik/admin/clients/{c.Id}/edit"))">
|
||||
수정
|
||||
</MudButton>
|
||||
<MudButton Color="Color.Error" @onclick="@(() => DeleteAsync(c))">
|
||||
삭제
|
||||
</MudButton>
|
||||
</MudButtonGroup>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</MudSimpleTable>
|
||||
|
||||
@* 페이징 *@
|
||||
@if (totalPages > 1)
|
||||
{
|
||||
<div class="d-flex justify-center pa-3">
|
||||
<MudPagination BoundaryCount="1" MiddleCount="3"
|
||||
Count="@totalPages" Selected="@currentPage"
|
||||
SelectedChanged="@OnPageChanged" />
|
||||
</div>
|
||||
}
|
||||
<MudText Typo="Typo.caption" Class="pa-2 text-muted">총 @(totalCount)명</MudText>
|
||||
}
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private List<Client>? clients;
|
||||
private string searchText = "";
|
||||
private string statusFilter = "";
|
||||
private int currentPage = 1;
|
||||
private int totalCount;
|
||||
private int totalPages;
|
||||
private const int PageSize = 20;
|
||||
|
||||
private RenderFragment ClientListSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 5);
|
||||
builder.AddAttribute(2, "Columns", 5);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
clients = [];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clients = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var (items, total) = await ClientClient.GetPagedAsync(
|
||||
currentPage, PageSize,
|
||||
string.IsNullOrEmpty(statusFilter) ? null : statusFilter,
|
||||
string.IsNullOrEmpty(searchText) ? null : searchText);
|
||||
|
||||
clients = items.ToList();
|
||||
totalCount = total;
|
||||
totalPages = (int)Math.Ceiling((double)total / PageSize);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
clients = [];
|
||||
totalCount = 0;
|
||||
totalPages = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SearchAsync()
|
||||
{
|
||||
currentPage = 1;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task ResetAsync()
|
||||
{
|
||||
searchText = "";
|
||||
statusFilter = "";
|
||||
currentPage = 1;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task OnPageChanged(int page)
|
||||
{
|
||||
currentPage = page;
|
||||
await LoadAsync();
|
||||
}
|
||||
|
||||
private async Task OnSearchKeyUp(KeyboardEventArgs e)
|
||||
{
|
||||
if (e.Key == "Enter") await SearchAsync();
|
||||
}
|
||||
|
||||
private async Task DeleteAsync(Client client)
|
||||
{
|
||||
var confirmed = await DialogService.ShowMessageBox(
|
||||
"고객 삭제",
|
||||
$"'{client.Name}' 고객을 삭제하시겠습니까? 관련 데이터도 함께 삭제됩니다.",
|
||||
yesText: "삭제", cancelText: "취소");
|
||||
|
||||
if (confirmed != true) return;
|
||||
|
||||
try
|
||||
{
|
||||
var success = await ClientClient.DeleteAsync(client.Id);
|
||||
if (success)
|
||||
{
|
||||
Snackbar.Add($"{client.Name} 고객이 삭제되었습니다.", Severity.Success);
|
||||
await LoadAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("삭제에 실패했습니다.", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
await LoadAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
@page "/admin/common-codes"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@using TaxBaik.Web.Services.AdminClients
|
||||
@using TaxBaik.Domain.Entities
|
||||
@attribute [Authorize]
|
||||
@inject ICommonCodeBrowserClient CommonCodeClient
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>공통관리</PageTitle>
|
||||
|
||||
<AdminPageHeader Title="공통관리" Eyebrow="System" Subtitle="공통코드 그룹과 항목을 일관된 기준으로 관리합니다." />
|
||||
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem XS="12" MD="4">
|
||||
<CommonCodeGroupPanel Groups="groups"
|
||||
SelectedGroup="selectedGroup"
|
||||
SelectedGroupChanged="OnGroupChanged"
|
||||
OnCreateRequested="PrepareCreate" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem XS="12" MD="8">
|
||||
<CommonCodeListPanel Loading="@isLoading"
|
||||
Codes="codes"
|
||||
EditModel="editModel"
|
||||
IsCreateMode="isCreateMode"
|
||||
Form="form"
|
||||
EditRequested="EditCode"
|
||||
DeleteRequested="DeleteCode"
|
||||
SaveRequested="SaveCode"
|
||||
ResetRequested="PrepareCreate" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
@code {
|
||||
private List<string> groups = [];
|
||||
private List<CommonCode> codes = [];
|
||||
private string selectedGroup = "";
|
||||
private bool isLoading = true;
|
||||
private CommonCode editModel = new();
|
||||
private bool isCreateMode = true;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
groups = await CommonCodeClient.GetGroupsAsync();
|
||||
selectedGroup = groups.FirstOrDefault() ?? "";
|
||||
await LoadCodes();
|
||||
PrepareCreate();
|
||||
}
|
||||
|
||||
private async Task OnGroupChanged(string value)
|
||||
{
|
||||
selectedGroup = value;
|
||||
await LoadCodes();
|
||||
PrepareCreate();
|
||||
}
|
||||
|
||||
private async Task LoadCodes()
|
||||
{
|
||||
isLoading = true;
|
||||
codes = string.IsNullOrWhiteSpace(selectedGroup)
|
||||
? []
|
||||
: await CommonCodeClient.GetByGroupAsync(selectedGroup);
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private void PrepareCreate()
|
||||
{
|
||||
isCreateMode = true;
|
||||
editModel = new CommonCode
|
||||
{
|
||||
CodeGroup = selectedGroup,
|
||||
IsActive = true
|
||||
};
|
||||
}
|
||||
|
||||
private void EditCode(CommonCode code)
|
||||
{
|
||||
isCreateMode = false;
|
||||
editModel = new CommonCode
|
||||
{
|
||||
CodeGroup = code.CodeGroup,
|
||||
CodeValue = code.CodeValue,
|
||||
CodeName = code.CodeName,
|
||||
SortOrder = code.SortOrder,
|
||||
IsActive = code.IsActive
|
||||
};
|
||||
}
|
||||
|
||||
private async Task SaveCode()
|
||||
{
|
||||
editModel.CodeGroup = editModel.CodeGroup?.Trim() ?? string.Empty;
|
||||
editModel.CodeValue = editModel.CodeValue?.Trim() ?? string.Empty;
|
||||
editModel.CodeName = editModel.CodeName?.Trim() ?? string.Empty;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(editModel.CodeGroup) ||
|
||||
string.IsNullOrWhiteSpace(editModel.CodeValue) ||
|
||||
string.IsNullOrWhiteSpace(editModel.CodeName))
|
||||
{
|
||||
Snackbar.Add("그룹, 값, 이름은 모두 입력해야 합니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (editModel.CodeGroup.Any(char.IsWhiteSpace))
|
||||
{
|
||||
Snackbar.Add("code_group에는 공백을 넣을 수 없습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (editModel.CodeValue.Any(char.IsWhiteSpace))
|
||||
{
|
||||
Snackbar.Add("code_value에는 공백을 넣을 수 없습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await CommonCodeClient.UpsertAsync(editModel))
|
||||
{
|
||||
Snackbar.Add("저장 실패", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("저장되었습니다.", Severity.Success);
|
||||
await LoadCodes();
|
||||
PrepareCreate();
|
||||
}
|
||||
|
||||
private async Task DeleteCode(CommonCode code)
|
||||
{
|
||||
if (!await CommonCodeClient.DeleteAsync(code.CodeGroup, code.CodeValue))
|
||||
{
|
||||
Snackbar.Add("삭제 실패", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("삭제되었습니다.", Severity.Success);
|
||||
await LoadCodes();
|
||||
PrepareCreate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
@page "/admin/companies/create"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.WasmClient.Components.Admin.Forms
|
||||
@inject IApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>고객사 등록</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Settings</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">새 고객사 등록</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">새로운 고객사를 추가합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Close" @onclick="GoBack">취소</MudButton>
|
||||
</section>
|
||||
|
||||
<MudPaper Class="pa-4 mt-4" Elevation="1">
|
||||
<CompanyForm ButtonText="등록" OnSubmit="HandleCreate" OnCancel="GoBack" />
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
private void GoBack()
|
||||
{
|
||||
Navigation.NavigateTo("/taxbaik/admin/companies");
|
||||
}
|
||||
|
||||
private async Task HandleCreate(CompanyForm.CompanyFormModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ApiClient.PostAsync<object>("company", new
|
||||
{
|
||||
companyCode = model.CompanyCode,
|
||||
companyName = model.CompanyName,
|
||||
contactPerson = model.ContactPerson,
|
||||
phone = model.Phone,
|
||||
email = model.Email,
|
||||
memo = model.Memo
|
||||
});
|
||||
|
||||
Snackbar.Add("고객사가 등록되었습니다.", Severity.Success);
|
||||
Navigation.NavigateTo("/taxbaik/admin/companies");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"등록 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
@page "/admin/companies/{id:int}/edit"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.WasmClient.Components.Admin.Forms
|
||||
@inject IApiClient ApiClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
|
||||
<PageTitle>고객사 수정</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Settings</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">고객사 수정</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">고객사 정보를 수정합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Close" @onclick="GoBack">취소</MudButton>
|
||||
</section>
|
||||
|
||||
<AdminEditorPanel Loading="@isLoading" SkeletonContent="@CompanySkeleton">
|
||||
@if (formModel == null)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mt-4">고객사를 찾을 수 없습니다.</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudPaper Class="pa-4 mt-4" Elevation="1">
|
||||
<CompanyForm ButtonText="수정" InitialData="formModel" OnSubmit="HandleUpdate" OnCancel="GoBack" />
|
||||
|
||||
<MudDivider Class="my-4" />
|
||||
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" @onclick="DeleteCompany" Class="mt-2">
|
||||
고객사 삭제
|
||||
</MudButton>
|
||||
</MudPaper>
|
||||
}
|
||||
</AdminEditorPanel>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
private CompanyForm.CompanyFormModel? formModel;
|
||||
private bool isLoading = true;
|
||||
|
||||
private RenderFragment CompanySkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 6);
|
||||
builder.AddAttribute(2, "Columns", 3);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var company = await ApiClient.GetAsync<dynamic>($"company/{Id}");
|
||||
IDictionary<string, object>? dict = company as IDictionary<string, object>;
|
||||
if (dict != null)
|
||||
{
|
||||
formModel = new CompanyForm.CompanyFormModel
|
||||
{
|
||||
CompanyCode = (string)dict["companyCode"],
|
||||
CompanyName = (string)dict["companyName"],
|
||||
ContactPerson = (string?)dict["contactPerson"],
|
||||
Phone = (string?)dict["phone"],
|
||||
Email = (string?)dict["email"],
|
||||
Memo = (string?)dict["memo"],
|
||||
IsActive = (bool)(dynamic)dict["isActive"]
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"고객사 로드 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
{
|
||||
Navigation.NavigateTo("/taxbaik/admin/companies");
|
||||
}
|
||||
|
||||
private async Task HandleUpdate(CompanyForm.CompanyFormModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
await ApiClient.PutAsync<object>($"company/{Id}", new
|
||||
{
|
||||
companyCode = model.CompanyCode,
|
||||
companyName = model.CompanyName,
|
||||
contactPerson = model.ContactPerson,
|
||||
phone = model.Phone,
|
||||
email = model.Email,
|
||||
memo = model.Memo,
|
||||
isActive = model.IsActive
|
||||
});
|
||||
|
||||
Snackbar.Add("고객사가 수정되었습니다.", Severity.Success);
|
||||
Navigation.NavigateTo("/taxbaik/admin/companies");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"수정 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteCompany()
|
||||
{
|
||||
var result = await DialogService.ShowMessageBox(
|
||||
"고객사 삭제",
|
||||
"정말 삭제하시겠습니까? 이 작업은 취소할 수 없습니다.",
|
||||
"삭제", "취소");
|
||||
|
||||
if (result != true)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await ApiClient.DeleteAsync($"company/{Id}");
|
||||
Snackbar.Add("고객사가 삭제되었습니다.", Severity.Success);
|
||||
Navigation.NavigateTo("/taxbaik/admin/companies");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
@page "/admin/companies"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@inject IApiClient ApiClient
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>고객사 관리</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Settings</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">고객사 관리</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">등록된 고객사를 관리하고 새로운 고객사를 추가합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add"
|
||||
Href="/taxbaik/admin/companies/create">새 고객사 등록</MudButton>
|
||||
</section>
|
||||
|
||||
<MudPaper Class="admin-surface mb-4 mt-4" Elevation="0">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween">
|
||||
<MudText Typo="Typo.subtitle1">@($"전체 고객사 {totalCompanies}개")</MudText>
|
||||
<MudText Typo="Typo.body2">페이지 @currentPage / @totalPages</MudText>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
|
||||
<MudDataGrid Items="@companies" Striped="true" Hoverable="true" Loading="@isLoading" Class="admin-grid">
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.CompanyCode" Title="회사코드" />
|
||||
<PropertyColumn Property="x => x.CompanyName" Title="회사명" />
|
||||
<PropertyColumn Property="x => x.ContactPerson" Title="담당자" />
|
||||
<PropertyColumn Property="x => x.Phone" Title="전화" />
|
||||
<PropertyColumn Property="x => x.Email" Title="이메일" />
|
||||
<PropertyColumn Property="x => x.IsActive" Title="활성">
|
||||
<CellTemplate Context="cell">
|
||||
<MudCheckBox T="bool" Value="@cell.Item.IsActive" Disabled="true" />
|
||||
</CellTemplate>
|
||||
</PropertyColumn>
|
||||
<PropertyColumn Property="x => x.CreatedAt" Title="등록일" Format="yyyy-MM-dd" />
|
||||
<TemplateColumn>
|
||||
<CellTemplate Context="cell">
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" Color="Color.Primary"
|
||||
Href="@($"/taxbaik/admin/companies/{cell.Item.Id}/edit")">수정</MudButton>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
|
||||
<MudStack Row="true" Justify="Justify.Center" Class="mt-4" Spacing="2">
|
||||
<MudButton Variant="Variant.Outlined" Disabled="@(currentPage <= 1 || isLoading)" @onclick="PreviousPage">이전</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Disabled="@(currentPage >= totalPages || isLoading)" @onclick="NextPage">다음</MudButton>
|
||||
</MudStack>
|
||||
|
||||
@code {
|
||||
private List<CompanyDto> companies = [];
|
||||
private bool isLoading = true;
|
||||
private int currentPage = 1;
|
||||
private int totalPages = 1;
|
||||
private int totalCompanies = 0;
|
||||
private const int PageSize = 20;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
isLoading = true;
|
||||
var response = await ApiClient.GetAsync<dynamic>($"company?page={currentPage}&pageSize={PageSize}");
|
||||
|
||||
IDictionary<string, object>? dict = response as IDictionary<string, object>;
|
||||
if (dict != null)
|
||||
{
|
||||
totalCompanies = (int)(dynamic)dict["total"];
|
||||
totalPages = (totalCompanies + PageSize - 1) / PageSize;
|
||||
|
||||
if (dict["data"] is System.Collections.IEnumerable dataList)
|
||||
{
|
||||
companies = new List<CompanyDto>();
|
||||
foreach (var item in dataList)
|
||||
{
|
||||
if (item is IDictionary<string, object> companyDict)
|
||||
{
|
||||
companies.Add(new CompanyDto
|
||||
{
|
||||
Id = (int)(dynamic)companyDict["id"],
|
||||
CompanyCode = (string)companyDict["companyCode"],
|
||||
CompanyName = (string)companyDict["companyName"],
|
||||
ContactPerson = (string?)companyDict["contactPerson"],
|
||||
Phone = (string?)companyDict["phone"],
|
||||
Email = (string?)companyDict["email"],
|
||||
IsActive = (bool)(dynamic)companyDict["isActive"],
|
||||
CreatedAt = DateTime.Parse(companyDict["createdAt"].ToString()!)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"고객사 로드 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task NextPage()
|
||||
{
|
||||
currentPage++;
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task PreviousPage()
|
||||
{
|
||||
currentPage = Math.Max(1, currentPage - 1);
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private class CompanyDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string CompanyCode { get; set; } = "";
|
||||
public string CompanyName { get; set; } = "";
|
||||
public string? ContactPerson { get; set; }
|
||||
public string? Phone { get; set; }
|
||||
public string? Email { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
@page "/admin/consulting-activities"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@using TaxBaik.Web.Services.AdminClients
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject IConsultingActivityBrowserClient ActivityClient
|
||||
@inject IClientBrowserClient ClientClient
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>상담 활동 관리</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">CRM & 세무관리</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">상담 활동 관리</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">고객별 상담 이력과 팔로업을 추적합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OpenCreateDialog" StartIcon="@Icons.Material.Filled.Add">
|
||||
새 활동 기록
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
<AdminDataPanel Loading="@(activities is null)" SkeletonContent="@ActivitySkeleton">
|
||||
@if (activities is null)
|
||||
{
|
||||
}
|
||||
else if (activities.Count == 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Class="mt-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Timeline" Class="me-2" />
|
||||
상담 활동이 없습니다.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudDataGrid T="ConsultingActivity"
|
||||
Items="@activities"
|
||||
Dense="true"
|
||||
Hover="true"
|
||||
Striped="true"
|
||||
Virtualize="true"
|
||||
RowsPerPage="30"
|
||||
Class="admin-grid">
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.Id" Title="ID" Sortable="true" />
|
||||
<TemplateColumn Title="고객">
|
||||
<CellTemplate>
|
||||
@if (clientMap.TryGetValue(context.Item.ClientId, out var clientName))
|
||||
{
|
||||
<MudLink Href="@($"/taxbaik/admin/clients/{context.Item.ClientId}")" Color="Color.Primary">
|
||||
@clientName
|
||||
</MudLink>
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Property="x => x.ActivityType" Title="활동 유형" />
|
||||
<PropertyColumn Property="x => x.ActivityDate" Title="활동일시" Format="g" />
|
||||
<TemplateColumn Title="설명">
|
||||
<CellTemplate>
|
||||
@{
|
||||
var desc = context.Item.Description ?? "";
|
||||
if (desc.Length > 30) desc = desc.Substring(0, 30) + "...";
|
||||
}
|
||||
<span>@desc</span>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="다음 팔로업">
|
||||
<CellTemplate>
|
||||
@if (context.Item.NextFollowupDate.HasValue)
|
||||
{
|
||||
var daysLeft = (context.Item.NextFollowupDate.Value.Date - DateTime.Today).Days;
|
||||
<MudChip Size="Size.Small"
|
||||
Color="@(daysLeft < 0 ? Color.Error : daysLeft <= 3 ? Color.Warning : Color.Success)"
|
||||
Variant="Variant.Filled">
|
||||
@context.Item.NextFollowupDate.Value.ToString("yyyy-MM-dd")
|
||||
</MudChip>
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="작업" Sortable="false">
|
||||
<CellTemplate>
|
||||
<MudButtonGroup Size="Size.Small" Variant="Variant.Outlined">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Edit" OnClick="@(async () => await OpenEditDialog(context.Item))" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error"
|
||||
OnClick="@(async () => await DeleteActivity(context.Item.Id))" />
|
||||
</MudButtonGroup>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
}
|
||||
</AdminDataPanel>
|
||||
|
||||
<MudDialog @bind-IsVisible="isDialogOpen" Options="new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true }">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">@(editingActivity == null ? "새 활동 기록" : "활동 기록 수정")</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudForm @ref="form">
|
||||
<MudSelect T="int" @bind-Value="activityForm.ClientId" Label="고객" Required="true" Variant="Variant.Outlined" FullWidth="true" Class="mb-4">
|
||||
@foreach (var client in clients)
|
||||
{
|
||||
<MudSelectItem Value="@client.Id">@GetClientDisplayName(client)</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<CommonCodeSelect @bind-Value="activityForm.ActivityType" Group="CONSULTING_ACTIVITY_TYPE" Label="활동 유형" Class="mb-4" Required="true" />
|
||||
<MudDatePicker @bind-Date="activityForm.ActivityDate" Label="활동일" Variant="Variant.Outlined" FullWidth="true" Class="mb-4" Required="true" />
|
||||
<MudTextField T="string" @bind-Value="activityForm.Description" Label="설명" Variant="Variant.Outlined" FullWidth="true" Lines="3" Class="mb-4" Required="true" />
|
||||
<MudDatePicker @bind-Date="activityForm.NextFollowupDate" Label="다음 팔로업일" Variant="Variant.Outlined" FullWidth="true" Class="mb-4" />
|
||||
</MudForm>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="CloseDialog">취소</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="SaveActivity">저장</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private List<ConsultingActivity>? activities;
|
||||
private List<Client> clients = [];
|
||||
private Dictionary<int, string> clientMap = new();
|
||||
private MudForm? form;
|
||||
private bool isDialogOpen;
|
||||
private ConsultingActivity? editingActivity;
|
||||
private ConsultingActivityForm activityForm = new();
|
||||
|
||||
private RenderFragment ActivitySkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 5);
|
||||
builder.AddAttribute(2, "Columns", 4);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
activities = [];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
activities = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
activities = await ActivityClient.GetAllAsync();
|
||||
var (clientItems, _) = await ClientClient.GetPagedAsync(pageSize: 1000);
|
||||
clients = clientItems.ToList();
|
||||
clientMap = clients.ToDictionary(c => c.Id, GetClientDisplayName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"데이터 로드 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenCreateDialog()
|
||||
{
|
||||
editingActivity = null;
|
||||
activityForm = new ConsultingActivityForm
|
||||
{
|
||||
ActivityDate = DateTime.Now,
|
||||
ClientId = clients.FirstOrDefault()?.Id ?? 0
|
||||
};
|
||||
isDialogOpen = true;
|
||||
}
|
||||
|
||||
private async Task OpenEditDialog(ConsultingActivity activity)
|
||||
{
|
||||
editingActivity = activity;
|
||||
activityForm = new ConsultingActivityForm
|
||||
{
|
||||
ClientId = activity.ClientId,
|
||||
ActivityType = activity.ActivityType,
|
||||
ActivityDate = activity.ActivityDate,
|
||||
Description = activity.Description,
|
||||
NextFollowupDate = activity.NextFollowupDate
|
||||
};
|
||||
isDialogOpen = true;
|
||||
}
|
||||
|
||||
private async Task SaveActivity()
|
||||
{
|
||||
if (form != null)
|
||||
{
|
||||
await form.Validate();
|
||||
if (!form.IsValid)
|
||||
{
|
||||
Snackbar.Add("필수 항목을 입력해주세요.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (editingActivity == null)
|
||||
{
|
||||
var actDate = activityForm.ActivityDate ?? DateTime.Now;
|
||||
var newId = await ActivityClient.CreateAsync(
|
||||
activityForm.ClientId,
|
||||
activityForm.ActivityType,
|
||||
actDate,
|
||||
activityForm.Description,
|
||||
null,
|
||||
activityForm.NextFollowupDate);
|
||||
|
||||
if (newId > 0)
|
||||
{
|
||||
Snackbar.Add("활동이 기록되었습니다.", Severity.Success);
|
||||
CloseDialog();
|
||||
await LoadData();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await ActivityClient.UpdateAsync(
|
||||
editingActivity.Id,
|
||||
null,
|
||||
activityForm.NextFollowupDate);
|
||||
|
||||
Snackbar.Add("활동이 업데이트되었습니다.", Severity.Success);
|
||||
CloseDialog();
|
||||
await LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteActivity(int id)
|
||||
{
|
||||
var parameters = new DialogParameters
|
||||
{
|
||||
{ "Title", "삭제 확인" },
|
||||
{ "Message", "이 활동을 삭제하시겠습니까?" }
|
||||
};
|
||||
|
||||
var dialog = await DialogService.ShowAsync<ConfirmDialog>("", parameters);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result?.Canceled ?? true)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await ActivityClient.DeleteAsync(id);
|
||||
Snackbar.Add("활동이 삭제되었습니다.", Severity.Success);
|
||||
await LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseDialog()
|
||||
{
|
||||
isDialogOpen = false;
|
||||
editingActivity = null;
|
||||
activityForm = new();
|
||||
}
|
||||
|
||||
private static string GetClientDisplayName(Client client)
|
||||
=> !string.IsNullOrWhiteSpace(client.CompanyName)
|
||||
? client.CompanyName
|
||||
: !string.IsNullOrWhiteSpace(client.Name)
|
||||
? client.Name
|
||||
: $"Client #{client.Id}";
|
||||
private class ConsultingActivityForm
|
||||
{
|
||||
public int ClientId { get; set; }
|
||||
public string ActivityType { get; set; } = "";
|
||||
public DateTime? ActivityDate { get; set; } = DateTime.Now;
|
||||
public string Description { get; set; } = "";
|
||||
public DateTime? NextFollowupDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
@page "/admin/contracts"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@using TaxBaik.Web.Services.AdminClients
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject IContractBrowserClient ContractClient
|
||||
@inject IClientBrowserClient ClientClient
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>계약 관리</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">CRM & 세무관리</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">계약 관리</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">고객 계약과 월 정기수익을 함께 관리합니다.</MudText>
|
||||
@if (mrr > 0)
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mt-2">
|
||||
월 정기수익:
|
||||
<MudChip Size="Size.Small" Color="Color.Primary" Variant="Variant.Filled">₩@mrr.ToString("N0")</MudChip>
|
||||
</MudText>
|
||||
}
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="PrepareCreate" StartIcon="@Icons.Material.Filled.Add" id="btn-add-contract">
|
||||
새 계약 추가
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
<AdminEditorPanel Loading="@(contracts is null)" SkeletonContent="@ContractSkeleton">
|
||||
@if (contracts is null)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudGrid Spacing="2" Class="mt-2">
|
||||
<!-- Left: Dense Grid List -->
|
||||
<MudItem XS="12" MD="8">
|
||||
@if (contracts.Count == 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Description" Class="me-2" />
|
||||
계약이 없습니다.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudDataGrid T="Contract"
|
||||
Items="@contracts"
|
||||
Dense="true"
|
||||
Hover="true"
|
||||
Striped="true"
|
||||
Virtualize="true"
|
||||
RowsPerPage="30"
|
||||
SelectedItem="@selectedContract"
|
||||
SelectedItemChanged="OnRowSelected"
|
||||
Class="admin-grid">
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.Id" Title="ID" Sortable="true" />
|
||||
<TemplateColumn Title="고객">
|
||||
<CellTemplate>
|
||||
@if (clientMap.TryGetValue(context.Item.ClientId, out var clientName))
|
||||
{
|
||||
@clientName
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Property="x => x.ContractNumber" Title="계약번호" />
|
||||
<PropertyColumn Property="x => x.ServiceType" Title="서비스 유형" />
|
||||
<PropertyColumn Property="x => x.MonthlyFee" Title="월 수수료" Format="C" />
|
||||
<TemplateColumn Title="계약기간">
|
||||
<CellTemplate>
|
||||
@context.Item.StartDate.ToString("yyyy-MM-dd")
|
||||
@if (context.Item.EndDate.HasValue)
|
||||
{
|
||||
<span>~@context.Item.EndDate.Value.ToString("yyyy-MM-dd")</span>
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="상태">
|
||||
<CellTemplate>
|
||||
@{
|
||||
var isActive = !context.Item.EndDate.HasValue || context.Item.EndDate.Value >= DateTime.Today;
|
||||
}
|
||||
@if (isActive)
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Success" Variant="Variant.Filled">활성</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Default" Variant="Variant.Outlined">만료</MudChip>
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="작업" Sortable="false">
|
||||
<CellTemplate>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" Size="Size.Small"
|
||||
OnClick="@(async () => await DeleteContract(context.Item.Id))" />
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
}
|
||||
</MudItem>
|
||||
|
||||
<!-- Right: Detail Form Panel (Inline Editor) -->
|
||||
<MudItem XS="12" MD="4">
|
||||
<MudPaper Class="pa-4 admin-surface admin-editor-panel" Elevation="0" Style="border: 1px solid var(--border-color); min-height: 400px;">
|
||||
<div class="d-flex align-center justify-space-between mb-4">
|
||||
<MudText Typo="Typo.h6" Class="font-weight-bold">@(isEditMode ? "계약 상세 정보" : "새 계약 추가")</MudText>
|
||||
@if (isEditMode)
|
||||
{
|
||||
<MudButton Size="Size.Small" Variant="Variant.Outlined" Color="Color.Secondary" OnClick="PrepareCreate">
|
||||
새로 작성
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
<MudForm @ref="form">
|
||||
<MudSelect T="int?" @bind-Value="contractForm.ClientId" Label="고객" Required="true" Variant="Variant.Outlined" FullWidth="@true" Class="mb-3" RequiredError="고객을 선택하세요." Disabled="@isEditMode">
|
||||
@foreach (var client in clients)
|
||||
{
|
||||
<MudSelectItem Value="@((int?)client.Id)">@GetClientDisplayName(client)</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudTextField T="string" @bind-Value="contractForm.ContractNumber" Label="계약번호" Variant="Variant.Outlined" FullWidth="@true" Class="mb-3" Required="true" />
|
||||
<CommonCodeSelect @bind-Value="contractForm.ServiceType" Group="CONTRACT_SERVICE_TYPE" Label="서비스 유형" Class="mb-3" Required="true" />
|
||||
<MudDatePicker @bind-Date="contractForm.StartDate" Label="계약 시작일" Variant="Variant.Outlined" FullWidth="@true" Class="mb-3" Required="true" />
|
||||
<MudNumericField T="decimal?" @bind-Value="contractForm.MonthlyFee" Label="월 수수료" Variant="Variant.Outlined" FullWidth="@true" Class="mb-4" />
|
||||
|
||||
<div class="d-flex justify-end gap-2">
|
||||
@if (isEditMode)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="@(async () => await DeleteContract(selectedContract?.Id ?? 0))">삭제</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SaveContract" id="btn-save-contract">저장</MudButton>
|
||||
}
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
}
|
||||
</AdminEditorPanel>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private List<Contract>? contracts;
|
||||
private List<Client> clients = [];
|
||||
private Dictionary<int, string> clientMap = new();
|
||||
private decimal mrr = 0;
|
||||
private MudForm? form;
|
||||
private bool isEditMode;
|
||||
private Contract? selectedContract;
|
||||
private ContractForm contractForm = new();
|
||||
|
||||
private RenderFragment ContractSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 6);
|
||||
builder.AddAttribute(2, "Columns", 4);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadData();
|
||||
PrepareCreate();
|
||||
}
|
||||
else
|
||||
{
|
||||
contracts = [];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
contracts = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
contracts = await ContractClient.GetAllAsync();
|
||||
var (clientItems, _) = await ClientClient.GetPagedAsync(pageSize: 1000);
|
||||
clients = clientItems.ToList();
|
||||
clientMap = clients.ToDictionary(c => c.Id, GetClientDisplayName);
|
||||
mrr = await ContractClient.GetMonthlyRecurringRevenueAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"데이터 로드 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareCreate()
|
||||
{
|
||||
selectedContract = null;
|
||||
isEditMode = false;
|
||||
contractForm = new ContractForm
|
||||
{
|
||||
ClientId = clients.FirstOrDefault()?.Id,
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
}
|
||||
|
||||
private void OnRowSelected(Contract contract)
|
||||
{
|
||||
if (contract == null) return;
|
||||
selectedContract = contract;
|
||||
isEditMode = true;
|
||||
contractForm = new ContractForm
|
||||
{
|
||||
ClientId = contract.ClientId,
|
||||
ContractNumber = contract.ContractNumber,
|
||||
ServiceType = contract.ServiceType,
|
||||
StartDate = contract.StartDate,
|
||||
MonthlyFee = contract.MonthlyFee
|
||||
};
|
||||
}
|
||||
|
||||
private async Task SaveContract()
|
||||
{
|
||||
if (form != null)
|
||||
{
|
||||
await form.Validate();
|
||||
if (!form.IsValid)
|
||||
{
|
||||
Snackbar.Add("필수 항목을 입력해주세요.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (contractForm.ClientId == null) return;
|
||||
var newId = await ContractClient.CreateAsync(
|
||||
contractForm.ClientId.Value,
|
||||
contractForm.ContractNumber,
|
||||
contractForm.ServiceType,
|
||||
contractForm.StartDate ?? DateTime.Now,
|
||||
contractForm.MonthlyFee);
|
||||
|
||||
if (newId > 0)
|
||||
{
|
||||
Snackbar.Add("계약이 추가되었습니다.", Severity.Success);
|
||||
PrepareCreate();
|
||||
await LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteContract(int id)
|
||||
{
|
||||
var parameters = new DialogParameters
|
||||
{
|
||||
{ "Title", "삭제 확인" },
|
||||
{ "Message", "이 계약을 삭제하시겠습니까?" }
|
||||
};
|
||||
|
||||
var dialog = await DialogService.ShowAsync<ConfirmDialog>("", parameters);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result?.Canceled ?? true)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await ContractClient.DeleteAsync(id);
|
||||
Snackbar.Add("계약이 삭제되었습니다.", Severity.Success);
|
||||
if (selectedContract?.Id == id)
|
||||
{
|
||||
PrepareCreate();
|
||||
}
|
||||
await LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetClientDisplayName(Client client)
|
||||
=> !string.IsNullOrWhiteSpace(client.CompanyName)
|
||||
? client.CompanyName
|
||||
: !string.IsNullOrWhiteSpace(client.Name)
|
||||
? client.Name
|
||||
: $"Client #{client.Id}";
|
||||
|
||||
private class ContractForm
|
||||
{
|
||||
public int? ClientId { get; set; }
|
||||
public string ContractNumber { get; set; } = "";
|
||||
public string ServiceType { get; set; } = "";
|
||||
public DateTime? StartDate { get; set; }
|
||||
public decimal? MonthlyFee { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
@page "/admin/dashboard"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject IAdminDashboardClient DashboardClient
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<PageTitle>대시보드</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Overview</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">대시보드</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">문의 흐름과 콘텐츠 상태를 한 화면에서 확인합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add" Href="/taxbaik/admin/blog/create">
|
||||
새 포스트 작성
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
@if (!string.IsNullOrEmpty(errorMessage))
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mb-4">@errorMessage</MudAlert>
|
||||
}
|
||||
|
||||
<AdminDataPanel Loading="@isLoading" SkeletonContent="@DashboardSkeleton">
|
||||
<div class="admin-metric-grid">
|
||||
<AdminMetricCard Label="이번달 문의" Value="@summary.ThisMonthInquiries" Caption="월간 상담 유입 (클릭 시 이동)" Accent="accent-blue" Icon="💬" ValueColor="var(--primary-dark)" IconColor="var(--primary-color)" OnClick="@GoInquiries" />
|
||||
<AdminMetricCard Label="신규 문의" Value="@summary.NewInquiries" Caption="처리 대기 (클릭 시 이동)" Accent="accent-amber" Icon="⚠️" ValueColor="var(--tertiary-dark)" IconColor="var(--tertiary-color)" OnClick="@GoNewInquiries" />
|
||||
<AdminMetricCard Label="전체 포스트" Value="@summary.TotalPosts" Caption="콘텐츠 자산 (클릭 시 이동)" Accent="accent-slate" Icon="📄" ValueColor="#455a64" IconColor="#607d8b" OnClick="@GoBlog" />
|
||||
<AdminMetricCard Label="발행된 포스트" Value="@summary.PublishedPosts" Caption="검색 노출 대상 (클릭 시 이동)" Accent="accent-green" Icon="🌐" ValueColor="var(--secondary-dark)" IconColor="var(--secondary-color)" OnClick="@GoBlog" />
|
||||
</div>
|
||||
|
||||
@if (upcomingFilings.Count > 0)
|
||||
{
|
||||
<MudPaper Class="admin-surface mt-4" Elevation="0">
|
||||
<div class="admin-section-header">
|
||||
<div>
|
||||
<MudText Typo="Typo.h6">이번 달 마감 임박 신고</MudText>
|
||||
<MudText Typo="Typo.body2">30일 이내 신고 예정 건 (고객명 클릭 시 상세 카드로 연결)</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" Href="/taxbaik/admin/tax-filings">전체 일정 보기</MudButton>
|
||||
</div>
|
||||
<MudSimpleTable Striped="true" Dense="true" Class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>고객</th>
|
||||
<th>신고 유형</th>
|
||||
<th>기한</th>
|
||||
<th>D-day</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var f in upcomingFilings)
|
||||
{
|
||||
var dday = BusinessDayCalculator.GetDday(DateOnly.FromDateTime(f.DueDate));
|
||||
var effectiveDueDate = BusinessDayCalculator.GetEffectiveDueDate(DateOnly.FromDateTime(f.DueDate));
|
||||
<tr>
|
||||
<td>
|
||||
<MudLink Href="@($"/taxbaik/admin/clients/{f.ClientId}")" Underline="Underline.Hover" Color="Color.Primary" Class="font-weight-bold">
|
||||
@f.ClientName
|
||||
</MudLink>
|
||||
</td>
|
||||
<td>@f.FilingType</td>
|
||||
<td>@effectiveDueDate.ToDateTime(TimeOnly.MinValue).ToString("yyyy-MM-dd")</td>
|
||||
<td>
|
||||
@if (dday < 0)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Dark">기한 초과 (@(-dday)일)</MudChip>
|
||||
}
|
||||
else if (dday <= 7)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Error">D-@dday</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>D-@dday</span>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</MudSimpleTable>
|
||||
</MudPaper>
|
||||
}
|
||||
|
||||
<MudPaper Class="admin-surface mt-4" Elevation="0">
|
||||
<div class="admin-section-header">
|
||||
<div>
|
||||
<MudText Typo="Typo.h6">최근 문의</MudText>
|
||||
<MudText Typo="Typo.body2">최근 유입된 상담 요청을 빠르게 확인합니다. (이름 클릭 시 상세 관리 화면으로 연계)</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" Href="/taxbaik/admin/inquiries">문의 전체 보기</MudButton>
|
||||
</div>
|
||||
<MudSimpleTable Striped="true" Dense="true" Class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>이름</th>
|
||||
<th>전화</th>
|
||||
<th>분야</th>
|
||||
<th>상태</th>
|
||||
<th>날짜</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var inquiry in summary.RecentInquiries)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<MudLink Href="@($"/taxbaik/admin/inquiries?id={inquiry.Id}")" Underline="Underline.Hover" Color="Color.Primary" Class="font-weight-bold">
|
||||
@inquiry.Name
|
||||
</MudLink>
|
||||
</td>
|
||||
<td>@inquiry.Phone</td>
|
||||
<td>@inquiry.ServiceType</td>
|
||||
<td>
|
||||
<MudChip T="string" Size="Size.Small" Color="@StatusColor(inquiry.Status)">
|
||||
@GetStatusLabel(inquiry.Status)
|
||||
</MudChip>
|
||||
</td>
|
||||
<td>@inquiry.CreatedAt.ToString("yyyy-MM-dd")</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</MudSimpleTable>
|
||||
</MudPaper>
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private AdminDashboardSummary summary = new(0, 0, 0, 0, []);
|
||||
private List<Domain.Entities.TaxFiling> upcomingFilings = [];
|
||||
private string? errorMessage;
|
||||
private bool isLoading = true;
|
||||
|
||||
private RenderFragment DashboardSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 6);
|
||||
builder.AddAttribute(2, "Columns", 4);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
private void GoInquiries()
|
||||
{
|
||||
Nav.NavigateTo("/taxbaik/admin/inquiries");
|
||||
}
|
||||
|
||||
private void GoNewInquiries()
|
||||
{
|
||||
Nav.NavigateTo("/taxbaik/admin/inquiries?status=new");
|
||||
}
|
||||
|
||||
private void GoBlog()
|
||||
{
|
||||
Nav.NavigateTo("/taxbaik/admin/blog");
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var summaryTask = DashboardClient.GetSummaryAsync();
|
||||
var filingsTask = DashboardClient.GetUpcomingFilingsAsync(30);
|
||||
|
||||
await Task.WhenAll(summaryTask, filingsTask);
|
||||
summary = await summaryTask;
|
||||
upcomingFilings = (await filingsTask).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
errorMessage = "대시보드 데이터를 불러올 수 없습니다.";
|
||||
Console.Error.WriteLine($"Dashboard error: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// AuthorizeRouteView already gates this page, so this branch is
|
||||
// only a transient auth-state resolution timing gap - but without
|
||||
// resetting isLoading here, AdminDataPanel would spin forever.
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetStatusLabel(string status) => InquiryStatusMapper.Labels.GetValueOrDefault(status, status);
|
||||
|
||||
private static Color StatusColor(string status) => status switch
|
||||
{
|
||||
"new" => Color.Warning,
|
||||
"consulting" => Color.Info,
|
||||
"contracted" => Color.Success,
|
||||
"rejected" => Color.Error,
|
||||
"closed" => Color.Dark,
|
||||
_ => Color.Default
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
@page "/admin/faqs/create"
|
||||
@page "/admin/faqs/{Id:int}/edit"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.Domain.Entities
|
||||
@inject IFaqBrowserClient FaqClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>@(Id.HasValue ? "FAQ 수정" : "FAQ 등록")</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">홈페이지</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">@(Id.HasValue ? "FAQ 수정" : "FAQ 등록")</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Outlined" Href="/taxbaik/admin/faqs"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack">목록으로</MudButton>
|
||||
</section>
|
||||
|
||||
<AdminEditorPanel Loading="@isLoading" SkeletonContent="@FaqSkeleton">
|
||||
<MudPaper Class="admin-surface" Elevation="0" Style="max-width:720px;">
|
||||
<MudForm @ref="form" @bind-IsValid="isValid">
|
||||
<MudGrid Spacing="3">
|
||||
<MudItem xs="12">
|
||||
<MudTextField @bind-Value="faq.Question"
|
||||
Label="질문 *" Required="true"
|
||||
RequiredError="질문을 입력하세요."
|
||||
Counter="300" MaxLength="300"
|
||||
Lines="2" AutoGrow="true"
|
||||
Placeholder="예: 기장료가 얼마인지 미리 알 수 있나요?" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudTextField @bind-Value="faq.Answer"
|
||||
Label="답변 *" Required="true"
|
||||
RequiredError="답변을 입력하세요."
|
||||
Lines="5" AutoGrow="true"
|
||||
Placeholder="방문자에게 보여질 답변을 입력하세요." />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="6">
|
||||
<CommonCodeSelect @bind-Value="faq.Category" Group="FAQ_CATEGORY" Label="카테고리" Clearable="true" Placeholder="전체" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="3">
|
||||
<MudNumericField @bind-Value="faq.SortOrder"
|
||||
Label="정렬 순서"
|
||||
HelperText="작을수록 위에 노출"
|
||||
Min="0" Max="9999" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="3" Class="d-flex align-center">
|
||||
<MudSwitch T="bool" @bind-Value="faq.IsActive" Color="Color.Success"
|
||||
Label="@(faq.IsActive ? "노출 중" : "비활성")" />
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" Class="d-flex gap-2 mt-2">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Save"
|
||||
OnClick="@SaveAsync" Disabled="@isSaving">
|
||||
@(isSaving ? "저장 중..." : "저장")
|
||||
</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" Href="/taxbaik/admin/faqs">
|
||||
취소
|
||||
</MudButton>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
</AdminEditorPanel>
|
||||
|
||||
@code {
|
||||
[Parameter] public int? Id { get; set; }
|
||||
|
||||
private MudForm form = null!;
|
||||
private Faq faq = new() { SortOrder = 10, IsActive = true };
|
||||
private bool isValid;
|
||||
private bool isLoading = true;
|
||||
private bool isSaving;
|
||||
|
||||
private RenderFragment FaqSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 5);
|
||||
builder.AddAttribute(2, "Columns", 3);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (Id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var existing = await FaqClient.GetByIdAsync(Id.Value);
|
||||
if (existing is null)
|
||||
{
|
||||
Snackbar.Add("FAQ를 찾을 수 없습니다.", Severity.Error);
|
||||
Navigation.NavigateTo("/taxbaik/admin/faqs");
|
||||
return;
|
||||
}
|
||||
faq = existing;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
Navigation.NavigateTo("/taxbaik/admin/faqs");
|
||||
return;
|
||||
}
|
||||
}
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
await form.Validate();
|
||||
if (!isValid) return;
|
||||
|
||||
isSaving = true;
|
||||
try
|
||||
{
|
||||
if (Id.HasValue)
|
||||
{
|
||||
var result = await FaqClient.UpdateAsync(Id.Value, faq);
|
||||
if (result != null)
|
||||
Snackbar.Add("FAQ가 수정되었습니다.", Severity.Success);
|
||||
else
|
||||
Snackbar.Add("수정 실패", Severity.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = await FaqClient.CreateAsync(faq);
|
||||
if (result != null)
|
||||
Snackbar.Add("FAQ가 등록되었습니다.", Severity.Success);
|
||||
else
|
||||
Snackbar.Add("등록 실패", Severity.Error);
|
||||
}
|
||||
Navigation.NavigateTo("/taxbaik/admin/faqs");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isSaving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
@page "/admin/faqs"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.Domain.Entities
|
||||
@inject IFaqBrowserClient FaqClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>FAQ 관리</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">홈페이지</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">FAQ 관리</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">홈페이지 자주 묻는 질문을 등록하고 순서를 관리합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Add"
|
||||
Href="/taxbaik/admin/faqs/create">
|
||||
FAQ 등록
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
<div class="d-flex pa-4 gap-4 align-center">
|
||||
<MudTextField @bind-Value="searchQuery" Placeholder="질문 또는 답변 검색..." Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" Class="flex-grow-1" Immediate="true" Clearable="true" />
|
||||
</div>
|
||||
|
||||
<AdminDataPanel Loading="@(faqs is null)" SkeletonContent="@FaqListSkeleton">
|
||||
@if (faqs is null)
|
||||
{
|
||||
}
|
||||
else if (!FilteredFaqs.Any())
|
||||
{
|
||||
<div class="pa-6 text-center">
|
||||
<MudIcon Icon="@Icons.Material.Filled.QuestionAnswer" Style="font-size:3rem; opacity:.3;" />
|
||||
<MudText Class="mt-2 text-muted">검색 조건에 맞는 FAQ가 없습니다.</MudText>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudSimpleTable Striped="true" Dense="true" Class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:110px;">순서</th>
|
||||
<th>질문</th>
|
||||
<th style="width:130px;">카테고리</th>
|
||||
<th style="width:90px;">상태</th>
|
||||
<th style="width:160px;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in FilteredFaqs)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<div class="d-flex align-center justify-start gap-1">
|
||||
<MudText Typo="Typo.body2" Class="mr-2">@item.SortOrder</MudText>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowDropUp" Size="Size.Small" OnClick="@(() => MoveUpAsync(item))" Style="padding:2px;" Dense="true" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.ArrowDropDown" Size="Size.Small" OnClick="@(() => MoveDownAsync(item))" Style="padding:2px;" Dense="true" />
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<MudText Typo="Typo.body2" Style="max-width:480px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
|
||||
@item.Question
|
||||
</MudText>
|
||||
</td>
|
||||
<td>
|
||||
@if (!string.IsNullOrEmpty(item.Category))
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Default">@item.Category</MudChip>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (item.IsActive)
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Success">노출 중</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Default">비활성</MudChip>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<MudButtonGroup Size="Size.Small" Variant="Variant.Outlined">
|
||||
<MudButton @onclick="@(() => Navigation.NavigateTo($"/taxbaik/admin/faqs/{item.Id}/edit"))">
|
||||
수정
|
||||
</MudButton>
|
||||
<MudButton Color="Color.Error" @onclick="@(() => DeleteAsync(item))">
|
||||
삭제
|
||||
</MudButton>
|
||||
</MudButtonGroup>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</MudSimpleTable>
|
||||
<MudText Typo="Typo.caption" Class="pa-2 text-muted">
|
||||
검색 결과 @(FilteredFaqs.Count())개 · 총 @(faqs.Count)개 · 노출 중 @(faqs.Count(f => f.IsActive))개
|
||||
</MudText>
|
||||
}
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private List<Faq>? faqs;
|
||||
private string searchQuery = "";
|
||||
|
||||
private RenderFragment FaqListSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 5);
|
||||
builder.AddAttribute(2, "Columns", 4);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
private IEnumerable<Faq> FilteredFaqs => faqs?
|
||||
.Where(f => string.IsNullOrEmpty(searchQuery) ||
|
||||
f.Question.Contains(searchQuery, StringComparison.OrdinalIgnoreCase) ||
|
||||
(f.Answer != null && f.Answer.Contains(searchQuery, StringComparison.OrdinalIgnoreCase)))
|
||||
.OrderBy(f => f.SortOrder) ?? Enumerable.Empty<Faq>();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
faqs = [];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
faqs = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
faqs = (await FaqClient.GetAllAsync()).OrderBy(f => f.SortOrder).ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
faqs = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task MoveUpAsync(Faq item)
|
||||
{
|
||||
if (faqs == null) return;
|
||||
var sorted = faqs.OrderBy(f => f.SortOrder).ToList();
|
||||
var index = sorted.IndexOf(item);
|
||||
if (index <= 0) return;
|
||||
|
||||
var prev = sorted[index - 1];
|
||||
var temp = item.SortOrder;
|
||||
item.SortOrder = prev.SortOrder;
|
||||
prev.SortOrder = temp;
|
||||
|
||||
if (item.SortOrder == prev.SortOrder)
|
||||
{
|
||||
prev.SortOrder = item.SortOrder + 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await FaqClient.UpdateAsync(item.Id, item);
|
||||
await FaqClient.UpdateAsync(prev.Id, prev);
|
||||
Snackbar.Add("순서가 상향되었습니다.", Severity.Success);
|
||||
await LoadAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"순서 조정 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task MoveDownAsync(Faq item)
|
||||
{
|
||||
if (faqs == null) return;
|
||||
var sorted = faqs.OrderBy(f => f.SortOrder).ToList();
|
||||
var index = sorted.IndexOf(item);
|
||||
if (index < 0 || index >= sorted.Count - 1) return;
|
||||
|
||||
var next = sorted[index + 1];
|
||||
var temp = item.SortOrder;
|
||||
item.SortOrder = next.SortOrder;
|
||||
next.SortOrder = temp;
|
||||
|
||||
if (item.SortOrder == next.SortOrder)
|
||||
{
|
||||
next.SortOrder = item.SortOrder + 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await FaqClient.UpdateAsync(item.Id, item);
|
||||
await FaqClient.UpdateAsync(next.Id, next);
|
||||
Snackbar.Add("순서가 하향되었습니다.", Severity.Success);
|
||||
await LoadAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"순서 조정 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteAsync(Faq item)
|
||||
{
|
||||
var confirmed = await DialogService.ShowMessageBox(
|
||||
"FAQ 삭제",
|
||||
$"'{item.Question}' 항목을 삭제하시겠습니까?",
|
||||
yesText: "삭제", cancelText: "취소");
|
||||
|
||||
if (confirmed != true) return;
|
||||
|
||||
try
|
||||
{
|
||||
var success = await FaqClient.DeleteAsync(item.Id);
|
||||
if (success)
|
||||
{
|
||||
Snackbar.Add("FAQ가 삭제되었습니다.", Severity.Success);
|
||||
await LoadAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("삭제 실패", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
@page "/admin/inquiries/create"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Application.DTOs
|
||||
@using TaxBaik.WasmClient.Components.Admin.Forms
|
||||
@inject IInquiryBrowserClient InquiryClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>문의 등록</PageTitle>
|
||||
|
||||
<AdminCrudPageShell Title="새 문의 등록"
|
||||
Eyebrow="Customer Relations"
|
||||
Subtitle="고객 문의를 등록합니다. (전화, 오프라인 등)"
|
||||
Loading="@false"
|
||||
OnCancel="@GoBack">
|
||||
<MudPaper Class="pa-4 mt-4" Elevation="1">
|
||||
<InquiryForm ButtonText="등록" OnSubmit="HandleCreate" OnCancel="GoBack" />
|
||||
</MudPaper>
|
||||
</AdminCrudPageShell>
|
||||
|
||||
@code {
|
||||
private void GoBack()
|
||||
{
|
||||
Navigation.NavigateTo("/taxbaik/admin/inquiries");
|
||||
}
|
||||
|
||||
private async Task HandleCreate(InquiryForm.InquiryFormModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await InquiryClient.CreateAsync(new SubmitInquiryDto
|
||||
{
|
||||
Name = model.Name,
|
||||
Phone = model.Phone,
|
||||
Email = model.Email,
|
||||
ServiceType = model.ServiceType,
|
||||
Message = model.Message,
|
||||
SuppressNotification = false
|
||||
});
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("문의가 등록되지 않았습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("✅ 문의가 등록되었고 고객에게 알림이 발송되었습니다.", Severity.Success);
|
||||
// 사용자가 성공 메시지를 볼 수 있도록 3초 후에 목록으로 이동
|
||||
await Task.Delay(3000);
|
||||
Navigation.NavigateTo("/taxbaik/admin/inquiries");
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
Snackbar.Add(ex.Message, Severity.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"등록 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
@page "/admin/inquiries/{InquiryId:int}"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Application.Services
|
||||
@using TaxBaik.Web.Services
|
||||
@inject IInquiryBrowserClient InquiryClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>문의 상세</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Inquiry Details</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">문의 상세</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">문의 정보를 확인하고 처리 상태를 관리합니다.</MudText>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@if (inquiry != null)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.ArrowBack"
|
||||
@onclick="@(() => Navigation.NavigateTo("/taxbaik/admin/inquiries"))">
|
||||
문의 목록으로
|
||||
</MudButton>
|
||||
|
||||
<MudGrid Class="mt-4">
|
||||
<MudItem xs="12" md="8">
|
||||
<AdminDetailSection Title="문의 정보">
|
||||
<MudGrid>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">이름</MudText>
|
||||
<MudText>@inquiry.Name</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">연락처</MudText>
|
||||
<MudText>@inquiry.Phone</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">이메일</MudText>
|
||||
<MudText>@(inquiry.Email ?? "-")</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">분야</MudText>
|
||||
<MudText>@inquiry.ServiceType</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">문의 내용</MudText>
|
||||
<MudPaper Class="pa-3 mt-1" Outlined="true">
|
||||
<MudText Style="white-space: pre-wrap;">@inquiry.Message</MudText>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">접수일시</MudText>
|
||||
<MudText>@inquiry.CreatedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm")</MudText>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
</AdminDetailSection>
|
||||
|
||||
<AdminDetailSection Title="담당자 메모" CssClass="pa-4 mt-4">
|
||||
<MudTextField T="string" @bind-Value="adminMemo" Label="내부 메모 (고객에게 미노출)"
|
||||
Lines="4" Variant="Variant.Outlined" />
|
||||
<MudButton Class="mt-2" Variant="Variant.Filled" Color="Color.Primary"
|
||||
OnClick="SaveMemo">메모 저장</MudButton>
|
||||
</AdminDetailSection>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" md="4">
|
||||
<AdminDetailSection Title="처리 상태">
|
||||
<MudStack Spacing="2">
|
||||
@foreach (var (key, label) in InquiryStatusMapper.Labels)
|
||||
{
|
||||
<MudButton Variant="@(inquiry.Status == key ? Variant.Filled : Variant.Outlined)"
|
||||
Color="@StatusColor(key)"
|
||||
FullWidth="true"
|
||||
OnClick="@(() => OnStatusChanged(key))">
|
||||
@label
|
||||
</MudButton>
|
||||
}
|
||||
</MudStack>
|
||||
</AdminDetailSection>
|
||||
|
||||
@if (inquiry.ClientId == null)
|
||||
{
|
||||
<AdminDetailSection Title="고객 카드 생성" CssClass="pa-4 mt-4">
|
||||
<MudText Typo="Typo.body2" Class="mb-3">이 문의를 고객 카드로 등록합니다.</MudText>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Success" FullWidth="true"
|
||||
OnClick="ConvertToClient">
|
||||
고객으로 등록
|
||||
</MudButton>
|
||||
</AdminDetailSection>
|
||||
}
|
||||
else
|
||||
{
|
||||
<AdminDetailSection Title="연결된 고객" CssClass="pa-4 mt-4">
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" FullWidth="true"
|
||||
Href="@($"/taxbaik/admin/clients/{inquiry.ClientId}")">
|
||||
고객 카드 보기
|
||||
</MudButton>
|
||||
</AdminDetailSection>
|
||||
}
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText>문의를 찾을 수 없습니다.</MudText>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public int InquiryId { get; set; }
|
||||
|
||||
private Domain.Entities.Inquiry? inquiry;
|
||||
private string adminMemo = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
inquiry = await InquiryClient.GetByIdAsync(InquiryId);
|
||||
adminMemo = inquiry?.AdminMemo ?? "";
|
||||
}
|
||||
|
||||
private async Task OnStatusChanged(string status)
|
||||
{
|
||||
if (inquiry == null) return;
|
||||
try
|
||||
{
|
||||
var success = await InquiryClient.UpdateStatusAsync(inquiry.Id, status);
|
||||
if (success)
|
||||
{
|
||||
inquiry.Status = status;
|
||||
Snackbar.Add("상태가 변경되었습니다.", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("상태 변경에 실패했습니다.", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveMemo()
|
||||
{
|
||||
if (inquiry == null) return;
|
||||
try
|
||||
{
|
||||
var success = await InquiryClient.UpdateAdminMemoAsync(inquiry.Id, adminMemo);
|
||||
if (success)
|
||||
{
|
||||
inquiry.AdminMemo = adminMemo;
|
||||
Snackbar.Add("메모가 저장되었습니다.", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("메모 저장에 실패했습니다.", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ConvertToClient()
|
||||
{
|
||||
if (inquiry == null) return;
|
||||
try
|
||||
{
|
||||
var clientId = await InquiryClient.ConvertToClientAsync(
|
||||
inquiry.Id,
|
||||
inquiry.Name,
|
||||
inquiry.Phone,
|
||||
inquiry.ServiceType);
|
||||
|
||||
if (clientId > 0)
|
||||
{
|
||||
inquiry.ClientId = clientId;
|
||||
inquiry.Status = InquiryStatusMapper.StatusConsulting;
|
||||
Snackbar.Add("고객 카드가 생성되었습니다.", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("고객 카드 생성에 실패했습니다.", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private Color StatusColor(string status) => status switch
|
||||
{
|
||||
"new" => Color.Default,
|
||||
"consulting" => Color.Info,
|
||||
"contracted" => Color.Success,
|
||||
"rejected" => Color.Error,
|
||||
"closed" => Color.Dark,
|
||||
_ => Color.Default
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
@page "/admin/inquiries/{id:int}/edit"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Application.DTOs
|
||||
@using TaxBaik.WasmClient.Components.Admin.Forms
|
||||
@inject IInquiryBrowserClient InquiryClient
|
||||
@inject NavigationManager Navigation
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
|
||||
<PageTitle>문의 수정</PageTitle>
|
||||
|
||||
<AdminCrudPageShell Title="문의 수정"
|
||||
Eyebrow="Customer Relations"
|
||||
Subtitle="고객 문의 정보를 수정합니다."
|
||||
Loading="@isLoading"
|
||||
SkeletonContent="@EditorSkeleton"
|
||||
OnCancel="@GoBack">
|
||||
@if (inquiry == null)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Class="mt-4">문의를 찾을 수 없습니다.</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudPaper Class="pa-4 mt-4" Elevation="1">
|
||||
<InquiryForm ButtonText="수정" InitialData="formModel" OnSubmit="HandleUpdate" OnCancel="GoBack" IsEditMode="true" />
|
||||
|
||||
<MudDivider Class="my-4" />
|
||||
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" @onclick="DeleteInquiry" Class="mt-2">
|
||||
문의 삭제
|
||||
</MudButton>
|
||||
</MudPaper>
|
||||
}
|
||||
</AdminCrudPageShell>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
private Domain.Entities.Inquiry? inquiry;
|
||||
private InquiryForm.InquiryFormModel? formModel;
|
||||
private bool isLoading = true;
|
||||
|
||||
private RenderFragment EditorSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 5);
|
||||
builder.AddAttribute(2, "Columns", 3);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
inquiry = await InquiryClient.GetByIdAsync(Id);
|
||||
if (inquiry != null)
|
||||
{
|
||||
formModel = new InquiryForm.InquiryFormModel
|
||||
{
|
||||
Name = inquiry.Name,
|
||||
Phone = inquiry.Phone,
|
||||
Email = inquiry.Email,
|
||||
ServiceType = inquiry.ServiceType,
|
||||
Message = inquiry.Message,
|
||||
Status = inquiry.Status,
|
||||
AdminMemo = inquiry.AdminMemo
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"문의 로드 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void GoBack()
|
||||
{
|
||||
Navigation.NavigateTo("/taxbaik/admin/inquiries");
|
||||
}
|
||||
|
||||
private async Task HandleUpdate(InquiryForm.InquiryFormModel model)
|
||||
{
|
||||
if (inquiry == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var updated = await InquiryClient.UpdateAsync(inquiry.Id, new UpdateInquiryDto
|
||||
{
|
||||
Name = model.Name,
|
||||
Phone = model.Phone,
|
||||
Email = model.Email,
|
||||
ServiceType = model.ServiceType,
|
||||
Message = model.Message,
|
||||
Status = model.Status,
|
||||
AdminMemo = model.AdminMemo
|
||||
});
|
||||
|
||||
if (updated == null)
|
||||
{
|
||||
Snackbar.Add("문의 수정에 실패했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
inquiry = updated;
|
||||
formModel = new InquiryForm.InquiryFormModel
|
||||
{
|
||||
Name = inquiry.Name,
|
||||
Phone = inquiry.Phone,
|
||||
Email = inquiry.Email,
|
||||
ServiceType = inquiry.ServiceType,
|
||||
Message = inquiry.Message,
|
||||
Status = inquiry.Status,
|
||||
AdminMemo = inquiry.AdminMemo
|
||||
};
|
||||
|
||||
Snackbar.Add("문의가 수정되었습니다.", Severity.Success);
|
||||
Navigation.NavigateTo("/taxbaik/admin/inquiries");
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
Snackbar.Add(ex.Message, Severity.Error);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"수정 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteInquiry()
|
||||
{
|
||||
if (inquiry == null)
|
||||
return;
|
||||
|
||||
var result = await DialogService.ShowMessageBox(
|
||||
"문의 삭제",
|
||||
"정말 삭제하시겠습니까? 이 작업은 취소할 수 없습니다.",
|
||||
"삭제", "취소");
|
||||
|
||||
if (result != true)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var deleted = await InquiryClient.DeleteAsync(inquiry.Id);
|
||||
if (!deleted)
|
||||
{
|
||||
Snackbar.Add("문의 삭제에 실패했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
Snackbar.Add("문의가 삭제되었습니다.", Severity.Success);
|
||||
Navigation.NavigateTo("/taxbaik/admin/inquiries");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
@page "/admin/inquiries"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Application.Services
|
||||
@using TaxBaik.Web.Services
|
||||
@inject IInquiryBrowserClient InquiryClient
|
||||
|
||||
<PageTitle>문의 관리</PageTitle>
|
||||
|
||||
<AdminPageHeader Title="문의 관리" Eyebrow="Customer Requests" Subtitle="상담 요청을 상태별로 확인하고 후속 조치를 기록합니다.">
|
||||
<ChildContent>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add"
|
||||
Href="/taxbaik/admin/inquiries/create">새 문의 등록</MudButton>
|
||||
</ChildContent>
|
||||
</AdminPageHeader>
|
||||
|
||||
<AdminDataPanel Loading="@isLoading">
|
||||
<MudTabs Rounded="true" Elevation="0" Class="admin-tabs">
|
||||
<MudTabPanel Text="전체">
|
||||
<InquiryTable Inquiries="allInquiries" Status="" />
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="신규">
|
||||
<InquiryTable Inquiries="allInquiries" Status="@InquiryStatusMapper.StatusNew" />
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="상담중">
|
||||
<InquiryTable Inquiries="allInquiries" Status="@InquiryStatusMapper.StatusConsulting" />
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="계약완료">
|
||||
<InquiryTable Inquiries="allInquiries" Status="@InquiryStatusMapper.StatusContracted" />
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="거절">
|
||||
<InquiryTable Inquiries="allInquiries" Status="@InquiryStatusMapper.StatusRejected" />
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="종결">
|
||||
<InquiryTable Inquiries="allInquiries" Status="@InquiryStatusMapper.StatusClosed" />
|
||||
</MudTabPanel>
|
||||
</MudTabs>
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private bool isLoading = true;
|
||||
private IReadOnlyList<Domain.Entities.Inquiry> allInquiries = [];
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
isLoading = true;
|
||||
try
|
||||
{
|
||||
var (items, _) = await InquiryClient.GetPagedAsync(1, 200);
|
||||
allInquiries = items.ToList();
|
||||
}
|
||||
catch
|
||||
{
|
||||
allInquiries = [];
|
||||
}
|
||||
finally
|
||||
{
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@page "/admin/login"
|
||||
@layout TaxBaik.WasmClient.Components.Admin.Layout.BlankLayout
|
||||
@attribute [AllowAnonymous]
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: true))
|
||||
<PageTitle>로그인</PageTitle>
|
||||
<AdminLoginForm />
|
||||
@@ -0,0 +1,18 @@
|
||||
@page "/admin/logout"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@using TaxBaik.Web.Services
|
||||
@inject CustomAuthenticationStateProvider AuthStateProvider
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<PageTitle>로그아웃</PageTitle>
|
||||
|
||||
@code {
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// 사용자 로그아웃
|
||||
await AuthStateProvider.LogoutAsync();
|
||||
|
||||
// 로그인 페이지로 리다이렉트
|
||||
NavigationManager.NavigateTo("/taxbaik/admin/login", forceLoad: true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
@page "/admin/revenue-trackings"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@using TaxBaik.Web.Services.AdminClients
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject IRevenueTrackingBrowserClient RevenueClient
|
||||
@inject IClientBrowserClient ClientClient
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>수익 추적 관리</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">CRM & 세무관리</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">수익 추적 관리</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">청구, 납부, 미수금 상태를 한 화면에서 관리합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OpenCreateDialog" StartIcon="@Icons.Material.Filled.Add">
|
||||
새 청구 추가
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
<AdminDataPanel Loading="@(revenues is null)" SkeletonContent="@RevenueSkeleton">
|
||||
@if (revenues is null)
|
||||
{
|
||||
}
|
||||
else if (revenues.Count == 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Class="mt-4">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Payments" Class="me-2" />
|
||||
청구 기록이 없습니다.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudDataGrid T="RevenueTracking"
|
||||
Items="@revenues"
|
||||
Dense="true"
|
||||
Hover="true"
|
||||
Striped="true"
|
||||
Virtualize="true"
|
||||
RowsPerPage="30"
|
||||
Class="admin-grid">
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.Id" Title="ID" Sortable="true" />
|
||||
<TemplateColumn Title="고객">
|
||||
<CellTemplate>
|
||||
@if (clientMap.TryGetValue(context.Item.ClientId, out var clientName))
|
||||
{
|
||||
<MudLink Href="@($"/taxbaik/admin/clients/{context.Item.ClientId}")" Color="Color.Primary">
|
||||
@clientName
|
||||
</MudLink>
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Property="x => x.InvoiceNumber" Title="청구번호" />
|
||||
<PropertyColumn Property="x => x.InvoiceDate" Title="청구일" Format="yyyy-MM-dd" />
|
||||
<PropertyColumn Property="x => x.Amount" Title="청구액" Format="C" />
|
||||
<TemplateColumn Title="납부여부">
|
||||
<CellTemplate>
|
||||
@if (context.Item.PaymentStatus == "paid")
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Success" Variant="Variant.Filled">납부</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Warning" Variant="Variant.Filled">미납</MudChip>
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="작업" Sortable="false">
|
||||
<CellTemplate>
|
||||
<MudButtonGroup Size="Size.Small" Variant="Variant.Outlined">
|
||||
@if (context.Item.PaymentStatus != "paid")
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.CheckCircle" Color="Color.Success"
|
||||
OnClick="@(async () => await MarkPaid(context.Item.Id))" Title="납부 처리" />
|
||||
}
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error"
|
||||
OnClick="@(async () => await DeleteRevenue(context.Item.Id))" />
|
||||
</MudButtonGroup>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
}
|
||||
</AdminDataPanel>
|
||||
|
||||
<!-- Create Dialog -->
|
||||
<MudDialog @bind-IsVisible="isDialogOpen" Options="new DialogOptions { MaxWidth = MaxWidth.Small, FullWidth = true }">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">새 청구 추가</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudForm @ref="form">
|
||||
<MudSelect T="int" @bind-Value="revenueForm.ClientId" Label="고객" Required="true" Variant="Variant.Outlined" FullWidth="true" Class="mb-4">
|
||||
@foreach (var client in clients)
|
||||
{
|
||||
<MudSelectItem Value="@client.Id">@GetClientDisplayName(client)</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudTextField T="string" @bind-Value="revenueForm.InvoiceNumber" Label="청구번호" Variant="Variant.Outlined" FullWidth="true" Class="mb-4" Required="true" />
|
||||
<MudDatePicker @bind-Date="revenueForm.InvoiceDate" Label="청구일" Variant="Variant.Outlined" FullWidth="true" Class="mb-4" Required="true" />
|
||||
<MudNumericField T="decimal" @bind-Value="revenueForm.Amount" Label="청구액" Variant="Variant.Outlined" FullWidth="true" Class="mb-4" Required="true" />
|
||||
<CommonCodeSelect @bind-Value="revenueForm.ServiceType" Group="REVENUE_SERVICE_TYPE" Label="서비스 유형" Class="mb-4" />
|
||||
<MudDatePicker @bind-Date="revenueForm.DueDate" Label="납부예정일" Variant="Variant.Outlined" FullWidth="true" Class="mb-4" />
|
||||
</MudForm>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="CloseDialog">취소</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="SaveRevenue">저장</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private List<RevenueTracking>? revenues;
|
||||
private List<Client> clients = [];
|
||||
private Dictionary<int, string> clientMap = new();
|
||||
private MudForm? form;
|
||||
private bool isDialogOpen;
|
||||
private RevenueForm revenueForm = new();
|
||||
|
||||
private RenderFragment RevenueSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 5);
|
||||
builder.AddAttribute(2, "Columns", 5);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
revenues = [];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
revenues = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
revenues = await RevenueClient.GetAllAsync();
|
||||
var (clientItems, _) = await ClientClient.GetPagedAsync(pageSize: 1000);
|
||||
clients = clientItems.ToList();
|
||||
clientMap = clients.ToDictionary(c => c.Id, GetClientDisplayName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"데이터 로드 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenCreateDialog()
|
||||
{
|
||||
revenueForm = new RevenueForm
|
||||
{
|
||||
ClientId = clients.FirstOrDefault()?.Id ?? 0,
|
||||
InvoiceDate = DateTime.Today,
|
||||
DueDate = DateTime.Today.AddDays(14)
|
||||
};
|
||||
isDialogOpen = true;
|
||||
}
|
||||
|
||||
private async Task SaveRevenue()
|
||||
{
|
||||
if (form != null)
|
||||
{
|
||||
await form.Validate();
|
||||
if (!form.IsValid)
|
||||
{
|
||||
Snackbar.Add("필수 항목을 입력해주세요.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var newId = await RevenueClient.CreateAsync(
|
||||
revenueForm.ClientId,
|
||||
revenueForm.InvoiceNumber,
|
||||
revenueForm.InvoiceDate ?? DateTime.Now,
|
||||
revenueForm.Amount,
|
||||
revenueForm.ServiceType,
|
||||
revenueForm.DueDate);
|
||||
|
||||
if (newId > 0)
|
||||
{
|
||||
Snackbar.Add("청구가 추가되었습니다.", Severity.Success);
|
||||
CloseDialog();
|
||||
await LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task MarkPaid(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await RevenueClient.MarkPaidAsync(id, DateTime.Now);
|
||||
Snackbar.Add("납부가 처리되었습니다.", Severity.Success);
|
||||
await LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"처리 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteRevenue(int id)
|
||||
{
|
||||
var parameters = new DialogParameters
|
||||
{
|
||||
{ "Title", "삭제 확인" },
|
||||
{ "Message", "이 청구를 삭제하시겠습니까?" }
|
||||
};
|
||||
|
||||
var dialog = await DialogService.ShowAsync<ConfirmDialog>("", parameters);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result?.Canceled ?? true)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await RevenueClient.DeleteAsync(id);
|
||||
Snackbar.Add("청구가 삭제되었습니다.", Severity.Success);
|
||||
await LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseDialog()
|
||||
{
|
||||
isDialogOpen = false;
|
||||
revenueForm = new();
|
||||
}
|
||||
|
||||
private static string GetClientDisplayName(Client client)
|
||||
=> !string.IsNullOrWhiteSpace(client.CompanyName)
|
||||
? client.CompanyName
|
||||
: !string.IsNullOrWhiteSpace(client.Name)
|
||||
? client.Name
|
||||
: $"Client #{client.Id}";
|
||||
private class RevenueForm
|
||||
{
|
||||
public int ClientId { get; set; }
|
||||
public string InvoiceNumber { get; set; } = "";
|
||||
public DateTime? InvoiceDate { get; set; }
|
||||
public decimal Amount { get; set; }
|
||||
public string? ServiceType { get; set; }
|
||||
public DateTime? DueDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
@page "/admin/season-simulator"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Application.Seasonal
|
||||
@using TaxBaik.Application.Services
|
||||
|
||||
<PageTitle>시즌 시뮬레이터</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Season Preview</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">시즌 시뮬레이터</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">날짜를 선택해 홈페이지 시즌 화면이 어떻게 보이는지 미리 확인합니다.</MudText>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="4">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" Class="mb-3">시뮬레이션 날짜</MudText>
|
||||
<MudDatePicker @bind-Date="simulationDate" Label="날짜 선택" DateFormat="yyyy-MM-dd" PickerVariant="PickerVariant.Static" />
|
||||
<MudDivider Class="my-3" />
|
||||
<MudText Typo="Typo.subtitle2" Class="mb-2">연간 세무 캘린더</MudText>
|
||||
@foreach (var season in TaxSeasonCalendar.Seasons)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Size="Size.Small" FullWidth="true"
|
||||
Class="mb-1" Color="Color.Primary"
|
||||
OnClick="@(() => JumpToSeason(season))">
|
||||
@season.StartMonth/@season.StartDay — @season.Name
|
||||
</MudButton>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" md="8">
|
||||
<MudPaper Class="pa-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" Class="mb-1">
|
||||
@(simulationDate?.ToString("yyyy년 MM월 dd일") ?? "날짜를 선택하세요") 홈페이지 미리보기
|
||||
</MudText>
|
||||
@if (activeSeason != null)
|
||||
{
|
||||
<MudChip T="string" Color="Color.Warning" Size="Size.Small" Class="mb-3">
|
||||
@activeSeason.Name 시즌 활성
|
||||
</MudChip>
|
||||
<MudDivider Class="mb-4" />
|
||||
<!-- Hero 섹션 미리보기 -->
|
||||
<div style="background: linear-gradient(135deg, #1a365d 0%, #2a4365 100%); border-radius: 12px; padding: 2rem; color: white; margin-bottom: 1.5rem;">
|
||||
@if (activeSeason.DaysUntilDeadline <= 7 && activeSeason.DaysUntilDeadline >= 0)
|
||||
{
|
||||
<div style="background: #f59e0b; color: #1a202c; display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 700; margin-bottom: 1rem;">
|
||||
D-@activeSeason.DaysUntilDeadline 마감 임박
|
||||
</div>
|
||||
}
|
||||
<div style="font-size: 1.8rem; font-weight: 800; white-space: pre-line; margin-bottom: 0.5rem; line-height: 1.3;">
|
||||
@activeSeason.HeroHeadline
|
||||
</div>
|
||||
<div style="font-size: 0.95rem; color: rgba(255,255,255,0.8); margin-bottom: 1.5rem;">
|
||||
@activeSeason.HeroSubtext
|
||||
</div>
|
||||
<div style="display: flex; gap: 0.75rem; flex-wrap: wrap;">
|
||||
<div style="background: #e53e3e; color: white; padding: 10px 20px; border-radius: 8px; font-weight: 700; font-size: 0.95rem;">
|
||||
@activeSeason.CtaText
|
||||
</div>
|
||||
<div style="background: transparent; border: 2px solid rgba(255,255,255,0.5); color: white; padding: 10px 20px; border-radius: 8px; font-size: 0.95rem;">
|
||||
서비스 안내
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">활성 시즌 키</MudText>
|
||||
<MudText><code>@activeSeason.Key</code></MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">마감까지</MudText>
|
||||
<MudText>
|
||||
@if (activeSeason.DaysUntilDeadline >= 0)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small"
|
||||
Color="@(activeSeason.DaysUntilDeadline <= 7 ? Color.Error : Color.Warning)">
|
||||
D-@activeSeason.DaysUntilDeadline
|
||||
</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>마감 후 @(-activeSeason.DaysUntilDeadline)일</span>
|
||||
}
|
||||
</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">포커스 서비스</MudText>
|
||||
<MudText>@activeSeason.FocusService</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="6">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">블로그 카테고리</MudText>
|
||||
<MudText>@activeSeason.RelatedCategorySlug</MudText>
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudText Typo="Typo.subtitle2" Color="Color.Secondary">긴박감 배지 문구</MudText>
|
||||
<MudText><code>@activeSeason.UrgencyBadge</code></MudText>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudAlert Severity="Severity.Info">
|
||||
선택한 날짜(@(simulationDate?.ToString("MM월 dd일") ?? "-"))는 시즌 비활성 기간입니다.
|
||||
홈페이지는 기본 Hero를 표시합니다.
|
||||
</MudAlert>
|
||||
<div style="background: linear-gradient(135deg, #1a365d 0%, #2a4365 100%); border-radius: 12px; padding: 2rem; color: white; margin-top: 1.5rem;">
|
||||
<div style="font-size: 1.8rem; font-weight: 800; margin-bottom: 0.5rem;">
|
||||
사업자 세금, 부동산,<br/>가족자산까지
|
||||
</div>
|
||||
<div style="font-size: 0.95rem; color: rgba(255,255,255,0.8); margin-bottom: 1.5rem;">
|
||||
세무사·부동산중개사·보험설계사 자격 보유 | 온라인 맞춤 상담
|
||||
</div>
|
||||
<div style="background: #e53e3e; color: white; display: inline-block; padding: 10px 20px; border-radius: 8px; font-weight: 700;">
|
||||
무료 상담 신청
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
<MudPaper Class="pa-4 mt-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" Class="mb-3">연간 시즌 타임라인</MudText>
|
||||
<MudSimpleTable Dense="true">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>기간</th>
|
||||
<th>시즌</th>
|
||||
<th>블로그 카테고리</th>
|
||||
<th>상태</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var s in TaxSeasonCalendar.Seasons)
|
||||
{
|
||||
var isActive = activeSeason?.Key == s.Key;
|
||||
<tr style="@(isActive ? "background: rgba(66,153,225,0.1);" : "")">
|
||||
<td style="white-space: nowrap;">
|
||||
@s.StartMonth/@s.StartDay ~ @s.EndMonth/@s.EndDay
|
||||
</td>
|
||||
<td>@s.Name</td>
|
||||
<td><code style="font-size:0.8rem;">@s.RelatedCategorySlug</code></td>
|
||||
<td>
|
||||
@if (isActive)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Success">활성</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span style="color: #a0aec0; font-size: 0.85rem;">비활성</span>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</MudSimpleTable>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
@code {
|
||||
private DateTime? simulationDate = DateTime.Today;
|
||||
private CurrentSeasonDto? activeSeason;
|
||||
|
||||
protected override void OnInitialized() => ComputeSeason();
|
||||
|
||||
private void ComputeSeason()
|
||||
{
|
||||
if (simulationDate == null) { activeSeason = null; return; }
|
||||
var date = simulationDate.Value;
|
||||
var season = TaxSeasonCalendar.Seasons.FirstOrDefault(s =>
|
||||
{
|
||||
var start = new DateTime(date.Year, s.StartMonth, s.StartDay);
|
||||
var endYear = (s.EndMonth < s.StartMonth) ? date.Year + 1 : date.Year;
|
||||
var end = new DateTime(endYear, s.EndMonth, s.EndDay);
|
||||
return date >= start && date <= end;
|
||||
});
|
||||
|
||||
if (season == null) { activeSeason = null; return; }
|
||||
|
||||
var endYearCalc = (season.EndMonth < season.StartMonth) ? date.Year + 1 : date.Year;
|
||||
var deadline = new DateTime(endYearCalc, season.EndMonth, season.EndDay);
|
||||
var ddays = (deadline.Date - date.Date).Days;
|
||||
|
||||
var badge = ddays <= 7 && ddays >= 0
|
||||
? season.UrgencyBadge.Replace("{n}", ddays.ToString())
|
||||
: season.UrgencyBadge;
|
||||
|
||||
activeSeason = new CurrentSeasonDto
|
||||
{
|
||||
Key = season.Key,
|
||||
Name = season.Name,
|
||||
HeroHeadline = season.HeroHeadline,
|
||||
HeroSubtext = season.HeroSubtext,
|
||||
UrgencyBadge = badge,
|
||||
FocusService = season.FocusService,
|
||||
RelatedCategorySlug = season.RelatedCategorySlug,
|
||||
CtaText = season.CtaText,
|
||||
DaysUntilDeadline = ddays,
|
||||
Deadline = deadline
|
||||
};
|
||||
}
|
||||
|
||||
private void JumpToSeason(TaxSeason season)
|
||||
{
|
||||
simulationDate = new DateTime(DateTime.Today.Year, season.StartMonth, season.StartDay);
|
||||
ComputeSeason();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
@page "/admin/settings"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Collections.Generic
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.Domain.Interfaces
|
||||
@inject IApiClient ApiClient
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>설정</PageTitle>
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.Large" Class="pa-6">
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">System</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">설정</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">공개 사이트 연락처와 관리자 계정 보안을 관리합니다.</MudText>
|
||||
</div>
|
||||
</section>
|
||||
</MudContainer>
|
||||
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="7">
|
||||
<MudPaper Class="admin-surface" Elevation="0">
|
||||
<div class="admin-section-header compact">
|
||||
<div>
|
||||
<MudText Typo="Typo.h6">사이트 정보</MudText>
|
||||
<MudText Typo="Typo.body2">홈페이지와 문의 알림에 노출되는 기본 정보입니다.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
<MudForm>
|
||||
<MudTextField @bind-Value="phone" Label="전화번호"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="email" Label="이메일"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="kakaoUrl" Label="카카오채널 URL"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="instagramUrl" Label="인스타그램"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.Save"
|
||||
@onclick="SaveSettings">사이트 정보 저장</MudButton>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<MudItem xs="12" md="5">
|
||||
<MudPaper Class="admin-surface admin-account-card" Elevation="0">
|
||||
<div class="admin-section-header compact">
|
||||
<div>
|
||||
<MudText Typo="Typo.h6">계정 관리</MudText>
|
||||
<MudText Typo="Typo.body2">비밀번호는 12자 이상으로 관리합니다.</MudText>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudForm>
|
||||
<MudTextField @bind-Value="currentPassword" Label="현재 비밀번호" InputType="InputType.Password"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="newPassword" Label="새 비밀번호" InputType="InputType.Password"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudTextField @bind-Value="confirmNewPassword" Label="새 비밀번호 확인" InputType="InputType.Password"
|
||||
Variant="Variant.Outlined" Class="mb-4" />
|
||||
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
Disabled="@isChangingPassword"
|
||||
StartIcon="@Icons.Material.Filled.LockReset"
|
||||
@onclick="ChangePassword">
|
||||
@(isChangingPassword ? "변경 중..." : "비밀번호 변경")
|
||||
</MudButton>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
@code {
|
||||
private string phone = "010-4122-8268";
|
||||
private string email = "taxbaik5668@gmail.com";
|
||||
private string kakaoUrl = "http://pf.kakao.com/_xoxchTX";
|
||||
private string instagramUrl = "https://www.instagram.com/taxtory5668/";
|
||||
private string currentPassword = "";
|
||||
private string newPassword = "";
|
||||
private string confirmNewPassword = "";
|
||||
private bool isChangingPassword;
|
||||
private bool isLoadingSettings;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadSettingsAsync();
|
||||
}
|
||||
|
||||
private async Task LoadSettingsAsync()
|
||||
{
|
||||
isLoadingSettings = true;
|
||||
|
||||
try
|
||||
{
|
||||
var settings = await ApiClient.GetAsync<Dictionary<string, string>>("site-settings");
|
||||
if (settings is null || settings.Count == 0)
|
||||
return;
|
||||
|
||||
if (settings.TryGetValue("PhoneNumber", out var loadedPhone) && !string.IsNullOrWhiteSpace(loadedPhone))
|
||||
phone = loadedPhone;
|
||||
|
||||
if (settings.TryGetValue("EmailAddress", out var loadedEmail) && !string.IsNullOrWhiteSpace(loadedEmail))
|
||||
email = loadedEmail;
|
||||
|
||||
if (settings.TryGetValue("KakaoChannelUrl", out var loadedKakao) && !string.IsNullOrWhiteSpace(loadedKakao))
|
||||
kakaoUrl = loadedKakao;
|
||||
|
||||
if (settings.TryGetValue("InstagramUrl", out var loadedInstagram) && !string.IsNullOrWhiteSpace(loadedInstagram))
|
||||
instagramUrl = loadedInstagram;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Snackbar.Add("사이트 설정을 불러오지 못했습니다.", Severity.Warning);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isLoadingSettings = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveSettings()
|
||||
{
|
||||
if (isLoadingSettings)
|
||||
return;
|
||||
|
||||
var response = await ApiClient.PutAsync<SaveSettingsResponse>("site-settings", new
|
||||
{
|
||||
Phone = phone,
|
||||
Email = email,
|
||||
KakaoUrl = kakaoUrl,
|
||||
InstagramUrl = instagramUrl
|
||||
});
|
||||
|
||||
if (response?.Message is null)
|
||||
{
|
||||
Snackbar.Add("설정 저장에 실패했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add(response.Message, Severity.Success);
|
||||
}
|
||||
|
||||
private async Task ChangePassword()
|
||||
{
|
||||
if (isChangingPassword)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(currentPassword) || string.IsNullOrWhiteSpace(newPassword))
|
||||
{
|
||||
Snackbar.Add("현재 비밀번호와 새 비밀번호를 입력하세요.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPassword != confirmNewPassword)
|
||||
{
|
||||
Snackbar.Add("새 비밀번호 확인이 일치하지 않습니다.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
isChangingPassword = true;
|
||||
|
||||
try
|
||||
{
|
||||
var response = await ApiClient.PostAsync<ChangePasswordResponse>("auth/change-password", new
|
||||
{
|
||||
CurrentPassword = currentPassword,
|
||||
NewPassword = newPassword
|
||||
});
|
||||
|
||||
if (response?.Message == null)
|
||||
{
|
||||
Snackbar.Add("비밀번호 변경에 실패했습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add(response.Message, Severity.Success);
|
||||
currentPassword = "";
|
||||
newPassword = "";
|
||||
confirmNewPassword = "";
|
||||
}
|
||||
catch
|
||||
{
|
||||
Snackbar.Add("비밀번호 변경 중 오류가 발생했습니다.", Severity.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isChangingPassword = false;
|
||||
}
|
||||
}
|
||||
|
||||
private class ChangePasswordResponse
|
||||
{
|
||||
public string Message { get; set; } = "";
|
||||
}
|
||||
|
||||
private class SaveSettingsResponse
|
||||
{
|
||||
public string Message { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
@page "/admin/tax-filing-schedules"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@using TaxBaik.Web.Services.AdminClients
|
||||
@using TaxBaik.Domain.Entities
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject ITaxFilingScheduleBrowserClient TaxFilingClient
|
||||
@inject IClientBrowserClient ClientClient
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>신고 일정</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">CRM & 세무관리</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">신고 일정</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">고객별 마감일과 처리 상태를 한 화면에서 관리합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="PrepareCreate" StartIcon="@Icons.Material.Filled.Add" id="btn-add-schedule">
|
||||
새 일정 추가
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
<AdminDataPanel Loading="@(schedules is null)" SkeletonContent="@ScheduleSkeleton">
|
||||
@if (schedules is null)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudGrid Spacing="2" Class="mt-2">
|
||||
<!-- Left: Dense Grid List -->
|
||||
<MudItem XS="12" MD="8">
|
||||
@if (schedules.Count == 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info">
|
||||
<MudIcon Icon="@Icons.Material.Filled.EventBusy" Class="me-2" />
|
||||
신고 일정이 없습니다.
|
||||
</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudDataGrid T="TaxFilingSchedule"
|
||||
Items="@schedules"
|
||||
Dense="true"
|
||||
Hover="true"
|
||||
Striped="true"
|
||||
Virtualize="true"
|
||||
RowsPerPage="30"
|
||||
SelectedItem="@selectedSchedule"
|
||||
SelectedItemChanged="OnRowSelected"
|
||||
Class="admin-grid">
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.Id" Title="ID" Sortable="true" />
|
||||
<TemplateColumn Title="고객">
|
||||
<CellTemplate>
|
||||
@if (clientMap.TryGetValue(context.Item.ClientId, out var clientName))
|
||||
{
|
||||
@clientName
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Property="x => x.FilingType" Title="신고 유형" />
|
||||
<TemplateColumn Title="마감일">
|
||||
<CellTemplate>
|
||||
@{
|
||||
var effectiveDueDate = BusinessDayCalculator.GetEffectiveDueDate(DateOnly.FromDateTime(context.Item.DueDate));
|
||||
var daysLeft = BusinessDayCalculator.GetDday(DateOnly.FromDateTime(context.Item.DueDate));
|
||||
var statusColor = daysLeft < 0 ? Color.Error : daysLeft <= 7 ? Color.Warning : Color.Success;
|
||||
}
|
||||
<MudChip Size="Size.Small" Color="@statusColor" Variant="Variant.Filled">
|
||||
@effectiveDueDate.ToDateTime(TimeOnly.MinValue).ToString("yyyy-MM-dd")
|
||||
@if (daysLeft >= 0)
|
||||
{
|
||||
<span class="ms-1">(D-@daysLeft)</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="ms-1">(마감 @Math.Abs(daysLeft)일 경과)</span>
|
||||
}
|
||||
</MudChip>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Property="x => x.FilingYear" Title="신고연도" />
|
||||
<TemplateColumn Title="상태">
|
||||
<CellTemplate>
|
||||
@if (context.Item.Status == "completed")
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Success" Variant="Variant.Filled">완료</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip Size="Size.Small" Color="Color.Default" Variant="Variant.Outlined">대기</MudChip>
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="작업" Sortable="false">
|
||||
<CellTemplate>
|
||||
<MudButtonGroup Size="Size.Small" Variant="Variant.Outlined">
|
||||
@if (context.Item.Status != "completed")
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.CheckCircle"
|
||||
Color="Color.Success"
|
||||
OnClick="@(async () => await CompleteSchedule(context.Item.Id))"
|
||||
Title="완료" />
|
||||
}
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
||||
Color="Color.Error"
|
||||
OnClick="@(async () => await DeleteSchedule(context.Item.Id))"
|
||||
Title="삭제" />
|
||||
</MudButtonGroup>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
}
|
||||
</MudItem>
|
||||
|
||||
<!-- Right: Detail Form Panel (Inline Editor) -->
|
||||
<MudItem XS="12" MD="4">
|
||||
<MudPaper Class="pa-4 admin-surface admin-editor-panel" Elevation="0" Style="border: 1px solid var(--border-color); min-height: 400px;">
|
||||
<div class="d-flex align-center justify-space-between mb-4">
|
||||
<MudText Typo="Typo.h6" Class="font-weight-bold">@(isEditMode ? "신고 일정 상세" : "새 신고 일정 추가")</MudText>
|
||||
@if (isEditMode)
|
||||
{
|
||||
<MudButton Size="Size.Small" Variant="Variant.Outlined" Color="Color.Secondary" OnClick="PrepareCreate">
|
||||
새로 작성
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
<MudForm @ref="form">
|
||||
<MudSelect T="int?"
|
||||
@bind-Value="scheduleForm.ClientId"
|
||||
Label="고객"
|
||||
Required="true"
|
||||
Variant="Variant.Outlined"
|
||||
FullWidth="@true"
|
||||
Class="mb-3"
|
||||
RequiredError="고객을 선택하세요."
|
||||
Disabled="@isEditMode">
|
||||
@foreach (var client in clients)
|
||||
{
|
||||
<MudSelectItem Value="@((int?)client.Id)">@GetClientDisplayName(client)</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<CommonCodeSelect @bind-Value="scheduleForm.FilingType" Group="FILING_TYPE" Label="신고 유형" Class="mb-3" Required="true" />
|
||||
<MudDatePicker @bind-Date="scheduleForm.DueDate" Label="마감일" Variant="Variant.Outlined" FullWidth="@true" Class="mb-3" Required="true" />
|
||||
<MudNumericField T="int" @bind-Value="scheduleForm.FilingYear" Label="신고연도" Variant="Variant.Outlined" FullWidth="@true" Class="mb-4" Required="true" />
|
||||
|
||||
<div class="d-flex justify-end gap-2">
|
||||
@if (isEditMode && selectedSchedule?.Status != "completed")
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Success" OnClick="@(async () => await CompleteSchedule(selectedSchedule?.Id ?? 0))">완료 처리</MudButton>
|
||||
}
|
||||
@if (isEditMode)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="@(async () => await DeleteSchedule(selectedSchedule?.Id ?? 0))">삭제</MudButton>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SaveSchedule" id="btn-save-schedule">저장</MudButton>
|
||||
}
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
}
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private List<TaxFilingSchedule>? schedules;
|
||||
private List<Client> clients = [];
|
||||
private Dictionary<int, string> clientMap = new();
|
||||
private MudForm? form;
|
||||
private bool isEditMode;
|
||||
private TaxFilingSchedule? selectedSchedule;
|
||||
private TaxFilingScheduleForm scheduleForm = new();
|
||||
|
||||
private RenderFragment ScheduleSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 6);
|
||||
builder.AddAttribute(2, "Columns", 4);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadData();
|
||||
PrepareCreate();
|
||||
}
|
||||
else
|
||||
{
|
||||
schedules = [];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
schedules = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
schedules = await TaxFilingClient.GetAllAsync();
|
||||
var (clientItems, _) = await ClientClient.GetPagedAsync(pageSize: 1000);
|
||||
clients = clientItems.ToList();
|
||||
clientMap = clients.ToDictionary(c => c.Id, GetClientDisplayName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"데이터 로드 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareCreate()
|
||||
{
|
||||
selectedSchedule = null;
|
||||
isEditMode = false;
|
||||
scheduleForm = new TaxFilingScheduleForm
|
||||
{
|
||||
FilingYear = DateTime.Now.Year,
|
||||
DueDate = DateTime.Today,
|
||||
ClientId = clients.FirstOrDefault()?.Id,
|
||||
FilingType = string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
private void OnRowSelected(TaxFilingSchedule schedule)
|
||||
{
|
||||
if (schedule == null) return;
|
||||
selectedSchedule = schedule;
|
||||
isEditMode = true;
|
||||
scheduleForm = new TaxFilingScheduleForm
|
||||
{
|
||||
ClientId = schedule.ClientId,
|
||||
FilingType = schedule.FilingType,
|
||||
DueDate = schedule.DueDate,
|
||||
FilingYear = schedule.FilingYear
|
||||
};
|
||||
}
|
||||
|
||||
private async Task SaveSchedule()
|
||||
{
|
||||
if (form != null)
|
||||
{
|
||||
await form.Validate();
|
||||
if (!form.IsValid)
|
||||
{
|
||||
Snackbar.Add("필수 항목을 입력해주세요.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (scheduleForm.ClientId == null) return;
|
||||
var newId = await TaxFilingClient.CreateAsync(
|
||||
scheduleForm.ClientId.Value,
|
||||
scheduleForm.FilingType,
|
||||
scheduleForm.DueDate ?? DateTime.Today,
|
||||
scheduleForm.FilingYear);
|
||||
|
||||
if (newId > 0)
|
||||
{
|
||||
Snackbar.Add("신고 일정이 추가되었습니다.", Severity.Success);
|
||||
PrepareCreate();
|
||||
await LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("등록에 실패했습니다.", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CompleteSchedule(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await TaxFilingClient.MarkCompletedAsync(id);
|
||||
Snackbar.Add("신고 일정이 완료 처리되었습니다.", Severity.Success);
|
||||
if (selectedSchedule?.Id == id)
|
||||
{
|
||||
PrepareCreate();
|
||||
}
|
||||
await LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"처리 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteSchedule(int id)
|
||||
{
|
||||
var parameters = new DialogParameters
|
||||
{
|
||||
{ "Title", "삭제 확인" },
|
||||
{ "Message", "이 신고 일정을 삭제하시겠습니까?" }
|
||||
};
|
||||
|
||||
var dialog = await DialogService.ShowAsync<ConfirmDialog>("", parameters);
|
||||
var result = await dialog.Result;
|
||||
if (result?.Canceled ?? true)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await TaxFilingClient.DeleteAsync(id);
|
||||
Snackbar.Add("신고 일정이 삭제되었습니다.", Severity.Success);
|
||||
if (selectedSchedule?.Id == id)
|
||||
{
|
||||
PrepareCreate();
|
||||
}
|
||||
await LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetClientDisplayName(Client client)
|
||||
=> !string.IsNullOrWhiteSpace(client.CompanyName)
|
||||
? client.CompanyName
|
||||
: !string.IsNullOrWhiteSpace(client.Name)
|
||||
? client.Name
|
||||
: $"Client #{client.Id}";
|
||||
|
||||
private class TaxFilingScheduleForm
|
||||
{
|
||||
public int? ClientId { get; set; }
|
||||
public string FilingType { get; set; } = "";
|
||||
public DateTime? DueDate { get; set; }
|
||||
public int FilingYear { get; set; } = DateTime.Now.Year;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.Domain.Entities
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject ITaxFilingBrowserClient FilingClient
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
@if (Filings == null || Filings.Count == 0)
|
||||
{
|
||||
<MudText Class="pa-4" Color="Color.Secondary">항목이 없습니다.</MudText>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="Filings" Hover="true" Dense="true" Class="mt-2">
|
||||
<HeaderContent>
|
||||
<MudTh>고객</MudTh>
|
||||
<MudTh>신고 유형</MudTh>
|
||||
<MudTh>기한</MudTh>
|
||||
<MudTh>D-day</MudTh>
|
||||
<MudTh>메모</MudTh>
|
||||
<MudTh>처리</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>@context.ClientName</MudTd>
|
||||
<MudTd>@context.FilingType</MudTd>
|
||||
<MudTd>@BusinessDayCalculator.GetEffectiveDueDate(DateOnly.FromDateTime(context.DueDate)).ToDateTime(TimeOnly.MinValue).ToString("yyyy-MM-dd")</MudTd>
|
||||
<MudTd>
|
||||
@{
|
||||
var dday = BusinessDayCalculator.GetDday(DateOnly.FromDateTime(context.DueDate));
|
||||
}
|
||||
@if (dday < 0)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Error">D+@(-dday)</MudChip>
|
||||
}
|
||||
else if (dday <= 7)
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Warning">D-@dday</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudText Typo="Typo.body2">D-@dday</MudText>
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd>@(context.Memo ?? "")</MudTd>
|
||||
<MudTd>
|
||||
@if (context.Status == "pending")
|
||||
{
|
||||
<MudButton Size="Size.Small" Variant="Variant.Filled" Color="Color.Success"
|
||||
OnClick="@(() => MarkFiled(context))">완료</MudButton>
|
||||
}
|
||||
else if (context.Status == "filed")
|
||||
{
|
||||
<MudChip T="string" Size="Size.Small" Color="Color.Success">완료</MudChip>
|
||||
}
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Size="Size.Small" Color="Color.Error"
|
||||
OnClick="@(() => DeleteFiling(context.Id))" />
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public List<TaxFiling>? Filings { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnStatusChange { get; set; }
|
||||
|
||||
private async Task MarkFiled(TaxFiling filing)
|
||||
{
|
||||
try
|
||||
{
|
||||
filing.Status = "filed";
|
||||
var result = await FilingClient.UpdateAsync(filing.Id, filing);
|
||||
if (result != null)
|
||||
{
|
||||
Snackbar.Add("신고 완료 처리되었습니다.", Severity.Success);
|
||||
await OnStatusChange.InvokeAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("처리 실패", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteFiling(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var success = await FilingClient.DeleteAsync(id);
|
||||
if (success)
|
||||
{
|
||||
Snackbar.Add("삭제되었습니다.", Severity.Info);
|
||||
await OnStatusChange.InvokeAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("삭제 실패", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
@page "/admin/tax-filings"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@attribute [Authorize]
|
||||
@using TaxBaik.Web.Services
|
||||
@using TaxBaik.Domain.Entities
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject ITaxFilingBrowserClient FilingClient
|
||||
@inject IClientBrowserClient ClientClient
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>신고 일정 관리</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">Tax Schedule</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">신고 일정</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">고객별 세금 신고 마감일을 관리하고 완료 처리합니다.</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary"
|
||||
OnClick="@(() => showAddForm = !showAddForm)"
|
||||
StartIcon="@Icons.Material.Filled.Add">
|
||||
일정 추가
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
@if (showAddForm)
|
||||
{
|
||||
<MudPaper Class="pa-4 mb-4" Elevation="1">
|
||||
<MudText Typo="Typo.h6" Class="mb-3">새 신고 일정</MudText>
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem xs="12" sm="6" md="4">
|
||||
<MudAutocomplete T="Domain.Entities.Client" @bind-Value="selectedClient"
|
||||
Label="고객 검색 *"
|
||||
SearchFunc="SearchClients"
|
||||
ToStringFunc="@(c => c == null ? "" : $"{c.Name} {c.CompanyName ?? ""}")"
|
||||
Variant="Variant.Outlined" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6" md="4">
|
||||
<CommonCodeSelect @bind-Value="newFilingType" Group="FILING_TYPE" Label="신고 유형 *" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" sm="6" md="4">
|
||||
<MudDatePicker @bind-Date="newDueDate" Label="신고 기한 *" DateFormat="yyyy-MM-dd" />
|
||||
</MudItem>
|
||||
<MudItem xs="12">
|
||||
<MudTextField T="string" @bind-Value="newMemo" Label="메모" Variant="Variant.Outlined" />
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
<MudStack Row="true" Class="mt-3" Spacing="2">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="AddFiling">저장</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" OnClick="@(() => showAddForm = false)">취소</MudButton>
|
||||
</MudStack>
|
||||
</MudPaper>
|
||||
}
|
||||
|
||||
<MudPaper Class="admin-surface" Elevation="0">
|
||||
<MudTabs Rounded="true" Elevation="0" Class="admin-tabs">
|
||||
<MudTabPanel Text="신고 예정">
|
||||
<FilingTable Filings="@pending" OnStatusChange="Reload" />
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="신고 완료">
|
||||
<FilingTable Filings="@filed" OnStatusChange="Reload" />
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="기한 초과">
|
||||
<FilingTable Filings="@overdue" OnStatusChange="Reload" />
|
||||
</MudTabPanel>
|
||||
</MudTabs>
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
private List<Domain.Entities.TaxFiling> pending = [];
|
||||
private List<Domain.Entities.TaxFiling> filed = [];
|
||||
private List<Domain.Entities.TaxFiling> overdue = [];
|
||||
|
||||
private bool showAddForm;
|
||||
private Domain.Entities.Client? selectedClient;
|
||||
private string newFilingType = "";
|
||||
private DateTime? newDueDate = DateTime.Today.AddDays(30);
|
||||
private string newMemo = "";
|
||||
|
||||
protected override async Task OnInitializedAsync() => await Reload();
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
}
|
||||
|
||||
private async Task Reload()
|
||||
{
|
||||
try
|
||||
{
|
||||
var all = (await FilingClient.GetUpcomingAsync(365)).ToList();
|
||||
pending = all.Where(x => x.Status == "pending").ToList();
|
||||
filed = all.Where(x => x.Status == "filed").ToList();
|
||||
overdue = all.Where(x => x.Status == "overdue").ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<Client>> SearchClients(string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
var (items, _) = await ClientClient.GetPagedAsync(1, 100, search: value);
|
||||
return items;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetClientDisplayName(Client client)
|
||||
=> !string.IsNullOrWhiteSpace(client.CompanyName)
|
||||
? client.CompanyName
|
||||
: !string.IsNullOrWhiteSpace(client.Name)
|
||||
? client.Name
|
||||
: $"Client #{client.Id}";
|
||||
private async Task AddFiling()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (selectedClient == null)
|
||||
{
|
||||
Snackbar.Add("고객을 선택하세요.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
var filing = new TaxFiling
|
||||
{
|
||||
ClientId = selectedClient.Id,
|
||||
FilingType = newFilingType,
|
||||
DueDate = newDueDate?.ToUniversalTime() ?? DateTime.UtcNow,
|
||||
Status = "pending",
|
||||
Memo = string.IsNullOrWhiteSpace(newMemo) ? null : newMemo
|
||||
};
|
||||
var result = await FilingClient.CreateAsync(filing);
|
||||
if (result != null)
|
||||
{
|
||||
showAddForm = false;
|
||||
Snackbar.Add("신고 일정이 추가되었습니다.", Severity.Success);
|
||||
await Reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add("추가 실패", Severity.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"오류: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
@page "/admin/tax-profiles"
|
||||
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
|
||||
@using TaxBaik.Web.Services.AdminClients
|
||||
@using TaxBaik.WasmClient.Components.Admin.Shared
|
||||
@inject ITaxProfileBrowserClient TaxProfileClient
|
||||
@inject IClientBrowserClient ClientClient
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
@attribute [Authorize]
|
||||
|
||||
<PageTitle>세무 프로필</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">CRM & 세무관리</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">세무 프로필</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">고객별 세무 프로필, 신고 일정, 위험도 추적</MudText>
|
||||
</div>
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="PrepareCreate" StartIcon="@Icons.Material.Filled.Add" id="btn-add-profile">
|
||||
새 프로필 추가
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
<AdminDataPanel Loading="@(profiles == null)" SkeletonContent="@ProfileSkeleton">
|
||||
@if (profiles == null)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudGrid Spacing="2" Class="mt-2">
|
||||
<!-- Left: Dense Grid List -->
|
||||
<MudItem XS="12" MD="8">
|
||||
@if (profiles.Count == 0)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info">세무 프로필이 없습니다.</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudDataGrid T="TaxProfile"
|
||||
Items="@profiles"
|
||||
Dense="true"
|
||||
Hover="true"
|
||||
Striped="true"
|
||||
Virtualize="true"
|
||||
RowsPerPage="30"
|
||||
SelectedItem="@selectedProfile"
|
||||
SelectedItemChanged="OnRowSelected"
|
||||
Class="admin-grid">
|
||||
<Columns>
|
||||
<PropertyColumn Property="x => x.Id" Title="ID" Sortable="true" />
|
||||
<TemplateColumn Title="고객">
|
||||
<CellTemplate>
|
||||
@if (clientMap.TryGetValue(context.Item.ClientId, out var clientName))
|
||||
{
|
||||
@clientName
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Property="x => x.BusinessType" Title="사업 유형" />
|
||||
<TemplateColumn Title="위험도">
|
||||
<CellTemplate>
|
||||
<MudChip Size="Size.Small" Color="@GetRiskColor(context.Item.TaxRiskLevel)" Variant="Variant.Filled">
|
||||
@context.Item.TaxRiskLevel
|
||||
</MudChip>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="다음 신고">
|
||||
<CellTemplate>
|
||||
@if (context.Item.NextFilingDueDate.HasValue)
|
||||
{
|
||||
@context.Item.NextFilingDueDate.Value.ToString("yyyy-MM-dd")
|
||||
}
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<TemplateColumn Title="작업" Sortable="false">
|
||||
<CellTemplate>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" Size="Size.Small" OnClick="@(async () => await DeleteProfile(context.Item.Id))" />
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
}
|
||||
</MudItem>
|
||||
|
||||
<!-- Right: Detail Form Panel (Inline Editor) -->
|
||||
<MudItem XS="12" MD="4">
|
||||
<MudPaper Class="pa-4 admin-surface admin-editor-panel" Elevation="0" Style="border: 1px solid var(--border-color); min-height: 400px;">
|
||||
<div class="d-flex align-center justify-space-between mb-4">
|
||||
<MudText Typo="Typo.h6" Class="font-weight-bold">@(isEditMode ? "세무 프로필 수정" : "새 세무 프로필 추가")</MudText>
|
||||
@if (isEditMode)
|
||||
{
|
||||
<MudButton Size="Size.Small" Variant="Variant.Outlined" Color="Color.Secondary" OnClick="PrepareCreate">
|
||||
새로 작성
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
<MudForm @ref="form">
|
||||
<MudSelect T="int?" @bind-Value="profileForm.ClientId" Label="고객" Required="true" Variant="Variant.Outlined" FullWidth="@true" Class="mb-3" RequiredError="고객을 선택하세요." Disabled="@isEditMode">
|
||||
@foreach (var client in clients)
|
||||
{
|
||||
<MudSelectItem Value="@((int?)client.Id)">@GetClientDisplayName(client)</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<CommonCodeSelect @bind-Value="profileForm.BusinessType" Group="BUSINESS_TYPE" Label="사업 유형" Class="mb-3" Required="true" />
|
||||
<CommonCodeSelect @bind-Value="profileForm.TaxRiskLevel" Group="TAX_RISK_LEVEL" Label="위험도" Class="mb-3" />
|
||||
<MudDatePicker @bind-Date="profileForm.NextFilingDueDate" Label="다음 신고 예정일" Variant="Variant.Outlined" FullWidth="@true" Class="mb-3" />
|
||||
<MudTextField T="string" @bind-Value="profileForm.SpecialNotes" Label="특수 사항" Variant="Variant.Outlined" FullWidth="@true" Lines="3" Class="mb-4" />
|
||||
|
||||
<div class="d-flex justify-end gap-2">
|
||||
@if (isEditMode)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Error" OnClick="@(async () => await DeleteProfile(selectedProfile?.Id ?? 0))">삭제</MudButton>
|
||||
}
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SaveProfile" id="btn-save-profile">저장</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
}
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[CascadingParameter]
|
||||
private Task<AuthenticationState>? AuthStateTask { get; set; }
|
||||
|
||||
private List<TaxProfile>? profiles;
|
||||
private List<Client> clients = [];
|
||||
private Dictionary<int, string> clientMap = new();
|
||||
private List<CommonCode> riskLevels = [];
|
||||
private MudForm? form;
|
||||
private bool isEditMode;
|
||||
private TaxProfile? selectedProfile;
|
||||
private TaxProfileForm profileForm = new();
|
||||
|
||||
private RenderFragment ProfileSkeleton => builder =>
|
||||
{
|
||||
builder.OpenComponent<AdminSkeletonRows>(0);
|
||||
builder.AddAttribute(1, "Rows", 6);
|
||||
builder.AddAttribute(2, "Columns", 4);
|
||||
builder.CloseComponent();
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
if (AuthStateTask != null)
|
||||
{
|
||||
var authState = await AuthStateTask;
|
||||
if (authState.User.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
await LoadData();
|
||||
PrepareCreate();
|
||||
}
|
||||
else
|
||||
{
|
||||
profiles = [];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
profiles = [];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
profiles = await TaxProfileClient.GetAllAsync();
|
||||
var (clientItems, _) = await ClientClient.GetPagedAsync(pageSize: 1000);
|
||||
clients = clientItems.ToList();
|
||||
clientMap = clients.ToDictionary(c => c.Id, GetClientDisplayName);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"데이터 로드 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareCreate()
|
||||
{
|
||||
selectedProfile = null;
|
||||
isEditMode = false;
|
||||
profileForm = new TaxProfileForm
|
||||
{
|
||||
ClientId = clients.FirstOrDefault()?.Id,
|
||||
TaxRiskLevel = "normal",
|
||||
NextFilingDueDate = DateTime.Today.AddMonths(1)
|
||||
};
|
||||
}
|
||||
|
||||
private void OnRowSelected(TaxProfile profile)
|
||||
{
|
||||
if (profile == null) return;
|
||||
selectedProfile = profile;
|
||||
isEditMode = true;
|
||||
profileForm = new TaxProfileForm
|
||||
{
|
||||
ClientId = profile.ClientId,
|
||||
BusinessType = profile.BusinessType ?? "",
|
||||
TaxRiskLevel = profile.TaxRiskLevel,
|
||||
NextFilingDueDate = profile.NextFilingDueDate,
|
||||
SpecialNotes = profile.SpecialNotes
|
||||
};
|
||||
}
|
||||
|
||||
private async Task SaveProfile()
|
||||
{
|
||||
if (form != null)
|
||||
{
|
||||
await form.Validate();
|
||||
if (!form.IsValid)
|
||||
{
|
||||
Snackbar.Add("고객을 선택하세요.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (isEditMode && selectedProfile != null)
|
||||
{
|
||||
await TaxProfileClient.UpdateAsync(selectedProfile.Id, profileForm.BusinessType,
|
||||
null, profileForm.NextFilingDueDate, profileForm.TaxRiskLevel);
|
||||
Snackbar.Add("세무 프로필이 수정되었습니다.", Severity.Success);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!profileForm.ClientId.HasValue)
|
||||
{
|
||||
Snackbar.Add("고객을 선택하세요.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
var newId = await TaxProfileClient.CreateAsync(
|
||||
profileForm.ClientId.Value,
|
||||
profileForm.BusinessType);
|
||||
if (newId > 0)
|
||||
{
|
||||
await TaxProfileClient.UpdateAsync(
|
||||
newId,
|
||||
profileForm.BusinessType,
|
||||
null,
|
||||
profileForm.NextFilingDueDate,
|
||||
profileForm.TaxRiskLevel);
|
||||
Snackbar.Add("세무 프로필이 추가되었습니다.", Severity.Success);
|
||||
}
|
||||
}
|
||||
PrepareCreate();
|
||||
await LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"저장 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteProfile(int id)
|
||||
{
|
||||
var parameters = new DialogParameters();
|
||||
parameters.Add("Title", "삭제 확인");
|
||||
parameters.Add("Message", "이 세무 프로필을 삭제하시겠습니까?");
|
||||
|
||||
var dialog = await DialogService.ShowAsync<ConfirmDialog>("", parameters);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result?.Canceled ?? true)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
await TaxProfileClient.DeleteAsync(id);
|
||||
Snackbar.Add("세무 프로필이 삭제되었습니다.", Severity.Success);
|
||||
if (selectedProfile?.Id == id)
|
||||
{
|
||||
PrepareCreate();
|
||||
}
|
||||
await LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private Color GetRiskColor(string riskLevel) => riskLevel switch
|
||||
{
|
||||
"high" => Color.Error,
|
||||
"normal" => Color.Warning,
|
||||
"low" => Color.Success,
|
||||
_ => Color.Default
|
||||
};
|
||||
|
||||
private static string GetClientDisplayName(Client client)
|
||||
=> !string.IsNullOrWhiteSpace(client.CompanyName)
|
||||
? client.CompanyName
|
||||
: !string.IsNullOrWhiteSpace(client.Name)
|
||||
? client.Name
|
||||
: $"Client #{client.Id}";
|
||||
|
||||
private class TaxProfileForm
|
||||
{
|
||||
public int? ClientId { get; set; }
|
||||
public string BusinessType { get; set; } = "";
|
||||
public string TaxRiskLevel { get; set; } = "normal";
|
||||
public DateTime? NextFilingDueDate { get; set; }
|
||||
public string? SpecialNotes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
@inject NavigationManager Navigation
|
||||
@inject IJSRuntime Js
|
||||
|
||||
@code {
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (!firstRender)
|
||||
return;
|
||||
|
||||
await Js.InvokeVoidAsync("taxbaikAdminSession.clearAuthToken");
|
||||
var returnUrl = Uri.EscapeDataString(Navigation.ToBaseRelativePath(Navigation.Uri));
|
||||
Navigation.NavigateTo($"/taxbaik/admin/login?returnUrl={returnUrl}", replace: true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
@namespace TaxBaik.WasmClient.Components.Admin
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
|
||||
<Router AppAssembly="@typeof(TaxBaik.WasmClient._Imports).Assembly">
|
||||
<Found Context="routeData">
|
||||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(TaxBaik.WasmClient.Components.Admin.Layout.MainLayout)">
|
||||
<NotAuthorized>
|
||||
<RedirectToLogin />
|
||||
</NotAuthorized>
|
||||
</AuthorizeRouteView>
|
||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>찾을 수 없음</PageTitle>
|
||||
<LayoutView Layout="@typeof(TaxBaik.WasmClient.Components.Admin.Layout.MainLayout)">
|
||||
<p>요청한 페이지를 찾을 수 없습니다.</p>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
@@ -0,0 +1,118 @@
|
||||
namespace TaxBaik.Web.Services.AdminClients;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TaxBaik.Domain.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
public interface ICommonCodeBrowserClient
|
||||
{
|
||||
Task<List<string>> GetGroupsAsync(CancellationToken ct = default);
|
||||
Task<List<CommonCode>> GetAllActiveAsync(CancellationToken ct = default);
|
||||
Task<List<CommonCode>> GetByGroupAsync(string group, CancellationToken ct = default);
|
||||
Task<CommonCode?> GetAsync(string group, string value, CancellationToken ct = default);
|
||||
Task<bool> UpsertAsync(CommonCode code, CancellationToken ct = default);
|
||||
Task<bool> DeleteAsync(string group, string value, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class CommonCodeBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger<CommonCodeBrowserClient> logger) : ICommonCodeBrowserClient
|
||||
{
|
||||
private const string BaseUrl = "/api/commoncode";
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tokenStore.AccessToken))
|
||||
httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken);
|
||||
else
|
||||
httpClient.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<List<CommonCode>> GetAllActiveAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<CommonCode>>($"{BaseUrl}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get all active common codes");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<CommonCode>> GetByGroupAsync(string group, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<CommonCode>>($"{BaseUrl}/group/{group}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get common codes for group {Group}", group);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetGroupsAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<string>>($"{BaseUrl}/groups", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get common code groups");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CommonCode?> GetAsync(string group, string value, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<CommonCode>($"{BaseUrl}/{group}/{value}", ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get common code {Group}/{Value}", group, value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpsertAsync(CommonCode code, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.PostAsJsonAsync(BaseUrl, code, ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to upsert common code {Group}/{Value}", code.CodeGroup, code.CodeValue);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(string group, string value, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.DeleteAsync($"{BaseUrl}/{group}/{value}", ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to delete common code {Group}/{Value}", group, value);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
namespace TaxBaik.Web.Services.AdminClients;
|
||||
|
||||
using System.Text.Json;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
public interface IConsultingActivityBrowserClient
|
||||
{
|
||||
Task<List<ConsultingActivity>> GetAllAsync(CancellationToken ct = default);
|
||||
Task<List<ConsultingActivity>> GetByClientIdAsync(int clientId, CancellationToken ct = default);
|
||||
Task<List<ConsultingActivity>> GetPendingFollowupsAsync(CancellationToken ct = default);
|
||||
Task<int> CreateAsync(int clientId, string activityType, DateTime activityDate, string description,
|
||||
int? consultantId = null, DateTime? nextFollowupDate = null, CancellationToken ct = default);
|
||||
Task UpdateAsync(int id, string? outcome = null, DateTime? nextFollowupDate = null, CancellationToken ct = default);
|
||||
Task DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class ConsultingActivityBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger<ConsultingActivityBrowserClient> logger)
|
||||
: IConsultingActivityBrowserClient
|
||||
{
|
||||
private const string BaseUrl = "/api/consultingactivity";
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tokenStore.AccessToken))
|
||||
httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken);
|
||||
else
|
||||
httpClient.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<List<ConsultingActivity>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<ConsultingActivity>>($"{BaseUrl}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get consulting activities");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<ConsultingActivity>> GetByClientIdAsync(int clientId, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<ConsultingActivity>>($"{BaseUrl}/client/{clientId}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get activities for client {ClientId}", clientId);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<ConsultingActivity>> GetPendingFollowupsAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>($"{BaseUrl}/pending-followups", ct);
|
||||
if (response.TryGetProperty("data", out var data))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<List<ConsultingActivity>>(data.GetRawText()) ?? [];
|
||||
return [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get pending followups");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> CreateAsync(int clientId, string activityType, DateTime activityDate, string description,
|
||||
int? consultantId = null, DateTime? nextFollowupDate = null, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { clientId, activityType, activityDate, description, consultantId, nextFollowupDate };
|
||||
var response = await httpClient.PostAsJsonAsync(BaseUrl, request, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var result = await response.Content.ReadFromJsonAsync<JsonElement>(cancellationToken: ct);
|
||||
return result.TryGetProperty("id", out var idProp) ? idProp.GetInt32() : 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to create consulting activity");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(int id, string? outcome = null, DateTime? nextFollowupDate = null, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { outcome, nextFollowupDate };
|
||||
var response = await httpClient.PutAsJsonAsync($"{BaseUrl}/{id}", request, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to update consulting activity {Id}", id);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.DeleteAsync($"{BaseUrl}/{id}", ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to delete consulting activity {Id}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
namespace TaxBaik.Web.Services.AdminClients;
|
||||
|
||||
using System.Text.Json;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
public interface IContractBrowserClient
|
||||
{
|
||||
Task<List<Contract>> GetAllAsync(CancellationToken ct = default);
|
||||
Task<Contract?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||
Task<List<Contract>> GetByClientIdAsync(int clientId, CancellationToken ct = default);
|
||||
Task<List<Contract>> GetActiveContractsAsync(CancellationToken ct = default);
|
||||
Task<List<Contract>> GetExpiringContractsAsync(int daysAhead = 30, CancellationToken ct = default);
|
||||
Task<decimal> GetMonthlyRecurringRevenueAsync(CancellationToken ct = default);
|
||||
Task<int> CreateAsync(int clientId, string contractNumber, string serviceType, DateTime startDate,
|
||||
decimal? monthlyFee = null, decimal? totalAmount = null, CancellationToken ct = default);
|
||||
Task DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class ContractBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger<ContractBrowserClient> logger)
|
||||
: IContractBrowserClient
|
||||
{
|
||||
private const string BaseUrl = "/api/contract";
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tokenStore.AccessToken))
|
||||
httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken);
|
||||
else
|
||||
httpClient.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<List<Contract>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<Contract>>($"{BaseUrl}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get contracts");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Contract?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<Contract>($"{BaseUrl}/{id}", ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get contract {Id}", id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Contract>> GetByClientIdAsync(int clientId, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<Contract>>($"{BaseUrl}/client/{clientId}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get contracts for client {ClientId}", clientId);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Contract>> GetActiveContractsAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>($"{BaseUrl}/active", ct);
|
||||
if (response.TryGetProperty("data", out var data))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<List<Contract>>(data.GetRawText()) ?? [];
|
||||
return [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get active contracts");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<Contract>> GetExpiringContractsAsync(int daysAhead = 30, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>($"{BaseUrl}/expiring?daysAhead={daysAhead}", ct);
|
||||
if (response.TryGetProperty("data", out var data))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<List<Contract>>(data.GetRawText()) ?? [];
|
||||
return [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get expiring contracts");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<decimal> GetMonthlyRecurringRevenueAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>($"{BaseUrl}/mrr", ct);
|
||||
if (response.TryGetProperty("mrr", out var mrrValue))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<decimal>(mrrValue.GetRawText());
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get MRR");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> CreateAsync(int clientId, string contractNumber, string serviceType, DateTime startDate,
|
||||
decimal? monthlyFee = null, decimal? totalAmount = null, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { clientId, contractNumber, serviceType, startDate, monthlyFee, totalAmount };
|
||||
var response = await httpClient.PostAsJsonAsync(BaseUrl, request, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var result = await response.Content.ReadFromJsonAsync<JsonElement>(cancellationToken: ct);
|
||||
return result.TryGetProperty("id", out var idProp) ? idProp.GetInt32() : 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to create contract");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.DeleteAsync($"{BaseUrl}/{id}", ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to delete contract {Id}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
namespace TaxBaik.Web.Services.AdminClients;
|
||||
|
||||
using System.Text.Json;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
public interface IRevenueTrackingBrowserClient
|
||||
{
|
||||
Task<List<RevenueTracking>> GetAllAsync(CancellationToken ct = default);
|
||||
Task<List<RevenueTracking>> GetByClientIdAsync(int clientId, CancellationToken ct = default);
|
||||
Task<List<RevenueTracking>> GetPendingPaymentsAsync(CancellationToken ct = default);
|
||||
Task<List<RevenueTracking>> GetMonthlyRevenueAsync(int year, int month, CancellationToken ct = default);
|
||||
Task<decimal> GetTotalRevenueAsync(DateTime startDate, DateTime endDate, CancellationToken ct = default);
|
||||
Task<int> CreateAsync(int clientId, string invoiceNumber, DateTime invoiceDate, decimal amount,
|
||||
string? serviceType = null, DateTime? dueDate = null, CancellationToken ct = default);
|
||||
Task MarkPaidAsync(int id, DateTime paymentDate, CancellationToken ct = default);
|
||||
Task DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class RevenueTrackingBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger<RevenueTrackingBrowserClient> logger)
|
||||
: IRevenueTrackingBrowserClient
|
||||
{
|
||||
private const string BaseUrl = "/api/revenuetracking";
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tokenStore.AccessToken))
|
||||
httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken);
|
||||
else
|
||||
httpClient.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<List<RevenueTracking>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<RevenueTracking>>($"{BaseUrl}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get revenue tracking");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<RevenueTracking>> GetByClientIdAsync(int clientId, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<RevenueTracking>>($"{BaseUrl}/client/{clientId}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get revenue for client {ClientId}", clientId);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<RevenueTracking>> GetPendingPaymentsAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>($"{BaseUrl}/pending", ct);
|
||||
if (response.TryGetProperty("data", out var data))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<List<RevenueTracking>>(data.GetRawText()) ?? [];
|
||||
return [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get pending payments");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<RevenueTracking>> GetMonthlyRevenueAsync(int year, int month, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>($"{BaseUrl}/monthly?year={year}&month={month}", ct);
|
||||
if (response.TryGetProperty("data", out var data))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<List<RevenueTracking>>(data.GetRawText()) ?? [];
|
||||
return [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get monthly revenue {Year}-{Month}", year, month);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<decimal> GetTotalRevenueAsync(DateTime startDate, DateTime endDate, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>(
|
||||
$"{BaseUrl}/total?startDate={startDate:yyyy-MM-dd}&endDate={endDate:yyyy-MM-dd}", ct);
|
||||
if (response.TryGetProperty("total", out var totalValue))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<decimal>(totalValue.GetRawText());
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get total revenue");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> CreateAsync(int clientId, string invoiceNumber, DateTime invoiceDate, decimal amount,
|
||||
string? serviceType = null, DateTime? dueDate = null, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { clientId, invoiceNumber, invoiceDate, amount, serviceType, dueDate };
|
||||
var response = await httpClient.PostAsJsonAsync(BaseUrl, request, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var result = await response.Content.ReadFromJsonAsync<JsonElement>(cancellationToken: ct);
|
||||
return result.TryGetProperty("id", out var idProp) ? idProp.GetInt32() : 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to create revenue tracking");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task MarkPaidAsync(int id, DateTime paymentDate, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { paymentDate };
|
||||
var response = await httpClient.PutAsJsonAsync($"{BaseUrl}/{id}/paid", request, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to mark payment {Id}", id);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.DeleteAsync($"{BaseUrl}/{id}", ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to delete revenue tracking {Id}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
namespace TaxBaik.Web.Services.AdminClients;
|
||||
|
||||
using System.Text.Json;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
public interface ITaxFilingScheduleBrowserClient
|
||||
{
|
||||
Task<List<TaxFilingSchedule>> GetAllAsync(CancellationToken ct = default);
|
||||
Task<TaxFilingSchedule?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||
Task<List<TaxFilingSchedule>> GetByClientIdAsync(int clientId, CancellationToken ct = default);
|
||||
Task<List<TaxFilingSchedule>> GetUpcomingDuesAsync(int daysAhead = 30, CancellationToken ct = default);
|
||||
Task<int> CreateAsync(int clientId, string filingType, DateTime dueDate, int filingYear,
|
||||
int? assignedTo = null, CancellationToken ct = default);
|
||||
Task MarkCompletedAsync(int id, CancellationToken ct = default);
|
||||
Task DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class TaxFilingScheduleBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger<TaxFilingScheduleBrowserClient> logger)
|
||||
: ITaxFilingScheduleBrowserClient
|
||||
{
|
||||
private const string BaseUrl = "/api/taxfilingschedule";
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tokenStore.AccessToken))
|
||||
httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken);
|
||||
else
|
||||
httpClient.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<List<TaxFilingSchedule>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<TaxFilingSchedule>>($"{BaseUrl}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get tax filing schedules");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<TaxFilingSchedule?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<TaxFilingSchedule>($"{BaseUrl}/{id}", ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get tax filing schedule {Id}", id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<TaxFilingSchedule>> GetByClientIdAsync(int clientId, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<TaxFilingSchedule>>($"{BaseUrl}/client/{clientId}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get filing schedules for client {ClientId}", clientId);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<TaxFilingSchedule>> GetUpcomingDuesAsync(int daysAhead = 30, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>($"{BaseUrl}/upcoming?daysAhead={daysAhead}", ct);
|
||||
if (response.TryGetProperty("data", out var data))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<List<TaxFilingSchedule>>(data.GetRawText()) ?? [];
|
||||
return [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get upcoming filings");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> CreateAsync(int clientId, string filingType, DateTime dueDate, int filingYear,
|
||||
int? assignedTo = null, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { clientId, filingType, dueDate, filingYear, assignedTo };
|
||||
var response = await httpClient.PostAsJsonAsync(BaseUrl, request, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var result = await response.Content.ReadFromJsonAsync<JsonElement>(cancellationToken: ct);
|
||||
return result.TryGetProperty("id", out var idProp) ? idProp.GetInt32() : 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to create tax filing schedule");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task MarkCompletedAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.PutAsJsonAsync($"{BaseUrl}/{id}/complete", new { }, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to mark filing as completed {Id}", id);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.DeleteAsync($"{BaseUrl}/{id}", ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to delete tax filing schedule {Id}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
namespace TaxBaik.Web.Services.AdminClients;
|
||||
|
||||
using System.Text.Json;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
public interface ITaxProfileBrowserClient
|
||||
{
|
||||
Task<List<TaxProfile>> GetAllAsync(CancellationToken ct = default);
|
||||
Task<TaxProfile?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||
Task<List<TaxProfile>> GetByClientIdAsync(int clientId, CancellationToken ct = default);
|
||||
Task<List<TaxProfile>> GetHighRiskProfilesAsync(CancellationToken ct = default);
|
||||
Task<List<TaxProfile>> GetUpcomingFilingDuesAsync(int daysAhead = 30, CancellationToken ct = default);
|
||||
Task<int> CreateAsync(int clientId, string businessType, string? businessRegistration = null,
|
||||
string? accountingMethod = null, DateTime? establishmentDate = null, CancellationToken ct = default);
|
||||
Task UpdateAsync(int id, string? businessType = null, string? accountingMethod = null,
|
||||
DateTime? nextFilingDueDate = null, string? taxRiskLevel = null, CancellationToken ct = default);
|
||||
Task DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class TaxProfileBrowserClient(HttpClient httpClient, ITokenStore tokenStore, ILogger<TaxProfileBrowserClient> logger) : ITaxProfileBrowserClient
|
||||
{
|
||||
private const string BaseUrl = "/api/taxprofile";
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tokenStore.AccessToken))
|
||||
httpClient.DefaultRequestHeaders.Authorization = new("Bearer", tokenStore.AccessToken);
|
||||
else
|
||||
httpClient.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<List<TaxProfile>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<TaxProfile>>($"{BaseUrl}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get tax profiles");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<TaxProfile?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<TaxProfile>($"{BaseUrl}/{id}", ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get tax profile {Id}", id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<TaxProfile>> GetByClientIdAsync(int clientId, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await httpClient.GetFromJsonAsync<List<TaxProfile>>($"{BaseUrl}/client/{clientId}", ct) ?? [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get tax profiles for client {ClientId}", clientId);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<TaxProfile>> GetHighRiskProfilesAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>($"{BaseUrl}/high-risk", ct);
|
||||
if (response.TryGetProperty("data", out var data))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<List<TaxProfile>>(data.GetRawText()) ?? [];
|
||||
return [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get high-risk profiles");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<TaxProfile>> GetUpcomingFilingDuesAsync(int daysAhead = 30, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.GetFromJsonAsync<JsonElement>($"{BaseUrl}/upcoming-filings?daysAhead={daysAhead}", ct);
|
||||
if (response.TryGetProperty("data", out var data))
|
||||
return System.Text.Json.JsonSerializer.Deserialize<List<TaxProfile>>(data.GetRawText()) ?? [];
|
||||
return [];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to get upcoming filings");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> CreateAsync(int clientId, string businessType, string? businessRegistration = null,
|
||||
string? accountingMethod = null, DateTime? establishmentDate = null, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { clientId, businessType, businessRegistration, accountingMethod, establishmentDate };
|
||||
var response = await httpClient.PostAsJsonAsync(BaseUrl, request, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var result = await response.Content.ReadFromJsonAsync<JsonElement>(cancellationToken: ct);
|
||||
return result.TryGetProperty("id", out var idProp) ? idProp.GetInt32() : 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to create tax profile");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(int id, string? businessType = null, string? accountingMethod = null,
|
||||
DateTime? nextFilingDueDate = null, string? taxRiskLevel = null, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { businessType, accountingMethod, nextFilingDueDate, taxRiskLevel };
|
||||
var response = await httpClient.PutAsJsonAsync($"{BaseUrl}/{id}", request, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to update tax profile {Id}", id);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await httpClient.DeleteAsync($"{BaseUrl}/{id}", ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to delete tax profile {Id}", id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using TaxBaik.Application.Services;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Admin Dashboard API Client
|
||||
/// SOLID: Single Responsibility - Dashboard API 호출만 담당
|
||||
/// Dependency Inversion - 추상화된 인터페이스 사용
|
||||
/// </summary>
|
||||
public interface IAdminDashboardClient
|
||||
{
|
||||
Task<AdminDashboardSummary> GetSummaryAsync(CancellationToken ct = default);
|
||||
Task<IEnumerable<TaxFiling>> GetUpcomingFilingsAsync(int days = 30, CancellationToken ct = default);
|
||||
Task<IEnumerable<Inquiry>> GetRecentInquiriesAsync(int limit = 10, CancellationToken ct = default);
|
||||
Task<object> GetMonthlyStatsAsync(string? month = null, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class AdminDashboardClient : IAdminDashboardClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<AdminDashboardClient> _logger;
|
||||
private readonly ITokenStore _tokenStore;
|
||||
|
||||
public AdminDashboardClient(HttpClient http, ILogger<AdminDashboardClient> logger, ITokenStore tokenStore)
|
||||
{
|
||||
_http = http;
|
||||
_logger = logger;
|
||||
_tokenStore = tokenStore;
|
||||
}
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_tokenStore.AccessToken))
|
||||
_http.DefaultRequestHeaders.Authorization = new("Bearer", _tokenStore.AccessToken);
|
||||
else
|
||||
_http.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<AdminDashboardSummary> GetSummaryAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<AdminDashboardSummary>(
|
||||
"admin-dashboard/summary", cancellationToken: ct);
|
||||
return result ?? new(0, 0, 0, 0, []);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch dashboard summary");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TaxFiling>> GetUpcomingFilingsAsync(int days = 30, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<ApiResponse<TaxFiling>>(
|
||||
$"admin-dashboard/upcoming-filings?days={days}", cancellationToken: ct);
|
||||
return result?.Data ?? [];
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch upcoming filings");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Inquiry>> GetRecentInquiriesAsync(int limit = 10, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<ApiResponse<Inquiry>>(
|
||||
$"admin-dashboard/recent-inquiries?limit={limit}", cancellationToken: ct);
|
||||
return result?.Data ?? [];
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch recent inquiries");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<object> GetMonthlyStatsAsync(string? month = null, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var url = "admin-dashboard/monthly-stats";
|
||||
if (!string.IsNullOrEmpty(month))
|
||||
url += $"?month={month}";
|
||||
|
||||
var result = await _http.GetFromJsonAsync<object>(url, cancellationToken: ct);
|
||||
return result ?? new();
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch monthly stats");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Response wrapper
|
||||
/// </summary>
|
||||
internal class ApiResponse<T>
|
||||
{
|
||||
public IEnumerable<T>? Data { get; set; }
|
||||
public int Total { get; set; }
|
||||
public int Page { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using TaxBaik.Application.DTOs;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
public interface IAnnouncementBrowserClient
|
||||
{
|
||||
Task<IEnumerable<Announcement>> GetAllAsync(CancellationToken ct = default);
|
||||
Task<Announcement?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||
Task<Announcement?> CreateAsync(AnnouncementDto dto, CancellationToken ct = default);
|
||||
Task<Announcement?> UpdateAsync(int id, AnnouncementDto dto, CancellationToken ct = default);
|
||||
Task<bool> DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class AnnouncementBrowserClient : IAnnouncementBrowserClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<AnnouncementBrowserClient> _logger;
|
||||
private readonly ITokenStore _tokenStore;
|
||||
|
||||
public AnnouncementBrowserClient(HttpClient http, ILogger<AnnouncementBrowserClient> logger, ITokenStore tokenStore)
|
||||
{
|
||||
_http = http;
|
||||
_logger = logger;
|
||||
_tokenStore = tokenStore;
|
||||
}
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_tokenStore.AccessToken))
|
||||
_http.DefaultRequestHeaders.Authorization = new("Bearer", _tokenStore.AccessToken);
|
||||
else
|
||||
_http.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Announcement>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<AnnouncementListResponse>("announcement", cancellationToken: ct);
|
||||
return result?.Data ?? [];
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch announcements");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Announcement?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await _http.GetFromJsonAsync<Announcement>($"announcement/{id}", cancellationToken: ct);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch announcement {AnnouncementId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Announcement?> CreateAsync(AnnouncementDto dto, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PostAsJsonAsync("announcement", dto, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<Announcement>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to create announcement");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Announcement?> UpdateAsync(int id, AnnouncementDto dto, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PutAsJsonAsync($"announcement/{id}", dto, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<Announcement>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to update announcement {AnnouncementId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.DeleteAsync($"announcement/{id}", cancellationToken: ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to delete announcement {AnnouncementId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private class AnnouncementListResponse
|
||||
{
|
||||
public List<Announcement> Data { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using System.Text.Json;
|
||||
|
||||
public interface IApiClient
|
||||
{
|
||||
Task<T?> GetAsync<T>(string endpoint);
|
||||
Task<T?> PostAsync<T>(string endpoint, object data);
|
||||
Task<T?> PutAsync<T>(string endpoint, object data);
|
||||
Task DeleteAsync(string endpoint);
|
||||
Task SetAuthToken(string? token);
|
||||
}
|
||||
|
||||
public class ApiClient : IApiClient
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly NavigationManager _navigationManager;
|
||||
private string? _authToken;
|
||||
|
||||
public ApiClient(HttpClient httpClient, NavigationManager navigationManager)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_navigationManager = navigationManager;
|
||||
}
|
||||
|
||||
public async Task SetAuthToken(string? token)
|
||||
{
|
||||
_authToken = token;
|
||||
if (token != null)
|
||||
_httpClient.DefaultRequestHeaders.Authorization = new("Bearer", token);
|
||||
else
|
||||
_httpClient.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<T?> GetAsync<T>(string endpoint)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetAsync(BuildApiUri(endpoint));
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return default;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync();
|
||||
return JsonSerializer.Deserialize<T>(content, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<T?> PostAsync<T>(string endpoint, object data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(data);
|
||||
var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
|
||||
var response = await _httpClient.PostAsync(BuildApiUri(endpoint), content);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return default;
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
return JsonSerializer.Deserialize<T>(responseContent, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<T?> PutAsync<T>(string endpoint, object data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(data);
|
||||
var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
|
||||
var response = await _httpClient.PutAsync(BuildApiUri(endpoint), content);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return default;
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
return JsonSerializer.Deserialize<T>(responseContent, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string endpoint)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _httpClient.DeleteAsync(BuildApiUri(endpoint));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
private Uri BuildApiUri(string endpoint)
|
||||
{
|
||||
var relative = $"api/{endpoint.TrimStart('/')}";
|
||||
return new Uri(new Uri(_navigationManager.BaseUri), relative);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using System.Net.Http.Json;
|
||||
using TaxBaik.Application.DTOs;
|
||||
|
||||
public interface IBlogBrowserClient
|
||||
{
|
||||
Task<(IEnumerable<BlogPostResponseDto> Items, int Total)> GetAdminPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default);
|
||||
Task<(IEnumerable<BlogPostResponseDto> Items, int Total)> GetArchivedPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default);
|
||||
Task<BlogPostResponseDto?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||
Task<BlogPostResponseDto?> CreateAsync(CreateBlogPostDto dto, CancellationToken ct = default);
|
||||
Task<BlogPostResponseDto?> UpdateAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default);
|
||||
Task<bool> DeleteAsync(int id, CancellationToken ct = default);
|
||||
Task<bool> RestoreAsync(int id, CancellationToken ct = default);
|
||||
Task<bool> TogglePublishAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class BlogBrowserClient : IBlogBrowserClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<BlogBrowserClient> _logger;
|
||||
private readonly ITokenStore _tokenStore;
|
||||
|
||||
public BlogBrowserClient(HttpClient http, ILogger<BlogBrowserClient> logger, ITokenStore tokenStore)
|
||||
{
|
||||
_http = http;
|
||||
_logger = logger;
|
||||
_tokenStore = tokenStore;
|
||||
}
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_tokenStore.AccessToken))
|
||||
_http.DefaultRequestHeaders.Authorization = new("Bearer", _tokenStore.AccessToken);
|
||||
else
|
||||
_http.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<BlogPostResponseDto> Items, int Total)> GetAdminPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default)
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<PagedResponse>($"blog/admin?page={page}&pageSize={pageSize}", ct);
|
||||
return result != null ? (result.Data, result.Total) : ([], 0);
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<BlogPostResponseDto> Items, int Total)> GetArchivedPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default)
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<PagedResponse>($"blog/admin/archived?page={page}&pageSize={pageSize}", ct);
|
||||
return result != null ? (result.Data, result.Total) : ([], 0);
|
||||
}
|
||||
|
||||
public async Task<BlogPostResponseDto?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await _http.GetFromJsonAsync<BlogPostResponseDto>($"blog/{id}", ct);
|
||||
}
|
||||
|
||||
public async Task<BlogPostResponseDto?> CreateAsync(CreateBlogPostDto dto, CancellationToken ct = default)
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PostAsJsonAsync("blog", dto, ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<BlogPostResponseDto>(content, new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
|
||||
public async Task<BlogPostResponseDto?> UpdateAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default)
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PutAsJsonAsync($"blog/{id}", dto, ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<BlogPostResponseDto>(content, new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.DeleteAsync($"blog/{id}", ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> RestoreAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PostAsync($"blog/{id}/restore", null, ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public async Task<bool> TogglePublishAsync(int id, CreateBlogPostDto dto, CancellationToken ct = default)
|
||||
{
|
||||
var result = await UpdateAsync(id, dto, ct);
|
||||
return result != null;
|
||||
}
|
||||
|
||||
private sealed class PagedResponse
|
||||
{
|
||||
public List<BlogPostResponseDto> Data { get; set; } = [];
|
||||
public int Total { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using System.Net.Http.Json;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
public interface ICategoryBrowserClient
|
||||
{
|
||||
Task<IReadOnlyList<Category>> GetAllAsync(CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class CategoryBrowserClient : ICategoryBrowserClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<CategoryBrowserClient> _logger;
|
||||
|
||||
public CategoryBrowserClient(HttpClient http, ILogger<CategoryBrowserClient> logger)
|
||||
{
|
||||
_http = http;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<Category>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _http.GetFromJsonAsync<List<Category>>("category", cancellationToken: ct);
|
||||
return result ?? [];
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch categories");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using TaxBaik.Application.DTOs;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Client API Client for Admin Blazor
|
||||
/// SOLID: Single Responsibility - Client API calls only
|
||||
/// </summary>
|
||||
public interface IClientBrowserClient
|
||||
{
|
||||
Task<(IEnumerable<Client> Items, int Total)> GetPagedAsync(
|
||||
int page = 1, int pageSize = 20, string? status = null, string? search = null, CancellationToken ct = default);
|
||||
Task<Client?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||
Task<Client?> CreateAsync(CreateClientDto dto, CancellationToken ct = default);
|
||||
Task<Client?> UpdateAsync(int id, CreateClientDto dto, CancellationToken ct = default);
|
||||
Task<bool> DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class ClientBrowserClient : IClientBrowserClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<ClientBrowserClient> _logger;
|
||||
private readonly ITokenStore _tokenStore;
|
||||
|
||||
public ClientBrowserClient(HttpClient http, ILogger<ClientBrowserClient> logger, ITokenStore tokenStore)
|
||||
{
|
||||
_http = http;
|
||||
_logger = logger;
|
||||
_tokenStore = tokenStore;
|
||||
}
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_tokenStore.AccessToken))
|
||||
_http.DefaultRequestHeaders.Authorization = new("Bearer", _tokenStore.AccessToken);
|
||||
else
|
||||
_http.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<Client> Items, int Total)> GetPagedAsync(
|
||||
int page = 1, int pageSize = 20, string? status = null, string? search = null, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var query = $"client?page={page}&pageSize={pageSize}";
|
||||
if (!string.IsNullOrEmpty(status))
|
||||
query += $"&status={status}";
|
||||
if (!string.IsNullOrEmpty(search))
|
||||
query += $"&search={Uri.EscapeDataString(search)}";
|
||||
|
||||
var result = await _http.GetFromJsonAsync<ClientPagedResponse>(query, cancellationToken: ct);
|
||||
return result != null ? (result.Data, result.Total) : ([], 0);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch clients");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Client?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await _http.GetFromJsonAsync<Client>($"client/{id}", cancellationToken: ct);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch client {ClientId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Client?> CreateAsync(CreateClientDto dto, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PostAsJsonAsync("client", dto, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<Client>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to create client");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Client?> UpdateAsync(int id, CreateClientDto dto, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PutAsJsonAsync($"client/{id}", dto, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<Client>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to update client {ClientId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.DeleteAsync($"client/{id}", cancellationToken: ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to delete client {ClientId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private class ClientPagedResponse
|
||||
{
|
||||
public List<Client> Data { get; set; } = [];
|
||||
public int Total { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using TaxBaik.Application.Services;
|
||||
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
public class CustomAuthenticationStateProvider : AuthenticationStateProvider
|
||||
{
|
||||
private readonly ILocalStorageService _localStorage;
|
||||
private readonly ITokenStore _tokenStore;
|
||||
private readonly IApiClient _apiClient;
|
||||
private readonly ILogger<CustomAuthenticationStateProvider> _logger;
|
||||
|
||||
public CustomAuthenticationStateProvider(
|
||||
ILocalStorageService localStorage,
|
||||
ITokenStore tokenStore,
|
||||
IApiClient apiClient,
|
||||
ILogger<CustomAuthenticationStateProvider> logger)
|
||||
{
|
||||
_localStorage = localStorage;
|
||||
_tokenStore = tokenStore;
|
||||
_apiClient = apiClient;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var accessToken = _tokenStore.AccessToken;
|
||||
|
||||
// TokenStore가 비어있으면 localStorage에서 복원 (페이지 리로드 후)
|
||||
if (string.IsNullOrEmpty(accessToken))
|
||||
{
|
||||
var storedToken = await _localStorage.GetItemAsStringAsync("accessToken");
|
||||
if (!string.IsNullOrEmpty(storedToken))
|
||||
{
|
||||
var refreshToken = await _localStorage.GetItemAsStringAsync("refreshToken");
|
||||
var ticksStr = await _localStorage.GetItemAsStringAsync("tokenExpiry");
|
||||
if (TryNormalizeExpiryTicks(ticksStr, out var ticks))
|
||||
{
|
||||
_tokenStore.AccessToken = storedToken;
|
||||
_tokenStore.RefreshToken = refreshToken;
|
||||
_tokenStore.TokenExpiryTicks = ticks;
|
||||
accessToken = storedToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(_tokenStore.AccessToken))
|
||||
{
|
||||
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
|
||||
}
|
||||
|
||||
// 토큰이 만료되면 로그아웃
|
||||
if (_tokenStore.IsAccessTokenExpired())
|
||||
{
|
||||
_logger.LogWarning("Access token 만료됨 - 자동 로그아웃");
|
||||
await LogoutAsync();
|
||||
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
|
||||
}
|
||||
|
||||
// 토큰이 5분 이내로 만료되면 자동 갱신 시도 (사용자 경험 향상)
|
||||
if (!string.IsNullOrEmpty(_tokenStore.RefreshToken) && ShouldRefreshToken())
|
||||
{
|
||||
_logger.LogInformation("토큰 만료 5분 전 - 자동 갱신 시작");
|
||||
var request = new { RefreshToken = _tokenStore.RefreshToken };
|
||||
var newTokenPair = await _apiClient.PostAsync<WasmAuthTokenPair>("auth/refresh", request);
|
||||
if (newTokenPair != null && !string.IsNullOrEmpty(newTokenPair.AccessToken))
|
||||
{
|
||||
await LoginAsync(newTokenPair.AccessToken, newTokenPair.RefreshToken, newTokenPair.ExpiresIn);
|
||||
_logger.LogInformation("토큰 자동 갱신 성공");
|
||||
accessToken = newTokenPair.AccessToken;
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("토큰 자동 갱신 실패 - 로그아웃");
|
||||
await LogoutAsync();
|
||||
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
|
||||
}
|
||||
}
|
||||
|
||||
var principal = ValidateTokenWithoutDb(accessToken ?? string.Empty);
|
||||
if (principal == null)
|
||||
{
|
||||
await LogoutAsync();
|
||||
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
|
||||
}
|
||||
|
||||
return new AuthenticationState(principal);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "인증 상태 조회 중 오류 발생");
|
||||
return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
|
||||
}
|
||||
}
|
||||
|
||||
private ClaimsPrincipal? ValidateTokenWithoutDb(string token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var jwtToken = handler.ReadJwtToken(token);
|
||||
var identity = new ClaimsIdentity(jwtToken.Claims, "jwt");
|
||||
return new ClaimsPrincipal(identity);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task LoginAsync(string accessToken, string refreshToken, int expiresIn)
|
||||
{
|
||||
var tokenExpiryTicks = DateTime.UtcNow.AddSeconds(expiresIn).Ticks;
|
||||
|
||||
// TokenStore에 저장 (DelegatingHandler에서 사용)
|
||||
_tokenStore.AccessToken = accessToken;
|
||||
_tokenStore.RefreshToken = refreshToken;
|
||||
_tokenStore.TokenExpiryTicks = tokenExpiryTicks;
|
||||
|
||||
// localStorage에도 저장 (페이지 리로드 후 복원)
|
||||
await _localStorage.SetItemAsStringAsync("accessToken", accessToken);
|
||||
await _localStorage.SetItemAsStringAsync("refreshToken", refreshToken);
|
||||
await _localStorage.SetItemAsStringAsync("tokenExpiry", tokenExpiryTicks.ToString());
|
||||
|
||||
// Blazor에 인증 상태 변경을 알림 - 이 호출 자체는 async이지만 fire-and-forget OK
|
||||
// (NotifyAuthenticationStateChanged는 내부적으로 Task를 구독함)
|
||||
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
||||
}
|
||||
|
||||
private static bool TryNormalizeExpiryTicks(string? rawValue, out long ticks)
|
||||
{
|
||||
ticks = 0;
|
||||
if (!long.TryParse(rawValue, out var parsed))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Support both legacy Unix-millisecond storage and .NET ticks.
|
||||
if (parsed > 10_000_000_000_000L && parsed < 100_000_000_000_000_000L)
|
||||
{
|
||||
ticks = parsed;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parsed > 1_000_000_000_000L && parsed < 100_000_000_000_000L)
|
||||
{
|
||||
ticks = DateTimeOffset.FromUnixTimeMilliseconds(parsed).UtcDateTime.Ticks;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ShouldRefreshToken()
|
||||
{
|
||||
// 토큰이 5분 이내로 만료되면 갱신 (300초 = 5분)
|
||||
if (!_tokenStore.TokenExpiryTicks.HasValue || _tokenStore.TokenExpiryTicks.Value <= 0)
|
||||
return false;
|
||||
|
||||
const int refreshThresholdSeconds = 300;
|
||||
try
|
||||
{
|
||||
var expiryTime = new DateTime(_tokenStore.TokenExpiryTicks.Value, DateTimeKind.Utc);
|
||||
var timeUntilExpiry = expiryTime - DateTime.UtcNow;
|
||||
return timeUntilExpiry.TotalSeconds <= refreshThresholdSeconds && timeUntilExpiry.TotalSeconds > 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task LogoutAsync()
|
||||
{
|
||||
// TokenStore 초기화
|
||||
_tokenStore.Clear();
|
||||
|
||||
// localStorage 초기화
|
||||
await _localStorage.RemoveItemAsync("accessToken");
|
||||
await _localStorage.RemoveItemAsync("refreshToken");
|
||||
await _localStorage.RemoveItemAsync("tokenExpiry");
|
||||
|
||||
NotifyAuthenticationStateChanged(GetAuthenticationStateAsync());
|
||||
}
|
||||
|
||||
private bool IsTokenExpired(string token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var jwtToken = handler.ReadJwtToken(token);
|
||||
return jwtToken.ValidTo < DateTime.UtcNow;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class WasmAuthTokenPair
|
||||
{
|
||||
public WasmAuthTokenPair() { }
|
||||
public WasmAuthTokenPair(string accessToken, string refreshToken, int expiresIn)
|
||||
{
|
||||
AccessToken = accessToken;
|
||||
RefreshToken = refreshToken;
|
||||
ExpiresIn = expiresIn;
|
||||
}
|
||||
public string AccessToken { get; set; } = "";
|
||||
public string RefreshToken { get; set; } = "";
|
||||
public int ExpiresIn { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
public interface IFaqBrowserClient
|
||||
{
|
||||
Task<IEnumerable<Faq>> GetAllAsync(CancellationToken ct = default);
|
||||
Task<Faq?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||
Task<Faq?> CreateAsync(Faq faq, CancellationToken ct = default);
|
||||
Task<Faq?> UpdateAsync(int id, Faq faq, CancellationToken ct = default);
|
||||
Task<bool> DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class FaqBrowserClient : IFaqBrowserClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<FaqBrowserClient> _logger;
|
||||
private readonly ITokenStore _tokenStore;
|
||||
|
||||
public FaqBrowserClient(HttpClient http, ILogger<FaqBrowserClient> logger, ITokenStore tokenStore)
|
||||
{
|
||||
_http = http;
|
||||
_logger = logger;
|
||||
_tokenStore = tokenStore;
|
||||
}
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_tokenStore.AccessToken))
|
||||
_http.DefaultRequestHeaders.Authorization = new("Bearer", _tokenStore.AccessToken);
|
||||
else
|
||||
_http.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Faq>> GetAllAsync(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<FaqListResponse>("faq", cancellationToken: ct);
|
||||
return result?.Data ?? [];
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch FAQs");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Faq?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await _http.GetFromJsonAsync<Faq>($"faq/{id}", cancellationToken: ct);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch FAQ {FaqId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Faq?> CreateAsync(Faq faq, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PostAsJsonAsync("faq", faq, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<Faq>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to create FAQ");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Faq?> UpdateAsync(int id, Faq faq, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PutAsJsonAsync($"faq/{id}", faq, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode) return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<Faq>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to update FAQ {FaqId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.DeleteAsync($"faq/{id}", cancellationToken: ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to delete FAQ {FaqId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private class FaqListResponse
|
||||
{
|
||||
public List<Faq> Data { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
public interface ILocalStorageService
|
||||
{
|
||||
Task<string?> GetItemAsStringAsync(string key);
|
||||
Task SetItemAsStringAsync(string key, string value);
|
||||
Task RemoveItemAsync(string key);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Scoped in-memory token store for Blazor Server.
|
||||
/// SOLID: Single Responsibility - Token lifecycle management
|
||||
/// Avoids JS interop from DelegatingHandler (which runs on non-circuit thread)
|
||||
/// </summary>
|
||||
public interface ITokenStore
|
||||
{
|
||||
string? AccessToken { get; set; }
|
||||
string? RefreshToken { get; set; }
|
||||
long? TokenExpiryTicks { get; set; }
|
||||
|
||||
bool IsAccessTokenExpired();
|
||||
void Clear();
|
||||
}
|
||||
|
||||
public class TokenStore : ITokenStore
|
||||
{
|
||||
public string? AccessToken { get; set; }
|
||||
public string? RefreshToken { get; set; }
|
||||
public long? TokenExpiryTicks { get; set; }
|
||||
|
||||
public bool IsAccessTokenExpired()
|
||||
{
|
||||
if (TokenExpiryTicks == null)
|
||||
return true;
|
||||
|
||||
var expiryTime = new DateTime(TokenExpiryTicks.Value, DateTimeKind.Utc);
|
||||
return expiryTime <= DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
AccessToken = null;
|
||||
RefreshToken = null;
|
||||
TokenExpiryTicks = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using TaxBaik.Application.DTOs;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Inquiry API Client for Admin Blazor
|
||||
/// SOLID: Single Responsibility - Inquiry API calls only
|
||||
/// Dependency Inversion - abstraction via interface
|
||||
/// </summary>
|
||||
public interface IInquiryBrowserClient
|
||||
{
|
||||
Task<(IEnumerable<Inquiry> Items, int Total)> GetPagedAsync(int page = 1, int pageSize = 20, CancellationToken ct = default);
|
||||
Task<Inquiry?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||
Task<bool> UpdateStatusAsync(int id, string status, CancellationToken ct = default);
|
||||
Task<bool> UpdateAdminMemoAsync(int id, string adminMemo, CancellationToken ct = default);
|
||||
Task<Inquiry?> UpdateAsync(int id, UpdateInquiryDto dto, CancellationToken ct = default);
|
||||
Task<int> ConvertToClientAsync(int id, string name, string phone, string serviceType, CancellationToken ct = default);
|
||||
Task<Inquiry?> CreateAsync(SubmitInquiryDto dto, CancellationToken ct = default);
|
||||
Task<bool> DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class InquiryBrowserClient : IInquiryBrowserClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<InquiryBrowserClient> _logger;
|
||||
private readonly ITokenStore _tokenStore;
|
||||
|
||||
public InquiryBrowserClient(HttpClient http, ILogger<InquiryBrowserClient> logger, ITokenStore tokenStore)
|
||||
{
|
||||
_http = http;
|
||||
_logger = logger;
|
||||
_tokenStore = tokenStore;
|
||||
}
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_tokenStore.AccessToken))
|
||||
_http.DefaultRequestHeaders.Authorization = new("Bearer", _tokenStore.AccessToken);
|
||||
else
|
||||
_http.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<Inquiry> Items, int Total)> GetPagedAsync(
|
||||
int page = 1, int pageSize = 20, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<InquiryPagedResponse>(
|
||||
$"inquiry?page={page}&pageSize={pageSize}",
|
||||
cancellationToken: ct);
|
||||
|
||||
return result != null
|
||||
? (result.Data, result.Total)
|
||||
: ([], 0);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch inquiries");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Inquiry?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await _http.GetFromJsonAsync<Inquiry>(
|
||||
$"inquiry/{id}",
|
||||
cancellationToken: ct);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch inquiry {InquiryId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateStatusAsync(int id, string status, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { status };
|
||||
var response = await _http.PutAsJsonAsync(
|
||||
$"inquiry/{id}/status",
|
||||
request,
|
||||
cancellationToken: ct);
|
||||
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to update inquiry {InquiryId} status", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAdminMemoAsync(int id, string adminMemo, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var request = new { adminMemo };
|
||||
var response = await _http.PutAsJsonAsync(
|
||||
$"inquiry/{id}/memo",
|
||||
request,
|
||||
cancellationToken: ct);
|
||||
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to update inquiry {InquiryId} memo", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Inquiry?> UpdateAsync(int id, UpdateInquiryDto dto, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PutAsJsonAsync($"inquiry/{id}", dto, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<Inquiry>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to update inquiry {InquiryId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> ConvertToClientAsync(int id, string name, string phone, string serviceType, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PostAsJsonAsync(
|
||||
$"inquiry/{id}/convert-to-client",
|
||||
new { name, phone, serviceType },
|
||||
cancellationToken: ct);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return 0;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
var result = System.Text.Json.JsonSerializer.Deserialize<ConvertToClientResponse>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
|
||||
return result?.ClientId ?? 0;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to convert inquiry {InquiryId} to client", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Inquiry?> CreateAsync(SubmitInquiryDto dto, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PostAsJsonAsync("inquiry", dto, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<Inquiry>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to create inquiry");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.DeleteAsync($"inquiry/{id}", ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to delete inquiry {InquiryId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private class InquiryPagedResponse
|
||||
{
|
||||
public List<Inquiry> Data { get; set; } = [];
|
||||
public int Total { get; set; }
|
||||
public int Page { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
}
|
||||
|
||||
private class ConvertToClientResponse
|
||||
{
|
||||
public int ClientId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
public class LocalStorageService : ILocalStorageService
|
||||
{
|
||||
private readonly IJSRuntime _jsRuntime;
|
||||
|
||||
public LocalStorageService(IJSRuntime jsRuntime)
|
||||
{
|
||||
_jsRuntime = jsRuntime;
|
||||
}
|
||||
|
||||
public async Task<string?> GetItemAsStringAsync(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await _jsRuntime.InvokeAsync<string>("localStorage.getItem", key);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetItemAsStringAsync(string key, string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", key, value);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
public async Task RemoveItemAsync(string key)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", key);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using TaxBaik.Domain.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// TaxFiling API Client for Admin Blazor
|
||||
/// </summary>
|
||||
public interface ITaxFilingBrowserClient
|
||||
{
|
||||
Task<IEnumerable<TaxFiling>> GetUpcomingAsync(int daysAhead = 30, CancellationToken ct = default);
|
||||
Task<IEnumerable<TaxFiling>> GetByClientIdAsync(int clientId, CancellationToken ct = default);
|
||||
Task<TaxFiling?> GetByIdAsync(int id, CancellationToken ct = default);
|
||||
Task<TaxFiling?> CreateAsync(TaxFiling filing, CancellationToken ct = default);
|
||||
Task<TaxFiling?> UpdateAsync(int id, TaxFiling filing, CancellationToken ct = default);
|
||||
Task<bool> DeleteAsync(int id, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
public class TaxFilingBrowserClient : ITaxFilingBrowserClient
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private readonly ILogger<TaxFilingBrowserClient> _logger;
|
||||
private readonly ITokenStore _tokenStore;
|
||||
|
||||
public TaxFilingBrowserClient(HttpClient http, ILogger<TaxFilingBrowserClient> logger, ITokenStore tokenStore)
|
||||
{
|
||||
_http = http;
|
||||
_logger = logger;
|
||||
_tokenStore = tokenStore;
|
||||
}
|
||||
|
||||
private void EnsureAuthHeader()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_tokenStore.AccessToken))
|
||||
_http.DefaultRequestHeaders.Authorization = new("Bearer", _tokenStore.AccessToken);
|
||||
else
|
||||
_http.DefaultRequestHeaders.Authorization = null;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TaxFiling>> GetUpcomingAsync(int daysAhead = 30, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<TaxFilingListResponse>(
|
||||
$"taxfiling/upcoming?daysAhead={daysAhead}", cancellationToken: ct);
|
||||
return result?.Data ?? [];
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch upcoming filings");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TaxFiling>> GetByClientIdAsync(int clientId, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var result = await _http.GetFromJsonAsync<TaxFilingListResponse>(
|
||||
$"taxfiling/client/{clientId}", cancellationToken: ct);
|
||||
return result?.Data ?? [];
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch filings for client {ClientId}", clientId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<TaxFiling?> GetByIdAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
return await _http.GetFromJsonAsync<TaxFiling>(
|
||||
$"taxfiling/{id}", cancellationToken: ct);
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to fetch filing {FilingId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<TaxFiling?> CreateAsync(TaxFiling filing, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PostAsJsonAsync("taxfiling", filing, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<TaxFiling>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to create filing");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<TaxFiling?> UpdateAsync(int id, TaxFiling filing, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.PutAsJsonAsync($"taxfiling/{id}", filing, cancellationToken: ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(ct);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<TaxFiling>(
|
||||
content,
|
||||
new System.Text.Json.JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to update filing {FilingId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(int id, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuthHeader();
|
||||
var response = await _http.DeleteAsync($"taxfiling/{id}", cancellationToken: ct);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to delete filing {FilingId}", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private class TaxFilingListResponse
|
||||
{
|
||||
public List<TaxFiling> Data { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
namespace TaxBaik.Web.Services;
|
||||
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 요청 시 자동으로 access token을 추가하고,
|
||||
/// 401 응답을 받으면 refresh token으로 새 토큰을 획득한 후 재시도합니다.
|
||||
/// SOLID: Single Responsibility - 토큰 갱신 로직만 담당
|
||||
/// </summary>
|
||||
public class TokenRefreshHandler : DelegatingHandler
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ILogger<TokenRefreshHandler> _logger;
|
||||
|
||||
public TokenRefreshHandler(IServiceProvider serviceProvider, ILogger<TokenRefreshHandler> logger)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// 최신 Scoped ITokenStore 실시간 해석 (Scope Capture 차단 및 기존 Blazor 회로 수명 공유)
|
||||
var tokenStore = Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService<ITokenStore>(_serviceProvider);
|
||||
|
||||
// 요청에 access token 추가
|
||||
if (!string.IsNullOrEmpty(tokenStore.AccessToken))
|
||||
{
|
||||
request.Headers.Authorization = new("Bearer", tokenStore.AccessToken);
|
||||
}
|
||||
|
||||
var response = await base.SendAsync(request, cancellationToken);
|
||||
|
||||
// 401 응답이면 토큰 갱신 시도
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tokenStore.RefreshToken))
|
||||
{
|
||||
var newTokenPair = await RefreshTokenAsync(tokenStore.RefreshToken, request, cancellationToken);
|
||||
if (newTokenPair != null)
|
||||
{
|
||||
// TokenStore에 토큰 저장
|
||||
tokenStore.AccessToken = newTokenPair.AccessToken;
|
||||
tokenStore.RefreshToken = newTokenPair.RefreshToken;
|
||||
tokenStore.TokenExpiryTicks = DateTime.UtcNow.AddSeconds(newTokenPair.ExpiresIn).Ticks;
|
||||
|
||||
// 새 토큰으로 재요청
|
||||
request.Headers.Authorization = new("Bearer", newTokenPair.AccessToken);
|
||||
response = await base.SendAsync(request, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("토큰 갱신 실패 - 로그아웃");
|
||||
tokenStore.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private async Task<WasmAuthTokenPair?> RefreshTokenAsync(string refreshToken, HttpRequestMessage originalRequest, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 원래 요청의 호스트 정보 추출
|
||||
var authority = originalRequest.RequestUri?.Authority ?? "localhost:5001";
|
||||
var scheme = originalRequest.RequestUri?.Scheme ?? "http";
|
||||
|
||||
using var httpClient = new HttpClient();
|
||||
var refreshUri = new Uri($"{scheme}://{authority}/taxbaik/api/auth/refresh");
|
||||
var json = JsonSerializer.Serialize(new { refreshToken });
|
||||
var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
var response = await httpClient.PostAsync(refreshUri, content, ct);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogWarning($"Token refresh failed with status {response.StatusCode}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync(ct);
|
||||
var result = JsonSerializer.Deserialize<AuthTokenResponse>(responseContent,
|
||||
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
|
||||
|
||||
return result != null
|
||||
? new WasmAuthTokenPair(result.AccessToken, result.RefreshToken, result.ExpiresIn)
|
||||
: null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception during token refresh");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class AuthTokenResponse
|
||||
{
|
||||
public string AccessToken { get; set; } = string.Empty;
|
||||
public string RefreshToken { get; set; } = string.Empty;
|
||||
public int ExpiresIn { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">@Eyebrow</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">@Title</MudText>
|
||||
@if (!string.IsNullOrWhiteSpace(Subtitle))
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">@Subtitle</MudText>
|
||||
}
|
||||
</div>
|
||||
<MudButton Variant="Variant.Outlined" StartIcon="@Icons.Material.Filled.Close" @onclick="OnCancel">
|
||||
@CancelText
|
||||
</MudButton>
|
||||
</section>
|
||||
|
||||
<AdminEditorPanel Loading="@Loading" SkeletonContent="@SkeletonContent">
|
||||
@ChildContent
|
||||
</AdminEditorPanel>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public string Title { get; set; } = "";
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public string Eyebrow { get; set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public string? Subtitle { get; set; }
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public EventCallback OnCancel { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string CancelText { get; set; } = "취소";
|
||||
|
||||
[Parameter]
|
||||
public bool Loading { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? SkeletonContent { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<MudPaper Class="admin-surface" Elevation="0">
|
||||
@if (Loading)
|
||||
{
|
||||
@if (SkeletonContent is not null)
|
||||
{
|
||||
@SkeletonContent
|
||||
}
|
||||
else
|
||||
{
|
||||
<AdminSkeletonRows />
|
||||
}
|
||||
}
|
||||
else if (ChildContent is not null)
|
||||
{
|
||||
@ChildContent
|
||||
}
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public bool Loading { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? SkeletonContent { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<MudPaper Class="@CssClass" Elevation="@Elevation">
|
||||
@if (!string.IsNullOrWhiteSpace(Title))
|
||||
{
|
||||
<MudText Typo="Typo.h6" Class="mb-3">@Title</MudText>
|
||||
}
|
||||
@ChildContent
|
||||
</MudPaper>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string CssClass { get; set; } = "pa-4";
|
||||
|
||||
[Parameter]
|
||||
public int Elevation { get; set; } = 1;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<AdminDataPanel Loading="@Loading" SkeletonContent="@SkeletonContent">
|
||||
<div class="admin-editor-panel-shell">
|
||||
@ChildContent
|
||||
</div>
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public bool Loading { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? SkeletonContent { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<div class="pa-6 text-center">
|
||||
<MudIcon Icon="@Icon" Style="font-size:3rem; opacity:.3;" />
|
||||
<MudText Class="mt-2 text-muted">@Message</MudText>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public string Icon { get; set; } = Icons.Material.Filled.Info;
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public string Message { get; set; } = "";
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<div class="d-flex gap-2">
|
||||
<MudButton Variant="@SubmitVariant"
|
||||
Color="@SubmitColor"
|
||||
StartIcon="@SubmitIcon"
|
||||
@onclick="OnSubmit"
|
||||
Disabled="@IsSubmitting">
|
||||
@(IsSubmitting ? LoadingText : SubmitText)
|
||||
</MudButton>
|
||||
@if (OnCancel.HasDelegate)
|
||||
{
|
||||
<MudButton Variant="Variant.Outlined" @onclick="OnCancel">
|
||||
@CancelText
|
||||
</MudButton>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public string SubmitText { get; set; } = "저장";
|
||||
|
||||
[Parameter]
|
||||
public string LoadingText { get; set; } = "저장 중...";
|
||||
|
||||
[Parameter]
|
||||
public string CancelText { get; set; } = "취소";
|
||||
|
||||
[Parameter]
|
||||
public Variant SubmitVariant { get; set; } = Variant.Filled;
|
||||
|
||||
[Parameter]
|
||||
public Color SubmitColor { get; set; } = Color.Primary;
|
||||
|
||||
[Parameter]
|
||||
public string? SubmitIcon { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnSubmit { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnCancel { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsSubmitting { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<div class="@CssClass">
|
||||
@if (!string.IsNullOrWhiteSpace(Title))
|
||||
{
|
||||
<MudText Typo="Typo.subtitle1" Class="font-weight-bold mb-1">@Title</MudText>
|
||||
}
|
||||
@if (!string.IsNullOrWhiteSpace(Description))
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="mb-2">@Description</MudText>
|
||||
}
|
||||
@ChildContent
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string CssClass { get; set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
@inject ILocalStorageService LocalStorageService
|
||||
@inject IJSRuntime Js
|
||||
|
||||
<MudContainer MaxWidth="MaxWidth.Small" Class="admin-login-page d-flex align-center justify-center" Style="min-height: 100vh;">
|
||||
<MudPaper Class="pa-8" Elevation="3" Style="width: 100%; max-width: 400px;">
|
||||
<MudText Typo="Typo.h4" Class="mb-6 text-center">관리자 로그인</MudText>
|
||||
|
||||
<form id="admin-login-form">
|
||||
<input class="mud-input mud-input-outlined mud-input-root mud-input-root-adorned-start mb-4"
|
||||
style="width: 100%; min-height: 56px; padding: 16px 14px;"
|
||||
placeholder="사용자명"
|
||||
autocomplete="username"
|
||||
name="username"
|
||||
value="@rememberedUsername" />
|
||||
|
||||
<input type="password"
|
||||
class="mud-input mud-input-outlined mud-input-root mud-input-root-adorned-start mb-4"
|
||||
style="width: 100%; min-height: 56px; padding: 16px 14px;"
|
||||
placeholder="비밀번호"
|
||||
autocomplete="current-password"
|
||||
name="password" />
|
||||
|
||||
<div class="mb-4">
|
||||
<input class="mud-checkbox" type="checkbox" name="rememberMe" />
|
||||
<label style="margin-left: 8px; cursor: pointer;">아이디 저장</label>
|
||||
</div>
|
||||
|
||||
<div class="mud-alert mud-alert-filled-error mb-4 login-error-message" style="display:none;">로그인 중 오류가 발생했습니다.</div>
|
||||
|
||||
<button type="submit"
|
||||
id="admin-login-submit"
|
||||
disabled="@(!isReady)"
|
||||
class="mud-button-root mud-button mud-button-filled mud-button-filled-primary mud-elevation-0"
|
||||
style="width: 100%; min-height: 52px; border: 0; border-radius: 4px; color: white;">
|
||||
<span>@(isReady ? "로그인" : "준비 중...")</span>
|
||||
</button>
|
||||
</form>
|
||||
</MudPaper>
|
||||
</MudContainer>
|
||||
|
||||
@code {
|
||||
private string rememberedUsername = "";
|
||||
private bool isRememberChecked = false;
|
||||
private bool isReady;
|
||||
private const string RememberedUsernameKey = "admin-remembered-username";
|
||||
private const string RememberedCheckboxKey = "admin-remember-checkbox";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
rememberedUsername = await LocalStorageService.GetItemAsStringAsync(RememberedUsernameKey) ?? "";
|
||||
var checkboxValue = await LocalStorageService.GetItemAsStringAsync(RememberedCheckboxKey) ?? "false";
|
||||
isRememberChecked = checkboxValue == "true" && !string.IsNullOrEmpty(rememberedUsername);
|
||||
}
|
||||
catch
|
||||
{
|
||||
rememberedUsername = "";
|
||||
isRememberChecked = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Js.InvokeVoidAsync("taxbaikAdminSession.syncRouteClass");
|
||||
await Js.InvokeVoidAsync("taxbaikAdminSession.bindLoginForm");
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Login UI must remain visible even if JS binding fails.
|
||||
}
|
||||
finally
|
||||
{
|
||||
isReady = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<div class="admin-metric-card @Accent cursor-pointer" @onclick="OnClick">
|
||||
<div class="admin-metric-card-body">
|
||||
<span class="admin-metric-card-label">@Label</span>
|
||||
<div class="admin-metric-card-value-row">
|
||||
<span class="admin-metric-card-value" style="color: @ValueColor;">@Value</span>
|
||||
<span class="admin-metric-card-icon" style="color: @IconColor;">@Icon</span>
|
||||
</div>
|
||||
<span class="admin-metric-card-caption">@Caption</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public string Label { get; set; } = "";
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public object? Value { get; set; }
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public string Caption { get; set; } = "";
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public string Accent { get; set; } = "";
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public string Icon { get; set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public string ValueColor { get; set; } = "inherit";
|
||||
|
||||
[Parameter]
|
||||
public string IconColor { get; set; } = "inherit";
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnClick { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
@if (!string.IsNullOrWhiteSpace(Eyebrow))
|
||||
{
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">@Eyebrow</MudText>
|
||||
}
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">@Title</MudText>
|
||||
@if (!string.IsNullOrWhiteSpace(Subtitle))
|
||||
{
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">@Subtitle</MudText>
|
||||
}
|
||||
</div>
|
||||
@if (ChildContent is not null)
|
||||
{
|
||||
<div>@ChildContent</div>
|
||||
}
|
||||
</section>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public string Title { get; set; } = "";
|
||||
|
||||
[Parameter]
|
||||
public string? Eyebrow { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string? Subtitle { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
@inject NavigationManager Navigation
|
||||
@inject IJSRuntime JS
|
||||
@implements IDisposable
|
||||
|
||||
<MudPopoverProvider />
|
||||
<MudDialogProvider />
|
||||
<MudSnackbarProvider />
|
||||
|
||||
<MudLayout Class="admin-shell">
|
||||
<MudAppBar Elevation="0" Class="admin-topbar">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Menu"
|
||||
Color="Color.Inherit"
|
||||
Edge="Edge.Start"
|
||||
Class="admin-menu-button"
|
||||
OnClick="@ToggleDrawer" />
|
||||
<div class="admin-topbar-title">
|
||||
<MudText Typo="Typo.body2" Class="font-weight-bold admin-brand-text">TaxBaik</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-brand-subtitle">세무회계 관리 대시보드</MudText>
|
||||
</div>
|
||||
<MudSpacer />
|
||||
|
||||
<div class="admin-topbar-actions">
|
||||
<MudButton Class="admin-topbar-action"
|
||||
Variant="Variant.Text"
|
||||
Color="Color.Inherit"
|
||||
Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.OpenInNew"
|
||||
Href="/taxbaik"
|
||||
Target="_blank">
|
||||
공개 사이트
|
||||
</MudButton>
|
||||
|
||||
<MudDivider Vertical="true" FlexItem="true" Class="mx-2" />
|
||||
|
||||
<MudButton Class="admin-topbar-action"
|
||||
Variant="Variant.Text"
|
||||
Color="Color.Error"
|
||||
Size="Size.Small"
|
||||
StartIcon="@Icons.Material.Filled.Logout"
|
||||
Href="/taxbaik/admin/logout">
|
||||
로그아웃
|
||||
</MudButton>
|
||||
</div>
|
||||
</MudAppBar>
|
||||
|
||||
<MudDrawer @bind-open="@drawerOpen"
|
||||
Elevation="0"
|
||||
Variant="DrawerVariant.Responsive"
|
||||
Breakpoint="Breakpoint.Md"
|
||||
Class="admin-drawer">
|
||||
<div class="admin-drawer-brand">
|
||||
<div class="admin-brand-mark">T</div>
|
||||
<div>
|
||||
<MudText Typo="Typo.subtitle1">TaxBaik</MudText>
|
||||
<MudText Typo="Typo.caption">세무 운영 콘솔</MudText>
|
||||
</div>
|
||||
</div>
|
||||
<MudNavMenu Class="admin-nav">
|
||||
<MudNavLink Href="/taxbaik/admin/dashboard" Match="NavLinkMatch.All" Icon="@Icons.Material.Filled.Dashboard" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/dashboard"))">대시보드</MudNavLink>
|
||||
<MudNavGroup Title="CRM & 세무관리" Icon="@Icons.Material.Filled.BusinessCenter" @bind-Expanded="@expandedCRMGroup">
|
||||
<MudNavLink Href="/taxbaik/admin/tax-profiles" Icon="@Icons.Material.Filled.Assignment" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/tax-profiles"))">세무 프로필</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/tax-filing-schedules" Icon="@Icons.Material.Filled.CalendarMonth" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/tax-filing-schedules"))">신고 일정</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/contracts" Icon="@Icons.Material.Filled.Description" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/contracts"))">계약 관리</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/consulting-activities" Icon="@Icons.Material.Filled.ChatBubble" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/consulting-activities"))">상담 활동</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/revenue-trackings" Icon="@Icons.Material.Filled.Receipt" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/revenue-trackings"))">수익 추적</MudNavLink>
|
||||
</MudNavGroup>
|
||||
<MudNavGroup Title="고객 관리" Icon="@Icons.Material.Filled.PeopleAlt" @bind-Expanded="@expandedCustomerGroup">
|
||||
<MudNavLink Href="/taxbaik/admin/clients" Icon="@Icons.Material.Filled.ContactPage" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/clients"))">고객 카드</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/tax-filings" Icon="@Icons.Material.Filled.Assessment" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/tax-filings"))">세무신고</MudNavLink>
|
||||
</MudNavGroup>
|
||||
<MudNavGroup Title="홈페이지" Icon="@Icons.Material.Filled.Home" @bind-Expanded="@expandedWebsiteGroup">
|
||||
<MudNavLink Href="/taxbaik/admin/announcements" Icon="@Icons.Material.Filled.Campaign" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/announcements"))">공지사항</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/faqs" Icon="@Icons.Material.Filled.QuestionAnswer" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/faqs"))">FAQ 관리</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/blog" Icon="@Icons.Material.Filled.Article" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/blog"))">블로그 관리</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/season-simulator" Icon="@Icons.Material.Filled.Preview" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/season-simulator"))">시즌 시뮬레이터</MudNavLink>
|
||||
</MudNavGroup>
|
||||
<MudNavLink Href="/taxbaik/admin/inquiries" Icon="@Icons.Material.Filled.Forum" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/inquiries"))">문의 관리</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/settings" Icon="@Icons.Material.Filled.Tune" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/settings"))">설정</MudNavLink>
|
||||
<MudNavLink Href="/taxbaik/admin/common-codes" Icon="@Icons.Material.Filled.Category" ClickPreventDefault="true" OnClick="@(() => NavigateTo("/taxbaik/admin/common-codes"))">공통관리</MudNavLink>
|
||||
</MudNavMenu>
|
||||
<div class="admin-drawer-version">
|
||||
<div class="admin-drawer-version-label">Version</div>
|
||||
<div class="admin-drawer-version-value">vunknown</div>
|
||||
<div class="admin-drawer-version-built">unknown</div>
|
||||
</div>
|
||||
</MudDrawer>
|
||||
|
||||
<MudMainContent Class="admin-main">
|
||||
<MudContainer MaxWidth="MaxWidth.False" Class="admin-content">
|
||||
@ChildContent
|
||||
</MudContainer>
|
||||
</MudMainContent>
|
||||
</MudLayout>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public RenderFragment? ChildContent { get; set; }
|
||||
|
||||
private bool drawerOpen = true;
|
||||
private bool expandedCRMGroup = true;
|
||||
private bool expandedCustomerGroup = false;
|
||||
private bool expandedWebsiteGroup = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Navigation.LocationChanged += OnLocationChanged;
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
await JS.InvokeVoidAsync("taxbaikAdminSession.setContext", "admin/shell", "navigation", "layout", "shell", "shell", "", "main");
|
||||
await JS.InvokeVoidAsync("taxbaikAdminSession.hideLoading");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLocationChanged(object? sender, LocationChangedEventArgs args)
|
||||
{
|
||||
var route = new Uri(args.Location).AbsolutePath;
|
||||
_ = JS.InvokeVoidAsync("taxbaikAdminSession.setContext", route, "navigation", "route-change", "layout", "shell", "", route);
|
||||
_ = InvokeAsync(() => JS.InvokeVoidAsync("taxbaikAdminSession.hideLoading"));
|
||||
}
|
||||
|
||||
private void ToggleDrawer()
|
||||
{
|
||||
drawerOpen = !drawerOpen;
|
||||
_ = JS.InvokeVoidAsync("taxbaikAdminSession.setContext", "admin/shell", "navigation", "drawer", drawerOpen ? "opened" : "closed", "shell", "", "drawer");
|
||||
_ = JS.InvokeVoidAsync("taxbaikAdminSession.traceUiState", "admin-shell", drawerOpen ? "drawer opened" : "drawer closed");
|
||||
}
|
||||
|
||||
private void NavigateTo(string url)
|
||||
{
|
||||
Navigation.NavigateTo(url);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Navigation.LocationChanged -= OnLocationChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<div class="admin-skeleton-stack">
|
||||
@for (var i = 0; i < Rows; i++)
|
||||
{
|
||||
<div class="admin-skeleton-row">
|
||||
@for (var j = 0; j < Columns; j++)
|
||||
{
|
||||
<div class="admin-skeleton-block @GetWidthClass(j)" />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public int Rows { get; set; } = 4;
|
||||
|
||||
[Parameter]
|
||||
public int Columns { get; set; } = 3;
|
||||
|
||||
private static string GetWidthClass(int index) => index switch
|
||||
{
|
||||
0 => "w-40",
|
||||
1 => "w-25",
|
||||
_ => "w-20"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
@using System.Text.RegularExpressions
|
||||
@inject IJSRuntime Js
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
@code {
|
||||
[Parameter] public string Screen { get; set; } = "";
|
||||
[Parameter] public string Feature { get; set; } = "";
|
||||
[Parameter] public string Action { get; set; } = "";
|
||||
[Parameter] public string Step { get; set; } = "";
|
||||
[Parameter] public string Entity { get; set; } = "";
|
||||
[Parameter] public string EntityId { get; set; } = "";
|
||||
[Parameter] public string DataKey { get; set; } = "";
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
{
|
||||
try
|
||||
{
|
||||
var route = GetRoute();
|
||||
var context = ResolveContext(route);
|
||||
await Js.InvokeVoidAsync("taxbaikAdminSession.setContext",
|
||||
string.IsNullOrWhiteSpace(Screen) ? context.Screen : Screen,
|
||||
string.IsNullOrWhiteSpace(Feature) ? context.Feature : Feature,
|
||||
string.IsNullOrWhiteSpace(Action) ? context.Action : Action,
|
||||
string.IsNullOrWhiteSpace(Step) ? context.Step : Step,
|
||||
string.IsNullOrWhiteSpace(Entity) ? context.Entity : Entity,
|
||||
string.IsNullOrWhiteSpace(EntityId) ? context.EntityId : EntityId,
|
||||
string.IsNullOrWhiteSpace(DataKey) ? context.DataKey : DataKey);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// telemetry must never block rendering
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetRoute()
|
||||
{
|
||||
var path = Navigation.ToBaseRelativePath(Navigation.Uri);
|
||||
return string.IsNullOrWhiteSpace(path) ? "/" : "/" + path.TrimStart('/');
|
||||
}
|
||||
|
||||
private static (string Screen, string Feature, string Action, string Step, string Entity, string EntityId, string DataKey) ResolveContext(string route)
|
||||
=> route.ToLowerInvariant() switch
|
||||
{
|
||||
"/" => ("admin/index", "shell", "load", "index", "admin", "", "index"),
|
||||
"/admin/login" => ("admin/login", "auth", "render", "login page", "auth", "", "login"),
|
||||
"/admin/dashboard" => ("admin/dashboard", "dashboard", "load", "summary", "dashboard", "", "summary"),
|
||||
"/admin/common-codes" => ("admin/common-codes", "common-code", "load", "group list", "common_code", "", "group"),
|
||||
"/admin/blog" => ("admin/blog", "content", "load", "list", "blog", "", "list"),
|
||||
"/admin/blog/create" => ("admin/blog/create", "content", "create", "form", "blog", "", "create"),
|
||||
"/admin/blog/0/edit" => ("admin/blog/edit", "content", "edit", "form", "blog", "0", "edit"),
|
||||
"/admin/inquiries" => ("admin/inquiries", "customer-request", "load", "list", "inquiry", "", "list"),
|
||||
"/admin/inquiries/create" => ("admin/inquiries/create", "customer-request", "create", "form", "inquiry", "", "create"),
|
||||
"/admin/settings" => ("admin/settings", "system", "load", "settings", "site_setting", "", "settings"),
|
||||
"/admin/announcements" => ("admin/announcements", "content", "load", "list", "announcement", "", "list"),
|
||||
"/admin/announcements/create" => ("admin/announcements/create", "content", "create", "form", "announcement", "", "create"),
|
||||
"/admin/companies" => ("admin/companies", "company", "load", "list", "company", "", "list"),
|
||||
"/admin/faqs" => ("admin/faqs", "faq", "load", "list", "faq", "", "list"),
|
||||
"/admin/tax-profiles" => ("admin/tax-profiles", "tax-profile", "load", "list", "tax_profile", "", "list"),
|
||||
"/admin/tax-filing-schedules" => ("admin/tax-filing-schedules", "schedule", "load", "list", "tax_filing_schedule", "", "list"),
|
||||
"/admin/contracts" => ("admin/contracts", "crm", "load", "list", "contract", "", "list"),
|
||||
"/admin/consulting-activities" => ("admin/consulting-activities", "crm", "load", "list", "consulting_activity", "", "list"),
|
||||
"/admin/revenue-trackings" => ("admin/revenue-trackings", "crm", "load", "list", "revenue_tracking", "", "list"),
|
||||
"/admin/clients" => ("admin/clients", "customer", "load", "list", "client", "", "list"),
|
||||
"/admin/tax-filings" => ("admin/tax-filings", "tax-filing", "load", "list", "tax_filing", "", "list"),
|
||||
"/admin/season-simulator" => ("admin/season-simulator", "schedule", "load", "simulator", "season", "", "simulator"),
|
||||
_ => ResolveDynamicContext(route)
|
||||
};
|
||||
|
||||
private static (string Screen, string Feature, string Action, string Step, string Entity, string EntityId, string DataKey) ResolveDynamicContext(string route)
|
||||
{
|
||||
var normalized = route.ToLowerInvariant().TrimEnd('/');
|
||||
|
||||
foreach (var pattern in new[]
|
||||
{
|
||||
("/admin/blog/", "admin/blog/edit", "content", "edit", "form", "blog", "edit"),
|
||||
("/admin/announcements/", "admin/announcements/edit", "content", "edit", "form", "announcement", "edit"),
|
||||
("/admin/inquiries/", "admin/inquiries/edit", "customer-request", "edit", "form", "inquiry", "edit"),
|
||||
("/admin/clients/", "admin/clients/detail", "customer", "view", "detail", "client", "detail"),
|
||||
("/admin/companies/", "admin/companies/edit", "company", "edit", "form", "company", "edit"),
|
||||
("/admin/faqs/", "admin/faqs/edit", "faq", "edit", "form", "faq", "edit"),
|
||||
("/admin/tax-profiles/", "admin/tax-profiles/edit", "tax-profile", "edit", "form", "tax_profile", "edit"),
|
||||
("/admin/tax-filing-schedules/", "admin/tax-filing-schedules/edit", "schedule", "edit", "form", "tax_filing_schedule", "edit"),
|
||||
})
|
||||
{
|
||||
if (!normalized.StartsWith(pattern.Item1, StringComparison.OrdinalIgnoreCase))
|
||||
continue;
|
||||
|
||||
var remainder = normalized[pattern.Item1.Length..].Trim('/');
|
||||
var id = ExtractLeadingId(remainder);
|
||||
if (string.IsNullOrWhiteSpace(id))
|
||||
id = remainder.Split('/', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? "";
|
||||
|
||||
return (pattern.Item2, pattern.Item3, pattern.Item4, pattern.Item5, pattern.Item6, id, pattern.Item7);
|
||||
}
|
||||
|
||||
return (route.Trim('/'), "admin", "load", "view", "admin", "", route.Trim('/'));
|
||||
}
|
||||
|
||||
private static string ExtractLeadingId(string value)
|
||||
{
|
||||
var match = Regex.Match(value, @"^\d+");
|
||||
return match.Success ? match.Value : "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<AdminDataPanel Loading="@false">
|
||||
<AdminFormSection Title="그룹 선택" Description="코드 그룹을 먼저 선택합니다." CssClass="mb-4">
|
||||
<MudSelect T="string"
|
||||
Value="@SelectedGroup"
|
||||
ValueChanged="OnSelectedGroupChanged"
|
||||
Label="코드 그룹"
|
||||
Variant="Variant.Outlined"
|
||||
FullWidth="true"
|
||||
Clearable="true">
|
||||
<MudSelectItem Value="@string.Empty">선택</MudSelectItem>
|
||||
@foreach (var group in Groups)
|
||||
{
|
||||
<MudSelectItem Value="@group">@group</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</AdminFormSection>
|
||||
|
||||
<AdminFormSection Title="새 코드" Description="선택한 그룹에 항목을 추가합니다.">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OnCreateRequested">새 코드 추가</MudButton>
|
||||
</AdminFormSection>
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public IReadOnlyList<string> Groups { get; set; } = [];
|
||||
|
||||
[Parameter]
|
||||
public string SelectedGroup { get; set; } = "";
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public EventCallback<string> SelectedGroupChanged { get; set; }
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public EventCallback OnCreateRequested { get; set; }
|
||||
|
||||
private Task OnSelectedGroupChanged(string value) => SelectedGroupChanged.InvokeAsync(value);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<AdminDataPanel Loading="@Loading">
|
||||
<AdminFormSection Title="코드 목록" Description="그룹별 공통코드와 상태를 관리합니다." CssClass="mb-4">
|
||||
<MudTable Items="@Codes" Dense="true" Hover="true">
|
||||
<HeaderContent>
|
||||
<MudTh>그룹</MudTh>
|
||||
<MudTh>값</MudTh>
|
||||
<MudTh>이름</MudTh>
|
||||
<MudTh>순서</MudTh>
|
||||
<MudTh>상태</MudTh>
|
||||
<MudTh>작업</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>@context.CodeGroup</MudTd>
|
||||
<MudTd>@context.CodeValue</MudTd>
|
||||
<MudTd>@context.CodeName</MudTd>
|
||||
<MudTd>@context.SortOrder</MudTd>
|
||||
<MudTd>@(context.IsActive ? "활성" : "비활성")</MudTd>
|
||||
<MudTd>
|
||||
<MudButton Size="Size.Small" Variant="Variant.Text" OnClick="@(async () => await InvokeEditAsync(context))">수정</MudButton>
|
||||
<MudButton Size="Size.Small" Variant="Variant.Text" Color="Color.Error" OnClick="@(async () => await InvokeDeleteAsync(context))">삭제</MudButton>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
</AdminFormSection>
|
||||
|
||||
<MudDivider Class="my-4" />
|
||||
|
||||
<AdminFormSection Title="코드 편집" Description="공백 없는 값과 일관된 이름만 허용합니다.">
|
||||
<MudForm>
|
||||
<MudTextField @bind-Value="EditModel.CodeGroup" Label="그룹" Variant="Variant.Outlined" FullWidth="true" Required="true" Disabled="@(!IsCreateMode)" MaxLength="80" Class="mb-3" />
|
||||
<MudTextField @bind-Value="EditModel.CodeValue" Label="값" Variant="Variant.Outlined" FullWidth="true" Required="true" Disabled="@(!IsCreateMode)" MaxLength="120" Class="mb-3" />
|
||||
<MudTextField @bind-Value="EditModel.CodeName" Label="이름" Variant="Variant.Outlined" FullWidth="true" Required="true" MaxLength="200" Class="mb-3" />
|
||||
<MudNumericField T="int" @bind-Value="EditModel.SortOrder" Label="순서" Variant="Variant.Outlined" FullWidth="true" Class="mb-3" />
|
||||
<MudSwitch @bind-Checked="EditModel.IsActive" Color="Color.Primary">활성</MudSwitch>
|
||||
<div class="d-flex gap-2 mt-4">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="OnSaveRequested">저장</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" OnClick="OnResetRequested">초기화</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
</AdminFormSection>
|
||||
</AdminDataPanel>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public bool Loading { get; set; }
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public IReadOnlyList<CommonCode> Codes { get; set; } = [];
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public CommonCode EditModel { get; set; } = new();
|
||||
|
||||
[Parameter]
|
||||
public bool IsCreateMode { get; set; }
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public EventCallback<CommonCode> EditRequested { get; set; }
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public EventCallback<CommonCode> DeleteRequested { get; set; }
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public EventCallback SaveRequested { get; set; }
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public EventCallback ResetRequested { get; set; }
|
||||
|
||||
private Task InvokeEditAsync(CommonCode code) => EditRequested.InvokeAsync(code);
|
||||
private Task InvokeDeleteAsync(CommonCode code) => DeleteRequested.InvokeAsync(code);
|
||||
private Task OnSaveRequested() => SaveRequested.InvokeAsync();
|
||||
private Task OnResetRequested() => ResetRequested.InvokeAsync();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
@using TaxBaik.Domain.Entities
|
||||
@using TaxBaik.Web.Services.AdminClients
|
||||
@inject ICommonCodeBrowserClient CommonCodeClient
|
||||
|
||||
<MudSelect T="string"
|
||||
Value="Value"
|
||||
ValueChanged="ValueChanged"
|
||||
Label="@Label"
|
||||
Variant="@Variant"
|
||||
FullWidth="@FullWidth"
|
||||
Class="@Class"
|
||||
Required="@Required"
|
||||
Clearable="@Clearable"
|
||||
Disabled="@Disabled">
|
||||
@if (!string.IsNullOrWhiteSpace(Placeholder))
|
||||
{
|
||||
<MudSelectItem Value="@string.Empty">@Placeholder</MudSelectItem>
|
||||
}
|
||||
@foreach (var item in items)
|
||||
{
|
||||
<MudSelectItem Value="@item.CodeValue">@item.CodeName</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
@code {
|
||||
[Parameter] public string? Value { get; set; }
|
||||
[Parameter] public EventCallback<string?> ValueChanged { get; set; }
|
||||
[Parameter] public string Group { get; set; } = string.Empty;
|
||||
[Parameter] public string Label { get; set; } = string.Empty;
|
||||
[Parameter] public Variant Variant { get; set; } = Variant.Outlined;
|
||||
[Parameter] public bool FullWidth { get; set; } = true;
|
||||
[Parameter] public string? Class { get; set; }
|
||||
[Parameter] public bool Required { get; set; }
|
||||
[Parameter] public bool Clearable { get; set; }
|
||||
[Parameter] public bool Disabled { get; set; }
|
||||
[Parameter] public string? Placeholder { get; set; }
|
||||
|
||||
private List<CommonCode> items = [];
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
var normalizedGroup = Group?.Trim() ?? string.Empty;
|
||||
if (!string.Equals(normalizedGroup, _loadedGroup, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_loadedGroup = normalizedGroup;
|
||||
items = string.IsNullOrWhiteSpace(normalizedGroup)
|
||||
? []
|
||||
: (await CommonCodeClient.GetByGroupAsync(normalizedGroup))
|
||||
.OrderBy(x => x.SortOrder)
|
||||
.ThenBy(x => x.CodeName)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private string? _loadedGroup;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
@using MudBlazor
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudText>@Message</MudText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel">취소</MudButton>
|
||||
<MudButton Color="Color.Error" Variant="Variant.Filled" OnClick="Confirm">삭제</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[CascadingParameter] MudDialogInstance MudDialog { get; set; } = null!;
|
||||
[Parameter] public string Title { get; set; } = "";
|
||||
[Parameter] public string Message { get; set; } = "";
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
private void Confirm() => MudDialog.Close();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http.Json
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Http
|
||||
@using Microsoft.JSInterop
|
||||
@using MudBlazor
|
||||
@using TaxBaik.Web.Components.Admin
|
||||
@using TaxBaik.Web.Components.Admin.Services
|
||||
@using TaxBaik.Web.Components.Admin.Services.AdminClients
|
||||
@using TaxBaik.Application.DTOs
|
||||
@using TaxBaik.Domain.Entities
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
@@ -402,12 +402,11 @@ app.MapStaticAssets();
|
||||
// AllowAnonymous: JWT 미들웨어가 Blazor 셸 요청을 401로 차단하지 않도록 한다.
|
||||
// 인증은 Blazor AuthorizeRouteView → RedirectToLogin 에서 처리한다.
|
||||
// Phase 8: WebAssembly 렌더 모드 완전 마이그레이션
|
||||
// - App.razor: TaxBaik.WasmClient (호스트, WebAssembly)
|
||||
// - Routes + Pages + Shared + Layout + Forms: TaxBaik.WasmClient (WebAssembly)
|
||||
// MapRazorComponents는 자동으로 root 컴포넌트의 어셈블리 로드
|
||||
// 동일 어셈블리의 Page/Shared 컴포넌트는 자동 발견되므로 AddAdditionalAssemblies 불필요
|
||||
// (같은 어셈블리를 2번 등록하면 "Assembly already defined" 에러 발생)
|
||||
app.MapRazorComponents<TaxBaik.WasmClient.Components.Admin.App>()
|
||||
// - App.razor: TaxBaik.Web (메인 웹 서버)
|
||||
// - Routes + Pages + Shared + Layout + Forms: TaxBaik.Web (메인 웹 서버)
|
||||
// 모든 Blazor 컴포넌트가 웹 서버에서 통합 서비스됨
|
||||
// API는 웹 서버에서만 제공 (클라이언트 프로젝트 분리 불필요)
|
||||
app.MapRazorComponents<TaxBaik.Web.Components.Admin.App>()
|
||||
.AddInteractiveWebAssemblyRenderMode()
|
||||
.AllowAnonymous();
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TaxBaik.Application\TaxBaik.Application.csproj" />
|
||||
<ProjectReference Include="..\TaxBaik.Infrastructure\TaxBaik.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\TaxBaik.Web.Client\TaxBaik.Web.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>TaxBaik - 관리자 대시보드</title>
|
||||
<base href="/taxbaik/" />
|
||||
<link rel="icon" type="image/svg+xml" href="/taxbaik/favicon.svg" />
|
||||
<link rel="stylesheet" href="/taxbaik/css/admin.css" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet" />
|
||||
</head>
|
||||
<body class="blazor-dark">
|
||||
<div id="app"></div>
|
||||
|
||||
<!-- .NET 10 WebAssembly: blazor.webassembly.js (not blazor.web.js) -->
|
||||
<script src="/taxbaik/_framework/blazor.webassembly.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user