5 Star 2 Fork 0

LuoRongZhou / UCAS-BBS-Server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
README.md 4.80 KB
一键复制 编辑 原始数据 按行查看 历史
LuoRongZhou 提交于 2020-12-14 13:22 . 完善API接口文档

UCAS-BBS 服务端


参考文档

创建用户User示例

  • 使用命令行rails generate scaffold api/User name:string password:string sex:string age:integer department:string avatar_url:string token:string admin:boolean创建用户User资源,这一行动将会把一系列(Model、Controller、routes)资源全部都创建。
  • seeds.rb文件中填写初始的测试用户数据。
  • 执行命令行rails db:migrate迁移数据库,执行命令行rails db:seed将初始数据存入数据库中。
  • 使用命令行sqlite3 db/development.sqlite3可以进入本项目的数据库,可以进行SQL语句的操作。

创建本项目的统一JSON数据返回类Response以及全局状态枚举Status,在helps文件夹中

  • Response包括了状态码code、状态描述message、数据data。
  • Status包括了状态码code、状态描述message。

所有Controller的所有方法都是返回统一JSON数据

  • 实现了Api::UsersController的index和show方法,供参考。

测k试

  • 添加了cheng.

注释了数据库字段,见schema.rb文件

添加了API接口文档,在doc文件夹,还未完成

数据库字段注释


# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_11_27_094203) do

  # 帖子表
  create_table "api_articles", force: :cascade do |t|
    t.integer "author_id" # 作者id
    t.string "title"  # 标题
    t.text "content"  # 内容
    t.string "tags" # 标签
    t.integer "comment_num" # 评论数
    t.integer "like_num"  # 点赞数
    t.integer "view_num"  # 浏览数
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  # 一级评论表
  create_table "api_comment_to_articles", force: :cascade do |t|
    t.integer "article_id"  # 被评论帖子id
    t.integer "commentator_id"  # 评论人id
    t.text "content"  # 内容
    t.integer "child_num" # 二级评论数量
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  # 二级评论表
  create_table "api_comment_to_comments", force: :cascade do |t|
    t.integer "father_id" # 所属一级评论id
    t.integer "commentator_id"  # 评论人id
    t.integer "ated_id" # 被评论人(被@的人)id
    t.text "content"  # 内容
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  # 通知记录
  create_table "api_information", force: :cascade do |t|
    t.integer "notifier"  # 发起通知者id
    t.integer "reciever_id" # 收到通知人id
    t.integer "entity_id" # 被通知实体id(例如帖子被评论,被通知实体id就是帖子id)
    t.integer "type"  # 通知类型(帖子被评论1、帖子被点赞2、一级评论被评论3、二级评论被评论4)
    t.boolean "status"  # 通知状态(未读false、已读true)
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  # 点赞记录
  create_table "api_like_records", force: :cascade do |t|
    t.integer "article_id"  # 帖子id
    t.integer "creator_id"  # 点赞人id
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

  # 用户
  create_table "api_users", force: :cascade do |t|
    t.string "name" # 昵称
    t.string "password" # 密码(前端md5加密后的密文)
    t.string "sex"  # 性别(男、女、秘密)
    t.string "department" # 部门
    t.string "avatar_url" # 头像的链接(云端存储头像图片)
    t.string "token"  # token(一个复杂的独一无二的字符串,只有http请求携带了正确的token,即视为登录状态)
    t.boolean "admin" # 管理员(是true、否false)
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

end
Ruby
1
https://gitee.com/pttq/ucas-bbs-server.git
git@gitee.com:pttq/ucas-bbs-server.git
pttq
ucas-bbs-server
UCAS-BBS-Server
master

搜索帮助