|
23 | 23 | //! error rather than a missing row on a device, and a write says what it |
24 | 24 | //! changed — which is what an incrementally maintained query will need. |
25 | 25 |
|
| 26 | +// A mutation's arguments are the wire format: each one is a field in the |
| 27 | +// log, and every verb here is generated into several functions — the |
| 28 | +// authoring call, the dispatch arm, the foreign export. So the lint fires |
| 29 | +// on code nobody wrote, and the refactor it asks for (bundle them into a |
| 30 | +// struct) would put a second shape between a caller and the entry, which |
| 31 | +// is the thing `mutations.txt` exists to pin down. |
| 32 | +#![allow(clippy::too_many_arguments)] |
| 33 | + |
26 | 34 | use petros_schema::prelude::*; |
27 | 35 |
|
28 | 36 | // `#[mutation]` and `#[query]` each emit a method on the peer a foreign caller |
@@ -60,6 +68,16 @@ pub fn add_song( |
60 | 68 | album: String, |
61 | 69 | duration_ms: i64, |
62 | 70 | file: String, |
| 71 | + // Everything below was added after the log had entries in it. That is |
| 72 | + // allowed and is why the arguments are at the end: a payload written |
| 73 | + // before they existed decodes with each at its default, so an old entry |
| 74 | + // replays as a song with no track number and no catalogue — which is |
| 75 | + // exactly what it was. |
| 76 | + track: i64, |
| 77 | + part: String, |
| 78 | + catalogue: String, |
| 79 | + performer: String, |
| 80 | + bpm: i64, |
63 | 81 | ) -> Result { |
64 | 82 | if title.trim().is_empty() { |
65 | 83 | return Err("a song needs a title".into()); |
@@ -104,6 +122,16 @@ pub fn add_song( |
104 | 122 | db.put(&Song { |
105 | 123 | media_id: id, |
106 | 124 | album: album.trim().to_string(), |
| 125 | + // Negatives are not a position in an album, and neither is a number |
| 126 | + // past any plausible one: clamped rather than refused, because a bad |
| 127 | + // track number is not a reason to lose the recording. |
| 128 | + track: track.clamp(0, 999), |
| 129 | + part: part.trim().to_string(), |
| 130 | + catalogue: catalogue.trim().to_string(), |
| 131 | + performer: performer.trim().to_string(), |
| 132 | + // The slowest marking anybody writes is around 20 and the fastest |
| 133 | + // around 300; outside that it is not a tempo. |
| 134 | + bpm: if (20..=300).contains(&bpm) { bpm } else { 0 }, |
107 | 135 | })?; |
108 | 136 | Ok(()) |
109 | 137 | } |
@@ -420,13 +448,18 @@ pub fn artists(db: &mut Db) -> Result<Vec<crate::schema::Artist>> { |
420 | 448 | /// The column a table draws beside the artist. Read from the song end, so a |
421 | 449 | /// kind with no albums contributes nothing and needs no case here. |
422 | 450 | #[query] |
423 | | -pub fn track_albums(db: &mut Db) -> Result<Vec<crate::schema::TrackAlbum>> { |
| 451 | +pub fn track_details(db: &mut Db) -> Result<Vec<crate::schema::TrackDetail>> { |
424 | 452 | Ok(db |
425 | 453 | .select(Song::all()) |
426 | 454 | .into_iter() |
427 | | - .map(|s| crate::schema::TrackAlbum { |
| 455 | + .map(|s| crate::schema::TrackDetail { |
428 | 456 | media_id: s.media_id, |
429 | 457 | album: s.album, |
| 458 | + track: s.track, |
| 459 | + part: s.part, |
| 460 | + catalogue: s.catalogue, |
| 461 | + performer: s.performer, |
| 462 | + bpm: s.bpm, |
430 | 463 | }) |
431 | 464 | .collect()) |
432 | 465 | } |
|
0 commit comments