mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-16 12:23:12 +00:00
fix: variable type in store
This commit is contained in:
parent
407a8cc7fb
commit
8dfae8a6aa
@ -127,13 +127,19 @@ func (s *APIV1Service) registerShortcutRoutes(g *echo.Group) {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted patch shortcut request").SetInternal(err)
|
||||
}
|
||||
|
||||
shortcut, err = s.Store.UpdateShortcut(ctx, &store.UpdateShortcut{
|
||||
ID: shortcutID,
|
||||
RowStatus: (*store.RowStatus)(patch.RowStatus),
|
||||
Name: patch.Name,
|
||||
Link: patch.Link,
|
||||
Visibility: (*store.Visibility)(patch.Visibility),
|
||||
})
|
||||
shortcutUpdate := &store.UpdateShortcut{
|
||||
ID: shortcutID,
|
||||
Name: patch.Name,
|
||||
Link: patch.Link,
|
||||
Description: patch.Description,
|
||||
}
|
||||
if patch.RowStatus != nil {
|
||||
shortcutUpdate.RowStatus = (*store.RowStatus)(patch.RowStatus)
|
||||
}
|
||||
if patch.Visibility != nil {
|
||||
shortcutUpdate.Visibility = (*store.Visibility)(patch.Visibility)
|
||||
}
|
||||
shortcut, err = s.Store.UpdateShortcut(ctx, shortcutUpdate)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to patch shortcut").SetInternal(err)
|
||||
}
|
||||
@ -227,16 +233,13 @@ func (s *APIV1Service) composeShortcut(ctx context.Context, shortcut *Shortcut)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if shortcut.CreatorID != 0 {
|
||||
user, err := s.Store.GetUser(ctx, &store.FindUser{
|
||||
ID: &shortcut.CreatorID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
shortcut.Creator = convertUserFromStore(user)
|
||||
user, err := s.Store.GetUser(ctx, &store.FindUser{
|
||||
ID: &shortcut.CreatorID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
shortcut.Creator = convertUserFromStore(user)
|
||||
return shortcut, nil
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ func upsertMigrationHistory(ctx context.Context, tx *sql.Tx, upsert *MigrationHi
|
||||
version=EXCLUDED.version
|
||||
RETURNING version, created_ts
|
||||
`
|
||||
var migrationHistory MigrationHistory
|
||||
migrationHistory := &MigrationHistory{}
|
||||
if err := tx.QueryRowContext(ctx, query, upsert.Version).Scan(
|
||||
&migrationHistory.Version,
|
||||
&migrationHistory.CreatedTs,
|
||||
@ -114,5 +114,5 @@ func upsertMigrationHistory(ctx context.Context, tx *sql.Tx, upsert *MigrationHi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &migrationHistory, nil
|
||||
return migrationHistory, nil
|
||||
}
|
||||
|
@ -111,9 +111,8 @@ func (s *Store) UpdateShortcut(ctx context.Context, update *UpdateShortcut) (*Sh
|
||||
defer tx.Rollback()
|
||||
|
||||
set, args := []string{}, []any{}
|
||||
|
||||
if update.RowStatus != nil {
|
||||
set, args = append(set, "row_status = ?"), append(args, *update.RowStatus)
|
||||
set, args = append(set, "row_status = ?"), append(args, update.RowStatus.String())
|
||||
}
|
||||
if update.Name != nil {
|
||||
set, args = append(set, "name = ?"), append(args, *update.Name)
|
||||
@ -125,7 +124,7 @@ func (s *Store) UpdateShortcut(ctx context.Context, update *UpdateShortcut) (*Sh
|
||||
set, args = append(set, "description = ?"), append(args, *update.Description)
|
||||
}
|
||||
if update.Visibility != nil {
|
||||
set, args = append(set, "visibility = ?"), append(args, *update.Visibility)
|
||||
set, args = append(set, "visibility = ?"), append(args, update.Visibility.String())
|
||||
}
|
||||
if len(set) == 0 {
|
||||
return nil, fmt.Errorf("no update specified")
|
||||
@ -140,7 +139,7 @@ func (s *Store) UpdateShortcut(ctx context.Context, update *UpdateShortcut) (*Sh
|
||||
id = ?
|
||||
RETURNING id, creator_id, created_ts, updated_ts, row_status, name, link, description, visibility
|
||||
`
|
||||
var shortcut *Shortcut
|
||||
shortcut := &Shortcut{}
|
||||
if err := tx.QueryRowContext(ctx, query, args...).Scan(
|
||||
&shortcut.ID,
|
||||
&shortcut.CreatorID,
|
||||
@ -275,7 +274,7 @@ func listShortcuts(ctx context.Context, tx *sql.Tx, find *FindShortcut) ([]*Shor
|
||||
|
||||
list := make([]*Shortcut, 0)
|
||||
for rows.Next() {
|
||||
var shortcut Shortcut
|
||||
shortcut := &Shortcut{}
|
||||
if err := rows.Scan(
|
||||
&shortcut.ID,
|
||||
&shortcut.CreatorID,
|
||||
@ -289,8 +288,7 @@ func listShortcuts(ctx context.Context, tx *sql.Tx, find *FindShortcut) ([]*Shor
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list = append(list, &shortcut)
|
||||
list = append(list, shortcut)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
|
@ -272,7 +272,7 @@ func listUsers(ctx context.Context, tx *sql.Tx, find *FindUser) ([]*User, error)
|
||||
|
||||
list := make([]*User, 0)
|
||||
for rows.Next() {
|
||||
user := User{}
|
||||
user := &User{}
|
||||
if err := rows.Scan(
|
||||
&user.ID,
|
||||
&user.CreatedTs,
|
||||
@ -286,7 +286,7 @@ func listUsers(ctx context.Context, tx *sql.Tx, find *FindUser) ([]*User, error)
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list = append(list, &user)
|
||||
list = append(list, user)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
|
@ -115,7 +115,7 @@ func listUserSettings(ctx context.Context, tx *sql.Tx, find *FindUserSetting) ([
|
||||
|
||||
userSettingMessageList := make([]*UserSetting, 0)
|
||||
for rows.Next() {
|
||||
var userSettingMessage UserSetting
|
||||
userSettingMessage := &UserSetting{}
|
||||
if err := rows.Scan(
|
||||
&userSettingMessage.UserID,
|
||||
&userSettingMessage.Key,
|
||||
@ -123,7 +123,7 @@ func listUserSettings(ctx context.Context, tx *sql.Tx, find *FindUserSetting) ([
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
userSettingMessageList = append(userSettingMessageList, &userSettingMessage)
|
||||
userSettingMessageList = append(userSettingMessageList, userSettingMessage)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user