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
15 16 17 18 19 20 21 22 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 15 def create prompt = Prompt.new(prompt_params) if prompt.save render json: prompt, status: :created else render json: {errors: prompt.errors}, status: :unprocessable_entity end end |
#destroy ⇒ Object
36 37 38 39 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 36 def destroy @prompt.destroy! head :no_content end |
#index ⇒ Object
7 8 9 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 7 def index render json: Prompt.order(created_at: :desc) end |
#publish ⇒ Object
41 42 43 44 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 41 def publish @prompt.publish! render json: @prompt.reload end |
#show ⇒ Object
11 12 13 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 11 def show render json: @prompt end |
#update ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/completion_kit/api/v1/prompts_controller.rb', line 24 def update if @prompt.runs.exists? new_prompt = @prompt.clone_as_new_version(prompt_params.to_h) new_prompt.publish! render json: new_prompt elsif @prompt.update(prompt_params) render json: @prompt else render json: {errors: @prompt.errors}, status: :unprocessable_entity end end |