Skip to content

Manages a collection of books with a custom database table, REST API, and a React-based admin interface.

Notifications You must be signed in to change notification settings

mofizul21/library-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Library Manager

A WordPress plugin to manage a collection of books with a custom database table, REST API, and a React-based (TypeScript) admin interface.

Features

  • Custom Database Table: Manages book data in a dedicated database table.
  • REST API: Provides secure and validated REST endpoints for CRUD operations on books.
  • React-based Admin Interface: A dynamic and interactive admin area built with React and TypeScript for managing books. Includes:
    • Adding, editing, and deleting books.
    • Search functionality by title, author, or description.
    • Pagination for browsing large collections.
    • Visual status indicators (colored circles).
  • Internationalization (i18n): Ready for translation.
  • Robust Build Process: Automated build and packaging for production readiness.

Installation

  1. Download the plugin: Obtain the plugin as a ZIP file (e.g., from a release or by building it).
  2. Upload to WordPress: In your WordPress admin, go to Plugins > Add New.
  3. Click Upload Plugin and select the downloaded ZIP file.
  4. Activate the plugin: After successful upload, activate the plugin. Upon activation, a custom database table ({$wpdb->prefix}library_books) will be created.

Build Process (For Developers)

This plugin includes a React application for its admin interface, developed with TypeScript, and a Grunt-based build system for packaging.

1. Install Global Dependencies (if not already installed)

Ensure you have Node.js and npm installed.

2. Install Plugin Root Dependencies

These are for the Grunt build system. Navigate to the plugin's root directory:

cd /path/to/your/wp-content/plugins/library-manager
npm install

3. Build the Plugin (including React App)

To generate a production-ready ZIP file of the entire plugin:

cd /path/to/your/wp-content/plugins/library-manager
npm run build

This command will:

  • Install React app dependencies (if not already installed).
  • Compile the TypeScript React application located in admin/js.
  • Generate translation files (.pot).
  • Copy all necessary plugin files.
  • Create a distributable ZIP file (e.g., library-manager-1.0.0.zip) in the build/ directory.

4. Frontend Development (React App)

If you wish to develop or modify the React application directly:

  1. Navigate to the admin/js directory:
    cd /path/to/your/wp-content/plugins/library-manager/admin/js
  2. Install its dependencies:
    npm install
  3. You can then run the React development server:
    npm start
    (Note: This is for frontend development purposes only and typically runs on a separate port. For changes to reflect in WordPress, you would need to run npm run build in admin/js and then npm run build in the plugin root.)

WP-CLI Commands

This plugin provides the following WP-CLI commands for command-line management.

wp library import <file>

  • Description: Imports book data from a JSON file into the library.
  • Arguments:
    • <file> (string, required): The absolute or relative path to the JSON file containing book data. The JSON file should contain an array of book objects, each with title, author, publication_year, and description properties.
  • Example:
    wp library import /Users/mofizulislam/Sites/wpplugins/wp-content/plugins/library-manager/sample.json
    or (if run from WordPress root):
    wp library import wp-content/plugins/library-manager/sample.json

REST API Documentation

Base URL

/wp-json/library/v1

Endpoints

GET /books

  • Description: Get all books.
  • Filters:
    • status (string): available, borrowed, or unavailable
    • author (string): Filter by author name.
    • year (integer): Filter by publication year.
    • search (string): Search by title, author, or description.
  • Pagination:
    • page (integer): Current page (default: 1).
    • per_page (integer): Items per page (default: 10).

GET /books/{id}

  • Description: Get a single book by ID.

POST /books

  • Description: Create a new book.
  • Permission: edit_posts capability.
  • Body (JSON):
    • title (string, required)
    • author (string, required)
    • publication_year (integer, required)
    • description (string)
    • status (string): available, borrowed, or unavailable

PUT /books/{id}

  • Description: Update a book by ID.
  • Permission: edit_posts capability.
  • Body (JSON): Same as POST.

DELETE /books/{id}

  • Description: Delete a book by ID.
  • Permission: edit_posts capability.

Table Schema

The plugin creates a custom table named {$wpdb->prefix}library_books with the following schema:

  • id BIGINT unsigned AUTO_INCREMENT PRIMARY KEY
  • title VARCHAR(255) NOT NULL
  • description LONGTEXT
  • author VARCHAR(255) NOT NULL
  • publication_year INT NOT NULL
  • status ENUM('available','borrowed','unavailable') DEFAULT 'available'
  • created_at DATETIME DEFAULT CURRENT_TIMESTAMP
  • updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

About

Manages a collection of books with a custom database table, REST API, and a React-based admin interface.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published