memos/store/activity.go

66 lines
1.2 KiB
Go
Raw Normal View History

package store
import (
"context"
storepb "github.com/usememos/memos/proto/gen/store"
)
type ActivityType string
const (
2023-11-06 20:49:02 +08:00
ActivityTypeMemoComment ActivityType = "MEMO_COMMENT"
ActivityTypeVersionUpdate ActivityType = "VERSION_UPDATE"
)
func (t ActivityType) String() string {
return string(t)
}
type ActivityLevel string
const (
ActivityLevelInfo ActivityLevel = "INFO"
)
func (l ActivityLevel) String() string {
return string(l)
}
type Activity struct {
2023-08-04 21:55:07 +08:00
ID int32
// Standard fields
2023-08-04 21:55:07 +08:00
CreatorID int32
CreatedTs int64
// Domain specific fields
Type ActivityType
Level ActivityLevel
Payload *storepb.ActivityPayload
}
type FindActivity struct {
2023-11-06 20:49:02 +08:00
ID *int32
Type *ActivityType
}
func (s *Store) CreateActivity(ctx context.Context, create *Activity) (*Activity, error) {
return s.driver.CreateActivity(ctx, create)
}
2023-10-27 08:36:43 +08:00
func (s *Store) ListActivities(ctx context.Context, find *FindActivity) ([]*Activity, error) {
2023-10-27 01:11:41 +08:00
return s.driver.ListActivities(ctx, find)
}
2023-10-28 00:21:53 +08:00
func (s *Store) GetActivity(ctx context.Context, find *FindActivity) (*Activity, error) {
list, err := s.ListActivities(ctx, find)
if err != nil {
return nil, err
}
if len(list) == 0 {
return nil, nil
}
return list[0], nil
}