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
47c0c700
Commit
47c0c700
authored
Jul 30, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
random bug fixes
parent
c0d9cb1e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
20 deletions
+15
-20
app.rb
+15
-20
No files found.
app.rb
View file @
47c0c700
...
@@ -18,16 +18,15 @@ CommentService.config = YAML.load_file("config/application.yml")
...
@@ -18,16 +18,15 @@ CommentService.config = YAML.load_file("config/application.yml")
Mongoid
.
load!
(
"config/mongoid.yml"
)
Mongoid
.
load!
(
"config/mongoid.yml"
)
Mongoid
.
logger
.
level
=
Logger
::
INFO
Mongoid
.
logger
.
level
=
Logger
::
INFO
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/lib/**/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/lib/**/*.rb'
].
each
{
|
file
|
require
file
}
Dir
[
File
.
dirname
(
__FILE__
)
+
'/models/*.rb'
].
each
{
|
file
|
require
file
}
get
'/api/v1/search/threads'
do
get
'/api/v1/search/threads'
do
results
=
CommentThread
.
solr_search
do
CommentThread
.
solr_search
do
fulltext
(
params
[
"text"
])
if
params
[
"text"
]
fulltext
(
params
[
"text"
])
if
params
[
"text"
]
with
(
:commentable_id
,
params
[
"commentable_id"
])
if
params
[
"commentable_id"
]
with
(
:commentable_id
,
params
[
"commentable_id"
])
if
params
[
"commentable_id"
]
with
(
:tags
).
all_of
(
params
[
"tags"
].
split
/,/
)
if
params
[
"tags"
]
with
(
:tags
).
all_of
(
params
[
"tags"
].
split
/,/
)
if
params
[
"tags"
]
end
.
results
end
.
results
.
map
(
&
:to_hash
).
to_json
results
.
map
(
&
:to_hash
).
to_json
end
end
delete
'/api/v1/:commentable_id/threads'
do
|
commentable_id
|
delete
'/api/v1/:commentable_id/threads'
do
|
commentable_id
|
...
@@ -45,9 +44,9 @@ post '/api/v1/:commentable_id/threads' do |commentable_id|
...
@@ -45,9 +44,9 @@ post '/api/v1/:commentable_id/threads' do |commentable_id|
thread
.
author
=
user
thread
.
author
=
user
thread
.
save
thread
.
save
if
thread
.
errors
.
any?
if
thread
.
errors
.
any?
error
400
,
thread
.
errors
.
messages
.
to_json
error
400
,
thread
.
errors
.
full_
messages
.
to_json
else
else
author
.
subscribe
(
thread
)
if
params
[
"auto_subscribe"
]
and
autho
r
user
.
subscribe
(
thread
)
if
params
[
"auto_subscribe"
]
and
use
r
thread
.
to_hash
.
to_json
thread
.
to_hash
.
to_json
end
end
end
end
...
@@ -61,7 +60,7 @@ get '/api/v1/threads/tags/autocomplete' do
...
@@ -61,7 +60,7 @@ get '/api/v1/threads/tags/autocomplete' do
end
end
get
'/api/v1/threads/:thread_id'
do
|
thread_id
|
get
'/api/v1/threads/:thread_id'
do
|
thread_id
|
thread
.
to_hash
(
recursive:
params
[
"recursive"
]).
to_json
CommentThread
.
find
(
thread_id
)
.
to_hash
(
recursive:
params
[
"recursive"
]).
to_json
end
end
put
'/api/v1/threads/:thread_id'
do
|
thread_id
|
put
'/api/v1/threads/:thread_id'
do
|
thread_id
|
...
@@ -71,7 +70,7 @@ put '/api/v1/threads/:thread_id' do |thread_id|
...
@@ -71,7 +70,7 @@ put '/api/v1/threads/:thread_id' do |thread_id|
thread
.
save
thread
.
save
end
end
if
thread
.
errors
.
any?
if
thread
.
errors
.
any?
error
400
,
thread
.
errors
.
messages
.
to_json
error
400
,
thread
.
errors
.
full_
messages
.
to_json
else
else
thread
.
to_hash
.
to_json
thread
.
to_hash
.
to_json
end
end
...
@@ -82,9 +81,9 @@ post '/api/v1/threads/:thread_id/comments' do |thread_id|
...
@@ -82,9 +81,9 @@ post '/api/v1/threads/:thread_id/comments' do |thread_id|
comment
.
author
=
user
comment
.
author
=
user
comment
.
save
comment
.
save
if
comment
.
errors
.
any?
if
comment
.
errors
.
any?
error
400
,
comment
.
errors
.
messages
.
to_json
error
400
,
comment
.
errors
.
full_
messages
.
to_json
else
else
author
.
subscribe
(
thread
)
if
params
[
"auto_subscribe"
]
and
autho
r
user
.
subscribe
(
thread
)
if
params
[
"auto_subscribe"
]
and
use
r
comment
.
to_hash
.
to_json
comment
.
to_hash
.
to_json
end
end
end
end
...
@@ -101,7 +100,7 @@ end
...
@@ -101,7 +100,7 @@ end
put
'/api/v1/comments/:comment_id'
do
|
comment_id
|
put
'/api/v1/comments/:comment_id'
do
|
comment_id
|
comment
.
update_attributes
(
params
.
slice
(
*
%w[body endorsed]
))
comment
.
update_attributes
(
params
.
slice
(
*
%w[body endorsed]
))
if
comment
.
errors
.
any?
if
comment
.
errors
.
any?
error
400
,
comment
.
errors
.
messages
.
to_json
error
400
,
comment
.
errors
.
full_
messages
.
to_json
else
else
comment
.
to_hash
.
to_json
comment
.
to_hash
.
to_json
end
end
...
@@ -113,7 +112,7 @@ post '/api/v1/comments/:comment_id' do |comment_id|
...
@@ -113,7 +112,7 @@ post '/api/v1/comments/:comment_id' do |comment_id|
sub_comment
.
comment_thread
=
comment
.
comment_thread
sub_comment
.
comment_thread
=
comment
.
comment_thread
sub_comment
.
save
sub_comment
.
save
if
sub_comment
.
errors
.
any?
if
sub_comment
.
errors
.
any?
error
400
,
sub_comment
.
errors
.
messages
.
to_json
error
400
,
sub_comment
.
errors
.
full_
messages
.
to_json
else
else
sub_comment
.
to_hash
.
to_json
sub_comment
.
to_hash
.
to_json
end
end
...
@@ -168,17 +167,13 @@ if environment.to_s == "development"
...
@@ -168,17 +167,13 @@ if environment.to_s == "development"
end
end
error
BSON
::
InvalidObjectId
do
error
BSON
::
InvalidObjectId
do
error
400
,
"requested object not found"
error
400
,
[
"requested object not found"
].
to_json
end
end
error
Mongoid
::
Errors
::
DocumentNotFound
do
error
Mongoid
::
Errors
::
DocumentNotFound
do
error
400
,
"requested object not found"
error
400
,
[
"requested object not found"
].
to_json
end
error
ValueError
do
error
400
,
env
[
'sinatra.error'
].
message
end
end
error
Mongoid
::
Errors
::
Validations
do
error
ArgumentError
do
error
400
,
env
[
'sinatra.error'
].
message
error
400
,
[
env
[
'sinatra.error'
].
message
].
to_json
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