Code Monkey home page Code Monkey logo

employee_system's Introduction

README - Employee System Assignment

Technologies used

  • Ruby
  • Javascript
  • HTML
  • CSS
  • Rails
  • PostgreSQL
  • Bootstrap

Approach

  • As the initial instructions stated a CRUD application, I chose Ruby on Rails as it would ease the process of dealing with all CRUD actions.
  • This left me more time to deal with the main issue which was accessing the hiearchy of each employee in the SHOW route.
  • I created an ERD of what a table would look like deciding finally to go with a single employee table that has an ID, a name, and a manager_id which would be referencing the employee's ID.(Shown Below)

ALT text

Recursive Query

  • The biggest issue was dealing with the recursive query that would handle fetching the employee's manager and every subsequent manager in the Hiearchy. The query is as follows:
 @hierarchy = Employee.find_by_sql("
      WITH RECURSIVE EmployeeCTE AS (
          
          --ANCHOR--
        SELECT id, name, manager_id FROM employees 
        where id = #{params[:id]}
        UNION 

          --RECURSION--
        SELECT employees.id, employees.name, employees.manager_id
        FROM employees JOIN EmployeeCTE
        On employees.id = EmployeeCTE.manager_id
      )
        SELECT * from EmployeeCTE
     
    ")
  • In this query, The anchor first gets executed passing in the ID params from the SHOW route which returns the employee ID, name and manager_id result set.
  • This result set is now the input for the recursion and returns the original Employee's manager name, id and manager_id
  • This runs until a result set where manager_id is null is returned.
  • The final line is SELECT * from EmployeeCTE to return the id, name and manager_id for all rows.
  • Once this was solved I added bootstrap to add some stylings to the application.

Installation

  • Install Ruby & Rails (latest version)
  • Install PostgreSQL
  • Run Bundle Install
  • Run rails db:create, db:migrate, db:seed (for dummy data)
  • Run Rails server
  • Accessible on Localhost:3000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.