fix
This commit is contained in:
parent
0554040341
commit
43abe4300f
1 changed files with 15 additions and 4 deletions
|
@ -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<Self> {
|
||||
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<chrono::Utc>, Option<uuid::Uuid>, Option<uuid::Uuid>, Option<serde_json::Value>, chrono::DateTime<chrono::Utc>)> = 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.
|
||||
|
|
Loading…
Reference in a new issue