CloudMigrations: Add sorting and error filtering to Snapshot Results backend (#102753)
* implement sorting * swagger gen * minor fixes * clean up param reading * add todo * add errors only prop * codegen stuff * fix copy paste error * forgot the api gen * cleanup * remove tests that are obe * fix test
This commit is contained in:
@@ -241,7 +241,7 @@ func (ss *sqlStore) deleteSnapshot(ctx context.Context, snapshotUid string) erro
|
||||
})
|
||||
}
|
||||
|
||||
func (ss *sqlStore) GetSnapshotByUID(ctx context.Context, orgID int64, sessionUid, uid string, resultPage int, resultLimit int) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
func (ss *sqlStore) GetSnapshotByUID(ctx context.Context, orgID int64, sessionUid, uid string, params cloudmigration.SnapshotResultQueryParams) (*cloudmigration.CloudMigrationSnapshot, error) {
|
||||
// first we check if the session exists, using orgId and sessionUid
|
||||
session, err := ss.GetMigrationSessionByUID(ctx, orgID, sessionUid)
|
||||
if err != nil || session == nil {
|
||||
@@ -272,7 +272,7 @@ func (ss *sqlStore) GetSnapshotByUID(ctx context.Context, orgID int64, sessionUi
|
||||
snapshot.EncryptionKey = []byte(secret)
|
||||
}
|
||||
|
||||
resources, err := ss.getSnapshotResources(ctx, uid, resultPage, resultLimit)
|
||||
resources, err := ss.getSnapshotResources(ctx, uid, params)
|
||||
if err == nil {
|
||||
snapshot.Resources = resources
|
||||
}
|
||||
@@ -421,19 +421,17 @@ func (ss *sqlStore) UpdateSnapshotResources(ctx context.Context, snapshotUid str
|
||||
})
|
||||
}
|
||||
|
||||
func (ss *sqlStore) getSnapshotResources(ctx context.Context, snapshotUid string, page int, limit int) ([]cloudmigration.CloudMigrationResource, error) {
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
if limit == 0 {
|
||||
limit = 100
|
||||
}
|
||||
func (ss *sqlStore) getSnapshotResources(ctx context.Context, snapshotUid string, params cloudmigration.SnapshotResultQueryParams) ([]cloudmigration.CloudMigrationResource, error) {
|
||||
page, limit, col, dir, errorsOnly := int(params.ResultPage), int(params.ResultLimit), string(params.SortColumn), string(params.SortOrder), params.ErrorsOnly
|
||||
|
||||
var resources []cloudmigration.CloudMigrationResource
|
||||
err := ss.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
offset := (page - 1) * limit
|
||||
sess.Limit(limit, offset)
|
||||
return sess.OrderBy("id ASC").Find(&resources, &cloudmigration.CloudMigrationResource{
|
||||
if errorsOnly {
|
||||
sess.Where("status = ?", cloudmigration.ItemStatusError)
|
||||
}
|
||||
return sess.OrderBy(fmt.Sprintf("%s %s", col, dir)).Find(&resources, &cloudmigration.CloudMigrationResource{
|
||||
SnapshotUID: snapshotUid,
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user