Skip to content

[JITERA] Implement Reader Module for Book Borrowing Management

chi le requested to merge feat/reader-module-1750781196 into main

Created by: chi-jitera

Overview

This pull request introduces a new reader module that allows for the management of readers who borrow books. The module includes a model, controller, routes, and updates to the server configuration.

Changes Made

  1. Create Reader Model

    • A new model file Reader.js was created in the /models directory. This model defines the schema for a reader, including their name, contact information, and a list of borrowed books.
    const mongoose = require('../config/db');
    const readerSchema = new mongoose.Schema({
        name: { type: String, required: true },
        contactInfo: { type: String, required: true },
        borrowedBooks: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Book' }]
    });
    module.exports = mongoose.model('Reader', readerSchema);
  2. Create Reader Controller

    • A new controller file readerController.js was created in the /controllers directory. This controller includes methods for adding a reader, retrieving all readers, and allowing a reader to borrow a book.
    const Reader = require('../models/Reader');
    const Book = require('../models/Book');
    
    exports.addReader = async (req, res) => { /* implementation */ };
    exports.getReaders = async (req, res) => { /* implementation */ };
    exports.borrowBook = async (req, res) => { /* implementation */ };
  3. Create Reader Routes

    • A new routes file readerRoutes.js was created in the /routes directory. This file defines the API endpoints for managing readers, including routes for adding a reader, getting all readers, and borrowing a book.
    const express = require('express');
    const readerController = require('../controllers/readerController');
    const router = express.Router();
    
    router.post('/readers', readerController.addReader);
    router.get('/readers', readerController.getReaders);
    router.post('/readers/:readerId/borrow/:bookId', readerController.borrowBook);
    module.exports = router;
  4. Update Server to Include Reader Module

    • The server.js file was updated to include the new reader routes. This allows the application to handle requests related to readers.
    const readerRoutes = require('./routes/readerRoutes');
    app.use('/api', readerRoutes);

This implementation provides a complete solution for managing readers and their book borrowing activities.

Merge request reports