apikey.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. type GetApiKeyByIdQuery struct {
  47. ApiKeyId int64
  48. Result *ApiKey
  49. }
  50. // ------------------------
  51. // DTO & Projections
  52. type ApiKeyDTO struct {
  53. Id int64 `json:"id"`
  54. Name string `json:"name"`
  55. Role RoleType `json:"role"`
  56. }