sunday_slate/fantasy_teams/
model.rs1use crate::media::Media;
2use crate::media::MediaId;
3use time::PrimitiveDateTime;
4
5#[derive(Debug, Clone, sqlx::FromRow)]
6pub struct FantasyTeam {
7 pub id: i64,
8 pub league_id: i64,
9 pub user_id: i64,
10 pub name: String,
11 pub owner_name: String,
12 pub logo_media_id: Option<MediaId>,
13 pub is_commissioner: bool,
14 pub created_at: PrimitiveDateTime,
15 pub updated_at: PrimitiveDateTime,
16}
17
18pub struct LeagueTeam {
21 pub id: FantasyTeamId,
22 pub name: String,
23 pub owner_name: String,
24 pub logo: Option<Media>,
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, sqlx::Type)]
30#[sqlx(transparent)]
31pub struct FantasyTeamId(pub i64);
32
33pub fn monogram(name: &str) -> String {
35 name.split_whitespace()
36 .filter_map(|w| w.chars().next())
37 .take(2)
38 .collect::<String>()
39 .to_uppercase()
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn monogram_takes_up_to_two_initials() {
48 assert_eq!(monogram("Gridiron Giants"), "GG");
49 assert_eq!(monogram("Solo"), "S");
50 assert_eq!(monogram("a b c"), "AB");
51 assert_eq!(monogram(""), "");
52 }
53}