Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
backend/app/__pycache__/*
frontend/node_modules/*
backend/app/models/__pycache__/*
backend/app/schemas/__pycache__/*
backend/app/routers/__pycache__/*
Empty file added backend/app/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions backend/app/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import os

SQLALCHEMY_DATABASE_URL = "sqlite:///./test.db"

engine = create_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()

def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
107 changes: 107 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from app.routers import items, auth, users, laboratories, devices, reservations, experiments, attendances, maintenances, notifications, dashboard
from app.routers import lab_profiles, teachers, research_directions, research_achievements, lab_members, team_activities
from app.routers import servers, compute_tasks, usage_records, uploads
from app.database import engine, Base
from app.models.models import User
from app.database import SessionLocal
from app.utils.auth import get_password_hash

Base.metadata.create_all(bind=engine)

def init_db():
db = SessionLocal()
try:
admin = db.query(User).filter(User.username == "admin").first()
if not admin:
admin_user = User(
username="admin",
password=get_password_hash("admin123"),
name="管理员",
email="admin@example.com",
role="admin",
is_active=True
)
db.add(admin_user)
db.commit()
print("管理员账户已创建: admin / admin123")

teacher = db.query(User).filter(User.username == "teacher").first()
if not teacher:
teacher_user = User(
username="teacher",
password=get_password_hash("teacher123"),
name="张老师",
email="teacher@example.com",
role="teacher",
is_active=True
)
db.add(teacher_user)
db.commit()
print("教师账户已创建: teacher / teacher123")

student = db.query(User).filter(User.username == "student").first()
if not student:
student_user = User(
username="student",
password=get_password_hash("student123"),
name="李学生",
email="student@example.com",
role="student",
student_id="2024001",
major="计算机科学与技术",
grade="2024级",
advisor="张教授",
is_active=True
)
db.add(student_user)
db.commit()
print("学生账户已创建: student / student123")
finally:
db.close()

init_db()

app = FastAPI(title="研究生实验室管理系统", version="1.0.0")

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.include_router(auth.router, prefix="/api/auth", tags=["认证"])
app.include_router(users.router, prefix="/api/users", tags=["用户管理"])
app.include_router(laboratories.router, prefix="/api/laboratories", tags=["实验室管理"])
app.include_router(devices.router, prefix="/api/devices", tags=["设备管理"])
app.include_router(reservations.router, prefix="/api/reservations", tags=["预约管理"])
app.include_router(experiments.router, prefix="/api/experiments", tags=["实验记录"])
app.include_router(attendances.router, prefix="/api/attendances", tags=["考勤管理"])
app.include_router(maintenances.router, prefix="/api/maintenances", tags=["维护管理"])
app.include_router(notifications.router, prefix="/api/notifications", tags=["通知管理"])
app.include_router(dashboard.router, prefix="/api/dashboard", tags=["仪表板"])
app.include_router(items.router, prefix="/api", tags=["示例项目"])

app.include_router(lab_profiles.router, prefix="/api/lab-profiles", tags=["实验室简介"])
app.include_router(teachers.router, prefix="/api/teachers", tags=["教师信息"])
app.include_router(research_directions.router, prefix="/api/research-directions", tags=["研究方向"])
app.include_router(research_achievements.router, prefix="/api/research-achievements", tags=["研究成果"])
app.include_router(lab_members.router, prefix="/api/lab-members", tags=["实验室成员"])
app.include_router(team_activities.router, prefix="/api/team-activities", tags=["团建活动"])

app.include_router(servers.router, prefix="/api/servers", tags=["服务器管理"])
app.include_router(compute_tasks.router, prefix="/api/compute-tasks", tags=["计算任务"])
app.include_router(usage_records.router, prefix="/api/usage-records", tags=["使用记录"])
app.include_router(uploads.router, prefix="/api/upload", tags=["文件上传"])

@app.get("/")
def read_root():
return {"message": "欢迎使用研究生实验室管理系统", "version": "1.0.0"}

@app.get("/health")
def health_check():
return {"status": "healthy"}
Empty file added backend/app/models/__init__.py
Empty file.
Loading