feat(domain): add StoredSong, SongSummary, SongRepositoryPort
This commit is contained in:
@@ -60,6 +60,40 @@ pub struct Song {
|
||||
pub sections: Vec<Section>,
|
||||
}
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct StoredSong {
|
||||
pub id: Uuid,
|
||||
pub song: Song,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SongSummary {
|
||||
pub id: Uuid,
|
||||
pub meta: SongMeta,
|
||||
pub preview_chords: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn song_preview_chords(song: &Song) -> Vec<String> {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
let mut result = Vec::new();
|
||||
'outer: for section in &song.sections {
|
||||
for line in §ion.lines {
|
||||
for cp in &line.chords {
|
||||
let name = cp.chord.name(true);
|
||||
if seen.insert(name.clone()) {
|
||||
result.push(name);
|
||||
if result.len() >= 5 {
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user