Store website content as HTML #273
23
app/controllers/websites_controller.rb
Normal file
23
app/controllers/websites_controller.rb
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
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.expect(website: [:content])
|
||||
end
|
||||
end
|
25
app/models/website.rb
Normal file
25
app/models/website.rb
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == 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
|
@ -23,4 +23,5 @@ class Wedding < ApplicationRecord
|
||||
has_many :guests, dependent: :delete_all
|
||||
has_many :groups, dependent: :delete_all
|
||||
has_many :invitations, dependent: :delete_all
|
||||
has_one :website, dependent: :destroy
|
||||
end
|
||||
|
@ -37,6 +37,9 @@ Rails.application.routes.draw do
|
||||
resources :expenses, only: %i[index create update destroy] do
|
||||
get :summary, on: :collection
|
||||
end
|
||||
|
||||
resource :website, only: [:show, :update]
|
||||
|
||||
resources :tables_arrangements, only: %i[index show create]
|
||||
resources :summary, only: :index
|
||||
resources :invitations, only: %i[index create update destroy]
|
||||
|
10
db/migrate/20250608181054_create_websites.rb
Normal file
10
db/migrate/20250608181054_create_websites.rb
Normal 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
11
db/schema.rb
generated
@ -10,7 +10,7 @@
|
||||
#
|
||||
# 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
|
||||
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"
|
||||
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|
|
||||
t.string "slug", 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 "tables_arrangements", "weddings", on_delete: :cascade
|
||||
add_foreign_key "users", "weddings", on_delete: :cascade
|
||||
add_foreign_key "websites", "weddings"
|
||||
end
|
||||
|
10
spec/factories/websites.rb
Normal file
10
spec/factories/websites.rb
Normal file
@ -0,0 +1,10 @@
|
||||
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :website do
|
||||
content { 'MyText' }
|
||||
wedding { nil }
|
||||
end
|
||||
end
|
9
spec/models/website_spec.rb
Normal file
9
spec/models/website_spec.rb
Normal file
@ -0,0 +1,9 @@
|
||||
# Copyright (C) 2024-2025 LibreWeddingPlanner contributors
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Website do
|
||||
it { is_expected.to belong_to(:wedding) }
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user