-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added backend as server and setup database
- Loading branch information
Showing
12 changed files
with
674 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,65 @@ | ||
# MI_LIBRO | ||
Bookstore Library & Stock keeping app project from ict kerala | ||
# MI LIBRO | ||
|
||
MI LIBRO is a book management system built with `Node.js`, `Express` and `Reactjs` with `MUI` Theme. | ||
|
||
## Project Information | ||
|
||
- Version: 1.0.1 | ||
- Repository: [https://github.com/Ajayos/MI_LIBRO](https://github.com/Ajayos/MI_LIBRO) | ||
- Authors: [`Ajay o s`](https://github.com/Ajayos), [`Akarsh Krishna`](https://github.com/akarsh-krishna), [` Abinas Sulaimans`](https://github.com/Abinas8055), [`Saran T K`](https://github.com/SARAN-TK), [`Yasir Muhd`](https://github.com/yasirmuhd) | ||
- Created: 2023-05-17 | ||
- Modified: 2023-05-17 | ||
- Editor: Ajayos | ||
|
||
## Description | ||
|
||
MI LIBRO is a web application that allows users to manage books. It provides features such as adding new books, renting or selling books, tracking book status, and user interactions like comments and likes. | ||
|
||
## Installation | ||
|
||
1. Clone the repository: | ||
|
||
```bash | ||
git clone https://github.com/Ajayos/MI_LIBRO.git | ||
``` | ||
2. Change to MI_LIBRO: | ||
|
||
```bash | ||
cd MI_LIBRO | ||
``` | ||
|
||
3. Install the dependencies: | ||
|
||
```bash | ||
npm install | ||
``` | ||
4. Set up the database configuration in the `.env` file. | ||
|
||
5. Start the server: | ||
```bash | ||
npm start | ||
``` | ||
|
||
## Usage | ||
|
||
1. Start the server: | ||
```bash | ||
npm start | ||
``` | ||
The server will start running on http://localhost:3000. | ||
|
||
2. Access the MI LIBRO application in a web browser by visiting http://localhost:3000. | ||
|
||
3. If a Public folder is found in the project directory, the server will serve the index.html file from the Public folder as a static file. | ||
- If the Public folder exists and contains an index.html file, it will be displayed in the web browser. | ||
- If the Public folder does not exist or does not contain an index.html file, the server will display a default "Server Running" message. | ||
|
||
4. Use the provided routes to interact with the book management system. For example: | ||
|
||
- To view all books: GET /api/v1/books | ||
- To add a new book: POST /api/v1/books | ||
- To add a comment: POST /api/v1/books/:id/comments | ||
- To like a book: POST //api/v1books/:id/likes | ||
* *Replace :id with the actual ID of the book. | ||
|
||
Note: Make sure to set up the database configuration in the .env file before starting the server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Client Folder for the MI LIBRO APP |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Module for managing admin data in the database. | ||
* | ||
* @project : MI LIBRO | ||
* @version : 1.0.1 | ||
* @link : https://github.com/Ajayos/MI_LIBRO | ||
* @authors : Ajay, Akarsh, Abhinas, Saran, Yasir | ||
* @created : 2023-05-17 10:19:06 | ||
* @modified : 2023-05-17 12:06:25 | ||
* @editor : Ajayos | ||
* @file : Admin.js | ||
* @path : Models/Admin.js | ||
* | ||
* Description : This module exports a Mongoose model for managing admin data in the database. It defines an admin schema | ||
* with fields such as username and password. The Admin model allows adding, updating, or deleting admin data from the database. | ||
* | ||
* GitHub Repository: https://github.com/Ajayos/MI_LIBRO | ||
* | ||
* All rights reserved. (C) 2023 Ajayos and co-authors (Akarsh, Abhinas, Saran, Yasir) | ||
*/ | ||
|
||
// Import the mongoose package | ||
const mongoose = require('mongoose'); | ||
|
||
/** | ||
* Admin schema for managing admin data. | ||
*/ | ||
const adminSchema = new mongoose.Schema({ | ||
// Define the 'username' field with type String and it is required and should be unique | ||
username: { | ||
type: String, | ||
required: true, | ||
unique: true, | ||
}, | ||
// Define the 'password' field with type String and it is required | ||
password: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
|
||
/** | ||
* Create an Admin model using the admin schema. | ||
* | ||
* @param {String} username - The username of the admin. (required) | ||
* @param {String} password - The password of the admin. (required) | ||
* @returns {Model} The Admin model. | ||
*/ | ||
const Admin = mongoose.model('Admin', adminSchema); | ||
|
||
module.exports = Admin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* Module for managing book data in the database. | ||
* | ||
* @project : MI LIBRO | ||
* @version : 1.0.1 | ||
* @link : https://github.com/Ajayos/MI_LIBRO | ||
* @authors : Ajay, Akarsh, Abhinas, Saran, Yasir | ||
* @created : 2023-05-17 11:12:02 | ||
* @modified : 2023-05-17 22:19:14 | ||
* @editor : Ajayos | ||
* @file : Books.js | ||
* @path : Models/Books.js | ||
* | ||
* Description: This module exports a Mongoose model for managing book data in the database. It defines a book schema | ||
* with fields such as title, author, genre, publication date, description, status, rented by, buy info, likes, and comments. | ||
* The Book model allows adding, updating, or deleting book data from the database. | ||
* | ||
* GitHub Repository: https://github.com/Ajayos/MI_LIBRO | ||
* | ||
* All rights reserved. (C) 2023 Ajayos and co-authors (Akarsh, Abhinas, Saran, Yasir) | ||
*/ | ||
|
||
const mongoose = require('mongoose'); | ||
|
||
/** | ||
* Book schema for managing book data. | ||
*/ | ||
const bookSchema = new mongoose.Schema({ | ||
// Define the 'title' field with type String and it is required | ||
title: { | ||
type: String, | ||
required: true, | ||
}, | ||
// Define the 'author' field with type String and it is required | ||
author: { | ||
type: String, | ||
required: true, | ||
}, | ||
// Define the 'genre' field with type String and it is required | ||
genre: { | ||
type: String, | ||
required: true, | ||
}, | ||
// Define the 'publicationDate' field with type Date and it is required | ||
publicationDate: { | ||
type: Date, | ||
required: true, | ||
}, | ||
// Define the 'description' field with type String and it is required | ||
description: { | ||
type: String, | ||
required: true, | ||
}, | ||
// Define the 'status' field with type String, it has enum values 'Available', 'Rented', 'Sold', and default value 'Available' | ||
status: { | ||
type: String, | ||
enum: ['Available', 'Rented', 'Sold'], | ||
default: 'Available', | ||
}, | ||
// Define the 'rentedBy' field with type String and default value null | ||
rentedBy: { | ||
type: String, | ||
default: null, | ||
}, | ||
// Define the 'buyInfo' field as an embedded document with 'buyer', 'purchaseDate', and 'returnDate' fields | ||
buyInfo: { | ||
buyer: { | ||
type: String, | ||
default: null, | ||
}, | ||
purchaseDate: { | ||
type: Date, | ||
default: null, | ||
}, | ||
returnDate: { | ||
type: Date, | ||
default: null, | ||
}, | ||
}, | ||
// Define the 'likes' field as an array of objects referencing the 'User' model | ||
likes: [ | ||
{ | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User', | ||
}, | ||
}, | ||
], | ||
// Define the 'comments' field as an array of objects with 'user' and 'comment' fields | ||
comments: [ | ||
{ | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User', | ||
}, | ||
comment: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
], | ||
}); | ||
|
||
/** | ||
* Create a Book model using the book schema. | ||
* | ||
* @param {String} title - The title of the book. (required) | ||
* @param {String} author - The author of the book. (required) | ||
* @param {String} genre - The genre of the book. (required) | ||
* @param {Date} publicationDate - The publication date of the book. (required) | ||
* @param {String} description - The description of the book. (required) | ||
* @returns {Model} The Book model. | ||
*/ | ||
const Book = mongoose.model('Book', bookSchema); | ||
|
||
module.exports = Book; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Module for connecting to the MongoDB database using Mongoose. | ||
* | ||
* @project : MI LIBRO | ||
* @version : 1.0.1 | ||
* @link : https://github.com/Ajayos/MI_LIBRO | ||
* @authors : Ajay, Akarsh, Abhinas, Saran, Yasir | ||
* @created : 2023-05-17 10:11:19 | ||
* @modified : 2023-05-17 10:14:10 | ||
* @editor : Ajayos | ||
* @file : Database.js | ||
* @path : Models/Database.js | ||
* | ||
* Description: This module exports a function to connect to the MongoDB database using Mongoose. | ||
* | ||
* GitHub Repository: https://github.com/Ajayos/MI_LIBRO | ||
* | ||
* All rights reserved. (C) 2023 Ajayos and co-authors (Akarsh, Abhinas, Saran, Yasir) | ||
*/ | ||
|
||
// Import the necessary dependencies | ||
const mongoose = require("mongoose"); | ||
const nodelog = require('@ajayos/nodelog'); | ||
const colors = require("colors"); | ||
|
||
/** | ||
* Define a function to connect to the MongoDB database. | ||
* | ||
* @param {string} url - The MongoDB URL with username and password. (required) | ||
*/ | ||
const connectDB = async (url) => { | ||
// Exit the process with a non-zero status code if the URL is not provided | ||
if (!url) return process.exit(); | ||
|
||
try { | ||
// Use Mongoose to connect to the database with the provided URL | ||
const conn = await mongoose.connect(url, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
|
||
// Log a message indicating that the connection was successful | ||
nodelog.log(`MongoDB Connected`.cyan.underline); | ||
} catch (error) { | ||
// Log an error message if the connection failed | ||
nodelog.log(`Error: ${error.message}`.red.bold); | ||
// Exit the process with a non-zero status code | ||
process.exit(); | ||
} | ||
}; | ||
|
||
// Export the connectDB function | ||
module.exports = connectDB; |
Oops, something went wrong.