Add PartiesController

This commit is contained in:
Justin Edmund 2020-09-16 03:42:12 -07:00
parent 703bcbdf9d
commit aa7820dd22
2 changed files with 35 additions and 17 deletions

View file

@ -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

View 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