-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from xlpero/managing_group
Add migration, model and controller för managing groups
- Loading branch information
Showing
11 changed files
with
148 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class ManagingGroupsController < ApplicationController | ||
before_filter :validate_token | ||
# Find all managing_group and show them. | ||
def index | ||
objs = ManagingGroup.all.order(:name) | ||
if objs | ||
render json: {managing_groups: objs}, status: 200 | ||
else | ||
render json: {}, status: 500 | ||
end | ||
rescue => error | ||
render json: {}, status: 500 | ||
end | ||
|
||
# Find one managing_group using id and show it. | ||
def show | ||
objid = params[:id] | ||
obj = ManagingGroup.find_by_id(objid) | ||
if obj | ||
render json: {managing_group: obj}, status: 200 | ||
else | ||
render json: {}, status: 404 | ||
end | ||
rescue => error | ||
render json: {}, status: 500 | ||
end | ||
|
||
# Find one managing_group using label and show it. | ||
def show_by_label | ||
objid = params[:label] | ||
obj = ManagingGroup.find_by_label(objid) | ||
if obj | ||
render json: {managing_group: obj}, status: 200 | ||
else | ||
render json: {}, status: 404 | ||
end | ||
rescue => error | ||
render json: {}, status: 500 | ||
end | ||
|
||
|
||
def create | ||
render json: {}, status: 501 | ||
end | ||
|
||
def update | ||
render json: {}, status: 501 | ||
end | ||
|
||
def delete | ||
render json: {}, status: 501 | ||
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
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,11 @@ | ||
class ManagingGroup < ActiveRecord::Base | ||
has_many :orders | ||
has_many :users | ||
|
||
validates_presence_of :label | ||
validates_uniqueness_of :label | ||
|
||
def as_json(options = {}) | ||
super(:except => [:created_at, :updated_at]) | ||
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
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
5 changes: 5 additions & 0 deletions
5
db/migrate/20190301132818_add_column_is_active_to_pickup_locations.rb
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,5 @@ | ||
class AddColumnIsActiveToPickupLocations < ActiveRecord::Migration | ||
def change | ||
add_column :pickup_locations, :is_active, :boolean | ||
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,13 @@ | ||
class AddTableManagingGroups < ActiveRecord::Migration | ||
def change | ||
create_table :managing_groups do |t| | ||
t.string :label | ||
t.string :name | ||
t.string :email | ||
t.string :sublocation | ||
t.boolean :is_active | ||
|
||
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,6 @@ | ||
class AddColumnsManagingGroupId < ActiveRecord::Migration | ||
def change | ||
add_column :orders, :managing_group_id, :integer | ||
add_column :users, :managing_group_id, :integer | ||
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