Skip to content

LoiKos/perfectAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This API as been design to be used to tests the Swift Perfect framework performances.

This API is build to work with a PostgreSQL database and provide a way to interact with stores and products through an relational model.

Api Documentation

Stores | Products | Stock | Errors

Stores

URL : api/v1/stores | api/v1/stores/:id

Method : GET,POST | DELETE , PATCH GET

URL Params :     none         |  id: required

Parameters :  Limit and Offet with GET | None

Request body Structure :

// Store obj
{
   "refStore": String   //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "vat":Double,        //  optional
   "currency":String,   //  optional
   "merchantkey":String //  optional
} 

Code

Code: 200 OK

Content:

// Store obj
{
   "refStore": String   //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "vat":Double,        //  optional
   "currency":String,   //  optional
   "merchantkey":String //  optional
} 

OR

[
   {
      "refStore": String   //  Auto generated do not modify
      "name": String,      //  required
      "picture":String,    //  optional
      "vat":Double,        //  optional
      "currency":String,   //  optional
      "merchantkey":String //  optional
   },{
      "refStore": String   //  Auto generated do not modify
      "name": String,      //  required
      "picture":String,    //  optional
      "vat":Double,        //  optional
      "currency":String,   //  optional
      "merchantkey":String //  optional
   }
   ,...
] 

Code: 201 CREATED

Content:

// Store obj
{
   "refStore": String   //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "vat":Double,        //  optional
   "currency":String,   //  optional
   "merchantkey":String //  optional
} 

Products

URL : api/v1/products | api/v1/products/:id

Method : GET,POST | DELETE , PATCH GET

URL Params :     none         |  id: required

Parameters :  Limit and Offet with GET | None

Request body Structure :

// Product obj
{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
} 

Code

Code: 200 OK

Content:

// Product obj
{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
} 

OR

[
   // Product obj
{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
},{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
} 
   ,...
] 

Code: 201 CREATED

Content:

// Product obj
{
   "refproduct": String //  Auto generated do not modify
   "name": String,      //  required
   "picture":String,    //  optional
   "creationdate":Date //  Auto generated do not modify
} 

Stock

URL : api/v1/stores/:storeId/products | api/v1/stores/:storeId/products/:productId

Method : GET,POST | DELETE , PATCH GET

URL Params :     storeId: required         |  storeId: required, productId: required

Parameters :  Limit and Offet with GET | None

Request body Structure :

// Stock obj
{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
} 

Code

Code: 200 OK

Content:

// Stock obj
{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
} 

OR

[
   // Product obj
// Stock obj
{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
} ,{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
}
   ,...
] 

Code: 201 CREATED

Content:

// Stock obj
{
   "product_refproduct": String //  Auto generated do not modify
   "product_name": String,      //  required
   "product_picture":String,    //  optional
   "product_creationdate":Date, //  Auto generated do not modify
   "refproduct":String,
   "refstore":String,
   "quantity":Int,
   "vat":Double,
   "priceht":Double,
   "status":String,
   "creationdate":Date,
   "lastupdate":Date
}

API Error

Code: 400 BAD REQUEST

Example :

  • Empty JSON Body for POST or PATCH

  • Missing required properties POST

  • Wrong limit or offset ( < 0 )

Code: 404 NOT FOUND

Example : Id not found in database

Code: 500 INTERNAL SERVER ERROR

Work with Docker

Required images :

$ docker pull postgres
$ docker pull swift

Launch database container :

$ docker run --name *containerName* -e POSTGRES_PASSWORD=*pwd* -e POSTGRES_USER=*userName* -e POSTGRES_DB=*dbName* -d postgres

Build image :

First go in the Docker file and update these lines :

ENV DATABASE_HOST=*host*  #provide your host name ( you can retrieve via docker inspect )
ENV DATABASE_PORT=*port*  #provide your host port ( postgres work often with 5432 )
ENV DATABASE_DB=*db name*
ENV DATABASE_USER=*user name*
ENV DATABASE_PASSWORD=*database password*

Then lauch this command inside the project folder. If you want to set it :

$ docker build -t *name* . 

Launch perfect container :

$ docker run -it --rm --link *databaseContainerName*:database -p 8080:8080 -v `pwd`:`pwd` -w `pwd` *perfectImageName*

Code Coverage

Coming Soon

Task Flow

  • Database connection
  • Stores routes
  • Products routes
  • Stock routes
  • Docker
  • Linux compatibility
  • API docs
  • Unit tests
  • CI
  • Code Cov

Packages

No packages published

Languages