Skip to content

Commit aae7313

Browse files
authored
Fix issue adding job (#62)
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
1 parent ffa599a commit aae7313

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

database/migrations/schema/0001_initial.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ create table job (
207207
archived_at timestamptz,
208208
benefits text[],
209209
open_source int check (open_source >= 0 and open_source <= 100),
210-
projects jsonb,
211210
published_at timestamptz,
212211
qualifications text check (qualifications <> ''),
213212
responsibilities text check (responsibilities <> ''),

gitjobs-server/src/db/dashboard/employer.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ impl DBDashBoardEmployer for PgDB {
142142
apply_url,
143143
benefits,
144144
open_source,
145-
projects,
146145
qualifications,
147146
responsibilities,
148147
salary,
@@ -166,16 +165,15 @@ impl DBDashBoardEmployer for PgDB {
166165
$9::text,
167166
$10::text[],
168167
$11::int,
169-
nullif($12::jsonb, 'null'::jsonb),
168+
$12::text,
170169
$13::text,
171-
$14::text,
172-
$15::bigint,
173-
$16::text,
170+
$14::bigint,
171+
$15::text,
172+
$16::bigint,
174173
$17::bigint,
175-
$18::bigint,
176-
$19::text,
177-
$20::text[],
178-
$21::int,
174+
$18::text,
175+
$19::text[],
176+
$20::int,
179177
case when $3::text = 'published' then current_timestamp else null end
180178
returning job_id;
181179
",
@@ -191,7 +189,6 @@ impl DBDashBoardEmployer for PgDB {
191189
&job.apply_url,
192190
&job.benefits,
193191
&job.open_source,
194-
&serde_json::to_value(&job.projects).expect("projects should be valid json"),
195192
&job.qualifications,
196193
&job.responsibilities,
197194
&job.salary,
@@ -560,16 +557,15 @@ impl DBDashBoardEmployer for PgDB {
560557
apply_url = $9::text,
561558
benefits = $10::text[],
562559
open_source = $11::int,
563-
projects = nullif($12::jsonb, 'null'::jsonb),
564-
qualifications = $13::text,
565-
responsibilities = $14::text,
566-
salary = $15::bigint,
567-
salary_currency = $16::text,
568-
salary_min = $17::bigint,
569-
salary_max = $18::bigint,
570-
salary_period = $19::text,
571-
skills = $20::text[],
572-
upstream_commitment = $21::int,
560+
qualifications = $12::text,
561+
responsibilities = $13::text,
562+
salary = $14::bigint,
563+
salary_currency = $15::text,
564+
salary_min = $16::bigint,
565+
salary_max = $17::bigint,
566+
salary_period = $18::text,
567+
skills = $19::text[],
568+
upstream_commitment = $20::int,
573569
updated_at = current_timestamp
574570
where job_id = $1::uuid;
575571
",
@@ -585,7 +581,6 @@ impl DBDashBoardEmployer for PgDB {
585581
&job.apply_url,
586582
&job.benefits,
587583
&job.open_source,
588-
&serde_json::to_value(&job.projects).expect("projects should be valid json"),
589584
&job.qualifications,
590585
&job.responsibilities,
591586
&job.salary,

gitjobs-server/src/db/dashboard/job_seeker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl DBDashBoardJobSeeker for PgDB {
7979
open_to_relocation: row.get("open_to_relocation"),
8080
open_to_remote: row.get("open_to_remote"),
8181
phone: row.get("phone"),
82-
photo_id: row.get("avatar_id"),
82+
photo_id: row.get("photo_id"),
8383
projects: row
8484
.get::<_, Option<serde_json::Value>>("projects")
8585
.map(|v| serde_json::from_value(v).expect("projects should be valid json")),

gitjobs-server/src/handlers/dashboard/employer/jobs.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
error::HandlerError,
1919
extractors::{JobBoardId, SelectedEmployerIdRequired},
2020
},
21-
templates::dashboard::employer::jobs,
21+
templates::dashboard::employer::jobs::{self, Job},
2222
};
2323

2424
// Pages handlers.
@@ -88,13 +88,21 @@ pub(crate) async fn update_page(
8888
#[instrument(skip_all, err)]
8989
pub(crate) async fn add(
9090
State(db): State<DynDB>,
91+
State(form_de): State<serde_qs::Config>,
9192
SelectedEmployerIdRequired(employer_id): SelectedEmployerIdRequired,
92-
Form(mut job): Form<jobs::Job>,
93+
body: String,
9394
) -> Result<impl IntoResponse, HandlerError> {
95+
// Get job information from body
96+
let mut job: Job = match form_de.deserialize_str(&body).map_err(anyhow::Error::new) {
97+
Ok(profile) => profile,
98+
Err(e) => return Ok((StatusCode::UNPROCESSABLE_ENTITY, e.to_string()).into_response()),
99+
};
94100
job.normalize();
101+
102+
// Add job to database
95103
db.add_job(&employer_id, &job).await?;
96104

97-
Ok(StatusCode::CREATED)
105+
Ok(StatusCode::CREATED.into_response())
98106
}
99107

100108
/// Handler that archives a job.
@@ -134,11 +142,19 @@ pub(crate) async fn publish(
134142
#[instrument(skip_all, err)]
135143
pub(crate) async fn update(
136144
State(db): State<DynDB>,
145+
State(form_de): State<serde_qs::Config>,
137146
Path(job_id): Path<Uuid>,
138-
Form(mut job): Form<jobs::Job>,
147+
body: String,
139148
) -> Result<impl IntoResponse, HandlerError> {
149+
// Get job information from body
150+
let mut job: Job = match form_de.deserialize_str(&body).map_err(anyhow::Error::new) {
151+
Ok(profile) => profile,
152+
Err(e) => return Ok((StatusCode::UNPROCESSABLE_ENTITY, e.to_string()).into_response()),
153+
};
140154
job.normalize();
155+
156+
// Update job in database
141157
db.update_job(&job_id, &job).await?;
142158

143-
Ok(StatusCode::NO_CONTENT)
159+
Ok(StatusCode::NO_CONTENT.into_response())
144160
}

gitjobs-server/src/handlers/dashboard/job_seeker/profile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub(crate) async fn update_page(
5353
#[instrument(skip_all, err)]
5454
pub(crate) async fn update(
5555
State(db): State<DynDB>,
56+
State(form_de): State<serde_qs::Config>,
5657
auth_session: AuthSession,
5758
body: String,
5859
) -> Result<impl IntoResponse, HandlerError> {
@@ -62,7 +63,7 @@ pub(crate) async fn update(
6263
};
6364

6465
// Get profile information from body
65-
let mut profile: JobSeekerProfile = match serde_qs::from_str(&body).map_err(anyhow::Error::new) {
66+
let mut profile: JobSeekerProfile = match form_de.deserialize_str(&body).map_err(anyhow::Error::new) {
6667
Ok(profile) => profile,
6768
Err(e) => return Ok((StatusCode::UNPROCESSABLE_ENTITY, e.to_string()).into_response()),
6869
};

gitjobs-server/src/router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct StaticFile;
5050
pub(crate) struct State {
5151
pub db: DynDB,
5252
pub image_store: DynImageStore,
53+
pub form_de: serde_qs::Config,
5354
}
5455

5556
/// Setup router.
@@ -59,6 +60,7 @@ pub(crate) fn setup(cfg: &HttpServerConfig, db: DynDB, image_store: DynImageStor
5960
let state = State {
6061
db: db.clone(),
6162
image_store,
63+
form_de: serde_qs::Config::new(3, false),
6264
};
6365

6466
// Setup authentication / authorization layer

0 commit comments

Comments
 (0)