yggdrasil/src/util/structs/cape.rs

39 lines
1.4 KiB
Rust

/*
* Yggdrasil: Minecraft authentication server
* Copyright (C) 2023 0xf8.dev@proton.me
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use log::debug;
use serde::{Deserialize, Serialize};
use crate::*;
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Cape {
pub id: i64,
pub friendly_id: String,
pub alias: String,
}
impl Cape {
pub async fn from_id(db: &Database, id: i64) -> Option<Self> {
let record = sqlx::query_as!(Cape, "SELECT * FROM capes WHERE id = $1", id)
.fetch_one(&db.pool)
.await;
match record {
Ok(r) => Some(r),
Err(e) => { debug!("{e}"); None },
}
}
pub fn capes_to_string(capes: Vec<Cape>) -> String {
capes.into_iter().map(|c| c.alias).collect::<Vec<String>>().join(",")
}
}