add projects view and template

This commit is contained in:
2024-11-10 04:47:40 +01:00
parent 5eb0246863
commit a3de4dcb43
21 changed files with 350 additions and 65 deletions

View File

@@ -7,4 +7,5 @@ pub mod services;
pub mod tasks;
pub mod views;
pub mod workers;
pub mod filters;
pub mod filters;
pub mod shared;

View File

@@ -16,12 +16,4 @@ pub struct JobWithTechnologies {
pub end_date: Option<Date>,
pub technologies: Vec<String>,
pub still_working: bool,
}
pub fn get_technologies_from_string(technologies: &str) -> Vec<String> {
technologies
.split(',')
.map(|s| s.to_string())
.filter(|s| !s.trim().is_empty())
.collect()
}
}

View File

@@ -7,20 +7,7 @@ impl ActiveModelBehavior for ActiveModel {
// extend activemodel below (keep comment for generators)
}
#[derive(Clone, Debug, Serialize, Deserialize)]
struct ProjectWithTechnologies {
pub id: i32,
pub name: String,
pub technologies: Vec<String>,
pub short_description: String,
pub description: Option<String>,
pub category: String,
pub github_url: Option<String>,
pub download_url: Option<String>,
pub visit_url: Option<String>,
}
#[derive(Debug)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Category {
Web,
Mobile,
@@ -28,3 +15,33 @@ pub enum Category {
Game,
Api,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectDto {
pub id: i32,
pub name: String,
pub short_description: String,
pub description: Option<String>,
pub category: Category,
pub github_url: Option<String>,
pub download_url: Option<String>,
pub visit_url: Option<String>,
pub technologies: Vec<String>,
pub thumbnails: Vec<String>,
}
pub fn get_category_from_string(category: &str) -> Category {
match category {
"Web" => Category::Web,
"Mobile" => Category::Mobile,
"Desktop" => Category::Desktop,
"Game" => Category::Game,
"Api" => Category::Api,
"web" => Category::Web,
"mobile" => Category::Mobile,
"desktop" => Category::Desktop,
"game" => Category::Game,
"api" => Category::Api,
_ => Category::Desktop,
}
}

View File

@@ -1,9 +1,9 @@
use loco_rs::prelude::*;
use crate::models::{
use crate::{models::{
_entities::jobs::{Entity, Model},
jobs::{get_technologies_from_string, JobWithTechnologies},
};
jobs::JobWithTechnologies,
}, shared::get_technologies_from_string::get_technologies_from_string};
pub async fn get_all_jobs(ctx: &AppContext) -> Result<Vec<Model>> {
let jobs = Entity::find().all(&ctx.db).await?;

View File

@@ -2,3 +2,4 @@ pub mod data;
pub mod jobs;
pub mod skills;
pub mod website;
pub mod projects;

69
src/services/projects.rs Normal file
View File

@@ -0,0 +1,69 @@
use loco_rs::prelude::*;
use crate::{models::{_entities::{project_thumbnails, projects::{self, Entity, Model}}, projects::{get_category_from_string, ProjectDto}}, shared::get_technologies_from_string::get_technologies_from_string};
pub async fn get_all_projects(ctx: &AppContext) -> Result<Vec<Model>> {
let projects = Entity::find().all(&ctx.db).await?;
Ok(projects)
}
pub async fn get_project_by_id(ctx: &AppContext, id: i32) -> Result<Model> {
let project = Entity::find_by_id(id).one(&ctx.db).await?;
let project = project.ok_or_else(|| ModelError::EntityNotFound)?;
Ok(project)
}
pub async fn get_archived_projects(ctx: &AppContext) -> Result<Vec<Model>> {
let archived_projects = Entity::find()
.filter(
model::query::condition()
.eq(projects::Column::IsArchived, true)
.build(),
)
.all(&ctx.db)
.await?;
Ok(archived_projects)
}
pub async fn get_highlighted_projects(ctx: &AppContext) -> Result<Vec<Model>> {
let highlighted_projects = Entity::find()
.filter(
model::query::condition()
.eq(projects::Column::IsHighlighted, true)
.build(),
)
.all(&ctx.db)
.await?;
Ok(highlighted_projects)
}
pub async fn get_all_projects_dto(ctx: &AppContext) -> Result<Vec<ProjectDto>> {
let projects_with_thumbnails = Entity::find()
.find_with_related(project_thumbnails::Entity)
.all(&ctx.db)
.await?;
let projects_dto = projects_with_thumbnails
.into_iter()
.map(|(project, thumbnails)| {
let thumbnails = thumbnails
.into_iter()
.map(|thumbnail| thumbnail.data_id.to_string())
.collect();
ProjectDto {
id: project.id,
name: project.name,
short_description: project.short_description,
description: project.description,
category: get_category_from_string(&project.category),
github_url: project.github_url,
download_url: project.download_url,
visit_url: project.visit_url,
technologies: get_technologies_from_string(&project.technology),
thumbnails,
}
})
.collect();
Ok(projects_dto)
}

View File

@@ -0,0 +1,7 @@
pub fn get_technologies_from_string(technologies: &str) -> Vec<String> {
technologies
.split(',')
.map(|s| s.to_string())
.filter(|s| !s.trim().is_empty())
.collect()
}

1
src/shared/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod get_technologies_from_string;

View File

@@ -14,9 +14,9 @@ pub async fn index(v: impl ViewRenderer, ctx: &AppContext) -> Result<impl IntoRe
}
pub async fn projects(v: impl ViewRenderer, ctx: &AppContext) -> Result<impl IntoResponse> {
// let projects = services::projects::get_all_projects(ctx).await?;
let projects = services::projects::get_all_projects_dto(ctx).await?;
format::render().view(&v, "website/projects.html", data!({"projects": {}}))
format::render().view(&v, "website/projects.html", data!({"projects": projects}))
}
pub async fn about(v: impl ViewRenderer) -> Result<impl IntoResponse> {