diff --git a/docs/bulk-scheduled-notifications-integration.md b/docs/bulk-scheduled-notifications-integration.md index 5fa1b627..73be1ad0 100644 --- a/docs/bulk-scheduled-notifications-integration.md +++ b/docs/bulk-scheduled-notifications-integration.md @@ -877,7 +877,7 @@ Valid platform `users.role` values: | Super admin | `SUPER_ADMIN` | | Support | `SUPPORT` | -When `role` is set without `user_ids`, the API loads **all users** matching that role. +When `role` is set without `user_ids`, the API loads **all users** matching that role (up to 100k). Role values are matched case-insensitively (`STUDENT`, `student`, etc.). ### Combining targets diff --git a/internal/services/user/direct.go b/internal/services/user/direct.go index 8618d1d7..59ab6156 100644 --- a/internal/services/user/direct.go +++ b/internal/services/user/direct.go @@ -3,9 +3,13 @@ package user import ( "Yimaru-Backend/internal/domain" "context" + "strings" "time" ) +// defaultUnpaginatedUserLimit is used when PageSize is unset (e.g. bulk notification role targeting). +const defaultUnpaginatedUserLimit int64 = 100_000 + func (s *Service) UpdateUserKnowledgeLevel(ctx context.Context, userID int64, knowledgeLevel string) error { return s.userStore.UpdateUserKnowledgeLevel(ctx, userID, knowledgeLevel) } @@ -76,12 +80,14 @@ func (s *Service) GetAllUsers( var role *string if filter.Role != "" { - role = &filter.Role + normalized := strings.ToUpper(strings.TrimSpace(filter.Role)) + role = &normalized } var status *string if filter.Status != "" { - status = &filter.Status + normalized := strings.ToUpper(strings.TrimSpace(filter.Status)) + status = &normalized } var query *string @@ -104,7 +110,12 @@ func (s *Service) GetAllUsers( subscriptionStatus = &filter.SubscriptionStatus } - offset := int32(filter.Page * filter.PageSize) + pageSize := filter.PageSize + if pageSize <= 0 { + pageSize = defaultUnpaginatedUserLimit + } + + offset := int32(filter.Page * pageSize) return s.userStore.GetAllUsers( ctx, @@ -116,7 +127,7 @@ func (s *Service) GetAllUsers( country, region, subscriptionStatus, - int32(filter.PageSize), + int32(pageSize), offset, ) }