using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ZeroFramework.DeviceCenter.Application.Models.Projects;
using ZeroFramework.DeviceCenter.Application.PermissionProviders;
using ZeroFramework.DeviceCenter.Application.Services.Generics;
namespace ZeroFramework.DeviceCenter.API.Controllers
{
///
/// For more information on enabling Web API for empty projects
///
[Route("api/[controller]")]
[ApiController]
public class ProjectsController(ICrudApplicationService crudService) : ControllerBase
{
private readonly ICrudApplicationService _crudService = crudService;
// GET: api/
[HttpGet]
[Authorize(ProjectPermissions.Projects.Default)]
public async Task> Get([FromQuery] PagedRequestModel model)
{
return await _crudService.GetListAsync(model);
}
// GET api//5
[HttpGet("{id}")]
[Authorize(ProjectPermissions.Projects.Default)]
public async Task Get(int id)
{
return await _crudService.GetAsync(id);
}
// POST api/
[HttpPost]
[Authorize(ProjectPermissions.Projects.Create)]
public async Task Post([FromBody] ProjectCreateOrUpdateRequestModel value)
{
return await _crudService.CreateAsync(value);
}
// PUT api//5
[HttpPut("{id}")]
[Authorize(ProjectPermissions.Projects.Edit)]
public async Task Put(int id, [FromBody] ProjectCreateOrUpdateRequestModel value)
{
value.Id = id;
return await _crudService.UpdateAsync(id, value);
}
// DELETE api//5
[HttpDelete("{id}")]
[Authorize(ProjectPermissions.Projects.Delete)]
public async Task Delete(int id)
{
await _crudService.DeleteAsync(id);
}
}
}