first commit

This commit is contained in:
2026-08-08 21:14:10 -05:00
commit e1600da8b1
55 changed files with 2687 additions and 0 deletions
@@ -0,0 +1,9 @@
class ApplicationController < ActionController::API
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
private
def render_not_found
render json: { error: "not_found" }, status: :not_found
end
end
+8
View File
@@ -0,0 +1,8 @@
class HealthController < ActionController::API
def show
ActiveRecord::Base.connection.select_value("SELECT 1")
head :ok
rescue ActiveRecord::ActiveRecordError
head :service_unavailable
end
end
+41
View File
@@ -0,0 +1,41 @@
class TodosController < ApplicationController
before_action :set_todo, only: %i[show update destroy]
def index
render json: Todo.order(created_at: :desc)
end
def show
render json: @todo
end
def create
todo = Todo.new(todo_params)
todo.save!
render json: todo, status: :created
rescue ActiveRecord::RecordInvalid => error
render json: { errors: error.record.errors }, status: :unprocessable_entity
end
def update
@todo.update!(todo_params)
render json: @todo
rescue ActiveRecord::RecordInvalid => error
render json: { errors: error.record.errors }, status: :unprocessable_entity
end
def destroy
@todo.destroy!
head :no_content
end
private
def set_todo
@todo = Todo.find(params[:id])
end
def todo_params
params.expect(todo: %i[title completed])
end
end
+3
View File
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
+3
View File
@@ -0,0 +1,3 @@
class Todo < ApplicationRecord
validates :title, presence: true, length: { maximum: 255 }
end