feat: add created_at key
This commit is contained in:
parent
1934241057
commit
85bf1f36fc
|
@ -5,6 +5,8 @@ use crate::listing::PartyFinderListing;
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq)]
|
||||
pub struct ListingContainer {
|
||||
#[serde(with = "mongodb::bson::serde_helpers::chrono_datetime_as_bson_datetime")]
|
||||
pub created_at: DateTime<Utc>,
|
||||
#[serde(with = "mongodb::bson::serde_helpers::chrono_datetime_as_bson_datetime")]
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub listing: PartyFinderListing,
|
||||
|
@ -12,6 +14,8 @@ pub struct ListingContainer {
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize, PartialEq)]
|
||||
pub struct QueriedListing {
|
||||
#[serde(with = "mongodb::bson::serde_helpers::chrono_datetime_as_bson_datetime")]
|
||||
pub created_at: DateTime<Utc>,
|
||||
#[serde(with = "mongodb::bson::serde_helpers::chrono_datetime_as_bson_datetime")]
|
||||
pub updated_at: DateTime<Utc>,
|
||||
#[serde(with = "mongodb::bson::serde_helpers::chrono_datetime_as_bson_datetime")]
|
||||
|
|
|
@ -2,6 +2,7 @@ use std::cmp::Ordering;
|
|||
use std::convert::{Infallible, TryFrom};
|
||||
use anyhow::{Result, Context};
|
||||
use std::sync::Arc;
|
||||
use chrono::Utc;
|
||||
use mongodb::{Client as MongoClient, Collection, IndexModel};
|
||||
use mongodb::options::{IndexOptions, UpdateOptions};
|
||||
use mongodb::results::UpdateResult;
|
||||
|
@ -264,6 +265,7 @@ async fn insert_listing(state: &State, listing: PartyFinderListing) -> mongodb::
|
|||
.build();
|
||||
let value = serde_json::to_value(&listing).unwrap();
|
||||
let bson_value = mongodb::bson::Bson::try_from(value).unwrap();
|
||||
let now = Utc::now();
|
||||
state
|
||||
.collection()
|
||||
.update_one(
|
||||
|
@ -278,7 +280,10 @@ async fn insert_listing(state: &State, listing: PartyFinderListing) -> mongodb::
|
|||
},
|
||||
"$set": {
|
||||
"listing": bson_value,
|
||||
}
|
||||
},
|
||||
"$setOnInsert": {
|
||||
"created_at": now,
|
||||
},
|
||||
},
|
||||
opts,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue