| 157 | |
| 158 | #[tracing::instrument(level = "debug", skip(self))] |
| 159 | pub fn create_playlist(&self, mut playlist: QueryablePlaylist) -> Result<String> { |
| 160 | let mut conn = self.pool.get().unwrap(); |
| 161 | |
| 162 | trace!("Sanitizing playlist"); |
| 163 | |
| 164 | if playlist.playlist_id.is_none() { |
| 165 | playlist.playlist_id = Some(Uuid::new_v4().to_string()); |
| 166 | } |
| 167 | |
| 168 | if playlist.playlist_name.is_empty() { |
| 169 | playlist.playlist_name = "New playlist".to_string(); |
| 170 | } |
| 171 | |
| 172 | if playlist.playlist_path.is_some() { |
| 173 | let fetched = self.get_playlists( |
| 174 | QueryablePlaylist { |
| 175 | playlist_path: playlist.playlist_path.clone(), |
| 176 | ..Default::default() |
| 177 | }, |
| 178 | false, |
| 179 | &mut conn, |
| 180 | )?; |
| 181 | if !fetched.is_empty() { |
| 182 | return Ok(fetched[0].playlist_id.clone().unwrap()); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | self.insert_playlist(&mut conn, &playlist) |
| 187 | } |
| 188 | |
| 189 | #[tracing::instrument(level = "debug", skip(self))] |
| 190 | pub fn add_to_playlist_bridge(&self, playlist_id: String, song_id: String) -> Result<()> { |