diff --git a/app/controllers/api/v1/parties_controller.rb b/app/controllers/api/v1/parties_controller.rb deleted file mode 100644 index 8760678..0000000 --- a/app/controllers/api/v1/parties_controller.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/app/controllers/api/v1/party_controller.rb b/app/controllers/api/v1/party_controller.rb new file mode 100644 index 0000000..c1d90ab --- /dev/null +++ b/app/controllers/api/v1/party_controller.rb @@ -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 \ No newline at end of file