Skip to main content

๐Ÿ“ฆ Plan Service

The Plan Service manages subscription plans and their associated features. Each plan contains pricing, duration, and an array of features with their own usage and durations. It supports full CRUD operations, as well as activation/deactivation.


๐Ÿงญ Overviewโ€‹

This service helps manage:

  • Subscription plans (e.g., monthly, annual)
  • Feature-specific limits for each plan
  • Admin-side plan lifecycle (create, update, activate, deactivate)
  • Paginated listing and lookup by ID

๐Ÿงพ Plan Structureโ€‹

Planโ€‹

FieldTypeDescription
iduint32 (optional)Unique plan ID
namestringName of the plan
descriptionstringDescription of the plan
pricedoubleCost of the plan
currencystringCurrency code (e.g., "USD", "INR")
durationint32Duration in days/months
is_activeboolIndicates if the plan is currently active
feature_plansrepeated FeaturePlanList of features with their limits and durations
created_attimestampTime of creation
updated_attimestampTime of last update
created_byuint32User ID of creator
updated_byuint32User ID of last updater

FeaturePlanโ€‹

FieldTypeDescription
feature_iduint32Unique ID of the feature
durationuint32Duration of the feature in the plan
usageuint32Number of allowed uses for this feature
created_attimestampWhen the feature plan was created
updated_attimestampLast update time
created_byuint32User ID of creator
updated_byuint32User ID of last updater

๐Ÿง‘โ€๐Ÿ’ป gRPC Service Methodsโ€‹

PlanServiceโ€‹

MethodRequest TypeResponse TypeDescription
CreatePlanCreatePlanRequestPlanResponseCreate a new plan
GetPlanByIDGetPlanByIDRequestPlanResponseGet details of a specific plan
ListAllPlansListAllPlansRequestPlanResponseGet paginated list of all plans
UpdatePlanByIDUpdatePlanByIDRequestPlanResponseUpdate a specific plan
ActivatePlanByIDActivatePlanByIDRequestCheckResponseSet a plan to active
DeactivatePlanByIDDeactivatePlanByIDRequestCheckResponseDeactivate a plan

๐Ÿ“ฆ Request & Response Messagesโ€‹

โœ… CreatePlanRequestโ€‹

{
"plan": {
"name": "Pro Plan",
"description": "For advanced users",
"price": 49.99,
"currency": "USD",
"duration": 30,
"is_active": true,
"feature_plans": [
{
"feature_id": 1,
"duration": 30,
"usage": 100
}
]
}
}

๐Ÿ“ฅ PlanResponseโ€‹

{
"message": "Plan created successfully",
"code": "201",
"data": [...],
"total": 1
}

๐Ÿ” CheckResponseโ€‹

{
"message": "Plan activated successfully",
"code": "200",
"check": true
}

๐Ÿ—ƒ๏ธ Go Modelsโ€‹

Planโ€‹

type Plan struct {
ID uint32 `json:"id" gorm:"primaryKey"`
Name string `json:"name"`
Description string `json:"description"`
Price float64 `json:"price"`
Currency string `json:"currency"`
Duration uint32 `json:"duration"`
FeaturePlans []FeaturePlan `json:"feature_plans" gorm:"serializer:json"`
IsActive bool `json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy uint32 `gorm:"type:bigint" json:"created_by"`
UpdatedBy uint32 `gorm:"type:bigint" json:"updated_by"`
}

FeaturePlanโ€‹

type FeaturePlan struct {
FeatureID uint32 `json:"feature_id" gorm:"primaryKey"`
Duration uint32 `json:"duration" gorm:"primaryKey"`
Usage uint32 `json:"usage"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy uint32 `gorm:"type:bigint" json:"created_by"`
UpdatedBy uint32 `gorm:"type:bigint" json:"updated_by"`
}