using Microsoft.AspNetCore.Mvc; using WmsLite.Api.Common; using WmsLite.Api.Dtos.Location; using WmsLite.Api.Infrastructure.Auth; using WmsLite.Api.Services.Interfaces; namespace WmsLite.Api.Controllers; [ApiController] [Route("api/[controller]")] public class LocationController : WmsLiteControllerBase { private readonly ILocationService _locationService; public LocationController(ILocationService locationService, ICurrentUserContext currentUser) : base(currentUser) { _locationService = locationService; } [HttpPost("paged-list")] public async Task> GetPagedList([FromBody] LocationPagedQuery request) { var result = await _locationService.GetPagedListAsync(request); return Ok(BusinessResult.Ok(result)); } [HttpGet("{id:long}")] public async Task> GetById(long id) { var result = await _locationService.GetByIdAsync(id, TenantId, OwnerCode); return result is null ? NotFound(BusinessResult.NotFound("Resource not found.")) : Ok(BusinessResult.Ok(result)); } [HttpPost("batch-create")] public async Task> BatchCreate([FromBody] LocationBatchCreateRequest request) { var result = await _locationService.BatchCreateAsync(request); return Ok(BusinessResult.Ok(result)); } [HttpPost("create")] public async Task> Create([FromBody] LocationSaveRequest request) { var result = await _locationService.CreateAsync(request); return Ok(BusinessResult.Ok(result)); } [HttpPut("update")] public async Task> Update([FromBody] LocationUpdateRequest request) { var result = await _locationService.UpdateAsync(request); return result is null ? NotFound(BusinessResult.NotFound("Resource not found.")) : Ok(BusinessResult.Ok(result)); } [HttpDelete("{id:long}")] public async Task> Delete(long id) { var affectedRows = await _locationService.DeleteAsync(id, TenantId, OwnerCode); return Ok(BusinessResult.Ok(new { AffectedRows = affectedRows })); } }