| name | api-controller |
| description | Generates REST API controllers following Clean Architecture and PortalEmpleo conventions. Use when implementing REST API endpoints, creating controllers, or defining API routes for the job portal application. |
| license | MIT |
| metadata | {"author":"course-team@netmind.es","version":"1.0.0"} |
| compatibility | Requires .NET 8 SDK and ASP.NET Core Web API |
| allowed-tools | Read Write Bash(git:*) Bash(dotnet:*) |
API Controller Skill - PortalEmpleo
When to use this skill
Use this skill when implementing REST API controllers for PortalEmpleo project. This skill is automatically triggered when the user mentions:
- Creating controllers
- API endpoints
- REST API
- Web API routes
Project Context
- Stack: .NET 8, ASP.NET Core Web API
- Architecture: Clean Architecture (Domain, Application, Infrastructure, Api)
- Autenticación: JWT HS256 (60min access, 7days refresh)
- Validation: FluentValidation
Controller Standards
Estructura del Controlador
namespace PortalEmpleo.Api.Controllers;
[ApiController]
[Route("api/v1/[controller]")]
[Produces("application/json")]
public class AuthController : ControllerBase
{
private readonly IAuthService _authService;
private readonly ILogger<AuthController> _logger;
public AuthController(IAuthService authService, ILogger<AuthController> logger)
{
_authService = authService;
_logger = logger;
}
[HttpPost("register")]
[ProducesResponseType(typeof(AuthResultDto), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> Register([FromBody] RegisterDto registerDto)
{
try
{
var result = await _authService.RegisterAsync(registerDto);
return StatusCode(StatusCodes.Status201Created, result);
}
catch (ValidationException ex)
{
return BadRequest(new ProblemDetails
{
Title = "Validation Error",
Detail = ex.Message
});
}
}
}
Required Elements
1. Atributos de Clase
[ApiController]
[Route("api/v1/[controller]")]
[Produces("application/json")]
2. Documentación XML
<summary> para la clase
<summary> para cada método público
<param> para parámetros
<returns> para valor de retorno
[ProducesResponseType] para todos los status codes posibles
3. Dependency Injection
- Inyectar interfaces de servicios
- Logger con ILogger
4. Manejo de Errores
- Try-catch con logging
- Devolver ProblemDetails para errores
5. convenciones de Nombres
- Controller suffix en nombre de clase
- PascalCase para métodos
- HTTP verbs: [HttpGet], [HttpPost], [HttpPut], [HttpPatch], [HttpDelete]
Example Endpoints PortalEmpleo
AuthController
[HttpPost("register")]
[HttpPost("login")]
[HttpPost("refresh")]
UsersController
[HttpGet("me")]
[HttpPut("me")]
[HttpDelete("me")]
JobOffersController
[HttpGet]
[HttpPost]
[HttpGet("{id}")]
[HttpPut("{id}")]
[HttpPatch("{id}/publish")]
[HttpPatch("{id}/pause")]
[HttpPatch("{id}/close")]
ApplicationsController
[HttpPost]
[HttpGet("me")]
[HttpGet("../job-offers/{id}/applications")]
[HttpPatch("{id}/status")]
Output Format
Generate complete .cs file with:
- All using statements
- Full class implementation
- XML documentation
- Error handling
- Route attributes
Files to Write
src/PortalEmpleo.Api/Controllers/[Feature]Controller.cs