-
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.
- Loading branch information
Showing
30 changed files
with
997 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class BooksController < ApplicationController | ||
before_action :set_book, only: [:show, :update, :destroy] | ||
|
||
# GET /books | ||
def index | ||
@books = Book.all | ||
|
||
render json: @books | ||
end | ||
|
||
# GET /books/1 | ||
def show | ||
render json: @book | ||
end | ||
|
||
# POST /books | ||
def create | ||
@book = Book.new(book_params) | ||
|
||
if @book.save | ||
render json: @book, status: :created, location: @book | ||
else | ||
render json: @book.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# PATCH/PUT /books/1 | ||
def update | ||
if @book.update(book_params) | ||
render json: @book | ||
else | ||
render json: @book.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# DELETE /books/1 | ||
def destroy | ||
@book.destroy | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_book | ||
@book = Book.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def book_params | ||
params.require(:book).permit(:title, :category, :cover_image, :author, :condition, :is_available, :user_id) | ||
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,51 @@ | ||
class RatingsController < ApplicationController | ||
before_action :set_rating, only: [:show, :update, :destroy] | ||
|
||
# GET /ratings | ||
def index | ||
@ratings = Rating.all | ||
|
||
render json: @ratings | ||
end | ||
|
||
# GET /ratings/1 | ||
def show | ||
render json: @rating | ||
end | ||
|
||
# POST /ratings | ||
def create | ||
@rating = Rating.new(rating_params) | ||
|
||
if @rating.save | ||
render json: @rating, status: :created, location: @rating | ||
else | ||
render json: @rating.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# PATCH/PUT /ratings/1 | ||
def update | ||
if @rating.update(rating_params) | ||
render json: @rating | ||
else | ||
render json: @rating.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# DELETE /ratings/1 | ||
def destroy | ||
@rating.destroy | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_rating | ||
@rating = Rating.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def rating_params | ||
params.require(:rating).permit(:rate, :user_id) | ||
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,51 @@ | ||
class ReviewsController < ApplicationController | ||
before_action :set_review, only: [:show, :update, :destroy] | ||
|
||
# GET /reviews | ||
def index | ||
@reviews = Review.all | ||
|
||
render json: @reviews | ||
end | ||
|
||
# GET /reviews/1 | ||
def show | ||
render json: @review | ||
end | ||
|
||
# POST /reviews | ||
def create | ||
@review = Review.new(review_params) | ||
|
||
if @review.save | ||
render json: @review, status: :created, location: @review | ||
else | ||
render json: @review.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# PATCH/PUT /reviews/1 | ||
def update | ||
if @review.update(review_params) | ||
render json: @review | ||
else | ||
render json: @review.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# DELETE /reviews/1 | ||
def destroy | ||
@review.destroy | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_review | ||
@review = Review.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def review_params | ||
params.require(:review).permit(:content, :rate, :book_id, :user_id) | ||
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,51 @@ | ||
class UsersController < ApplicationController | ||
before_action :set_user, only: [:show, :update, :destroy] | ||
|
||
# GET /users | ||
def index | ||
@users = User.all | ||
|
||
render json: @users | ||
end | ||
|
||
# GET /users/1 | ||
def show | ||
render json: @user | ||
end | ||
|
||
# POST /users | ||
def create | ||
@user = User.new(user_params) | ||
|
||
if @user.save | ||
render json: @user, status: :created, location: @user | ||
else | ||
render json: @user.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# PATCH/PUT /users/1 | ||
def update | ||
if @user.update(user_params) | ||
render json: @user | ||
else | ||
render json: @user.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# DELETE /users/1 | ||
def destroy | ||
@user.destroy | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_user | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def user_params | ||
params.require(:user).permit(:username, :email, :phone, :location) | ||
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,3 @@ | ||
class Book < ApplicationRecord | ||
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Rating < ApplicationRecord | ||
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Review < ApplicationRecord | ||
belongs_to :book | ||
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class User < ApplicationRecord | ||
has_many :books | ||
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 BookSerializer < ActiveModel::Serializer | ||
attributes :id, :title, :category, :cover_image, :author, :condition, :is_available | ||
has_one :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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class RatingSerializer < ActiveModel::Serializer | ||
attributes :id, :rate | ||
has_one :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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ReviewSerializer < ActiveModel::Serializer | ||
attributes :id, :content, :rate | ||
has_one :book | ||
has_one :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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class UserSerializer < ActiveModel::Serializer | ||
attributes :id, :username, :email, :phone, :location | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class CreateUsers < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :users do |t| | ||
t.string :username | ||
t.string :email | ||
t.string :phone | ||
t.string :location | ||
|
||
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,15 @@ | ||
class CreateBooks < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :books do |t| | ||
t.string :title | ||
t.string :category | ||
t.string :cover_image | ||
t.string :author | ||
t.string :condition | ||
t.boolean :is_available | ||
t.references :user, null: false, foreign_key: true | ||
|
||
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,12 @@ | ||
class CreateReviews < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :reviews do |t| | ||
t.text :content | ||
t.integer :rate | ||
t.references :book, null: false, foreign_key: true | ||
t.references :user, null: false, foreign_key: true | ||
|
||
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,10 @@ | ||
class CreateRatings < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :ratings do |t| | ||
t.integer :rate | ||
t.references :user, null: false, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Book, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Rating, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Review, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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,5 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe User, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
end |
Oops, something went wrong.