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
6bdeede0
Commit
6bdeede0
authored
Jul 15, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
all necessary apis implemented; untested
parent
d5148ade
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
9 deletions
+90
-9
app.rb
+78
-1
models/comment.rb
+1
-1
models/comment_thread.rb
+1
-1
models/user.rb
+10
-6
No files found.
app.rb
View file @
6bdeede0
...
@@ -41,7 +41,14 @@ config = YAML.load_file("config/application.yml")
...
@@ -41,7 +41,14 @@ config = YAML.load_file("config/application.yml")
# DELETE /api/v1/votes/comment_threads/:comment_thread_id/users/:user_id
# DELETE /api/v1/votes/comment_threads/:comment_thread_id/users/:user_id
#
#
# GET /api/v1/users/:user_id/feeds
# GET /api/v1/users/:user_id/feeds
# POST /api/v1/users/:user_id/feeds/subscribe
# POST /api/v1/users/:user_id/follow
# POST /api/v1/users/:user_id/unfollow
# POST /api/v1/users/:user_id/watch/commentable
# POST /api/v1/users/:user_id/unwatch/commentable
# POST /api/v1/users/:user_id/watch/comment_thread
# POST /api/v1/users/:user_id/unwatch/comment_thread
#
#
#
#
# DELETE /api/v1/commentables/:commentable_type/:commentable_id
# DELETE /api/v1/commentables/:commentable_type/:commentable_id
...
@@ -182,6 +189,76 @@ delete '/api/v1/votes/comment_threads/:comment_thread_id/users/:user_id' do |com
...
@@ -182,6 +189,76 @@ delete '/api/v1/votes/comment_threads/:comment_thread_id/users/:user_id' do |com
user
.
unvote
(
comment_thread
)
user
.
unvote
(
comment_thread
)
end
end
# GET /api/v1/users/:user_id/feeds
# get all subscribed feeds for the user
get
'/api/v1/users/:user_id/feeds'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
user
.
feeds
.
to_json
end
# POST /api/v1/users/:user_id/follow
# follow user
post
'/api/v1/users/:user_id/follow'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
followed_user
=
User
.
find_or_create_by
(
external_id:
params
[
:user_id
])
user
.
follow
(
followed_user
)
user
.
to_hash
.
to_json
end
# POST /api/v1/users/:user_id/unfollow
# unfollow user
post
'/api/v1/users/:user_id/unfollow'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
followed_user
=
User
.
find_or_create_by
(
external_id:
params
[
:user_id
])
user
.
unfollow
(
followed_user
)
user
.
to_hash
.
to_json
end
# POST /api/v1/users/:user_id/watch/commentable
# watch a commentable
post
'/api/v1/users/:user_id/watch/commentable'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
commentable
=
Commentable
.
find_or_create_by
(
commentable_type:
params
[
:commentable_type
],
commentable_id:
parasm
[
:commentable_id
])
user
.
watch_commentable
(
commentable
)
user
.
to_hash
.
to_json
end
# POST /api/v1/users/:user_id/unwatch/commentable
# unwatch a commentable
post
'/api/v1/users/:user_id/unwatch/commentable'
do
|
user_id
|
user
=
User
.
find_or_create_by
(
external_id:
user_id
)
commentable
=
Commentable
.
find_or_create_by
(
commentable_type:
params
[
:commentable_type
],
commentable_id:
parasm
[
:commentable_id
])
user
.
unwatch_commentable
(
commentable
)
user
.
to_hash
.
to_json
end
# POST /api/v1/users/:user_id/watch/comment_thread
# watch a comment thread
post
'/api/v1/users/:user_id/watch/comment_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
)
user
.
to_hash
.
to_json
end
# POST /api/v1/users/:user_id/unwatch/comment_thread
# unwatch a comment thread
post
'/api/v1/users/:user_id/unwatch/comment_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
)
user
.
to_hash
.
to_json
end
if
env
.
to_s
==
"development"
if
env
.
to_s
==
"development"
get
'/api/v1/clean'
do
get
'/api/v1/clean'
do
Comment
.
delete_all
Comment
.
delete_all
...
...
models/comment.rb
View file @
6bdeede0
...
@@ -19,7 +19,7 @@ class Comment
...
@@ -19,7 +19,7 @@ class Comment
validates_presence_of
:course_id
# do we really need this?
validates_presence_of
:course_id
# do we really need this?
#validates_presence_of :author # allow anonymity?
#validates_presence_of :author # allow anonymity?
before_destroy
:delete_descendants
before_destroy
:delete_descendants
# TODO async
after_create
:generate_feeds
after_create
:generate_feeds
def
self
.
hash_tree
(
nodes
)
def
self
.
hash_tree
(
nodes
)
...
...
models/comment_thread.rb
View file @
6bdeede0
...
@@ -11,7 +11,7 @@ class CommentThread
...
@@ -11,7 +11,7 @@ class CommentThread
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
belongs_to
:author
,
class_name:
"User"
,
inverse_of: :comment_threads
,
index:
true
belongs_to
:commentable
,
index:
true
belongs_to
:commentable
,
index:
true
has_many
:comments
,
dependent: :destroy
# Use destroy to envoke callback on the top-level comments
has_many
:comments
,
dependent: :destroy
# Use destroy to envoke callback on the top-level comments
TODO async
has_and_belongs_to_many
:watchers
,
class_name:
"User"
,
inverse_of: :watched_comment_threads
has_and_belongs_to_many
:watchers
,
class_name:
"User"
,
inverse_of: :watched_comment_threads
attr_accessible
:title
,
:body
,
:course_id
attr_accessible
:title
,
:body
,
:course_id
...
...
models/user.rb
View file @
6bdeede0
...
@@ -19,13 +19,15 @@ class User
...
@@ -19,13 +19,15 @@ class User
index
:external_id
,
unique:
true
index
:external_id
,
unique:
true
def
follow
(
user
)
def
follow
(
user
)
if
self
.
id
!=
user
.
id
and
not
self
.
following
.
include?
user
if
id
!=
user
.
id
and
not
following
.
include?
user
self
.
following
<<
user
following
<<
user
save!
end
end
end
end
def
unfollow
(
user
)
def
unfollow
(
user
)
self
.
following
.
delete
(
user
)
following
.
delete
(
user
)
save!
end
end
def
self
.
watching
(
class_plural_sym
)
def
self
.
watching
(
class_plural_sym
)
...
@@ -38,13 +40,15 @@ class User
...
@@ -38,13 +40,15 @@ class User
self
.
class_eval
<<-
END
self
.
class_eval
<<-
END
def watch_
#{
class_single
}
(watching_object)
def watch_
#{
class_single
}
(watching_object)
if not self.watched_
#{
class_plural
}
.include? watching_object
if not watched_
#{
class_plural
}
.include? watching_object
self.watched_
#{
class_plural
}
<< watching_object
watched_
#{
class_plural
}
<< watching_object
save!
end
end
end
end
def unwatch_
#{
class_single
}
(watching_object)
def unwatch_
#{
class_single
}
(watching_object)
self.watched_
#{
class_plural
}
.delete(watching_object)
watched_
#{
class_plural
}
.delete(watching_object)
save!
end
end
END
END
end
end
...
...
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