-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf03c58
commit db0da1e
Showing
19 changed files
with
208 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Mutations::Post::LockPost < Mutations::Base | ||
argument :input, | ||
Types::Input::Post::Lock, | ||
required: true, | ||
description: 'Lock a Post.', | ||
as: :post | ||
|
||
field :post, Types::Post, null: true | ||
|
||
def load_post(value) | ||
post = ::Post.find(value.id) | ||
post.assign_attributes(value.to_model) | ||
post | ||
end | ||
|
||
def authorized?(post:) | ||
super(post, :lock?) | ||
end | ||
|
||
def resolve(post:) | ||
post.save | ||
|
||
if post.errors.any? | ||
Errors::RailsModel.graphql_error(post) | ||
else | ||
{ | ||
post: post | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Mutations::Post::UnlockPost < Mutations::Base | ||
argument :input, | ||
Types::Input::Post::Unlock, | ||
required: true, | ||
description: 'Unlock a Post.', | ||
as: :post | ||
|
||
field :post, Types::Post, null: true | ||
|
||
def load_post(value) | ||
post = ::Post.find(value.id) | ||
post.assign_attributes(value.to_model) | ||
post | ||
end | ||
|
||
def authorized?(post:) | ||
super(post, :unlock?) | ||
end | ||
|
||
def resolve(post:) | ||
post.save | ||
|
||
if post.errors.any? | ||
Errors::RailsModel.graphql_error(post) | ||
else | ||
{ | ||
post: post | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Types::Enum::LockedReason < Types::Enum::Base | ||
value 'SPAM', value: 'spam' | ||
value 'TOO_HEATED', value: 'too_heated' | ||
value 'CLOSED', value: 'closed' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,8 @@ def self.default_graphql_name | |
def to_model | ||
to_h | ||
end | ||
|
||
def current_user | ||
User.current | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Types::Input::Post::Lock < Types::Input::Base | ||
argument :id, ID, required: true | ||
argument :locked_reason, Types::Enum::LockedReason, required: true | ||
|
||
def to_model | ||
to_h.merge(locked_at: DateTime.current, locked_by: current_user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Types::Input::Post::Unlock < Types::Input::Base | ||
argument :id, ID, required: true | ||
|
||
def to_model | ||
to_h.merge(locked_at: nil, locked_by: nil, locked_reason: nil) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Types::Mutations::PostMutation < Types::BaseObject | ||
field :lock, | ||
mutation: ::Mutations::Post::LockPost, | ||
description: 'Lock a Post.' | ||
|
||
field :unlock, | ||
mutation: ::Mutations::Post::UnlockPost, | ||
description: 'Unlock a Post.' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class AddLockUnlockToPost < ActiveRecord::Migration[5.1] | ||
def change | ||
add_column :posts, :locked_by_id, :integer | ||
add_column :posts, :locked_at, :datetime | ||
add_column :posts, :locked_reason, :integer | ||
add_index :posts, :locked_by_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters