mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-11-07 20:45:15 +00:00
refactor: Split subscriber service into separate files for better code organization
- Move IMSI allocation logic to subscriber_imsi.go - Move authentication key generation (generateAuthKeys, getOperatorVariant, generateOPc) to subscriber_auth.go - Move eSIM profile operations (provisionESIMProfile, deactivateESIMProfile) to subscriber_esim.go - Keep core subscriber CRUD operations and session management in subscriber.go - Remove unused crypto/aes, crypto/rand, encoding/hex, and os imports from main
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/nutcas3/telecom-platform/apps/api-server/internal/models"
|
||||
)
|
||||
|
||||
// allocateIMSI allocates a new IMSI for a subscriber
|
||||
func (s *SubscriberService) allocateIMSI(ctx context.Context) (models.IMSI, error) {
|
||||
// Get current IMSI allocation
|
||||
alloc, err := s.db.GetIMSIAllocation(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get IMSI allocation: %w", err)
|
||||
}
|
||||
|
||||
// Check if we've reached the maximum
|
||||
if alloc.LastIMSI >= alloc.MaxIMSI {
|
||||
return "", fmt.Errorf("IMSI range exhausted: max %d reached", alloc.MaxIMSI)
|
||||
}
|
||||
|
||||
// Allocate next IMSI
|
||||
nextIMSI := alloc.LastIMSI + 1
|
||||
alloc.LastIMSI = nextIMSI
|
||||
|
||||
// Update allocation state
|
||||
if err := s.db.UpdateIMSIAllocation(ctx, alloc); err != nil {
|
||||
return "", fmt.Errorf("failed to update IMSI allocation: %w", err)
|
||||
}
|
||||
|
||||
// Format IMSI: MCC (3) + MNC (2-3) + subscriber number
|
||||
imsiStr := fmt.Sprintf("%s%010d", s.config.IMSI.Prefix, nextIMSI)
|
||||
return models.IMSI(imsiStr), nil
|
||||
}
|
||||
Reference in New Issue
Block a user