token.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. AccountId int64 `json:"-"`
  27. Role RoleType `json:"role"`
  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. }