@@ -24,11 +24,11 @@ func NewUserService() *UserService {
2424func (s * UserService ) Register (ctx context.Context , requestedName , dn , passwd string ) (* models.User , error ) {
2525 requestedName = strings .ToLower (strings .TrimSpace (requestedName ))
2626 dn = strings .TrimSpace (dn )
27-
27+
2828 if len (requestedName ) < 3 || len (requestedName ) > 25 {
2929 return nil , errors .New ("username prefix must be between 3 and 25 characters" )
3030 }
31-
31+
3232 isAlphanumeric := regexp .MustCompile (`^[a-z0-9]+$` ).MatchString
3333 if ! isAlphanumeric (requestedName ) {
3434 return nil , errors .New ("username prefix must contain only alphanumeric characters" )
@@ -52,9 +52,9 @@ func (s *UserService) Register(ctx context.Context, requestedName, dn, passwd st
5252 return nil , errors .New ("failed to generate secure user discriminator" )
5353 }
5454 discriminator := nBig .Int64 () + 1000 // forces range [1000, 9999]
55-
55+
5656 candidate := fmt .Sprintf ("%s.%d" , requestedName , discriminator )
57-
57+
5858 exists , err := s .repo .UsernameExists (ctx , candidate )
5959 if err != nil {
6060 return nil , err
@@ -76,4 +76,18 @@ func (s *UserService) Register(ctx context.Context, requestedName, dn, passwd st
7676 }
7777
7878 return s .repo .CreateUser (ctx , finalUsername , dn , hash )
79- }
79+ }
80+
81+ func (s * UserService ) Search (ctx context.Context , query string , page , limit int ) ([]models.User , error ) {
82+ query = strings .TrimSpace (query )
83+
84+ if limit <= 0 || limit > 100 {
85+ limit = 20
86+ }
87+ if page <= 0 {
88+ page = 1
89+ }
90+ offset := (page - 1 ) * limit
91+
92+ return s .repo .SearchUsers (ctx , query , limit , offset )
93+ }
0 commit comments