Refactor tags services and added tests

Implemented some functionality which will allow the service
configuration of the app to be split among the features for readability
and testability.
This commit is contained in:
Cameron Cordes
2023-03-19 15:05:20 -04:00
parent fbcfc68e01
commit de4041bd17
6 changed files with 143 additions and 50 deletions

View File

@@ -36,6 +36,7 @@ use crate::auth::login;
use crate::data::*;
use crate::database::*;
use crate::files::{is_image_or_video, is_valid_full_path};
use crate::service::ServiceBuilder;
use crate::state::AppState;
use crate::tags::*;
use crate::video::*;
@@ -49,6 +50,7 @@ mod state;
mod tags;
mod video;
mod service;
#[cfg(test)]
mod testhelpers;
@@ -482,14 +484,7 @@ fn main() -> std::io::Result<()> {
.service(put_add_favorite)
.service(delete_favorite)
.service(get_file_metadata)
.service(
web::resource("image/tags")
.route(web::post().to(add_tag::<SqliteTagDao>))
.route(web::get().to(get_tags::<SqliteTagDao>))
.route(web::delete().to(remove_tagged_photo::<SqliteTagDao>)),
)
.service(web::resource("image/tags/all").route(web::get().to(get_all_tags::<SqliteTagDao>)))
.service(web::resource("image/tags/batch").route(web::post().to(update_tags::<SqliteTagDao>)))
.add_feature(add_tag_services::<_, SqliteTagDao>)
.app_data(app_data.clone())
.app_data::<Data<Mutex<SqliteUserDao>>>(Data::new(Mutex::new(user_dao)))
.app_data::<Data<Mutex<Box<dyn FavoriteDao>>>>(Data::new(Mutex::new(Box::new(