Skip to content

Commit 231d3f4

Browse files
authored
Libs: implement the patch endpoints for partial updates (#987)
This implements the `patch` functions for application, endpoint and event type. Fixes #608
1 parent dd242a8 commit 231d3f4

File tree

25 files changed

+1152
-583
lines changed

25 files changed

+1152
-583
lines changed

csharp/Svix/Abstractions/IApplication.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ Task<ApplicationOut> GetAsync(string appId, string idempotencyKey = default,
3232

3333
Task<ApplicationOut> UpdateAsync(string appId, ApplicationIn application, string idempotencyKey = default,
3434
CancellationToken cancellationToken = default);
35+
36+
ApplicationOut Patch(string appId, ApplicationPatch application, string idempotencyKey = default);
37+
38+
Task<ApplicationOut> PatchAsync(string appId, ApplicationPatch application, string idempotencyKey = default,
39+
CancellationToken cancellationToken = default);
3540
}
3641
}

csharp/Svix/Abstractions/IEndpoint.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ Task<bool> RotateSecretAsync(string appId, string endpointId, EndpointSecretRota
5858
Task<EndpointOut> UpdateAsync(string appId, string endpointId, EndpointUpdate endpoint, string idempotencyKey = default,
5959
CancellationToken cancellationToken = default);
6060

61+
EndpointOut Patch(string appId, string endpointId, EndpointPatch endpoint, string idempotencyKey = default);
62+
63+
Task<EndpointOut> PatchAsync(string appId, string endpointId, EndpointPatch endpoint, string idempotencyKey = default,
64+
CancellationToken cancellationToken = default);
65+
6166
bool UpdateHeaders(string appId, string endpointId, EndpointHeadersIn headers, string idempotencyKey = default);
6267

6368
Task<bool> UpdateHeadersAsync(string appId, string endpointId, EndpointHeadersIn headers,

csharp/Svix/Abstractions/IEventType.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ Task<List<EventTypeOut>> ListAsync(EventTypeListOptions options = null, string i
3232

3333
Task<EventTypeOut> UpdateAsync(string eventType, EventTypeUpdate update, string idempotencyKey = default,
3434
CancellationToken cancellationToken = default);
35+
36+
EventTypeOut Patch(string eventType, EventTypePatch update, string idempotencyKey = default);
37+
38+
Task<EventTypeOut> PatchAsync(string eventType, EventTypePatch update, string idempotencyKey = default,
39+
CancellationToken cancellationToken = default);
3540
}
3641
}

csharp/Svix/Application.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,48 @@ public async Task<ApplicationOut> UpdateAsync(string appId, ApplicationIn applic
236236
return null;
237237
}
238238
}
239+
240+
public ApplicationOut Patch(string appId, ApplicationPatch application, string idempotencyKey = default)
241+
{
242+
try
243+
{
244+
var lApplication = _applicationApi.V1ApplicationPatch(
245+
appId,
246+
application);
247+
248+
return lApplication;
249+
}
250+
catch (ApiException e)
251+
{
252+
Logger?.LogError(e, $"{nameof(Patch)} failed");
253+
254+
if (Throw)
255+
throw;
256+
257+
return null;
258+
}
259+
}
260+
261+
public async Task<ApplicationOut> PatchAsync(string appId, ApplicationPatch application, string idempotencyKey = default, CancellationToken cancellationToken = default)
262+
{
263+
try
264+
{
265+
var lApplication = await _applicationApi.V1ApplicationPatchAsync(
266+
appId,
267+
application,
268+
cancellationToken);
269+
270+
return lApplication;
271+
}
272+
catch (ApiException e)
273+
{
274+
Logger?.LogError(e, $"{nameof(PatchAsync)} failed");
275+
276+
if (Throw)
277+
throw;
278+
279+
return null;
280+
}
281+
}
239282
}
240283
}

csharp/Svix/Endpoint.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,52 @@ public async Task<EndpointOut> UpdateAsync(string appId, string endpointId, Endp
479479
}
480480
}
481481

482+
public EndpointOut Patch(string appId, string endpointId, EndpointPatch endpoint, string idempotencyKey = default)
483+
{
484+
try
485+
{
486+
var lEndpoint = _endpointApi.V1EndpointPatch(
487+
appId,
488+
endpointId,
489+
endpoint);
490+
491+
return lEndpoint;
492+
}
493+
catch (ApiException e)
494+
{
495+
Logger?.LogError(e, $"{nameof(Patch)} failed");
496+
497+
if (Throw)
498+
throw;
499+
500+
return null;
501+
}
502+
}
503+
504+
public async Task<EndpointOut> PatchAsync(string appId, string endpointId, EndpointPatch endpoint, string idempotencyKey = default,
505+
CancellationToken cancellationToken = default)
506+
{
507+
try
508+
{
509+
var lEndpoint = await _endpointApi.V1EndpointPatchAsync(
510+
appId,
511+
endpointId,
512+
endpoint,
513+
cancellationToken);
514+
515+
return lEndpoint;
516+
}
517+
catch (ApiException e)
518+
{
519+
Logger?.LogError(e, $"{nameof(PatchAsync)} failed");
520+
521+
if (Throw)
522+
throw;
523+
524+
return null;
525+
}
526+
}
527+
482528
public bool UpdateHeaders(string appId, string endpointId, EndpointHeadersIn headers, string idempotencyKey = default)
483529
{
484530
try

csharp/Svix/EventType.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,49 @@ public async Task<EventTypeOut> UpdateAsync(string eventType, EventTypeUpdate up
241241
return null;
242242
}
243243
}
244+
245+
public EventTypeOut Patch(string eventType, EventTypePatch update, string idempotencyKey = default)
246+
{
247+
try
248+
{
249+
var lEventType = _eventTypeApi.V1EventTypePatch(
250+
eventType,
251+
update);
252+
253+
return lEventType;
254+
}
255+
catch (ApiException e)
256+
{
257+
Logger?.LogError(e, $"{nameof(Patch)} failed");
258+
259+
if (Throw)
260+
throw;
261+
262+
return null;
263+
}
264+
}
265+
266+
public async Task<EventTypeOut> PatchAsync(string eventType, EventTypePatch update, string idempotencyKey = default,
267+
CancellationToken cancellationToken = default)
268+
{
269+
try
270+
{
271+
var lEventType = await _eventTypeApi.V1EventTypePatchAsync(
272+
eventType,
273+
update,
274+
cancellationToken);
275+
276+
return lEventType;
277+
}
278+
catch (ApiException e)
279+
{
280+
Logger?.LogError(e, $"{nameof(PatchAsync)} failed");
281+
282+
if (Throw)
283+
throw;
284+
285+
return null;
286+
}
287+
}
244288
}
245289
}

go/application.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type (
1010
ListResponseApplicationOut openapi.ListResponseApplicationOut
1111
ApplicationIn openapi.ApplicationIn
1212
ApplicationOut openapi.ApplicationOut
13+
ApplicationPatch openapi.ApplicationPatch
1314
)
1415

1516
type Application struct {
@@ -105,6 +106,17 @@ func (a *Application) Update(ctx context.Context, appId string, applicationIn *A
105106
return &ret, nil
106107
}
107108

109+
func (a *Application) Patch(ctx context.Context, appId string, applicationPatch *ApplicationPatch) (*ApplicationOut, error) {
110+
req := a.api.ApplicationApi.V1ApplicationPatch(ctx, appId)
111+
req = req.ApplicationPatch(openapi.ApplicationPatch(*applicationPatch))
112+
resp, res, err := req.Execute()
113+
if err != nil {
114+
return nil, wrapError(err, res)
115+
}
116+
ret := ApplicationOut(resp)
117+
return &ret, nil
118+
}
119+
108120
func (a *Application) Delete(ctx context.Context, appId string) error {
109121
req := a.api.ApplicationApi.V1ApplicationDelete(ctx, appId)
110122
res, err := req.Execute()

go/endpoint.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type (
1212
EndpointIn openapi.EndpointIn
1313
EndpointUpdate openapi.EndpointUpdate
1414
EndpointOut openapi.EndpointOut
15+
EndpointPatch openapi.EndpointPatch
1516
EndpointSecretOut openapi.EndpointSecretOut
1617
EndpointSecretRotateIn openapi.EndpointSecretRotateIn
1718
EndpointTransformationIn openapi.EndpointTransformationIn
@@ -103,6 +104,17 @@ func (e *Endpoint) Update(ctx context.Context, appId string, endpointId string,
103104
return &ret, nil
104105
}
105106

107+
func (e *Endpoint) Patch(ctx context.Context, appId string, endpointId string, endpointPatch *EndpointPatch) (*EndpointOut, error) {
108+
req := e.api.EndpointApi.V1EndpointPatch(ctx, appId, endpointId)
109+
req = req.EndpointPatch(openapi.EndpointPatch(*endpointPatch))
110+
out, res, err := req.Execute()
111+
if err != nil {
112+
return nil, wrapError(err, res)
113+
}
114+
ret := EndpointOut(out)
115+
return &ret, nil
116+
}
117+
106118
func (e *Endpoint) Delete(ctx context.Context, appId string, endpointId string) error {
107119
req := e.api.EndpointApi.V1EndpointDelete(ctx, appId, endpointId)
108120
res, err := req.Execute()

go/eventtype.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type (
1414
ListResponseEventTypeOut openapi.ListResponseEventTypeOut
1515
EventTypeIn openapi.EventTypeIn
1616
EventTypeOut openapi.EventTypeOut
17+
EventTypePatch openapi.EventTypePatch
1718
EventTypeUpdate openapi.EventTypeUpdate
1819
)
1920

@@ -89,6 +90,17 @@ func (e *EventType) Update(ctx context.Context, eventTypeName string, eventTypeU
8990
return &ret, nil
9091
}
9192

93+
func (e *EventType) Patch(ctx context.Context, eventTypeName string, eventTypePatch *EventTypePatch) (*EventTypeOut, error) {
94+
req := e.api.EventTypeApi.V1EventTypePatch(ctx, eventTypeName)
95+
req = req.EventTypePatch(openapi.EventTypePatch(*eventTypePatch))
96+
out, res, err := req.Execute()
97+
if err != nil {
98+
return nil, wrapError(err, res)
99+
}
100+
ret := EventTypeOut(out)
101+
return &ret, nil
102+
}
103+
92104
func (e *EventType) Delete(ctx context.Context, eventTypeName string) error {
93105
req := e.api.EventTypeApi.V1EventTypeDelete(ctx, eventTypeName)
94106
res, err := req.Execute()

0 commit comments

Comments
 (0)