diff --git a/configs/dBlog.sql b/configs/dBlog.sql index 6ac6b14..2b5fc4f 100644 --- a/configs/dBlog.sql +++ b/configs/dBlog.sql @@ -34,7 +34,7 @@ USE `dazblog`; -- Table structure for table `post` -- -DROP TABLE IF EXISTS `post`; +DROP TABLE IF EXISTS posts; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `post` ( @@ -48,7 +48,7 @@ CREATE TABLE `post` ( PRIMARY KEY (`id`), UNIQUE KEY `postID` (`postID`), KEY `idx_username` (`username`), - CONSTRAINT `fk_post_username` FOREIGN KEY (`username`) REFERENCES `user` (`username`) ON DELETE CASCADE + CONSTRAINT `fk_post_username` FOREIGN KEY (`username`) REFERENCES users (`username`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -56,7 +56,7 @@ CREATE TABLE `post` ( -- Table structure for table `user` -- -DROP TABLE IF EXISTS `user`; +DROP TABLE IF EXISTS users; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `user` ( diff --git a/configs/dazBlog.yaml b/configs/dazBlog.yaml deleted file mode 100644 index 71ee923..0000000 --- a/configs/dazBlog.yaml +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2023 daz-3ux(杨鹏达) . All rights reserved. -# Use of this source code is governed by a MIT style -# license that can be found in the LICENSE file. The original repo for -# this file is https://github.com/Daz-3ux/dBlog. - -# common configs -runmode: debug # Gin run mode, debug / release / test -addr: :8081 # HTTP server listen port -jwt-secret: szO8T9zWx+AyZB1le9MaEG7MCToMVcELHZYiakv1rRE - -# gRPC server config -grpc: - addr: :9090 - -# HTTPS server config -tls: - addr: :8443 - cert: ./_output/cert/server.crt - key: ./_output/cert/server.key - -# mysql configs -db: - host: 127.0.0.1 - username: root - password: passwd - database: dazblog - max-idle-connections: 100 - max-open-connections: 100 - max-connection-life-time: 10s - log-level: 2 # GORM log level, 1: silent, 2:error, 3:warn, 4:info - -# log configs -log: - disable-caller: false - disable-stacktrace: false - level: debug - format: console - output-paths: [stdout, /var/log/dazblog/dazblog.log] \ No newline at end of file diff --git a/internal/dazBlog/biz/user/user.go b/internal/dazBlog/biz/user/user.go index fd91cd1..0bfe2ea 100644 --- a/internal/dazBlog/biz/user/user.go +++ b/internal/dazBlog/biz/user/user.go @@ -126,19 +126,19 @@ func (b *userBiz) Update(ctx context.Context, username string, user *v1.UpdateUs return err } - if *user.Nickname != "" { + if user.Nickname != nil && *user.Nickname != "" { userM.Nickname = *user.Nickname } - if *user.Email != "" { + if user.Email != nil && *user.Email != "" { userM.Email = *user.Email } - if *user.Gender != "" { + if user.Gender != nil && *user.Gender != "" { userM.Gender = *user.Gender } - if *user.Phone != "" { + if user.Phone != nil && *user.Phone != "" { userM.Phone = *user.Phone } - if *user.QQ != "" { + if user.QQ != nil && *user.QQ != "" { userM.QQ = *user.QQ } diff --git a/internal/dazBlog/controller/v1/user/change_password.go b/internal/dazBlog/controller/v1/user/change_password.go index 49c4087..9f1f32a 100644 --- a/internal/dazBlog/controller/v1/user/change_password.go +++ b/internal/dazBlog/controller/v1/user/change_password.go @@ -34,5 +34,5 @@ func (ctrl *UserController) ChangePassword(c *gin.Context) { return } - core.WriteResponse(c, nil, nil) + core.WriteResponse(c, nil, map[string]string{"change password": "ok"}) } diff --git a/internal/dazBlog/controller/v1/user/create.go b/internal/dazBlog/controller/v1/user/create.go index 516bc4d..12fb5e3 100644 --- a/internal/dazBlog/controller/v1/user/create.go +++ b/internal/dazBlog/controller/v1/user/create.go @@ -24,6 +24,7 @@ func (ctrl *UserController) Create(c *gin.Context) { var r v1.CreateUserRequest if err := c.ShouldBindJSON(&r); err != nil { core.WriteResponse(c, errno.ErrBind, nil) + log.C(c).Errorw("Create user function called", "error", err.Error()) return } @@ -43,5 +44,5 @@ func (ctrl *UserController) Create(c *gin.Context) { return } - core.WriteResponse(c, nil, nil) + core.WriteResponse(c, nil, map[string]string{"create user": "ok"}) } diff --git a/internal/dazBlog/controller/v1/user/update.go b/internal/dazBlog/controller/v1/user/update.go index f4a2f06..acbda99 100644 --- a/internal/dazBlog/controller/v1/user/update.go +++ b/internal/dazBlog/controller/v1/user/update.go @@ -21,7 +21,7 @@ func (ctrl *UserController) Update(c *gin.Context) { var r v1.UpdateUserRequest if err := c.ShouldBindJSON(&r); err != nil { core.WriteResponse(c, errno.ErrBind, nil) - + log.C(c).Errorw("binding request failed", "error", err.Error()) return } @@ -33,9 +33,9 @@ func (ctrl *UserController) Update(c *gin.Context) { if err := ctrl.b.Users().Update(c, c.Param("name"), &r); err != nil { core.WriteResponse(c, err, nil) - + log.C(c).Errorw("updating user failed", "error", err.Error()) return } - core.WriteResponse(c, nil, nil) + core.WriteResponse(c, nil, map[string]string{"update user info": "ok"}) } diff --git a/pkg/api/dazBlog/v1/user.go b/pkg/api/dazBlog/v1/user.go index feb0333..77171fe 100644 --- a/pkg/api/dazBlog/v1/user.go +++ b/pkg/api/dazBlog/v1/user.go @@ -13,9 +13,10 @@ type CreateUserRequest struct { Password string `json:"password" valid:"required,stringlength(6|18)"` Nickname string `json:"nickname" valid:"required,stringlength(1|30)"` Email string `json:"email" valid:"required,email"` - Gender string `json:"gender" valid:"required"` - Phone string `json:"phone" valid:"required,numeric,stringlength(11|11)"` - QQ string `json:"qq" valid:"numeric,stringlength(5|16)"` + // only male || female || other + Gender string `json:"gender" valid:"required"` + Phone string `json:"phone" valid:"required,numeric,stringlength(11|11)"` + QQ string `json:"qq" valid:"numeric,stringlength(5|16)"` } // GetUserResponse specifies the response parameters for