179 lines
4.1 KiB
Markdown
179 lines
4.1 KiB
Markdown
# DMRocket API
|
|
|
|
A Node.js/Express API for managing orders with MySQL database integration.
|
|
|
|
## Setup
|
|
|
|
### 1. Install Dependencies
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
### 2. Database Setup
|
|
Create your MySQL database and table:
|
|
|
|
```sql
|
|
CREATE DATABASE dmrocket;
|
|
USE dmrocket;
|
|
|
|
CREATE TABLE `Orders` (
|
|
`id` INT NOT NULL AUTO_INCREMENT,
|
|
`wallet` TEXT NOT NULL,
|
|
`mint` TEXT NOT NULL,
|
|
`amount` BIGINT NOT NULL DEFAULT '100',
|
|
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
`user_id` TEXT NOT NULL,
|
|
`pk` TEXT,
|
|
`order_data` JSON,
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE = InnoDB;
|
|
```
|
|
|
|
### 3. Environment Configuration
|
|
Create a `.env.local` file in the root directory with your database credentials:
|
|
|
|
```env
|
|
# Database Configuration
|
|
DB_HOST=localhost
|
|
DB_USER=root
|
|
DB_PASSWORD=your_password_here
|
|
DB_NAME=dmrocket
|
|
DB_PORT=3306
|
|
|
|
# Server Configuration
|
|
PORT=7111
|
|
NODE_ENV=development
|
|
```
|
|
|
|
### 4. Run the Application
|
|
```bash
|
|
# Development mode
|
|
npm run dev
|
|
|
|
# Production build
|
|
npm run build
|
|
npm start
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
All endpoints use GET requests for simplicity and ease of use.
|
|
|
|
### Orders API
|
|
|
|
#### Create Order
|
|
- **GET** `/api/v1/create_order`
|
|
- **Query Parameters:**
|
|
- `mint` (required) - Mint address
|
|
- `amount` (optional) - Order amount (default: 100)
|
|
- `user_id` (required) - User identifier
|
|
- `instagramAccount` (required) - Instagram account
|
|
- `targetAccounts` (required) - Target accounts
|
|
- `targetHashtags` (required) - Target hashtags
|
|
- `targetLocation` (required) - Target location
|
|
- `packageType` (required) - Package type (number)
|
|
- `customMessage` (required) - Custom message
|
|
- `email` (required) - Email address
|
|
|
|
**Note:** A new Solana wallet is automatically generated for each order, including the wallet address and private key.
|
|
|
|
**Example:**
|
|
```
|
|
GET /api/v1/create_order?mint=mint_address&amount=200&user_id=user123&instagramAccount=myaccount&targetAccounts=account1,account2&targetHashtags=#tag1,#tag2&targetLocation=New York&packageType=1&customMessage=Hello&email=user@example.com
|
|
```
|
|
|
|
#### Get All Orders
|
|
- **GET** `/api/v1/get_all_orders`
|
|
|
|
**Example:**
|
|
```
|
|
GET /api/v1/get_all_orders
|
|
```
|
|
|
|
#### Get Order by ID
|
|
- **GET** `/api/v1/get_order_by_id/:id`
|
|
|
|
**Example:**
|
|
```
|
|
GET /api/v1/get_order_by_id/1
|
|
```
|
|
|
|
#### Get Orders by User ID
|
|
- **GET** `/api/v1/get_orders_by_user/:userId`
|
|
|
|
**Example:**
|
|
```
|
|
GET /api/v1/get_orders_by_user/user123
|
|
```
|
|
|
|
#### Update Order
|
|
- **GET** `/api/v1/update_order/:id`
|
|
- **Query Parameters:** (any combination of fields)
|
|
- `wallet` (optional) - New wallet address
|
|
- `mint` (optional) - New mint address
|
|
- `amount` (optional) - New amount
|
|
- `user_id` (optional) - New user ID
|
|
- `pk` (optional) - New private key
|
|
- `instagramAccount` (optional) - New Instagram account
|
|
- `targetAccounts` (optional) - New target accounts
|
|
- `targetHashtags` (optional) - New target hashtags
|
|
- `targetLocation` (optional) - New target location
|
|
- `packageType` (optional) - New package type
|
|
- `customMessage` (optional) - New custom message
|
|
- `email` (optional) - New email address
|
|
|
|
**Example:**
|
|
```
|
|
GET /api/v1/update_order/1?amount=300&user_id=newuser456&packageType=2&customMessage=Updated message
|
|
```
|
|
|
|
#### Delete Order
|
|
- **GET** `/api/v1/delete_order/:id`
|
|
|
|
**Example:**
|
|
```
|
|
GET /api/v1/delete_order/1
|
|
```
|
|
|
|
### Health Check
|
|
- **GET** `/health` - Returns API status and database connection status
|
|
|
|
## Response Format
|
|
|
|
All API responses follow this format:
|
|
|
|
```json
|
|
{
|
|
"success": true,
|
|
"data": {...},
|
|
"count": 1
|
|
}
|
|
```
|
|
|
|
Error responses:
|
|
```json
|
|
{
|
|
"error": "Error message",
|
|
"message": "Detailed error description"
|
|
}
|
|
```
|
|
|
|
## Database Schema
|
|
|
|
| Field | Type | Description |
|
|
|-------|------|-------------|
|
|
| id | INT | Auto-increment primary key |
|
|
| wallet | TEXT | Wallet address (auto-generated) |
|
|
| mint | TEXT | Mint address |
|
|
| amount | BIGINT | Order amount (default: 100) |
|
|
| created_at | DATETIME | Timestamp (auto-generated) |
|
|
| user_id | TEXT | User identifier |
|
|
| pk | TEXT | Private key (auto-generated) |
|
|
| order_data | JSON | Order details (Instagram account, targets, etc.) |
|
|
|
|
## Development
|
|
|
|
- **TypeScript** for type safety
|
|
- **Express.js** for the web framework
|
|
- **MySQL2** for database operations
|
|
- **Dotenv** for environment variable management |