Skip to content

Commit 7231efe

Browse files
authored
fix: including app name in get all labels api and also introoduced optional query param (#6688)
1 parent 2e01cdb commit 7231efe

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

api/restHandler/app/appInfo/AppInfoRestHandler.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,23 @@ func (handler AppInfoRestHandlerImpl) GetAllLabels(w http.ResponseWriter, r *htt
8787
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
8888
return
8989
}
90+
propagatedLabelsOnlyStr := r.URL.Query().Get("showPropagatedOnly")
91+
92+
var propagatedLabelsOnlyBool *bool
93+
if propagatedLabelsOnlyStr != "" {
94+
if val, err := strconv.ParseBool(propagatedLabelsOnlyStr); err == nil {
95+
propagatedLabelsOnlyBool = &val
96+
} else {
97+
// Invalid boolean value provided, treat as null (nil)
98+
propagatedLabelsOnlyBool = nil
99+
handler.logger.Infow("Invalid 'showPropagatedOnly' value from quey params — defaulting to nil", propagatedLabelsOnlyStr)
100+
}
101+
}
102+
90103
token := r.Header.Get("token")
91104
results := make([]*bean.AppLabelDto, 0)
92-
labels, err := handler.appService.FindAll()
105+
106+
labels, err := handler.appService.FindAll(propagatedLabelsOnlyBool)
93107
if err != nil {
94108
handler.logger.Errorw("service err, GetAllLabels", "err", err)
95109
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

internal/sql/repository/pipelineConfig/AppLabelsRepository.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type AppLabelRepository interface {
4141
Delete(model *AppLabel, tx *pg.Tx) error
4242
FindById(id int) (*AppLabel, error)
4343
FindAllByIds(ids []int) ([]*AppLabel, error)
44-
FindAll() ([]*AppLabel, error)
44+
FindAll(propagated *bool) ([]*AppLabel, error)
4545
FindByLabelKey(key string) ([]*AppLabel, error)
4646
FindByAppIdAndKeyAndValue(appId int, key string, value string) (*AppLabel, error)
4747
FindByLabelValue(label string) ([]*AppLabel, error)
@@ -89,9 +89,16 @@ func (impl AppLabelRepositoryImpl) FindAllByIds(ids []int) ([]*AppLabel, error)
8989
err := impl.dbConnection.Model(&models).Where("id in (?)", pg.In(ids)).Order("updated_on desc").Select()
9090
return models, err
9191
}
92-
func (impl AppLabelRepositoryImpl) FindAll() ([]*AppLabel, error) {
92+
func (impl AppLabelRepositoryImpl) FindAll(propagated *bool) ([]*AppLabel, error) {
9393
var models []*AppLabel
94-
err := impl.dbConnection.Model(&models).Order("updated_on desc").Select()
94+
query := impl.dbConnection.Model(&models).
95+
Column("app_label.*", "App").
96+
Order("updated_on desc")
97+
// if propagated flag is not set then show all labels
98+
if propagated != nil {
99+
query = query.Where("propagate = ?", *propagated)
100+
}
101+
err := query.Select()
95102
return models, err
96103
}
97104
func (impl AppLabelRepositoryImpl) FindByLabelKey(key string) ([]*AppLabel, error) {

pkg/app/AppCrudOperationService.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type CrudOperationServiceConfig struct {
5959
type AppCrudOperationService interface {
6060
Create(request *bean.AppLabelDto, tx *pg.Tx) (*bean.AppLabelDto, error)
6161
FindById(id int) (*bean.AppLabelDto, error)
62-
FindAll() ([]*bean.AppLabelDto, error)
62+
FindAll(propagated *bool) ([]*bean.AppLabelDto, error)
6363
GetAppMetaInfo(appId int, installedAppId int, envId int) (*bean.AppMetaInfoDto, error)
6464
GetHelmAppMetaInfo(appId string) (*bean.AppMetaInfoDto, error)
6565
GetAppLabelsForDeployment(ctx context.Context, appId int, appName, envName string) ([]byte, error)
@@ -318,9 +318,9 @@ func (impl AppCrudOperationServiceImpl) FindById(id int) (*bean.AppLabelDto, err
318318
return label, nil
319319
}
320320

321-
func (impl AppCrudOperationServiceImpl) FindAll() ([]*bean.AppLabelDto, error) {
321+
func (impl AppCrudOperationServiceImpl) FindAll(propagated *bool) ([]*bean.AppLabelDto, error) {
322322
results := make([]*bean.AppLabelDto, 0)
323-
models, err := impl.appLabelRepository.FindAll()
323+
models, err := impl.appLabelRepository.FindAll(propagated)
324324
if err != nil && err != pg.ErrNoRows {
325325
impl.logger.Errorw("error in fetching FindAll app labels", "error", err)
326326
return nil, err
@@ -334,6 +334,7 @@ func (impl AppCrudOperationServiceImpl) FindAll() ([]*bean.AppLabelDto, error) {
334334
Key: model.Key,
335335
Value: model.Value,
336336
Propagate: model.Propagate,
337+
AppName: model.App.AppName,
337338
}
338339
results = append(results, dto)
339340
}

pkg/bean/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ type AppLabelDto struct {
901901
Value string `json:"value,notnull"`
902902
Propagate bool `json:"propagate,notnull"`
903903
AppId int `json:"appId,omitempty"`
904+
AppName string `json:"appName,omitempty"`
904905
UserId int32 `json:"-"`
905906
}
906907

wire_gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)