token.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. var ErrInvalidToken = errors.New("Invalid token")
  7. type Token struct {
  8. Id int64
  9. AccountId int64 `xorm:"not null unique(uix_account_id_name)"`
  10. Name string `xorm:"not null unique(uix_account_id_name)"`
  11. Token string `xorm:"UNIQUE NOT NULL"`
  12. Role RoleType `xorm:"not null"`
  13. Created time.Time
  14. Updated time.Time
  15. }
  16. // ---------------------
  17. // COMMANDS
  18. type AddTokenCommand struct {
  19. Name string `json:"name" binding:"required"`
  20. Role RoleType `json:"role" binding:"required"`
  21. AccountId int64 `json:"-"`
  22. Token string `json:"-"`
  23. Result *Token `json:"-"`
  24. }
  25. type UpdateTokenCommand struct {
  26. Id int64 `json:"id"`
  27. Name string `json:"name"`
  28. Role RoleType `json:"role"`
  29. AccountId int64 `json:"-"`
  30. Result *Token `json:"-"`
  31. }
  32. type DeleteTokenCommand struct {
  33. Id int64 `json:"id"`
  34. AccountId int64 `json:"-"`
  35. Result *Token `json:"-"`
  36. }
  37. // ----------------------
  38. // QUERIES
  39. type GetTokensQuery struct {
  40. AccountId int64
  41. Result []*Token
  42. }
  43. type GetTokenByTokenQuery struct {
  44. Token string
  45. Result *Token
  46. }
  47. // ------------------------
  48. // DTO & Projections
  49. type TokenDTO struct {
  50. Id int64 `json:"id"`
  51. Name string `json:"name"`
  52. Token string `json:"token"`
  53. Role RoleType `json:"role"`
  54. }