Browse Source

fix(user):register duplicate name

caisi35 3 tháng trước cách đây
mục cha
commit
e04773a409
1 tập tin đã thay đổi với 8 bổ sung0 xóa
  1. 8 0
      api/user/user.go

+ 8 - 0
api/user/user.go

@@ -57,6 +57,14 @@ func AddUser(c *gin.Context) {
 		Password: json.Password,
 	}
 
+	// duplicate name
+	_, err = u.Where(u.Name.Eq(json.Name)).First()
+	if !(err != nil && err.Error() == "record not found") {
+		c.JSON(http.StatusConflict, gin.H{
+			"message": "name already exists",
+		})
+	}
+
 	err = u.Create(&user)
 
 	if err != nil {