Use db_type for Artist
This commit is contained in:
@ -12,6 +12,7 @@ cfg_if! {
|
||||
use diesel::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
use crate::models::backend::Album;
|
||||
use crate::models::backend::NewArtist;
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,10 +30,7 @@ pub async fn add_artist(artist_name: String) -> Result<(), ServerFnError> {
|
||||
use crate::schema::artists::dsl::*;
|
||||
use leptos::server_fn::error::NoCustomError;
|
||||
|
||||
let new_artist = Artist {
|
||||
id: None,
|
||||
name: artist_name,
|
||||
};
|
||||
let new_artist = NewArtist { name: artist_name };
|
||||
|
||||
let db = &mut get_db_conn();
|
||||
diesel::insert_into(artists)
|
||||
|
@ -369,9 +369,9 @@ pub async fn top_artists(
|
||||
(
|
||||
plays,
|
||||
frontend::Artist {
|
||||
id: artist.id.unwrap(),
|
||||
id: artist.id,
|
||||
name: artist.name,
|
||||
image_path: format!("/assets/images/artist/{}.webp", artist.id.unwrap()),
|
||||
image_path: format!("/assets/images/artist/{}.webp", artist.id),
|
||||
},
|
||||
)
|
||||
})
|
||||
|
@ -130,9 +130,9 @@ pub async fn search_artists(
|
||||
.map(|(artist, score)| {
|
||||
(
|
||||
frontend::Artist {
|
||||
id: artist.id.unwrap(),
|
||||
id: artist.id,
|
||||
name: artist.name,
|
||||
image_path: format!("/assets/images/artist/{}.webp", artist.id.unwrap()),
|
||||
image_path: format!("/assets/images/artist/{}.webp", artist.id),
|
||||
},
|
||||
score,
|
||||
)
|
||||
|
@ -176,14 +176,8 @@ pub fn SongArtists(artists: Vec<Artist>) -> impl IntoView {
|
||||
let i = i as isize;
|
||||
|
||||
view! {
|
||||
{
|
||||
if let Some(id) = artist.id {
|
||||
Either::Left(view! { <a class="hover:underline active:text-controls-active"
|
||||
href={format!("/artist/{id}")}>{artist.name.clone()}</a> })
|
||||
} else {
|
||||
Either::Right(view! { <span>{artist.name.clone()}</span> })
|
||||
}
|
||||
}
|
||||
<a class="hover:underline active:text-controls-active"
|
||||
href={format!("/artist/{}", artist.id)}>{artist.name.clone()}</a>
|
||||
{
|
||||
use std::cmp::Ordering;
|
||||
|
||||
|
@ -57,7 +57,7 @@ pub fn Upload(open: RwSignal<bool>) -> impl IntoView {
|
||||
artists
|
||||
.into_iter()
|
||||
.map(|(artist, _score)| Artist {
|
||||
id: Some(artist.id),
|
||||
id: artist.id,
|
||||
name: artist.name,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
@ -217,11 +217,7 @@ pub fn Artist(
|
||||
let mut ids: Vec<&str> = all_artirts.split(",").collect();
|
||||
//If there is only one artist in the input, get their id equivalent and add it to the string
|
||||
if ids.len() == 1 {
|
||||
let value_str = match artist.id {
|
||||
Some(v) => v.to_string(),
|
||||
None => String::from("None"),
|
||||
};
|
||||
s.push_str(&value_str);
|
||||
s.push_str(&artist.id.to_string());
|
||||
s.push(',');
|
||||
set_artists.update(|value| *value = s);
|
||||
//If there are multiple artists in the input, pop the last artist by string off the vector,
|
||||
@ -232,11 +228,7 @@ pub fn Artist(
|
||||
s.push_str(id);
|
||||
s.push(',');
|
||||
}
|
||||
let value_str = match artist.id {
|
||||
Some(v) => v.to_string(),
|
||||
None => String::from("None"),
|
||||
};
|
||||
s.push_str(&value_str);
|
||||
s.push_str(&artist.id.to_string());
|
||||
s.push(',');
|
||||
set_artists.update(|value| *value = s);
|
||||
}
|
||||
|
@ -1,25 +1,13 @@
|
||||
use libretunes_macro::db_type;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "ssr")] {
|
||||
use diesel::prelude::*;
|
||||
}
|
||||
}
|
||||
|
||||
/// Model for an artist
|
||||
#[cfg_attr(
|
||||
feature = "ssr",
|
||||
derive(Queryable, Selectable, Insertable, Identifiable)
|
||||
)]
|
||||
#[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::artists))]
|
||||
#[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))]
|
||||
#[db_type(crate::schema::artists)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Artist {
|
||||
/// A unique id for the artist
|
||||
#[cfg_attr(feature = "ssr", diesel(deserialize_as = i32))]
|
||||
pub id: Option<i32>,
|
||||
#[omit_new]
|
||||
pub id: i32,
|
||||
/// The artist's name
|
||||
pub name: String,
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ pub mod user;
|
||||
pub use album::Album;
|
||||
pub use album::NewAlbum;
|
||||
pub use artist::Artist;
|
||||
pub use artist::NewArtist;
|
||||
pub use history_entry::HistoryEntry;
|
||||
pub use playlist::Playlist;
|
||||
pub use song::NewSong;
|
||||
|
@ -83,8 +83,7 @@ fn ArtistIdProfile(#[prop(into)] id: Signal<i32>) -> impl IntoView {
|
||||
|
||||
#[component]
|
||||
fn ArtistProfile(artist: Artist) -> impl IntoView {
|
||||
let artist_id = artist.id.unwrap();
|
||||
let profile_image_path = format!("/assets/images/artist/{artist_id}.webp");
|
||||
let profile_image_path = format!("/assets/images/artist/{}.webp", artist.id);
|
||||
|
||||
leptos::logging::log!("Artist name: {}", artist.name);
|
||||
|
||||
|
Reference in New Issue
Block a user