From a06819588af840f53037a5ae9835fae111066a8f Mon Sep 17 00:00:00 2001 From: Garrett Bowman Date: Mon, 16 Sep 2024 14:45:40 -0500 Subject: [PATCH 1/3] added to seeds --- db/seeds.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/seeds.rb b/db/seeds.rb index f45a716..6594749 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,7 +7,12 @@ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| # MovieGenre.find_or_create_by!(name: genre_name) # end +Event.destroy_all +Attendee.destroy_all +UserArtist.destroy_all User.destroy_all +Artist.destroy_all + User.create!(name: 'peterkim_pk1', email: 'peterkim.pk1@gmail.com') From e22c56c57662fa4af4582b96e3b5e887e3fbd1e2 Mon Sep 17 00:00:00 2001 From: Garrett Bowman <74687494+GBowman1@users.noreply.github.com> Date: Mon, 16 Sep 2024 14:46:43 -0500 Subject: [PATCH 2/3] Update seeds.rb --- db/seeds.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/db/seeds.rb b/db/seeds.rb index f45a716..8c0e648 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,7 +7,11 @@ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| # MovieGenre.find_or_create_by!(name: genre_name) # end +Event.destroy_all +Attendee.destroy_all +UserArtist.destroy_all User.destroy_all +Artist.destroy_all User.create!(name: 'peterkim_pk1', email: 'peterkim.pk1@gmail.com') From e1e5ed007c31ea5a539f49ae2e7437c7627b221b Mon Sep 17 00:00:00 2001 From: Garrett Bowman Date: Tue, 17 Sep 2024 08:55:22 -0500 Subject: [PATCH 3/3] Added index for users --- app/controllers/api/v1/users_controller.rb | 6 ++++++ config/routes.rb | 2 +- spec/requests/api/v1/user_request_spec.rb | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index c6e08b2..08641a9 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -1,4 +1,10 @@ class Api::V1::UsersController < ApplicationController + + def index + users = User.all + render json: UserSerializer.new(users) + end + def show user = User.find(params[:id]) render json: UserSerializer.new(user) diff --git a/config/routes.rb b/config/routes.rb index 67c07ed..9bfdc06 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ namespace :api do namespace :v1 do resources :events, only: [:show, :index] # this will be all events in db no matter the user - resources :users, only: [:show, :create, :update, :destroy] do + resources :users, only: [:show, :create, :update, :destroy, :index] do resources :user_events, only: [:create, :show, :index, :destroy] #user_events controller to pull events for a user (and create and delete) end resources :artists, only: [:index, :create, :destroy] diff --git a/spec/requests/api/v1/user_request_spec.rb b/spec/requests/api/v1/user_request_spec.rb index 2a56ad1..b6406dd 100644 --- a/spec/requests/api/v1/user_request_spec.rb +++ b/spec/requests/api/v1/user_request_spec.rb @@ -72,4 +72,24 @@ expect(User.find_by(id: user_id)).to be_nil end + + it "sends all users" do + get "/api/v1/users" + + users = JSON.parse(response.body, symbolize_names: true) + + expect(response).to be_successful + expect(response.status).to eq(200) + + expect(users).to be_a(Hash) + expect(users).to have_key(:data) + + expect(users[:data].count).to eq(2) + + expect(users[:data].first[:attributes][:name]).to eq(@user1.name) + expect(users[:data].first[:attributes][:email]).to eq(@user1.email) + + expect(users[:data].last[:attributes][:name]).to eq(@user2.name) + expect(users[:data].last[:attributes][:email]).to eq(@user2.email) + end end