Add PartiesController
This commit is contained in:
parent
703bcbdf9d
commit
aa7820dd22
2 changed files with 35 additions and 17 deletions
|
|
@ -1,17 +0,0 @@
|
||||||
class Api::V1::PartiesController < ActionController::API
|
|
||||||
def index
|
|
||||||
parties = Parties.all
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
end
|
|
||||||
|
|
||||||
def show
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
|
||||||
end
|
|
||||||
end
|
|
||||||
35
app/controllers/api/v1/party_controller.rb
Normal file
35
app/controllers/api/v1/party_controller.rb
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
class Api::V1::PartyController < ActionController::API
|
||||||
|
before_action :set, except: ['create']
|
||||||
|
|
||||||
|
def index
|
||||||
|
parties = Party.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@party = Party.new(shortcode: random_string)
|
||||||
|
render :show, status: :created if @party.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
ap @party
|
||||||
|
ap @party
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def random_string
|
||||||
|
numChars = 6
|
||||||
|
o = [('a'..'z'), ('A'..'Z'), (0..9)].map(&:to_a).flatten
|
||||||
|
return (0...numChars).map { o[rand(o.length)] }.join
|
||||||
|
end
|
||||||
|
|
||||||
|
def set
|
||||||
|
@party = Party.where(shortcode: params[:id])
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue