Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Candidates section challenge #10

Closed
wants to merge 93 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
26e610c
Add main.css and main.jsx initial config files
andrecego Feb 8, 2024
776be99
refactor: initial setup app for react
andrecego Feb 8, 2024
c14e5ae
feat: add `@` alias for src folder
andrecego Feb 8, 2024
cf3951f
chore: remove useless view test
andrecego Feb 8, 2024
0719cc9
refactor: development and test gems on Gemfile
andrecego Feb 8, 2024
0701e1d
Merge pull request #1 from andrecego/feat/initial-project-configs
andrecego Feb 8, 2024
5960c1a
lint: Gemfile autocorrect
andrecego Feb 8, 2024
92edebf
feat: add RSpec and Rubocop workflows
andrecego Feb 8, 2024
83ccffd
fix: test workflow
andrecego Feb 8, 2024
21d1707
Merge pull request #2 from andrecego/ci/add-lint-and-test-workflows
andrecego Feb 8, 2024
1a600d4
Add React JSX support and configure vitest
andrecego Feb 8, 2024
53728fc
build: add React CI workflow
andrecego Feb 8, 2024
8d15631
chore: add @babel/preset-react and babel-plugin-transform-react-remov…
andrecego Feb 8, 2024
f7e5243
fix: proposal to transform in babel config
andrecego Feb 8, 2024
9343c91
Merge pull request #3 from andrecego/ci/react-test-workflow
andrecego Feb 8, 2024
3f74a43
chore: update dependencies and configuration files
andrecego Feb 9, 2024
f1e474c
build: add faker and pry
andrecego Feb 9, 2024
2576465
feat: add Candidate model and migration
andrecego Feb 9, 2024
ee86cee
Merge pull request #4 from andrecego/feat/create-candidate-model
andrecego Feb 9, 2024
fb55486
chore: add BaseValidator class
andrecego Feb 9, 2024
690f2f9
feat: add Candidates::CreateValidator
andrecego Feb 9, 2024
71eeb25
Merge pull request #5 from andrecego/feat/create-candidate-validator
andrecego Feb 9, 2024
17ae20b
fix: job name from "build" to "test" in react.yml
andrecego Feb 9, 2024
6980875
chore: add Candidates::CreateUseCase
andrecego Feb 9, 2024
64b1f14
feat: add API controller and routes for creating candidates
andrecego Feb 9, 2024
483a727
fix: birthdate validation to include current date
andrecego Feb 9, 2024
e2d4f46
Merge pull request #6 from andrecego/feat/add-candidate-endpoint
andrecego Feb 9, 2024
81c0dfc
deat: add Rswag gem and configure Swagger documentation
andrecego Feb 9, 2024
9d574b0
Merge pull request #7 from andrecego/feat/add-open-api
andrecego Feb 9, 2024
d7750f3
feat: add PaginateService
andrecego Feb 9, 2024
8bd21b3
deps: add gem 'oj' for json serialization performance
andrecego Feb 9, 2024
7112fd0
lint: update rubocop configs and lint
andrecego Feb 9, 2024
17ca29a
feat: add candidates listing endpoint
andrecego Feb 9, 2024
1e65381
chore: update candidates Swagger documentation
andrecego Feb 9, 2024
14a4d6c
Merge pull request #8 from andrecego/feat/add-candidates-list
andrecego Feb 9, 2024
96c195f
feat: add show action to CandidatesController and update routes and t…
andrecego Feb 9, 2024
ade8648
Merge pull request #9 from andrecego/feat/add-show-endpoint-for-candi…
andrecego Feb 9, 2024
e69cb93
refactor: candidates CreateValidator to UpsertValidator
andrecego Feb 9, 2024
db8ec87
chore: add error handling to ApiController
andrecego Feb 9, 2024
8dad735
feat: add update action to candidates controller
andrecego Feb 9, 2024
f754852
Merge pull request #10 from andrecego/feat/add-update-endpoint
andrecego Feb 9, 2024
8ed4c75
feat: add destroy action to CandidatesController
andrecego Feb 9, 2024
4a03252
docs: add API endpoints for updating and deleting candidates
andrecego Feb 9, 2024
9e19db8
Merge pull request #11 from andrecego/feat/add-delete-candidate-enpoint
andrecego Feb 9, 2024
e51a141
lint: add ESLint configuration and linting scripts
andrecego Feb 10, 2024
733b8f2
build: add linting workflow
andrecego Feb 10, 2024
ad6cdf2
lint: update ESLint rules and auto fix
andrecego Feb 10, 2024
e0d3eed
Merge pull request #12 from andrecego/feat/add-eslint
andrecego Feb 10, 2024
f0d5f24
chore: add request functions
andrecego Feb 10, 2024
bd25741
chore: add candidate model
andrecego Feb 10, 2024
e29489e
chore: add candidates repository
andrecego Feb 10, 2024
1154485
i18n: add i18n configuration and en.json file
andrecego Feb 10, 2024
70ab84c
feat: add Router and Routes components
andrecego Feb 10, 2024
6352e58
lint: auto fix
andrecego Feb 10, 2024
ed28b51
test: add test setup and teardown in createCandidate function
andrecego Feb 10, 2024
aeb84a5
Merge pull request #13 from andrecego/feat/add-router-i18n
andrecego Feb 11, 2024
5e11dd7
chore: update main.css with CSS reset
andrecego Feb 11, 2024
a9ab308
deps: add antd package dependency
andrecego Feb 11, 2024
a3b6bd3
feat: add CandidateCard component
andrecego Feb 11, 2024
9759edc
chore: add getCandidate function to candidates repository
andrecego Feb 11, 2024
da99c7d
feat: add Candidate details view
andrecego Feb 11, 2024
36166a2
chore: add support for proposal-optional-chaining in Babel config
andrecego Feb 11, 2024
126b1e8
Merge pull request #14 from andrecego/feat/add-candidate-details-view
andrecego Feb 11, 2024
b42ef4f
refactor: CandidateCard component styling
andrecego Feb 12, 2024
c2f5d4f
refactor: candidates repository with meta
andrecego Feb 12, 2024
8fb88ca
chore: add candidateMeta function to candidate model
andrecego Feb 12, 2024
6ce5218
fat: add Candidates view listing
andrecego Feb 12, 2024
f380766
Merge pull request #15 from andrecego/feat/candidates-listing
andrecego Feb 12, 2024
8604351
chore: add toastify-js lib
andrecego Feb 12, 2024
9200d33
refactor: candidates controller to always return a json
andrecego Feb 12, 2024
49b9827
refactor: routes to use <BrowserRouter>
andrecego Feb 12, 2024
d699fc5
chore: add createCandidate action on repository
andrecego Feb 12, 2024
515af9f
feat: add CandidateForm and CandidateNew components
andrecego Feb 12, 2024
19f3420
feat: add NavBar component
andrecego Feb 12, 2024
03e3a1a
chore: add error status to form inputs
andrecego Feb 12, 2024
b6f5ee1
fix: flaky specs
andrecego Feb 12, 2024
49ed3de
Merge pull request #16 from andrecego/feat/create-new-candidate
andrecego Feb 12, 2024
66b1b0a
feat: refactor CandidateNew to CandidateUpsert
andrecego Feb 12, 2024
b3e3e04
chore: add toForm method to Candidate model
andrecego Feb 12, 2024
65f733b
chore: add updateCandidate function to candidates repository
andrecego Feb 12, 2024
e62753a
feat: add update autocomplete on CandidateForm
andrecego Feb 12, 2024
22439bd
test: add mock for react-router-dom and antd components
andrecego Feb 12, 2024
c06f6ba
Merge pull request #17 from andrecego/feat/add-update-candidate
andrecego Feb 12, 2024
6d0dc3d
feat: add deleteCandidate function
andrecego Feb 12, 2024
9bf8e09
test: add deleteCandidate function to candidates repository
andrecego Feb 12, 2024
271a929
Merge pull request #18 from andrecego/feat/delete-candidate
andrecego Feb 12, 2024
a591ddf
chore: update render statements in candidates_controller.rb
andrecego Feb 12, 2024
fca3560
chore: remove Home view and update route to Candidates
andrecego Feb 12, 2024
a7aa0c4
fix: remove onClick event from DeleteFilled component
andrecego Feb 12, 2024
e33fec1
docs: update README.md with resolution summary and add preview image
andrecego Feb 12, 2024
61008fb
chore: add seed data for candidates
andrecego Feb 12, 2024
4bca5d4
chore: remove size changer from pagination
andrecego Feb 12, 2024
585112e
Merge pull request #19 from andrecego/challenge-resolved
andrecego Feb 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"extends": [
"eslint:recommended",
"google",
"plugin:react/recommended"
],
"env": {
"browser": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"react/react-in-jsx-scope": "off",
"object-curly-spacing": ["error", "always"],
"semi": ["error", "never"],
"max-len": ["error", { "ignoreComments": true, "code": 120 }],
"react/prop-types": "off",
"react/display-name": "off"
}
}
60 changes: 60 additions & 0 deletions .github/workflows/rails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "Ruby on Rails CI"
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
test:
runs-on: ubuntu-latest
services:
mysql2:
image: mysql:5.7
ports:
- "3306:3306"
env:
MYSQL_DATABASE: rails_test
MYSQL_USER: rails
MYSQL_PASSWORD: password
MYSQL_TCP_PORT: 3306
MYSQL_RANDOM_ROOT_PASSWORD: true
MYSQL_ONETIME_PASSWORD: true
# Before continuing, verify the mysql container is reachable from the ubuntu host
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

env:
RAILS_ENV: test
NODE_ENV: test
DATABASE_URL: "mysql2://rails:password@127.0.0.1:3306/rails_test" # localhost doesn't work because the application can't connect to the linux host socket
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Ruby and gems
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
with:
bundler-cache: true
- name: Set up database schema
run: bundle exec rails db:create db:migrate
- name: Install Node.js and packages
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install Yarn and packages
run: npm install -g yarn@1.22.19 && yarn install
- name: Run webpacker
run: NODE_OPTIONS="--openssl-legacy-provider" bundle exec rails webpacker:compile # NODE_OPTIONS needs to be set inline to avoid a webpacker error with node 18
- name: Run rspec
run: bundle exec rspec

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Ruby and gems
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
with:
bundler-cache: true
# Add or replace any other lints here
- name: Run rubocop
run: bundle exec rubocop
42 changes: 42 additions & 0 deletions .github/workflows/react.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "React CI"
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js 18
uses: actions/setup-node@v1
with:
node-version: 18

- name: Install dependencies
run: yarn install

- name: Run the tests
run: yarn test

lint:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js 18
uses: actions/setup-node@v1
with:
node-version: 18

- name: Install dependencies
run: yarn install

- name: Run the linter
run: yarn lint
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--require spec_helper
--require rails_helper
17 changes: 17 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,20 @@ AllCops:

Style/Documentation:
Enabled: false

RSpec/EmptyExampleGroup:
Exclude:
- "**/*swagger_spec.rb"

RSpec/NestedGroups:
Max: 4

RSpec/ExampleLength:
Enabled: false

Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Layout/HashAlignment:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 2.7.7
42 changes: 15 additions & 27 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,32 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.7.7'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem 'rails', '~> 6.1.7', '>= 6.1.7.3'
# Use mysql as the database for Active Record
gem 'bootsnap', '>= 1.4.4', require: false
gem 'mysql2', '~> 0.5'
# Use Puma as the app server
gem 'oj'
gem 'puma', '~> 5.0'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'rails', '~> 6.1.7', '>= 6.1.7.3'
gem 'rswag'
gem 'webpacker', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'factory_bot_rails', '~> 6.0.0', require: false
gem 'faker', '~> 3.2'
gem 'pry-byebug'
gem 'rspec-rails', '~> 6.0.0'
gem 'rubocop', '~> 1.48', require: false
gem 'rubocop-performance', '~> 1.16', require: false
gem 'rubocop-rails', '~> 2.18', require: false
gem 'rubocop-rake', '~> 0.6.0', require: false
gem 'rubocop-rspec', '~> 2.19', require: false
end

group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 4.1.0'
# Display performance information such as SQL time and flame graphs for each request in your browser.
# Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
gem 'rack-mini-profiler', '~> 2.0'
gem 'ruby-lsp-rails'
gem 'web-console', '>= 4.1.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

gem 'rspec-rails', '~> 6.0.0', groups: %i[development test]

gem 'factory_bot_rails', '~> 6.0.0', groups: %i[development test]

gem 'rubocop', '~> 1.48', groups: %i[development test], require: false
gem 'rubocop-performance', '~> 1.16', groups: %i[development test], require: false
gem 'rubocop-rails', '~> 2.18', groups: %i[development test], require: false
gem 'rubocop-rake', '~> 0.6.0', groups: %i[development test], require: false
gem 'rubocop-rspec', '~> 2.19', groups: %i[development test], require: false
54 changes: 50 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ GEM
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bigdecimal (3.1.6)
bindex (0.8.1)
bootsnap (1.16.0)
msgpack (~> 1.2)
builder (3.2.4)
byebug (11.1.3)
coderay (1.1.3)
concurrent-ruby (1.2.2)
crass (1.0.6)
date (3.3.3)
Expand All @@ -76,14 +80,16 @@ GEM
factory_bot_rails (6.0.0)
factory_bot (~> 6.0.0)
railties (>= 5.0.0)
faker (3.2.3)
i18n (>= 1.8.11, < 2)
globalid (1.1.0)
activesupport (>= 5.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.6.3)
json-schema (4.1.1)
addressable (>= 2.8)
language_server-protocol (3.17.0.3)
loofah (2.19.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand All @@ -110,9 +116,19 @@ GEM
nio4r (2.5.8)
nokogiri (1.14.2-x86_64-linux)
racc (~> 1.4)
oj (3.16.3)
bigdecimal (>= 3.0)
parallel (1.22.1)
parser (3.2.1.1)
ast (~> 2.4.1)
prettier_print (1.2.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
public_suffix (5.0.4)
puma (5.6.5)
nio4r (~> 2.0)
racc (1.6.2)
Expand Down Expand Up @@ -170,6 +186,21 @@ GEM
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-support (3.12.0)
rswag (2.13.0)
rswag-api (= 2.13.0)
rswag-specs (= 2.13.0)
rswag-ui (= 2.13.0)
rswag-api (2.13.0)
activesupport (>= 3.1, < 7.2)
railties (>= 3.1, < 7.2)
rswag-specs (2.13.0)
activesupport (>= 3.1, < 7.2)
json-schema (>= 2.2, < 5.0)
railties (>= 3.1, < 7.2)
rspec-core (>= 2.14)
rswag-ui (2.13.0)
actionpack (>= 3.1, < 7.2)
railties (>= 3.1, < 7.2)
rubocop (1.48.1)
json (~> 2.3)
parallel (~> 1.10)
Expand All @@ -196,15 +227,26 @@ GEM
rubocop-rspec (2.19.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-lsp (0.4.5)
language_server-protocol (~> 3.17.0)
sorbet-runtime
syntax_tree (>= 6.1.1, < 7)
ruby-lsp-rails (0.1.0)
rails (>= 6.0)
ruby-lsp (~> 0.4.5)
sorbet-runtime (>= 0.5.9897)
ruby-progressbar (1.13.0)
semantic_range (3.0.0)
sorbet-runtime (0.5.11238)
sprockets (4.2.0)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
thor (1.2.1)
timeout (0.3.2)
tzinfo (2.0.6)
Expand Down Expand Up @@ -232,17 +274,21 @@ DEPENDENCIES
bootsnap (>= 1.4.4)
byebug
factory_bot_rails (~> 6.0.0)
jbuilder (~> 2.7)
faker (~> 3.2)
mysql2 (~> 0.5)
oj
pry-byebug
puma (~> 5.0)
rack-mini-profiler (~> 2.0)
rails (~> 6.1.7, >= 6.1.7.3)
rspec-rails (~> 6.0.0)
rswag
rubocop (~> 1.48)
rubocop-performance (~> 1.16)
rubocop-rails (~> 2.18)
rubocop-rake (~> 0.6.0)
rubocop-rspec (~> 2.19)
ruby-lsp-rails
tzinfo-data
web-console (>= 4.1.0)
webpacker (~> 5.0)
Expand Down
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@ Coding challenge presented to candidates interviewing for a role at [Haistack.AI

_#findyourneedle_

![A screenshot of the application](SCREENSHOT.png)
![A screenshot of the application](./haistack_challenge/preview.png)

## Resolution summary
All of the PRs can be found at https://github.com/andrecego/haistack-coding-challenge/pulls?q=is%3Apr+is%3Aclosed
API Documentation can be found at http://localhost:3000/api-docs

Key points of each PR:
- [PR #1](https://github.com/andrecego/haistack-coding-challenge/pull/1): Initial setup of the project with frontend aliases
- [PR #2](https://github.com/andrecego/haistack-coding-challenge/pull/2): Added lint and test workflows
- [PR #3](https://github.com/andrecego/haistack-coding-challenge/pull/3): Setup the frontend test environment with vitest and react-testing-library
- [PR #4](https://github.com/andrecego/haistack-coding-challenge/pull/4): Add the candidate model
- [PR #5](https://github.com/andrecego/haistack-coding-challenge/pull/5): Base validator and validator classes
- [PR #6](https://github.com/andrecego/haistack-coding-challenge/pull/6): Create use case to create a candidate along with the route
- [PR #7](https://github.com/andrecego/haistack-coding-challenge/pull/7): Add Swagger documentation
- [PR #8](https://github.com/andrecego/haistack-coding-challenge/pull/8): Add Paginate service and oj for performance
- [PR #9](https://github.com/andrecego/haistack-coding-challenge/pull/9): Show candidate endpoint
- [PR #10](https://github.com/andrecego/haistack-coding-challenge/pull/10): Update candidate endpoint
- [PR #11](https://github.com/andrecego/haistack-coding-challenge/pull/11): Delete candidate endpoint
- [PR #12](https://github.com/andrecego/haistack-coding-challenge/pull/12): Add ESLint and linting rules
- [PR #13](https://github.com/andrecego/haistack-coding-challenge/pull/13): Add i18n
- [PR #14](https://github.com/andrecego/haistack-coding-challenge/pull/14): Add Candidate card
- [PR #15](https://github.com/andrecego/haistack-coding-challenge/pull/15): Add Candidates list
- [PR #16](https://github.com/andrecego/haistack-coding-challenge/pull/16): Add Candidate Form and Candidate New pages
- [PR #17](https://github.com/andrecego/haistack-coding-challenge/pull/17): Refactor the candidate new to candidate upsert
- [PR #18](https://github.com/andrecego/haistack-coding-challenge/pull/18): Add delete candidate button
- [PR #19](https://github.com/andrecego/haistack-coding-challenge/pull/19): Documentation and final touches


## Installation

Expand Down
13 changes: 13 additions & 0 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Api
class ApiController < ActionController::API
rescue_from ActiveRecord::RecordNotFound, with: :not_found

private

def not_found
head :not_found
end
end
end
Loading