Sistem web pentru rezervarea de birouri și săli de ședință cu flux de aprobare administrativă. Stack: FastAPI + Vue.js 3 + SQLite + TypeScript Features implementate: - Autentificare JWT + Self-registration cu email verification - CRUD Spații, Utilizatori, Settings (Admin) - Calendar interactiv (FullCalendar) cu drag-and-drop - Creare rezervări cu validare (durată, program, overlap, max/zi) - Rezervări recurente (săptămânal) - Admin: aprobare/respingere/anulare cereri - Admin: creare directă rezervări (bypass approval) - Admin: editare orice rezervare - User: editare/anulare rezervări proprii - Notificări in-app (bell icon + dropdown) - Notificări email (async SMTP cu BackgroundTasks) - Jurnal acțiuni administrative (audit log) - Rapoarte avansate (utilizare, top users, approval rate) - Șabloane rezervări (booking templates) - Atașamente fișiere (upload/download) - Conflict warnings (verificare disponibilitate real-time) - Integrare Google Calendar (OAuth2) - Suport timezone (UTC storage + user preference) - 225+ teste backend Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
"""Seed database with initial data."""
|
|
from app.core.security import get_password_hash
|
|
from app.db.session import Base, SessionLocal, engine
|
|
from app.models.settings import Settings
|
|
from app.models.user import User
|
|
|
|
|
|
def seed_database() -> None:
|
|
"""Create initial users for testing."""
|
|
# Create tables
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
db = SessionLocal()
|
|
try:
|
|
# Check if users already exist
|
|
existing_admin = db.query(User).filter(User.email == "admin@example.com").first()
|
|
if existing_admin:
|
|
print("Database already seeded. Skipping...")
|
|
return
|
|
|
|
# Create admin user
|
|
admin = User(
|
|
email="admin@example.com",
|
|
full_name="Admin User",
|
|
hashed_password=get_password_hash("adminpassword"),
|
|
role="admin",
|
|
organization="Management",
|
|
is_active=True,
|
|
)
|
|
db.add(admin)
|
|
|
|
# Create regular user
|
|
user = User(
|
|
email="user@example.com",
|
|
full_name="Regular User",
|
|
hashed_password=get_password_hash("userpassword"),
|
|
role="user",
|
|
organization="Engineering",
|
|
is_active=True,
|
|
)
|
|
db.add(user)
|
|
|
|
# Create default settings if not exist
|
|
existing_settings = db.query(Settings).filter(Settings.id == 1).first()
|
|
if not existing_settings:
|
|
default_settings = Settings(
|
|
id=1,
|
|
min_duration_minutes=30,
|
|
max_duration_minutes=480, # 8 hours
|
|
working_hours_start=8, # 8 AM
|
|
working_hours_end=20, # 8 PM
|
|
max_bookings_per_day_per_user=3,
|
|
min_hours_before_cancel=2,
|
|
)
|
|
db.add(default_settings)
|
|
|
|
db.commit()
|
|
print("✓ Database seeded successfully!")
|
|
print("Admin: admin@example.com / adminpassword")
|
|
print("User: user@example.com / userpassword")
|
|
except Exception as e:
|
|
print(f"Error seeding database: {e}")
|
|
db.rollback()
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
seed_database()
|