Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正数据库password字段问题 #8

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Register(c *gin.Context) {
} else {
newUser := &model.User{
Name: username,
PassWord: password,
Password: password,
}
//userinfo register
model.CreateUser(context.Background(), newUser)
Expand All @@ -84,7 +84,7 @@ func Login(c *gin.Context) {

if user != nil {
//judge password
if service.ComparePasswords(user.PassWord, password) {
if service.ComparePasswords(user.Password, password) {
c.JSON(http.StatusOK, UserLoginResponse{
Response: Response{StatusCode: 0},
UserId: user.ID,
Expand Down
188 changes: 98 additions & 90 deletions db/douyin.sql
Original file line number Diff line number Diff line change
@@ -1,90 +1,98 @@
/*
Navicat Premium Data Transfer

Source Server : douyin
Source Server Type : MySQL
Source Server Version : 80029
Source Host : xinzf0520.top:20607
Source Schema : douyin

Target Server Type : MySQL
Target Server Version : 80029
File Encoding : 65001

Date: 07/06/2022 18:46:56
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for comment
-- ----------------------------
DROP TABLE IF EXISTS `comment`;
CREATE TABLE `comment` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int NULL DEFAULT NULL COMMENT '用户id',
`video_id` datetime NULL DEFAULT NULL COMMENT '视频id',
`content` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '内容',
`created_at` datetime NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for favorite
-- ----------------------------
DROP TABLE IF EXISTS `favorite`;
CREATE TABLE `favorite` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int NULL DEFAULT NULL COMMENT '用户id',
`video_id` int NULL DEFAULT NULL COMMENT '视频id',
`status` tinyint NULL DEFAULT NULL COMMENT '点赞状态',
`created_at` datetime NULL DEFAULT NULL COMMENT '创建时间',
`updated_at` datetime NULL DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for follow
-- ----------------------------
DROP TABLE IF EXISTS `follow`;
CREATE TABLE `follow` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int NULL DEFAULT NULL COMMENT '用户id',
`followed_user` int NULL DEFAULT NULL COMMENT '被关注者id',
`status` tinyint NULL DEFAULT 1 COMMENT '关注状态',
`created_at` datetime NULL DEFAULT NULL COMMENT '创建时间',
`updated_at` datetime NULL DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '姓名',
`pass_word` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`follow_count` int UNSIGNED NULL DEFAULT NULL COMMENT '关注数',
`follower_count` int UNSIGNED NULL DEFAULT NULL COMMENT '粉丝数',
`created_at` datetime NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for video
-- ----------------------------
DROP TABLE IF EXISTS `video`;
CREATE TABLE `video` (
`id` int NOT NULL AUTO_INCREMENT,
`author_id` int NULL DEFAULT NULL COMMENT '作者id',
`play_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '播放路径',
`cover_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '封面路径',
`favorite_count` int NULL DEFAULT NULL COMMENT '喜欢数',
`comment_count` int NULL DEFAULT NULL COMMENT '评论数',
`created_at` datetime NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;
/*
Navicat Premium Data Transfer

Source Server : 127.0.0.1
Source Server Type : MySQL
Source Server Version : 80029
Source Host : 127.0.0.1:3306
Source Schema : douyin

Target Server Type : MySQL
Target Server Version : 80029
File Encoding : 65001

Date: 09/06/2022 23:45:29
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for comment
-- ----------------------------
DROP TABLE IF EXISTS `comment`;
CREATE TABLE `comment` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int DEFAULT NULL COMMENT '用户id',
`video_id` datetime DEFAULT NULL COMMENT '视频id',
`status` tinyint DEFAULT NULL COMMENT '评论状态',
`content` text CHARACTER SET utf8mb3 COLLATE utf8_general_ci COMMENT '内容',
`created_at` datetime DEFAULT NULL COMMENT '创建时间',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_video_id_status` (`video_id`,`status`) USING BTREE COMMENT '获取某个视频的所有评论'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- ----------------------------
-- Table structure for favorite
-- ----------------------------
DROP TABLE IF EXISTS `favorite`;
CREATE TABLE `favorite` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int DEFAULT NULL COMMENT '用户id',
`video_id` int DEFAULT NULL COMMENT '视频id',
`status` tinyint DEFAULT NULL COMMENT '点赞状态',
`created_at` datetime DEFAULT NULL COMMENT '创建时间',
`updated_at` datetime DEFAULT NULL COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_user_id_status_video_id` (`user_id`,`status`,`video_id`) USING BTREE COMMENT '获取某个用户所有点赞视频id'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

-- ----------------------------
-- Table structure for follow
-- ----------------------------
DROP TABLE IF EXISTS `follow`;
CREATE TABLE `follow` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int DEFAULT NULL COMMENT '用户id',
`followed_user` int DEFAULT NULL COMMENT '被关注者id',
`status` tinyint DEFAULT '1' COMMENT '关注状态',
`created_at` datetime DEFAULT NULL COMMENT '创建时间',
`updated_at` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_user_id_status_followed_user` (`user_id`,`status`,`followed_user`) USING BTREE COMMENT '查询关注列表',
KEY `idx_followed_user_status_user_id` (`followed_user`,`status`,`user_id`) USING BTREE COMMENT '查询粉丝列表'
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb3;

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '姓名',
`password` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '密码',
`follow_count` int DEFAULT NULL COMMENT '关注数',
`follower_count` int DEFAULT NULL COMMENT '粉丝数',
`created_at` datetime DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `idx_name` (`name`) USING BTREE COMMENT '根据用户名查询信息(如注册)'
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb3;

-- ----------------------------
-- Table structure for video
-- ----------------------------
DROP TABLE IF EXISTS `video`;
CREATE TABLE `video` (
`id` int NOT NULL AUTO_INCREMENT,
`author_id` int DEFAULT NULL COMMENT '作者id',
`play_url` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '播放路径',
`cover_url` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8_general_ci DEFAULT NULL COMMENT '封面路径',
`favorite_count` int DEFAULT NULL COMMENT '喜欢数',
`comment_count` int DEFAULT NULL COMMENT '评论数',
`created_at` datetime DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_author_id` (`author_id`) USING BTREE COMMENT '根据用户id查询所有发布的视频'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

SET FOREIGN_KEY_CHECKS = 1;
2 changes: 1 addition & 1 deletion db/model/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var DB *gorm.DB
// Init init DB
func Init() {
var err error
DB, err = gorm.Open(mysql.Open(constants.MySQLDefaultDSN),
DB, err = gorm.Open(mysql.Open(constants.MySQLLocalDSN),
&gorm.Config{
PrepareStmt: true, // executes the given query in cached statement
SkipDefaultTransaction: true, // disable default transaction
Expand Down
2 changes: 1 addition & 1 deletion db/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
type User struct {
ID int64 `gorm:"primarykey"`
Name string
PassWord string
Password string
FollowCount int64
FollowerCount int64
CreatedAt time.Time
Expand Down
2 changes: 1 addition & 1 deletion pkg/constants/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package constants

const (
MySQLDefaultDSN = "dyweadmin:JXU2MTNGJXU5NzUyJXU5Rjk5JXU2MzA3JXU1RjE1JXU0RjYw@tcp(xinzf0520.top:20607)/douyin?charset=utf8&parseTime=True&loc=Local"
//MySQLLocalDSN = "root:root@tcp(127.0.0.1:3306)/douyin?charset=utf8&parseTime=True&loc=Local"
MySQLLocalDSN = "root:root@tcp(127.0.0.1:3306)/douyin?charset=utf8&parseTime=True&loc=Local"
)