Skip to content

Commit 746397d

Browse files
committed
fix: remove some more unused things
1 parent 681fe0a commit 746397d

File tree

3 files changed

+2
-138
lines changed

3 files changed

+2
-138
lines changed

src/types/models/incompatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashMap;
33
use crate::types::api::ApiError;
44
use crate::types::models::dependency::ModVersionCompare;
55
use serde::{Deserialize, Serialize};
6-
use sqlx::{PgConnection, Postgres, QueryBuilder};
6+
use sqlx::{PgConnection, Postgres};
77

88
use super::{
99
dependency::ResponseDependency,

src/types/models/mod_version_status.rs

-8
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,3 @@ pub enum ModVersionStatusEnum {
99
Rejected,
1010
Unlisted,
1111
}
12-
13-
pub struct ModVersionStatus {
14-
pub id: i32,
15-
pub mod_version_id: i32,
16-
pub status: ModVersionStatusEnum,
17-
pub info: Option<String>,
18-
pub admin_id: i32,
19-
}

src/types/models/tag.rs

+1-129
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use sqlx::{PgConnection, Postgres, QueryBuilder};
3+
use sqlx::PgConnection;
44

55
use crate::types::api::ApiError;
66

@@ -19,134 +19,6 @@ pub struct Tag {
1919
}
2020

2121
impl Tag {
22-
pub async fn get_tag_ids(
23-
tags: Vec<String>,
24-
pool: &mut PgConnection,
25-
) -> Result<Vec<FetchedTag>, ApiError> {
26-
let db_tags = match sqlx::query_as!(
27-
FetchedTag,
28-
"SELECT id, name FROM mod_tags WHERE is_readonly = false"
29-
)
30-
.fetch_all(&mut *pool)
31-
.await
32-
{
33-
Ok(tags) => tags,
34-
Err(e) => {
35-
log::error!("{}", e);
36-
return Err(ApiError::DbError);
37-
}
38-
};
39-
40-
let mut ret = Vec::new();
41-
for tag in tags {
42-
if let Some(t) = db_tags.iter().find(|t| t.name == tag.to_lowercase()) {
43-
ret.push(t.clone())
44-
} else {
45-
return Err(ApiError::BadRequest(format!(
46-
"Tag '{}' isn't allowed. Only the following are allowed: '{}'",
47-
tag,
48-
db_tags
49-
.iter()
50-
.map(|t| t.name.clone())
51-
.collect::<Vec<String>>()
52-
.join(", ")
53-
)));
54-
}
55-
}
56-
57-
Ok(ret)
58-
}
59-
60-
pub async fn update_mod_tags(
61-
mod_id: &str,
62-
tags: Vec<i32>,
63-
pool: &mut PgConnection,
64-
) -> Result<(), ApiError> {
65-
let existing = match sqlx::query!(
66-
"SELECT mod_id, tag_id FROM mods_mod_tags WHERE mod_id = $1",
67-
mod_id,
68-
)
69-
.fetch_all(&mut *pool)
70-
.await
71-
{
72-
Ok(existing) => existing,
73-
Err(e) => {
74-
log::error!("{}", e);
75-
return Err(ApiError::DbError);
76-
}
77-
};
78-
79-
let insertable = tags
80-
.iter()
81-
.filter(|t| !existing.iter().any(|e| e.tag_id == **t))
82-
.collect::<Vec<_>>();
83-
84-
let deletable = existing
85-
.iter()
86-
.filter(|e| !tags.iter().any(|t| e.tag_id == *t))
87-
.map(|x| x.tag_id)
88-
.collect::<Vec<_>>();
89-
90-
Tag::delete_tags_for_mod(mod_id, deletable, pool).await?;
91-
92-
if insertable.is_empty() {
93-
return Ok(());
94-
}
95-
96-
let mut query_builder: QueryBuilder<Postgres> =
97-
QueryBuilder::new("INSERT INTO mods_mod_tags (mod_id, tag_id) VALUES (");
98-
99-
for (index, tag) in insertable.iter().enumerate() {
100-
if existing.iter().any(|e| e.tag_id == **tag) {
101-
continue;
102-
}
103-
let mut separated = query_builder.separated(", ");
104-
separated.push_bind(mod_id);
105-
separated.push_bind(tag);
106-
query_builder.push(")");
107-
108-
if index != insertable.len() - 1 {
109-
query_builder.push(", (");
110-
}
111-
}
112-
113-
if let Err(e) = query_builder.build().execute(&mut *pool).await {
114-
log::error!("{}", e);
115-
return Err(ApiError::DbError);
116-
}
117-
Ok(())
118-
}
119-
120-
pub async fn delete_tags_for_mod(
121-
mod_id: &str,
122-
tags: Vec<i32>,
123-
pool: &mut PgConnection,
124-
) -> Result<(), ApiError> {
125-
if tags.is_empty() {
126-
return Ok(());
127-
}
128-
let mut query_builder: QueryBuilder<Postgres> =
129-
QueryBuilder::new("DELETE FROM mods_mod_tags WHERE (mod_id, tag_id) IN ((");
130-
131-
for (index, tag) in tags.iter().enumerate() {
132-
let mut separated = query_builder.separated(", ");
133-
separated.push_bind(mod_id);
134-
separated.push_bind(tag);
135-
query_builder.push(")");
136-
137-
if index != tags.len() - 1 {
138-
query_builder.push(", (");
139-
}
140-
}
141-
query_builder.push(")");
142-
143-
if let Err(e) = query_builder.build().execute(&mut *pool).await {
144-
log::error!("{}", e);
145-
return Err(ApiError::DbError);
146-
}
147-
Ok(())
148-
}
149-
15022
pub async fn get_tags_for_mod(
15123
mod_id: &str,
15224
pool: &mut PgConnection,

0 commit comments

Comments
 (0)