GithubHelp home page GithubHelp logo

treetopexercise's Introduction

##TreeTop Engineering Solution

This project solves a problem provided by TreeTop Commons as part of the hiring evaluation process

Synopsis

This project implements a REST API with one GET endpoint that returns a list of organizations filtered by field names(case insensitive).

API specification

GET /organizations?category=Greek&city=Washington

Fields:

Id: numeric id

Name: string //organization name

City: string //US city name

State: string //US state name

Postal: string //US postal code

Category: string //categorization of org

Additional query params:

Orderby: string //fieldname to order the results by

Direction: string //ASC or DSC

The expected response is a JSON collection of organizations:

{ "organizations": [

{

"id":"102",

"name":"Sigma Kappa Zeta Chapter",

"city":"Washington",

"state":"DC",

"postal":"20052",

"category":"Greek"

},

...

]

}

All query parameters are optional.

Approach

  • This project works with a Glassfish server and uses Jersey to implement a JAX-RS service.
  • The required filters are very similar to simple SQL statements, so I imported the data from the .csv file into a postgres database, and used JDBC to query it. I used Jackson for JSON conversion.
  • Due to time constraints, I was not able to mock classes properly, so I isolated the code to be tested into methods with few dependencies and changed them from private to protected.
  • Also due to time constraints, I was not able to build end to end tests using Postman. This should be done to ensure the database queries actually work properly and consistently.
  • I built simple DTO objects with JAXB annotations to deal with the return values, and then subclassed them with objects with extra methods for actually dealing with the database.
  • The DTOs used public fields because of time constraints in dealing with JAXB annotations; this should be improved for production code.
  • Due to time constraints, no validation of input parameters is done. The validation should be added for negative ids and invalid orderby fields and directions.
  • This implementation did not address security at all. Authentication and Authorization needs to be addressed, and the jdbc query is vulnerable to sql injection attack.
  • Lastly, due to time constraints, very few JavaDoc comments were put in, and this should be improved.

Installation

Aside from downloading the code and setting up Intellij to run the project, you will need to setup the postgres database and import the data.

Create an empty table in PostgreSql

Create a TreeTop PostgreSql server and add a TreeTopDB database with an organizations table(User postgres with password postgres):

CREATE TABLE public.organizations

(

id integer,

name character varying(256),

city character varying(256),

state character varying(256),

postal character varying(256),

category character varying(256)

)

WITH (

OIDS=FALSE

);

ALTER TABLE public.organizations

OWNER TO postgres;

Import the .csv file into the organizations Table

Tests

The unit tests can be run in Intellij or on the command line.

You can test the API using Postman as follows:

GET http://localhost:8080/treetop4_war_exploded/organizations?name=Timeless

Headers: Content-Type application/json

Body returned:

{

"organizations": [

{

  "id": 22,
  
  "name": "Timeless",
  
  "city": "Port Saint Lucie West",
  
  "state": "FL",
  
  "postal": "34986",
  
  "category": "Community"
  
}

]

}

Contributors

James Owen

License

??

treetopexercise's People

Watchers

 avatar

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.