Skip to content

Commit b64f7b2

Browse files
tegiozcynthia-sg
andauthored
Add foundation filter (#224)
Signed-off-by: Sergio Castaño Arteaga <[email protected]> Signed-off-by: Cintia Sánchez García <[email protected]> Co-authored-by: Cintia Sánchez García <[email protected]>
1 parent 125b5e9 commit b64f7b2

File tree

5 files changed

+66
-16
lines changed

5 files changed

+66
-16
lines changed

database/migrations/functions/jobboard/search_jobs.sql

+14-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ declare
55
v_benefits text[];
66
v_date_from date;
77
v_date_to date;
8-
v_max_distance real := (p_filters->>'max_distance')::real;
8+
v_foundation text := (p_filters->>'foundation');
99
v_kind text[];
1010
v_limit int := coalesce((p_filters->>'limit')::int, 20);
1111
v_location_id uuid := ((p_filters->'location')->>'location_id')::uuid;
12+
v_max_distance real := (p_filters->>'max_distance')::real;
1213
v_offset int := coalesce((p_filters->>'offset')::int, 0);
1314
v_open_source int := (p_filters->>'open_source')::int;
1415
v_projects text[];
@@ -135,6 +136,16 @@ begin
135136
case when v_date_from is not null and v_date_to is not null then
136137
j.published_at::date >= v_date_from and j.published_at::date <= v_date_to
137138
else true end
139+
and
140+
case when v_foundation is not null then
141+
j.job_id = any(
142+
select job_id from job_project
143+
where project_id = any(
144+
select project_id from project
145+
where foundation = v_foundation
146+
)
147+
)
148+
else true end
138149
and
139150
case when cardinality(v_kind) > 0 then
140151
j.kind = any(v_kind)
@@ -159,7 +170,8 @@ begin
159170
select project_id from project
160171
where name = any(v_projects)
161172
)
162-
) else true end
173+
)
174+
else true end
163175
and
164176
case when v_salary_min is not null then
165177
case

gitjobs-server/src/db/jobboard.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -198,24 +198,32 @@ impl DBJobBoard for PgDB {
198198
let row = db
199199
.query_one(
200200
"
201-
select
202-
(
203-
select json_agg(json_build_object(
204-
'project_id', project_id,
205-
'foundation', foundation,
206-
'logo_url', logo_url,
207-
'maturity', maturity,
208-
'name', name
209-
))
210-
from project
211-
)::text as projects;
212-
",
201+
select
202+
(
203+
select json_agg(json_build_object(
204+
'foundation_id', foundation_id,
205+
'name', name
206+
))
207+
from foundation
208+
)::text as foundations,
209+
(
210+
select json_agg(json_build_object(
211+
'project_id', project_id,
212+
'foundation', foundation,
213+
'logo_url', logo_url,
214+
'maturity', maturity,
215+
'name', name
216+
))
217+
from project
218+
)::text as projects;
219+
",
213220
&[],
214221
)
215222
.await?;
216223

217224
// Prepare filters options
218225
let filters_options = FiltersOptions {
226+
foundations: serde_json::from_str(&row.get::<_, String>("foundations"))?,
219227
projects: serde_json::from_str(&row.get::<_, String>("projects"))?,
220228
};
221229

gitjobs-server/src/templates/jobboard/jobs.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::templates::{
1212
dashboard::employer::jobs::{JobKind, SalaryKind, Workplace},
1313
filters,
1414
helpers::{DATE_FORMAT, DATE_FORMAT_3, build_jobboard_image_url, option_is_none_or_default},
15-
misc::{Location, Member, Project},
15+
misc::{Foundation, Location, Member, Project},
1616
pagination::{NavigationLinks, Pagination},
1717
};
1818

@@ -64,6 +64,8 @@ pub(crate) struct Filters {
6464
#[serde(skip_serializing_if = "option_is_none_or_default")]
6565
pub date_range: Option<DateRange>,
6666
#[serde(skip_serializing_if = "option_is_none_or_default")]
67+
pub foundation: Option<String>,
68+
#[serde(skip_serializing_if = "option_is_none_or_default")]
6769
pub kind: Option<Vec<JobKind>>,
6870
#[serde(skip_serializing_if = "option_is_none_or_default")]
6971
pub limit: Option<usize>,
@@ -146,8 +148,9 @@ pub(crate) enum Seniority {
146148
}
147149

148150
/// Filters options used in the jobs explore section.
149-
#[derive(Debug, Clone, Serialize, Deserialize)]
151+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
150152
pub(crate) struct FiltersOptions {
153+
pub foundations: Vec<Foundation>,
151154
pub projects: Vec<Project>,
152155
}
153156

gitjobs-server/src/templates/misc.rs

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ pub(crate) struct UserMenuSection {
3939

4040
// Types.
4141

42+
/// Foundation information.
43+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
44+
#[allow(clippy::struct_field_names)]
45+
pub(crate) struct Foundation {
46+
pub foundation_id: Uuid,
47+
pub name: String,
48+
}
49+
4250
/// Location information.
4351
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
4452
#[allow(clippy::struct_field_names)]

gitjobs-server/templates/jobboard/jobs/jobs_macros.html

+19
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@
110110
</div>
111111
{# End projects -#}
112112

113+
{# Foundation -#}
114+
<div>
115+
<div class="text-xs/6 text-stone-500/75 -mt-2">
116+
or any project from the <span class="inline-block lg:hidden xl:inline-block">following</span> foundation
117+
</div>
118+
<div class="mt-2.5">
119+
<select form="{{ form }}"
120+
data-trigger-form="true"
121+
name="foundation"
122+
class="select-primary py-0.5 text-[0.8rem]/6 text-stone-500">
123+
{% call macros::select_option(value = "", label = "", selected = filters.foundation|display_some) -%}
124+
{% for foundation in filters_options.foundations -%}
125+
{% call macros::select_option(value = &foundation.name, label = foundation.name|upper, selected = filters.foundation|display_some) -%}
126+
{% endfor -%}
127+
</select>
128+
</div>
129+
</div>
130+
{# End foundation -#}
131+
113132
{# Open source -#}
114133
<div>
115134
{% call filters_subtitle(text = "Time working on open source") -%}

0 commit comments

Comments
 (0)