Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion api/restHandler/app/appInfo/AppInfoRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,23 @@ func (handler AppInfoRestHandlerImpl) GetAllLabels(w http.ResponseWriter, r *htt
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return
}
propagatedLabelsOnlyStr := r.URL.Query().Get("showPropagatedOnly")

var propagatedLabelsOnlyBool *bool
if propagatedLabelsOnlyStr != "" {
if val, err := strconv.ParseBool(propagatedLabelsOnlyStr); err == nil {
propagatedLabelsOnlyBool = &val
} else {
// Invalid boolean value provided, treat as null (nil)
propagatedLabelsOnlyBool = nil
handler.logger.Infow("Invalid 'showPropagatedOnly' value from quey params — defaulting to nil", propagatedLabelsOnlyStr)
}
}

token := r.Header.Get("token")
results := make([]*bean.AppLabelDto, 0)
labels, err := handler.appService.FindAll()

labels, err := handler.appService.FindAll(propagatedLabelsOnlyBool)
if err != nil {
handler.logger.Errorw("service err, GetAllLabels", "err", err)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
Expand Down
13 changes: 10 additions & 3 deletions internal/sql/repository/pipelineConfig/AppLabelsRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type AppLabelRepository interface {
Delete(model *AppLabel, tx *pg.Tx) error
FindById(id int) (*AppLabel, error)
FindAllByIds(ids []int) ([]*AppLabel, error)
FindAll() ([]*AppLabel, error)
FindAll(propagated *bool) ([]*AppLabel, error)
FindByLabelKey(key string) ([]*AppLabel, error)
FindByAppIdAndKeyAndValue(appId int, key string, value string) (*AppLabel, error)
FindByLabelValue(label string) ([]*AppLabel, error)
Expand Down Expand Up @@ -89,9 +89,16 @@ func (impl AppLabelRepositoryImpl) FindAllByIds(ids []int) ([]*AppLabel, error)
err := impl.dbConnection.Model(&models).Where("id in (?)", pg.In(ids)).Order("updated_on desc").Select()
return models, err
}
func (impl AppLabelRepositoryImpl) FindAll() ([]*AppLabel, error) {
func (impl AppLabelRepositoryImpl) FindAll(propagated *bool) ([]*AppLabel, error) {
var models []*AppLabel
err := impl.dbConnection.Model(&models).Order("updated_on desc").Select()
query := impl.dbConnection.Model(&models).
Column("app_label.*", "App").
Order("updated_on desc")
// if propagated flag is not set then show all labels
if propagated != nil {
query = query.Where("propagate = ?", *propagated)
}
err := query.Select()
return models, err
}
func (impl AppLabelRepositoryImpl) FindByLabelKey(key string) ([]*AppLabel, error) {
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/AppCrudOperationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type CrudOperationServiceConfig struct {
type AppCrudOperationService interface {
Create(request *bean.AppLabelDto, tx *pg.Tx) (*bean.AppLabelDto, error)
FindById(id int) (*bean.AppLabelDto, error)
FindAll() ([]*bean.AppLabelDto, error)
FindAll(propagated *bool) ([]*bean.AppLabelDto, error)
GetAppMetaInfo(appId int, installedAppId int, envId int) (*bean.AppMetaInfoDto, error)
GetHelmAppMetaInfo(appId string) (*bean.AppMetaInfoDto, error)
GetAppLabelsForDeployment(ctx context.Context, appId int, appName, envName string) ([]byte, error)
Expand Down Expand Up @@ -318,9 +318,9 @@ func (impl AppCrudOperationServiceImpl) FindById(id int) (*bean.AppLabelDto, err
return label, nil
}

func (impl AppCrudOperationServiceImpl) FindAll() ([]*bean.AppLabelDto, error) {
func (impl AppCrudOperationServiceImpl) FindAll(propagated *bool) ([]*bean.AppLabelDto, error) {
results := make([]*bean.AppLabelDto, 0)
models, err := impl.appLabelRepository.FindAll()
models, err := impl.appLabelRepository.FindAll(propagated)
if err != nil && err != pg.ErrNoRows {
impl.logger.Errorw("error in fetching FindAll app labels", "error", err)
return nil, err
Expand All @@ -334,6 +334,7 @@ func (impl AppCrudOperationServiceImpl) FindAll() ([]*bean.AppLabelDto, error) {
Key: model.Key,
Value: model.Value,
Propagate: model.Propagate,
AppName: model.App.AppName,
}
results = append(results, dto)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/bean/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ type AppLabelDto struct {
Value string `json:"value,notnull"`
Propagate bool `json:"propagate,notnull"`
AppId int `json:"appId,omitempty"`
AppName string `json:"appName,omitempty"`
UserId int32 `json:"-"`
}

Expand Down
2 changes: 1 addition & 1 deletion wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.