This is a Next.js project bootstrapped with create-next-app.

Tech Stack

Next.Js, Prisma, Typescript, NodeJS, Tailwind, PostgreSQL, MobX

Installations

  1. Clone the Repo
git clone https://github.com/rdhhauzan/library-nextjs.git
  1. Install dependencies
cd library-nextjs
npm install
  1. rename .env.example
cp .env.example .env
  1. Update .env
DATABASE_URL="your postgresql url"
  1. Run Migrations
npx prisma migrate dev
  1. Run NextJS
npm run dev

API Routes

URI Additional Notes
GET /categories Retrieve all categories
POST /categories Create a new category
PATCH /category/:id Update an existing category based on its ID.
DELETE /category/:id Delete a category based on its ID.
GET /category/:id Retrieve a category based on its ID
GET /categories/:id/books Retrieve all books based on the category ID, you can filter data, see below
GET /books Retrieve a list of all books, you can filter data, see below
POST /books Create a new book.
PATCH /book/:id Update an existing book based on its ID.
DELETE /book/:id Delete a book based on its ID.
GET /book/:id Retrieve details of a specific book.
POST /login Authenticate and login a user.
POST /register Register a new user.

Search and Filter Books

You can apply the following filters when retrieving books using below routes :

URI Additional Notes
GET /categories/:id/books Retrieve all books based on the category ID, you can filter data, see below
GET /books Retrieve a list of all books, you can filter data, see below

Filter :

  • title (case-insensitive search by title)
  • minYear (filter by minimum publication year)
  • maxYear (filter by maximum publication year)
  • minPage (filter by minimum number of pages)
  • maxPage (filter by maximum number of pages)
  • sortByTitle (sort books in ascending or descending order by title)

Example :

GET /categories/:id/books?title=example&minYear=2000&maxPage=300&sortByTitle=asc
GET /books?title=example&minYear=2000&maxPage=300&sortByTitle=asc

Update 09 December 2023

Add and use MobX state management