|  | 
| 18 | 18 | package service | 
| 19 | 19 | 
 | 
| 20 | 20 | import ( | 
|  | 21 | +	"errors" | 
| 21 | 22 | 	appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean" | 
| 22 | 23 | 	"github.com/devtron-labs/devtron/pkg/appStore/deployment/repository" | 
| 23 | 24 | 	appStoreValuesRepository "github.com/devtron-labs/devtron/pkg/appStore/values/repository" | 
| @@ -69,7 +70,7 @@ type ChartGroupList struct { | 
| 69 | 70 | 	Groups []*ChartGroupBean `json:"groups,omitempty"` | 
| 70 | 71 | } | 
| 71 | 72 | type ChartGroupBean struct { | 
| 72 |  | -	Name               string                 `json:"name,omitempty" validate:"name-component,max=200"` | 
|  | 73 | +	Name               string                 `json:"name,omitempty" validate:"name-component,max=200,min=5"` | 
| 73 | 74 | 	Description        string                 `json:"description,omitempty"` | 
| 74 | 75 | 	Id                 int                    `json:"id,omitempty"` | 
| 75 | 76 | 	ChartGroupEntries  []*ChartGroupEntryBean `json:"chartGroupEntries,omitempty"` | 
| @@ -108,8 +109,21 @@ type InstalledChart struct { | 
| 108 | 109 | 	InstalledAppId int `json:"installedAppId,omitempty"` | 
| 109 | 110 | } | 
| 110 | 111 | 
 | 
|  | 112 | +const AppNameAlreadyExistsError = "A chart with this name already exist" | 
|  | 113 | + | 
| 111 | 114 | func (impl *ChartGroupServiceImpl) CreateChartGroup(req *ChartGroupBean) (*ChartGroupBean, error) { | 
| 112 | 115 | 	impl.Logger.Debugw("chart group create request", "req", req) | 
|  | 116 | + | 
|  | 117 | +	exist, err := impl.chartGroupRepository.FindByName(req.Name) | 
|  | 118 | +	if err != nil { | 
|  | 119 | +		impl.Logger.Errorw("error in creating chart group", "req", req, "err", err) | 
|  | 120 | +		return nil, err | 
|  | 121 | +	} | 
|  | 122 | +	if exist { | 
|  | 123 | +		impl.Logger.Errorw("Chart with this name already exist", "req", req, "err", err) | 
|  | 124 | +		return nil, errors.New(AppNameAlreadyExistsError) | 
|  | 125 | +	} | 
|  | 126 | + | 
| 113 | 127 | 	chartGrouModel := &repository.ChartGroup{ | 
| 114 | 128 | 		Name:        req.Name, | 
| 115 | 129 | 		Description: req.Description, | 
|  | 
0 commit comments