user.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package fetdata
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "golang-fave/utils"
  5. )
  6. type User struct {
  7. wrap *wrapper.Wrapper
  8. object *utils.MySql_user
  9. }
  10. func (this *User) load(id int) {
  11. if this == nil {
  12. return
  13. }
  14. if this.object != nil {
  15. return
  16. }
  17. this.object = &utils.MySql_user{}
  18. if err := this.wrap.DB.QueryRow(`
  19. SELECT
  20. id,
  21. first_name,
  22. last_name,
  23. email,
  24. admin,
  25. active
  26. FROM
  27. users
  28. WHERE
  29. id = ?
  30. LIMIT 1;`,
  31. id,
  32. ).Scan(
  33. &this.object.A_id,
  34. &this.object.A_first_name,
  35. &this.object.A_last_name,
  36. &this.object.A_email,
  37. &this.object.A_admin,
  38. &this.object.A_active,
  39. ); err != nil {
  40. return
  41. }
  42. }
  43. func (this *User) Id() int {
  44. if this == nil {
  45. return 0
  46. }
  47. return this.object.A_id
  48. }
  49. func (this *User) FirstName() string {
  50. if this == nil {
  51. return ""
  52. }
  53. return this.object.A_first_name
  54. }
  55. func (this *User) LastName() string {
  56. if this == nil {
  57. return ""
  58. }
  59. return this.object.A_last_name
  60. }
  61. func (this *User) Email() string {
  62. if this == nil {
  63. return ""
  64. }
  65. return this.object.A_email
  66. }
  67. func (this *User) IsAdmin() bool {
  68. if this == nil {
  69. return false
  70. }
  71. return this.object.A_admin == 1
  72. }
  73. func (this *User) IsActive() bool {
  74. if this == nil {
  75. return false
  76. }
  77. return this.object.A_active == 1
  78. }