mysql_user.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "go-common/app/admin/ep/marthe/model"
  4. "go-common/library/ecode"
  5. pkgerr "github.com/pkg/errors"
  6. )
  7. // FindUserByUserName find user by username.
  8. func (d *Dao) FindUserByUserName(name string) (user *model.User, err error) {
  9. user = &model.User{}
  10. if err = d.db.Where("name = ?", name).First(user).Error; err != nil {
  11. if err == ecode.NothingFound {
  12. err = nil
  13. } else {
  14. err = pkgerr.WithStack(err)
  15. }
  16. }
  17. return
  18. }
  19. // FindUserByID find user by id.
  20. func (d *Dao) FindUserByID(ID int64) (user *model.User, err error) {
  21. user = &model.User{}
  22. err = pkgerr.WithStack(d.db.Where("id = ?", ID).First(user).Error)
  23. return
  24. }
  25. // CreateUser create user.
  26. func (d *Dao) CreateUser(user *model.User) error {
  27. return pkgerr.WithStack(d.db.Create(user).Error)
  28. }
  29. // DelUser delete user.
  30. func (d *Dao) DelUser(user *model.User) error {
  31. return pkgerr.WithStack(d.db.Delete(user).Error)
  32. }
  33. // UpdateUserVisibleBugly Update User Visible Bugly.
  34. func (d *Dao) UpdateUserVisibleBugly(ID int64, visibleBugly bool) error {
  35. return pkgerr.WithStack(d.db.Model(&model.User{}).Where("id = ?", ID).Update("visible_bugly", visibleBugly).Error)
  36. }