mirror of
https://github.com/OHV-IT/collabrix.git
synced 2025-12-15 16:48:36 +01:00
- Complete chat application similar to Microsoft Teams - Code snippet library with syntax highlighting - Real-time messaging with WebSockets - File upload with Office integration - Department-based permissions - Dark/Light theme support - Production deployment with SSL/Reverse Proxy - Docker containerization - PostgreSQL database with SQLModel ORM
212 lines
7.1 KiB
Python
212 lines
7.1 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Script to create demo data for Team Chat application
|
||
"""
|
||
import requests
|
||
import sys
|
||
|
||
BASE_URL = "http://localhost:8000"
|
||
|
||
def create_demo_data():
|
||
print("🚀 Creating demo data for Team Chat...")
|
||
|
||
# 1. Register users
|
||
print("\n1️⃣ Registering users...")
|
||
users = [
|
||
{"username": "alice", "email": "alice@example.com", "password": "pass123", "full_name": "Alice Smith"},
|
||
{"username": "bob", "email": "bob@example.com", "password": "pass123", "full_name": "Bob Jones"},
|
||
{"username": "charlie", "email": "charlie@example.com", "password": "pass123", "full_name": "Charlie Brown"},
|
||
]
|
||
|
||
for user in users:
|
||
try:
|
||
response = requests.post(f"{BASE_URL}/auth/register", json=user)
|
||
if response.status_code == 201:
|
||
print(f" ✅ Created user: {user['username']}")
|
||
else:
|
||
print(f" ⚠️ User {user['username']} already exists")
|
||
except Exception as e:
|
||
print(f" ❌ Error creating user {user['username']}: {e}")
|
||
|
||
# 2. Login as alice
|
||
print("\n2️⃣ Logging in as alice...")
|
||
try:
|
||
response = requests.post(
|
||
f"{BASE_URL}/auth/login",
|
||
json={"username": "alice", "password": "pass123"}
|
||
)
|
||
token = response.json()["access_token"]
|
||
headers = {"Authorization": f"Bearer {token}"}
|
||
print(" ✅ Logged in successfully")
|
||
except Exception as e:
|
||
print(f" ❌ Login failed: {e}")
|
||
return
|
||
|
||
# 3. Create departments
|
||
print("\n3️⃣ Creating departments...")
|
||
departments = [
|
||
{"name": "Engineering", "description": "Engineering Team"},
|
||
{"name": "Marketing", "description": "Marketing Team"},
|
||
{"name": "HR", "description": "Human Resources"},
|
||
]
|
||
|
||
dept_ids = []
|
||
for dept in departments:
|
||
try:
|
||
response = requests.post(f"{BASE_URL}/departments/", json=dept, headers=headers)
|
||
if response.status_code == 201:
|
||
dept_id = response.json()["id"]
|
||
dept_ids.append(dept_id)
|
||
print(f" ✅ Created department: {dept['name']} (ID: {dept_id})")
|
||
else:
|
||
print(f" ⚠️ Department {dept['name']} might already exist")
|
||
except Exception as e:
|
||
print(f" ❌ Error creating department {dept['name']}: {e}")
|
||
|
||
# 4. Add users to departments
|
||
print("\n4️⃣ Adding users to departments...")
|
||
# Alice (user_id 1) → Engineering (dept 1)
|
||
# Bob (user_id 2) → Engineering (dept 1)
|
||
# Charlie (user_id 3) → Marketing (dept 2)
|
||
|
||
user_dept_assignments = [
|
||
(1, 1), # Alice → Engineering
|
||
(2, 1), # Bob → Engineering
|
||
(3, 2), # Charlie → Marketing
|
||
]
|
||
|
||
for user_id, dept_id in user_dept_assignments:
|
||
try:
|
||
response = requests.post(
|
||
f"{BASE_URL}/departments/{dept_id}/users/{user_id}",
|
||
headers=headers
|
||
)
|
||
if response.status_code == 200:
|
||
print(f" ✅ Added user {user_id} to department {dept_id}")
|
||
except Exception as e:
|
||
print(f" ⚠️ Error assigning user {user_id} to dept {dept_id}: {e}")
|
||
|
||
# 5. Create channels
|
||
print("\n5️⃣ Creating channels...")
|
||
channels = [
|
||
{"name": "general", "description": "General discussion", "department_id": 1},
|
||
{"name": "tech-talk", "description": "Technical discussions", "department_id": 1},
|
||
{"name": "campaigns", "description": "Marketing campaigns", "department_id": 2},
|
||
]
|
||
|
||
for channel in channels:
|
||
try:
|
||
response = requests.post(f"{BASE_URL}/channels/", json=channel, headers=headers)
|
||
if response.status_code == 201:
|
||
print(f" ✅ Created channel: {channel['name']}")
|
||
except Exception as e:
|
||
print(f" ❌ Error creating channel {channel['name']}: {e}")
|
||
|
||
# 6. Create messages
|
||
print("\n6️⃣ Creating sample messages...")
|
||
messages = [
|
||
{"content": "Welcome to Team Chat! 👋", "channel_id": 1},
|
||
{"content": "This is our general discussion channel.", "channel_id": 1},
|
||
{"content": "Feel free to share ideas and collaborate!", "channel_id": 1},
|
||
]
|
||
|
||
for msg in messages:
|
||
try:
|
||
response = requests.post(f"{BASE_URL}/messages/", json=msg, headers=headers)
|
||
if response.status_code == 201:
|
||
print(f" ✅ Created message")
|
||
except Exception as e:
|
||
print(f" ⚠️ Error creating message: {e}")
|
||
|
||
# 7. Create snippets
|
||
print("\n7️⃣ Creating code snippets...")
|
||
snippets = [
|
||
{
|
||
"title": "FastAPI Hello World",
|
||
"language": "python",
|
||
"content": """from fastapi import FastAPI
|
||
|
||
app = FastAPI()
|
||
|
||
@app.get("/")
|
||
def read_root():
|
||
return {"Hello": "World"}""",
|
||
"tags": "fastapi, python, api",
|
||
"visibility": "organization"
|
||
},
|
||
{
|
||
"title": "PostgreSQL Connection",
|
||
"language": "python",
|
||
"content": """import psycopg2
|
||
|
||
conn = psycopg2.connect(
|
||
host="localhost",
|
||
database="mydb",
|
||
user="user",
|
||
password="password"
|
||
)""",
|
||
"tags": "postgresql, database, python",
|
||
"visibility": "organization"
|
||
},
|
||
{
|
||
"title": "React useState Hook",
|
||
"language": "javascript",
|
||
"content": """import React, { useState } from 'react';
|
||
|
||
function Counter() {
|
||
const [count, setCount] = useState(0);
|
||
|
||
return (
|
||
<div>
|
||
<p>Count: {count}</p>
|
||
<button onClick={() => setCount(count + 1)}>
|
||
Increment
|
||
</button>
|
||
</div>
|
||
);
|
||
}""",
|
||
"tags": "react, javascript, hooks",
|
||
"visibility": "organization"
|
||
},
|
||
{
|
||
"title": "SQL Select with Join",
|
||
"language": "sql",
|
||
"content": """SELECT
|
||
u.username,
|
||
d.name as department_name,
|
||
c.name as channel_name
|
||
FROM users u
|
||
JOIN user_department ud ON u.id = ud.user_id
|
||
JOIN departments d ON ud.department_id = d.id
|
||
JOIN channels c ON c.department_id = d.id
|
||
WHERE u.is_active = true;""",
|
||
"tags": "sql, join, query",
|
||
"visibility": "department",
|
||
"department_id": 1
|
||
}
|
||
]
|
||
|
||
for snippet in snippets:
|
||
try:
|
||
response = requests.post(f"{BASE_URL}/snippets/", json=snippet, headers=headers)
|
||
if response.status_code == 201:
|
||
print(f" ✅ Created snippet: {snippet['title']}")
|
||
except Exception as e:
|
||
print(f" ❌ Error creating snippet {snippet['title']}: {e}")
|
||
|
||
print("\n✅ Demo data creation complete!")
|
||
print("\n📝 Login credentials:")
|
||
print(" Username: alice, bob, or charlie")
|
||
print(" Password: pass123")
|
||
print("\n🌐 Access the app at: http://localhost:5173")
|
||
|
||
if __name__ == "__main__":
|
||
try:
|
||
create_demo_data()
|
||
except KeyboardInterrupt:
|
||
print("\n\n⚠️ Aborted by user")
|
||
sys.exit(1)
|
||
except Exception as e:
|
||
print(f"\n\n❌ Fatal error: {e}")
|
||
sys.exit(1)
|