user.go 1.3 KB

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