From 43abe4300f5a6f5d086a7a789d2627285e15391d Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 7 Oct 2024 08:21:03 +0200 Subject: [PATCH] fix --- src/library/track.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/library/track.rs b/src/library/track.rs index 6c45bf5..0127741 100644 --- a/src/library/track.rs +++ b/src/library/track.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use serde_json::json; use sqlx::prelude::FromRow; -use std::{collections::HashSet, str::FromStr}; +use std::str::FromStr; use crate::{ get_pg, @@ -9,7 +9,7 @@ use crate::{ route::{to_uuid, ToAPI}, }; -use super::{event::Event, metadata::AudioMetadata, user::User}; +use super::{metadata::AudioMetadata, user::User}; #[derive(Debug, Clone, Serialize, Deserialize, FromRow)] pub struct Track { @@ -198,11 +198,22 @@ impl Track { /// /// A vector of `Track` objects representing the latest tracks for the given user. pub async fn get_latest_of_user(u: &User) -> Vec { - sqlx::query_as("SELECT DISTINCT t.* FROM track t JOIN events e ON t.id = e.track WHERE e.user = $1 ORDER BY e.time DESC") + let res: Vec<(uuid::Uuid, String, String, chrono::DateTime, Option, Option, Option, chrono::DateTime)> = sqlx::query_as("SELECT DISTINCT(t.*), e.time FROM track t JOIN events e ON t.id = e.track WHERE e.user = $1 ORDER BY e.time DESC") .bind(&u.username) .fetch_all(get_pg!()) .await - .unwrap() + .unwrap(); + res.into_iter() + .map(|x| Self { + id: x.0, + path: x.1, + title: x.2, + date_added: x.3, + album: x.4, + artist: x.5, + meta: x.6, + }) + .collect() } /// Transcodes audio to OPUS format with the specified bitrate.