Class: CompletionKit::Api::V1::PromptsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- CompletionKit::Api::V1::PromptsController
- Defined in:
- app/controllers/completion_kit/api/v1/prompts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #publish ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 17 def create prompt = Prompt.new(prompt_params) if prompt.save render json: prompt, status: :created else render_validation_errors(prompt) end end |
#destroy ⇒ Object
45 46 47 48 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 45 def destroy @prompt.destroy! head :no_content end |
#index ⇒ Object
7 8 9 10 11 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 7 def index scope = Prompt.includes(:tags) scope = (scope) render json: paginate(scope.order(created_at: :desc)) end |
#publish ⇒ Object
50 51 52 53 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 50 def publish @prompt.publish! render json: @prompt.reload end |
#show ⇒ Object
13 14 15 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 13 def show render json: @prompt end |
#update ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 26 def update if @prompt.runs.exists? new_prompt = @prompt.build_next_version(prompt_params.to_h) if new_prompt.valid? CompletionKit::ApplicationRecord.transaction do new_prompt.save! new_prompt.publish! end render json: new_prompt.reload else render_validation_errors(new_prompt) end elsif @prompt.update(prompt_params) render json: @prompt else render_validation_errors(@prompt) end end |