@@ -20,6 +20,7 @@ import (
20
20
"encoding/json"
21
21
"errors"
22
22
"github.com/devtron-labs/devtron/internal/sql/repository"
23
+ "github.com/devtron-labs/devtron/pkg/attributes/adapter"
23
24
"github.com/devtron-labs/devtron/pkg/attributes/bean"
24
25
"github.com/go-pg/pg"
25
26
"go.uber.org/zap"
@@ -118,22 +119,22 @@ func (impl UserAttributesServiceImpl) PatchUserAttributes(request *UserAttribute
118
119
119
120
existingData , err := impl .parseJSONValue (existingAttribute .Value , "existing" )
120
121
if err != nil {
122
+ impl .logger .Errorw ("error in parsing json" , "existingAttribute.Value" , existingAttribute .Value , "error" , err )
121
123
return nil , err
122
124
}
123
125
124
126
newData , err := impl .parseJSONValue (request .Value , "request" )
125
127
if err != nil {
128
+ impl .logger .Errorw ("error in parsing request json" , "request.Value" , request .Value , "error" , err )
126
129
return nil , err
127
130
}
128
131
129
- // Merge the data
130
132
hasChanges := impl .mergeUserAttributesData (existingData , newData )
131
133
if ! hasChanges {
132
134
impl .logger .Infow ("no changes detected, skipping update" , "key" , request .Key )
133
135
return existingAttribute , nil
134
136
}
135
137
136
- // Update in database and return result
137
138
return impl .updateAttributeInDatabase (request , existingData )
138
139
}
139
140
@@ -156,14 +157,12 @@ func (impl UserAttributesServiceImpl) parseJSONValue(jsonValue, context string)
156
157
157
158
// updateAttributeInDatabase updates the merged data in the database
158
159
func (impl UserAttributesServiceImpl ) updateAttributeInDatabase (request * UserAttributesDto , mergedData map [string ]interface {}) (* UserAttributesDto , error ) {
159
- // Convert merged data back to JSON
160
160
mergedJSON , err := json .Marshal (mergedData )
161
161
if err != nil {
162
162
impl .logger .Errorw ("error converting merged data to JSON" , "data" , mergedData , "error" , err )
163
163
return nil , errors .New ("error occurred while processing user attributes" )
164
164
}
165
165
166
- // Create DAO for database update
167
166
dao := & repository.UserAttributesDao {
168
167
EmailId : request .EmailId ,
169
168
Key : request .Key ,
@@ -179,17 +178,7 @@ func (impl UserAttributesServiceImpl) updateAttributeInDatabase(request *UserAtt
179
178
}
180
179
181
180
// Build and return response
182
- return impl .buildResponseDTO (request , string (mergedJSON )), nil
183
- }
184
-
185
- // buildResponseDTO creates the response DTO
186
- func (impl UserAttributesServiceImpl ) buildResponseDTO (request * UserAttributesDto , mergedValue string ) * UserAttributesDto {
187
- return & UserAttributesDto {
188
- EmailId : request .EmailId ,
189
- Key : request .Key ,
190
- Value : mergedValue ,
191
- UserId : request .UserId ,
192
- }
181
+ return adapter .BuildResponseDTO (request , string (mergedJSON )), nil
193
182
}
194
183
195
184
// mergeUserAttributesData merges newData into existingData with special handling for resources
@@ -264,19 +253,6 @@ func (impl UserAttributesServiceImpl) mergeResourceTypes(existingResources, newR
264
253
return hasChanges
265
254
}
266
255
267
- // initializeSupportedResourceTypes ensures all supported resource types are initialized
268
- func (impl UserAttributesServiceImpl ) initializeSupportedResourceTypes (existingResources map [string ]interface {}) {
269
- supportedResourceTypes := []string {"cluster" , "job" , "app-group" , "application/devtron-application" }
270
-
271
- for _ , resourceType := range supportedResourceTypes {
272
- if existingResources [resourceType ] == nil {
273
- existingResources [resourceType ] = map [string ]interface {}{
274
- "recently-visited" : []interface {}{},
275
- }
276
- }
277
- }
278
- }
279
-
280
256
func (impl UserAttributesServiceImpl ) GetUserAttribute (request * UserAttributesDto ) (* UserAttributesDto , error ) {
281
257
282
258
dao := & repository.UserAttributesDao {
0 commit comments