Store website content as HTML #273

Merged
bustikiller merged 3 commits from store-website into main 2025-06-08 21:35:43 +00:00
8 changed files with 75 additions and 1 deletions
Showing only changes of commit cc10fbfb83 - Show all commits

View File

@ -0,0 +1,19 @@
class WebsitesController < ApplicationController
def show
render json: current_tenant.website.as_json(only: %i[content]) || {}, status: :ok
end
def update
ActiveRecord::Base.transaction do
website = current_tenant.website || current_tenant.create_website
website.update!(website_params)
render json: website.as_json(only: %i[content]), status: :ok
end
end
private
def website_params
params.require(:website).permit(:content)
end
end

21
app/models/website.rb Normal file
View File

@ -0,0 +1,21 @@
# == Schema Information
#
# Table name: websites
#
# id :bigint not null, primary key
# content :text
# created_at :datetime not null
# updated_at :datetime not null
# wedding_id :uuid not null
#
# Indexes
#
# index_websites_on_wedding_id (wedding_id)
#
# Foreign Keys
#
# fk_rails_... (wedding_id => weddings.id)
#
class Website < ApplicationRecord
belongs_to :wedding
end

View File

@ -23,4 +23,5 @@ class Wedding < ApplicationRecord
has_many :guests, dependent: :delete_all has_many :guests, dependent: :delete_all
has_many :groups, dependent: :delete_all has_many :groups, dependent: :delete_all
has_many :invitations, dependent: :delete_all has_many :invitations, dependent: :delete_all
has_one :website, dependent: :destroy
end end

View File

@ -37,6 +37,9 @@ Rails.application.routes.draw do
resources :expenses, only: %i[index create update destroy] do resources :expenses, only: %i[index create update destroy] do
get :summary, on: :collection get :summary, on: :collection
end end
resource :website, only: [:show, :update]
resources :tables_arrangements, only: %i[index show create] resources :tables_arrangements, only: %i[index show create]
resources :summary, only: :index resources :summary, only: :index
resources :invitations, only: %i[index create update destroy] resources :invitations, only: %i[index create update destroy]

View File

@ -0,0 +1,10 @@
class CreateWebsites < ActiveRecord::Migration[8.0]
def change
create_table :websites do |t|
t.text :content
t.references :wedding, null: false, foreign_key: true, type: :uuid
t.timestamps
end
end
end

11
db/schema.rb generated
View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_01_27_190131) do ActiveRecord::Schema[8.0].define(version: 2025_06_08_181054) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql" enable_extension "pg_catalog.plpgsql"
@ -241,6 +241,14 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_27_190131) do
t.index ["wedding_id"], name: "index_users_on_wedding_id" t.index ["wedding_id"], name: "index_users_on_wedding_id"
end end
create_table "websites", force: :cascade do |t|
t.text "content"
t.uuid "wedding_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["wedding_id"], name: "index_websites_on_wedding_id"
end
create_table "weddings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "weddings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "slug", null: false t.string "slug", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
@ -268,4 +276,5 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_27_190131) do
add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
add_foreign_key "tables_arrangements", "weddings", on_delete: :cascade add_foreign_key "tables_arrangements", "weddings", on_delete: :cascade
add_foreign_key "users", "weddings", on_delete: :cascade add_foreign_key "users", "weddings", on_delete: :cascade
add_foreign_key "websites", "weddings"
end end

View File

@ -0,0 +1,6 @@
FactoryBot.define do
factory :website do
content { "MyText" }
wedding { nil }
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Website, type: :model do
it { should belong_to(:wedding) }
end