@@ -2,7 +2,7 @@ use sqlx::{query, query_as};
22
33use crate :: {
44 DbConnection ,
5- domain:: race:: { NewRace , NewRaceResult , RaceView , SubmitTownSearchParams } ,
5+ domain:: race:: { NewRace , NewRaceResult , RaceSearchParams , RaceView , SubmitTownSearchParams } ,
66 util:: pagination:: { Paginatable , PaginatedResponse , Pagination } ,
77} ;
88
@@ -25,29 +25,6 @@ impl RaceRepository {
2525 Ok ( race)
2626 }
2727
28- pub async fn submit_town_search (
29- & self ,
30- params : & SubmitTownSearchParams ,
31- ) -> PaginatedResponse < RaceView > {
32- let pattern = & format ! ( "%{}%" , params. race_name. to_lowercase( ) ) ;
33-
34- RaceView :: paginate_filter (
35- & self . db ,
36- & Pagination :: default ( ) ,
37- Some (
38- r#"
39- LOWER(name) LIKE ? AND town_id = ? AND
40- start_date >= DATE('now', '-6 months') AND
41- start_date <= DATE('now')
42- ORDER BY start_date DESC
43- "# ,
44- ) ,
45- vec ! [ pattern, & params. town_id. to_string( ) ] ,
46- )
47- . await
48- . unwrap ( )
49- }
50-
5128 pub async fn get_or_create ( & self , race : NewRace ) -> Result < RaceView , String > {
5229 let race_id: i64 = sqlx:: query_scalar (
5330 r#"
@@ -71,7 +48,7 @@ impl RaceRepository {
7148 self . find_by_id ( race_id) . await
7249 }
7350
74- pub async fn save ( & self , result : NewRaceResult ) -> Result < ( ) , String > {
51+ pub async fn save_result ( & self , result : NewRaceResult ) -> Result < ( ) , String > {
7552 query (
7653 r#"
7754 INSERT INTO race_results (user_id, race_id, notes)
@@ -87,4 +64,36 @@ impl RaceRepository {
8764
8865 Ok ( ( ) )
8966 }
67+
68+ pub async fn search_for_upcoming (
69+ & self ,
70+ params : RaceSearchParams ,
71+ ) -> PaginatedResponse < RaceView > {
72+ RaceView :: paginate_filter ( & self . db , & Pagination :: from ( params) , None , vec ! [ ] )
73+ . await
74+ . unwrap ( )
75+ }
76+
77+ pub async fn submit_town_search (
78+ & self ,
79+ params : & SubmitTownSearchParams ,
80+ ) -> PaginatedResponse < RaceView > {
81+ let pattern = & format ! ( "%{}%" , params. race_name. to_lowercase( ) ) ;
82+
83+ RaceView :: paginate_filter (
84+ & self . db ,
85+ & Pagination :: default ( ) ,
86+ Some (
87+ r#"
88+ LOWER(name) LIKE ? AND town_id = ? AND
89+ start_date >= DATE('now', '-6 months') AND
90+ start_date <= DATE('now')
91+ ORDER BY start_date DESC
92+ "# ,
93+ ) ,
94+ vec ! [ pattern, & params. town_id. to_string( ) ] ,
95+ )
96+ . await
97+ . unwrap ( )
98+ }
9099}
0 commit comments