Class: ActionAgent::Api::TemplatesController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ActionAgent::ApplicationController
- BaseController
- ActionAgent::Api::TemplatesController
- Defined in:
- app/controllers/action_agent/api/templates_controller.rb
Instance Method Summary collapse
-
#index ⇒ Object
GET /api/templates.
-
#show ⇒ Object
GET /api/templates/:id.
-
#use ⇒ Object
POST /api/templates/:id/use.
Methods inherited from ActionAgent::ApplicationController
Instance Method Details
#index ⇒ Object
GET /api/templates
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/action_agent/api/templates_controller.rb', line 12 def index @templates = AgentTemplate.public_templates.order(usage_count: :desc) # Filter by category @templates = @templates.by_category(params[:category]) if params[:category].present? # Featured only @templates = @templates.featured if params[:featured].present? render json: { templates: @templates.map { |t| template_json(t) }, categories: AgentTemplate::CATEGORIES } end |
#show ⇒ Object
GET /api/templates/:id
28 29 30 31 |
# File 'app/controllers/action_agent/api/templates_controller.rb', line 28 def show @template = AgentTemplate.find(params[:id]) render json: { template: template_json(@template, include_details: true) } end |
#use ⇒ Object
POST /api/templates/:id/use
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/action_agent/api/templates_controller.rb', line 34 def use @template = AgentTemplate.find(params[:id]) agent = @template.create_agent_for( current_user, name: params[:name] || @template.name ) if agent.persisted? render json: { agent: agent_json(agent) }, status: :created else render json: { errors: agent.errors. }, status: :unprocessable_entity end end |