Skip to content

Commit

Permalink
Fixed CI/CD errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonKibong committed Jun 12, 2024
1 parent 61fbe6d commit f4036a8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 13 deletions.
39 changes: 34 additions & 5 deletions src/controllers/admin/articles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pub struct ListTemplate {
}

impl ListTemplate {
fn new() -> ListTemplate {
ListTemplate {
const fn new() -> Self {
Self {
rows: Vec::<ItemTemplate>::new(),
page: 0,
page_size: 0,
Expand All @@ -71,7 +71,7 @@ impl ListTemplate {
}

fn build(response: PageResponse<Model>, pagination_query: &PaginationQuery) -> Self {
let mut template: ListTemplate = response.page.into_iter().map(|item| ItemTemplate::from(item)).collect();
let mut template: ListTemplate = response.page.into_iter().map(ItemTemplate::from).collect();

Check failure on line 74 in src/controllers/admin/articles.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

unnecessary structure name repetition
template.page = pagination_query.page;
template.page_size = pagination_query.page_size;
template.total_pages = response.total_pages;
Expand All @@ -82,7 +82,7 @@ impl ListTemplate {
impl FromIterator<ItemTemplate> for ListTemplate {
fn from_iter<U>(iter: U) -> Self
where U: IntoIterator<Item=ItemTemplate> {
let mut c = ListTemplate::new();
let mut c = Self::new();

for i in iter {
c.add(i);
Expand All @@ -91,6 +91,12 @@ impl FromIterator<ItemTemplate> for ListTemplate {
}
}

/// # Panics
///
/// Will panic if unwrap panics
/// # Errors
///
/// Will return 'Err' if something goes wrong
#[debug_handler]
pub async fn list(Query(query_params): Query<QueryParams>, State(ctx): State<AppContext>) -> Result<Response> {
let response = article::list_inner(&ctx, &query_params).await?;
Expand All @@ -99,22 +105,39 @@ pub async fn list(Query(query_params): Query<QueryParams>, State(ctx): State<App
Ok(Html(rendered).into_response())
}

/// # Panics
///
/// Will panic if unwrap panics
/// # Errors
///
/// Will return 'Err' if something goes wrong
#[debug_handler]
pub async fn new() -> Result<Response> {
let template = NewTemplate {};
let rendered = template.render().unwrap();
Ok(Html(rendered).into_response())
}

/// # Panics
///
/// Will panic if unwrap panics
/// # Errors
///
/// Will return 'Err' if something goes wrong
#[debug_handler]
pub async fn edit(Path(id): Path<i32>, State(ctx): State<AppContext>) -> Result<Response> {
let item = article::load_item(&ctx, id).await?;
println!("============ Editing =============");
let template = ItemTemplate::from(item);
let rendered = template.render().unwrap();
Ok(Html(rendered).into_response())
}

/// # Panics
///
/// Will panic if unwrap panics
/// # Errors
///
/// Will return 'Err' if something goes wrong
#[debug_handler]
pub async fn add(State(ctx): State<AppContext>, Json(params): Json<article::Params>) -> Result<Response> {
let item = article::add_inner(&ctx, params).await?;
Expand All @@ -123,6 +146,12 @@ pub async fn add(State(ctx): State<AppContext>, Json(params): Json<article::Para
Ok(Html(rendered).into_response())
}

/// # Panics
///
/// Will panic if unwrap panics
/// # Errors
///
/// Will return 'Err' if something goes wrong
#[debug_handler]
pub async fn update(Path(id): Path<i32>, State(ctx): State<AppContext>, Json(params): Json<article::Params>) -> Result<Response> {
let item = article::update_inner(id, &ctx, params).await?;
Expand Down
18 changes: 18 additions & 0 deletions src/controllers/admin/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,59 @@ pub struct TablesTemplate {}
#[template(path="tabs.html")]
pub struct TabsTemplate {}

/// # Panics
///
/// Will panic if unwrap panics
#[debug_handler]
pub async fn blank() -> Result<Response> {

Check failure on line 34 in src/controllers/admin/home.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

docs for function returning `Result` missing `# Errors` section
let template = BlankTemplate {};
let rendered = template.render().unwrap();
Ok(Html(rendered).into_response())
}

/// # Panics
///
/// Will panic if unwrap panics
#[debug_handler]
pub async fn calendar() -> Result<Response> {

Check failure on line 44 in src/controllers/admin/home.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

docs for function returning `Result` missing `# Errors` section
let template = CalnedarTemplate {};
let rendered = template.render().unwrap();
Ok(Html(rendered).into_response())
}

/// # Panics
///
/// Will panic if unwrap panics
#[debug_handler]
pub async fn forms() -> Result<Response> {

Check failure on line 54 in src/controllers/admin/home.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

docs for function returning `Result` missing `# Errors` section
let template = FormsTemplate {};
let rendered = template.render().unwrap();
Ok(Html(rendered).into_response())
}

/// # Panics
///
/// Will panic if unwrap panics
#[debug_handler]
pub async fn index() -> Result<Response> {

Check failure on line 64 in src/controllers/admin/home.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

docs for function returning `Result` missing `# Errors` section
let template = IndexTemplate {};
let rendered = template.render().unwrap();
Ok(Html(rendered).into_response())
}

/// # Panics
///
/// Will panic if unwrap panics
#[debug_handler]
pub async fn tables() -> Result<Response> {

Check failure on line 74 in src/controllers/admin/home.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

docs for function returning `Result` missing `# Errors` section
let template = TablesTemplate {};
let rendered = template.render().unwrap();
Ok(Html(rendered).into_response())
}

/// # Panics
///
/// Will panic if unwrap panics
#[debug_handler]
pub async fn tabs() -> Result<Response> {

Check failure on line 84 in src/controllers/admin/home.rs

View workflow job for this annotation

GitHub Actions / Run Clippy

docs for function returning `Result` missing `# Errors` section
let template = TabsTemplate {};
Expand Down
15 changes: 7 additions & 8 deletions src/controllers/article.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ pub struct PaginationResponse {}
impl From<Model> for ListResponse {
fn from(article: Model) -> Self {
Self {
id: article.id.clone(),
id: article.id,
title: article.title.clone(),
content: article.content.clone(),
created_at: article.created_at.clone(),
updated_at: article.updated_at.clone(),
created_at: article.created_at,
updated_at: article.updated_at,
}
}
}
Expand Down Expand Up @@ -83,19 +83,18 @@ pub async fn load_item(ctx: &AppContext, id: i32) -> Result<Model> {
}

pub async fn list_inner(ctx: &AppContext, query_params: &QueryParams) -> Result<PageResponse<Model>> {
let title_filter = query_params.title.as_ref().unwrap_or(&"".to_string()).clone();
let content_filter = query_params.content.as_ref().unwrap_or(&"".to_string()).clone();
let title_filter = query_params.title.as_ref().unwrap_or(&String::new()).clone();
let content_filter = query_params.content.as_ref().unwrap_or(&String::new()).clone();
let mut condition = Condition::all();
if !title_filter.is_empty() {
condition = condition.add(Column::Title.contains(&title_filter));
}
if !content_filter.is_empty() {
condition = condition.add(Column::Content.contains(&content_filter));
}
let response = model::query::paginate(
model::query::paginate(
&ctx.db, Entity::find(), Some(condition), &query_params.pagination_query
).await;
response
).await
}

#[debug_handler]
Expand Down

0 comments on commit f4036a8

Please sign in to comment.