94 lines
3.2 KiB
C#
94 lines
3.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Security.Claims;
|
|
using TaxBaik.Application.Services;
|
|
|
|
namespace TaxBaik.Web.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class InquiryController : ControllerBase
|
|
{
|
|
private readonly InquiryService _inquiryService;
|
|
|
|
public InquiryController(InquiryService inquiryService)
|
|
{
|
|
_inquiryService = inquiryService;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Submit([FromBody] SubmitInquiryRequest request)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Name) || string.IsNullOrWhiteSpace(request.Phone))
|
|
return BadRequest(new ProblemDetails { Title = "이름과 전화번호를 입력하세요.", Status = StatusCodes.Status400BadRequest });
|
|
|
|
try
|
|
{
|
|
await _inquiryService.SubmitAsync(
|
|
request.Name,
|
|
request.Phone,
|
|
request.ServiceType,
|
|
request.Message,
|
|
request.Email,
|
|
HttpContext.Connection.RemoteIpAddress?.ToString());
|
|
return Ok(new { message = "상담 신청이 접수되었습니다." });
|
|
}
|
|
catch (ValidationException ex)
|
|
{
|
|
return BadRequest(new ProblemDetails { Title = ex.Message, Status = StatusCodes.Status400BadRequest });
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Authorize]
|
|
public async Task<IActionResult> GetPaged([FromQuery] int page = 1, [FromQuery] int pageSize = 20)
|
|
{
|
|
var (inquiries, total) = await _inquiryService.GetPagedAsync(page, pageSize);
|
|
return Ok(new { data = inquiries, total, page, pageSize });
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
[Authorize]
|
|
public async Task<IActionResult> GetById(int id)
|
|
{
|
|
var inquiry = await _inquiryService.GetByIdAsync(id);
|
|
if (inquiry == null)
|
|
return NotFound(new ProblemDetails { Title = "문의를 찾을 수 없습니다.", Status = StatusCodes.Status404NotFound });
|
|
return Ok(inquiry);
|
|
}
|
|
|
|
[HttpPut("{id}/status")]
|
|
[Authorize]
|
|
public async Task<IActionResult> UpdateStatus(int id, [FromBody] UpdateStatusRequest request)
|
|
{
|
|
var inquiry = await _inquiryService.GetByIdAsync(id);
|
|
if (inquiry == null)
|
|
return NotFound(new ProblemDetails { Title = "문의를 찾을 수 없습니다.", Status = StatusCodes.Status404NotFound });
|
|
|
|
try
|
|
{
|
|
var changedBy = User.FindFirstValue(ClaimTypes.Name) ?? User.Identity?.Name;
|
|
await _inquiryService.UpdateStatusAsync(id, request.Status, changedBy);
|
|
return Ok(new { message = "상태가 변경되었습니다." });
|
|
}
|
|
catch (ValidationException ex)
|
|
{
|
|
return BadRequest(new ProblemDetails { Title = ex.Message, Status = StatusCodes.Status400BadRequest });
|
|
}
|
|
}
|
|
}
|
|
|
|
public class SubmitInquiryRequest
|
|
{
|
|
public string Name { get; set; } = string.Empty;
|
|
public string Phone { get; set; } = string.Empty;
|
|
public string? Email { get; set; }
|
|
public string ServiceType { get; set; } = string.Empty;
|
|
public string Message { get; set; } = string.Empty;
|
|
}
|
|
|
|
public class UpdateStatusRequest
|
|
{
|
|
public string Status { get; set; } = string.Empty;
|
|
}
|