This project is the Golang Backend Web Development bootcamp ending project organized by patika.dev and kodluyoruz, sponsored by Picus Security. Within the scope of the project, Basket API application was realized.
Used technologies;
- GORM
- Gin
- MySQL
- JWT
- Swagger
PS: Before you start, set the sql connections in the configs/project.qa.yaml file. If you have your own connections you can do it by setting it on main.go line:18.
Only admins can add categories and products admin id can be added as foreignkey adminId to category, product entities.
Basket and Order difference is providing with IsOrder attribute.
In this point requests contain email and password if DB has this user returns JWT token to use other points' Authorization processes.
Point has 2 using with request body(email,password);
POST localhost:8080/login/customer
POST localhost:8080/login/admin
This point takes customer with name,username,email,password,phone and address information but only username,email and password is necessary fields. If there is same name or email customer it will return err. After signup point returns JWT token.
Point has using with request body(Customer fields);
POST localhost:8080/signup
Getting all categories comes with pagination. An admin can add a category with uploading csv file, in this file should contains name,code and description columns if there is not one of them api will response with not readable. In adding process if given file line is in DB with same name or code it will not create you can see on logs.
Point has using two router;
Getting all categories with pagination takes page and size query parameters, if you dont enter will be default(1-100). Max size is 10000.
GET localhost:8080/category
Adding category runs with takes Authorization JWT token and form-data body key should be named as "file", this file taken and uploads in /assets with random name, after this process checks it and adds to DB its lines, if there is some problem with reading deletes the file from /assets if there is not holds the file in /assets .
POST localhost:8080/category
Point has five router;
Get products works like categories, it has same pagination specialities. Pagination takes page and size query parameters.
GET localhost:8080/product
Searching has 3 query parameters. These are "name","categoryId" or "amount". All can work together, name field checks which categories has same query input, categoryId gives back all entered input products that has same categoryId and lastly amount returns back products which has equal or bigger amount products. If there is not entered data returns not found.
GET localhost:8080/product/search
Creating new product needs Authorization JWT token and request body of Product it should has unique name and code. If category id is not given then categorizing will be default with category named Other.
POST localhost:8080/product
Deleting product runs with Authorization JWT token and query product id or request body product but this process needs only product id.
DELETE localhost:8080/product
Updating product needs Authorization JWT token and all product fields especially id,name,categoryid and code. Takes fields and updates them.
PUT localhost:8080/product
Point has five router;
Get basket works with Authorization JWT token gives back customers all basket items.
GET localhost:8080/basket
Adding basket runs with Authorization JWT token and request body (product id and amount is needed). There can be one or more product in request and request should not contain same product twice or more. Checks product with given id and is there enough amount of product if there is decreases the products amount. After checking adds them into DB.
POST localhost:8080/basket
Complete to order needs Authorization JWT token. If the basket products deleted by admin. customer should delete the product from own basket.
POST localhost:8080/basket/complete
Deleting basket products runs with Authorization JWT token and query product id or request body product but this process needs only product id. Deleting process contains delete basket products by one by.
DELETE localhost:8080/product
Updating basket product needs Authorization JWT token and request body(amount and product id is needed). This process runs on amount count.
PATCH localhost:8080/product
There is two router;
Get orders runs with Authorization JWT token and returns customers orders.
GET localhost:8080/order
Cancel order works with Authorization JWT token and query parameter "code". Code represents order and cancels if it has not been 14 days since ordered.
PATCH localhost:8080/order/cancel
In Swagger POST /category with CSV not implemented. Can be run in Postman.
Order and Basket implement works on same entity named order. Difference is providing with isOrder and orderCode. If IsOrder is true it is order but if it is false it represents basket item. The order code is created when the basket is ordered.
When program starts admin users and one category named as Other will be created.
If a product is deleted but if it is in order it will not shown on get all orders, if is in basket it will be deleted customers by self.
Adding category process CSV file shoud contain columns name,code(uint) and description.
When a customer or admin added password will be hashed. Same hashing is using at user roles.
There are soft deletes working on the DB so the response can contain more information.
Basket entity can be added to DB
No test execution provided yet.