一、项目概述:

二需求分析

1 用户系统

用户可以注册账户、登录、修改账户信息、修改密码、注销账户

  1. 用户注册
    必须填写 accountId,password,email,phone,username
    可选填写:avatar
    自动填写:createTime,follow_count,follower_count,isDelete
    封装为 User 传输
    返回注册成功 Result(200,”success”) 不需要返回data
    controller:
    url:/users Post
    返回值 Result,接收参数@RequestBody User
    service:
    accountId,password,email,phone 判空
    accountId,email,phone 的 Unique 检查
    不需要返回值,接收参数 User
    mmaper:
    接收参数 User,不需要返回值
    Insert

  2. 用户登录
    必须填写密码
    accountId,email,phone 三选一填写
    封装为 loginDTO 传输
    返回登录成功 Result(200,”success”,data) data 含 token 给前端校验, accountId, username, avatar, email, phone 给前端展示
    controller
    url:/login Post
    返回值 Result,接收参数 Result(ErrorCodeEnum.SUCCESS,ResponseDTO)
    service
    账户信息判空,账户密码正确性判断
    生成token,完成 JWT 登录校验,将 token 添加至 LoginResponseDTO 并返回
    接收参数 LoginDTO,返回参数 ResponseDTO
    mapper
    动态 sql,accountId、email、phone 非空即判断
    接收参数 LoginDTO 返回参数 ResponseDTO

  3. 修改账户信息
    登录后可使用该接口,token 包含 id 属性,通过 id 定位
    username,avatar,email,phone,username 非空即修改,空则不修改
    封装为 updateDTO 传输
    返会修改成功 Result(200,”success”,data),data 含 token 给前端校验,还有修改后数据库的 accountId,email,phone,username,avatar 来给前端展示
    controller
    url:/profile
    接收参数 header token 和 body UpdateDTO,返回参数 Result(ErrorCodeEnum.SUCCESS,ResponseDTO)
    service
    accountId, email, phone 判断修改前后是否一致
    根据执行后 mapper 的返回值 int 是否为0 判断是否更新了内容
    接收参数 updateDTO,返回参数 UpdateResponseDTO
    mapper
    动态 sql,如果 accountId、email、phone、username、avatar 非空则修改
    接收参数 updateDTO,返回参数影响行数 int

  4. 注销账户:
    登陆后可使用该接口,token 包含 id 属性,通过 id 定位
    需传递 password 确认
    修改isDelete
    返回注销成功 Result(200,”success”)

2 博客系统

3 评论系统

三、数据库设计:

  1. 数据库建表语法:
    用户表:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    create table users(
    id bigint primary key auto_increment,
    account_id varchar(50) unique not null comment "账户号",
    password varchar(100) not null comment "密码",
    username varchar(50) not null comment "昵称",
    email varchar(100) unique not null comment "邮箱",
    phone varchar(20) not null unique comment "手机号",
    avatar varchar(255) comment "头像URL",
    follow_count int default 0 comment "关注数",
    follower_count int default 0 comment "粉丝数",
    create_time DateTime default current_timestamp comment "账户创建时间",
    is_delete tinyint default 0
    )comment "用户表";
    关注-粉丝表:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    create table user_follow(
    id bigint primary key auto_increment,
    user_id bigint not null comment"被关注用户id",
    follow_user_id bigint not null comment"粉丝id",
    create_time datetime default current_timestamp comment"关注时间",
    unique key(user_id,follow_user_id),
    foreign key (user_id) references users(id) on delete cascade,
    foreign key (follow_user_id) references users(id) on delete cascade
    )comment"关注_粉丝表";
    文章概览表:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    create table blog_summary(
    id bigint primary key auto_increment,
    title varchar(30) not null comment"标题",
    summary varchar(70) not null comment"摘要",
    user_id bigint not null comment"作者id",
    view_counts int default 0 comment"浏览量",
    like_counts int default 0 comment"点赞数",
    star_counts int default 0 comment"收藏量",
    create_time datetime default current_timestamp comment"创建时间",
    update_time datetime default current_timestamp comment"最后修改时间",
    is_delete tinyint default 0 comment"逻辑删除",
    category_id bigint comment"博客内容类别",
    foreign key (user_id) references users(id),
    foreign key (category_id) references category(id),\
    index idx_user(user_id),
    index idx_category(category_id),
    index idx_create_time(create_time)
    )comment"文章概览表";
    文章详情表:
    1
    2
    3
    4
    5
    6
    create table blog_content(
    id bigint primary key,
    content longtext not null comment"内容",
    is_delete tinyint default 0 comment"逻辑删除",
    foreign key (id) references blog_summary(id) on delete cascade
    )comment"文章详情表";
    文章类别表:
    1
    2
    3
    4
    5
    create table category(
    id bigint primary key auto_increment,
    name varchar(10) not null unique comment"博客类别名",
    is_delete tinyint default 0
    );
    评论表:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    create table comment(
    id bigint primary key auto_increment,
    content varchar(500) not null comment"评论内容",
    like_counts int default 0 comment"点赞数",
    user_id bigint not null comment"发评人id",
    blog_id bigint not null comment"博客id",
    parent_id bigint comment"父评论",
    create_time datetime default current_timestamp comment"发评时间",
    is_delete tinyint default 0 comment"逻辑删除",
    foreign key (user_id) references users(id),
    foreign key (blog_id) references blog_summary(id),
    foreign key (parent_id) references comment(id),
    index idx_blog(blog_id),
    index idx_user(user_id),
    index idx_parent(parent_id),
    index idx_blog_time(blog_id,create_time)
    );

接口设计: