@@ -156,12 +156,23 @@ impl Database for Sqlite {
156156 . map_err ( |_| database:: Error :: UserNotFound )
157157 }
158158
159- async fn get_user_profiles_paginated ( & self , offset : u64 , limit : u8 ) -> Result < UserProfilesResponse , database:: Error > {
160- let mut query_string = "SELECT * FROM torrust_user_profiles" . to_string ( ) ;
159+ async fn get_user_profiles_search_paginated (
160+ & self ,
161+ search : & Option < String > ,
162+ offset : u64 ,
163+ limit : u8 ,
164+ ) -> Result < UserProfilesResponse , database:: Error > {
165+ let user_name = match search {
166+ None => "%" . to_string ( ) ,
167+ Some ( v) => format ! ( "%{v}%" ) ,
168+ } ;
169+
170+ let mut query_string = "SELECT * FROM torrust_user_profiles WHERE username LIKE ?" . to_string ( ) ;
161171
162172 let count_query = format ! ( "SELECT COUNT(*) as count FROM ({query_string}) AS count_table" ) ;
163173
164174 let count_result: Result < i64 , database:: Error > = query_as ( & count_query)
175+ . bind ( user_name. clone ( ) )
165176 . fetch_one ( & self . pool )
166177 . await
167178 . map ( |( v, ) | v)
@@ -172,6 +183,7 @@ impl Database for Sqlite {
172183 query_string = format ! ( "{query_string} LIMIT ?, ?" ) ;
173184
174185 let res: Vec < UserProfile > = sqlx:: query_as :: < _ , UserProfile > ( & query_string)
186+ . bind ( user_name. clone ( ) )
175187 . bind ( i64:: saturating_add_unsigned ( 0 , offset) )
176188 . bind ( limit)
177189 . fetch_all ( & self . pool )
0 commit comments