memo.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package store
  2. import (
  3. "context"
  4. )
  5. // Visibility is the type of a visibility.
  6. type Visibility string
  7. const (
  8. // Public is the PUBLIC visibility.
  9. Public Visibility = "PUBLIC"
  10. // Protected is the PROTECTED visibility.
  11. Protected Visibility = "PROTECTED"
  12. // Private is the PRIVATE visibility.
  13. Private Visibility = "PRIVATE"
  14. )
  15. func (v Visibility) String() string {
  16. switch v {
  17. case Public:
  18. return "PUBLIC"
  19. case Protected:
  20. return "PROTECTED"
  21. case Private:
  22. return "PRIVATE"
  23. }
  24. return "PRIVATE"
  25. }
  26. type Memo struct {
  27. ID int32
  28. // Standard fields
  29. RowStatus RowStatus
  30. CreatorID int32
  31. CreatedTs int64
  32. UpdatedTs int64
  33. // Domain specific fields
  34. Content string
  35. Visibility Visibility
  36. // Composed fields
  37. // For those comment memos, the parent ID is the memo ID of the memo being commented.
  38. // If the parent ID is nil, then this memo is not a comment.
  39. ParentID *int32
  40. Pinned bool
  41. ResourceIDList []int32
  42. RelationList []*MemoRelation
  43. }
  44. type FindMemo struct {
  45. ID *int32
  46. // Standard fields
  47. RowStatus *RowStatus
  48. CreatorID *int32
  49. CreatedTsAfter *int64
  50. CreatedTsBefore *int64
  51. // Domain specific fields
  52. Pinned *bool
  53. ContentSearch []string
  54. VisibilityList []Visibility
  55. // Pagination
  56. Limit *int
  57. Offset *int
  58. OrderByUpdatedTs bool
  59. }
  60. type UpdateMemo struct {
  61. ID int32
  62. CreatedTs *int64
  63. UpdatedTs *int64
  64. RowStatus *RowStatus
  65. Content *string
  66. Visibility *Visibility
  67. }
  68. type DeleteMemo struct {
  69. ID int32
  70. }
  71. func (s *Store) CreateMemo(ctx context.Context, create *Memo) (*Memo, error) {
  72. return s.driver.CreateMemo(ctx, create)
  73. }
  74. func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error) {
  75. return s.driver.ListMemos(ctx, find)
  76. }
  77. func (s *Store) GetMemo(ctx context.Context, find *FindMemo) (*Memo, error) {
  78. list, err := s.ListMemos(ctx, find)
  79. if err != nil {
  80. return nil, err
  81. }
  82. if len(list) == 0 {
  83. return nil, nil
  84. }
  85. memo := list[0]
  86. return memo, nil
  87. }
  88. func (s *Store) UpdateMemo(ctx context.Context, update *UpdateMemo) error {
  89. return s.driver.UpdateMemo(ctx, update)
  90. }
  91. func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error {
  92. return s.driver.DeleteMemo(ctx, delete)
  93. }
  94. func (s *Store) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]Visibility, error) {
  95. return s.driver.FindMemosVisibilityList(ctx, memoIDs)
  96. }