Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Latest commit

 

History

History
executable file
·
203 lines (177 loc) · 4.99 KB

README.md

File metadata and controls

executable file
·
203 lines (177 loc) · 4.99 KB

Database properties:

  • name: coffeeshop
  • username: cemal
  • password: 1234

After creatin the database, create sequence for each table:

  • CREATE SEQUENCE ownerid_seq;
  • CREATE SEQUENCE productid_seq;
  • CREATE SEQUENCE customerid_seq;
  • CREATE SEQUENCE orderid_seq;

Then create the tables with the following order:

owner table

CREATE TABLE public.owner (
   id int2 DEFAULT nextval('ownerid_seq'::regclass) NOT NULL,
   realname varchar(50) NOT NULL,
   surname varchar(50) NOT NULL,
   username varchar(50) NOT NULL,
   password varchar(3000) NOT NULL
);
CREATE UNIQUE INDEX owner_id_key ON public.owner (id);

customer table

CREATE TABLE public.customer (
   id int2 DEFAULT nextval('customerid_seq'::regclass) NOT NULL,
     realname varchar(50) NOT NULL,
     surname varchar(50) NOT NULL,
     username varchar(50) NOT NULL,
     password varchar(3000) NOT NULL,
     floorno int4 NOT NULL,
     buildingno int4 NOT NULL,
     roomno int4 NOT NULL
  );
  CREATE UNIQUE INDEX customer_id_key ON public.customer (id);

product table

CREATE TABLE public.product (
   id int2 DEFAULT nextval('productid_seq'::regclass) NOT NULL,
     productname varchar(50) NOT NULL
  );
  CREATE UNIQUE INDEX product_id_key ON public.product (id);

orders table

CREATE TABLE public.orders (
   id int2 DEFAULT nextval('orderid_seq'::regclass) NOT NULL,
     neworsent varchar(4) NOT NULL,
     customer_id int2 NOT NULL,
     product_id int2 NOT NULL,
     CONSTRAINT orders_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customer(id),
     CONSTRAINT orders_product_id_fkey FOREIGN KEY (product_id) REFERENCES public.product(id)
  );
  CREATE UNIQUE INDEX order_id_key ON public.orders (id);

Some example request to REST API:

Orders

Add order

Send POST request to localhost:8080/orders/makeorder and the body is:

{
  "newOrSent": "sent",
  "customer": {
	  "id": 6
  },
  "product": {
  	"id": 4
  }
}

Get Order by its id

Send GET request to localhost:8080/orders/order_id

The example response is

{
    "message": "SUCCESS!",
    "data": {
        "id": 29,
        "orderdate": "19-05-2018 14:01:59",
        "customer": {
            "id": 17,
            "username": "customer2",
            "realname": "gulsen",
            "surname": "aktepe",
            "password": "qwery",
            "floorno": 2,
            "buildingno": 3,
            "roomno": 4,
            "new": false
        },
        "product": {
            "id": 10,
            "productname": "soda",
            "new": false
        },
        "newOrSent": "sent",
        "new": false
    }
}

Get orders by Customer id

Send GET request to localhost:8080/orders/bycustomer/customer_id

The example response is

{
    "message": "SUCCESS!",
    "data": [
        {
            "id": 32,
            "orderdate": "19-05-2018 14:04:06",
            "customer": {
                "id": 18,
                "username": "customer1",
                "realname": "cemal",
                "surname": "unal",
                "password": "qwery",
                "floorno": 2,
                "buildingno": 2,
                "roomno": 2,
                "new": false
            },
            "product": {
                "id": 12,
                "productname": "turk kahvesi",
                "new": false
            },
            "newOrSent": "sent",
            "new": false
        },
        {
            "id": 33,
            "orderdate": "19-05-2018 14:05:58",
            "customer": {
                "id": 18,
                "username": "customer1",
                "realname": "cemal",
                "surname": "unal",
                "password": "qwery",
                "floorno": 2,
                "buildingno": 2,
                "roomno": 2,
                "new": false
            },
            "product": {
                "id": 11,
                "productname": "latte",
                "new": false
            },
            "newOrSent": "sent",
            "new": false
        },
        {
            "id": 34,
            "orderdate": "19-05-2018 14:10:05",
            "customer": {
                "id": 18,
                "username": "customer1",
                "realname": "cemal",
                "surname": "unal",
                "password": "qwery",
                "floorno": 2,
                "buildingno": 2,
                "roomno": 2,
                "new": false
            },
            "product": {
                "id": 11,
                "productname": "latte",
                "new": false
            },
            "newOrSent": "sent",
            "new": false
        }
    ]
}

Edit Order

Send PUT request to localhost:8080/orders/editorder/order_id

Example body is:

{
  "newOrSent": "new"
}

Since we are allowing to edit only status of the order, sending only newOrSent is enough.