Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cs_comments_service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
cs_comments_service
Commits
18327d93
Commit
18327d93
authored
Jul 15, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initialize feed & use to_hash everywhere
parent
6bdeede0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
3 deletions
+13
-3
app.rb
+2
-1
models/commentable.rb
+2
-2
models/feed.rb
+4
-0
models/user.rb
+4
-0
spec/app_spec.rb
+1
-0
No files found.
app.rb
View file @
18327d93
...
@@ -194,7 +194,7 @@ end
...
@@ -194,7 +194,7 @@ end
get
'/api/v1/users/:user_id/feeds'
do
|
user_id
|
get
'/api/v1/users/:user_id/feeds'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
.
feeds
.
to_json
user
.
feeds
.
map
(
&
:to_hash
).
to_json
end
end
# POST /api/v1/users/:user_id/follow
# POST /api/v1/users/:user_id/follow
...
@@ -265,6 +265,7 @@ if env.to_s == "development"
...
@@ -265,6 +265,7 @@ if env.to_s == "development"
CommentThread
.
delete_all
CommentThread
.
delete_all
Commentable
.
delete_all
Commentable
.
delete_all
User
.
delete_all
User
.
delete_all
Feed
.
delete_all
{}.
to_json
{}.
to_json
end
end
end
end
models/commentable.rb
View file @
18327d93
...
@@ -15,8 +15,8 @@ class Commentable
...
@@ -15,8 +15,8 @@ class Commentable
index
[[
:commentable_type
,
Mongo
::
ASCENDING
],
[
:commentable_id
,
Mongo
::
ASCENDING
]]
index
[[
:commentable_type
,
Mongo
::
ASCENDING
],
[
:commentable_id
,
Mongo
::
ASCENDING
]]
def
to_hash
def
to_hash
(
params
=
{})
as_document
as_document
.
slice
(
*
%w[_id commentable_type commentable_id]
)
end
end
end
end
models/feed.rb
View file @
18327d93
...
@@ -15,4 +15,8 @@ class Feed
...
@@ -15,4 +15,8 @@ class Feed
validates_presence_of
:target
validates_presence_of
:target
has_and_belongs_to_many
:subscribers
,
class_name:
"User"
,
inverse_of: :subscribed_feeds
has_and_belongs_to_many
:subscribers
,
class_name:
"User"
,
inverse_of: :subscribed_feeds
def
to_hash
(
params
=
{})
as_document
.
slice
(
*
%w[_id feed_type info actor target]
)
end
end
end
models/user.rb
View file @
18327d93
...
@@ -18,6 +18,10 @@ class User
...
@@ -18,6 +18,10 @@ class User
index
:external_id
,
unique:
true
index
:external_id
,
unique:
true
def
to_hash
(
params
=
{})
as_document
.
slice
(
*
%w[_id external_id]
)
end
def
follow
(
user
)
def
follow
(
user
)
if
id
!=
user
.
id
and
not
following
.
include?
user
if
id
!=
user
.
id
and
not
following
.
include?
user
following
<<
user
following
<<
user
...
...
spec/app_spec.rb
View file @
18327d93
...
@@ -7,6 +7,7 @@ describe "app" do
...
@@ -7,6 +7,7 @@ describe "app" do
CommentThread
.
delete_all
CommentThread
.
delete_all
Commentable
.
delete_all
Commentable
.
delete_all
User
.
delete_all
User
.
delete_all
Feed
.
delete_all
commentable
=
Commentable
.
create!
(
commentable_type:
"questions"
,
commentable_id:
"1"
)
commentable
=
Commentable
.
create!
(
commentable_type:
"questions"
,
commentable_id:
"1"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment