← 返回文章

后端——内容项目详细设计

内容项目详细设计,包含博客中各项信息的结构关系,pb文件以及数据库中的各项结构。

需求

我的博客不需要人评论。

完成博客、日记、书籍、简历等内容的增删改查,并提供相应的 CRUD API。

  • 对于博客内容,添加用户信息。
  • 支持对日记、博客、书籍、简历的 CRUD。
  • 等…

博客定义

博客内容分为文章主体、标签信息、分类信息、用户信息。

其博客的各项结构如上图所示。


同时,该项目中存储了用户信息,因此,管理员界面登录也需要通过内容项目来查询用户,进而抉择是否发送token,之后管理员界面的所有操作都需要带上 token 字段才能访问。

\

pb结构

博客中各项信息的pb结构如下:

message Category {
  // 类目编号
  uint64 id = 1;
  // 父类目编号
  uint64 parent_id = 2;
  // 类目级别
  int32 level = 3;
  // 类目名称
  string name = 4;
  // 创建时间, 系统自动生成.
  google.protobuf.Timestamp created_at = 8;
  // 修改时间, 系统自动生成.
  google.protobuf.Timestamp updated_at = 9;
}

message Post {
  // 商品的状态枚举
  enum Status {
    // 不限制,只是用来筛选状态用
    STATUS_UNLIMITED = 0;
    // 开放
    STATUS_OPEN = 1;
    // 关闭
    STATUS_CLOSE = 2;
    // 占位符,用于判断最大值,这个值会随时间改变
    STATUS_NONE = 8;
  }
  // 博客编号
  uint64 id = 1;
  // 博客标题
  string title = 2;
  // 博客内容
  string body = 3;
  // 博客内容摘要
  string excerpt = 4;
  // 博客内容观看人数,系统自动增加
  uint32 views = 5;
  // 博客内容喜欢人数
  uint32 likes = 6;
  // 博客封面
  string cover_url = 7;
  // 博客内容抬头图
  string title_url = 8;
  // 博客状态
  Status status = 9;
  // 类目编号
  uint64 category_id = 10;
  // 标签编号列表
  repeated uint64 tag_ids = 11;
  // 用户编号
  uint64 author_id = 12;
  // 创建时间, 系统自动生成.
  google.protobuf.Timestamp created_at = 18;
  // 修改时间, 系统自动生成.
  google.protobuf.Timestamp updated_at = 19;
}

message Tag {
 // 标签编号
  uint64 id = 1;
  // 标签名
  string name = 2;
  // 创建时间, 系统自动生成.
  // [EN] Creation time, automatically generated by system.
  google.protobuf.Timestamp created_at = 20;
  // 修改时间, 系统自动生成.
  // [EN] Updated time, automatically generated by system.
  google.protobuf.Timestamp updated_at = 21;
}

message User {
  // 用户的状态枚举
  enum Status {
    // 不限制,只是用来筛选状态用
    STATUS_UNLIMITED = 0;
    // 普通用户
    STATUS_COMMON = 1;
    // 超级管理员
    STATUS_SUPER = 2;
    // 占位符,用于判断最大值,这个值会随时间改变
    STATUS_NONE = 8;
  }
  // 用户信息编号
  uint64 id = 1;
  // 密码
  string password = 2;
  // 用户状态
  Status status = 3;
  // 用户名
  string username = 4;
  // 邮箱
  string email = 5;
  // 上次登录时间
  google.protobuf.Timestamp last_login = 19;
  // 创建时间, 系统自动生成.
  // [EN] Creation time, automatically generated by system.
  google.protobuf.Timestamp created_at = 20;
}

\