user.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. AccountId 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 SetUsingAccountCommand struct {
  53. UserId int64
  54. AccountId 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. // ------------------------
  81. // DTO & Projections
  82. type SignedInUser struct {
  83. UserId int64
  84. AccountId int64
  85. AccountName string
  86. AccountRole RoleType
  87. Login string
  88. Name string
  89. Email string
  90. ApiKeyId int64
  91. IsGrafanaAdmin bool
  92. }
  93. type UserDTO struct {
  94. Email string `json:"email"`
  95. Name string `json:"name"`
  96. Login string `json:"login"`
  97. }
  98. type UserSearchHitDTO struct {
  99. Id int64 `json:"id"`
  100. Name string `json:"name"`
  101. Login string `json:"login"`
  102. Email string `json:"email"`
  103. IsAdmin bool `json:"isAdmin"`
  104. }