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