diff --git a/app/models/hackathon/regional.rb b/app/models/hackathon/regional.rb index ec73f17d..b814375e 100644 --- a/app/models/hackathon/regional.rb +++ b/app/models/hackathon/regional.rb @@ -35,6 +35,18 @@ def country ISO3166::Country[country_code]&.common_name end + # TODO: This method and the `apac` column is a temporary solution! + # The column contains the migrated `apac` boolean from Airtable. Newly created + # hackathons (after the migration) will have the `apac` column set to `nil`, + # where it uses on the Country gem to determine if the hackathon is in APAC. + # + # See https://github.com/hackclub/hackathons-backend/issues/106 + def apac? + return apac unless apac.nil? + + ISO3166::Country[country_code]&.world_region == "APAC" + end + def to_location Location.new(city, province, country_code) end diff --git a/app/views/api/hackathons/_hackathon.json.v1.jbuilder b/app/views/api/hackathons/_hackathon.json.v1.jbuilder index cd4f8d48..f1952587 100644 --- a/app/views/api/hackathons/_hackathon.json.v1.jbuilder +++ b/app/views/api/hackathons/_hackathon.json.v1.jbuilder @@ -18,4 +18,7 @@ shape_for hackathon, json do json.longitude hackathon.longitude json.latitude hackathon.latitude end + + # This is temporary! See `Hackathon.apac?` for more info. + json.apac hackathon.apac? end diff --git a/db/migrate/20230814030407_add_apac_to_hackathon.rb b/db/migrate/20230814030407_add_apac_to_hackathon.rb new file mode 100644 index 00000000..61659855 --- /dev/null +++ b/db/migrate/20230814030407_add_apac_to_hackathon.rb @@ -0,0 +1,5 @@ +class AddApacToHackathon < ActiveRecord::Migration[7.0] + def change + add_column :hackathons, :apac, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index fb8b149d..9839b767 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: 2023_08_11_051252) do +ActiveRecord::Schema[7.0].define(version: 2023_08_14_030407) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -118,12 +118,13 @@ t.string "street" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.bigint "applicant_id", null: false t.string "website" t.boolean "high_school_led", default: true, null: false t.integer "expected_attendees" t.integer "modality", default: 0, null: false + t.bigint "applicant_id", null: false t.bigint "swag_mailing_address_id" + t.boolean "apac" t.index ["address"], name: "index_hackathons_on_address" t.index ["applicant_id"], name: "index_hackathons_on_applicant_id" t.index ["country_code", "city"], name: "index_hackathons_on_country_code_and_city"