Skip to content

Commit

Permalink
Add homepage posts endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhbhatia committed Dec 15, 2024
1 parent 2f8cb38 commit 16c92d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/api/v1/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class Api::V1::PostsController < ApplicationController
def latest
@posts = Post.published.last(3)
end
end
9 changes: 9 additions & 0 deletions app/views/api/v1/posts/latest.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

json.array! @posts do |post|
json.title post.title
json.article_type post.article_type
json.summary post.summary
json.slug post.slug
json.created_at post.created_at
end
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
resources :stores do
get "random", to: "stores#random", on: :collection
end
resources :posts do
get "latest", to: "posts#latest", on: :collection
end
end
end

Expand Down

0 comments on commit 16c92d4

Please sign in to comment.