Skip to content

Commit

Permalink
feat: update subscription's condition
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed Nov 3, 2023
1 parent bdcb179 commit 7deb1fb
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 84 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,12 @@ func main() {
}
subId, err = client.CreateSubscription(ctx, userId, subData)

// Update the subscription mutable fields
// Update the subscription
upd := subscription.Data{
Description: "my disabled subscription",
Enabled: false,
subData.Expires, // don't change
subData.Condition, // don't change
}
err = client.UpdateSubscription(ctx, userId, subId, upd)

Expand Down
2 changes: 1 addition & 1 deletion api/grpc/limits/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/grpc/permits/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/grpc/reader/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/grpc/resolver/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/grpc/subject/subject.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions api/grpc/subscriptions/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Service interface {
// Read returns the subscription specified by the id. Returns ErrNotFound if subscription is missing.
Read(ctx context.Context, userId, subId string) (subData subscription.Data, err error)

// Update the mutable part of the subscription.Data
// Update the subscription.Data
Update(ctx context.Context, userId, subId string, subData subscription.Data) (err error)

// Delete the specified subscription all associated conditions those not in use by any other subscription.
Expand Down Expand Up @@ -92,14 +92,20 @@ func (svc service) Read(ctx context.Context, userId, subId string) (subData subs

func (svc service) Update(ctx context.Context, userId, subId string, data subscription.Data) (err error) {
ctx = auth.SetOutgoingAuthInfo(ctx, userId)
req := UpdateRequest{
Id: subId,
Description: data.Description,
Enabled: data.Enabled,
Expires: timestamppb.New(data.Expires.UTC()),
if data.Condition == nil {
err = fmt.Errorf("%w: missing condition", ErrInvalid)
}
if err == nil {
req := UpdateRequest{
Id: subId,
Description: data.Description,
Enabled: data.Enabled,
Expires: timestamppb.New(data.Expires.UTC()),
Cond: encodeCondition(data.Condition),
}
_, err = svc.client.Update(ctx, &req)
err = decodeError(err)
}
_, err = svc.client.Update(ctx, &req)
err = decodeError(err)
return
}

Expand Down
145 changes: 79 additions & 66 deletions api/grpc/subscriptions/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/grpc/subscriptions/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ message UpdateRequest {
string description = 2;
bool enabled = 3;
google.protobuf.Timestamp expires = 4;
Condition cond = 5;
}

message UpdateResponse {
Expand Down
Loading

0 comments on commit 7deb1fb

Please sign in to comment.