Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Bug fix" #194

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions migrations/00000000000003_create_mushaf/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CREATE TABLE quran_mushafs (
short_name VARCHAR(200),
name VARCHAR(400),
source VARCHAR(300),
bismillah_text TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT mushaf_fk_user_id_rel FOREIGN KEY(creator_user_id) REFERENCES app_users(id),
Expand Down
2 changes: 2 additions & 0 deletions migrations/00000000000005_create_quran_surahs/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CREATE TABLE quran_surahs (
name VARCHAR(50) NOT NULL,
period VARCHAR(50),
number serial NOT NULL,
bismillah_status BOOLEAN NOT NULL,
bismillah_as_first_ayah BOOLEAN NOT NULL,
mushaf_id serial NOT NULL,
name_pronunciation TEXT,
name_translation_phrase TEXT,
Expand Down
2 changes: 0 additions & 2 deletions migrations/2023-02-19-100955_create_quran_ayahs/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ CREATE TABLE quran_ayahs (
surah_id serial NOT NULL,
ayah_number serial NOT NULL,
sajdah VARCHAR(20),
is_bismillah BOOLEAN NOT NULL,
bismillah_text TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT quran_ayahs_id PRIMARY KEY (id),
Expand Down
48 changes: 20 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,19 @@ async fn main() -> std::io::Result<()> {
.route(web::delete().to(translation_delete::translation_delete)),
)
.service(
web::scope("/text")
.route(
"/{translation_uuid}",
web::get().to(translation_text_view::translation_text_view),
)
.service(
web::resource("/{translation_uuid}")
.wrap(AuthZ::new(auth_z_controller.clone()))
.wrap(TokenAuth::new(user_id_from_token.clone(), true))
.route(
web::post()
.to(translation_text_modify::translation_text_modify),
)
.route(
web::delete()
.to(translation_text_delete::translation_text_delete),
),
),
web::scope("/text").service(
web::resource("/{translation_uuid}")
.wrap(TokenAuth::new(user_id_from_token.clone(), false))
.route(web::get().to(translation_text_view::translation_text_view))
.route(
web::post()
.to(translation_text_modify::translation_text_modify),
)
.route(
web::delete()
.to(translation_text_delete::translation_text_delete),
),
),
),
)
.service(
Expand Down Expand Up @@ -337,18 +332,15 @@ async fn main() -> std::io::Result<()> {
)
.service(
web::scope("/phrase")
.wrap(AuthZ::new(auth_z_controller.clone()))
.wrap(TokenAuth::new(user_id_from_token.clone(), true))
.route("", web::get().to(phrase_list::list_phrase))
.route("", web::post().to(add_phrase::add_phrase))
.route("/{language}", web::get().to(view_phrase::view_phrase))
.service(
web::scope("")
.wrap(AuthZ::new(auth_z_controller.clone()))
.wrap(TokenAuth::new(user_id_from_token.clone(), true))
.route("", web::post().to(add_phrase::add_phrase))
.route("/{language}", web::post().to(edit_phrase::edit_phrase))
.route(
"/{language}",
web::delete().to(delete_phrase::delete_phrase),
),
.route("/{language}", web::post().to(edit_phrase::edit_phrase))
.route(
"/{language}",
web::delete().to(delete_phrase::delete_phrase),
),
)
})
Expand Down
11 changes: 7 additions & 4 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ pub struct QuranAyah {

pub ayah_number: i32,
pub sajdah: Option<String>,
pub is_bismillah: bool,
pub bismillah_text: Option<String>,

#[serde(skip_serializing)]
pub created_at: NaiveDateTime,
Expand All @@ -262,8 +260,6 @@ pub struct NewQuranAyah {
pub surah_id: i32,
pub ayah_number: i32,
pub sajdah: Option<String>,
pub is_bismillah: bool,
pub bismillah_text: Option<String>,
}

#[derive(Clone, Selectable, Identifiable, Associations, Queryable, PartialEq, Debug, Serialize)]
Expand Down Expand Up @@ -307,6 +303,8 @@ pub struct QuranSurah {
pub name: String,
pub period: Option<String>,
pub number: i32,
pub bismillah_status: bool,
pub bismillah_as_first_ayah: bool,
pub mushaf_id: i32,

pub name_pronunciation: Option<String>,
Expand All @@ -327,6 +325,8 @@ pub struct NewQuranSurah {
pub name: String,
pub period: Option<String>,
pub number: i32,
pub bismillah_status: bool,
pub bismillah_as_first_ayah: bool,
pub mushaf_id: i32,
pub name_pronunciation: Option<String>,
pub name_translation_phrase: Option<String>,
Expand All @@ -346,6 +346,8 @@ pub struct QuranMushaf {
pub name: Option<String>,
pub source: Option<String>,

pub bismillah_text: Option<String>,

#[serde(skip_serializing)]
pub created_at: NaiveDateTime,
#[serde(skip_serializing)]
Expand All @@ -359,6 +361,7 @@ pub struct NewQuranMushaf<'a> {
pub short_name: Option<&'a str>,
pub name: Option<&'a str>,
pub source: Option<&'a str>,
pub bismillah_text: Option<String>,
}

#[derive(Deserialize, Serialize, Clone, Validate, Identifiable, Queryable, Debug, Selectable)]
Expand Down
4 changes: 0 additions & 4 deletions src/routers/quran/ayah/ayah_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ pub struct AyahWithText {
pub surah_uuid: String,
pub sajdah: Option<Sajdah>,
pub text: String,
pub is_bismillah: bool,
pub bismillah_text: Option<String>,
}

/// Add's a new ayah
Expand Down Expand Up @@ -61,8 +59,6 @@ pub async fn ayah_add(
sajdah: new_ayah.sajdah.map(|sajdah| sajdah.to_string()),
ayah_number: (latest_ayah_number + 1) as i32,
creator_user_id: user,
is_bismillah: new_ayah.is_bismillah,
bismillah_text: new_ayah.bismillah_text,
}
.insert_into(quran_ayahs)
.get_result(&mut conn)?;
Expand Down
20 changes: 2 additions & 18 deletions src/routers/quran/ayah/ayah_edit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::RouterError;
use crate::{AyahBismillah, DbPool};
use crate::DbPool;
use actix_web::web;
use diesel::prelude::*;
use uuid::Uuid;
Expand All @@ -13,8 +13,7 @@ pub async fn ayah_edit(
pool: web::Data<DbPool>,
) -> Result<&'static str, RouterError> {
use crate::schema::quran_ayahs::dsl::{
ayah_number, bismillah_text, is_bismillah, quran_ayahs, sajdah as ayah_sajdah,
uuid as ayah_uuid,
ayah_number, quran_ayahs, sajdah as ayah_sajdah, uuid as ayah_uuid,
};

let new_ayah = new_ayah.into_inner();
Expand All @@ -29,21 +28,6 @@ pub async fn ayah_edit(
.set((
ayah_number.eq(new_ayah.ayah_number),
ayah_sajdah.eq(new_sajdah),
is_bismillah.eq(new_ayah
.bismillah
.clone()
.unwrap_or(AyahBismillah {
is_ayah: false,
text: None,
})
.is_ayah),
bismillah_text.eq(new_ayah
.bismillah
.unwrap_or(AyahBismillah {
is_ayah: false,
text: None,
})
.text),
))
.execute(&mut conn)?;

Expand Down
13 changes: 0 additions & 13 deletions src/routers/quran/ayah/ayah_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::error::{RouterError, RouterErrorDetailBuilder};
use crate::filter::Filter;
use crate::models::QuranAyah;
use crate::routers::multip;
use crate::AyahBismillah;
use crate::{
routers::quran::surah::{AyahTy, Format, SimpleAyah},
DbPool,
Expand Down Expand Up @@ -45,18 +44,6 @@ pub async fn ayah_list(
number: a.ayah_number as u32,
uuid: a.uuid,
sajdah: a.sajdah,
bismillah: match (a.is_bismillah, a.bismillah_text) {
(true, None) => Some(AyahBismillah {
is_ayah: true,
text: None,
}),
(false, Some(text)) => Some(AyahBismillah {
is_ayah: false,
text: Some(text),
}),
(false, None) => None,
(_, _) => None,
},
});

let final_ayahs = ayahs_as_map
Expand Down
3 changes: 1 addition & 2 deletions src/routers/quran/ayah/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use uuid::Uuid;

use crate::{
filter::{Filters, Order},
AyahBismillah, Format,
Format,
};

#[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -64,7 +64,6 @@ pub struct AyahWithContent {
pub struct SimpleAyah {
pub ayah_number: i32,
pub sajdah: Option<Sajdah>,
pub bismillah: Option<AyahBismillah>,
}

#[derive(Deserialize, Clone)]
Expand Down
1 change: 1 addition & 0 deletions src/routers/quran/mushaf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct SimpleMushaf {
short_name: String,
name: String,
source: String,
bismillah_text: Option<String>,
}

#[derive(Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions src/routers/quran/mushaf/mushaf_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub async fn mushaf_add(
creator_user_id: user,
name: Some(&new_mushaf.name),
source: Some(&new_mushaf.source),
bismillah_text: new_mushaf.bismillah_text,
}
.insert_into(quran_mushafs)
.execute(&mut conn)?;
Expand Down
3 changes: 2 additions & 1 deletion src/routers/quran/mushaf/mushaf_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub async fn mushaf_edit(
pool: web::Data<DbPool>,
) -> Result<&'static str, RouterError> {
use crate::schema::quran_mushafs::dsl::{
name as mushaf_name, quran_mushafs, short_name as mushaf_short_name,
bismillah_text, quran_mushafs, name as mushaf_name, short_name as mushaf_short_name,
source as mushaf_source, uuid as mushaf_uuid,
};

Expand All @@ -28,6 +28,7 @@ pub async fn mushaf_edit(
mushaf_name.eq(new_mushaf.name),
mushaf_short_name.eq(new_mushaf.short_name),
mushaf_source.eq(new_mushaf.source),
bismillah_text.eq(new_mushaf.bismillah_text),
))
.execute(&mut conn)?;

Expand Down
20 changes: 5 additions & 15 deletions src/routers/quran/surah/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,12 @@ impl PartialOrd for SimpleAyahSurah {
}
}

#[derive(Hash, Ord, PartialOrd, PartialEq, Eq, Serialize, Clone, Debug, Deserialize)]
pub struct AyahBismillah {
pub is_ayah: bool,
pub text: Option<String>,
}

// This will be returned in /surah/{uuid} router
#[derive(Hash, Ord, PartialOrd, PartialEq, Eq, Serialize, Clone, Debug, Deserialize)]
pub struct SurahBismillah {
pub as_first_ayah: bool,
pub text: Option<String>,
}

/// The Ayah type that will return in the response
#[derive(Hash, Ord, PartialOrd, PartialEq, Eq, Serialize, Clone, Debug)]
pub struct SimpleAyah {
pub number: u32,
pub uuid: Uuid,
pub sajdah: Option<String>,
pub bismillah: Option<AyahBismillah>,
}

/// it contains ayah info and the content
Expand Down Expand Up @@ -191,8 +177,10 @@ pub struct SingleSurahResponse {
pub names: Vec<SurahName>,
pub period: Option<String>,
pub number: i32,
pub bismillah_status: bool,
pub bismillah_as_first_ayah: bool,
pub bismillah_text: Option<String>,
pub number_of_ayahs: i64,
pub bismillah: Option<SurahBismillah>,
}

/// The response type for /surah
Expand All @@ -215,5 +203,7 @@ pub struct SimpleSurah {
pub name_transliteration: Option<String>,
pub period: Option<String>,
pub number: i32,
pub bismillah_status: bool,
pub bismillah_as_first_ayah: bool,
pub mushaf_uuid: Uuid,
}
2 changes: 2 additions & 0 deletions src/routers/quran/surah/surah_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub async fn surah_add(
period: new_surah.period,
number: (latest_surah_number + 1) as i32,
mushaf_id: mushaf,
bismillah_status: new_surah.bismillah_status,
bismillah_as_first_ayah: new_surah.bismillah_as_first_ayah,
name_pronunciation: new_surah.name_pronunciation,
name_translation_phrase: new_surah.name_translation_phrase,
name_transliteration: new_surah.name_transliteration,
Expand Down
7 changes: 5 additions & 2 deletions src/routers/quran/surah/surah_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ pub async fn surah_edit(
) -> Result<&'static str, RouterError> {
use crate::schema::quran_mushafs::dsl::{id as mushaf_id, quran_mushafs, uuid as mushaf_uuid};
use crate::schema::quran_surahs::dsl::{
mushaf_id as surah_mushaf_id, name, name_pronunciation, name_translation_phrase,
name_transliteration, number, period, quran_surahs, uuid as surah_uuid,
bismillah_as_first_ayah, bismillah_status, mushaf_id as surah_mushaf_id, name,
name_pronunciation, name_translation_phrase, name_transliteration, number, period,
quran_surahs, uuid as surah_uuid,
};

let new_surah = new_surah.into_inner();
Expand All @@ -36,6 +37,8 @@ pub async fn surah_edit(
number.eq(new_surah.number),
surah_mushaf_id.eq(mushaf),
name.eq(new_surah.name),
bismillah_status.eq(new_surah.bismillah_status),
bismillah_as_first_ayah.eq(new_surah.bismillah_as_first_ayah),
period.eq(new_surah.period),
name_pronunciation.eq(new_surah.name_pronunciation),
name_translation_phrase.eq(new_surah.name_translation_phrase),
Expand Down
Loading
Loading