mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-03 20:21:40 +00:00
chore: add view field into shortcut api
This commit is contained in:
@ -54,6 +54,7 @@ type Shortcut struct {
|
||||
Description string `json:"description"`
|
||||
Visibility Visibility `json:"visibility"`
|
||||
Tags []string `json:"tags"`
|
||||
View int `json:"view"`
|
||||
}
|
||||
|
||||
type CreateShortcutRequest struct {
|
||||
@ -279,9 +280,20 @@ func (s *APIV1Service) composeShortcut(ctx context.Context, shortcut *Shortcut)
|
||||
ID: &shortcut.CreatorID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "Failed to get creator")
|
||||
}
|
||||
shortcut.Creator = convertUserFromStore(user)
|
||||
|
||||
activityList, err := s.Store.ListActivities(ctx, &store.FindActivity{
|
||||
Type: store.ActivityShortcutView,
|
||||
Level: store.ActivityInfo,
|
||||
Where: []string{fmt.Sprintf("json_extract(payload, '$.shortcutId') = %d", shortcut.ID)},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Failed to list activities")
|
||||
}
|
||||
shortcut.View = len(activityList)
|
||||
|
||||
return shortcut, nil
|
||||
}
|
||||
|
||||
@ -299,6 +311,11 @@ func convertVisibilityToStore(visibility Visibility) store.Visibility {
|
||||
}
|
||||
|
||||
func convertShortcutFromStore(shortcut *store.Shortcut) *Shortcut {
|
||||
tags := []string{}
|
||||
if shortcut.Tag != "" {
|
||||
tags = append(tags, strings.Split(shortcut.Tag, " ")...)
|
||||
}
|
||||
|
||||
return &Shortcut{
|
||||
ID: shortcut.ID,
|
||||
CreatedTs: shortcut.CreatedTs,
|
||||
@ -309,6 +326,6 @@ func convertShortcutFromStore(shortcut *store.Shortcut) *Shortcut {
|
||||
Description: shortcut.Description,
|
||||
Visibility: Visibility(shortcut.Visibility),
|
||||
RowStatus: RowStatus(shortcut.RowStatus),
|
||||
Tags: strings.Split(shortcut.Tag, " "),
|
||||
Tags: tags,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user