user query 오류

This commit is contained in:
JongYeob Sheen 2024-01-29 17:56:39 +09:00
parent a402f046aa
commit 41e1ed5c58
2 changed files with 6 additions and 4 deletions

View File

@ -83,8 +83,6 @@ func (controller *userController) List(c *gin.Context) {
}
c.JSON(http.StatusOK, response)
c.JSON(http.StatusOK, response)
}
// Get User

View File

@ -33,7 +33,9 @@ func (r *userRepository) List(q string, page int, limit int) (*[]models.User, er
offset := limit * (page - 1)
fmt.Println("q", 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 {
fmt.Println(" query")
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 err error
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 {
err = r.DB.Model(&models.User{}).Where("user_role = ?", "member").Count(&total).Error
}