forked from expertiza/reimplementation-back-end
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bookmark scaffold files created * Create bookmarks_controller * crud ops * add score related functions for bookmark * Create bookmarks_controller_spec.rb * Adding setup.sh to automate the setup inside containers (expertiza#84) * Adding files to setup * Updating setup script with working seed file * Adding a setup script to try to automate setup * Adding setup.sh as entrypoint * add db creation initilization script --------- Co-authored-by: Muhammad Ali Qureshi <[email protected]> Co-authored-by: ameyagv <[email protected]> * deleted unnecessary files * modified sign_up_topic * removed gemfile.lock and schema.rb * added gemfile.lock and schema.rb * changes bookmarks controller * added bookmark rating functions * added bookmark controller tests * schema update * swagger config update * resovle sign_up_topic migration * update schema.rb --------- Co-authored-by: Akshat Nitin Savla <[email protected]> Co-authored-by: Mitanshu Reshamwala <[email protected]> Co-authored-by: Mitanshu Reshamwala <[email protected]> Co-authored-by: vyshnavi-adusumelli <[email protected]> Co-authored-by: Ali Qureshi <[email protected]> Co-authored-by: Muhammad Ali Qureshi <[email protected]>
- Loading branch information
1 parent
2e68f30
commit fdf2a81
Showing
14 changed files
with
1,861 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
class Api::V1::BookmarksController < ApplicationController | ||
|
||
# Index method returns the list of JSON objects of the bookmark | ||
# GET on /bookmarks | ||
def index | ||
@bookmarks = Bookmark.order(:id) | ||
render json: @bookmarks, status: :ok and return | ||
end | ||
|
||
# Show method returns the JSON object of bookmark with id = {:id} | ||
# GET on /bookmarks/:id | ||
def show | ||
begin | ||
@bookmark = Bookmark.find(params[:id]) | ||
render json: @bookmark, status: :ok and return | ||
rescue ActiveRecord::RecordNotFound | ||
render json: $ERROR_INFO.to_s, status: :not_found and return | ||
end | ||
end | ||
|
||
# Create method creates a bookmark and returns the JSON object of the created bookmark | ||
# POST on /bookmarks | ||
def create | ||
begin | ||
# params[:user_id] = @current_user.id | ||
@bookmark = Bookmark.new(bookmark_params) | ||
@bookmark.user_id = @current_user.id | ||
@bookmark.save! | ||
render json: @bookmark, status: :created and return | ||
rescue ActiveRecord::RecordInvalid | ||
render json: $ERROR_INFO.to_s, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# Update method updates the bookmark object with id - {:id} and returns the updated bookmark JSON object | ||
# PUT on /bookmarks/:id | ||
def update | ||
@bookmark = Bookmark.find(params[:id]) | ||
if @bookmark.update(update_bookmark_params) | ||
render json: @bookmark, status: :ok | ||
else | ||
render json: @bookmark.errors.full_messages, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# Destroy method deletes the bookmark object with id- {:id} | ||
# DELETE on /bookmarks/:id | ||
def destroy | ||
begin | ||
@bookmark = Bookmark.find(params[:id]) | ||
@bookmark.delete | ||
rescue ActiveRecord::RecordNotFound | ||
render json: $ERROR_INFO.to_s, status: :not_found and return | ||
end | ||
end | ||
|
||
# get_bookmark_rating_score method gets the bookmark rating of the bookmark object with id- {:id} | ||
# GET on /bookmarks/:id/bookmarkratings | ||
def get_bookmark_rating_score | ||
begin | ||
@bookmark = Bookmark.find(params[:id]) | ||
@bookmark_rating = BookmarkRating.where(bookmark_id: @bookmark.id, user_id: @current_user.id).first | ||
render json: @bookmark_rating, status: :ok and return | ||
rescue ActiveRecord::RecordNotFound | ||
render json: $ERROR_INFO.to_s, status: :not_found and return | ||
end | ||
end | ||
|
||
# save_bookmark_rating_score method creates or updates the bookmark rating of the bookmark object with id- {:id} | ||
# POST on /bookmarks/:id/bookmarkratings | ||
def save_bookmark_rating_score | ||
@bookmark = Bookmark.find(params[:id]) | ||
@bookmark_rating = BookmarkRating.where(bookmark_id: @bookmark.id, user_id: @current_user.id).first | ||
if @bookmark_rating.blank? | ||
@bookmark_rating = BookmarkRating.create(bookmark_id: @bookmark.id, user_id: @current_user.id, rating: params[:rating]) | ||
else | ||
@bookmark_rating.update({'rating': params[:rating].to_i}) | ||
end | ||
render json: {"bookmark": @bookmark, "rating": @bookmark_rating}, status: :ok | ||
end | ||
|
||
private | ||
|
||
def bookmark_params | ||
params.require(:bookmark).permit(:url, :title, :description, :topic_id, :rating, :id) | ||
end | ||
|
||
def update_bookmark_params | ||
params.require(:bookmark).permit(:url, :title, :description) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Bookmark < ApplicationRecord | ||
belongs_to :user | ||
# belongs_to :topic, class_name: "SignUpTopic" | ||
has_many :bookmark_ratings | ||
validates :url, presence: true | ||
validates :title, presence: true | ||
validates :description, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class BookmarkRating < ApplicationRecord | ||
belongs_to :bookmark | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class SignUpTopic < ApplicationRecord | ||
has_many :signed_up_teams, foreign_key: 'sign_up_topic_id', dependent: :destroy | ||
has_many :signed_up_teams, foreign_key: 'topic_id', dependent: :destroy | ||
has_many :teams, through: :signed_up_teams # list all teams choose this topic, no matter in waitlist or not | ||
has_many :assignment_questionnaires, class_name: 'AssignmentQuestionnaire', foreign_key: 'topic_id', dependent: :destroy | ||
belongs_to :assignment | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateBookmarks < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :bookmarks do |t| | ||
t.text :url | ||
t.text :title | ||
t.text :description | ||
t.integer :user_id | ||
t.integer :topic_id | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateBookmarkRatings < ActiveRecord::Migration[7.0] | ||
def up | ||
create_table "bookmark_ratings" do |t| | ||
t.integer "bookmark_id" | ||
t.integer "user_id" | ||
t.integer "rating" | ||
t.timestamps | ||
end | ||
end | ||
def down | ||
drop_table "bookmark_ratings" | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.