@@ -49,6 +49,7 @@ pub struct PodcastSearchModel {
4949 title : Option < String > ,
5050 order_option : Option < OrderOption > ,
5151 favored_only : bool ,
52+ tag : Option < String >
5253}
5354
5455#[ utoipa:: path(
@@ -87,6 +88,7 @@ pub async fn search_podcasts(
8788 let query = query. into_inner ( ) ;
8889 let _order = query. order . unwrap_or ( OrderCriteria :: Asc ) ;
8990 let _latest_pub = query. order_option . unwrap_or ( OrderOption :: Title ) ;
91+ let tag = query. tag ;
9092
9193 let opt_filter = Filter :: get_filter_by_username (
9294 requester. clone ( ) . unwrap ( ) . username . clone ( ) ,
@@ -122,6 +124,7 @@ pub async fn search_podcasts(
122124 _latest_pub. clone ( ) ,
123125 conn. get ( ) . map_err ( map_r2d2_error) ?. deref_mut ( ) ,
124126 username,
127+ tag
125128 ) ?;
126129 }
127130 Ok ( HttpResponse :: Ok ( ) . json ( podcasts) )
@@ -135,29 +138,35 @@ pub async fn search_podcasts(
135138 _latest_pub. clone ( ) ,
136139 & mut conn. get ( ) . unwrap ( ) ,
137140 username,
141+ tag
138142 ) ?;
139143 }
140144 Ok ( HttpResponse :: Ok ( ) . json ( podcasts) )
141145 }
142146 }
143147}
144148
149+
145150#[ utoipa:: path(
146151context_path="/api/v1" ,
147152responses(
148- ( status = 200 , description = "Find a podcast by its collection id" , body = [ Podcast ] )
153+ ( status = 200 , description = "Find a podcast by its collection id" , body = [ ( Podcast , Tags ) ] )
149154) ,
150155tag="podcasts"
151156) ]
152157#[ get( "/podcast/{id}" ) ]
153158pub async fn find_podcast_by_id (
154159 id : Path < String > ,
155160 conn : Data < DbPool > ,
161+ user : Option < web:: ReqData < User > > ,
156162) -> Result < HttpResponse , CustomError > {
157163 let id_num = from_str :: < i32 > ( & id) . unwrap ( ) ;
164+ let username = user. unwrap ( ) . username . clone ( ) ;
165+
158166 let podcast =
159167 PodcastService :: get_podcast ( conn. get ( ) . map_err ( map_r2d2_error) ?. deref_mut ( ) , id_num) ?;
160- let mapped_podcast = MappingService :: map_podcast_to_podcast_dto ( & podcast) ;
168+ let tags = Tag :: get_tags_of_podcast ( conn. get ( ) . map_err ( map_r2d2_error) ?. deref_mut ( ) , id_num, & username) ?;
169+ let mapped_podcast = MappingService :: map_podcast_to_podcast_dto ( & podcast, tags) ;
161170 Ok ( HttpResponse :: Ok ( ) . json ( mapped_podcast) )
162171}
163172
@@ -177,6 +186,7 @@ pub async fn find_all_podcasts(
177186
178187 let podcasts =
179188 PodcastService :: get_podcasts ( conn. get ( ) . map_err ( map_r2d2_error) ?. deref_mut ( ) , username) ?;
189+
180190 Ok ( HttpResponse :: Ok ( ) . json ( podcasts) )
181191}
182192
@@ -485,7 +495,7 @@ pub async fn refresh_all_podcasts(
485495 podcast_episode : None ,
486496 type_of : PodcastType :: RefreshPodcast ,
487497 message : format ! ( "Refreshed podcast: {}" , podcast. name) ,
488- podcast : Option :: from ( podcast . clone ( ) ) ,
498+ podcast : Option :: from ( MappingService :: map_podcast_to_podcast_dto ( & podcast , vec ! [ ] ) ) ,
489499 podcast_episodes : None ,
490500 } ) . unwrap ( ) ) ;
491501 }
@@ -690,7 +700,7 @@ async fn insert_outline(
690700 let _ = lobby. send_broadcast ( MAIN_ROOM . parse ( ) . unwrap ( ) , serde_json:: to_string ( & BroadcastMessage {
691701 type_of : PodcastType :: OpmlAdded ,
692702 message : "Refreshed podcasts" . to_string ( ) ,
693- podcast : Option :: from ( podcast) ,
703+ podcast : Option :: from ( MappingService :: map_podcast_to_podcast_dto ( & podcast, vec ! [ ] ) ) ,
694704 podcast_episodes : None ,
695705 podcast_episode : None ,
696706 } ) . unwrap ( ) ) . await ;
@@ -719,12 +729,14 @@ async fn insert_outline(
719729}
720730use crate :: models:: episode:: Episode ;
721731use utoipa:: ToSchema ;
732+ use crate :: models:: tag:: Tag ;
722733
723734use crate :: controllers:: podcast_episode_controller:: EpisodeFormatDto ;
724735use crate :: controllers:: server:: ChatServerHandle ;
725736use crate :: controllers:: websocket_controller:: RSSAPiKey ;
726737use crate :: models:: podcast_settings:: PodcastSetting ;
727738use crate :: models:: settings:: Setting ;
739+ use crate :: models:: tags_podcast:: TagsPodcast ;
728740use crate :: utils:: environment_variables:: is_env_var_present_and_true;
729741
730742use crate :: utils:: error:: { map_r2d2_error, map_reqwest_error, CustomError } ;
@@ -763,6 +775,8 @@ pub async fn delete_podcast(
763775 }
764776 Episode :: delete_watchtime ( & mut db. get ( ) . unwrap ( ) , * id) ?;
765777 PodcastEpisode :: delete_episodes_of_podcast ( & mut db. get ( ) . unwrap ( ) , * id) ?;
778+ TagsPodcast :: delete_tags_by_podcast_id ( & mut db. get ( ) . unwrap ( ) , * id) ?;
779+
766780 Podcast :: delete_podcast ( & mut db. get ( ) . unwrap ( ) , * id) ?;
767781 Ok ( HttpResponse :: Ok ( ) . into ( ) )
768782}
0 commit comments