account.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. Result Account `json:"-"`
  35. }
  36. type SetUsingAccountCommand struct {
  37. AccountId int64
  38. UsingAccountId int64
  39. }
  40. // ----------------------
  41. // QUERIES
  42. type GetAccountInfoQuery struct {
  43. Id int64
  44. Result AccountDTO
  45. }
  46. type GetOtherAccountsQuery struct {
  47. AccountId int64
  48. Result []*OtherAccountDTO
  49. }
  50. type GetAccountByIdQuery struct {
  51. Id int64
  52. Result *Account
  53. }
  54. type GetAccountByLoginQuery struct {
  55. Login string
  56. Result *Account
  57. }
  58. // ------------------------
  59. // DTO & Projections
  60. type OtherAccountDTO struct {
  61. Id int64 `json:"id"`
  62. Email string `json:"email"`
  63. Role string `json:"role"`
  64. IsUsing bool `json:"isUsing"`
  65. }
  66. type CollaboratorDTO struct {
  67. AccountId int64 `json:"accountId"`
  68. Email string `json:"email"`
  69. Role string `json:"role"`
  70. }
  71. type AccountDTO struct {
  72. Email string `json:"email"`
  73. Name string `json:"name"`
  74. Collaborators []*CollaboratorDTO `json:"collaborators"`
  75. }