@@ -135,8 +135,8 @@ func (e *EndpointsManager) CreateEndpoint(ctx context.Context, data EndpointData
135135 log .Warn ("endpoint creation failed name validation" , "name" , data .Name )
136136 return EndpointEntity {}, crud .ErrInvalidInput
137137 }
138- if data .Method == "" || data . URL == "" {
139- log .Warn ("endpoint creation failed - method and URL required" , "method" , data .Method , "url" , data . URL )
138+ if data .Method == "" {
139+ log .Warn ("endpoint creation failed - method required" , "method" , data .Method )
140140 return EndpointEntity {}, crud .ErrInvalidInput
141141 }
142142
@@ -174,6 +174,37 @@ func (e *EndpointsManager) CreateEndpoint(ctx context.Context, data EndpointData
174174 return EndpointEntity {Endpoint : endpoint }, nil
175175}
176176
177+ func (e * EndpointsManager ) UpdateEndpointName (ctx context.Context , id int64 , name string ) (EndpointEntity , error ) {
178+ if err := crud .ValidateID (id ); err != nil {
179+ log .Warn ("endpoint update failed ID validation" , "id" , id )
180+ return EndpointEntity {}, crud .ErrInvalidInput
181+ }
182+
183+ if err := crud .ValidateName (name ); err != nil {
184+ log .Warn ("endpoint update failed name validation" , "name" , name )
185+ return EndpointEntity {}, crud .ErrInvalidInput
186+ }
187+
188+ log .Debug ("updating endpoint name" , "id" , id , "name" , name )
189+
190+ endpoint , err := e .DB .UpdateEndpointName (ctx , database.UpdateEndpointNameParams {
191+ Name : name ,
192+ ID : id ,
193+ })
194+
195+ if err != nil {
196+ if err == sql .ErrNoRows {
197+ log .Debug ("endpoint not found for update" , "id" , id )
198+ return EndpointEntity {}, crud .ErrNotFound
199+ }
200+ log .Error ("failed to update endpoint" , "id" , id , "name" , name , "error" , err )
201+ return EndpointEntity {}, err
202+ }
203+
204+ log .Info ("updated endpoint" , "id" , endpoint .ID , "name" , endpoint .Name )
205+ return EndpointEntity {Endpoint : endpoint }, nil
206+ }
207+
177208func (e * EndpointsManager ) UpdateEndpoint (ctx context.Context , id int64 , data EndpointData ) (EndpointEntity , error ) {
178209 if err := crud .ValidateID (id ); err != nil {
179210 log .Warn ("endpoint update failed ID validation" , "id" , id )
@@ -183,8 +214,8 @@ func (e *EndpointsManager) UpdateEndpoint(ctx context.Context, id int64, data En
183214 log .Warn ("endpoint update failed name validation" , "name" , data .Name )
184215 return EndpointEntity {}, crud .ErrInvalidInput
185216 }
186- if data .Method == "" || data . URL == "" {
187- log .Warn ("endpoint update failed - method and URL required" , "method" , data .Method , "url" , data . URL )
217+ if data .Method == "" {
218+ log .Warn ("endpoint update failed - method required" , "method" , data .Method )
188219 return EndpointEntity {}, crud .ErrInvalidInput
189220 }
190221
0 commit comments