-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Continent
, Country
, Region
and City
by association to `Co…
…mpany` resource
- Loading branch information
1 parent
996e0f1
commit 4ed3df4
Showing
30 changed files
with
358 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface GeoFragment { | ||
id: number; | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class City < ApplicationRecord | ||
belongs_to :region | ||
has_one :country, through: :region | ||
has_one :continent, through: :country | ||
has_many :companies | ||
|
||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class Continent < ApplicationRecord | ||
has_many :cities, through: :regions | ||
has_many :regions, through: :countries | ||
has_many :countries | ||
has_many :companies, through: :cities | ||
|
||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class Country < ApplicationRecord | ||
belongs_to :continent | ||
has_many :regions | ||
has_many :cities, through: :regions | ||
has_many :companies, through: :cities | ||
|
||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class Region < ApplicationRecord | ||
has_many :cities | ||
belongs_to :country | ||
has_one :continent, through: :country | ||
has_many :companies, through: :cities | ||
|
||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
class CompanySerializer < ApplicationSerializer | ||
attributes :id, | ||
attributes( | ||
:id, | ||
:name, | ||
:website, | ||
:careers_page, | ||
:description | ||
:description, | ||
) | ||
|
||
attribute :short_location do | ||
[company.city&.name, company.country&.name].compact.join(", ") | ||
end | ||
|
||
attribute :medium_location do | ||
[company.city&.name, company.region&.name, company.country&.name].compact.join(", ") | ||
end | ||
|
||
attribute :full_location do | ||
[company.city&.name, company.region&.name, company.country&.name, company.continent&.name].compact.join(", ") | ||
end | ||
|
||
has_many :technologies, serializer: TechnologySerializer | ||
has_one :continent, serializer: GeoFragmentSerializer | ||
has_one :country, serializer: GeoFragmentSerializer | ||
has_one :region, serializer: GeoFragmentSerializer | ||
has_one :city, serializer: GeoFragmentSerializer | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class GeoFragmentSerializer < ApplicationSerializer | ||
attributes( | ||
:id, | ||
:name, | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class PaginationSerializer < ApplicationSerializer | ||
hash_attributes :scaffold_url, | ||
hash_attributes( | ||
:scaffold_url, | ||
:page, | ||
:pages, | ||
:prev, | ||
:next | ||
:next, | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class TechnologySerializer < ApplicationSerializer | ||
attributes :id, | ||
attributes( | ||
:id, | ||
:name, | ||
:background_color, | ||
:text_color | ||
:text_color, | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateContinents < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table(:continents) do |t| | ||
t.string(:name, null: false) | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateCountries < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table(:countries) do |t| | ||
t.string(:name, null: false) | ||
t.references(:continent, null: false, foreign_key: true) | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateRegions < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table(:regions) do |t| | ||
t.string(:name, null: false) | ||
t.references(:country, null: false, foreign_key: true) | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateCities < ActiveRecord::Migration[7.2] | ||
def change | ||
create_table(:cities) do |t| | ||
t.string(:name, null: false) | ||
t.references(:region, null: false, foreign_key: true) | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddCityToCompanies < ActiveRecord::Migration[7.2] | ||
def change | ||
add_reference(:companies, :city, null: false, foreign_key: true) | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.