Create Delete Tag endpoint
Some checks failed
Core Repos/ImageApi/pipeline/pr-master There was a failure building this commit
Some checks failed
Core Repos/ImageApi/pipeline/pr-master There was a failure building this commit
This commit is contained in:
34
src/main.rs
34
src/main.rs
@@ -401,6 +401,39 @@ async fn get_tags(_: Claims, request: web::Query<ThumbnailRequest>) -> impl Resp
|
||||
}
|
||||
}
|
||||
|
||||
#[delete("image/tags")]
|
||||
async fn remove_tagged_photo(_: Claims, request: web::Json<AddTagRequest>) -> impl Responder {
|
||||
use schema::tags;
|
||||
match tags::table
|
||||
.filter(tags::name.eq(&request.tag_name))
|
||||
.get_result::<Tag>(&connect())
|
||||
.optional()
|
||||
.and_then(|tag| {
|
||||
if let Some(tag) = tag {
|
||||
use schema::tagged_photo;
|
||||
diesel::delete(
|
||||
tagged_photo::table
|
||||
.filter(tagged_photo::tag_id.eq(tag.id))
|
||||
.filter(tagged_photo::photo_name.eq(&request.file_name)),
|
||||
)
|
||||
.execute(&connect())
|
||||
.map(|_| HttpResponse::Ok())
|
||||
} else {
|
||||
info!("No tag found with name '{}'", &request.tag_name);
|
||||
Ok(HttpResponse::NotFound())
|
||||
}
|
||||
}) {
|
||||
Ok(status) => status,
|
||||
Err(err) => {
|
||||
error!(
|
||||
"Error removing tag '{}' from file: {}. {:?}",
|
||||
&request.tag_name, &request.file_name, err
|
||||
);
|
||||
HttpResponse::InternalServerError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_thumbnails() {
|
||||
let thumbs = &dotenv::var("THUMBNAILS").expect("THUMBNAILS not defined");
|
||||
let thumbnail_directory: &Path = Path::new(thumbs);
|
||||
@@ -585,6 +618,7 @@ fn main() -> std::io::Result<()> {
|
||||
.service(get_file_metadata)
|
||||
.service(add_tag)
|
||||
.service(get_tags)
|
||||
.service(remove_tagged_photo)
|
||||
.app_data(app_data.clone())
|
||||
.data::<Box<dyn UserDao>>(Box::new(user_dao))
|
||||
.data::<Box<dyn FavoriteDao>>(Box::new(favorites_dao))
|
||||
|
||||
Reference in New Issue
Block a user