chore: update subscription service

This commit is contained in:
Steven 2024-08-16 21:02:51 +08:00
parent 63ebd6f8ea
commit 0be4d8c906
9 changed files with 310 additions and 245 deletions

View File

@ -16,6 +16,24 @@ const SubscriptionSetting: React.FC = () => {
const isAdmin = currentUser.role === Role.ADMIN; const isAdmin = currentUser.role === Role.ADMIN;
const profile = workspaceStore.profile; const profile = workspaceStore.profile;
const handleDeleteLicenseKey = async () => {
if (!isAdmin) {
toast.error("Only admin can upload license key");
return;
}
const confirmed = window.confirm("Are you sure you want to reset the license key?");
if (confirmed) {
try {
await subscriptionServiceClient.deleteSubscription({});
toast.success("License key has been reset");
} catch (error: any) {
toast.error(error.details);
}
await workspaceStore.fetchWorkspaceProfile();
}
};
const handleUpdateLicenseKey = async () => { const handleUpdateLicenseKey = async () => {
if (!isAdmin) { if (!isAdmin) {
toast.error("Only admin can upload license key"); toast.error("Only admin can upload license key");
@ -23,12 +41,10 @@ const SubscriptionSetting: React.FC = () => {
} }
try { try {
const { subscription } = await subscriptionServiceClient.updateSubscription({ const subscription = await subscriptionServiceClient.updateSubscription({
licenseKey, licenseKey,
}); });
if (subscription) { toast.success(`Welcome to Slash ${stringifyPlanType(subscription.plan)}🎉`);
toast.success(`Welcome to Slash ${stringifyPlanType(subscription.plan)}🎉`);
}
} catch (error: any) { } catch (error: any) {
toast.error(error.details); toast.error(error.details);
} }
@ -61,9 +77,16 @@ const SubscriptionSetting: React.FC = () => {
</Link> </Link>
)} )}
</div> </div>
<Button disabled={licenseKey === ""} onClick={handleUpdateLicenseKey}> <div className="flex justify-end items-center gap-2">
Upload license {profile.plan !== PlanType.FREE && (
</Button> <Button color="neutral" variant="plain" onClick={handleDeleteLicenseKey}>
Reset
</Button>
)}
<Button disabled={licenseKey === ""} onClick={handleUpdateLicenseKey}>
Upload license
</Button>
</div>
</div> </div>
</div> </div>
<Divider /> <Divider />

View File

@ -9,15 +9,21 @@ import "google/protobuf/timestamp.proto";
option go_package = "gen/api/v1"; option go_package = "gen/api/v1";
service SubscriptionService { service SubscriptionService {
rpc GetSubscription(GetSubscriptionRequest) returns (GetSubscriptionResponse) { // GetSubscription gets the current subscription of Slash instance.
rpc GetSubscription(GetSubscriptionRequest) returns (Subscription) {
option (google.api.http) = {get: "/v1/subscription"}; option (google.api.http) = {get: "/v1/subscription"};
} }
rpc UpdateSubscription(UpdateSubscriptionRequest) returns (UpdateSubscriptionResponse) { // UpdateSubscription updates the subscription.
rpc UpdateSubscription(UpdateSubscriptionRequest) returns (Subscription) {
option (google.api.http) = { option (google.api.http) = {
patch: "/v1/subscription" patch: "/v1/subscription"
body: "*" body: "*"
}; };
} }
// DeleteSubscription deletes the subscription.
rpc DeleteSubscription(DeleteSubscriptionRequest) returns (Subscription) {
option (google.api.http) = {delete: "/v1/subscription"};
}
} }
message Subscription { message Subscription {
@ -41,14 +47,8 @@ enum PlanType {
message GetSubscriptionRequest {} message GetSubscriptionRequest {}
message GetSubscriptionResponse {
Subscription subscription = 1;
}
message UpdateSubscriptionRequest { message UpdateSubscriptionRequest {
string license_key = 1 [(google.api.field_behavior) = REQUIRED]; string license_key = 1 [(google.api.field_behavior) = REQUIRED];
} }
message UpdateSubscriptionResponse { message DeleteSubscriptionRequest {}
Subscription subscription = 1;
}

View File

@ -79,11 +79,10 @@
- [ShortcutService](#slash-api-v1-ShortcutService) - [ShortcutService](#slash-api-v1-ShortcutService)
- [api/v1/subscription_service.proto](#api_v1_subscription_service-proto) - [api/v1/subscription_service.proto](#api_v1_subscription_service-proto)
- [DeleteSubscriptionRequest](#slash-api-v1-DeleteSubscriptionRequest)
- [GetSubscriptionRequest](#slash-api-v1-GetSubscriptionRequest) - [GetSubscriptionRequest](#slash-api-v1-GetSubscriptionRequest)
- [GetSubscriptionResponse](#slash-api-v1-GetSubscriptionResponse)
- [Subscription](#slash-api-v1-Subscription) - [Subscription](#slash-api-v1-Subscription)
- [UpdateSubscriptionRequest](#slash-api-v1-UpdateSubscriptionRequest) - [UpdateSubscriptionRequest](#slash-api-v1-UpdateSubscriptionRequest)
- [UpdateSubscriptionResponse](#slash-api-v1-UpdateSubscriptionResponse)
- [PlanType](#slash-api-v1-PlanType) - [PlanType](#slash-api-v1-PlanType)
@ -1108,6 +1107,16 @@
<a name="slash-api-v1-DeleteSubscriptionRequest"></a>
### DeleteSubscriptionRequest
<a name="slash-api-v1-GetSubscriptionRequest"></a> <a name="slash-api-v1-GetSubscriptionRequest"></a>
### GetSubscriptionRequest ### GetSubscriptionRequest
@ -1118,21 +1127,6 @@
<a name="slash-api-v1-GetSubscriptionResponse"></a>
### GetSubscriptionResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| subscription | [Subscription](#slash-api-v1-Subscription) | | |
<a name="slash-api-v1-Subscription"></a> <a name="slash-api-v1-Subscription"></a>
### Subscription ### Subscription
@ -1166,21 +1160,6 @@
<a name="slash-api-v1-UpdateSubscriptionResponse"></a>
### UpdateSubscriptionResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| subscription | [Subscription](#slash-api-v1-Subscription) | | |
@ -1209,8 +1188,9 @@
| Method Name | Request Type | Response Type | Description | | Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------| | ----------- | ------------ | ------------- | ------------|
| GetSubscription | [GetSubscriptionRequest](#slash-api-v1-GetSubscriptionRequest) | [GetSubscriptionResponse](#slash-api-v1-GetSubscriptionResponse) | | | GetSubscription | [GetSubscriptionRequest](#slash-api-v1-GetSubscriptionRequest) | [Subscription](#slash-api-v1-Subscription) | GetSubscription gets the current subscription of Slash instance. |
| UpdateSubscription | [UpdateSubscriptionRequest](#slash-api-v1-UpdateSubscriptionRequest) | [UpdateSubscriptionResponse](#slash-api-v1-UpdateSubscriptionResponse) | | | UpdateSubscription | [UpdateSubscriptionRequest](#slash-api-v1-UpdateSubscriptionRequest) | [Subscription](#slash-api-v1-Subscription) | UpdateSubscription updates the subscription. |
| DeleteSubscription | [DeleteSubscriptionRequest](#slash-api-v1-DeleteSubscriptionRequest) | [Subscription](#slash-api-v1-Subscription) | DeleteSubscription deletes the subscription. |

View File

@ -191,53 +191,6 @@ func (*GetSubscriptionRequest) Descriptor() ([]byte, []int) {
return file_api_v1_subscription_service_proto_rawDescGZIP(), []int{1} return file_api_v1_subscription_service_proto_rawDescGZIP(), []int{1}
} }
type GetSubscriptionResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Subscription *Subscription `protobuf:"bytes,1,opt,name=subscription,proto3" json:"subscription,omitempty"`
}
func (x *GetSubscriptionResponse) Reset() {
*x = GetSubscriptionResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_api_v1_subscription_service_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetSubscriptionResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetSubscriptionResponse) ProtoMessage() {}
func (x *GetSubscriptionResponse) ProtoReflect() protoreflect.Message {
mi := &file_api_v1_subscription_service_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetSubscriptionResponse.ProtoReflect.Descriptor instead.
func (*GetSubscriptionResponse) Descriptor() ([]byte, []int) {
return file_api_v1_subscription_service_proto_rawDescGZIP(), []int{2}
}
func (x *GetSubscriptionResponse) GetSubscription() *Subscription {
if x != nil {
return x.Subscription
}
return nil
}
type UpdateSubscriptionRequest struct { type UpdateSubscriptionRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@ -249,7 +202,7 @@ type UpdateSubscriptionRequest struct {
func (x *UpdateSubscriptionRequest) Reset() { func (x *UpdateSubscriptionRequest) Reset() {
*x = UpdateSubscriptionRequest{} *x = UpdateSubscriptionRequest{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_api_v1_subscription_service_proto_msgTypes[3] mi := &file_api_v1_subscription_service_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@ -262,7 +215,7 @@ func (x *UpdateSubscriptionRequest) String() string {
func (*UpdateSubscriptionRequest) ProtoMessage() {} func (*UpdateSubscriptionRequest) ProtoMessage() {}
func (x *UpdateSubscriptionRequest) ProtoReflect() protoreflect.Message { func (x *UpdateSubscriptionRequest) ProtoReflect() protoreflect.Message {
mi := &file_api_v1_subscription_service_proto_msgTypes[3] mi := &file_api_v1_subscription_service_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -275,7 +228,7 @@ func (x *UpdateSubscriptionRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use UpdateSubscriptionRequest.ProtoReflect.Descriptor instead. // Deprecated: Use UpdateSubscriptionRequest.ProtoReflect.Descriptor instead.
func (*UpdateSubscriptionRequest) Descriptor() ([]byte, []int) { func (*UpdateSubscriptionRequest) Descriptor() ([]byte, []int) {
return file_api_v1_subscription_service_proto_rawDescGZIP(), []int{3} return file_api_v1_subscription_service_proto_rawDescGZIP(), []int{2}
} }
func (x *UpdateSubscriptionRequest) GetLicenseKey() string { func (x *UpdateSubscriptionRequest) GetLicenseKey() string {
@ -285,31 +238,29 @@ func (x *UpdateSubscriptionRequest) GetLicenseKey() string {
return "" return ""
} }
type UpdateSubscriptionResponse struct { type DeleteSubscriptionRequest struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Subscription *Subscription `protobuf:"bytes,1,opt,name=subscription,proto3" json:"subscription,omitempty"`
} }
func (x *UpdateSubscriptionResponse) Reset() { func (x *DeleteSubscriptionRequest) Reset() {
*x = UpdateSubscriptionResponse{} *x = DeleteSubscriptionRequest{}
if protoimpl.UnsafeEnabled { if protoimpl.UnsafeEnabled {
mi := &file_api_v1_subscription_service_proto_msgTypes[4] mi := &file_api_v1_subscription_service_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
} }
func (x *UpdateSubscriptionResponse) String() string { func (x *DeleteSubscriptionRequest) String() string {
return protoimpl.X.MessageStringOf(x) return protoimpl.X.MessageStringOf(x)
} }
func (*UpdateSubscriptionResponse) ProtoMessage() {} func (*DeleteSubscriptionRequest) ProtoMessage() {}
func (x *UpdateSubscriptionResponse) ProtoReflect() protoreflect.Message { func (x *DeleteSubscriptionRequest) ProtoReflect() protoreflect.Message {
mi := &file_api_v1_subscription_service_proto_msgTypes[4] mi := &file_api_v1_subscription_service_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil { if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@ -320,16 +271,9 @@ func (x *UpdateSubscriptionResponse) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x) return mi.MessageOf(x)
} }
// Deprecated: Use UpdateSubscriptionResponse.ProtoReflect.Descriptor instead. // Deprecated: Use DeleteSubscriptionRequest.ProtoReflect.Descriptor instead.
func (*UpdateSubscriptionResponse) Descriptor() ([]byte, []int) { func (*DeleteSubscriptionRequest) Descriptor() ([]byte, []int) {
return file_api_v1_subscription_service_proto_rawDescGZIP(), []int{4} return file_api_v1_subscription_service_proto_rawDescGZIP(), []int{3}
}
func (x *UpdateSubscriptionResponse) GetSubscription() *Subscription {
if x != nil {
return x.Subscription
}
return nil
} }
var File_api_v1_subscription_service_proto protoreflect.FileDescriptor var File_api_v1_subscription_service_proto protoreflect.FileDescriptor
@ -362,57 +306,53 @@ var file_api_v1_subscription_service_proto_rawDesc = []byte{
0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41,
0x01, 0x03, 0x52, 0x08, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x22, 0x18, 0x0a, 0x16, 0x01, 0x03, 0x52, 0x08, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x73, 0x22, 0x18, 0x0a, 0x16,
0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x59, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x42, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75,
0x65, 0x12, 0x3e, 0x0a, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x65, 0x73, 0x74, 0x12, 0x25, 0x0a, 0x0b, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x6b,
0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x01, 0x02, 0x52, 0x0a,
0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x22, 0x1b, 0x0a, 0x19, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2a, 0x48, 0x0a, 0x08, 0x50, 0x6c, 0x61, 0x6e, 0x54,
0x79, 0x70, 0x65, 0x12, 0x19, 0x0a, 0x15, 0x50, 0x4c, 0x41, 0x4e, 0x5f, 0x54, 0x59, 0x50, 0x45,
0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08,
0x0a, 0x04, 0x46, 0x52, 0x45, 0x45, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x50, 0x52, 0x4f, 0x10,
0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x45, 0x4e, 0x54, 0x45, 0x52, 0x50, 0x52, 0x49, 0x53, 0x45, 0x10,
0x03, 0x32, 0xf1, 0x02, 0x0a, 0x13, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69,
0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6d, 0x0a, 0x0f, 0x47, 0x65, 0x74,
0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x24, 0x2e, 0x73,
0x6c, 0x61, 0x73, 0x68, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x53,
0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76,
0x31, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x18,
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x75, 0x62, 0x73,
0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x76, 0x0a, 0x12, 0x55, 0x70, 0x64, 0x61,
0x74, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x27,
0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70,
0x64, 0x61, 0x74, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2e,
0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x69, 0x6f, 0x6e, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x3a, 0x01, 0x2a, 0x32, 0x10,
0x6e, 0x22, 0x42, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x25, 0x12, 0x73, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72,
0x0a, 0x0b, 0x6c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x42, 0x04, 0xe2, 0x41, 0x01, 0x02, 0x52, 0x0a, 0x6c, 0x69, 0x63, 0x65, 0x6e,
0x73, 0x65, 0x4b, 0x65, 0x79, 0x22, 0x5c, 0x0a, 0x1a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53,
0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x12, 0x3e, 0x0a, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x73, 0x6c, 0x61, 0x73,
0x68, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
0x69, 0x6f, 0x6e, 0x2a, 0x48, 0x0a, 0x08, 0x50, 0x6c, 0x61, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12,
0x19, 0x0a, 0x15, 0x50, 0x4c, 0x41, 0x4e, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53,
0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x52,
0x45, 0x45, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x50, 0x52, 0x4f, 0x10, 0x02, 0x12, 0x0e, 0x0a,
0x0a, 0x45, 0x4e, 0x54, 0x45, 0x52, 0x50, 0x52, 0x49, 0x53, 0x45, 0x10, 0x03, 0x32, 0x96, 0x02,
0x0a, 0x13, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x78, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x73,
0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x24, 0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68,
0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x75, 0x62, 0x73, 0x63,
0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25,
0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65,
0x74, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f,
0x76, 0x31, 0x2f, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12,
0x84, 0x01, 0x0a, 0x12, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72,
0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x27, 0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x61, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x27, 0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x61,
0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x75, 0x62, 0x73, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x53, 0x75, 0x62, 0x73,
0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x28, 0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x1a, 0x2e, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x2e, 0x53,
0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x18, 0x82, 0xd3, 0xe4,
0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x93, 0x02, 0x12, 0x2a, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69,
0x15, 0x3a, 0x01, 0x2a, 0x32, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0xb6, 0x01, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x2e, 0x73, 0x6c,
0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0xb6, 0x01, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x2e, 0x73, 0x61, 0x73, 0x68, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x42, 0x18, 0x53, 0x75, 0x62, 0x73,
0x6c, 0x61, 0x73, 0x68, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x31, 0x42, 0x18, 0x53, 0x75, 0x62, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x50,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63,
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x6f, 0x6d, 0x2f, 0x79, 0x6f, 0x75, 0x72, 0x73, 0x65, 0x6c, 0x66, 0x68, 0x6f, 0x73, 0x74, 0x65,
0x63, 0x6f, 0x6d, 0x2f, 0x79, 0x6f, 0x75, 0x72, 0x73, 0x65, 0x6c, 0x66, 0x68, 0x6f, 0x73, 0x74, 0x64, 0x2f, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65,
0x65, 0x64, 0x2f, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x70, 0x69, 0x76, 0x31, 0xa2, 0x02,
0x65, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x3b, 0x61, 0x70, 0x69, 0x76, 0x31, 0xa2, 0x03, 0x53, 0x41, 0x58, 0xaa, 0x02, 0x0c, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x41, 0x70, 0x69,
0x02, 0x03, 0x53, 0x41, 0x58, 0xaa, 0x02, 0x0c, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x2e, 0x41, 0x70, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x0c, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x5c, 0x41, 0x70, 0x69, 0x5c,
0x69, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x0c, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x5c, 0x41, 0x70, 0x69, 0x56, 0x31, 0xe2, 0x02, 0x18, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x56,
0x5c, 0x56, 0x31, 0xe2, 0x02, 0x18, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0e,
0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x3a, 0x3a, 0x41, 0x70, 0x69, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06,
0x0e, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x3a, 0x3a, 0x41, 0x70, 0x69, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -428,31 +368,30 @@ func file_api_v1_subscription_service_proto_rawDescGZIP() []byte {
} }
var file_api_v1_subscription_service_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_api_v1_subscription_service_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_api_v1_subscription_service_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_api_v1_subscription_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_api_v1_subscription_service_proto_goTypes = []any{ var file_api_v1_subscription_service_proto_goTypes = []any{
(PlanType)(0), // 0: slash.api.v1.PlanType (PlanType)(0), // 0: slash.api.v1.PlanType
(*Subscription)(nil), // 1: slash.api.v1.Subscription (*Subscription)(nil), // 1: slash.api.v1.Subscription
(*GetSubscriptionRequest)(nil), // 2: slash.api.v1.GetSubscriptionRequest (*GetSubscriptionRequest)(nil), // 2: slash.api.v1.GetSubscriptionRequest
(*GetSubscriptionResponse)(nil), // 3: slash.api.v1.GetSubscriptionResponse (*UpdateSubscriptionRequest)(nil), // 3: slash.api.v1.UpdateSubscriptionRequest
(*UpdateSubscriptionRequest)(nil), // 4: slash.api.v1.UpdateSubscriptionRequest (*DeleteSubscriptionRequest)(nil), // 4: slash.api.v1.DeleteSubscriptionRequest
(*UpdateSubscriptionResponse)(nil), // 5: slash.api.v1.UpdateSubscriptionResponse (*timestamppb.Timestamp)(nil), // 5: google.protobuf.Timestamp
(*timestamppb.Timestamp)(nil), // 6: google.protobuf.Timestamp
} }
var file_api_v1_subscription_service_proto_depIdxs = []int32{ var file_api_v1_subscription_service_proto_depIdxs = []int32{
0, // 0: slash.api.v1.Subscription.plan:type_name -> slash.api.v1.PlanType 0, // 0: slash.api.v1.Subscription.plan:type_name -> slash.api.v1.PlanType
6, // 1: slash.api.v1.Subscription.started_time:type_name -> google.protobuf.Timestamp 5, // 1: slash.api.v1.Subscription.started_time:type_name -> google.protobuf.Timestamp
6, // 2: slash.api.v1.Subscription.expires_time:type_name -> google.protobuf.Timestamp 5, // 2: slash.api.v1.Subscription.expires_time:type_name -> google.protobuf.Timestamp
1, // 3: slash.api.v1.GetSubscriptionResponse.subscription:type_name -> slash.api.v1.Subscription 2, // 3: slash.api.v1.SubscriptionService.GetSubscription:input_type -> slash.api.v1.GetSubscriptionRequest
1, // 4: slash.api.v1.UpdateSubscriptionResponse.subscription:type_name -> slash.api.v1.Subscription 3, // 4: slash.api.v1.SubscriptionService.UpdateSubscription:input_type -> slash.api.v1.UpdateSubscriptionRequest
2, // 5: slash.api.v1.SubscriptionService.GetSubscription:input_type -> slash.api.v1.GetSubscriptionRequest 4, // 5: slash.api.v1.SubscriptionService.DeleteSubscription:input_type -> slash.api.v1.DeleteSubscriptionRequest
4, // 6: slash.api.v1.SubscriptionService.UpdateSubscription:input_type -> slash.api.v1.UpdateSubscriptionRequest 1, // 6: slash.api.v1.SubscriptionService.GetSubscription:output_type -> slash.api.v1.Subscription
3, // 7: slash.api.v1.SubscriptionService.GetSubscription:output_type -> slash.api.v1.GetSubscriptionResponse 1, // 7: slash.api.v1.SubscriptionService.UpdateSubscription:output_type -> slash.api.v1.Subscription
5, // 8: slash.api.v1.SubscriptionService.UpdateSubscription:output_type -> slash.api.v1.UpdateSubscriptionResponse 1, // 8: slash.api.v1.SubscriptionService.DeleteSubscription:output_type -> slash.api.v1.Subscription
7, // [7:9] is the sub-list for method output_type 6, // [6:9] is the sub-list for method output_type
5, // [5:7] is the sub-list for method input_type 3, // [3:6] is the sub-list for method input_type
5, // [5:5] is the sub-list for extension type_name 3, // [3:3] is the sub-list for extension type_name
5, // [5:5] is the sub-list for extension extendee 3, // [3:3] is the sub-list for extension extendee
0, // [0:5] is the sub-list for field type_name 0, // [0:3] is the sub-list for field type_name
} }
func init() { file_api_v1_subscription_service_proto_init() } func init() { file_api_v1_subscription_service_proto_init() }
@ -486,18 +425,6 @@ func file_api_v1_subscription_service_proto_init() {
} }
} }
file_api_v1_subscription_service_proto_msgTypes[2].Exporter = func(v any, i int) any { file_api_v1_subscription_service_proto_msgTypes[2].Exporter = func(v any, i int) any {
switch v := v.(*GetSubscriptionResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_api_v1_subscription_service_proto_msgTypes[3].Exporter = func(v any, i int) any {
switch v := v.(*UpdateSubscriptionRequest); i { switch v := v.(*UpdateSubscriptionRequest); i {
case 0: case 0:
return &v.state return &v.state
@ -509,8 +436,8 @@ func file_api_v1_subscription_service_proto_init() {
return nil return nil
} }
} }
file_api_v1_subscription_service_proto_msgTypes[4].Exporter = func(v any, i int) any { file_api_v1_subscription_service_proto_msgTypes[3].Exporter = func(v any, i int) any {
switch v := v.(*UpdateSubscriptionResponse); i { switch v := v.(*DeleteSubscriptionRequest); i {
case 0: case 0:
return &v.state return &v.state
case 1: case 1:
@ -528,7 +455,7 @@ func file_api_v1_subscription_service_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_api_v1_subscription_service_proto_rawDesc, RawDescriptor: file_api_v1_subscription_service_proto_rawDesc,
NumEnums: 1, NumEnums: 1,
NumMessages: 5, NumMessages: 4,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View File

@ -75,6 +75,24 @@ func local_request_SubscriptionService_UpdateSubscription_0(ctx context.Context,
} }
func request_SubscriptionService_DeleteSubscription_0(ctx context.Context, marshaler runtime.Marshaler, client SubscriptionServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq DeleteSubscriptionRequest
var metadata runtime.ServerMetadata
msg, err := client.DeleteSubscription(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_SubscriptionService_DeleteSubscription_0(ctx context.Context, marshaler runtime.Marshaler, server SubscriptionServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq DeleteSubscriptionRequest
var metadata runtime.ServerMetadata
msg, err := server.DeleteSubscription(ctx, &protoReq)
return msg, metadata, err
}
// RegisterSubscriptionServiceHandlerServer registers the http handlers for service SubscriptionService to "mux". // RegisterSubscriptionServiceHandlerServer registers the http handlers for service SubscriptionService to "mux".
// UnaryRPC :call SubscriptionServiceServer directly. // UnaryRPC :call SubscriptionServiceServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@ -132,6 +150,31 @@ func RegisterSubscriptionServiceHandlerServer(ctx context.Context, mux *runtime.
}) })
mux.Handle("DELETE", pattern_SubscriptionService_DeleteSubscription_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/slash.api.v1.SubscriptionService/DeleteSubscription", runtime.WithHTTPPathPattern("/v1/subscription"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_SubscriptionService_DeleteSubscription_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_SubscriptionService_DeleteSubscription_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil return nil
} }
@ -217,6 +260,28 @@ func RegisterSubscriptionServiceHandlerClient(ctx context.Context, mux *runtime.
}) })
mux.Handle("DELETE", pattern_SubscriptionService_DeleteSubscription_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/slash.api.v1.SubscriptionService/DeleteSubscription", runtime.WithHTTPPathPattern("/v1/subscription"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_SubscriptionService_DeleteSubscription_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_SubscriptionService_DeleteSubscription_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil return nil
} }
@ -224,10 +289,14 @@ var (
pattern_SubscriptionService_GetSubscription_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "subscription"}, "")) pattern_SubscriptionService_GetSubscription_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "subscription"}, ""))
pattern_SubscriptionService_UpdateSubscription_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "subscription"}, "")) pattern_SubscriptionService_UpdateSubscription_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "subscription"}, ""))
pattern_SubscriptionService_DeleteSubscription_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "subscription"}, ""))
) )
var ( var (
forward_SubscriptionService_GetSubscription_0 = runtime.ForwardResponseMessage forward_SubscriptionService_GetSubscription_0 = runtime.ForwardResponseMessage
forward_SubscriptionService_UpdateSubscription_0 = runtime.ForwardResponseMessage forward_SubscriptionService_UpdateSubscription_0 = runtime.ForwardResponseMessage
forward_SubscriptionService_DeleteSubscription_0 = runtime.ForwardResponseMessage
) )

View File

@ -21,14 +21,19 @@ const _ = grpc.SupportPackageIsVersion9
const ( const (
SubscriptionService_GetSubscription_FullMethodName = "/slash.api.v1.SubscriptionService/GetSubscription" SubscriptionService_GetSubscription_FullMethodName = "/slash.api.v1.SubscriptionService/GetSubscription"
SubscriptionService_UpdateSubscription_FullMethodName = "/slash.api.v1.SubscriptionService/UpdateSubscription" SubscriptionService_UpdateSubscription_FullMethodName = "/slash.api.v1.SubscriptionService/UpdateSubscription"
SubscriptionService_DeleteSubscription_FullMethodName = "/slash.api.v1.SubscriptionService/DeleteSubscription"
) )
// SubscriptionServiceClient is the client API for SubscriptionService service. // SubscriptionServiceClient is the client API for SubscriptionService service.
// //
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type SubscriptionServiceClient interface { type SubscriptionServiceClient interface {
GetSubscription(ctx context.Context, in *GetSubscriptionRequest, opts ...grpc.CallOption) (*GetSubscriptionResponse, error) // GetSubscription gets the current subscription of Slash instance.
UpdateSubscription(ctx context.Context, in *UpdateSubscriptionRequest, opts ...grpc.CallOption) (*UpdateSubscriptionResponse, error) GetSubscription(ctx context.Context, in *GetSubscriptionRequest, opts ...grpc.CallOption) (*Subscription, error)
// UpdateSubscription updates the subscription.
UpdateSubscription(ctx context.Context, in *UpdateSubscriptionRequest, opts ...grpc.CallOption) (*Subscription, error)
// DeleteSubscription deletes the subscription.
DeleteSubscription(ctx context.Context, in *DeleteSubscriptionRequest, opts ...grpc.CallOption) (*Subscription, error)
} }
type subscriptionServiceClient struct { type subscriptionServiceClient struct {
@ -39,9 +44,9 @@ func NewSubscriptionServiceClient(cc grpc.ClientConnInterface) SubscriptionServi
return &subscriptionServiceClient{cc} return &subscriptionServiceClient{cc}
} }
func (c *subscriptionServiceClient) GetSubscription(ctx context.Context, in *GetSubscriptionRequest, opts ...grpc.CallOption) (*GetSubscriptionResponse, error) { func (c *subscriptionServiceClient) GetSubscription(ctx context.Context, in *GetSubscriptionRequest, opts ...grpc.CallOption) (*Subscription, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetSubscriptionResponse) out := new(Subscription)
err := c.cc.Invoke(ctx, SubscriptionService_GetSubscription_FullMethodName, in, out, cOpts...) err := c.cc.Invoke(ctx, SubscriptionService_GetSubscription_FullMethodName, in, out, cOpts...)
if err != nil { if err != nil {
return nil, err return nil, err
@ -49,9 +54,9 @@ func (c *subscriptionServiceClient) GetSubscription(ctx context.Context, in *Get
return out, nil return out, nil
} }
func (c *subscriptionServiceClient) UpdateSubscription(ctx context.Context, in *UpdateSubscriptionRequest, opts ...grpc.CallOption) (*UpdateSubscriptionResponse, error) { func (c *subscriptionServiceClient) UpdateSubscription(ctx context.Context, in *UpdateSubscriptionRequest, opts ...grpc.CallOption) (*Subscription, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdateSubscriptionResponse) out := new(Subscription)
err := c.cc.Invoke(ctx, SubscriptionService_UpdateSubscription_FullMethodName, in, out, cOpts...) err := c.cc.Invoke(ctx, SubscriptionService_UpdateSubscription_FullMethodName, in, out, cOpts...)
if err != nil { if err != nil {
return nil, err return nil, err
@ -59,12 +64,26 @@ func (c *subscriptionServiceClient) UpdateSubscription(ctx context.Context, in *
return out, nil return out, nil
} }
func (c *subscriptionServiceClient) DeleteSubscription(ctx context.Context, in *DeleteSubscriptionRequest, opts ...grpc.CallOption) (*Subscription, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Subscription)
err := c.cc.Invoke(ctx, SubscriptionService_DeleteSubscription_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// SubscriptionServiceServer is the server API for SubscriptionService service. // SubscriptionServiceServer is the server API for SubscriptionService service.
// All implementations must embed UnimplementedSubscriptionServiceServer // All implementations must embed UnimplementedSubscriptionServiceServer
// for forward compatibility. // for forward compatibility.
type SubscriptionServiceServer interface { type SubscriptionServiceServer interface {
GetSubscription(context.Context, *GetSubscriptionRequest) (*GetSubscriptionResponse, error) // GetSubscription gets the current subscription of Slash instance.
UpdateSubscription(context.Context, *UpdateSubscriptionRequest) (*UpdateSubscriptionResponse, error) GetSubscription(context.Context, *GetSubscriptionRequest) (*Subscription, error)
// UpdateSubscription updates the subscription.
UpdateSubscription(context.Context, *UpdateSubscriptionRequest) (*Subscription, error)
// DeleteSubscription deletes the subscription.
DeleteSubscription(context.Context, *DeleteSubscriptionRequest) (*Subscription, error)
mustEmbedUnimplementedSubscriptionServiceServer() mustEmbedUnimplementedSubscriptionServiceServer()
} }
@ -75,12 +94,15 @@ type SubscriptionServiceServer interface {
// pointer dereference when methods are called. // pointer dereference when methods are called.
type UnimplementedSubscriptionServiceServer struct{} type UnimplementedSubscriptionServiceServer struct{}
func (UnimplementedSubscriptionServiceServer) GetSubscription(context.Context, *GetSubscriptionRequest) (*GetSubscriptionResponse, error) { func (UnimplementedSubscriptionServiceServer) GetSubscription(context.Context, *GetSubscriptionRequest) (*Subscription, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetSubscription not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetSubscription not implemented")
} }
func (UnimplementedSubscriptionServiceServer) UpdateSubscription(context.Context, *UpdateSubscriptionRequest) (*UpdateSubscriptionResponse, error) { func (UnimplementedSubscriptionServiceServer) UpdateSubscription(context.Context, *UpdateSubscriptionRequest) (*Subscription, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateSubscription not implemented") return nil, status.Errorf(codes.Unimplemented, "method UpdateSubscription not implemented")
} }
func (UnimplementedSubscriptionServiceServer) DeleteSubscription(context.Context, *DeleteSubscriptionRequest) (*Subscription, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteSubscription not implemented")
}
func (UnimplementedSubscriptionServiceServer) mustEmbedUnimplementedSubscriptionServiceServer() {} func (UnimplementedSubscriptionServiceServer) mustEmbedUnimplementedSubscriptionServiceServer() {}
func (UnimplementedSubscriptionServiceServer) testEmbeddedByValue() {} func (UnimplementedSubscriptionServiceServer) testEmbeddedByValue() {}
@ -138,6 +160,24 @@ func _SubscriptionService_UpdateSubscription_Handler(srv interface{}, ctx contex
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _SubscriptionService_DeleteSubscription_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeleteSubscriptionRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SubscriptionServiceServer).DeleteSubscription(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SubscriptionService_DeleteSubscription_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SubscriptionServiceServer).DeleteSubscription(ctx, req.(*DeleteSubscriptionRequest))
}
return interceptor(ctx, in, info, handler)
}
// SubscriptionService_ServiceDesc is the grpc.ServiceDesc for SubscriptionService service. // SubscriptionService_ServiceDesc is the grpc.ServiceDesc for SubscriptionService service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -153,6 +193,10 @@ var SubscriptionService_ServiceDesc = grpc.ServiceDesc{
MethodName: "UpdateSubscription", MethodName: "UpdateSubscription",
Handler: _SubscriptionService_UpdateSubscription_Handler, Handler: _SubscriptionService_UpdateSubscription_Handler,
}, },
{
MethodName: "DeleteSubscription",
Handler: _SubscriptionService_DeleteSubscription_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "api/v1/subscription_service.proto", Metadata: "api/v1/subscription_service.proto",

View File

@ -708,12 +708,27 @@ paths:
- WorkspaceService - WorkspaceService
/v1/subscription: /v1/subscription:
get: get:
summary: GetSubscription gets the current subscription of Slash instance.
operationId: SubscriptionService_GetSubscription operationId: SubscriptionService_GetSubscription
responses: responses:
"200": "200":
description: A successful response. description: A successful response.
schema: schema:
$ref: '#/definitions/v1GetSubscriptionResponse' $ref: '#/definitions/v1Subscription'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/rpcStatus'
tags:
- SubscriptionService
delete:
summary: DeleteSubscription deletes the subscription.
operationId: SubscriptionService_DeleteSubscription
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1Subscription'
default: default:
description: An unexpected error response. description: An unexpected error response.
schema: schema:
@ -721,12 +736,13 @@ paths:
tags: tags:
- SubscriptionService - SubscriptionService
patch: patch:
summary: UpdateSubscription updates the subscription.
operationId: SubscriptionService_UpdateSubscription operationId: SubscriptionService_UpdateSubscription
responses: responses:
"200": "200":
description: A successful response. description: A successful response.
schema: schema:
$ref: '#/definitions/v1UpdateSubscriptionResponse' $ref: '#/definitions/v1Subscription'
default: default:
description: An unexpected error response. description: An unexpected error response.
schema: schema:
@ -1036,11 +1052,6 @@ definitions:
properties: properties:
shortcut: shortcut:
$ref: '#/definitions/apiv1Shortcut' $ref: '#/definitions/apiv1Shortcut'
v1GetSubscriptionResponse:
type: object
properties:
subscription:
$ref: '#/definitions/v1Subscription'
v1GetUserResponse: v1GetUserResponse:
type: object type: object
properties: properties:
@ -1150,11 +1161,6 @@ definitions:
type: string type: string
required: required:
- licenseKey - licenseKey
v1UpdateSubscriptionResponse:
type: object
properties:
subscription:
$ref: '#/definitions/v1Subscription'
v1UpdateUserResponse: v1UpdateUserResponse:
type: object type: object
properties: properties:

View File

@ -9,22 +9,26 @@ import (
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1" v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
) )
func (s *APIV1Service) GetSubscription(ctx context.Context, _ *v1pb.GetSubscriptionRequest) (*v1pb.GetSubscriptionResponse, error) { func (s *APIV1Service) GetSubscription(ctx context.Context, _ *v1pb.GetSubscriptionRequest) (*v1pb.Subscription, error) {
subscription, err := s.LicenseService.LoadSubscription(ctx) subscription, err := s.LicenseService.LoadSubscription(ctx)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to load subscription: %v", err) return nil, status.Errorf(codes.Internal, "failed to load subscription: %v", err)
} }
return &v1pb.GetSubscriptionResponse{ return subscription, nil
Subscription: subscription,
}, nil
} }
func (s *APIV1Service) UpdateSubscription(ctx context.Context, request *v1pb.UpdateSubscriptionRequest) (*v1pb.UpdateSubscriptionResponse, error) { func (s *APIV1Service) UpdateSubscription(ctx context.Context, request *v1pb.UpdateSubscriptionRequest) (*v1pb.Subscription, error) {
subscription, err := s.LicenseService.UpdateSubscription(ctx, request.LicenseKey) subscription, err := s.LicenseService.UpdateSubscription(ctx, request.LicenseKey)
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to load subscription: %v", err) return nil, status.Errorf(codes.Internal, "failed to load subscription: %v", err)
} }
return &v1pb.UpdateSubscriptionResponse{ return subscription, nil
Subscription: subscription, }
}, nil
func (s *APIV1Service) DeleteSubscription(ctx context.Context, _ *v1pb.DeleteSubscriptionRequest) (*v1pb.Subscription, error) {
subscription, err := s.LicenseService.UpdateSubscription(ctx, "")
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to load subscription: %v", err)
}
return subscription, nil
} }

View File

@ -66,32 +66,44 @@ func (s *LicenseService) LoadSubscription(ctx context.Context) (*v1pb.Subscripti
if result == nil { if result == nil {
return subscription, nil return subscription, nil
} }
subscription.Plan = result.Plan subscription.Plan = result.Plan
subscription.ExpiresTime = timestamppb.New(result.ExpiresTime) subscription.ExpiresTime = timestamppb.New(result.ExpiresTime)
subscription.Seats = int32(result.Seats) subscription.Seats = int32(result.Seats)
for _, feature := range result.Features { for _, feature := range result.Features {
subscription.Features = append(subscription.Features, feature.String()) subscription.Features = append(subscription.Features, feature.String())
} }
s.cachedSubscription = subscription
return subscription, nil return subscription, nil
} }
func (s *LicenseService) UpdateSubscription(ctx context.Context, licenseKey string) (*v1pb.Subscription, error) { func (s *LicenseService) UpdateSubscription(ctx context.Context, licenseKey string) (*v1pb.Subscription, error) {
if licenseKey == "" { if licenseKey != "" {
return nil, errors.New("license key is required") result, err := validateLicenseKey(licenseKey)
if err != nil {
return nil, errors.Wrap(err, "failed to validate license key")
}
if result == nil {
return nil, errors.New("invalid license key")
}
} }
result, err := validateLicenseKey(licenseKey) if err := s.UpdateLicenseKey(ctx, licenseKey); err != nil {
return nil, errors.Wrap(err, "failed to update license key")
}
subscription, err := s.LoadSubscription(ctx)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to validate license key") return nil, errors.Wrap(err, "failed to load subscription")
}
if result == nil {
return nil, errors.New("invalid license key")
} }
s.cachedSubscription = subscription
return subscription, nil
}
func (s *LicenseService) UpdateLicenseKey(ctx context.Context, licenseKey string) error {
workspaceSettingGeneral, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{ workspaceSettingGeneral, err := s.Store.GetWorkspaceSetting(ctx, &store.FindWorkspaceSetting{
Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL, Key: storepb.WorkspaceSettingKey_WORKSPACE_SETTING_GENERAL,
}) })
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to get workspace setting") return errors.Wrap(err, "failed to get workspace setting")
} }
if workspaceSettingGeneral == nil || workspaceSettingGeneral.GetGeneral() == nil { if workspaceSettingGeneral == nil || workspaceSettingGeneral.GetGeneral() == nil {
workspaceSettingGeneral = &storepb.WorkspaceSetting{ workspaceSettingGeneral = &storepb.WorkspaceSetting{
@ -107,9 +119,9 @@ func (s *LicenseService) UpdateSubscription(ctx context.Context, licenseKey stri
} }
_, err = s.Store.UpsertWorkspaceSetting(ctx, workspaceSettingGeneral) _, err = s.Store.UpsertWorkspaceSetting(ctx, workspaceSettingGeneral)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to upsert workspace setting") return errors.Wrap(err, "failed to upsert workspace setting")
} }
return s.LoadSubscription(ctx) return nil
} }
func (s *LicenseService) GetSubscription() *v1pb.Subscription { func (s *LicenseService) GetSubscription() *v1pb.Subscription {