2023-01-01 23:55:02 +08:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-10-27 23:24:56 +08:00
|
|
|
|
|
|
|
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"
|
2023-01-01 23:55:02 +08:00
|
|
|
)
|
|
|
|
|
2023-10-27 23:24:56 +08:00
|
|
|
func (t ActivityType) String() string {
|
|
|
|
return string(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ActivityLevel string
|
|
|
|
|
|
|
|
const (
|
|
|
|
ActivityLevelInfo ActivityLevel = "INFO"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (l ActivityLevel) String() string {
|
|
|
|
return string(l)
|
|
|
|
}
|
|
|
|
|
2023-07-06 21:56:42 +08:00
|
|
|
type Activity struct {
|
2023-08-04 21:55:07 +08:00
|
|
|
ID int32
|
2023-06-26 23:06:53 +08:00
|
|
|
|
|
|
|
// Standard fields
|
2023-08-04 21:55:07 +08:00
|
|
|
CreatorID int32
|
2023-06-26 23:06:53 +08:00
|
|
|
CreatedTs int64
|
|
|
|
|
|
|
|
// Domain specific fields
|
2023-10-27 23:24:56 +08:00
|
|
|
Type ActivityType
|
|
|
|
Level ActivityLevel
|
|
|
|
Payload *storepb.ActivityPayload
|
2023-06-26 23:06:53 +08:00
|
|
|
}
|
|
|
|
|
2023-10-09 21:18:33 +08:00
|
|
|
type FindActivity struct {
|
2023-11-06 20:49:02 +08:00
|
|
|
ID *int32
|
|
|
|
Type *ActivityType
|
2023-10-09 21:18:33 +08:00
|
|
|
}
|
|
|
|
|
2023-07-06 21:56:42 +08:00
|
|
|
func (s *Store) CreateActivity(ctx context.Context, create *Activity) (*Activity, error) {
|
2023-09-26 17:16:58 +08:00
|
|
|
return s.driver.CreateActivity(ctx, create)
|
2023-06-26 23:06:53 +08:00
|
|
|
}
|
2023-10-09 21:18:33 +08:00
|
|
|
|
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-09 21:18:33 +08:00
|
|
|
}
|
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
|
|
|
|
}
|