@@ -911,9 +911,13 @@ impl<'a> Database<'a> {
911911 /// // Remove manga from user's history lists
912912 /// db.remove_from_history("manga_123")?;
913913 /// ```
914- pub fn remove_from_history ( & self , manga_id : & str ) -> rusqlite:: Result < ( ) > {
915- self . connection
916- . execute ( "DELETE FROM manga_history_union WHERE manga_history_union.manga_id = ?1" , params ! [ manga_id] ) ?;
914+ pub fn remove_from_history ( & self , manga_id : & str , hist_type : MangaHistoryType ) -> rusqlite:: Result < ( ) > {
915+ let hist_type_id = self . get_history_type ( hist_type) ?;
916+
917+ self . connection . execute (
918+ "DELETE FROM manga_history_union WHERE manga_history_union.manga_id = ?1 AND manga_history_union.type_id = ?2" ,
919+ params ! [ manga_id, hist_type_id] ,
920+ ) ?;
917921
918922 Ok ( ( ) )
919923 }
@@ -938,16 +942,17 @@ impl<'a> Database<'a> {
938942 pub fn remove_all_from_history ( & self , hist_type : MangaHistoryType , provider : MangaProviders ) -> rusqlite:: Result < ( ) > {
939943 let history_type_id = self . get_history_type ( hist_type) ?;
940944
941- let get_ids_manga_to_delete_statement = r#"SELECT mangas.id from mangas
945+ let get_ids_manga_to_delete_statement = r#"SELECT mangas.id from mangas
942946 INNER JOIN manga_history_union ON mangas.id = manga_history_union.manga_id
943947 WHERE manga_history_union.type_id = ?1 AND mangas.manga_provider = ?2
944948 "# ;
945949
946- let delete_statement =
947- format ! ( "DELETE FROM manga_history_union WHERE manga_history_union.manga_id IN ({get_ids_manga_to_delete_statement})" ) ;
950+ let delete_statement = format ! (
951+ "DELETE FROM manga_history_union WHERE manga_history_union.manga_id IN ({get_ids_manga_to_delete_statement}) AND manga_history_union.type_id = ?3"
952+ ) ;
948953
949954 self . connection
950- . execute ( & delete_statement, params ! [ history_type_id, provider. to_string( ) ] ) ?;
955+ . execute ( & delete_statement, params ! [ history_type_id, provider. to_string( ) , history_type_id ] ) ?;
951956
952957 Ok ( ( ) )
953958 }
@@ -2179,7 +2184,7 @@ mod test {
21792184 /* at this point 2 mangas must be stored in reading history */
21802185 assert_eq ! ( expected. mangas. len( ) , 2 ) ;
21812186
2182- database. remove_from_history ( & manga_id_mangadex) ?;
2187+ database. remove_from_history ( & manga_id_mangadex, MangaHistoryType :: ReadingHistory ) ?;
21832188
21842189 let expected = database. get_history ( GetHistoryArgs {
21852190 hist_type : MangaHistoryType :: ReadingHistory ,
@@ -2233,7 +2238,7 @@ mod test {
22332238 /* at this point 2 mangas must be stored in reading history */
22342239 assert_eq ! ( expected. mangas. len( ) , 2 ) ;
22352240
2236- database. remove_from_history ( & manga_id_mangadex) ?;
2241+ database. remove_from_history ( & manga_id_mangadex, MangaHistoryType :: PlanToRead ) ?;
22372242
22382243 let expected = database. get_history ( GetHistoryArgs {
22392244 hist_type : MangaHistoryType :: PlanToRead ,
@@ -2246,6 +2251,17 @@ mod test {
22462251 /* now only one should exist */
22472252 assert_eq ! ( expected. mangas. len( ) , 1 ) ;
22482253
2254+ let expected = database. get_history ( GetHistoryArgs {
2255+ hist_type : MangaHistoryType :: ReadingHistory ,
2256+ page : 1 ,
2257+ search : None ,
2258+ items_per_page : 10 ,
2259+ provider : MangaProviders :: Mangadex ,
2260+ } ) ?;
2261+
2262+ /* the reading history should be ketp the same */
2263+ assert_eq ! ( expected. mangas. len( ) , 2 ) ;
2264+
22492265 Ok ( ( ) )
22502266 }
22512267
@@ -2265,7 +2281,7 @@ mod test {
22652281 let manga_id_weeb_central = Uuid :: new_v4 ( ) . to_string ( ) ;
22662282 let manga_id_weeb_centra2 = Uuid :: new_v4 ( ) . to_string ( ) ;
22672283
2268- database. create_manga_if_not_exists ( MangaInsert {
2284+ database. save_plan_to_read ( MangaPlanToReadSave {
22692285 id : & manga_id_mangadex,
22702286 title : "of mangadex 1" ,
22712287 img_url : None ,
@@ -2274,7 +2290,7 @@ mod test {
22742290
22752291 database. insert_manga_in_reading_history ( & manga_id_mangadex) ?;
22762292
2277- database. create_manga_if_not_exists ( MangaInsert {
2293+ database. save_plan_to_read ( MangaPlanToReadSave {
22782294 id : & manga_id_mangadex2,
22792295 title : "of mangadex 2" ,
22802296 img_url : None ,
@@ -2357,8 +2373,8 @@ mod test {
23572373 provider : MangaProviders :: Mangadex ,
23582374 } ) ?;
23592375
2360- /* at this point 2 mangas in plant to read should exist */
2361- assert_eq ! ( expected. mangas. len( ) , 2 ) ;
2376+ /* at this point 4 mangas in plant to read should exist */
2377+ assert_eq ! ( expected. mangas. len( ) , 4 ) ;
23622378
23632379 database. remove_all_from_history ( MangaHistoryType :: ReadingHistory , MangaProviders :: Mangadex ) ?;
23642380
@@ -2393,7 +2409,7 @@ mod test {
23932409 } ) ?;
23942410
23952411 /* the plan to read history should remain untouched */
2396- assert_eq ! ( expected. mangas. len( ) , 2 ) ;
2412+ assert_eq ! ( expected. mangas. len( ) , 4 ) ;
23972413
23982414 Ok ( ( ) )
23992415 }
0 commit comments