Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mickvandijke committed Jun 8, 2023
1 parent 4286ba9 commit a6cf184
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 47 deletions.
5 changes: 4 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use crate::config::Configuration;
use crate::databases::database;
use crate::services::authentication::{DbUserAuthenticationRepository, JsonWebToken, Service};
use crate::services::category::{self, DbCategoryRepository};
use crate::services::torrent::{DbTorrentAnnounceUrlRepository, DbTorrentFileRepository, DbTorrentInfoRepository, DbTorrentListingGenerator, DbTorrentRepository, DbTorrentTagRepository};
use crate::services::torrent::{
DbTorrentAnnounceUrlRepository, DbTorrentFileRepository, DbTorrentInfoRepository, DbTorrentListingGenerator,
DbTorrentRepository, DbTorrentTagRepository,
};
use crate::services::user::{self, DbBannedUserList, DbUserProfileRepository, DbUserRepository};
use crate::services::{proxy, settings, torrent};
use crate::tracker::statistics_importer::StatisticsImporter;
Expand Down
5 changes: 4 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::config::Configuration;
use crate::databases::database::Database;
use crate::services::authentication::{DbUserAuthenticationRepository, JsonWebToken, Service};
use crate::services::category::{self, DbCategoryRepository};
use crate::services::torrent::{DbTorrentAnnounceUrlRepository, DbTorrentFileRepository, DbTorrentInfoRepository, DbTorrentListingGenerator, DbTorrentRepository, DbTorrentTagRepository};
use crate::services::torrent::{
DbTorrentAnnounceUrlRepository, DbTorrentFileRepository, DbTorrentInfoRepository, DbTorrentListingGenerator,
DbTorrentRepository, DbTorrentTagRepository,
};
use crate::services::user::{self, DbBannedUserList, DbUserProfileRepository, DbUserRepository};
use crate::services::{proxy, settings, torrent};
use crate::tracker::statistics_importer::StatisticsImporter;
Expand Down
21 changes: 11 additions & 10 deletions src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,9 @@ impl Database for Mysql {
}

async fn add_torrent_tag_links(&self, torrent_id: i64, tag_ids: &Vec<TagId>) -> Result<(), database::Error> {
let mut transaction = self.pool.begin()
let mut transaction = self
.pool
.begin()
.await
.map_err(|err| database::Error::ErrorWithText(err.to_string()))?;

Expand All @@ -738,7 +740,8 @@ impl Database for Mysql {
.map_err(|err| database::Error::ErrorWithText(err.to_string()))?;
}

transaction.commit()
transaction
.commit()
.await
.map_err(|err| database::Error::ErrorWithText(err.to_string()))
}
Expand Down Expand Up @@ -771,9 +774,7 @@ impl Database for Mysql {
}

async fn get_tags(&self) -> Result<Vec<TorrentTag>, database::Error> {
query_as::<_, TorrentTag>(
"SELECT tag_id, name FROM torrust_torrent_tags"
)
query_as::<_, TorrentTag>("SELECT tag_id, name FROM torrust_torrent_tags")
.fetch_all(&self.pool)
.await
.map_err(|_| database::Error::Error)
Expand All @@ -784,12 +785,12 @@ impl Database for Mysql {
"SELECT torrust_torrent_tags.tag_id, torrust_torrent_tags.name
FROM torrust_torrent_tags
JOIN torrust_torrent_tag_links ON torrust_torrent_tags.tag_id = torrust_torrent_tag_links.tag_id
WHERE torrust_torrent_tag_links.torrent_id = ?"
WHERE torrust_torrent_tag_links.torrent_id = ?",
)
.bind(torrent_id)
.fetch_all(&self.pool)
.await
.map_err(|_| database::Error::Error)
.bind(torrent_id)
.fetch_all(&self.pool)
.await
.map_err(|_| database::Error::Error)
}

async fn update_tracker_info(
Expand Down
21 changes: 11 additions & 10 deletions src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,9 @@ impl Database for Sqlite {
}

async fn add_torrent_tag_links(&self, torrent_id: i64, tag_ids: &Vec<TagId>) -> Result<(), database::Error> {
let mut transaction = self.pool.begin()
let mut transaction = self
.pool
.begin()
.await
.map_err(|err| database::Error::ErrorWithText(err.to_string()))?;

Expand All @@ -728,7 +730,8 @@ impl Database for Sqlite {
.map_err(|err| database::Error::ErrorWithText(err.to_string()))?;
}

transaction.commit()
transaction
.commit()
.await
.map_err(|err| database::Error::ErrorWithText(err.to_string()))
}
Expand Down Expand Up @@ -761,9 +764,7 @@ impl Database for Sqlite {
}

async fn get_tags(&self) -> Result<Vec<TorrentTag>, database::Error> {
query_as::<_, TorrentTag>(
"SELECT tag_id, name FROM torrust_torrent_tags"
)
query_as::<_, TorrentTag>("SELECT tag_id, name FROM torrust_torrent_tags")
.fetch_all(&self.pool)
.await
.map_err(|_| database::Error::Error)
Expand All @@ -774,12 +775,12 @@ impl Database for Sqlite {
"SELECT torrust_torrent_tags.tag_id, torrust_torrent_tags.name
FROM torrust_torrent_tags
JOIN torrust_torrent_tag_links ON torrust_torrent_tags.tag_id = torrust_torrent_tag_links.tag_id
WHERE torrust_torrent_tag_links.torrent_id = ?"
WHERE torrust_torrent_tag_links.torrent_id = ?",
)
.bind(torrent_id)
.fetch_all(&self.pool)
.await
.map_err(|_| database::Error::Error)
.bind(torrent_id)
.fetch_all(&self.pool)
.await
.map_err(|_| database::Error::Error)
}

async fn update_tracker_info(
Expand Down
2 changes: 1 addition & 1 deletion src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ pub mod info_hash;
pub mod response;
pub mod torrent;
pub mod torrent_file;
pub mod torrent_tag;
pub mod tracker_key;
pub mod user;
pub mod torrent_tag;
2 changes: 1 addition & 1 deletion src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ pub mod category;
pub mod proxy;
pub mod root;
pub mod settings;
pub mod tag;
pub mod torrent;
pub mod user;
pub mod tag;

pub const API_VERSION: &str = "v1";

Expand Down
23 changes: 5 additions & 18 deletions src/routes/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@ use crate::routes::API_VERSION;

pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope(&format!("/{API_VERSION}/tag"))
.service(
web::scope(&format!("/{API_VERSION}/tag")).service(
web::resource("")
.route(web::post().to(add_tag))
.route(web::delete().to(delete_tag)),
)
);
cfg.service(
web::scope(&format!("/{API_VERSION}/tags"))
.service(
web::resource("")
.route(web::get().to(get_tags))
)
),
);
cfg.service(web::scope(&format!("/{API_VERSION}/tags")).service(web::resource("").route(web::get().to(get_tags))));
}

pub async fn get_tags(app_data: WebAppData) -> ServiceResult<impl Responder> {
Expand Down Expand Up @@ -58,11 +51,7 @@ pub struct DeleteTag {
pub tag_id: TagId,
}

pub async fn delete_tag(
req: HttpRequest,
payload: web::Json<DeleteTag>,
app_data: WebAppData,
) -> ServiceResult<impl Responder> {
pub async fn delete_tag(req: HttpRequest, payload: web::Json<DeleteTag>, app_data: WebAppData) -> ServiceResult<impl Responder> {
let user_id = app_data.auth.get_user_id_from_request(&req).await?;

let user = app_data.user_repository.get_compact(&user_id).await?;
Expand All @@ -74,7 +63,5 @@ pub async fn delete_tag(

app_data.torrent_tag_repository.delete_tag(&payload.tag_id).await?;

Ok(HttpResponse::Ok().json(OkResponse {
data: payload.tag_id,
}))
Ok(HttpResponse::Ok().json(OkResponse { data: payload.tag_id }))
}
4 changes: 2 additions & 2 deletions src/routes/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct Create {
pub title: String,
pub description: String,
pub category: String,
pub tags: Vec<TagId>
pub tags: Vec<TagId>,
}

impl Create {
Expand Down Expand Up @@ -236,7 +236,7 @@ async fn get_torrent_request_from_payload(mut payload: Multipart) -> Result<Torr
title,
description,
category,
tags
tags,
};

fields.verify()?;
Expand Down
10 changes: 7 additions & 3 deletions src/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::models::info_hash::InfoHash;
use crate::models::response::{DeletedTorrentResponse, TorrentResponse, TorrentsResponse};
use crate::models::torrent::{TorrentId, TorrentListing, TorrentRequest};
use crate::models::torrent_file::{DbTorrentInfo, Torrent, TorrentFile};
use crate::models::torrent_tag::{TagId, TorrentTag};
use crate::models::user::UserId;
use crate::tracker::statistics_importer::StatisticsImporter;
use crate::{tracker, AsCSV};
use crate::models::torrent_tag::{TagId, TorrentTag};

pub struct Index {
configuration: Arc<Configuration>,
Expand Down Expand Up @@ -124,7 +124,9 @@ impl Index {
return Err(e);
}

self.torrent_tag_repository.link_torrent_to_tags(&torrent_id, &torrent_request.fields.tags).await?;
self.torrent_tag_repository
.link_torrent_to_tags(&torrent_id, &torrent_request.fields.tags)
.await?;

Ok(torrent_id)
}
Expand Down Expand Up @@ -476,7 +478,9 @@ impl DbTorrentInfoRepository {
}

if let Some(tags) = opt_tags {
let mut current_tags: Vec<TagId> = self.database.get_tags_for_torrent_id(*torrent_id)
let mut current_tags: Vec<TagId> = self
.database
.get_tags_for_torrent_id(*torrent_id)
.await?
.iter()
.map(|tag| tag.tag_id)
Expand Down

0 comments on commit a6cf184

Please sign in to comment.