mirror of
https://github.com/vee1e/bulk-questionnaire-upload.git
synced 2026-09-01 09:50:06 +00:00
feat: got mongodb working
This commit is contained in:
parent
d0179b0b56
commit
9af03f3f67
12 changed files with 618 additions and 51 deletions
152
README.md
152
README.md
|
|
@ -1,13 +1,14 @@
|
|||
# Bulk questionnaire Upload
|
||||
# Bulk Questionnaire Upload
|
||||
|
||||
A web application for uploading and parsing Excel-based questionnaires in XLSForm-like format.
|
||||
A web application for uploading and parsing Excel-based questionnaires in XLSForm-like format with MongoDB integration.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
│
|
||||
├── frontend/
|
||||
└── backend/
|
||||
├── frontend/ # Angular frontend application
|
||||
├── backend/ # FastAPI backend with MongoDB
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Stack
|
||||
|
|
@ -21,23 +22,140 @@ A web application for uploading and parsing Excel-based questionnaires in XLSFor
|
|||
### Backend
|
||||
|
||||
- Python FastAPI
|
||||
- MongoDB for data persistence
|
||||
- `openpyxl`/`pandas` for Excel parsing
|
||||
- `motor`/`pymongo` for MongoDB integration
|
||||
|
||||
## Setup Instructions
|
||||
## Prerequisites
|
||||
|
||||
### Frontend Setup
|
||||
- Python 3.8+ (recommend using a virtual environment)
|
||||
- Node.js 16+ and npm
|
||||
- MongoDB (local or cloud instance)
|
||||
- pip
|
||||
|
||||
1. Navigate to the `frontend/` directory
|
||||
2. Run `npm install`
|
||||
3. Run `ng serve` for development server
|
||||
## Installation & Setup
|
||||
|
||||
### Backend Setup
|
||||
### 1. Install MongoDB (Artix/Arch Linux)
|
||||
|
||||
1. Navigate to the `backend/` directory
|
||||
2. Create virtual environment: `python -m venv .env`
|
||||
3. Activate virtual environment:
|
||||
- Windows: `.\.env\Scripts\activate`
|
||||
- Unix: `source .env/bin/activate`
|
||||
4. Install dependencies: `pip install -r requirements.txt`
|
||||
5. Run development server: `uvicorn main:app --reload`
|
||||
**Start MongoDB service:**
|
||||
```bash
|
||||
sudo rc-service mongodb start # OpenRC (Artix default)
|
||||
# or
|
||||
sudo systemctl start mongodb # If using systemd
|
||||
mongosh --eval "db.runCommand('ping')"
|
||||
# Should output: { ok: 1 }
|
||||
```
|
||||
|
||||
### 2. Backend Setup
|
||||
|
||||
1. **Navigate to the backend directory:**
|
||||
```bash
|
||||
cd backend/
|
||||
```
|
||||
|
||||
2. **Create and activate virtual environment:**
|
||||
```bash
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
3. **Install Python dependencies:**
|
||||
```bash
|
||||
pip install --upgrade pip
|
||||
pip install --break-system-packages -r requirements.txt
|
||||
```
|
||||
> If you see an "externally-managed-environment" error, use the `--break-system-packages` flag as above.
|
||||
|
||||
4. **Create environment configuration:**
|
||||
Create a `.env` file in the `backend/` directory:
|
||||
```
|
||||
MONGODB_URL=mongodb://localhost:27017
|
||||
DATABASE_NAME=mform_bulk_upload
|
||||
API_HOST=0.0.0.0
|
||||
API_PORT=8000
|
||||
```
|
||||
|
||||
5. **Start the FastAPI server:**
|
||||
```bash
|
||||
uvicorn main:app --reload
|
||||
```
|
||||
|
||||
The API will be available at [http://localhost:8000](http://localhost:8000)
|
||||
|
||||
### 3. Frontend Setup
|
||||
|
||||
1. **Navigate to the frontend directory:**
|
||||
```bash
|
||||
cd frontend/
|
||||
```
|
||||
|
||||
2. **Install Node.js dependencies:**
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
3. **Start the development server:**
|
||||
```bash
|
||||
ng serve
|
||||
```
|
||||
|
||||
The frontend will be available at [http://localhost:4200](http://localhost:4200)
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### File Validation
|
||||
- **POST** `/api/validate`
|
||||
Validate Excel file structure.
|
||||
Returns detailed validation information including sheet status, metadata, and counts.
|
||||
|
||||
### File Upload
|
||||
- **POST** `/api/upload`
|
||||
Parse and store Excel file in MongoDB.
|
||||
Saves form metadata, questions, and answer options to separate collections.
|
||||
|
||||
### Forms Management
|
||||
- **GET** `/api/forms`
|
||||
Get all forms from database.
|
||||
- **GET** `/api/forms/{form_id}`
|
||||
Get specific form with questions and options.
|
||||
- **DELETE** `/api/forms/{form_id}`
|
||||
Delete form and all related data.
|
||||
|
||||
## Database Schema
|
||||
|
||||
### Forms Collection
|
||||
```json
|
||||
{
|
||||
"_id": "ObjectId",
|
||||
"title": "string",
|
||||
"language": "string",
|
||||
"version": "string",
|
||||
"created_at": "ISO timestamp"
|
||||
}
|
||||
```
|
||||
|
||||
### Questions Collection
|
||||
```json
|
||||
{
|
||||
"_id": "ObjectId",
|
||||
"form_id": "string",
|
||||
"order": "number",
|
||||
"title": "string",
|
||||
"view_sequence": "number",
|
||||
"input_type": "number",
|
||||
"created_at": "ISO timestamp"
|
||||
}
|
||||
```
|
||||
|
||||
### Options Collection
|
||||
```json
|
||||
{
|
||||
"_id": "ObjectId",
|
||||
"form_id": "string",
|
||||
"order": "number",
|
||||
"option_id": "number",
|
||||
"label": "string",
|
||||
"created_at": "ISO timestamp"
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue