Skip to content
Snippets Groups Projects
Commit a1d36ebc authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

add counters to user auth sign in object

parent 2fb0ab22
No related branches found
No related tags found
No related merge requests found
class V1::SessionsController < DeviseTokenAuth::SessionsController
def create
super do |resource|
return render json: resource
end
end
end
...@@ -40,7 +40,7 @@ class Collection < ApplicationRecord ...@@ -40,7 +40,7 @@ class Collection < ApplicationRecord
has_many :learning_objects, through: :collection_items, source: :collectionable, source_type: 'LearningObject' has_many :learning_objects, through: :collection_items, source: :collectionable, source_type: 'LearningObject'
has_many :collection_items has_many :collection_items
belongs_to :owner, polymorphic: true belongs_to :owner, polymorphic: true, counter_cache: true
validates :name, :owner, presence: true validates :name, :owner, presence: true
validates_inclusion_of :privacy, in: %w(public private), message: 'Privacy must be public or private' validates_inclusion_of :privacy, in: %w(public private), message: 'Privacy must be public or private'
......
...@@ -52,7 +52,7 @@ class LearningObject < ApplicationRecord ...@@ -52,7 +52,7 @@ class LearningObject < ApplicationRecord
has_many :collections, through: :collection_items has_many :collections, through: :collection_items
has_many :attachments, class_name: 'LearningObject::Attachment', autosave: true # autosave to allow import has_many :attachments, class_name: 'LearningObject::Attachment', autosave: true # autosave to allow import
belongs_to :publisher, polymorphic: true belongs_to :publisher, polymorphic: true, counter_cache: true
belongs_to :language belongs_to :language
belongs_to :license belongs_to :license
belongs_to :object_type belongs_to :object_type
......
...@@ -16,7 +16,7 @@ class Like < ApplicationRecord ...@@ -16,7 +16,7 @@ class Like < ApplicationRecord
include Trackable include Trackable
belongs_to :likeable, polymorphic: true, counter_cache: true belongs_to :likeable, polymorphic: true, counter_cache: true
belongs_to :user belongs_to :user, counter_cache: true
validates_presence_of :user, :likeable validates_presence_of :user, :likeable
validates :user_id, uniqueness: { scope: [:likeable_id, :likeable_type] } validates :user_id, uniqueness: { scope: [:likeable_id, :likeable_type] }
......
class UserSerializer < ActiveModel::Serializer class UserSerializer < ActiveModel::Serializer
cache key: 'user', expires_in: 4.hours cache key: 'user', expires_in: 4.hours
attributes :id, :email, :name, :description, :created_at, :updated_at, :role_ids, :institution_ids, :avatar attributes :id, :email, :name, :description, :role_ids, :institution_ids, :avatar, :likes_count, :learning_objects_count, :collections_count, :created_at, :updated_at
# has_many :roles
# has_many :institutions
end end
...@@ -67,7 +67,9 @@ Rails.application.routes.draw do ...@@ -67,7 +67,9 @@ Rails.application.routes.draw do
end end
scope :v1 do scope :v1 do
mount_devise_token_auth_for 'User', at: :auth mount_devise_token_auth_for 'User', at: :auth, controllers: {
sessions: 'v1/sessions'
}
end end
namespace :v1 do namespace :v1 do
......
class AddCountsToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :likes_count, :integer, default: 0
add_column :users, :learning_objects_count, :integer, default: 0
add_column :users, :collections_count, :integer, default: 0
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment