forked from
rocksky.app/rocksky
A decentralized music tracking and discovery platform built on AT Protocol 馃幍
1use serde_json::{json, Value};
2
3use crate::types::Scrobble;
4
5pub fn build_response(scrobbles: Vec<Scrobble>) -> Value {
6 json!({
7 "scrobbles": {
8 "@attr": {
9 "accepted": scrobbles.len().to_string(),
10 "ignored": "0"
11 },
12 "scrobble": scrobbles.iter().map(|s| json!({
13 "artist": { "#text": s.artist, "corrected": "0" },
14 "track": { "#text": s.track, "corrected": "0" },
15 "album": { "#text": s.album.clone().unwrap_or_default(), "corrected": "0" },
16 "timestamp": s.timestamp.to_string(),
17 "ignoredMessage": {
18 "#text": "",
19 "code": match s.ignored {
20 Some(true) => "1",
21 Some(false) => "0",
22 None => "0"
23 }
24 }
25 })).collect::<Vec<_>>()
26 }
27 })
28}