Skip to content

Commit

Permalink
Merge pull request #27 from andela-iamadi/fix-to-ask-question_route
Browse files Browse the repository at this point in the history
General update to serializers
  • Loading branch information
0sc committed Feb 12, 2016
2 parents 1a6777e + 04bbb75 commit 5348c83
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
5 changes: 3 additions & 2 deletions app/serializers/answer_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
class AnswerSerializer < ActiveModel::Serializer
attributes :id, :user, :content, :votes_count, :created_at, :updated_at, :comments_count


def user
{
id: object.user.id,
name: object.user.name,
image: object.user.social_providers.first.try(:profile_picture)
email: object.user.points,
image: object.user.social_providers.first.try(:profile_picture),
points: object.user.points
}
end
end
9 changes: 1 addition & 8 deletions app/serializers/comment_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
class CommentSerializer < ActiveModel::Serializer
attributes :id, :user, :content, :votes_count, :created_at, :updated_at


def user
{
id: object.user.id,
name: object.user.name,
image: object.user.social_providers.first.try(:profile_picture)
}
end
belongs_to :user
end
16 changes: 4 additions & 12 deletions app/serializers/question_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
class QuestionSerializer < ActiveModel::Serializer
attributes :id, :title,:content, :user, :votes_count, :tags, :created_at, :updated_at, :answers_count, :comments_count, :views

def user
{
id: object.user.id,
name: object.user.name,
image: object.user.social_providers.first.try(:profile_picture)
}
end
attributes :id, :title,:content, :votes_count, :tags, :created_at, :updated_at, :answers_count, :comments_count, :views
belongs_to :user

def attributes(*args)
data = super
data['answers'] = answers if instance_options[:include_answers]
data
class_eval { has_many :answers } if instance_options[:include_answers]
super
end

def answers
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class UserSerializer < ActiveModel::Serializer
attributes :id, :name, :email, :image
attributes :id, :name, :email, :image, :points

def attributes(*args)
data = super
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeColumnPointsInUsersAddDefault < ActiveRecord::Migration
def change
change_column :users, :points, :integer, default: 0
end
end
8 changes: 4 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160206104129) do
ActiveRecord::Schema.define(version: 20160212200122) do

create_table "answers", force: :cascade do |t|
t.integer "user_id"
Expand Down Expand Up @@ -86,9 +86,9 @@
t.string "email"
t.string "uuid"
t.string "provider"
t.integer "points"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "points", default: 0
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "active"
end

Expand Down

0 comments on commit 5348c83

Please sign in to comment.