events api

This commit is contained in:
2026-05-05 19:49:24 +02:00
parent 66442c420b
commit 130be14c59
6 changed files with 86 additions and 42 deletions
+35
View File
@@ -0,0 +1,35 @@
ActiveAdmin.register Event do
permit_params :name, :date
menu priority: 3
index do
selectable_column
id_column
column :name
column :date
column :created_at
actions
end
filter :name
filter :date
show do
attributes_table do
row :id
row :name
row :date
row :created_at
row :updated_at
end
end
form do |f|
f.inputs do
f.input :name
f.input :date, as: :date_time_picker
end
f.actions
end
end
@@ -0,0 +1,8 @@
class Api::EventsController < ApiController
def index
events = Event.upcoming.map do |e|
{ name: e.name, date: e.date.utc.strftime("%Y-%m-%dT%H:%M:%SZ") }
end
render json: events
end
end
+9
View File
@@ -0,0 +1,9 @@
class Event < ApplicationRecord
default_scope { where(deleted_at: nil) }
scope :upcoming, -> { where("date > ?", Time.current).order(:date) }
def self.ransackable_attributes(auth_object = nil)
%w[id name date created_at updated_at]
end
end
+1
View File
@@ -5,6 +5,7 @@ Rails.application.routes.draw do
namespace :api do
get "software", to: "software#index"
get "software/highlighted", to: "software_highlighted#index"
get "events", to: "events#index"
end
get "update", to: "update#update"
@@ -0,0 +1,15 @@
class CreateEvents < ActiveRecord::Migration[8.1]
def change
create_table :events, id: { type: :bigint, unsigned: true },
charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci",
if_not_exists: true do |t|
t.string :name, null: false
t.datetime :date, null: false
t.datetime :deleted_at, precision: 3
t.timestamps precision: 3
t.index :deleted_at, name: "idx_events_deleted_at"
t.index :date, name: "idx_events_date"
end
end
end