mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-09 05:15:53 +10:00
#11 Add latest timeline and hottest timelines
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the api/v1/timeline controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@@ -0,0 +1,13 @@
|
||||
class Api::V1::TimelineController < Api::V1::ApplicationController
|
||||
|
||||
skip_before_action :authenticate_user_from_token
|
||||
|
||||
def latest
|
||||
render json: Post.order(created_at: :desc).page(params[:page]), each_serializer: PostSerializer
|
||||
end
|
||||
|
||||
def hottest
|
||||
render json: Post.order(viewed_times: :desc).page(params[:page]), each_serializer: PostSerializer
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,2 @@
|
||||
module Api::V1::TimelineHelper
|
||||
end
|
||||
@@ -101,6 +101,9 @@ Rails.application.routes.draw do
|
||||
|
||||
get '/explore', to: 'explore#index'
|
||||
|
||||
get '/timeline/latest', to: 'timeline#latest'
|
||||
get '/timeline/hottest', to: 'timeline#hottest'
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::TimelineController, type: :controller do
|
||||
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the Api::V1::TimelineHelper. For example:
|
||||
#
|
||||
# describe Api::V1::TimelineHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
RSpec.describe Api::V1::TimelineHelper, type: :helper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Reference in New Issue
Block a user