Skip to content

Commit 5e135cc

Browse files
committed
fix: fix tag stuff
1 parent f73d9d3 commit 5e135cc

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "geode-index"
3-
version = "0.43.3"
3+
version = "0.43.4"
44
edition = "2021"
55

66
[dependencies]

src/database/repository/mod_tags.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ use crate::types::api::ApiError;
22
use crate::types::models::tag::Tag;
33
use sqlx::PgConnection;
44

5-
pub async fn get_all(conn: &mut PgConnection) -> Result<Vec<Tag>, ApiError> {
5+
pub async fn get_all_writable(conn: &mut PgConnection) -> Result<Vec<Tag>, ApiError> {
66
let tags = sqlx::query!(
77
"SELECT
88
id,
99
name,
1010
display_name,
1111
is_readonly
12-
FROM mod_tags"
12+
FROM mod_tags
13+
where is_readonly = false"
1314
)
1415
.fetch_all(&mut *conn)
1516
.await
1617
.map_err(|e| {
17-
log::error!("mod_tags::get_tags failed: {}", e);
18+
log::error!("mod_tags::get_all_writeable failed: {}", e);
1819
ApiError::DbError
1920
})?
2021
.into_iter()
@@ -29,6 +30,33 @@ pub async fn get_all(conn: &mut PgConnection) -> Result<Vec<Tag>, ApiError> {
2930
Ok(tags)
3031
}
3132

33+
pub async fn get_all(conn: &mut PgConnection) -> Result<Vec<Tag>, ApiError> {
34+
let tags = sqlx::query!(
35+
"SELECT
36+
id,
37+
name,
38+
display_name,
39+
is_readonly
40+
FROM mod_tags"
41+
)
42+
.fetch_all(&mut *conn)
43+
.await
44+
.map_err(|e| {
45+
log::error!("mod_tags::get_all failed: {}", e);
46+
ApiError::DbError
47+
})?
48+
.into_iter()
49+
.map(|i| Tag {
50+
id: i.id,
51+
display_name: i.display_name.unwrap_or(i.name.clone()),
52+
name: i.name,
53+
is_readonly: i.is_readonly,
54+
})
55+
.collect::<Vec<Tag>>();
56+
57+
Ok(tags)
58+
}
59+
3260
pub async fn get_for_mod(id: &str, conn: &mut PgConnection) -> Result<Vec<Tag>, ApiError> {
3361
sqlx::query!(
3462
"SELECT
@@ -67,7 +95,7 @@ pub async fn parse_tag_list(
6795
return Ok(vec![]);
6896
}
6997

70-
let db_tags = get_all(conn).await?;
98+
let db_tags = get_all_writable(conn).await?;
7199

72100
let mut ret = Vec::new();
73101
for tag in tags {
@@ -104,7 +132,7 @@ pub async fn update_for_mod(
104132

105133
let deletable = existing
106134
.iter()
107-
.filter(|e| !tags.iter().any(|t| e.id == t.id))
135+
.filter(|e| !e.is_readonly && !tags.iter().any(|t| e.id == t.id))
108136
.map(|x| x.id)
109137
.collect::<Vec<_>>();
110138

src/endpoints/tags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub async fn index(data: web::Data<AppData>) -> Result<impl Responder, ApiError>
1111
.acquire()
1212
.await
1313
.or(Err(ApiError::DbAcquireError))?;
14-
let tags = mod_tags::get_all(&mut pool)
14+
let tags = mod_tags::get_all_writable(&mut pool)
1515
.await?
1616
.into_iter()
1717
.map(|tag| tag.name)

0 commit comments

Comments
 (0)