feat: implement admin inquiry create/edit/delete functionality
TaxBaik CI/CD / build-and-deploy (push) Successful in 48s
TaxBaik CI/CD / build-and-deploy (push) Successful in 48s
Core Components: - Create reusable InquiryForm.razor component following SOLID principles - Implement InquiryCreate.razor for registering new inquiries (offline, phone) - Implement InquiryEdit.razor for modifying existing inquiries with delete - Add DeleteAsync method to InquiryRepository and InquiryService - Update InquiryList with 'Create' button and Edit link in table Architecture: - InquiryForm: Encapsulates form logic, can be reused for create/edit - Service Layer: All operations go through InquiryService for cache invalidation - Repository Pattern: Database operations isolated in InquiryRepository - UI Consistency: Both pages follow admin-page-hero pattern Features: - Admin can create inquiries from phone/offline consultations - Admin can modify inquiry details (name, phone, email, message, status, memo) - Admin can delete inquiries with confirmation dialog - All operations update dashboard cache - Status validation and error handling throughout Testing: - Updated FakeInquiryRepository in tests to implement DeleteAsync
This commit is contained in:
@@ -87,6 +87,14 @@ public class InquiryServiceTests
|
|||||||
inquiry.ClientId = clientId;
|
inquiry.ClientId = clientId;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task DeleteAsync(int id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var inquiry = Inquiries.FirstOrDefault(x => x.Id == id);
|
||||||
|
if (inquiry != null)
|
||||||
|
Inquiries.Remove(inquiry);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class FakeInquiryNotificationService : IInquiryNotificationService
|
private sealed class FakeInquiryNotificationService : IInquiryNotificationService
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ public class InquiryService(
|
|||||||
memoryCache.Remove(AdminDashboardService.CacheKey);
|
memoryCache.Remove(AdminDashboardService.CacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(int id, CancellationToken ct = default)
|
||||||
|
{
|
||||||
|
await repository.DeleteAsync(id, ct);
|
||||||
|
memoryCache.Remove(AdminDashboardService.CacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
private static int NormalizePage(int page) => Math.Max(1, page);
|
private static int NormalizePage(int page) => Math.Max(1, page);
|
||||||
|
|
||||||
private static int NormalizePageSize(int pageSize) => Math.Clamp(pageSize, 1, 100);
|
private static int NormalizePageSize(int pageSize) => Math.Clamp(pageSize, 1, 100);
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ public interface IInquiryRepository
|
|||||||
Task UpdateStatusAsync(int id, string status, CancellationToken cancellationToken = default);
|
Task UpdateStatusAsync(int id, string status, CancellationToken cancellationToken = default);
|
||||||
Task UpdateAdminMemoAsync(int id, string? adminMemo, CancellationToken cancellationToken = default);
|
Task UpdateAdminMemoAsync(int id, string? adminMemo, CancellationToken cancellationToken = default);
|
||||||
Task LinkClientAsync(int inquiryId, int clientId, CancellationToken cancellationToken = default);
|
Task LinkClientAsync(int inquiryId, int clientId, CancellationToken cancellationToken = default);
|
||||||
|
Task DeleteAsync(int id, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,4 +119,10 @@ public class InquiryRepository(IDbConnectionFactory connectionFactory) : BaseRep
|
|||||||
"UPDATE inquiries SET client_id = @ClientId, updated_at = NOW() WHERE id = @Id",
|
"UPDATE inquiries SET client_id = @ClientId, updated_at = NOW() WHERE id = @Id",
|
||||||
new { Id = inquiryId, ClientId = clientId });
|
new { Id = inquiryId, ClientId = clientId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(int id, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
using var conn = Conn();
|
||||||
|
await conn.ExecuteAsync("DELETE FROM inquiries WHERE id = @Id", new { Id = id });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
@using TaxBaik.Application.DTOs
|
||||||
|
@using TaxBaik.Application.Services
|
||||||
|
|
||||||
|
<MudForm @ref="form">
|
||||||
|
<MudTextField @bind-Value="model.Name" Label="이름"
|
||||||
|
Variant="Variant.Outlined" Class="mb-4" Required="true" />
|
||||||
|
|
||||||
|
<MudTextField @bind-Value="model.Phone" Label="전화번호 (예: 010-1234-5678)"
|
||||||
|
Variant="Variant.Outlined" Class="mb-4" Required="true" />
|
||||||
|
|
||||||
|
<MudTextField @bind-Value="model.Email" Label="이메일"
|
||||||
|
Variant="Variant.Outlined" Class="mb-4" InputType="InputType.Email" />
|
||||||
|
|
||||||
|
<MudSelect @bind-Value="model.ServiceType" Label="문의 유형"
|
||||||
|
Variant="Variant.Outlined" Class="mb-4">
|
||||||
|
<MudSelectItem Value="@("사업자세무")">사업자세무</MudSelectItem>
|
||||||
|
<MudSelectItem Value="@("부동산세금")">부동산세금</MudSelectItem>
|
||||||
|
<MudSelectItem Value="@("가족자산")">가족자산</MudSelectItem>
|
||||||
|
<MudSelectItem Value="@("기타")">기타</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
|
||||||
|
<MudTextField @bind-Value="model.Message" Label="문의 내용"
|
||||||
|
Variant="Variant.Outlined" Lines="5" Class="mb-4" Required="true" />
|
||||||
|
|
||||||
|
<MudSelect @bind-Value="model.Status" Label="상태"
|
||||||
|
Variant="Variant.Outlined" Class="mb-4">
|
||||||
|
<MudSelectItem Value="@("new")">신규</MudSelectItem>
|
||||||
|
<MudSelectItem Value="@("consulting")">상담중</MudSelectItem>
|
||||||
|
<MudSelectItem Value="@("contracted")">계약완료</MudSelectItem>
|
||||||
|
<MudSelectItem Value="@("rejected")">거절</MudSelectItem>
|
||||||
|
<MudSelectItem Value="@("closed")">종결</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
|
||||||
|
<MudTextField @bind-Value="model.AdminMemo" Label="관리 메모"
|
||||||
|
Variant="Variant.Outlined" Lines="3" 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<InquiryFormModel> OnSubmit { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public EventCallback OnCancel { get; set; }
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public InquiryFormModel? InitialData { get; set; }
|
||||||
|
|
||||||
|
private MudForm? form;
|
||||||
|
private InquiryFormModel model = new();
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,9 @@
|
|||||||
<td>@inquiry.CreatedAt.ToString("yyyy-MM-dd")</td>
|
<td>@inquiry.CreatedAt.ToString("yyyy-MM-dd")</td>
|
||||||
<td>
|
<td>
|
||||||
<MudButton Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary"
|
<MudButton Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary"
|
||||||
Href="@($"/taxbaik/admin/inquiries/{inquiry.Id}")">문의 내용 확인</MudButton>
|
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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
@page "/admin/inquiries/create"
|
||||||
|
@attribute [Authorize]
|
||||||
|
@using TaxBaik.Application.DTOs
|
||||||
|
@using TaxBaik.Application.Services
|
||||||
|
@using TaxBaik.Web.Components.Admin.Forms
|
||||||
|
@inject InquiryService InquiryService
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
|
||||||
|
<PageTitle>문의 등록</PageTitle>
|
||||||
|
|
||||||
|
<section class="admin-page-hero">
|
||||||
|
<div>
|
||||||
|
<MudText Typo="Typo.caption" Class="admin-eyebrow">Customer Relations</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">
|
||||||
|
<InquiryForm ButtonText="등록" OnSubmit="HandleCreate" OnCancel="GoBack" />
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private void GoBack()
|
||||||
|
{
|
||||||
|
Navigation.NavigateTo("/taxbaik/admin/inquiries");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleCreate(InquiryForm.InquiryFormModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await InquiryService.SubmitAsync(
|
||||||
|
model.Name,
|
||||||
|
model.Phone,
|
||||||
|
model.ServiceType,
|
||||||
|
model.Message,
|
||||||
|
model.Email,
|
||||||
|
ipAddress: "admin-registered");
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
@page "/admin/inquiries/{id:int}/edit"
|
||||||
|
@attribute [Authorize]
|
||||||
|
@using TaxBaik.Application.DTOs
|
||||||
|
@using TaxBaik.Application.Services
|
||||||
|
@using TaxBaik.Web.Components.Admin.Forms
|
||||||
|
@inject InquiryService InquiryService
|
||||||
|
@inject NavigationManager Navigation
|
||||||
|
@inject ISnackbar Snackbar
|
||||||
|
@inject IDialogService DialogService
|
||||||
|
|
||||||
|
<PageTitle>문의 수정</PageTitle>
|
||||||
|
|
||||||
|
<section class="admin-page-hero">
|
||||||
|
<div>
|
||||||
|
<MudText Typo="Typo.caption" Class="admin-eyebrow">Customer Relations</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>
|
||||||
|
|
||||||
|
@if (isLoading)
|
||||||
|
{
|
||||||
|
<MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="mt-4" />
|
||||||
|
}
|
||||||
|
else 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" />
|
||||||
|
|
||||||
|
<MudDivider Class="my-4" />
|
||||||
|
|
||||||
|
<MudButton Variant="Variant.Outlined" Color="Color.Error" @onclick="DeleteInquiry" Class="mt-2">
|
||||||
|
문의 삭제
|
||||||
|
</MudButton>
|
||||||
|
</MudPaper>
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
private Domain.Entities.Inquiry? inquiry;
|
||||||
|
private InquiryForm.InquiryFormModel? formModel;
|
||||||
|
private bool isLoading = true;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
inquiry = await InquiryService.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
|
||||||
|
{
|
||||||
|
inquiry.Name = model.Name;
|
||||||
|
inquiry.Phone = model.Phone;
|
||||||
|
inquiry.Email = model.Email;
|
||||||
|
inquiry.ServiceType = model.ServiceType;
|
||||||
|
inquiry.Message = model.Message;
|
||||||
|
inquiry.AdminMemo = model.AdminMemo;
|
||||||
|
|
||||||
|
if (inquiry.Status != model.Status)
|
||||||
|
{
|
||||||
|
await InquiryService.UpdateStatusAsync(inquiry.Id, model.Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
await InquiryService.UpdateAdminMemoAsync(inquiry.Id, model.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
|
||||||
|
{
|
||||||
|
await InquiryService.DeleteAsync(inquiry.Id);
|
||||||
|
Snackbar.Add("문의가 삭제되었습니다.", Severity.Success);
|
||||||
|
Navigation.NavigateTo("/taxbaik/admin/inquiries");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Snackbar.Add($"삭제 실패: {ex.Message}", Severity.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@
|
|||||||
<MudText Typo="Typo.h4" Class="admin-page-title">문의 관리</MudText>
|
<MudText Typo="Typo.h4" Class="admin-page-title">문의 관리</MudText>
|
||||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">상담 요청을 상태별로 확인하고 후속 조치를 기록합니다.</MudText>
|
<MudText Typo="Typo.body2" Class="admin-page-subtitle">상담 요청을 상태별로 확인하고 후속 조치를 기록합니다.</MudText>
|
||||||
</div>
|
</div>
|
||||||
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Add"
|
||||||
|
Href="/taxbaik/admin/inquiries/create">새 문의 등록</MudButton>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<MudPaper Class="admin-surface" Elevation="0">
|
<MudPaper Class="admin-surface" Elevation="0">
|
||||||
|
|||||||
Reference in New Issue
Block a user