@@ -26,7 +26,6 @@ import (
26
26
"github.com/devtron-labs/devtron/pkg/appStore/chartGroup"
27
27
"github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
28
28
"github.com/devtron-labs/devtron/pkg/auth/user"
29
- "github.com/gorilla/mux"
30
29
"go.uber.org/zap"
31
30
"gopkg.in/go-playground/validator.v9"
32
31
)
@@ -67,7 +66,7 @@ type ChartGroupRestHandler interface {
67
66
func (impl * ChartGroupRestHandlerImpl ) CreateChartGroup (w http.ResponseWriter , r * http.Request ) {
68
67
userId , err := impl .userAuthService .GetLoggedInUser (r )
69
68
if userId == 0 || err != nil {
70
- common .WriteJsonResp (w , err , "Unauthorized User" , http . StatusUnauthorized )
69
+ common .HandleUnauthorized (w , r )
71
70
return
72
71
}
73
72
decoder := json .NewDecoder (r .Body )
@@ -112,7 +111,7 @@ func (impl *ChartGroupRestHandlerImpl) CreateChartGroup(w http.ResponseWriter, r
112
111
func (impl * ChartGroupRestHandlerImpl ) UpdateChartGroup (w http.ResponseWriter , r * http.Request ) {
113
112
userId , err := impl .userAuthService .GetLoggedInUser (r )
114
113
if userId == 0 || err != nil {
115
- common .WriteJsonResp (w , err , "Unauthorized User" , http . StatusUnauthorized )
114
+ common .HandleUnauthorized (w , r )
116
115
return
117
116
}
118
117
decoder := json .NewDecoder (r .Body )
@@ -153,7 +152,7 @@ func (impl *ChartGroupRestHandlerImpl) UpdateChartGroup(w http.ResponseWriter, r
153
152
func (impl * ChartGroupRestHandlerImpl ) SaveChartGroupEntries (w http.ResponseWriter , r * http.Request ) {
154
153
userId , err := impl .userAuthService .GetLoggedInUser (r )
155
154
if userId == 0 || err != nil {
156
- common .WriteJsonResp (w , err , "Unauthorized User" , http . StatusUnauthorized )
155
+ common .HandleUnauthorized (w , r )
157
156
return
158
157
}
159
158
decoder := json .NewDecoder (r .Body )
@@ -187,14 +186,14 @@ func (impl *ChartGroupRestHandlerImpl) SaveChartGroupEntries(w http.ResponseWrit
187
186
func (impl * ChartGroupRestHandlerImpl ) GetChartGroupWithChartMetaData (w http.ResponseWriter , r * http.Request ) {
188
187
userId , err := impl .userAuthService .GetLoggedInUser (r )
189
188
if userId == 0 || err != nil {
190
- common .WriteJsonResp (w , err , "Unauthorized User" , http . StatusUnauthorized )
189
+ common .HandleUnauthorized (w , r )
191
190
return
192
191
}
193
- vars := mux .Vars (r )
194
- chartGroupId , err := strconv .Atoi (vars ["chartGroupId" ])
192
+
193
+ // Use enhanced parameter parsing with context
194
+ chartGroupId , err := common .ExtractIntPathParamWithContext (w , r , "chartGroupId" , "chart group" )
195
195
if err != nil {
196
- impl .Logger .Errorw ("request err, GetChartGroupWithChartMetaData" , "err" , err , "chartGroupId" , chartGroupId )
197
- common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
196
+ // Error already written by ExtractIntPathParamWithContext
198
197
return
199
198
}
200
199
@@ -219,14 +218,14 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupWithChartMetaData(w http.Res
219
218
func (impl * ChartGroupRestHandlerImpl ) GetChartGroupInstallationDetail (w http.ResponseWriter , r * http.Request ) {
220
219
userId , err := impl .userAuthService .GetLoggedInUser (r )
221
220
if userId == 0 || err != nil {
222
- common .WriteJsonResp (w , err , "Unauthorized User" , http . StatusUnauthorized )
221
+ common .HandleUnauthorized (w , r )
223
222
return
224
223
}
225
- vars := mux .Vars (r )
226
- chartGroupId , err := strconv .Atoi (vars ["chartGroupId" ])
224
+
225
+ // Use enhanced parameter parsing with context
226
+ chartGroupId , err := common .ExtractIntPathParamWithContext (w , r , "chartGroupId" , "chart group" )
227
227
if err != nil {
228
- impl .Logger .Errorw ("request err, GetChartGroupInstallationDetail" , "err" , err , "chartGroupId" , chartGroupId )
229
- common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
228
+ // Error already written by ExtractIntPathParamWithContext
230
229
return
231
230
}
232
231
@@ -251,7 +250,7 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupInstallationDetail(w http.Re
251
250
func (impl * ChartGroupRestHandlerImpl ) GetChartGroupList (w http.ResponseWriter , r * http.Request ) {
252
251
userId , err := impl .userAuthService .GetLoggedInUser (r )
253
252
if userId == 0 || err != nil {
254
- common .WriteJsonResp (w , err , "Unauthorized User" , http . StatusUnauthorized )
253
+ common .HandleUnauthorized (w , r )
255
254
return
256
255
}
257
256
@@ -286,7 +285,7 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupList(w http.ResponseWriter,
286
285
func (impl * ChartGroupRestHandlerImpl ) GetChartGroupListMin (w http.ResponseWriter , r * http.Request ) {
287
286
userId , err := impl .userAuthService .GetLoggedInUser (r )
288
287
if userId == 0 || err != nil {
289
- common .WriteJsonResp (w , err , "Unauthorized User" , http . StatusUnauthorized )
288
+ common .HandleUnauthorized (w , r )
290
289
return
291
290
}
292
291
@@ -321,7 +320,7 @@ func (impl *ChartGroupRestHandlerImpl) GetChartGroupListMin(w http.ResponseWrite
321
320
func (impl * ChartGroupRestHandlerImpl ) DeleteChartGroup (w http.ResponseWriter , r * http.Request ) {
322
321
userId , err := impl .userAuthService .GetLoggedInUser (r )
323
322
if userId == 0 || err != nil {
324
- common .WriteJsonResp (w , err , "Unauthorized User" , http . StatusUnauthorized )
323
+ common .HandleUnauthorized (w , r )
325
324
return
326
325
}
327
326
decoder := json .NewDecoder (r .Body )
0 commit comments