Skip to content

Commit

Permalink
fix: it now compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Jan 20, 2025
1 parent 39a315a commit f14ef6b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
15 changes: 6 additions & 9 deletions src/database/repository/developers.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::types::api::{ApiError, PaginatedData};
use crate::types::models::developer::{ModDeveloper, Developer};
use futures::TryFutureExt;
use sqlx::{PgConnection, Postgres, QueryBuilder};
use std::collections::hash_map::Entry;
use crate::types::models::developer::{Developer, ModDeveloper};
use sqlx::PgConnection;
use std::collections::HashMap;

pub async fn index(
Expand Down Expand Up @@ -129,10 +127,7 @@ async fn insert_github(
})?)
}

pub async fn get_one(
id: i32,
conn: &mut PgConnection,
) -> Result<Option<Developer>, ApiError> {
pub async fn get_one(id: i32, conn: &mut PgConnection) -> Result<Option<Developer>, ApiError> {
Ok(sqlx::query_as!(
Developer,
"SELECT
Expand Down Expand Up @@ -237,7 +232,7 @@ pub async fn get_all_for_mods(
ApiError::DbError
})?;

let mut ret = HashMap::new();
let mut ret: HashMap<String, Vec<ModDeveloper>> = HashMap::new();

for result_item in result {
ret.entry(result_item.mod_id)
Expand Down Expand Up @@ -361,6 +356,7 @@ pub async fn update_status(
dev_id
)
.fetch_one(&mut *conn)
.await
.map_err(|e| {
log::error!("Failed to update developer {}: {}", dev_id, e);
ApiError::DbError
Expand All @@ -387,6 +383,7 @@ pub async fn update_profile(
dev_id
)
.fetch_one(&mut *conn)
.await
.map_err(|e| {
log::error!("Failed to update profile for {}: {}", dev_id, e);
ApiError::DbError
Expand Down
20 changes: 8 additions & 12 deletions src/endpoints/developers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use actix_web::{delete, get, post, put, web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};
use sqlx::Acquire;

use crate::config::AppData;
use crate::database::repository::{auth_tokens, developers, mods};
Expand All @@ -9,13 +8,10 @@ use crate::{
types::{
api::{ApiError, ApiResponse},
models::{
developer::ModDeveloper,
mod_entity::Mod,
mod_version_status::ModVersionStatusEnum,
developer::ModDeveloper, mod_entity::Mod, mod_version_status::ModVersionStatusEnum,
},
},
};
use crate::types::models::developer::Developer;

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct SimpleDevMod {
Expand Down Expand Up @@ -104,10 +100,10 @@ pub async fn add_developer_to_mod(
.await
.or(Err(ApiError::DbAcquireError))?;

if (!mods::exists(&path.id, &mut pool).await?) {
if !mods::exists(&path.id, &mut pool).await? {
return Err(ApiError::NotFound(format!("Mod id {} not found", path.id)));
}
if !(developers::owns_mod(dev.id, &path.id, &mut pool).await?) {
if !developers::owns_mod(dev.id, &path.id, &mut pool).await? {
return Err(ApiError::Forbidden);
}

Expand Down Expand Up @@ -136,11 +132,11 @@ pub async fn remove_dev_from_mod(
.await
.or(Err(ApiError::DbAcquireError))?;

if (!mods::exists(&path.id, &mut pool).await) {
if !mods::exists(&path.id, &mut pool).await? {
return Err(ApiError::NotFound(format!("Mod id {} not found", path.id)));
}

if !(developers::owns_mod(dev.id, &path.id, &mut pool).await?) {
if !developers::owns_mod(dev.id, &path.id, &mut pool).await? {
return Err(ApiError::Forbidden);
}

Expand Down Expand Up @@ -300,7 +296,7 @@ pub async fn update_developer(
auth.admin()?;

if payload.admin.is_none() && payload.verified.is_none() {
return Ok(HttpResponse::Ok());
return Err(ApiError::BadRequest("Specify at least one param to modify".into()))
}

let mut pool = data
Expand All @@ -321,7 +317,7 @@ pub async fn update_developer(
} else {
developers::get_one(path.id, &mut pool)
.await?
.ok_or(ApiError::NotFound("Developer not found".into()))?;
.ok_or(ApiError::NotFound("Developer not found".into()))?
}
};

Expand All @@ -334,7 +330,7 @@ pub async fn update_developer(
.await?;

Ok(web::Json(ApiResponse {
error: "".into(),
error: "".to_string(),
payload: result,
}))
}
1 change: 0 additions & 1 deletion src/endpoints/mod_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::{
api::{ApiError, ApiResponse},
mod_json::{split_version_and_compare, ModJson},
models::{
developer::ModDeveloper,
mod_entity::{download_geode_file, Mod},
mod_gd_version::{GDVersionEnum, VerPlatform},
mod_version::{self, ModVersion},
Expand Down
1 change: 0 additions & 1 deletion src/endpoints/mods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::events::mod_feature::ModFeaturedEvent;
use crate::extractors::auth::Auth;
use crate::types::api::{create_download_link, ApiError, ApiResponse};
use crate::types::mod_json::ModJson;
use crate::types::models::developer::ModDeveloper;
use crate::types::models::incompatibility::Incompatibility;
use crate::types::models::mod_entity::{download_geode_file, Mod, ModUpdate};
use crate::types::models::mod_gd_version::{GDVersionEnum, VerPlatform};
Expand Down
2 changes: 1 addition & 1 deletion src/types/models/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use reqwest::{header::HeaderValue, Client};
use serde::{Deserialize, Serialize};
use sqlx::PgConnection;

use super::{developer::ModDeveloper, mod_entity::Mod};
use super::mod_entity::Mod;

#[derive(Deserialize)]
struct GithubReleaseAsset {
Expand Down

0 comments on commit f14ef6b

Please sign in to comment.