76 lines
3.0 KiB
C#
76 lines
3.0 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using SPMS.Application.DTOs.Device;
|
|
using SPMS.Application.Interfaces;
|
|
using SPMS.Domain.Common;
|
|
|
|
namespace SPMS.API.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("v1/in/device")]
|
|
[ApiExplorerSettings(GroupName = "device")]
|
|
public class DeviceController : ControllerBase
|
|
{
|
|
private readonly IDeviceService _deviceService;
|
|
|
|
public DeviceController(IDeviceService deviceService)
|
|
{
|
|
_deviceService = deviceService;
|
|
}
|
|
|
|
[HttpPost("register")]
|
|
[SwaggerOperation(Summary = "디바이스 등록", Description = "앱 최초 설치 시 디바이스를 등록합니다.")]
|
|
public async Task<IActionResult> RegisterAsync([FromBody] DeviceRegisterRequestDto request)
|
|
{
|
|
var serviceId = GetServiceId();
|
|
var result = await _deviceService.RegisterAsync(serviceId, request);
|
|
return Ok(ApiResponse<DeviceRegisterResponseDto>.Success(result));
|
|
}
|
|
|
|
[HttpPost("info")]
|
|
[SwaggerOperation(Summary = "디바이스 조회", Description = "디바이스 정보를 조회합니다.")]
|
|
public async Task<IActionResult> GetInfoAsync([FromBody] DeviceInfoRequestDto request)
|
|
{
|
|
var serviceId = GetServiceId();
|
|
var result = await _deviceService.GetInfoAsync(serviceId, request);
|
|
return Ok(ApiResponse<DeviceInfoResponseDto>.Success(result));
|
|
}
|
|
|
|
[HttpPost("update")]
|
|
[SwaggerOperation(Summary = "디바이스 수정", Description = "앱 실행 시 디바이스 정보를 업데이트합니다.")]
|
|
public async Task<IActionResult> UpdateAsync([FromBody] DeviceUpdateRequestDto request)
|
|
{
|
|
var serviceId = GetServiceId();
|
|
await _deviceService.UpdateAsync(serviceId, request);
|
|
return Ok(ApiResponse.Success());
|
|
}
|
|
|
|
[HttpPost("delete")]
|
|
[SwaggerOperation(Summary = "디바이스 삭제", Description = "앱 삭제/로그아웃 시 디바이스를 비활성화합니다.")]
|
|
public async Task<IActionResult> DeleteAsync([FromBody] DeviceDeleteRequestDto request)
|
|
{
|
|
var serviceId = GetServiceId();
|
|
await _deviceService.DeleteAsync(serviceId, request);
|
|
return Ok(ApiResponse.Success());
|
|
}
|
|
|
|
[HttpPost("list")]
|
|
[Authorize]
|
|
[SwaggerOperation(Summary = "디바이스 목록", Description = "대시보드에서 디바이스 목록을 조회합니다. JWT 인증 필요.")]
|
|
public async Task<IActionResult> GetListAsync([FromBody] DeviceListRequestDto request)
|
|
{
|
|
var serviceId = GetServiceId();
|
|
var result = await _deviceService.GetListAsync(serviceId, request);
|
|
return Ok(ApiResponse<DeviceListResponseDto>.Success(result));
|
|
}
|
|
|
|
private long GetServiceId()
|
|
{
|
|
if (HttpContext.Items.TryGetValue("ServiceId", out var serviceIdObj) && serviceIdObj is long serviceId)
|
|
return serviceId;
|
|
|
|
throw new Domain.Exceptions.SpmsException(ErrorCodes.BadRequest, "서비스 식별 정보가 없습니다.", 400);
|
|
}
|
|
}
|