token.go 1.2 KB

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