Skip to content

Commit

Permalink
fix: solve some bugs
Browse files Browse the repository at this point in the history
Signed-off-by: daz-3ux <[email protected]>
  • Loading branch information
Daz-3ux committed Oct 17, 2023
1 parent b0d55bf commit 6734b3d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 54 deletions.
6 changes: 3 additions & 3 deletions configs/dBlog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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` (
Expand All @@ -48,15 +48,15 @@ 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 */;

--
-- 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` (
Expand Down
38 changes: 0 additions & 38 deletions configs/dazBlog.yaml

This file was deleted.

10 changes: 5 additions & 5 deletions internal/dazBlog/biz/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion internal/dazBlog/controller/v1/user/change_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
}
3 changes: 2 additions & 1 deletion internal/dazBlog/controller/v1/user/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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"})
}
6 changes: 3 additions & 3 deletions internal/dazBlog/controller/v1/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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"})
}
7 changes: 4 additions & 3 deletions pkg/api/dazBlog/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6734b3d

Please sign in to comment.