From 987f5cb190a5fc075740184b2a2ad652c9713db3 Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Fri, 3 Jan 2025 22:21:00 +1100 Subject: [PATCH] Add Endpoint for creators --- app/controllers/api/v1/profiles_controller.rb | 7 +++++++ app/views/api/v1/profiles/home_profiles.json.jbuilder | 8 ++++++++ config/routes.rb | 3 +++ 3 files changed, 18 insertions(+) create mode 100644 app/controllers/api/v1/profiles_controller.rb create mode 100644 app/views/api/v1/profiles/home_profiles.json.jbuilder diff --git a/app/controllers/api/v1/profiles_controller.rb b/app/controllers/api/v1/profiles_controller.rb new file mode 100644 index 00000000..8b791742 --- /dev/null +++ b/app/controllers/api/v1/profiles_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Api::V1::ProfilesController < ApplicationController + def home_profiles + @creator_profiles = CreatorProfile.order("RANDOM()").take(12) + end +end diff --git a/app/views/api/v1/profiles/home_profiles.json.jbuilder b/app/views/api/v1/profiles/home_profiles.json.jbuilder new file mode 100644 index 00000000..b60a709c --- /dev/null +++ b/app/views/api/v1/profiles/home_profiles.json.jbuilder @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +json.array! @creator_profiles do |creator_profile| + json.name creator_profile.name + json.slug creator_profile.slug + json.skills creator_profile.skills + json.avatar url_for(creator_profile.avatar) if creator_profile.avatar.present? +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f3886cf6..4b33615e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,6 +55,9 @@ resources :posts do get "latest", to: "posts#latest", on: :collection end + resources :profiles do + get "home_profiles", to: "profiles#home_profiles", on: :collection + end end end