user query 오류
This commit is contained in:
parent
a402f046aa
commit
41e1ed5c58
@ -83,8 +83,6 @@ func (controller *userController) List(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, response)
|
c.JSON(http.StatusOK, response)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, response)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get User
|
// Get User
|
||||||
|
@ -33,7 +33,9 @@ func (r *userRepository) List(q string, page int, limit int) (*[]models.User, er
|
|||||||
offset := limit * (page - 1)
|
offset := limit * (page - 1)
|
||||||
fmt.Println("q", q)
|
fmt.Println("q", q)
|
||||||
if q != "" {
|
if q != "" {
|
||||||
err = r.DB.Offset(offset).Limit(limit).Order("last_name ASC, first_name ASC").Where("user_role = ?", "member").Where("name LIKE ? OR user_name LIKE ?", "%"+q+"%", "%"+q+"%").Find(&users).Error
|
err = r.DB.Offset(offset).Limit(limit).Order("last_name ASC, first_name ASC").Where("user_role = ?", "member").
|
||||||
|
Where("first_name LIKE ? OR last_name LIKE ? OR CONCAT(last_name, first_name) LIKE ? OR user_name LIKE ?", "%"+q+"%", "%"+q+"%", "%"+q+"%", "%"+q+"%").
|
||||||
|
Find(&users).Error
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(" query")
|
fmt.Println(" query")
|
||||||
err = r.DB.Offset(offset).Limit(limit).Order("last_name ASC, first_name ASC").Where("user_role = ?", "member").Find(&users).Error
|
err = r.DB.Offset(offset).Limit(limit).Order("last_name ASC, first_name ASC").Where("user_role = ?", "member").Find(&users).Error
|
||||||
@ -45,7 +47,9 @@ func (r *userRepository) Total(q string) (int64, error) {
|
|||||||
var total int64
|
var total int64
|
||||||
var err error
|
var err error
|
||||||
if q != "" {
|
if q != "" {
|
||||||
err = r.DB.Model(&models.User{}).Where("user_role = ?", "member").Where("name LIKE ? OR user_name LIKE ?", "%"+q+"%", "%"+q+"%").Count(&total).Error
|
err = r.DB.Model(&models.User{}).Where("user_role = ?", "member").
|
||||||
|
Where("first_name LIKE ? OR last_name LIKE ? OR CONCAT(last_name, first_name) LIKE ? OR user_name LIKE ?", "%"+q+"%", "%"+q+"%", "%"+q+"%", "%"+q+"%").
|
||||||
|
Count(&total).Error
|
||||||
} else {
|
} else {
|
||||||
err = r.DB.Model(&models.User{}).Where("user_role = ?", "member").Count(&total).Error
|
err = r.DB.Model(&models.User{}).Where("user_role = ?", "member").Count(&total).Error
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user