mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Addressing review comments
This commit is contained in:
@@ -60,6 +60,8 @@ func (m *mock) UpdateApp(ctx context.Context, app *models.App) (*models.App, err
|
||||
}
|
||||
|
||||
func (m *mock) RemoveApp(ctx context.Context, appName string) error {
|
||||
m.batchDeleteCalls(ctx, appName)
|
||||
m.batchDeleteRoutes(ctx, appName)
|
||||
for i, a := range m.Apps {
|
||||
if a.Name == appName {
|
||||
m.Apps = append(m.Apps[:i], m.Apps[i+1:]...)
|
||||
@@ -157,7 +159,7 @@ func (m *mock) GetCalls(ctx context.Context, filter *models.CallFilter) ([]*mode
|
||||
return m.Calls, nil
|
||||
}
|
||||
|
||||
func (m *mock) BatchDeleteCalls(ctx context.Context, appName string) error {
|
||||
func (m *mock) batchDeleteCalls(ctx context.Context, appName string) error {
|
||||
newCalls := []*models.Call{}
|
||||
for _, c := range m.Calls {
|
||||
if c.AppName != appName {
|
||||
@@ -168,7 +170,7 @@ func (m *mock) BatchDeleteCalls(ctx context.Context, appName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mock) BatchDeleteRoutes(ctx context.Context, appName string) error {
|
||||
func (m *mock) batchDeleteRoutes(ctx context.Context, appName string) error {
|
||||
newRoutes := []*models.Route{}
|
||||
for _, c := range m.Routes {
|
||||
if c.AppName != appName {
|
||||
|
||||
@@ -221,10 +221,16 @@ func (ds *sqlStore) UpdateApp(ctx context.Context, newapp *models.App) (*models.
|
||||
}
|
||||
|
||||
func (ds *sqlStore) RemoveApp(ctx context.Context, appName string) error {
|
||||
ds.db.ExecContext(ctx, ds.db.Rebind(
|
||||
`DELETE FROM routes, calls, logs WHERE app_name=?`), appName)
|
||||
query := ds.db.Rebind(`DELETE FROM apps WHERE name = ?`)
|
||||
_, err := ds.db.ExecContext(ctx, query, appName)
|
||||
res, err := ds.db.ExecContext(ctx, query, appName)
|
||||
if _, err := res.RowsAffected(); err != nil {
|
||||
return models.ErrAppsNotFound
|
||||
}
|
||||
_, err = ds.db.ExecContext(ctx, ds.db.Rebind(
|
||||
`DELETE FROM routes, calls, logs WHERE app_name=?`), appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -624,24 +630,6 @@ func (ds *sqlStore) DeleteLog(ctx context.Context, appName, callID string) error
|
||||
return err
|
||||
}
|
||||
|
||||
func (ds *sqlStore) BatchDeleteLogs(ctx context.Context, appName string) error {
|
||||
query := ds.db.Rebind(`DELETE FROM logs WHERE app_name=?`)
|
||||
_, err := ds.db.ExecContext(ctx, query, appName)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ds *sqlStore) BatchDeleteCalls(ctx context.Context, appName string) error {
|
||||
query := ds.db.Rebind(`DELETE FROM calls WHERE app_name=?`)
|
||||
_, err := ds.db.ExecContext(ctx, query, appName)
|
||||
return err
|
||||
}
|
||||
|
||||
func (ds *sqlStore) BatchDeleteRoutes(ctx context.Context, appName string) error {
|
||||
query := ds.db.Rebind(`DELETE FROM routes WHERE app_name=?`)
|
||||
_, err := ds.db.ExecContext(ctx, query, appName)
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO scrap for sqlx scanx ?? some things aren't perfect (e.g. config is a json string)
|
||||
type RowScanner interface {
|
||||
Scan(dest ...interface{}) error
|
||||
|
||||
@@ -45,12 +45,3 @@ func (m *mock) DeleteLog(ctx context.Context, appName, callID string) error {
|
||||
delete(m.Logs, callID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mock) BatchDeleteLogs(ctx context.Context, appName string) error {
|
||||
for _, log := range m.Logs {
|
||||
if log.AppName == appName {
|
||||
m.DeleteLog(ctx, appName, log.CallID)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ func (s *Server) handleAppDelete(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.FireBeforeAppDelete(ctx, app)
|
||||
|
||||
err = s.Datastore.RemoveApp(ctx, app.Name)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, err)
|
||||
|
||||
Reference in New Issue
Block a user