Skip to content

Kabazbay/libsystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

School Library Management API

A RESTful API for managing a School Library System built with Node.js, Express.js, and MongoDB. This API handles Authors, Books, Students, Library Attendants, and Book Borrowing & Returns.

Tech Stack

  • Runtime: Node.js
  • Framework: Express.js
  • Database: MongoDB (Mongoose ODM)
  • Dev Tools: Nodemon, dotenv

Setup & Installation

Prerequisites

Steps

  1. Clone the repository

    git clone https://github.com/Kabazbay/libsystem.git
    cd libsystem
  2. Install dependencies

    npm install
  3. Create a .env file in the root directory

    mongoDB=mongodb://localhost:27017/libraryDB
    
  4. Start MongoDB (if not already running)

    mongod
  5. Start the server

    npm run dev
  6. The API will be running at http://localhost:3000

Project Structure

/School Library Management API
  /models
    author.js
    book.js
    student.js
    attendant.js
  /controllers
    authorController.js
    bookController.js
    studentController.js
    attendantController.js
  /routes
    authorRoutes.js
    bookRoutes.js
    studentRoutes.js
    attendantRoutes.js
  /config
    database.js
  server.js

API Documentation

Base URL: http://localhost:3000


1. Author Endpoints

Create Author

  • POST /authors
  • Body:
    {
      "name": "Chinua Achebe",
      "bio": "Nigerian novelist and poet"
    }
  • Response: 200 — Created author object

Get All Authors

  • GET /authors
  • Response: 200 — Array of all authors

Get Single Author

  • GET /authors/:id
  • Response: 200 — Single author object

Update Author

  • PUT /authors/:id
  • Body:
    {
      "name": "Updated Name",
      "bio": "Updated bio"
    }
  • Response: 200 — Updated author object

Delete Author

  • DELETE /authors/:id
  • Response: 200 — Deleted author object

2. Book Endpoints

Create Book

  • POST /books
  • Body:
    {
      "title": "Things Fall Apart",
      "isbn": "978-0-385-47454-2",
      "authors": ["<author_id>"]
    }
  • Response: 200 — Created book object
  • Error: 400 — If ISBN already exists

Get All Books

  • GET /books
  • Response: 200 — Array of all books (authors populated)

Get Single Book

  • GET /books/:id
  • Response: 200 — Single book object with populated authors, borrowedBy, and issuedBy

Update Book

  • PUT /books/:id
  • Body:
    {
      "title": "Updated Title"
    }
  • Response: 200 — Updated book object

Delete Book

  • DELETE /books/:id
  • Response: 200 — Deleted book object

3. Student Endpoints

Create Student

  • POST /students
  • Body:
    {
      "name": "John Doe",
      "email": "john@school.com",
      "studentID": "STU001"
    }
  • Response: 200 — Created student object

Get All Students

  • GET /students
  • Response: 200 — Array of all students

Get Single Student

  • GET /students/:id
  • Response: 200 — Single student object

4. Library Attendant Endpoints

Create Attendant

  • POST /attendants
  • Body:
    {
      "name": "Jane Smith",
      "staffID": "STAFF001"
    }
  • Response: 200 — Created attendant object

Get All Attendants

  • GET /attendants
  • Response: 200 — Array of all attendants

5. Borrowing & Returning

Borrow a Book

  • POST /books/:id/borrow
  • Body:
    {
      "studentId": "<student_id>",
      "attendantId": "<attendant_id>",
      "returnDate": "2026-04-01"
    }
  • Rules:
    • Book must have status "IN"
    • Student and Attendant must exist
  • Response: 200{ "message": "Book borrowed successfully" }
  • Error: 400 — If book is already borrowed
  • Error: 404 — If student, attendant, or book not found

Return a Book

  • POST /books/:id/return
  • Rules:
    • Book must have status "OUT"
    • After return: status → "IN", clears borrowedBy, issuedBy, returnDate
  • Response: 200 — Updated book object
  • Error: 404 — If book not found

Data Models

Author

Field Type Required
name String Yes
bio String No
createdAt Date Auto

Book

Field Type Required Notes
title String Yes
isbn String Yes Unique
authors [ObjectId] Yes References Author
status String No "IN" or "OUT", default: "IN"
borrowedBy ObjectId No References Student
issuedBy ObjectId No References Attendant
returnDate Date No
createdAt Date Auto

Student

Field Type Required Notes
name String Yes
email String Yes Unique
studentID String Yes Unique
createdAt Date Auto

Library Attendant

Field Type Required Notes
name String Yes
staffID String Yes Unique
createdAt Date Auto

About

School Library System Management API - Assignment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors