Add created timestamps for tags

This commit is contained in:
Cameron Cordes
2021-10-11 21:32:17 -04:00
parent 9d925be84d
commit 2e5ac8861c
4 changed files with 16 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ extern crate diesel;
extern crate rayon;
use actix_web_prom::PrometheusMetrics;
use chrono::Utc;
use futures::stream::StreamExt;
use lazy_static::lazy_static;
use prometheus::{self, IntGauge};
@@ -310,7 +311,10 @@ async fn add_tag(_: Claims, body: web::Json<AddTagRequest>) -> impl Responder {
Ok(t.id)
} else {
match diesel::insert_into(tags::table)
.values(InsertTag { name: tag.clone() })
.values(InsertTag {
name: tag.clone(),
created_time: Utc::now().timestamp(),
})
.execute(connection)
.and_then(|_| {
no_arg_sql_function!(
@@ -347,6 +351,7 @@ async fn add_tag(_: Claims, body: web::Json<AddTagRequest>) -> impl Responder {
.values(InsertTaggedPhoto {
tag_id,
photo_name: file_name.clone(),
created_time: Utc::now().timestamp(),
})
.execute(connection)
.map(|_| {
@@ -384,7 +389,7 @@ async fn get_tags(_: Claims, request: web::Query<ThumbnailRequest>) -> impl Resp
match tags::table
.left_join(tagged_photo::table)
.filter(tagged_photo::photo_name.eq(&request.path))
.select((tags::id, tags::name))
.select((tags::id, tags::name, tags::created_time))
.get_results::<Tag>(&connect())
{
Ok(tags) => HttpResponse::Ok().json(tags),