Add created timestamps for tags
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
CREATE TABLE tags (
|
CREATE TABLE tags (
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
name TEXT NOT NULL
|
name TEXT NOT NULL,
|
||||||
|
created_time BIGINT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE tagged_photo (
|
CREATE TABLE tagged_photo (
|
||||||
id INTEGER PRIMARY KEY NOT NULL,
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
photo_name TEXT NOT NULL,
|
photo_name TEXT NOT NULL,
|
||||||
tag_id INTEGER NOT NULL,
|
tag_id INTEGER NOT NULL,
|
||||||
|
created_time BIGINT NOT NULL,
|
||||||
CONSTRAINT tagid FOREIGN KEY (tag_id) REFERENCES tags (id) ON DELETE CASCADE ON UPDATE CASCADE
|
CONSTRAINT tagid FOREIGN KEY (tag_id) REFERENCES tags (id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,12 +34,14 @@ pub struct Favorite {
|
|||||||
pub struct Tag {
|
pub struct Tag {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub created_time: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, Clone, Debug)]
|
#[derive(Insertable, Clone, Debug)]
|
||||||
#[table_name = "tags"]
|
#[table_name = "tags"]
|
||||||
pub struct InsertTag {
|
pub struct InsertTag {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub created_time: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, Clone, Debug)]
|
#[derive(Insertable, Clone, Debug)]
|
||||||
@@ -47,6 +49,7 @@ pub struct InsertTag {
|
|||||||
pub struct InsertTaggedPhoto {
|
pub struct InsertTaggedPhoto {
|
||||||
pub tag_id: i32,
|
pub tag_id: i32,
|
||||||
pub photo_name: String,
|
pub photo_name: String,
|
||||||
|
pub created_time: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Queryable, Clone, Debug)]
|
#[derive(Queryable, Clone, Debug)]
|
||||||
@@ -54,4 +57,5 @@ pub struct TaggedPhoto {
|
|||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub photo_name: String,
|
pub photo_name: String,
|
||||||
pub tag_id: i32,
|
pub tag_id: i32,
|
||||||
|
pub created_time: i64,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ table! {
|
|||||||
id -> Integer,
|
id -> Integer,
|
||||||
photo_name -> Text,
|
photo_name -> Text,
|
||||||
tag_id -> Integer,
|
tag_id -> Integer,
|
||||||
|
created_time -> BigInt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ table! {
|
|||||||
tags (id) {
|
tags (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
|
created_time -> BigInt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ extern crate diesel;
|
|||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
|
|
||||||
use actix_web_prom::PrometheusMetrics;
|
use actix_web_prom::PrometheusMetrics;
|
||||||
|
use chrono::Utc;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use prometheus::{self, IntGauge};
|
use prometheus::{self, IntGauge};
|
||||||
@@ -310,7 +311,10 @@ async fn add_tag(_: Claims, body: web::Json<AddTagRequest>) -> impl Responder {
|
|||||||
Ok(t.id)
|
Ok(t.id)
|
||||||
} else {
|
} else {
|
||||||
match diesel::insert_into(tags::table)
|
match diesel::insert_into(tags::table)
|
||||||
.values(InsertTag { name: tag.clone() })
|
.values(InsertTag {
|
||||||
|
name: tag.clone(),
|
||||||
|
created_time: Utc::now().timestamp(),
|
||||||
|
})
|
||||||
.execute(connection)
|
.execute(connection)
|
||||||
.and_then(|_| {
|
.and_then(|_| {
|
||||||
no_arg_sql_function!(
|
no_arg_sql_function!(
|
||||||
@@ -347,6 +351,7 @@ async fn add_tag(_: Claims, body: web::Json<AddTagRequest>) -> impl Responder {
|
|||||||
.values(InsertTaggedPhoto {
|
.values(InsertTaggedPhoto {
|
||||||
tag_id,
|
tag_id,
|
||||||
photo_name: file_name.clone(),
|
photo_name: file_name.clone(),
|
||||||
|
created_time: Utc::now().timestamp(),
|
||||||
})
|
})
|
||||||
.execute(connection)
|
.execute(connection)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
@@ -384,7 +389,7 @@ async fn get_tags(_: Claims, request: web::Query<ThumbnailRequest>) -> impl Resp
|
|||||||
match tags::table
|
match tags::table
|
||||||
.left_join(tagged_photo::table)
|
.left_join(tagged_photo::table)
|
||||||
.filter(tagged_photo::photo_name.eq(&request.path))
|
.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())
|
.get_results::<Tag>(&connect())
|
||||||
{
|
{
|
||||||
Ok(tags) => HttpResponse::Ok().json(tags),
|
Ok(tags) => HttpResponse::Ok().json(tags),
|
||||||
|
|||||||
Reference in New Issue
Block a user