Skip to content

Commit 341a55b

Browse files
committed
feat(metadata): get albums by ids
1 parent 866b24f commit 341a55b

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
fragment AlbumDetail on Album {
2+
id
3+
albumId
4+
level
5+
6+
title
7+
edition
8+
catalog
9+
artist
10+
11+
year
12+
month
13+
day
14+
15+
tags {
16+
...TagBase
17+
}
18+
19+
createdAt
20+
updatedAt
21+
extra
22+
23+
discs {
24+
id
25+
index
26+
title
27+
catalog
28+
artist
29+
30+
tags {
31+
...TagBase
32+
}
33+
34+
createdAt
35+
updatedAt
36+
37+
tracks {
38+
id
39+
index
40+
title
41+
artist
42+
type
43+
artists
44+
45+
tags {
46+
...TagBase
47+
}
48+
49+
createdAt
50+
updatedAt
51+
}
52+
}
53+
}
54+
55+
query albums($albumIds: [UUID!]!) {
56+
albums(by: { albumIds: $albumIds }) {
57+
pageInfo {
58+
hasPreviousPage
59+
hasNextPage
60+
startCursor
61+
endCursor
62+
}
63+
nodes {
64+
...AlbumDetail
65+
}
66+
}
67+
}

anni-metadata/src/annim/client.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ impl AnnimClient {
4848
Ok(response.data.and_then(|data| data.album))
4949
}
5050

51+
pub async fn albums(
52+
&self,
53+
album_ids: Vec<uuid::Uuid>,
54+
) -> anyhow::Result<Vec<query::album::AlbumFragment>> {
55+
let query = query::albums::AlbumsQuery::build(query::albums::AlbumsVariables {
56+
after: None,
57+
first: Some(album_ids.len() as i32),
58+
album_ids: Some(album_ids),
59+
});
60+
let response = self.client.post(&self.endpoint).run_graphql(query).await?;
61+
if let Some(errors) = response.errors {
62+
anyhow::bail!("GraphQL error: {:?}", errors);
63+
}
64+
65+
Ok(response
66+
.data
67+
.and_then(|data| data.albums)
68+
.map(|d| d.nodes)
69+
.unwrap())
70+
}
71+
5172
pub async fn add_album(
5273
&self,
5374
album: &model::Album,

anni-metadata/src/annim/query.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod album;
2+
pub mod albums;
23
pub mod tag;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::annim::{schema, Uuid};
2+
3+
use super::album::AlbumFragment;
4+
5+
#[derive(cynic::QueryVariables, Debug)]
6+
pub struct AlbumsVariables {
7+
pub album_ids: Option<Vec<Uuid>>,
8+
pub after: Option<String>,
9+
pub first: Option<i32>,
10+
}
11+
12+
#[derive(cynic::QueryFragment, Debug)]
13+
#[cynic(graphql_type = "MetadataQuery", variables = "AlbumsVariables")]
14+
pub struct AlbumsQuery {
15+
#[arguments(by: { albumIds: $album_ids }, after: $after, first: $first )]
16+
pub albums: Option<AlbumConnection>,
17+
}
18+
19+
#[derive(cynic::QueryFragment, Debug)]
20+
pub struct AlbumConnection {
21+
pub page_info: PageInfo,
22+
pub nodes: Vec<AlbumFragment>,
23+
}
24+
25+
#[derive(cynic::QueryFragment, Debug)]
26+
pub struct PageInfo {
27+
pub end_cursor: Option<String>,
28+
pub has_next_page: bool,
29+
pub has_previous_page: bool,
30+
pub start_cursor: Option<String>,
31+
}

0 commit comments

Comments
 (0)