Skip to content

Commit

Permalink
chore: Adding annotate in models, forms, serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeoleynik committed Sep 23, 2019
1 parent 870d2b6 commit d06ef59
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ group :development, :test do
end

group :development do
gem 'annotate'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ GEM
tzinfo (~> 1.1)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
annotate (2.7.5)
activerecord (>= 3.2, < 7.0)
rake (>= 10.4, < 13.0)
arel (9.0.0)
bcrypt (3.1.13)
bootsnap (1.4.5)
Expand Down Expand Up @@ -229,6 +232,7 @@ PLATFORMS
ruby

DEPENDENCIES
annotate
bootsnap (>= 1.1.0)
carrierwave (~> 2.0)
database_cleaner
Expand Down
3 changes: 3 additions & 0 deletions app/forms/create_task.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

# FormObject to create task and nested object.
# Associate tasks with users, themes, and picture.

class CreateTask
include ActiveModel::Model

Expand Down
12 changes: 12 additions & 0 deletions app/models/node.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# frozen_string_literal: true

# Join table for Theme and Task

# == Schema Information
#
# Table name: nodes
#
# id :bigint not null, primary key
# theme_id :bigint not null
# task_id :bigint not null
# access :boolean default(FALSE)
#

class Node < ApplicationRecord
belongs_to :theme
belongs_to :task
Expand Down
9 changes: 9 additions & 0 deletions app/models/picture.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: pictures
#
# id :bigint not null, primary key
# image :string not null
# task_id :integer
#

class Picture < ApplicationRecord
belongs_to :task

Expand Down
12 changes: 12 additions & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: tasks
#
# id :bigint not null, primary key
# title :string not null
# body :text not null
# difficulty :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#

class Task < ApplicationRecord
has_one :picture, dependent: :destroy
has_many :user_tasks, dependent: :destroy
Expand Down
10 changes: 10 additions & 0 deletions app/models/theme.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: themes
#
# id :bigint not null, primary key
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
#

class Theme < ApplicationRecord
has_many :nodes, dependent: :destroy
has_many :tasks, through: :nodes
Expand Down
22 changes: 22 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# fullname :string not null
# mentor :boolean default(FALSE)
# email :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# invitation_token :string
# invitation_created_at :datetime
# invitation_sent_at :datetime
# invitation_accepted_at :datetime
# invitation_limit :integer
# invited_by_type :string
# invited_by_id :bigint
# invitations_count :integer default(0)
#

class User < ApplicationRecord
devise :database_authenticatable, :invitable,
:recoverable, :rememberable, :validatable
Expand Down
11 changes: 11 additions & 0 deletions app/models/user_task.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# frozen_string_literal: true

# Join table for User and Task

# == Schema Information
#
# Table name: user_tasks
#
# id :bigint not null, primary key
# user_id :bigint not null
# task_id :bigint not null
#

class UserTask < ApplicationRecord
belongs_to :user
belongs_to :task
Expand Down
12 changes: 12 additions & 0 deletions app/serializers/task_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: tasks
#
# id :bigint not null, primary key
# title :string not null
# body :text not null
# difficulty :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#

class TaskSerializer < BaseSerializer
attributes :title, :body, :difficulty
end
10 changes: 10 additions & 0 deletions app/serializers/theme_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: themes
#
# id :bigint not null, primary key
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
#

class ThemeSerializer < BaseSerializer
attributes :title
end
22 changes: 22 additions & 0 deletions app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# fullname :string not null
# mentor :boolean default(FALSE)
# email :string default(""), not null
# encrypted_password :string default(""), not null
# reset_password_token :string
# reset_password_sent_at :datetime
# remember_created_at :datetime
# invitation_token :string
# invitation_created_at :datetime
# invitation_sent_at :datetime
# invitation_accepted_at :datetime
# invitation_limit :integer
# invited_by_type :string
# invited_by_id :bigint
# invitations_count :integer default(0)
#

class UserSerializer < BaseSerializer
attributes :email, :fullname
end
9 changes: 9 additions & 0 deletions app/serializers/user_task_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: user_tasks
#
# id :bigint not null, primary key
# user_id :bigint not null
# task_id :bigint not null
#

class UserTaskSerializer < BaseSerializer
attributes :user_id, :task_id
end

0 comments on commit d06ef59

Please sign in to comment.