/workshopII5-ws

A simple WebService for our trip project

Primary LanguageJava

Workshop-I5

This is our EPSI project. It consists of an application made with Ionic 2 which can interract with the webservice.

The idea is simple, organize a trip with your friend and split the spending.

Getting Started

Prerequisities

You need all these softwares in order to edit the current project.

  • NeatBeans 8.2 (EE edition)
  • JavaEE 7 with JDK 8
  • GlassFish 4.1
  • MySQL 5.7
  • Postman (optional)
  • A good web browser like Chromium

If you just want to install it in a production way.

  • GlassFish 4.1
  • MySQL 5.7

Installing

git clone https://github.com/Dinath/workshop-i5

Break down into end to end tests

Tests are auto-generated by the Application.java. Just comment the test() method to end it, then re-deploy the project.

NB

Database is recreated on each deployment throught persistence.xml.

Deployment

You just need to deploy the project through GlassFish or use Netbeans.

JSON Webservice

Returns 200 if it is OK, 400 otherwise.

On creation / connection, return the whole JSON entity.

Two routes are available.

http://localhost:8080/WorkshopI5/ws/trip/
http://localhost:8080/WorkshopI5/ws/user/

EntityUser.java "user"

### GET

Optional : use and ID to get a specified user.

http://localhost:8080/WorkshopI5/ws/user/{id}
[
  {
    "email": "root@root.org",
    "name": "root",
    "first-name": "root",
    "password": "H\u0013IM\u0013~\u00161��\u0001լ�n{��t�\u0011��VV^�\u001dsvw�",
    "date-creation": "2016-11-17",
    "phone-number": "06-07-88-99-14",
    "date-birthday": "2016-11-17"
  }
]

### DELETE

Optional : Delete an entity.

http://localhost:8080/WorkshopI5/ws/user/{id}

Returns the JSON code for entity or 404 not found.

### GET by ID

Optional : use and ID to get a specified user.

http://localhost:8080/WorkshopI5/ws/user/{id}

Returns the JSON code for entity or 404 not found.

### POST

http://localhost:8080/WorkshopI5/ws/user
{
    "date-birthday": "2016-10-19",
    "email": "alex@root-8.org",
    "first-name": "alex",
    "name": "alex",
    "password": "root",
    "phone-number": "06-07-88-99-14"
  }

Returns 405 code if the mail address is already used.

The POST returns the same JSON with its ID.

POST for Trip

Only needs ID for User fields.

http://localhost:8080/WorkshopI5/ws/trip

For PUT, add the Trip ID.

{
    "address-from": "Odyseum, Montpellier",
    "address-to": "Gare du Nord, Paris",
    "date-creation": "2016-11-17",
    "date-from": null,
    "date-to": null,
    "description": "Description...",
    "name": "davy trip",
    "number-insiders": 2,
    "number-participers": 10,
    "price": 20,
    "user-organizer": {
      "id": 1
    },
    "users-participer": [
      {
      "id": 1
      }
    ]
  }

### PUT

DO NOT FORGET TO PUT THE ID.

http://localhost:8080/WorkshopI5/ws/user
{
    "id": 6,
    "date-birthday": "2016-11-17",
    "date-creation": "2016-11-17",
    "email": "alex@root-8.org",
    "first-name": "alex",
    "name": "alex",
    "phone-number": "06-07-88-99-14"
  }

Custom routes

We can GET / POST on custom routes.

Trips by higher / lower price

Ordered by higher price.

http://localhost:8080/WorkshopI5/ws/trip/order-price/0

Ordered by lower price.

http://localhost:8080/WorkshopI5/ws/trip/order-price/1

Lower / Higher trip price

GET it from this URL, simple TEXT.

Lower

http://localhost:8080/WorkshopI5/ws/trip/best-price/1

Higher

http://localhost:8080/WorkshopI5/ws/trip/best-price/0

Trips available by PLACE, DEPART DATE and PRICE MIN / MAX

POST the JSON code on.

http://localhost:8080/WorkshopI5/ws/trip/with-params
{
    "place": "Paris",
    "dateFrom": "2016-11-17",
    "priceMin": 20,
    "priceMax": 25
}

Trips available by PLACE and DEPART DATE

POST a JSON code on the followin URL with proper informations : based on the destination date.

http://localhost:8080/WorkshopI5/ws/trip/available
{
	"address-to": "Paris",
	"date-to": "2016-11-17"
}

User connection

POST a JSON code with proper informations.

{
	"email": "root@root.org",
	"password": "root"
}

If the user exists, then the whole user entity will be returned. If the user does not exist, there will be a 404 Response.