diff --git a/app/controllers/api/bootcamp/drawings_controller.rb b/app/controllers/api/bootcamp/drawings_controller.rb index 5c626c82b4..bf9ce082ed 100644 --- a/app/controllers/api/bootcamp/drawings_controller.rb +++ b/app/controllers/api/bootcamp/drawings_controller.rb @@ -4,6 +4,7 @@ class API::Bootcamp::DrawingsController < API::Bootcamp::BaseController def update @drawing.update(code: params[:code]) if params[:code].present? @drawing.update(title: params[:title]) if params[:title].present? + @drawing.update(background_slug: params[:background_slug]) if params[:background_slug].present? render json: {}, status: :ok end diff --git a/app/helpers/react_components/bootcamp/drawing_page.rb b/app/helpers/react_components/bootcamp/drawing_page.rb index 826bb5f82f..deb1dbc3b5 100644 --- a/app/helpers/react_components/bootcamp/drawing_page.rb +++ b/app/helpers/react_components/bootcamp/drawing_page.rb @@ -12,12 +12,14 @@ def data { drawing: { uuid: drawing.uuid, - title: drawing.title + title: drawing.title, + background_slug: drawing.background_slug }, code: { code: drawing.code, stored_at: drawing.updated_at }, + backgrounds: BACKGROUNDS, links: { update_code: Exercism::Routes.api_bootcamp_drawing_url(drawing), drawings_index: Exercism::Routes.bootcamp_project_path(:drawing) @@ -25,4 +27,17 @@ def data } end end + + BACKGROUNDS = [ + { + slug: "none", + title: "No background", + image_url: nil + }, + { + slug: "room", + title: "A room to decorate", + image_url: "..." + } + ].freeze end diff --git a/db/migrate/20250110130304_add_background_slug_to_drawings.rb b/db/migrate/20250110130304_add_background_slug_to_drawings.rb new file mode 100644 index 0000000000..d4699f4ad9 --- /dev/null +++ b/db/migrate/20250110130304_add_background_slug_to_drawings.rb @@ -0,0 +1,7 @@ +class AddBackgroundSlugToDrawings < ActiveRecord::Migration[7.0] + def change + return if Rails.env.production? + + add_column :bootcamp_drawings, :background_slug, :string, null: false, default: "none" + end +end diff --git a/db/schema.rb b/db/schema.rb index 47fadbae7b..2afbd80e13 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[7.0].define(version: 2025_01_09_143039) do +ActiveRecord::Schema[7.0].define(version: 2025_01_10_130304) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -91,6 +91,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "title", null: false + t.string "background_slug", default: "none", null: false t.index ["user_id"], name: "index_bootcamp_drawings_on_user_id" end diff --git a/test/controllers/api/bootcamp/drawings_controller_test.rb b/test/controllers/api/bootcamp/drawings_controller_test.rb index ef03928bdb..1699a2e258 100644 --- a/test/controllers/api/bootcamp/drawings_controller_test.rb +++ b/test/controllers/api/bootcamp/drawings_controller_test.rb @@ -6,30 +6,34 @@ class API::Bootcamp::DrawingsControllerTest < API::BaseTestCase drawing = create(:bootcamp_drawing, user:) code = "Something" title = "New title" + background_slug = "beauty" setup_user(user) - patch api_bootcamp_drawing_url(drawing, code:, title:), headers: @headers + patch api_bootcamp_drawing_url(drawing, code:, title:, background_slug:), headers: @headers assert_response :ok assert_json_response({}) assert code, drawing.reload.code assert title, drawing.reload.title + assert background_slug, drawing.reload.background_slug end test "update: missing title doesn't touch code" do user = create :user code = "Something" title = "Some title" - drawing = create(:bootcamp_drawing, user:, code:, title:) + background_slug = "beauty" + drawing = create(:bootcamp_drawing, user:, code:, title:, background_slug:) setup_user(user) - patch api_bootcamp_drawing_url(drawing, title: ''), headers: @headers + patch api_bootcamp_drawing_url(drawing, title: '', background_slug: ''), headers: @headers assert_response :ok assert_json_response({}) assert code, drawing.reload.code assert title, drawing.reload.title + assert background_slug, drawing.reload.background_slug end end