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
bc407596
Commit
bc407596
authored
Jul 16, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed comment_thread to thread & removed commentable in url
parent
83989fc2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
50 deletions
+49
-50
app.rb
+45
-46
models/comment.rb
+2
-2
models/comment_thread.rb
+2
-2
spec/app_spec.rb
+0
-0
No files found.
app.rb
View file @
bc407596
...
...
@@ -21,68 +21,67 @@ Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file}
# DELETE /api/v1/commentables/:commentable_type/:commentable_id
# delete the commentable object and all of its associated comment threads and comments
delete
'/api/v1/commentables/:commentable_type/:commentable_id'
do
|
commentable_type
,
commentable_id
|
delete
'/api/v1/:commentable_type/:commentable_id/comments'
do
|
commentable_type
,
commentable_id
|
commentable
=
Commentable
.
find_or_initialize_by
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
)
commentable
.
destroy
commentable
.
to_hash
.
to_json
end
# GET /api/v1/commentables/:commentable_type/:commentable_id/
comment_
threads
# GET /api/v1/commentables/:commentable_type/:commentable_id/threads
# get all comment threads associated with a commentable object
# additional parameters accepted: recursive
get
'/api/v1/
commentables/:commentable_type/:commentable_id/comment_
threads'
do
|
commentable_type
,
commentable_id
|
get
'/api/v1/
:commentable_type/:commentable_id/
threads'
do
|
commentable_type
,
commentable_id
|
commentable
=
Commentable
.
find_or_create_by
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
)
commentable
.
comment_threads
.
map
{
|
t
|
t
.
to_hash
(
recursive:
params
[
"recursive"
])}.
to_json
end
# POST /api/v1/commentables/:commentable_type/:commentable_id/
comment_
threads
# POST /api/v1/commentables/:commentable_type/:commentable_id/threads
# create a new comment thread for the commentable object
post
'/api/v1/
commentables/:commentable_type/:commentable_id/comment_
threads'
do
|
commentable_type
,
commentable_id
|
post
'/api/v1/
:commentable_type/:commentable_id/
threads'
do
|
commentable_type
,
commentable_id
|
commentable
=
Commentable
.
find_or_create_by
(
commentable_type:
commentable_type
,
commentable_id:
commentable_id
)
comment_
thread
=
commentable
.
comment_threads
.
new
(
params
.
slice
(
*
%w[title body course_id]
))
comment_
thread
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
comment_
thread
.
save!
comment_
thread
.
to_hash
.
to_json
thread
=
commentable
.
comment_threads
.
new
(
params
.
slice
(
*
%w[title body course_id]
))
thread
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
thread
.
save!
thread
.
to_hash
.
to_json
end
# GET /api/v1/
comment_threads/:comment_
thread_id
# GET /api/v1/
threads/:
thread_id
# get information of a single comment thread
# additional parameters accepted: recursive
get
'/api/v1/
comment_threads/:comment_thread_id'
do
|
comment_
thread_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
comment_
thread
.
to_hash
(
recursive:
params
[
"recursive"
]).
to_json
get
'/api/v1/
threads/:thread_id'
do
|
thread_id
|
thread
=
CommentThread
.
find
(
thread_id
)
thread
.
to_hash
(
recursive:
params
[
"recursive"
]).
to_json
end
# PUT /api/v1/
comment_threads/:comment_
thread_id
# PUT /api/v1/
threads/:
thread_id
# update information of comment thread
put
'/api/v1/
comment_threads/:comment_thread_id'
do
|
comment_
thread_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
comment_
thread
.
update_attributes!
(
params
.
slice
(
*
%w[title body]
))
comment_
thread
.
to_hash
.
to_json
put
'/api/v1/
threads/:thread_id'
do
|
thread_id
|
thread
=
CommentThread
.
find
(
thread_id
)
thread
.
update_attributes!
(
params
.
slice
(
*
%w[title body]
))
thread
.
to_hash
.
to_json
end
# POST /api/v1/
comment_threads/:comment_
thread_id/comments
# POST /api/v1/
threads/:
thread_id/comments
# create a comment to the comment thread
post
'/api/v1/
comment_threads/:comment_thread_id/comments'
do
|
comment_
thread_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
comment
=
comment_
thread
.
comments
.
new
(
params
.
slice
(
*
%w[body course_id]
))
post
'/api/v1/
threads/:thread_id/comments'
do
|
thread_id
|
thread
=
CommentThread
.
find
(
thread_id
)
comment
=
thread
.
comments
.
new
(
params
.
slice
(
*
%w[body course_id]
))
comment
.
author
=
User
.
find_or_create_by
(
external_id:
params
[
"user_id"
])
if
params
[
"user_id"
]
comment
.
save!
comment
.
to_hash
.
to_json
end
# DELETE /api/v1/
comment_threads/:comment_
thread_id
# DELETE /api/v1/
threads/:
thread_id
# delete the comment thread and its comments
delete
'/api/v1/
comment_threads/:comment_thread_id'
do
|
comment_
thread_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
comment_
thread
.
destroy
comment_
thread
.
to_hash
.
to_json
delete
'/api/v1/
threads/:thread_id'
do
|
thread_id
|
thread
=
CommentThread
.
find
(
thread_id
)
thread
.
destroy
thread
.
to_hash
.
to_json
end
# GET /api/v1/comments/:comment_id
...
...
@@ -143,24 +142,24 @@ delete '/api/v1/votes/comments/:comment_id/users/:user_id' do |comment_id, user_
Comment
.
find
(
comment_id
).
to_hash
.
to_json
end
# PUT /api/v1/votes/
comment_threads/:comment_
thread_id/users/:user_id
# PUT /api/v1/votes/
threads/:
thread_id/users/:user_id
# create or update the vote on the comment thread
put
'/api/v1/votes/
comment_threads/:comment_thread_id/users/:user_id'
do
|
comment_
thread_id
,
user_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
put
'/api/v1/votes/
threads/:thread_id/users/:user_id'
do
|
thread_id
,
user_id
|
thread
=
CommentThread
.
find
(
thread_id
)
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
.
vote
(
comment_
thread
,
params
[
"value"
].
intern
)
CommentThread
.
find
(
comment_
thread_id
).
to_hash
.
to_json
user
.
vote
(
thread
,
params
[
"value"
].
intern
)
CommentThread
.
find
(
thread_id
).
to_hash
.
to_json
end
# DELETE /api/v1/votes/
comment_threads/:comment_
thread_id/users/:user_id
# DELETE /api/v1/votes/
threads/:
thread_id/users/:user_id
# unvote on the comment thread
delete
'/api/v1/votes/
comment_threads/:comment_thread_id/users/:user_id'
do
|
comment_
thread_id
,
user_id
|
comment_thread
=
CommentThread
.
find
(
comment_
thread_id
)
delete
'/api/v1/votes/
threads/:thread_id/users/:user_id'
do
|
thread_id
,
user_id
|
thread
=
CommentThread
.
find
(
thread_id
)
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
.
unvote
(
comment_
thread
)
CommentThread
.
find
(
comment_
thread_id
).
to_hash
.
to_json
user
.
unvote
(
thread
)
CommentThread
.
find
(
thread_id
).
to_hash
.
to_json
end
# GET /api/v1/users/:user_id/feeds
...
...
@@ -213,23 +212,23 @@ post '/api/v1/users/:user_id/unwatch/commentable' do |user_id|
user
.
to_hash
.
to_json
end
# POST /api/v1/users/:user_id/watch/
comment_
thread
# POST /api/v1/users/:user_id/watch/thread
# watch a comment thread
post
'/api/v1/users/:user_id/watch/
comment_
thread'
do
|
user_id
|
post
'/api/v1/users/:user_id/watch/thread'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
comment_thread
=
CommentThread
.
find
(
params
[
"comment_
thread_id"
])
user
.
watch_comment_thread
(
comment_
thread
)
thread
=
CommentThread
.
find
(
params
[
"
thread_id"
])
user
.
watch_comment_thread
(
thread
)
user
.
to_hash
.
to_json
end
# POST /api/v1/users/:user_id/unwatch/
comment_
thread
# POST /api/v1/users/:user_id/unwatch/thread
# unwatch a comment thread
post
'/api/v1/users/:user_id/unwatch/
comment_
thread'
do
|
user_id
|
post
'/api/v1/users/:user_id/unwatch/thread'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
comment_thread
=
CommentThread
.
find
(
params
[
"comment_
thread_id"
])
user
.
unwatch_comment_thread
(
comment_
thread
)
thread
=
CommentThread
.
find
(
params
[
"
thread_id"
])
user
.
unwatch_comment_thread
(
thread
)
user
.
to_hash
.
to_json
end
...
...
models/comment.rb
View file @
bc407596
...
...
@@ -58,8 +58,8 @@ private
feed
=
Feed
.
new
(
feed_type:
"post_reply"
,
info:
{
comment_
thread_id:
get_comment_thread
.
id
,
comment_
thread_title:
get_comment_thread
.
title
,
thread_id:
get_comment_thread
.
id
,
thread_title:
get_comment_thread
.
title
,
comment_id:
id
,
},
)
...
...
models/comment_thread.rb
View file @
bc407596
...
...
@@ -41,8 +41,8 @@ private
info:
{
commentable_id:
commentable
.
commentable_id
,
commentable_type:
commentable
.
commentable_type
,
comment_
thread_id:
id
,
comment_
thread_title:
title
,
thread_id:
id
,
thread_title:
title
,
},
)
feed
.
actor
=
author
...
...
spec/app_spec.rb
View file @
bc407596
This diff is collapsed.
Click to expand it.
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