user.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. // Typed errors
  7. var (
  8. ErrUserNotFound = errors.New("User not found")
  9. )
  10. type User struct {
  11. Id int64
  12. Version int
  13. Email string
  14. Name string
  15. Login string
  16. Password string
  17. Salt string
  18. Rands string
  19. Company string
  20. EmailVerified bool
  21. Theme string
  22. IsAdmin bool
  23. OrgId int64
  24. Created time.Time
  25. Updated time.Time
  26. }
  27. // ---------------------
  28. // COMMANDS
  29. type CreateUserCommand struct {
  30. Email string `json:"email" binding:"Required"`
  31. Login string `json:"login"`
  32. Name string `json:"name"`
  33. Company string `json:"compay"`
  34. Password string `json:"password" binding:"Required"`
  35. IsAdmin bool `json:"-"`
  36. Result User `json:"-"`
  37. }
  38. type UpdateUserCommand struct {
  39. Name string `json:"name"`
  40. Email string `json:"email"`
  41. Login string `json:"login"`
  42. UserId int64 `json:"-"`
  43. }
  44. type ChangeUserPasswordCommand struct {
  45. OldPassword string `json:"oldPassword"`
  46. NewPassword string `json:"newPassword"`
  47. UserId int64 `json:"-"`
  48. }
  49. type DeleteUserCommand struct {
  50. UserId int64
  51. }
  52. type SetUsingOrgCommand struct {
  53. UserId int64
  54. OrgId int64
  55. }
  56. // ----------------------
  57. // QUERIES
  58. type GetUserByLoginQuery struct {
  59. LoginOrEmail string
  60. Result *User
  61. }
  62. type GetUserByIdQuery struct {
  63. Id int64
  64. Result *User
  65. }
  66. type GetSignedInUserQuery struct {
  67. UserId int64
  68. Result *SignedInUser
  69. }
  70. type GetUserInfoQuery struct {
  71. UserId int64
  72. Result UserDTO
  73. }
  74. type SearchUsersQuery struct {
  75. Query string
  76. Page int
  77. Limit int
  78. Result []*UserSearchHitDTO
  79. }
  80. type GetUserOrgListQuery struct {
  81. UserId int64
  82. Result []*UserOrgDTO
  83. }
  84. // ------------------------
  85. // DTO & Projections
  86. type SignedInUser struct {
  87. UserId int64
  88. OrgId int64
  89. OrgName string
  90. OrgRole RoleType
  91. Login string
  92. Name string
  93. Email string
  94. ApiKeyId int64
  95. IsGrafanaAdmin bool
  96. }
  97. type UserDTO struct {
  98. Email string `json:"email"`
  99. Name string `json:"name"`
  100. Login string `json:"login"`
  101. }
  102. type UserSearchHitDTO struct {
  103. Id int64 `json:"id"`
  104. Name string `json:"name"`
  105. Login string `json:"login"`
  106. Email string `json:"email"`
  107. IsAdmin bool `json:"isAdmin"`
  108. }