Skip to content

Commit

Permalink
chore: clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mickvandijke committed Jun 8, 2023
1 parent a6cf184 commit 4730afd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
39 changes: 31 additions & 8 deletions src/routes/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,39 @@ pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope(&format!("/{API_VERSION}/tag")).service(
web::resource("")
.route(web::post().to(add_tag))
.route(web::delete().to(delete_tag)),
.route(web::post().to(create))
.route(web::delete().to(delete)),
),
);
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_all))));
}

pub async fn get_tags(app_data: WebAppData) -> ServiceResult<impl Responder> {
/// Get Tags
///
/// # Errors
///
/// This function will return an error if unable to get tags from database.
pub async fn get_all(app_data: WebAppData) -> ServiceResult<impl Responder> {
let tags = app_data.torrent_tag_repository.get_tags().await?;

Ok(HttpResponse::Ok().json(OkResponse { data: tags }))
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AddTag {
pub struct Create {
pub name: String,
}

pub async fn add_tag(req: HttpRequest, payload: web::Json<AddTag>, app_data: WebAppData) -> ServiceResult<impl Responder> {
/// Create Tag
///
/// # Errors
///
/// This function will return an error if unable to:
///
/// * Get the requesting user id from the request.
/// * Get the compact user from the user id.
/// * Add the new tag to the database.
pub async fn create(req: HttpRequest, payload: web::Json<Create>, 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 @@ -47,11 +61,20 @@ pub async fn add_tag(req: HttpRequest, payload: web::Json<AddTag>, app_data: Web
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DeleteTag {
pub struct Delete {
pub tag_id: TagId,
}

pub async fn delete_tag(req: HttpRequest, payload: web::Json<DeleteTag>, app_data: WebAppData) -> ServiceResult<impl Responder> {
/// Delete Tag
///
/// # Errors
///
/// This function will return an error if unable to:
///
/// * Get the requesting user id from the request.
/// * Get the compact user from the user id.
/// * Delete the tag from the database.
pub async fn delete(req: HttpRequest, payload: web::Json<Delete>, 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 Down
2 changes: 1 addition & 1 deletion src/services/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl Service {
// Renew token if it is valid for less than one week
let token = match claims.exp - clock::now() {
x if x < ONE_WEEK_IN_SECONDS => self.json_web_token.sign(user_compact.clone()).await,
_ => token.clone().to_owned(),
_ => token.to_string(),
};

Ok((token, user_compact))
Expand Down
4 changes: 2 additions & 2 deletions src/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ impl DbTorrentInfoRepository {

let mut new_tags = tags.clone();

current_tags.sort();
new_tags.sort();
current_tags.sort_unstable();
new_tags.sort_unstable();

if new_tags != current_tags {
self.database.delete_all_torrent_tag_links(*torrent_id).await?;
Expand Down

0 comments on commit 4730afd

Please sign in to comment.