account.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. // Typed errors
  7. var (
  8. ErrAccountNotFound = errors.New("Account not found")
  9. )
  10. type Account struct {
  11. Id int64
  12. Login string `xorm:"UNIQUE NOT NULL"`
  13. Email string `xorm:"UNIQUE NOT NULL"`
  14. Name string
  15. FullName string
  16. Password string
  17. IsAdmin bool
  18. Salt string `xorm:"VARCHAR(10)"`
  19. Company string
  20. NextDashboardId int
  21. UsingAccountId int64
  22. Created time.Time
  23. Updated time.Time
  24. }
  25. // ---------------------
  26. // COMMANDS
  27. type CreateAccountCommand struct {
  28. Email string `json:"email" binding:"required"`
  29. Login string `json:"login"`
  30. Password string `json:"password" binding:"required"`
  31. Name string `json:"name"`
  32. Company string `json:"company"`
  33. Salt string `json:"-"`
  34. IsAdmin bool `json:"-"`
  35. Result Account `json:"-"`
  36. }
  37. type UpdateAccountCommand struct {
  38. Email string `json:"email" binding:"Required"`
  39. Login string `json:"login"`
  40. Name string `json:"name"`
  41. AccountId int64 `json:"-"`
  42. }
  43. type SetUsingAccountCommand struct {
  44. AccountId int64
  45. UsingAccountId int64
  46. }
  47. // ----------------------
  48. // QUERIES
  49. type GetAccountInfoQuery struct {
  50. Id int64
  51. Result AccountDTO
  52. }
  53. type GetOtherAccountsQuery struct {
  54. AccountId int64
  55. Result []*OtherAccountDTO
  56. }
  57. type GetAccountByIdQuery struct {
  58. Id int64
  59. Result *Account
  60. }
  61. type GetAccountByLoginQuery struct {
  62. LoginOrEmail string
  63. Result *Account
  64. }
  65. type SearchAccountsQuery struct {
  66. Query string
  67. Page int
  68. Limit int
  69. Result []*AccountSearchHitDTO
  70. }
  71. type GetSignedInUserQuery struct {
  72. AccountId int64
  73. Result *SignedInUser
  74. }
  75. // ------------------------
  76. // DTO & Projections
  77. type SignedInUser struct {
  78. AccountId int64
  79. UsingAccountId int64
  80. UsingAccountName string
  81. UserRole RoleType
  82. UserLogin string
  83. UserName string
  84. UserEmail string
  85. ApiKeyId int64
  86. IsGrafanaAdmin bool
  87. }
  88. type OtherAccountDTO struct {
  89. AccountId int64 `json:"accountId"`
  90. Email string `json:"email"`
  91. Role RoleType `json:"role"`
  92. IsUsing bool `json:"isUsing"`
  93. }
  94. type AccountSearchHitDTO struct {
  95. Id int64 `json:"id"`
  96. Name string `json:"name"`
  97. Login string `json:"login"`
  98. Email string `json:"email"`
  99. IsAdmin bool `json:"isAdmin"`
  100. }
  101. type AccountDTO struct {
  102. Email string `json:"email"`
  103. Name string `json:"name"`
  104. Login string `json:"login"`
  105. }