mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-20 22:07:15 +00:00
chore: update find activities
This commit is contained in:
parent
9876fb27a4
commit
f057cd0078
@ -19,6 +19,7 @@ import (
|
||||
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
|
||||
storepb "github.com/yourselfhosted/slash/proto/gen/store"
|
||||
"github.com/yourselfhosted/slash/server/metric"
|
||||
"github.com/yourselfhosted/slash/server/service/license"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
)
|
||||
|
||||
@ -288,10 +289,15 @@ func (s *APIV1Service) GetShortcutAnalytics(ctx context.Context, request *v1pb.G
|
||||
return nil, status.Errorf(codes.NotFound, "shortcut not found")
|
||||
}
|
||||
|
||||
activities, err := s.Store.ListActivities(ctx, &store.FindActivity{
|
||||
activityFind := &store.FindActivity{
|
||||
Type: store.ActivityShortcutView,
|
||||
PayloadShortcutID: &shortcut.Id,
|
||||
})
|
||||
}
|
||||
if !s.LicenseService.IsFeatureEnabled(license.FeatureTypeAdvancedAnalytics) {
|
||||
createdTsAfter := time.Now().AddDate(0, 0, -14).Unix()
|
||||
activityFind.CreatedTsAfter = &createdTsAfter
|
||||
}
|
||||
activities, err := s.Store.ListActivities(ctx, activityFind)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get activities, err: %v", err)
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ type FindActivity struct {
|
||||
Type ActivityType
|
||||
Level ActivityLevel
|
||||
PayloadShortcutID *int32
|
||||
CreatedTsAfter *int64
|
||||
}
|
||||
|
||||
func (s *Store) CreateActivity(ctx context.Context, create *Activity) (*Activity, error) {
|
||||
|
@ -46,6 +46,9 @@ func (d *DB) ListActivities(ctx context.Context, find *store.FindActivity) ([]*s
|
||||
if find.PayloadShortcutID != nil {
|
||||
where, args = append(where, fmt.Sprintf("CAST(payload::JSON->>'shortcutId' AS INTEGER) = %s", placeholder(len(args)+1))), append(args, *find.PayloadShortcutID)
|
||||
}
|
||||
if find.CreatedTsAfter != nil {
|
||||
where, args = append(where, "created_ts > "+placeholder(len(args)+1)), append(args, *find.CreatedTsAfter)
|
||||
}
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
|
@ -45,6 +45,9 @@ func (d *DB) ListActivities(ctx context.Context, find *store.FindActivity) ([]*s
|
||||
if find.PayloadShortcutID != nil {
|
||||
where, args = append(where, "json_extract(payload, '$.shortcutId') = ?"), append(args, *find.PayloadShortcutID)
|
||||
}
|
||||
if find.CreatedTsAfter != nil {
|
||||
where, args = append(where, "created_ts > ?"), append(args, *find.CreatedTsAfter)
|
||||
}
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
|
Loading…
x
Reference in New Issue
Block a user