Skip to content

Commit bee2980

Browse files
Clean diff
1 parent eb95673 commit bee2980

File tree

5 files changed

+13
-35
lines changed

5 files changed

+13
-35
lines changed

src/abbreviate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const ONE_THOUSAND: f64 = 1_000.0;
22
const ONE_MILLION: f64 = 1_000_000.0;
3-
const ONE_MORBILLION: f64 = 1_000_000_000.0;
3+
const ONE_BILLION: f64 = 1_000_000_000.0;
44

55
pub fn abbreviate_number(n: i32) -> String {
66
let n = n as f64;
7-
if n.abs() >= ONE_MORBILLION {
8-
format!("{:.1}B", n / ONE_MORBILLION)
7+
if n.abs() >= ONE_BILLION {
8+
format!("{:.1}B", n / ONE_BILLION)
99
} else if n.abs() >= ONE_MILLION {
1010
format!("{:.1}M", n / ONE_MILLION)
1111
} else if n.abs() >= ONE_THOUSAND {

src/endpoints/mods.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ use crate::types::models::mod_version_status::ModVersionStatusEnum;
2626
use crate::webhook::discord::DiscordWebhook;
2727
use actix_web::{HttpResponse, Responder, get, post, put, web};
2828
use serde::Deserialize;
29-
use sqlx::Acquire;
30-
use utoipa::{IntoParams, ToSchema};
3129
use serde::Serialize;
30+
use sqlx::Acquire;
31+
use utoipa::{ToSchema, IntoParams};
3232

3333
#[derive(Deserialize, Default, Hash, Eq, PartialEq, ToSchema)]
3434
#[serde(rename_all = "snake_case")]
@@ -78,6 +78,7 @@ pub struct CreateQueryParams {
7878
(status = 403, description = "Forbidden")
7979
)
8080
)]
81+
8182
#[get("/v1/mods")]
8283
pub async fn index(
8384
data: web::Data<AppData>,
@@ -214,9 +215,7 @@ pub async fn create(
214215
let existing: Option<Mod> = mods::get_one(&json.id, false, &mut pool).await?;
215216

216217
if json.id.starts_with("geode.") && !dev.admin {
217-
return Err(ApiError::BadRequest(
218-
"Only index admins may use mod ids that start with 'geode.'".into(),
219-
));
218+
return Err(ApiError::BadRequest("Only index admins may use mod ids that start with 'geode.'".into()));
220219
}
221220

222221
if let Some(m) = &existing {

src/types/models/download_count.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,3 @@ impl Serialize for DownloadCount {
3838
}
3939
}
4040
}
41-
42-
#[cfg(test)]
43-
mod tests {
44-
use super::DownloadCount;
45-
46-
#[test]
47-
fn serializes_as_number_by_default() {
48-
let serialized = serde_json::to_string(&DownloadCount::new(1234)).unwrap();
49-
50-
assert_eq!(serialized, "1234");
51-
}
52-
53-
#[test]
54-
fn serializes_as_abbreviated_string_when_enabled() {
55-
let mut count = DownloadCount::new(1234);
56-
count.set_abbreviated(true);
57-
let serialized = serde_json::to_string(&count).unwrap();
58-
59-
assert_eq!(serialized, "\"1.2K\"");
60-
}
61-
}

src/types/models/mod_entity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ use crate::{
2323
},
2424
};
2525
use semver::Version;
26+
use serde::Serialize;
27+
use utoipa::ToSchema;
2628
use sqlx::{
2729
PgConnection,
2830
types::chrono::{DateTime, Utc},
2931
};
3032
use std::collections::HashMap;
31-
use serde::Serialize;
32-
use utoipa::ToSchema;
3333

34-
#[derive(Serialize, Debug, Clone, ToSchema)]
34+
#[derive(Serialize, Debug, Clone, sqlx::FromRow, ToSchema)]
3535
pub struct Mod {
3636
pub id: String,
3737
pub repository: Option<String>,

src/types/models/mod_version.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use crate::types::{
1414
serde::chrono_dt_secs,
1515
};
1616
use semver::Version;
17+
use serde::Serialize;
18+
use utoipa::ToSchema;
1719
use sqlx::{
1820
PgConnection, Postgres, QueryBuilder,
1921
types::chrono::{DateTime, Utc},
2022
};
2123
use std::collections::HashMap;
22-
use serde::Serialize;
23-
use utoipa::ToSchema;
2424

25-
#[derive(Serialize, Debug, Clone, ToSchema)]
25+
#[derive(Serialize, Debug, sqlx::FromRow, Clone, ToSchema)]
2626
pub struct ModVersion {
2727
#[serde(skip_serializing)]
2828
pub id: i32,

0 commit comments

Comments
 (0)