2021-12-08 18:43:14 +03:00
|
|
|
package store
|
|
|
|
|
2021-12-09 17:02:57 +03:00
|
|
|
import (
|
2022-08-07 05:17:12 +03:00
|
|
|
"context"
|
2021-12-09 17:02:57 +03:00
|
|
|
)
|
2021-12-08 18:43:14 +03:00
|
|
|
|
2023-05-25 16:50:37 +03:00
|
|
|
// Visibility is the type of a visibility.
|
|
|
|
type Visibility string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Public is the PUBLIC visibility.
|
|
|
|
Public Visibility = "PUBLIC"
|
|
|
|
// Protected is the PROTECTED visibility.
|
|
|
|
Protected Visibility = "PROTECTED"
|
|
|
|
// Private is the PRIVATE visibility.
|
|
|
|
Private Visibility = "PRIVATE"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (v Visibility) String() string {
|
|
|
|
switch v {
|
|
|
|
case Public:
|
|
|
|
return "PUBLIC"
|
|
|
|
case Protected:
|
|
|
|
return "PROTECTED"
|
|
|
|
case Private:
|
|
|
|
return "PRIVATE"
|
|
|
|
}
|
|
|
|
return "PRIVATE"
|
|
|
|
}
|
|
|
|
|
2023-07-06 16:56:42 +03:00
|
|
|
type Memo struct {
|
2023-08-04 16:55:07 +03:00
|
|
|
ID int32
|
2022-05-19 13:32:04 +03:00
|
|
|
|
|
|
|
// Standard fields
|
2023-05-25 16:50:37 +03:00
|
|
|
RowStatus RowStatus
|
2023-08-04 16:55:07 +03:00
|
|
|
CreatorID int32
|
2022-05-19 13:32:04 +03:00
|
|
|
CreatedTs int64
|
|
|
|
UpdatedTs int64
|
|
|
|
|
|
|
|
// Domain specific fields
|
2022-07-08 17:23:27 +03:00
|
|
|
Content string
|
2023-05-25 16:50:37 +03:00
|
|
|
Visibility Visibility
|
2022-05-19 13:32:04 +03:00
|
|
|
|
2023-05-25 16:50:37 +03:00
|
|
|
// Composed fields
|
2023-10-01 11:27:40 +03:00
|
|
|
// For those comment memos, the parent ID is the memo ID of the memo being commented.
|
|
|
|
// If the parent ID is nil, then this memo is not a comment.
|
|
|
|
ParentID *int32
|
2023-05-25 16:50:37 +03:00
|
|
|
Pinned bool
|
2023-08-04 16:55:07 +03:00
|
|
|
ResourceIDList []int32
|
2023-07-06 16:56:42 +03:00
|
|
|
RelationList []*MemoRelation
|
2022-05-19 13:32:04 +03:00
|
|
|
}
|
|
|
|
|
2023-07-06 16:56:42 +03:00
|
|
|
type FindMemo struct {
|
2023-08-04 16:55:07 +03:00
|
|
|
ID *int32
|
2022-08-07 05:17:12 +03:00
|
|
|
|
2023-05-25 16:50:37 +03:00
|
|
|
// Standard fields
|
2023-09-13 15:42:44 +03:00
|
|
|
RowStatus *RowStatus
|
|
|
|
CreatorID *int32
|
|
|
|
CreatedTsAfter *int64
|
|
|
|
CreatedTsBefore *int64
|
2022-08-07 05:17:12 +03:00
|
|
|
|
2023-05-25 16:50:37 +03:00
|
|
|
// Domain specific fields
|
2023-05-26 13:51:18 +03:00
|
|
|
ContentSearch []string
|
2023-05-25 16:50:37 +03:00
|
|
|
VisibilityList []Visibility
|
2023-10-07 19:42:02 +03:00
|
|
|
Pinned *bool
|
|
|
|
HasParent *bool
|
2023-10-20 03:48:52 +03:00
|
|
|
ExcludeContent bool
|
2022-05-19 13:32:04 +03:00
|
|
|
|
2023-05-25 16:50:37 +03:00
|
|
|
// Pagination
|
2023-05-27 21:04:05 +03:00
|
|
|
Limit *int
|
|
|
|
Offset *int
|
|
|
|
OrderByUpdatedTs bool
|
2023-11-19 04:42:59 +03:00
|
|
|
OrderByPinned bool
|
2023-05-25 16:50:37 +03:00
|
|
|
}
|
2022-08-07 05:17:12 +03:00
|
|
|
|
2023-07-06 16:56:42 +03:00
|
|
|
type UpdateMemo struct {
|
2023-08-04 16:55:07 +03:00
|
|
|
ID int32
|
2023-05-25 16:50:37 +03:00
|
|
|
CreatedTs *int64
|
|
|
|
UpdatedTs *int64
|
|
|
|
RowStatus *RowStatus
|
|
|
|
Content *string
|
|
|
|
Visibility *Visibility
|
|
|
|
}
|
2022-08-07 03:09:43 +03:00
|
|
|
|
2023-07-06 16:56:42 +03:00
|
|
|
type DeleteMemo struct {
|
2023-08-04 16:55:07 +03:00
|
|
|
ID int32
|
2021-12-08 18:43:14 +03:00
|
|
|
}
|
|
|
|
|
2023-07-06 16:56:42 +03:00
|
|
|
func (s *Store) CreateMemo(ctx context.Context, create *Memo) (*Memo, error) {
|
2023-09-27 03:57:12 +03:00
|
|
|
return s.driver.CreateMemo(ctx, create)
|
2021-12-09 17:02:57 +03:00
|
|
|
}
|
|
|
|
|
2023-07-06 16:56:42 +03:00
|
|
|
func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error) {
|
2023-09-27 03:57:12 +03:00
|
|
|
return s.driver.ListMemos(ctx, find)
|
2022-11-06 07:21:58 +03:00
|
|
|
}
|
|
|
|
|
2023-07-20 18:15:56 +03:00
|
|
|
func (s *Store) GetMemo(ctx context.Context, find *FindMemo) (*Memo, error) {
|
|
|
|
list, err := s.ListMemos(ctx, find)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(list) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
memo := list[0]
|
|
|
|
return memo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Store) UpdateMemo(ctx context.Context, update *UpdateMemo) error {
|
2023-09-27 03:57:12 +03:00
|
|
|
return s.driver.UpdateMemo(ctx, update)
|
2023-07-20 18:15:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error {
|
2023-09-27 04:27:31 +03:00
|
|
|
return s.driver.DeleteMemo(ctx, delete)
|
2023-07-20 18:15:56 +03:00
|
|
|
}
|
|
|
|
|
2023-08-04 16:55:07 +03:00
|
|
|
func (s *Store) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]Visibility, error) {
|
2023-09-27 03:57:12 +03:00
|
|
|
return s.driver.FindMemosVisibilityList(ctx, memoIDs)
|
2023-07-20 18:15:56 +03:00
|
|
|
}
|