account.go 2.5 KB

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