@@ -16,7 +16,7 @@ impl PostService {
1616 Self { pool }
1717 }
1818
19- fn row_to_post ( row : & rusqlite:: Row ) -> rusqlite:: Result < Post > {
19+ pub fn row_to_post ( row : & rusqlite:: Row ) -> rusqlite:: Result < Post > {
2020 let id: String = row. get ( "id" ) ?;
2121 let content_type_str: String = row. get ( "content_type" ) ?;
2222 let content_type = ContentType :: from ( content_type_str) ;
@@ -26,7 +26,11 @@ impl PostService {
2626 let quote_author: Option < String > = row. get ( "quote_author" ) ?;
2727 let date: String = row. get ( "date" ) ?;
2828 let content: String = row. get ( "content" ) ?;
29- let commits: Option < String > = row. get ( "commits" ) ?;
29+ let commits_str: Option < String > = row. get ( "commits" ) ?;
30+ let commits = commits_str. and_then ( |s| serde_json:: from_str ( & s) . ok ( ) ) ;
31+
32+ let tags_str: Option < String > = row. get ( "tags" ) ?;
33+ let tags = tags_str. and_then ( |s| serde_json:: from_str ( & s) . ok ( ) ) ;
3034
3135 Ok ( Post {
3236 id,
@@ -38,6 +42,7 @@ impl PostService {
3842 date,
3943 content,
4044 commits,
45+ tags,
4146 real_commits : None ,
4247 } )
4348 }
@@ -166,12 +171,12 @@ impl PostService {
166171 . map ( |mut v| v. remove ( 0 ) )
167172 }
168173
169- async fn bulk_convert_to_posts ( & self , mut posts : Vec < Post > ) -> Result < Vec < Post > > {
174+ pub async fn bulk_convert_to_posts ( & self , mut posts : Vec < Post > ) -> Result < Vec < Post > > {
170175 let all_commit_ids: Vec < _ > = posts
171176 . iter ( )
172177 . filter_map ( |post| post. commits . as_ref ( ) )
173- . flat_map ( |commits| commits . split_whitespace ( ) )
174- . map ( |s| s . to_owned ( ) )
178+ . flatten ( )
179+ . cloned ( )
175180 . collect ( ) ;
176181
177182 let commits_map = if !all_commit_ids. is_empty ( ) {
@@ -215,9 +220,10 @@ impl PostService {
215220
216221 for post in & mut posts {
217222 if let Some ( ids) = & post. commits {
218- let real_commits: Vec < Commit > = ids
219- . split_whitespace ( )
220- . filter_map ( |id| commits_map. get ( id) . cloned ( ) )
223+ let real_commits = ids
224+ . iter ( )
225+ . filter_map ( |id| commits_map. get ( id) )
226+ . cloned ( )
221227 . collect ( ) ;
222228 post. real_commits = Some ( real_commits) ;
223229 }
0 commit comments