Skip to content

10 Master Suppliers

Rijal Asep Nugroho edited this page Oct 5, 2019 · 1 revision

Master Suppliers

CRUD master supplier

Design Table

CREATE TABLE suppliers (
	id   BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
	company_id	INT(10) UNSIGNED NOT NULL,
	code	CHAR(10) NOT NULL UNIQUE,
	name	VARCHAR(255) NOT NULL,
	address VARCHAR(255),
	created TIMESTAMP NOT NULL DEFAULT NOW(),
	updated TIMESTAMP NOT NULL DEFAULT NOW(),
	PRIMARY KEY (id),
	KEY suppliers_company_id (company_id),
	CONSTRAINT fk_suppliers_to_companies FOREIGN KEY (company_id) REFERENCES companies(id)
);

Endpoint

HTTP Method Url Description
GET /suppliers Get suppliers list
POST /suppliers Create new supplier
GET /suppliers/:id Get supplier by id
PUT /suppliers/:id Edit supplier by id
DELETE /suppliers/:id Delete supplier by id

GET /suppliers

Request

Name Type Validation
code string required
name string required
address string

Example json of payload request :

{
	"code": "MHT"
	"name": "Mahaka Hutama Timor"
	"address": "Jl Kukusan Barat no 17 Jakarta Selatan"
}

Response

HTTP Code Text Description
200 Status OK Status OK
400 Bad Request Bad request
401 Forbidden Forbidden
500 Internal Server Error unknown error
404 Not Found Not Found

Logic

Make sure you filter the data. Supplier shown in the list of suppliers only belongs to the logged-in user. You can retrieve data of user login in context. You can use ctx.Value(api.Ctx("auth)).(User) in package of models.

POST /suppliers

Request

Response

Logic

GET /suppliers/:id

Request

Response

Logic

PUT /suppliers/:id

Request

Response

Logic

DELETE /suppliers/:id

Request

Response

Logic