Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
*.swp
/config/key.yml
.rvmrc
.DS_Store
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ gem 'rails_admin', '>= 1.0.0.rc'
gem 'annotate'
gem 'omniauth-facebook'
gem 'httparty'
gem 'simple_token_authentication', '~> 1.0'
gem 'bitly'
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ GEM
rake (>= 10.4, < 12.0)
arel (7.1.1)
bcrypt (3.1.11)
bitly (0.10.4)
httparty (>= 0.7.6)
multi_json (~> 1.3)
oauth2 (>= 0.5.0, < 2.0)
builder (3.2.2)
byebug (9.0.5)
carrierwave (1.0.0.beta)
Expand Down Expand Up @@ -192,6 +196,10 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
simple_token_authentication (1.14.0)
actionmailer (>= 3.2.6, < 6)
actionpack (>= 3.2.6, < 6)
devise (>= 3.2, < 6)
spring (1.7.2)
spring-watcher-listen (2.0.0)
listen (>= 2.7, < 4.0)
Expand Down Expand Up @@ -227,6 +235,7 @@ PLATFORMS

DEPENDENCIES
annotate
bitly
byebug
carrierwave (>= 1.0.0.beta, < 2.0)
coffee-rails (~> 4.2)
Expand All @@ -242,6 +251,7 @@ DEPENDENCIES
rails_admin (>= 1.0.0.rc)
remotipart!
sass-rails (~> 5.0)
simple_token_authentication (~> 1.0)
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
Expand Down
14 changes: 14 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@
*= require_tree .
*= require_self
*/

body {
min-height: 2000px;
padding-top: 70px;
}

.row.courses {
text-align: center;
}

.nopadding {
padding: 0 !important;
margin: 0 !important;
}
10 changes: 7 additions & 3 deletions app/assets/stylesheets/courses.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#course-title {
min-height: 50px;
position: fixed;
top: 0;
//position: fixed;
//top: 0;
background-color: #f8f8f8;
border-color: #e7e7e7;
border: 1px solid transparent;
Expand Down Expand Up @@ -88,4 +88,8 @@ a#btn-new-post {
position: fixed;
bottom: 0;
border-radius: 0;
}
}

.users {
text-align: left;
}
3 changes: 1 addition & 2 deletions app/assets/stylesheets/posts.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Place all the styles related to the posts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

#post-title {
min-height: 50px;
position: fixed;
Expand Down Expand Up @@ -31,4 +30,4 @@
max-width: 100%;
height: auto;
}
}
}
66 changes: 66 additions & 0 deletions app/controllers/api/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class Api::CommentsController < ApplicationController
# TODO pagination
def index
post = Post.find(params[:post_id])

if current_user.enrolled?(post.course_id)
comments = post.comments

render :json => {
comments: comments
}
else
render :json => {
comments: []
}, :status => 401
end
end

def create
post = Post.find(params[:post_id])

if current_user.enrolled?(post.course_id)
comment = Comment.new(comment_params)
comment.user = current_user
comment.course = post.course
comment.save

render :json => {
comment: comment
}
else
render :json => {
comment: {}
}, :status => 401
end
end

def update
comment = Comment.find(params[:id])

if comment.user_id == current_user.id
comment.update(comment_params)

render :json => {
comment: comment
}
else
render :json => {}, :status => 401
end
end

def delete
comment = Comment.find(params[:id])

if comment.user_id == current_user.id
comment.delete
render :json => {}
else
render :json => {}, :status => 401
end
end

def comment_params
params.require(:comment).permit(:content)
end
end
94 changes: 94 additions & 0 deletions app/controllers/api/courses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
class Api::CoursesController < ApplicationController
# TODO pagintation
def index
courses = Course.all
my_courses = current_user.courses

render :json => {
courses: courses,
my_courses: my_courses
}
end

def create
course = Course.new(course_params)
course.manager = current_user
course.save

course.generate_short_link
course.join(current_user)

render :json => {
course: course
}
end

def join
course = Course.find(params[:id])
course.join(current_user)

render :json => {
course: course
}
end

def leave
course = Course.find(params[:id])
course.leave(current_user)

render :json => {
}
end

def show
respond_to do |format|
format.html {
@course = Course.find(params[:id])
}
format.json {
course = Course.find(params[:id])

if current_user.enrolled?(course.id)
render :json => {
course: course
}
else
render :json => {
course: {}
}, :status => 401
end
}
end
end

def update
course = Course.find(params[:id])

if course.manager_id == current_user.id
course.update(course_params)

render :json => {
course: course
}
else
render :json => {}, :status => 401
end
end

def delete
course = Course.find(params[:id])

if course.manager_id == current_user.id
# TODO need to add condition
course.delete
render :json => {}
else
render :json => {}, :status => 401
end
end

def course_params
#params.require(:course).permit(:name)
params.require(:course).permit(:name, :attachment, :date)
end
end
127 changes: 127 additions & 0 deletions app/controllers/api/photos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
class Api::PhotosController < ApplicationController
def index
post = Post.find(params[:post_id])

if current_user.enrolled?(post.course_id)
photos = post.photos

render :json => {
photos: photos
}
else
render :json => {
photos: []
}, :status => 401
end
end

def create
post = Post.find(params[:post_id])

if current_user.enrolled?(post.course_id)
photo = Photo.new(photo_params)
photo.user = current_user
photo.post = post
photo.save

render :json => {
photo: photo
}
else
render :json => {
photo: {}
}, :status => 401
end
end

def show
photo = Photo.find(params[:id])

if current_user.enrolled?(params[:course_id])
render :json => {
photo: photo.attachment,
date: photo.created_at
}
else
render :json => {
photo: {},
date: nil
}, :status => 401
end
end

def update
photo = Photo.find(params[:id])

if photo.user_id == current_user.id
photo.update(photo_params)

render :json => {
photo: photo
}
else
render :json => {}, :status => 401
end
end

def delete
photo = Photo.find(params[:id])

if photo.user_id == current_user.id
photo.delete
render :json => {}
else
render :json => {}, :status => 401
end
end

def add_tag
course = Course.find(params[:course_id])

# TODO remove duplicated tag on post_id, user_id
if current_user.enrolled?(course.id)
tag = TaggedUser.new(tag_params)
tag.user = current_user
tag.photo_id = params[:photo_id]
tag.save

render :json => {
tag: tag
}
else
render :json => {}, :status => 401
end
end

def edit_tag
course = Course.find(params[:course_id])
tag = TaggedUser.find(params[:id])

if tag.user_id == current_user.id || course.manager_id == current_user.id
tag.update(tag_params)
render :json => {}
else
render :json => {}, :status => 401
end
end

def remove_tag
course = Course.find(params[:course_id])
tag = TaggedUser.find(params[:id])

if tag.user_id == current_user.id || course.manager_id == current_user.id
tag.delete
render :json => {}
else
render :json => {}, :status => 401
end
end

def photo_params
params.require(:photo).permit(:attachment, :post_id)
end

def tag_params
params.require(:tag).permit(:x, :y, :width, :height)
end
end
Loading