Skip to content

Commit 54e2fe6

Browse files
authored
Organization CRUD (#153)
* Create Organization and Address resources * Create FacilitatorOrganization association
1 parent 57224bd commit 54e2fe6

18 files changed

+339
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class AddressesController < ApplicationController
2+
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class OrganizationsController < ApplicationController
2+
end

app/models/address.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Address < ApplicationRecord
2+
belongs_to :organization
3+
4+
validates :street, presence: true
5+
validates :city, presence: true
6+
validates :state, presence: true
7+
validates :zip, presence: true
8+
end

app/models/facilitator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class Facilitator < ApplicationRecord
22
has_one :user
3+
has_many :facilitator_organizations, dependent: :restrict_with_exception
4+
has_many :organizations, through: :facilitator_organizations
35

46
CONTACT_TYPES = ["Work", "Personal"].freeze
57
PERMITTED_PARAMS = [
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class FacilitatorOrganization < ApplicationRecord
2+
belongs_to :facilitator
3+
belongs_to :organization
4+
end

app/models/organization.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Organization < ApplicationRecord
2+
has_many :addresses, dependent: :destroy
3+
has_many :facilitator_organizations, dependent: :restrict_with_exception
4+
has_many :facilitators, through: :facilitator_organizations
5+
6+
validates :name, presence: true
7+
validates :agency_type, presence: true
8+
validates :phone, presence: true
9+
end

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
resources :users
5252
resources :user_forms
5353
resources :facilitators
54+
resources :organizations
5455

5556
get 'reports/:id/edit_story', to: 'reports#edit_story', as: 'reports_edit_story'
5657
put 'reports/update_story/:id', to: 'reports#update_story', as: 'reports_update_story'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class CreateOrganizations < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :organizations do |t|
4+
t.string :name, null: false
5+
t.boolean :is_active, default: true
6+
t.date :start_date
7+
t.date :close_date
8+
t.string :website_url
9+
t.string :agency_type, null: false
10+
t.string :agency_type_other
11+
t.string :phone, null: false
12+
t.text :mission
13+
t.string :project_id
14+
15+
t.timestamps
16+
end
17+
end
18+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class CreateAddresses < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :addresses do |t|
4+
t.references :organization, null: false, foreign_key: true
5+
t.string :street, null: false
6+
t.string :city, null: false
7+
t.string :state, null: false
8+
t.string :zip, null: false
9+
t.string :country
10+
t.string :locality
11+
t.string :county
12+
t.integer :la_city_council_district
13+
t.integer :la_supervisorial_district
14+
t.integer :la_service_planning_area
15+
16+
t.timestamps
17+
end
18+
end
19+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class CreateFacilitatorOrganizations < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :facilitator_organizations do |t|
4+
t.references :facilitator, null: false, foreign_key: true
5+
t.references :organization, null: false, foreign_key: true
6+
7+
t.timestamps
8+
end
9+
10+
add_index :facilitator_organizations, [:facilitator_id, :organization_id],
11+
unique: true, name: 'index_facilitator_organizations_on_ids'
12+
end
13+
end

0 commit comments

Comments
 (0)