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
035d6f4c
Commit
035d6f4c
authored
Jun 27, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return comment after voting
parent
bfb43459
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
5 deletions
+15
-5
Rakefile
+13
-2
app.rb
+2
-3
No files found.
Rakefile
View file @
035d6f4c
...
...
@@ -27,8 +27,9 @@ namespace :db do
Vote
.
delete_all
User
.
delete_all
level_limit
=
YAML
.
load_file
(
"config/application.yml"
)[
"level_limit"
]
(
1
..
3
).
each
do
|
question_id
|
comment_thread
=
CommentThread
.
create!
:commentable_type
=>
"questions"
,
:commentable_id
=>
question_id
def
generate_comments
(
commentable_type
,
commentable_id
,
level_limit
)
comment_thread
=
CommentThread
.
create!
:commentable_type
=>
commentable_type
,
:commentable_id
=>
commentable_id
5
.
times
do
comment_thread
.
root_comments
.
create
:body
=>
"top comment"
,
:title
=>
"top
#{
rand
(
10
)
}
"
,
:user_id
=>
1
,
:course_id
=>
1
,
:comment_thread_id
=>
comment_thread
.
id
end
...
...
@@ -37,6 +38,15 @@ namespace :db do
comment
.
children
.
create
:body
=>
"comment body"
,
:title
=>
"comment title
#{
rand
(
50
)
}
"
,
:user_id
=>
1
,
:course_id
=>
1
,
:comment_thread_id
=>
comment_thread
.
id
end
end
generate_comments
(
"questions"
,
1
,
level_limit
)
generate_comments
(
"questions"
,
2
,
level_limit
)
generate_comments
(
"questions"
,
3
,
level_limit
)
generate_comments
(
"courses"
,
1
,
level_limit
)
generate_comments
(
"lectures"
,
1
,
level_limit
)
generate_comments
(
"lectures"
,
2
,
level_limit
)
generate_comments
(
"lectures"
,
3
,
level_limit
)
Comment
.
all
.
reject
{
|
c
|
c
.
is_root?
}.
each
do
|
c
|
(
1
..
20
).
each
do
|
id
|
user
=
User
.
find_or_create_by_id
(
id
)
...
...
@@ -44,4 +54,5 @@ namespace :db do
end
end
end
end
app.rb
View file @
035d6f4c
...
...
@@ -69,7 +69,6 @@ end
# get the information of a single comment
get
'/api/v1/comments/:comment_id'
do
|
comment_id
|
puts
params
comment
=
Comment
.
find_by_id
(
comment_id
)
if
comment
.
nil?
or
comment
.
is_root?
error
400
,
{
:error
=>
"invalid comment id"
}.
to_json
...
...
@@ -124,7 +123,7 @@ put '/api/v1/votes/comments/:comment_id/users/:user_id' do |comment_id, user_id|
if
%w[up down]
.
include?
params
[
"value"
]
user
=
User
.
find_or_create_by_id
(
user_id
)
vote
=
user
.
vote
(
comment
,
{
:direction
=>
(
params
[
"value"
]
==
"up"
?
:
up
:
:down
),
:exclusive
=>
:true
})
vote
.
to_json
comment
.
to_json
else
error
400
,
{
:error
=>
"value must be up or down"
}.
to_json
end
...
...
@@ -138,7 +137,7 @@ delete '/api/v1/votes/comments/:comment_id/users/:user_id' do |comment_id, user_
comment
=
Comment
.
find_by_id
(
comment_id
)
if
user
and
comment
and
not
comment
.
is_root?
vote
=
user
.
unvote_for
(
comment
)
vote
.
to_json
comment
.
to_json
else
error
400
,
{
:error
=>
"invalid user or comment id"
}.
to_json
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