memos/store/memo.go

111 lines
2.0 KiB
Go
Raw Normal View History

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"
}
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
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-12-06 17:44:49 +03:00
Pinned bool
2022-05-19 13:32:04 +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
ContentSearch []string
2023-05-25 16:50:37 +03:00
VisibilityList []Visibility
Pinned *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
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
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
type DeleteMemo struct {
2023-08-04 16:55:07 +03:00
ID int32
2021-12-08 18:43:14 +03:00
}
func (s *Store) CreateMemo(ctx context.Context, create *Memo) (*Memo, error) {
return s.driver.CreateMemo(ctx, create)
2021-12-09 17:02:57 +03:00
}
func (s *Store) ListMemos(ctx context.Context, find *FindMemo) ([]*Memo, error) {
return s.driver.ListMemos(ctx, find)
2022-11-06 07:21:58 +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 {
return s.driver.UpdateMemo(ctx, update)
}
func (s *Store) DeleteMemo(ctx context.Context, delete *DeleteMemo) error {
return s.driver.DeleteMemo(ctx, delete)
}