Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/sms-gateway/handlers/3rdparty.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (h *thirdPartyHandler) Register(router fiber.Router) {
h.logsHandler.Register(router.Group("/logs"))
}

// newThirdPartyHandler creates and initializes a thirdPartyHandler with the provided controllers, authentication service, logger, and validator.
func newThirdPartyHandler(params ThirdPartyHandlerParams) *thirdPartyHandler {
return &thirdPartyHandler{
Handler: base.Handler{Logger: params.Logger.Named("ThirdPartyHandler"), Validator: params.Validator},
Expand Down
1 change: 1 addition & 0 deletions internal/sms-gateway/handlers/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ type mobileHandlerParams struct {
SettingsCtrl *settings.MobileController
}

// newMobileHandler creates and initializes a mobileHandler with the provided services, controllers, and dependencies.
func newMobileHandler(params mobileHandlerParams) *mobileHandler {
idGen, _ := nanoid.Standard(21)

Expand Down
1 change: 1 addition & 0 deletions internal/sms-gateway/handlers/settings/3rdparty.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (h *ThirdPartyController) Register(app fiber.Router) {
app.Put("", userauth.WithUser(h.put))
}

// NewThirdPartyController creates a new ThirdPartyController with the provided device service, validator, and logger.
func NewThirdPartyController(params thirdPartyControllerParams) *ThirdPartyController {
return &ThirdPartyController{
Handler: base.Handler{
Expand Down
1 change: 1 addition & 0 deletions internal/sms-gateway/handlers/settings/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (h *MobileController) Register(router fiber.Router) {
router.Get("", deviceauth.WithDevice(h.get))
}

// NewMobileController creates a new MobileController with the provided devices service and a logger scoped to "settings".
func NewMobileController(params mobileControllerParams) *MobileController {
return &MobileController{
Handler: base.Handler{
Expand Down
1 change: 1 addition & 0 deletions internal/sms-gateway/modules/devices/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type DeviceSettings struct {
User models.User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE"`
}

// Migrate performs automatic schema migration for the DeviceSettings table using GORM.
func Migrate(db *gorm.DB) error {
return db.AutoMigrate(&DeviceSettings{})
}
1 change: 1 addition & 0 deletions internal/sms-gateway/modules/devices/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var Module = fx.Module(
}),
)

// init registers the Migrate function with the database migration system during package initialization.
func init() {
db.RegisterMigration(Migrate)
}
1 change: 1 addition & 0 deletions internal/sms-gateway/modules/devices/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (r *repository) ReplaceSettings(settings *DeviceSettings) (*DeviceSettings,
return settings, r.db.Save(settings).Error
}

// newDevicesRepository creates a new repository instance for managing devices using the provided GORM database connection.
func newDevicesRepository(db *gorm.DB) *repository {
return &repository{
db: db,
Expand Down
1 change: 1 addition & 0 deletions internal/sms-gateway/modules/devices/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (s *Service) ReplaceSettings(userID string, settings map[string]any) (map[s
return filterMap(updated.Settings, rulesPublic)
}

// NewService creates a new Service instance with the provided dependencies and initializes the device token cache.
func NewService(params ServiceParams) *Service {
return &Service{
config: params.Config,
Expand Down
4 changes: 4 additions & 0 deletions internal/sms-gateway/modules/devices/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ var rulesPublic = map[string]any{
},
}

// filterMap returns a new map containing only the fields from m that are specified in the rules map r, recursively filtering nested maps as defined by r.
// Returns an error if a field expected to be a nested map is not a map in m.
func filterMap(m map[string]any, r map[string]any) (map[string]any, error) {
var err error

Expand Down Expand Up @@ -89,6 +91,8 @@ func filterMap(m map[string]any, r map[string]any) (map[string]any, error) {
return result, nil
}

// appendMap recursively merges fields from m2 into m1 according to the structure defined by rules.
// Only fields present in the rules map are considered, with nested maps merged recursively and scalar values overwritten.
func appendMap(m1, m2 map[string]any, rules map[string]any) map[string]any {

for field, rule := range rules {
Expand Down
1 change: 1 addition & 0 deletions internal/sms-gateway/modules/push/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Service struct {
logger *zap.Logger
}

// New creates and initializes a new Service instance with configured caching, metrics, and device management for push notifications.
func New(params Params) *Service {
if params.Config.Timeout == 0 {
params.Config.Timeout = time.Second
Expand Down
Loading