user_dao.go 598 B

1234567891011121314151617181920212223242526272829303132333435
  1. package dao
  2. import "time"
  3. type UserEntity struct {
  4. ID int64
  5. Username string
  6. Password string
  7. Email string
  8. CreatedAt time.Time
  9. }
  10. func (UserEntity) TableName() string {
  11. return "user"
  12. }
  13. type UserDAO interface {
  14. SelectByEmail(email string)(*UserEntity, error)
  15. Save(user *UserEntity) error
  16. }
  17. type UserDAOImpl struct {
  18. }
  19. func (userDAO *UserDAOImpl) SelectByEmail(email string)(*UserEntity, error) {
  20. user := &UserEntity{}
  21. err := db.Where("email = ?", email).First(user).Error
  22. return user, err
  23. }
  24. func (userDAO *UserDAOImpl) Save(user *UserEntity) error {
  25. return db.Create(user).Error
  26. }