106 lines
3.7 KiB
C#
106 lines
3.7 KiB
C#
using CompanyManagment.App.Contracts.CameraBugReport;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace ServiceHost.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class BugReportController : ControllerBase
|
|
{
|
|
private readonly ICameraBugReportApplication _bugReportApplication;
|
|
|
|
public BugReportController(ICameraBugReportApplication bugReportApplication)
|
|
{
|
|
_bugReportApplication = bugReportApplication;
|
|
}
|
|
|
|
/// <summary>
|
|
/// ثبت یک گزارش خرابی جدید
|
|
/// </summary>
|
|
[HttpPost("submit")]
|
|
public IActionResult SubmitBugReport([FromBody] CreateCameraBugReportCommand command)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
return BadRequest(ModelState);
|
|
|
|
var result = _bugReportApplication.Create(command);
|
|
if (result.IsSuccedded)
|
|
return Ok(new { success = true, message = result.Message });
|
|
|
|
return BadRequest(new { success = false, message = result.Message });
|
|
}
|
|
|
|
/// <summary>
|
|
/// دریافت تمام گزارشهای خرابی (برای Admin)
|
|
/// </summary>
|
|
[HttpGet("list")]
|
|
public IActionResult GetBugReports(
|
|
[FromQuery] int? type,
|
|
[FromQuery] int? priority,
|
|
[FromQuery] int? status,
|
|
[FromQuery] string searchTerm = "",
|
|
[FromQuery] int pageNumber = 1,
|
|
[FromQuery] int pageSize = 10)
|
|
{
|
|
var searchModel = new CameraBugReportSearchModel
|
|
{
|
|
Type = type.HasValue ? (CameraBugReportType)type.Value : null,
|
|
Priority = priority.HasValue ? (CameraBugPriority)priority.Value : null,
|
|
Status = status.HasValue ? (CameraBugReportStatus)status.Value : null,
|
|
SearchTerm = searchTerm,
|
|
PageNumber = pageNumber,
|
|
PageSize = pageSize
|
|
};
|
|
|
|
var bugReports = _bugReportApplication.GetAll(searchModel);
|
|
return Ok(new { success = true, data = bugReports });
|
|
}
|
|
|
|
/// <summary>
|
|
/// دریافت جزئیات یک گزارش خرابی
|
|
/// </summary>
|
|
[HttpGet("{id}")]
|
|
public IActionResult GetBugReportDetails(long id)
|
|
{
|
|
var bugReport = _bugReportApplication.GetDetails(id);
|
|
if (bugReport == null)
|
|
return NotFound(new { success = false, message = "گزارش خرابی یافت نشد." });
|
|
|
|
return Ok(new { success = true, data = bugReport });
|
|
}
|
|
|
|
/// <summary>
|
|
/// ویرایش یک گزارش خرابی
|
|
/// </summary>
|
|
[HttpPut("{id}")]
|
|
public IActionResult EditBugReport(long id, [FromBody] EditCameraBugReportCommand command)
|
|
{
|
|
if (id != command.Id)
|
|
return BadRequest(new { success = false, message = "ID مطابقت ندارد." });
|
|
|
|
if (!ModelState.IsValid)
|
|
return BadRequest(ModelState);
|
|
|
|
var result = _bugReportApplication.Edit(command);
|
|
if (result.IsSuccedded)
|
|
return Ok(new { success = true, message = result.Message });
|
|
|
|
return BadRequest(new { success = false, message = result.Message });
|
|
}
|
|
|
|
/// <summary>
|
|
/// حذف یک گزارش خرابی
|
|
/// </summary>
|
|
[HttpDelete("{id}")]
|
|
public IActionResult DeleteBugReport(long id)
|
|
{
|
|
var result = _bugReportApplication.Delete(id);
|
|
if (result.IsSuccedded)
|
|
return Ok(new { success = true, message = result.Message });
|
|
|
|
return BadRequest(new { success = false, message = result.Message });
|
|
}
|
|
}
|
|
}
|
|
|