activity.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package store
  2. import (
  3. "context"
  4. storepb "github.com/usememos/memos/proto/gen/store"
  5. )
  6. type ActivityType string
  7. const (
  8. ActivityTypeMemoComment ActivityType = "MEMO_COMMENT"
  9. ActivityTypeVersionUpdate ActivityType = "VERSION_UPDATE"
  10. )
  11. func (t ActivityType) String() string {
  12. return string(t)
  13. }
  14. type ActivityLevel string
  15. const (
  16. ActivityLevelInfo ActivityLevel = "INFO"
  17. )
  18. func (l ActivityLevel) String() string {
  19. return string(l)
  20. }
  21. type Activity struct {
  22. ID int32
  23. // Standard fields
  24. CreatorID int32
  25. CreatedTs int64
  26. // Domain specific fields
  27. Type ActivityType
  28. Level ActivityLevel
  29. Payload *storepb.ActivityPayload
  30. }
  31. type FindActivity struct {
  32. ID *int32
  33. Type *ActivityType
  34. }
  35. func (s *Store) CreateActivity(ctx context.Context, create *Activity) (*Activity, error) {
  36. return s.driver.CreateActivity(ctx, create)
  37. }
  38. func (s *Store) ListActivities(ctx context.Context, find *FindActivity) ([]*Activity, error) {
  39. return s.driver.ListActivities(ctx, find)
  40. }
  41. func (s *Store) GetActivity(ctx context.Context, find *FindActivity) (*Activity, error) {
  42. list, err := s.ListActivities(ctx, find)
  43. if err != nil {
  44. return nil, err
  45. }
  46. if len(list) == 0 {
  47. return nil, nil
  48. }
  49. return list[0], nil
  50. }