apikey.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. var ErrInvalidApiKey = errors.New("Invalid API Key")
  7. type ApiKey struct {
  8. Id int64
  9. OrgId int64
  10. Name string
  11. Key string
  12. Role RoleType
  13. Created time.Time
  14. Updated time.Time
  15. }
  16. // ---------------------
  17. // COMMANDS
  18. type AddApiKeyCommand struct {
  19. Name string `json:"name" binding:"Required"`
  20. Role RoleType `json:"role" binding:"Required"`
  21. OrgId int64 `json:"-"`
  22. Key string `json:"-"`
  23. Result *ApiKey `json:"-"`
  24. }
  25. type UpdateApiKeyCommand struct {
  26. Id int64 `json:"id"`
  27. Name string `json:"name"`
  28. Role RoleType `json:"role"`
  29. OrgId int64 `json:"-"`
  30. }
  31. type DeleteApiKeyCommand struct {
  32. Id int64 `json:"id"`
  33. OrgId int64 `json:"-"`
  34. }
  35. // ----------------------
  36. // QUERIES
  37. type GetApiKeysQuery struct {
  38. OrgId int64
  39. Result []*ApiKey
  40. }
  41. type GetApiKeyByNameQuery struct {
  42. KeyName string
  43. OrgId int64
  44. Result *ApiKey
  45. }
  46. // ------------------------
  47. // DTO & Projections
  48. type ApiKeyDTO struct {
  49. Id int64 `json:"id"`
  50. Name string `json:"name"`
  51. Role RoleType `json:"role"`
  52. }