📜  圈子在线测验区域(1)

📅  最后修改于: 2023-12-03 15:23:05.877000             🧑  作者: Mango

圈子在线测验区域

导语

圈子在线测验区域是一个提供在线测验功能的平台。在这里,你可以创建自己的测验,并将其分享给其他用户。同时,你也可以参加其他用户创建的测验,测试自己的知识水平。

功能
  • 创建测验:用户可以创建自己的测验,并设置测验的题目和答案。
  • 参加测验:用户可以参加其他用户创建的测验,并提交自己的答案。
  • 查看结果:用户可以查看自己创建的测验和参加过的测验的结果,以及其他用户的测验结果。
技术栈
  • 前端:React、Ant Design
  • 后端:Node.js、Express、MySQL
开发者文档
目录结构
.
├── client          # 前端代码
│   ├── public      # 静态资源
│   │   ├── index.html
│   │   └── ...
│   ├── src         # 前端源码目录
│   │   ├── api     # API调用相关代码
│   │   ├── components  # React组件
│   │   ├── pages       # 页面组件
│   │   ├── styles      # 样式
│   │   └── index.js    # 前端入口文件
│   ├── package.json
│   └── ...
├── server          # 后端代码
│   ├── bin         # 启动脚本
│   ├── config      # 配置文件
│   ├── controllers # 路由处理函数
│   ├── models      # 数据库模型
│   ├── routes      # 路由配置
│   ├── app.js      # 后端入口文件
│   └── package.json
├── package.json
└── ...
启动开发环境
  1. 克隆代码仓库到本地:
git clone https://github.com/your-username/quiz-app.git
  1. 进入项目根目录,安装依赖:
cd quiz-app
npm install
  1. 启动前端开发服务器:
cd client
npm start
  1. 启动后端开发服务器:
cd server
npm start
API文档

获取测验列表

GET /api/quizzes
  • Query Params:

    • page {Number} 当前页数,默认为 1
    • limit {Number} 每页的数据条数,默认为 10
  • Response:

    • data {Array} 测验列表
      • _id {String} ID
      • title {String} 标题
      • description {String} 描述
      • createdAt {Date} 创建时间
      • updatedAt {Date} 更新时间
      • questions {Array} 问题列表
        • _id {String} ID
        • title {String} 标题
        • options {Array} 选项列表
          • _id {String} ID
          • title {String} 标题
        • answer {String} 答案

创建测验

POST /api/quizzes
  • Request Body:

    • title {String} 标题
    • description {String} 描述
    • questions {Array} 问题列表
      • title {String} 标题
      • options {Array} 选项列表
        • title {String} 标题
      • answer {String} 答案
  • Response:

    • data {Object} 创建的测验数据
      • _id {String} ID
      • title {String} 标题
      • description {String} 描述
      • createdAt {Date} 创建时间
      • updatedAt {Date} 更新时间
      • questions {Array} 问题列表
        • _id {String} ID
        • title {String} 标题
        • options {Array} 选项列表
          • _id {String} ID
          • title {String} 标题
        • answer {String} 答案

提交测验答案

POST /api/quizzes/:quizId/submit
  • Request Body:

    • answers {Array} 答案列表
      • questionId {String} 问题ID
      • answer {String} 答案
  • Response:

    • data {Object} 提交的测验答案数据
      • _id {String} ID
      • quiz {ObjectId} 对应测验ID
      • userId {ObjectId} 用户ID
      • answers {Array} 答案列表
        • question {ObjectId} 问题ID
        • answer {String} 答案
      • score {Number} 得分

以上API仅供参考,具体实现细节请查看代码。