diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index 71ad191123e622b27556979d536a395defb84bc6..727a98d86050d8408ef7d210baf08a3d2e4fb647 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -1,6 +1,7 @@ class ChannelsController < ApplicationController def index + @channels = Channel.all.order(quantity: :desc) render json: @channels, status: 200 end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 68bf520c460bc2cd95d31d0409e97e4d1b7a7ccc..a01b30e4296ed7f95a1f15fac3d6fbe18f4a04b0 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,6 +1,7 @@ class TagsController < ApplicationController def index + @tags = Tag.all.order(quantity: :desc) render json: @tags, status: 200 end diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb index be966f0ee4eb3715be1b473676b07d9f3caa02e1..f592f42983bfa50c7af5ff4dae3d04e1ad8d2f97 100644 --- a/app/controllers/tracks_controller.rb +++ b/app/controllers/tracks_controller.rb @@ -11,9 +11,15 @@ class TracksController < ApplicationController #@tracks = Track.includes(irc_posts: [:channel, :user], tag_assignations: :tag).all #includes(irc_posts: [{ :channels, :users}]) #includes(:channels,:tags,:users) #t = Track.all.joins('inner join irc_posts i ON tracks.track_id = i.track_id inner join channels c on i.channel_id = c.channel_id inner join gnations ti on tracks.track_id = ti.track_id inner join tags ta on ta.tag_id = ti.tag_id').select('tracks.name as t_name, u.name as u_name, c.name as c_name, ta.name as t_name') #t.first.c_name - @tracks = Track.page params[:page] + @tracks = Track.includes(:tags).page params[:page] filters :tag, :channel, :user - render json: @tracks, status: 200 + render json: @tracks, + status: 200, + meta: { + current_page: @tracks.current_page, + per_page: @tracks.default_per_page, + total_pages: @tracks.num_pages + } end def show diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..475d71044347884c7fc3654950addd02518957cc --- /dev/null +++ b/app/controllers/users_controller.rb @@ -0,0 +1,8 @@ +class UsersController < ApplicationController + + def index + @users = User.all.order(quantity: :desc) + render json: @users, status: 200 + end + +end diff --git a/app/models/track.rb b/app/models/track.rb index da2a931a08415a90e4d493a73ed1c2eaf716ba55..36db29261f4609e5c7559b421b6e12703779e849 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -1,5 +1,5 @@ class Track < ActiveRecord::Base - paginates_per 50 + paginates_per 51 #default_scope includes(:channels,:users,:tags) has_many :irc_posts diff --git a/app/serializers/channel_serializer.rb b/app/serializers/channel_serializer.rb index 3eb7ae6cbe6ddfc2f8406c8f48b6386ff364d2ea..8a115a5425ca53abbc1f212f3e4c020d743e4255 100644 --- a/app/serializers/channel_serializer.rb +++ b/app/serializers/channel_serializer.rb @@ -1,5 +1,5 @@ class ChannelSerializer < ActiveModel::Serializer - attributes :id, :name + attributes :id, :name, :quantity #has_many :tracks #has_many :users diff --git a/app/serializers/tag_serializer.rb b/app/serializers/tag_serializer.rb index 7589b05fb085b23bed8f8438e160ef2be2ec7664..6dfba5aa8e28ab7dbf9fbe09748eb1edf07002d8 100644 --- a/app/serializers/tag_serializer.rb +++ b/app/serializers/tag_serializer.rb @@ -1,5 +1,5 @@ class TagSerializer < ActiveModel::Serializer - attributes :id, :name + attributes :id, :name, :quantity #belongs_to :track end diff --git a/app/serializers/track_serializer.rb b/app/serializers/track_serializer.rb index 91b9647e60338c4b5b9ae71ff7759598eb3f1877..a15b86ed7e974c403f0ace5cfd52448b7069719e 100644 --- a/app/serializers/track_serializer.rb +++ b/app/serializers/track_serializer.rb @@ -1,10 +1,10 @@ class TrackSerializer < ActiveModel::Serializer attributes :id, :name, :url, :provider, :author, :channel - embed :ids, include: true + #embed :ids, include: true - has_many :channels - has_many :tags - has_many :users + #has_many :channels + has_many :tags, embed: :ids, include: true + #has_many :users end diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 2ec17e8aab0ffa9ed677df6ff6057a8ad632fc07..0c38406f21c50a5fcd683fe8cec6e0ce2a3fc2ff 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -1,5 +1,5 @@ class UserSerializer < ActiveModel::Serializer - attributes :id, :name + attributes :id, :name, :quantity #belongs_to :track end diff --git a/config/routes.rb b/config/routes.rb index e3d8c4ade456f3fa93bd6538d6a4f117fe7ed687..0febdc20b7d76b83fc911cfba6eae6bd61d98527 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,9 +5,9 @@ Rails.application.routes.draw do concern :tracks do resources :tracks, only: [:index] end - #resources :tags, concerns: :tracks, only: [:index, :show] - #resources :channels, concerns: :tracks, only: [:index, :show] - #resources :users, concerns: :tracks, only: [:index, :show] + resources :tags, concerns: :tracks, only: [:index, :show] + resources :channels, concerns: :tracks, only: [:index, :show] + resources :users, concerns: :tracks, only: [:index, :show] resources :tracks, only: [:index, :show] root to: 'tracks#index' diff --git a/db/seeds.rb b/db/seeds.rb index 57a2555fcc20f42e7210db9c67d169c8a5129c20..4e9f9ac2571839f4e155c6931d5dec032c5a1e84 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -15,13 +15,16 @@ OldDatabase::PlaybotChan.find_each do |p_chan| end user = User.find_or_create_by(name: p_chan.sender_irc) + user.increment!(:quantity) channel = Channel.find_or_create_by(name: p_chan.chan) + channel.increment!(:quantity) IrcPost.create(track_id: track.id, channel_id: channel.id, user_id: user.id, posted_at: p_chan.date) end OldDatabase::PlaybotTag.all.each do |p_tag| tag = Tag.find_or_create_by(name: p_tag.tag) + tag.increment!(:quantity) TagAssignation.create(track_id: p_tag.id, tag_id: tag.id) end