Skip to content

Commit

Permalink
include created_at and updated_at in mod payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Mar 2, 2024
1 parent afae0b9 commit 88754d9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
9 changes: 6 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ sha256 = "1.5.0"
semver = "1.0.21"
clap = { version = "4.5.1", features = ["derive"] }
regex = "1.10.3"
chrono = "0.4.34"
28 changes: 24 additions & 4 deletions src/types/models/mod_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ use crate::{
},
};
use actix_web::web::Bytes;
use chrono::SecondsFormat;
use reqwest::Client;
use serde::Serialize;
use sqlx::{PgConnection, Postgres, QueryBuilder};
use sqlx::{
types::chrono::{DateTime, Utc},
PgConnection, Postgres, QueryBuilder,
};
use std::{collections::HashMap, io::Cursor, str::FromStr};

use super::{
Expand All @@ -38,6 +42,8 @@ pub struct Mod {
pub tags: Vec<String>,
pub about: Option<String>,
pub changelog: Option<String>,
pub created_at: String,
pub updated_at: String,
}

#[derive(Serialize, Debug)]
Expand All @@ -58,6 +64,8 @@ struct ModRecord {
featured: bool,
about: Option<String>,
changelog: Option<String>,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
}

#[derive(sqlx::FromRow)]
Expand All @@ -79,6 +87,8 @@ struct ModRecordGetOne {
mod_id: String,
about: Option<String>,
changelog: Option<String>,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
}

impl Mod {
Expand Down Expand Up @@ -111,8 +121,8 @@ impl Mod {
}
}
let mut builder: QueryBuilder<Postgres> = QueryBuilder::new(
"SELECT q.id, q.repository, q.about, q.changelog, q.download_count, q.featured
FROM (SELECT m.id, m.repository, m.about, m.changelog, m.download_count, m.featured, m.updated_at,
"SELECT q.id, q.repository, q.about, q.changelog, q.download_count, q.featured, q.created_at, q.updated_at
FROM (SELECT m.id, m.repository, m.about, m.changelog, m.download_count, m.featured, m.created_at, m.updated_at,
row_number() over (partition by m.id order by mv.id desc) rn FROM mods m
INNER JOIN mod_versions mv ON m.id = mv.mod_id
INNER JOIN mod_gd_versions mgv ON mgv.mod_id = mv.id "
Expand Down Expand Up @@ -320,6 +330,8 @@ impl Mod {
versions: vec![version],
tags,
developers: devs,
created_at: x.created_at.to_rfc3339_opts(SecondsFormat::Secs, true),
updated_at: x.updated_at.to_rfc3339_opts(SecondsFormat::Secs, true),
about: None,
changelog: None,
}
Expand Down Expand Up @@ -361,6 +373,8 @@ impl Mod {
versions: version,
tags,
developers: devs,
created_at: x.created_at.to_rfc3339_opts(SecondsFormat::Secs, true),
updated_at: x.updated_at.to_rfc3339_opts(SecondsFormat::Secs, true),
about: x.about,
changelog: x.changelog,
}
Expand Down Expand Up @@ -450,7 +464,7 @@ impl Mod {
let records: Vec<ModRecordGetOne> = sqlx::query_as!(
ModRecordGetOne,
"SELECT
m.id, m.repository, m.about, m.changelog, m.featured, m.download_count as mod_download_count,
m.id, m.repository, m.about, m.changelog, m.featured, m.download_count as mod_download_count, m.created_at, m.updated_at,
mv.id as version_id, mv.name, mv.description, mv.version, mv.download_link, mv.download_count as mod_version_download_count,
mv.hash, mv.geode, mv.early_load, mv.api, mv.mod_id
FROM mods m
Expand Down Expand Up @@ -508,6 +522,12 @@ impl Mod {
versions,
tags,
developers: devs,
created_at: records[0]
.created_at
.to_rfc3339_opts(SecondsFormat::Secs, true),
updated_at: records[0]
.updated_at
.to_rfc3339_opts(SecondsFormat::Secs, true),
about: records[0].about.clone(),
changelog: records[0].changelog.clone(),
};
Expand Down

0 comments on commit 88754d9

Please sign in to comment.