Skip to content

Commit

Permalink
add DBServiceRepo GetFieldDistinctValue method
Browse files Browse the repository at this point in the history
  • Loading branch information
BugsGuru committed Jul 17, 2024
1 parent cf16cd3 commit 5936dcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/dms/biz/db_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type DBServiceRepo interface {
UpdateDBService(ctx context.Context, dbService *DBService) error
CountDBService(ctx context.Context) ([]DBTypeCount, error)
GetBusinessByProjectUID(ctx context.Context, projectUid string) ([]string, error)
GetFieldDistinctValue(ctx context.Context, field DBServiceField, results interface{}) error
}

type DBServiceUsecase struct {
Expand Down
9 changes: 9 additions & 0 deletions internal/dms/storage/db_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,12 @@ WHERE project_uid = ?;

return businessList, nil
}

func (d *DBServiceRepo) GetFieldDistinctValue(ctx context.Context, field biz.DBServiceField, results interface{}) error {
return transaction(d.log, ctx, d.db, func(tx *gorm.DB) error {
if err := tx.WithContext(ctx).Model(&model.DBService{}).Select(string(field)).Group(string(field)).Find(results).Error; err != nil {
return fmt.Errorf("DBServiceRepo failed to GroupByField: %v", err)
}
return nil
})
}

0 comments on commit 5936dcb

Please sign in to comment.