golang-cafe / job-board

Golang Cafe - Go job board with no recruiters and clear salary ranges
https://golang.cafe
BSD 3-Clause "New" or "Revised" License
208 stars 50 forks source link

[FEATURE] allow recruiters to search by experience level, rate, work preference #114

Closed rjackson closed 1 year ago

rjackson commented 1 year ago

As requested in #76

I've added filtering to the developers page that is only available to administrators and recruiters.

image

I've extended developers/model.go so I can reuse ValidRoleLevels and ValidRoleTypes, and I've introduced some Sorted... methods in there so we can control the order in which these fields render on the filters page.

When the search filters are applied, I'm taking the recruiter filters and adding them to the URL as query parameters.

The backend code only applies these filters if the logged in user is a recruiter or admin. For unauthorised users, the query parameters are ignored entirely – we don't even parse them.

To apply the filters, I've had to really change up how we were building the SQL query in DevelopersByLocationAndTag so we can dynamically add WHERE conditions when relevant.

This has allowed us to simplify the query in ways, as we no longer need a switch statement that covers every possible permutation of location, skills, and these new filters.

Annoyingly, the postgres database doesn't like ? placeholder values and instead requires us to set $1, $2, $3, etc. To make it work I've had to introduce argIndex to keep track of how many dynamic arguments we insert, so the next placeholders are set correctly (this enables the next condition to be added as $4.

Of course, I'm not wedded to any particular styling or behavioural decisions. Happy to work with y'all and tweak as required :)

Bounty hunting: /claim #76

ghost commented 1 year ago

thank you @rjackson!