account.go 2.4 KB

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