Skip to content
Back to skills

Scaffold Controller Gsu26se55 Frontend

ASecurity

Scaffold REST API Controller với full CRUD endpoints, authorization, MediatR integration

  • 30 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 8, 2026
ai-agentsapi

Works with

  • api

Security analysis

A100/100

Scanned November 8, 2026

npx -y skills add majiayu000/claude-skill-registry-data --skill scaffold-controller --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Scaffold Controller Gsu26se55 Frontend?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Scaffold Controller Gsu26se55 Frontend
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-scaffold-controller-gsu26se55-frontend/badge)](https://www.skillsdirectory.com/skills/majiayu000-scaffold-controller-gsu26se55-frontend)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: scaffold-controller
description: Scaffold REST API Controller với full CRUD endpoints, authorization, MediatR integration
argument-hint: [ServiceName EntityName]
allowed-tools: Write, Read, Edit
---

# Scaffold Controller `$ARGUMENTS`

Usage: `/scaffold-controller ServiceName EntityName`

## File: `Api/Controllers/{Entity}Controller.cs`

```csharp
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using {Service}.Application.Commands.{Entity}Create;
using {Service}.Application.Commands.{Entity}Update;
using {Service}.Application.Commands.{Entity}Delete;
using {Service}.Application.Commands.{Entity}Restore;
using {Service}.Application.Queries.{Entity}GetList;
using {Service}.Application.Queries.{Entity}GetById;

namespace {Service}.Api.Controllers;

[ApiController]
[Route("api/{entities}")]  // lowercase, plural, kebab-case
public class {Entity}Controller : ControllerBase
{
    private readonly IMediator _mediator;

    public {Entity}Controller(IMediator mediator) => _mediator = mediator;

    [HttpGet]
    public async Task<IActionResult> GetAll([FromQuery] {Entity}GetListQuery query)
        => Ok(await _mediator.Send(query));

    [HttpGet("{id}")]
    public async Task<IActionResult> GetById(Guid id, [FromQuery] string? fields,
        [FromQuery] bool? hasParent, [FromQuery] bool? hasChildren)
        => Ok(await _mediator.Send(new {Entity}GetByIdQuery
        {
            Id = id, Fields = fields,
            HasParent = hasParent ?? true, HasChildren = hasChildren ?? true,
        }));

    [HttpPost]
    [Authorize]  // Adjust: [Authorize(Policy = "AdminOnly")] or [Authorize(Policy = "ManagerOnly")]
    public async Task<IActionResult> Create([FromBody] {Entity}CreateCommand command)
        => Ok(await _mediator.Send(command));

    [HttpPut("{id}")]
    [Authorize]
    public async Task<IActionResult> Update(Guid id, [FromBody] {Entity}UpdateCommand command)
    { command.Id = id; return Ok(await _mediator.Send(command)); }

    [HttpDelete("{id}")]
    [Authorize(Policy = "AdminOnly")]
    public async Task<IActionResult> Delete(Guid id)
        => Ok(await _mediator.Send(new {Entity}DeleteCommand { Id = id }));

    [HttpPatch("{id}")]
    [Authorize(Policy = "AdminOnly")]
    public async Task<IActionResult> Restore(Guid id)
        => Ok(await _mediator.Send(new {Entity}RestoreCommand { Id = id }));
}
```

## HTTP Method Mapping

| Action | Method | Route | Auth |
|--------|--------|-------|------|
| List | GET | `/` | Public |
| Detail | GET | `/{id}` | Public |
| Create | POST | `/` | Auth |
| Update | PUT | `/{id}` | Auth |
| Delete (soft) | DELETE | `/{id}` | AdminOnly |
| Restore | PATCH | `/{id}` | AdminOnly |
| Custom action | PATCH | `/{id}/action` | Varies |

## Authorization

- `[Authorize]` — any authenticated user (Staff, Manager, Admin)
- `[Authorize(Policy = "AdminOnly")]` — Role = "1"
- `[Authorize(Policy = "ManagerOnly")]` — Role = "2"
- `[AllowAnonymous]` — internal/public endpoints
- No attribute = public (GET list/detail usually public)

## Rules
- Controller THIN — chỉ `_mediator.Send()`, KHÔNG chứa business logic
- `[FromBody]` cho POST/PUT, `[FromQuery]` cho GET
- Route: lowercase, plural, kebab-case
- Return `Ok(result)` — wrapper handles success/failure

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.