diff --git a/app/controllers/websites_controller.rb b/app/controllers/websites_controller.rb new file mode 100644 index 0000000..46e0d01 --- /dev/null +++ b/app/controllers/websites_controller.rb @@ -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 diff --git a/app/models/website.rb b/app/models/website.rb new file mode 100644 index 0000000..401b101 --- /dev/null +++ b/app/models/website.rb @@ -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 diff --git a/app/models/wedding.rb b/app/models/wedding.rb index e9bed42..36e3ca8 100644 --- a/app/models/wedding.rb +++ b/app/models/wedding.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index a4b7897..e908b04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] diff --git a/db/migrate/20250608181054_create_websites.rb b/db/migrate/20250608181054_create_websites.rb new file mode 100644 index 0000000..63715b7 --- /dev/null +++ b/db/migrate/20250608181054_create_websites.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 5a7e2fd..2576583 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/spec/factories/websites.rb b/spec/factories/websites.rb new file mode 100644 index 0000000..b8c4048 --- /dev/null +++ b/spec/factories/websites.rb @@ -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 diff --git a/spec/models/website_spec.rb b/spec/models/website_spec.rb new file mode 100644 index 0000000..a9533cd --- /dev/null +++ b/spec/models/website_spec.rb @@ -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