Is the back-end repository for the lend out app
Lend it
is a web-based application that allows users to lend and borrow items from others in their community. Our app aims to promote sustainability and reduce waste by providing a platform for people to share items they may only need occasionally. Users can create a profile, search for items they need, and request to borrow them from other users. The app also includes tracking item availability.
The purpose of this backend repository is to provide the server-side logic and integration with Firebase services for our lendout app. This includes handling authentication and user management, storing and retrieving data from the Firebase Realtime Database, and implementing cloud functions for automated processes. By separating the backend logic from the frontend, we can improve scalability and maintainability of our app.
- where-is-my-stuff-backend
We list out these technologies that we may use to build the backend for for the app. This could include a programming languages, frameworks, libraries, and cloud services that you have utilized.
- JavaScript
- Firebase
- Node.js
- Firebase Admin SDK: a library for accessing Firebase services from server-side code
- Express.js: a web application framework for Node.js that simplifies server-side development
- CORS: a middleware for Express.js that enables cross-origin resource sharing
- Axios: a promise-based library for making HTTP requests from Node.js
- Node.js and npm installed on your local machine
- A Firebase project created with Realtime Database and Authentication enabled
- Firebase CLI installed globally:
npm install -g firebase-tools
After cloning the repository, navigate to the root directory of the project and install the required dependencies using npm:
npm install
To set up the Firebase project, you will need to create a service account and download the corresponding JSON
file. This file will be used to authenticate with the Firebase Admin SDK.
- Go to the Firebase console and select your project.
- Navigate to the "Settings" page and select the "Service accounts" tab.
- Click "Generate new private key" to create a new service account.
- Save the JSON file to the
src
directory of your project and name itserviceAccountKey.json.
To run the server locally, run the following command:
npm run dev
This will start the server on http://localhost:5000.
To connect to Firebase services from the backend, you will need to initialize the Firebase Admin SDK with the service account credentials. You can do this by adding the following code to the top of your server-side JavaScript files:
const admin = require('firebase-admin');
const serviceAccount = require('./serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: '<your-database-url>',
});
Replace <your-database-url>
with the URL for your Firebase Realtime Database. You can find this URL in the Firebase console under the "Realtime Database" tab.
By following these steps, you should be able to set up the backend locally and start developing for our back-end app.
For Lend IT
app back-end includes an API that can be used by the front-end, this should provide documentation on the endpoints, request and response formats, and any authentication or authorization requirements.
This endpoint allows a user to create an item with a name, description, lender, lend out date and reminder date.
Request.
POST '/items'
{
"name": "Laptop",
"description": "MacBook Pro 2022",
"To": "name of the borrower",
"On": "2023-04-05",
"Reminder": "2023-04-12"
}
Response.
{
"id": "123456",
"name": "Laptop",
"description": "MacBook Pro 2022",
"To": "name of the borrower",
"On": "2023-04-05",
"Reminder": "2023-04-12"
}
This endpoint allows a user to retrieve the details of an item by providing its ID.
Request.
GET '/items/{itemId}'
Response.
{
"id": "123456",
"name": "Laptop",
"description": "MacBook Pro 2022",
"To": "name of the borrower",
"On": "2023-04-05",
"Reminder": "2023-04-12"
}
This endpoint allows a user to update the details of an item by providing its ID.
Request.
PUT '/items/{itemId}'
{
"name": "Laptop",
"description": "MacBook Pro 2022",
"To": "name of the borrower",
"On": "2023-04-05",
"Reminder": "2023-04-12"
}
Response.
{
"id": "123456",
"description": "MacBook Pro 2022",
"To": "name of the borrower",
"On": "2023-04-05",
"Reminder": "2023-04-12"
}
This endpoint allows a user to delete an item by providing its ID.
Request.
DELETE '/items/{itemId}'
Response.
{
"message": "Item deleted successfully"
}
this endpoint allows a user to retrieve a list of items that are currently lent out.
Request.
GET '/lentoutitems'
Response.
[
{
"id": "123456",
"name": "Laptop",
"description": "MacBook Pro 2022",
"To": "Name of borrower",
"lendOutDate": "2023-04-05",
"reminderDate": "2023-04-13"
},
{
"id": "654321",
"name": "Camera",
"description": "Canon EOS R5",
"To": "Name of borrower",
"lendOutDate": "2023-04-03",
"reminderDate": "2023-04-10"
}
]
Note!
check the Summary to have more overview about API.
Summary Goes Here
GET '/reminder'
Request.
N/A
Response.
[
{
"id": "123",
"name": "Lawn Mower",
"description": "A powerful lawn mower for medium-sized lawns.",
"to": "Omer",
"returnDate": "2023-05-01",
"lentTo": "John Doe"
},
{
"id": "456",
"name": "Power Drill",
"description": "A cordless drill for all your DIY needs.",
"to": "David",
"returnDate": "2023-04-25",
"lentTo": "Jane Smith"
},
]
GET '/reminder/:id'
Returns the details of the specified item in the reminder list.
Request.
N/A
Response.
{
"id": "123",
"name": "Lawn Mower",
"description": "A powerful lawn mower for medium-sized lawns.",
"to": "Omer",
"returnDate": "2023-05-01",
"lentTo": "John Doe"
}
POST '/reminder'
Adds a new item to the reminder list.
Request.
{
"name": "Bicycle Pump",
"description": "A portable pump for inflating bicycle tires.",
"returnDate": "2023-04-30",
"lentTo": "Sarah Lee"
}
Response.
{
"id": "789",
"name": "Bicycle Pump",
"description": "A portable pump for inflating bicycle tires.",
"returnDate": "2023-04-30",
"lentTo": "Sarah Lee"
}
PUT '/reminder/:id'
Updates the details of the specified item in the reminder list.
Request.
{
"name": "Lawn Mower",
"description": "A powerful lawn mower for large lawns.",
"returnDate": "2023-05-01",
"lentTo": "John Smith"
}
Response.
{
"id": "123",
"name": "Lawn Mower",
"description": "A powerful lawn mower for large lawns.",
"returnDate": "2023-05-01",
"lentTo": "John Smith"
}
DELETE '/reminder/:id'
Removes the specified item from the reminder list.
Request.
N/A
Response.
N/A
All endpoints in the lend out API require Firebase authentication. You must include
a Firebase authentication token in the Authorization
header of each request.
To obtain a Firebase authentication token, send a request to the Firebase Authentication API with the user's email and password. The response will include an idToken field that you can use as the authentication token for the lend out API.
These are some general steps for deploying your back-end to Firebase Hosting:
- Create a Firebase account and a new Firebase project.
- Install Firebase CLI tool using the command
npm install -g firebase-tools
. - Authenticate your Firebase account using firebase login command.
- Initialize Firebase project in your backend repository using firebase init.
- Select the Firebase features you want to use (in this case, Cloud Firestore).
- Choose the Firebase project you created in step 1.
- Set the public directory to your backend project directory.
- Build your backend using
npm run build
command. - Deploy your backend using firebase deploy command.
After the deployment is complete, you can then connect your frontend to the Firebase backend using the Firebase API keys provided in our app Firebase project settings.