mysql_contact_info.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // InsertContactInfo Insert Contact Info.
  8. func (d *Dao) InsertContactInfo(contactInfo *model.ContactInfo) error {
  9. return pkgerr.WithStack(d.db.Create(contactInfo).Error)
  10. }
  11. // UpdateContactInfo Update Contact Info.
  12. func (d *Dao) UpdateContactInfo(contactInfo *model.ContactInfo) error {
  13. return pkgerr.WithStack(d.db.Save(&contactInfo).Error)
  14. }
  15. // QueryContactInfoByUserID Query Contact Info By User ID
  16. func (d *Dao) QueryContactInfoByUserID(userID string) (contactInfo *model.ContactInfo, err error) {
  17. contactInfo = &model.ContactInfo{}
  18. if err = d.db.Where("user_id = ?", userID).First(contactInfo).Error; err != nil {
  19. if err == ecode.NothingFound {
  20. err = nil
  21. } else {
  22. err = pkgerr.WithStack(err)
  23. }
  24. }
  25. return
  26. }
  27. // QueryContactInfoByUsername Query Contact Info By Username
  28. func (d *Dao) QueryContactInfoByUsername(username string) (contactInfo *model.ContactInfo, err error) {
  29. contactInfo = &model.ContactInfo{}
  30. if err = d.db.Where("username = ?", username).First(contactInfo).Error; err != nil {
  31. if err == ecode.NothingFound {
  32. err = nil
  33. } else {
  34. err = pkgerr.WithStack(err)
  35. }
  36. }
  37. return
  38. }
  39. // QueryAllContactInfos Query All Contact Infos
  40. func (d *Dao) QueryAllContactInfos() (contactInfos []*model.ContactInfo, err error) {
  41. err = pkgerr.WithStack(d.db.Find(&contactInfos).Error)
  42. return
  43. }