memos/store/memo.go

118 lines
2.3 KiB
Go
Raw Normal View History

2021-12-08 23:43:14 +08:00
package store
2021-12-09 22:02:57 +08:00
import (
2022-08-07 10:17:12 +08:00
"context"
2021-12-09 22:02:57 +08:00
)
2021-12-08 23:43:14 +08:00
2023-05-25 21:50:37 +08: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"
}
type Memo struct {
2023-08-04 21:55:07 +08:00
ID int32
2022-05-19 18:32:04 +08:00
// Standard fields
2023-05-25 21:50:37 +08:00
RowStatus RowStatus
2023-08-04 21:55:07 +08:00
CreatorID int32
2022-05-19 18:32:04 +08:00
CreatedTs int64
UpdatedTs int64
// Domain specific fields
Content string
2023-05-25 21:50:37 +08:00
Visibility Visibility
2022-05-19 18:32:04 +08:00
2023-05-25 21:50:37 +08:00
// Composed fields
2023-10-01 16:27:40 +08: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 21:50:37 +08:00
Pinned bool
2023-08-04 21:55:07 +08:00
ResourceIDList []int32
RelationList []*MemoRelation
2022-05-19 18:32:04 +08:00
}
type FindMemo struct {
2023-08-04 21:55:07 +08:00
ID *int32
2022-08-07 10:17:12 +08:00
2023-05-25 21:50:37 +08:00
// Standard fields
2023-09-13 20:42:44 +08:00
RowStatus *RowStatus
CreatorID *int32
CreatedTsAfter *int64
CreatedTsBefore *int64
2022-08-07 10:17:12 +08:00
2023-05-25 21:50:37 +08:00
// Domain specific fields
Pinned *bool
ContentSearch []string
2023-05-25 21:50:37 +08:00
VisibilityList []Visibility
2022-05-19 18:32:04 +08:00
2023-05-25 21:50:37 +08:00
// Pagination
Limit *int
Offset *int
OrderByUpdatedTs bool
2023-05-25 21:50:37 +08:00
}
2022-08-07 10:17:12 +08:00
type UpdateMemo struct {
2023-08-04 21:55:07 +08:00
ID int32
2023-05-25 21:50:37 +08:00
CreatedTs *int64
UpdatedTs *int64
RowStatus *RowStatus
Content *string
Visibility *Visibility
}
2022-08-07 08:09:43 +08:00
type DeleteMemo struct {
2023-08-04 21:55:07 +08:00
ID int32
2021-12-08 23:43:14 +08:00
}
func (s *Store) CreateMemo(ctx context.Context, create *Memo) (*Memo, error) {
return s.driver.CreateMemo(ctx, create)
2021-12-09 22:02:57 +08:00
}
func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error) {
return s.driver.ListMemos(ctx, find)
2022-11-06 12:21:58 +08: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 {
return s.driver.UpdateMemo(ctx, update)
}
func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error {
return s.driver.DeleteMemo(ctx, delete)
}
2023-08-04 21:55:07 +08:00
func (s *Store) FindMemosVisibilityList(ctx context.Context, memoIDs []int32) ([]Visibility, error) {
return s.driver.FindMemosVisibilityList(ctx, memoIDs)
}