初始化仓库:more_agent
Go to file
root 32d28dcae2 生成代码工程 2026-05-12 13:03:18 +08:00
app 生成代码工程 2026-05-12 13:03:18 +08:00
tests 生成代码工程 2026-05-12 13:03:18 +08:00
.gitignore Initial commit: 项目初始化 2026-05-12 12:57:40 +08:00
README.md 生成代码工程 2026-05-12 13:03:18 +08:00
events.ndjson 生成代码工程 2026-05-12 13:03:18 +08:00
generation.json 生成代码工程 2026-05-12 13:03:18 +08:00
requirements.txt 生成代码工程 2026-05-12 13:03:18 +08:00

README.md

User Management Service - 用户管理服务

基于 FastAPI 构建的用户管理单体服务,采用内存假数据存储,无需外部依赖。

功能特性

  • 用户注册POST /api/users
  • 获取用户列表GET /api/users
  • 获取单个用户GET /api/users/{user_id}
  • 更新用户信息PUT /api/users/{user_id}
  • 删除用户DELETE /api/users/{user_id}
  • 用户登录验证POST /api/users/login
  • 健康检查GET /health

项目结构

project-files/
├── requirements.txt
├── README.md
├── app/
│   ├── __init__.py
│   ├── main.py          # FastAPI 应用入口及路由
│   ├── models.py        # 数据模型定义
│   ├── services.py      # 业务逻辑层
│   └── database.py      # 内存数据库(假数据)
└── tests/
    └── test_basic.py    # 基础单元测试

环境要求

  • Python >= 3.11

安装依赖

cd codegen-runs/codegen_216c32ee7c414070891e6bd4259621a9
pip install -r requirements.txt

启动服务

方式一:直接启动

python app/main.py

方式二:使用 uvicorn

uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

服务启动后访问:

运行测试

cd codegen-runs/codegen_216c32ee7c414070891e6bd4259621a9
pytest -v

API 接口说明

健康检查

GET /health

用户注册

POST /api/users
Content-Type: application/json

{
    "username": "alice",
    "email": "alice@example.com",
    "password": "secret123"
}

获取用户列表

GET /api/users?skip=0&limit=10

获取单个用户

GET /api/users/{user_id}

更新用户

PUT /api/users/{user_id}
Content-Type: application/json

{
    "username": "alice_new",
    "email": "alice_new@example.com"
}

删除用户

DELETE /api/users/{user_id}

用户登录

POST /api/users/login
Content-Type: application/json

{
    "username": "alice",
    "password": "secret123"
}