book listing and reviews
uses prisma
, mysql
, express
on the server and react
, react-router
, redux-toolkit
, sass
on client
- Endpoint:
GET /books
- Description: Get a list of all books with average ratings.
- Response:
- Status: 200 OK
- Body: An array of book objects, each containing book details and average rating.
- Endpoint:
GET /books/:id
- Description: Get detailed information about a specific book including its average rating.
- Parameters:
id
(number): The ID of the book to retrieve.
- Response:
- Status: 200 OK
- Body: Book details including average rating.
- Endpoint:
POST /ratings
- Description: Create a new rating and review for a book.
- Request Body:
review
(string): The review text.rating
(number): The rating value (1-5).bookId
(number): The ID of the book being rated.
- Response:
- Status: 201 Created
- Body: The rating object.
Table Rating {
id UUID [primary key]
createdAt DateTime [default: `now()`, not null]
updatedAt DateTime [not null]
review Text
rating Int
bookId UUID
foreign key (bookId) references Book(id)
}
Table Book {
id UUID [primary key]
createdAt DateTime [default: `now()`, not null]
updatedAt DateTime [not null]
name Text
author Text
description Text
price Int
img Text?
}
Ref: Rating.bookId > Book.id
Clone the repo
git clone https://github.com/33j33/2goodreads.git
cd ./server
npm install
- create a mysql database. usage of any other other can be configured in schema.prisma.
- create an
.env
file at root of server directory. - specify db url in MYSQL_URL in format mysql://${USER}:${PASSWORD}@${HOST}:${PORT}/${DB}
- specify dev server port, eg PORT=3000
- run
npx prisma generate
to create prisma client for you, using the schema. - run
npx prisma migrate dev
to run migrations. - run
npx prisma db seed
to seed db using books defined inprisma/seed.ts
- run
npx run dev
to start dev server
cd ./client
npm install
- create an
.env
file and specify backend server url in REACT_APP_API_URL - run
npm run start