diff --git a/app/assets/javascripts/api/v1/timeline.coffee b/app/assets/javascripts/api/v1/timeline.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/api/v1/timeline.coffee @@ -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/ diff --git a/app/assets/stylesheets/api/v1/timeline.scss b/app/assets/stylesheets/api/v1/timeline.scss new file mode 100644 index 0000000..98272de --- /dev/null +++ b/app/assets/stylesheets/api/v1/timeline.scss @@ -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/ diff --git a/app/controllers/api/v1/timeline_controller.rb b/app/controllers/api/v1/timeline_controller.rb new file mode 100644 index 0000000..cc94185 --- /dev/null +++ b/app/controllers/api/v1/timeline_controller.rb @@ -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 diff --git a/app/helpers/api/v1/timeline_helper.rb b/app/helpers/api/v1/timeline_helper.rb new file mode 100644 index 0000000..ec2db99 --- /dev/null +++ b/app/helpers/api/v1/timeline_helper.rb @@ -0,0 +1,2 @@ +module Api::V1::TimelineHelper +end diff --git a/config/routes.rb b/config/routes.rb index c3d1e65..3afe352 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/controllers/api/v1/timeline_controller_spec.rb b/spec/controllers/api/v1/timeline_controller_spec.rb new file mode 100644 index 0000000..a582f7a --- /dev/null +++ b/spec/controllers/api/v1/timeline_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::V1::TimelineController, type: :controller do + +end diff --git a/spec/helpers/api/v1/timeline_helper_spec.rb b/spec/helpers/api/v1/timeline_helper_spec.rb new file mode 100644 index 0000000..658f4ac --- /dev/null +++ b/spec/helpers/api/v1/timeline_helper_spec.rb @@ -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