Skip to content

Commit

Permalink
feat: readonly tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Dec 10, 2024
1 parent 6c73914 commit ac5a47d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions migrations/20241210001229_add_readonly_to_mod_tags.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Add down migration script here

ALTER TABLE mod_tags DROP is_readonly;
4 changes: 4 additions & 0 deletions migrations/20241210001229_add_readonly_to_mod_tags.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Add up migration script here

ALTER TABLE mod_tags
ADD is_readonly BOOLEAN NOT NULL DEFAULT false;
26 changes: 19 additions & 7 deletions src/types/models/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ pub struct Tag {
pub id: i32,
pub name: String,
pub display_name: String,
pub is_readonly: bool,
}

impl Tag {
pub async fn get_tags(pool: &mut PgConnection) -> Result<Vec<String>, ApiError> {
let tags = match sqlx::query!("SELECT name FROM mod_tags")
.fetch_all(&mut *pool)
.await
let tags = match sqlx::query!(
"
SELECT name FROM mod_tags
WHERE is_readonly = false
"
)
.fetch_all(&mut *pool)
.await
{
Ok(tags) => tags,
Err(e) => {
Expand All @@ -38,13 +44,15 @@ impl Tag {
id: i32,
name: String,
display_name: Option<String>,
is_readonly: bool,
}
let tags = sqlx::query_as!(
QueryResult,
"SELECT
id,
name,
display_name
display_name,
is_readonly
FROM mod_tags"
)
.fetch_all(&mut *conn)
Expand All @@ -60,6 +68,7 @@ impl Tag {
id: i.id,
name: i.name.clone(),
display_name: i.display_name.unwrap_or(i.name),
is_readonly: i.is_readonly,
})
.collect())
}
Expand All @@ -68,9 +77,12 @@ impl Tag {
tags: Vec<String>,
pool: &mut PgConnection,
) -> Result<Vec<FetchedTag>, ApiError> {
let db_tags = match sqlx::query_as!(FetchedTag, "SELECT id, name FROM mod_tags")
.fetch_all(&mut *pool)
.await
let db_tags = match sqlx::query_as!(
FetchedTag,
"SELECT id, name FROM mod_tags WHERE is_readonly = false"
)
.fetch_all(&mut *pool)
.await
{
Ok(tags) => tags,
Err(e) => {
Expand Down

0 comments on commit ac5a47d

Please sign in to comment.