├── 0. Request For Comments
├── README.md
└── pictures
│ ├── efishery-address.png
│ ├── efishery-orders.png
│ ├── efishery-products.png
│ ├── efishery-users.png
│ └── entity-relationship-diagram.png
├── 1. Version Control System
├── 1. git init.png
├── 10. git merge.png
├── 11. git pull.png
├── 12. git stash.png
├── 13. git clone.png
├── 2. git add.png
├── 3. git status.png
├── 4. git commit.png
├── 5. git remote.png
├── 6. git push new branch.png
├── 6. git push.png
├── 7. git checkout.png
├── 8. git branch.png
└── 9. git fetch.png
├── 2. Relationship Database Management System
├── assignment-postgres-query.sql
└── pictures
│ ├── entitiy-relationship-diagram.png
│ ├── final-table-customers.png
│ ├── final-table-orders.png
│ └── final-table-products.png
├── 3. Introduction to Golang
├── go.mod
├── library
│ └── library.go
└── main.go
├── 4. Advance Golang
├── go.mod
├── library
│ ├── extraction.go
│ └── substraction.go
└── main.go
├── 5. Assignment Week-1
├── README.md
├── go.mod
├── main.go
├── modules
│ ├── module-1.go
│ └── module-2.go
└── pictures
│ ├── exampleCode.png
│ └── job-website.png
├── 6. API
├── go.mod
├── go.sum
└── main.go
├── 7. Clean Architecture
├── .gitignore
├── config
│ └── postgres.go
├── entity
│ └── user.go
├── go.mod
├── go.sum
├── handler
│ └── user.go
├── main.go
├── repository
│ └── user.go
├── routes
│ └── user.go
└── usecase
│ └── user.go
├── 7.1. Exercise Clean Architecture
├── .gitignore
├── config
│ └── postgres.go
├── entity
│ └── user.go
├── go.mod
├── go.sum
├── handler
│ └── user.go
├── main.go
├── repository
│ └── user.go
├── routes
│ └── user.go
└── usecase
│ └── user.go
├── 8. Docker Example in Class
├── Dockerfile
├── go.mod
├── go.sum
├── nomad.hcl
└── server.go
├── 8.1. Cloud Native and Infrastructure
├── .gitignore
├── Dockerfile
├── config
│ └── postgres.go
├── entity
│ └── user.go
├── go.mod
├── go.sum
├── handler
│ └── user.go
├── repository
│ └── user.go
├── routes
│ └── user.go
├── server.go
└── usecase
│ └── user.go
├── 9. Final Project - Warehouse Management System
├── .gitignore
├── Dockerfile
├── README.md
├── config
│ ├── auth
│ │ └── hashPassword.go
│ └── database
│ │ └── postgres.go
├── docker-compose.yaml
├── eFishery Warehouse Management System 3aab94e0380e4d25852a111205ba3d89
│ └── warehouse_test_efishery_-_public2.png
├── entity
│ ├── responseJson
│ │ ├── errorResponse.go
│ │ └── successResponse.go
│ ├── supplier
│ │ ├── supplier.go
│ │ └── supplier_address.go
│ └── warehouse
│ │ ├── warehouse.go
│ │ ├── warehouse_address.go
│ │ ├── warehouse_auth.go
│ │ ├── warehouse_categories.go
│ │ ├── warehouse_orders.go
│ │ ├── warehouse_products.go
│ │ ├── warehouse_roles.go
│ │ ├── warehouse_section.go
│ │ └── warehouse_workers.go
├── go.mod
├── go.sum
├── handler
│ ├── supplier
│ │ ├── supplier.go
│ │ └── supplier_address.go
│ └── warehouse
│ │ ├── warehouse.go
│ │ ├── warehouse_address.go
│ │ ├── warehouse_categories.go
│ │ ├── warehouse_orders.go
│ │ ├── warehouse_product.go
│ │ ├── warehouse_roles.go
│ │ ├── warehouse_section.go
│ │ └── warehouse_workers.go
├── repository
│ ├── supplier
│ │ ├── supplier.go
│ │ └── supplier_address.go
│ └── warehouse
│ │ ├── warehouse.go
│ │ ├── warehouse_address.go
│ │ ├── warehouse_categories.go
│ │ ├── warehouse_orders.go
│ │ ├── warehouse_product.go
│ │ ├── warehouse_roles.go
│ │ ├── warehouse_section.go
│ │ └── warehouse_workers.go
├── routes
│ ├── supplier
│ │ ├── supplier.go
│ │ └── supplier_address.go
│ └── warehouse
│ │ ├── warehouse.go
│ │ ├── warehouse_address.go
│ │ ├── warehouse_categories.go
│ │ ├── warehouse_orders.go
│ │ ├── warehouse_product.go
│ │ ├── warehouse_roles.go
│ │ ├── warehouse_section.go
│ │ └── warehouse_worker.go
├── server.go
└── services
│ ├── supplier
│ ├── supplier.go
│ └── supplier_address.go
│ └── warehouse
│ ├── warehouse.go
│ ├── warehouse_address.go
│ ├── warehouse_categories.go
│ ├── warehouse_orders.go
│ ├── warehouse_product.go
│ ├── warehouse_roles.go
│ ├── warehouse_section.go
│ └── warehouse_workers.go
├── README.md
├── go.mod
└── learngo.go
/0. Request For Comments/README.md:
--------------------------------------------------------------------------------
1 | # eFishery Warehouse Design
2 |
3 | # 1. Summary
4 |
5 | Warehouse management system to manage user orders, warehouse inventory, in and out inventory from factory to warehouse and to user.
6 |
7 | # 2. Problem & Motivation
8 |
9 | By creating such system we can track how much inventory that each warehouse have, when to replenish inventory, when warehouse need to send to customer(user), and for easier sending inventory to user from the nearest warehouse.
10 |
11 | # 3. Detailed Design
12 |
13 | ## User Interface
14 |
15 | ## Entity Relationship Diagram
16 |
17 | - User ERD
18 |
19 | (id, username, password(hashed), phone number, address, role (user, head warehouse, officer warehouse), create at, modified at, )
20 |
21 | Warehouse ERD
22 |
23 | - Inventory in Mall ERD
24 |
25 | (inventory_id, product_name, stock(can be seen for user&warehouse), description, price, created_at, modified_at, transactional.in_product, transactional.out_product)
26 |
27 | - Transactional User and Warehouse.
28 |
29 | (transactional_id, inventory.product, in_product(howmuch in kg)(can be nulled), out_product(howmuch in kg)(can be nulled), user.location, status, created_at, modified_at).
30 |
31 | 
32 |
33 | [efishery.users](https://www.notion.so/fc1e55398d014762b914bb721199c94e)
34 |
35 | 
36 |
37 | [efishery.product](https://www.notion.so/6344661651d14967bd82c1c1e7199a9f)
38 |
39 | 
40 |
41 | [efishery.address](https://www.notion.so/1e2441cf21094fe79779b2382300e9a3)
42 |
43 | 
44 |
45 | [efishery.order](https://www.notion.so/e7c53e6f25c5458db6ac41836f5de3de)
46 |
47 | 
48 |
49 | ## API Contract
50 |
51 | ### **Create User and authentication**
52 |
53 | - Method: POST
54 | - Data sent:
55 |
56 | ```json
57 | {
58 | {
59 | "email": "test@gmail.com",
60 | "password": "test@123",
61 | "first_name": "Hakim",
62 | "last_name": "Naufal",
63 | "phone": "081285402208",
64 | }
65 | }
66 | ```
67 |
68 | - Endpoint: /api/user/registration
69 | - Response Body:
70 | - 201 Created
71 | - Body Payload:
72 |
73 | ```json
74 | {
75 | "message": "User created succesfully",
76 | "user": {
77 | "auth_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijc0YmNhZjUwLWFhNDAtNDc2Yy1hNTM5LTkyMTVmZTc4OGZkNiIsImlhdCI6MTY1NTYwNjcyMn0.gHs7YwXKx7yGSAakxx2_2pO700ShB5ApVjpttbiAy1A",
78 | "roles": "user",
79 | "created_at": "2022-06-19T08:18:28.288Z"
80 | }
81 | }
82 | ```
83 |
84 | ### Login Auth
85 |
86 | - Method: POST
87 | - Data sent:
88 |
89 | ```json
90 | {
91 | {
92 | "email": "test@gmail.com",
93 | "password": "test@123"
94 | }
95 | }
96 | ```
97 |
98 | - Endpoint: /api/user/login
99 | - Response Body:
100 | - 201 Created
101 | - Body Payload:
102 |
103 | ```json
104 | {
105 | {
106 | "message": "User logged in successfully",
107 | "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijc0YmNhZjUwLWFhNDAtNDc2Yy1hNTM5LTkyMTVmZTc4OGZkNiIsImlhdCI6MTY1NTYwNjcyMn0.gHs7YwXKx7yGSAakxx2_2pO700ShB5ApVjpttbiAy1A"
108 | }
109 | }
110 | ```
111 |
112 | ### Read User, and Warehouse profile for WebApp or NativeApp
113 |
114 | - Method: GET
115 | - Endpoint: /api/user/{id}
116 | - Response Body:
117 | - 200 OK
118 | - Body Payload:
119 |
120 | ```json
121 | {
122 | "message": "User retrived succesfully",
123 | "user": {
124 | "id": "74bcaf50-aa40-476c-a539-9215fe788fd6",
125 | "first_name": "John",
126 | "last_name": "Doe",
127 | "email": "test@gmail.com",
128 | "role": "admin",
129 | "createdAt": "2022-06-19T08:18:28.288Z",
130 | "updatedAt": "2022-06-19T08:18:28.288Z"
131 | }
132 | }
133 | ```
134 |
135 | ### Order from User and Warehouse
136 |
137 | - Method: POST
138 | - Data sent:
139 |
140 | ```json
141 | {
142 | {
143 | "product": "eFeeder",
144 | "in_product": "",
145 | "out_product": "1",
146 | "location": "Jakarta",
147 |
148 | }
149 | }
150 | ```
151 |
152 | - Endpoint: /api/transaction/{id}
153 | - Response Body:
154 | - 201 Created
155 | - Body Payload:
156 |
157 | ```json
158 | {
159 | "message": "Transaction succesful.",
160 | "details": {
161 | "product": "eFeeder",
162 | "status": "verified",
163 | "modified_at": "2022-10-19T12:18:28.288Z"
164 | }
165 | }
166 | ```
167 |
168 | # 4. Dependencies
169 |
170 | Using Google login
171 |
172 | # 5. Milestone
173 |
174 | # 6. Deployment
175 |
176 | # 7. Drawbacks/Risks/Possible Failure
177 |
178 | # 8. Alternative
179 |
180 | # 9. Unresolved/Future Possibilities
181 |
--------------------------------------------------------------------------------
/0. Request For Comments/pictures/efishery-address.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/0. Request For Comments/pictures/efishery-address.png
--------------------------------------------------------------------------------
/0. Request For Comments/pictures/efishery-orders.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/0. Request For Comments/pictures/efishery-orders.png
--------------------------------------------------------------------------------
/0. Request For Comments/pictures/efishery-products.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/0. Request For Comments/pictures/efishery-products.png
--------------------------------------------------------------------------------
/0. Request For Comments/pictures/efishery-users.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/0. Request For Comments/pictures/efishery-users.png
--------------------------------------------------------------------------------
/0. Request For Comments/pictures/entity-relationship-diagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/0. Request For Comments/pictures/entity-relationship-diagram.png
--------------------------------------------------------------------------------
/1. Version Control System/1. git init.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/1. git init.png
--------------------------------------------------------------------------------
/1. Version Control System/10. git merge.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/10. git merge.png
--------------------------------------------------------------------------------
/1. Version Control System/11. git pull.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/11. git pull.png
--------------------------------------------------------------------------------
/1. Version Control System/12. git stash.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/12. git stash.png
--------------------------------------------------------------------------------
/1. Version Control System/13. git clone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/13. git clone.png
--------------------------------------------------------------------------------
/1. Version Control System/2. git add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/2. git add.png
--------------------------------------------------------------------------------
/1. Version Control System/3. git status.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/3. git status.png
--------------------------------------------------------------------------------
/1. Version Control System/4. git commit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/4. git commit.png
--------------------------------------------------------------------------------
/1. Version Control System/5. git remote.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/5. git remote.png
--------------------------------------------------------------------------------
/1. Version Control System/6. git push new branch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/6. git push new branch.png
--------------------------------------------------------------------------------
/1. Version Control System/6. git push.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/6. git push.png
--------------------------------------------------------------------------------
/1. Version Control System/7. git checkout.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/7. git checkout.png
--------------------------------------------------------------------------------
/1. Version Control System/8. git branch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/8. git branch.png
--------------------------------------------------------------------------------
/1. Version Control System/9. git fetch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/1. Version Control System/9. git fetch.png
--------------------------------------------------------------------------------
/2. Relationship Database Management System/assignment-postgres-query.sql:
--------------------------------------------------------------------------------
1 | -- Creating table customers
2 | create table if not exists customers (
3 | id serial not null primary key,
4 | customer_name char(50) not null
5 | );
6 | -- Creating table products
7 | create table if not exists products (
8 | id serial not null primary key,
9 | name char(50) not null
10 | );
11 | -- Creating table orders
12 | create table if not exists orders (
13 | id serial not null primary key,
14 | customer_id int not null references customers(id),
15 | product_id int not null references products(id),
16 | order_date timestamp not null,
17 | total float not null
18 | );
19 | -- Inserting data into customers
20 | insert into customers(customer_name) values('Lewis');
21 | insert into customers(customer_name) values('Nikita');
22 | insert into customers(customer_name) values('Johan');
23 | insert into customers(customer_name) values('Verstrappen');
24 | insert into customers(customer_name) values('Sebastian');
25 |
26 | -- Inserting data into products
27 | insert into products(name) values('Ikan Tongkol');
28 | insert into products(name) values('Ikan Lele');
29 | insert into products(name) values('Ikan Mas');
30 | insert into products(name) values('Ikan Patin');
31 | insert into products(name) values('Ikan Kakap');
32 |
33 | -- Inserting data into orders
34 | insert into orders(customer_id, product_id, order_date, total) values(1, 5, now(), 100);
35 | insert into orders(customer_id, product_id, order_date, total) values(2, 4, now(), 200);
36 | insert into orders(customer_id, product_id, order_date, total) values(3, 3, now(), 300);
37 | insert into orders(customer_id, product_id, order_date, total) values(4, 2, now(), 400);
38 | insert into orders(customer_id, product_id, order_date, total) values(5, 1, now(), 500);
39 | -- or shorthand
40 | -- insert into orders(customer_id, product_id, order_date, total)
41 | -- values(1, 5, now(), 100), (2, 4, now(), 200), (3, 3, now(), 300), (4, 2, now(), 400), (5, 1, now(), 500);
42 |
43 | -- Update customers table
44 | update customers set customer_name = 'Lewis Hamilton' where id = 1;
45 | update customers set customer_name = 'Nikita Mazepin' where id = 2;
46 | update customers set customer_name = 'Johan Sebastian' where id = 3;
47 | update customers set customer_name = 'Max Verstrappen' where id = 4;
48 | update customers set customer_name = 'Sebastian Vettel' where id = 5;
49 |
50 | -- Update products table
51 | update products set name = 'Ikan Bandeng' where id = 1;
52 | update products set name = 'Ikan Tuna' where id = 2;
53 | update products set name = 'Ikan Gurame' where id = 3;
54 | update products set name = 'Ikan Kembung' where id = 4;
55 | update products set name = 'Ikan Nila' where id = 5;
56 |
57 | -- Update orders table
58 | update orders set total = 1000 where id = 1;
59 | update orders set product_id = 1 where id = 2; -- execute this to clear out foreign key constraint in orders table (product_id)
60 | update orders set customer_id = 1 where id = 2; -- execute this to clear out foreign key in orders table to customers table
61 | update orders set product_id = 1 where id = 3; -- execute this to clear out foreign key constraint in orders table (product_id)
62 | update orders set customer_id = 1 where id = 3; -- execute this to clear out foreign key in orders table to customers table
63 | update orders set order_date = now() where id = 4;
64 | update orders set total = 5000 where id = 5;
65 |
66 | -- Delete data from orders table
67 | delete from orders where id = 2;
68 | delete from orders where total = 5000;
69 |
70 | -- Delete data from customers table
71 | delete from customers where id = 2;
72 | delete from customers where customer_name = 'Johan Sebastian';
73 |
74 | -- Delete data from products table
75 | delete from products where name = 'Ikan Kembung';
76 | delete from products where id = 3;
77 |
78 | -- Inner join customers and orders table
79 | select orders.id, orders.customer_id, customers.customer_name, order_date, total
80 | from orders
81 | inner join customers
82 | on orders.customer_id = customers.id;
83 |
84 | -- Inner join products and orders table
85 | select orders.id, orders.customer_id, products."name" , orders.order_date , total
86 | from orders
87 | inner join products
88 | on orders.product_id = products.id;
89 |
90 | -- Inner join customers, products and orders table
91 | select orders.id, customers.customer_name, products."name" as product_name , orders.order_date , total
92 | from orders
93 | inner join products on orders.product_id = products.id
94 | inner join customers on orders.customer_id = customers.id ;
95 |
--------------------------------------------------------------------------------
/2. Relationship Database Management System/pictures/entitiy-relationship-diagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/2. Relationship Database Management System/pictures/entitiy-relationship-diagram.png
--------------------------------------------------------------------------------
/2. Relationship Database Management System/pictures/final-table-customers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/2. Relationship Database Management System/pictures/final-table-customers.png
--------------------------------------------------------------------------------
/2. Relationship Database Management System/pictures/final-table-orders.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/2. Relationship Database Management System/pictures/final-table-orders.png
--------------------------------------------------------------------------------
/2. Relationship Database Management System/pictures/final-table-products.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/2. Relationship Database Management System/pictures/final-table-products.png
--------------------------------------------------------------------------------
/3. Introduction to Golang/go.mod:
--------------------------------------------------------------------------------
1 | module intro-golang
2 |
3 | go 1.19
4 |
--------------------------------------------------------------------------------
/3. Introduction to Golang/library/library.go:
--------------------------------------------------------------------------------
1 | package library
2 |
3 | import "fmt"
4 |
5 | // Global function
6 | func SayHello() {
7 | fmt.Println("hello")
8 | introduce("John Wick")
9 | }
10 | func SayGoodBye() {
11 | fmt.Println("good bye")
12 | }
13 |
14 | // Private function
15 | func introduce(name string) {
16 | fmt.Println("My name is", name)
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/4. Advance Golang/go.mod:
--------------------------------------------------------------------------------
1 | module advance-golang
2 |
3 | go 1.19
4 |
--------------------------------------------------------------------------------
/4. Advance Golang/library/extraction.go:
--------------------------------------------------------------------------------
1 | package library
2 |
3 | func ExtractionData(name string) string {
4 |
5 | return name + " is a student" + privateData(" in Bandung")
6 | }
7 | func privateData(address string) string {
8 | return address
9 | }
10 |
--------------------------------------------------------------------------------
/4. Advance Golang/library/substraction.go:
--------------------------------------------------------------------------------
1 | package library
2 |
3 | func Substraction(a, b int) int {
4 | return a - b
5 | }
6 |
--------------------------------------------------------------------------------
/4. Advance Golang/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | libraryFunction "advance-golang/library" // --> import "advance-golang/library" with name libraryFunction
5 | "fmt"
6 | "math"
7 | "sync"
8 | )
9 |
10 | // Method
11 | type Vertex struct {
12 | X, Y float64
13 | }
14 |
15 | func (v Vertex) Abs() float64 {
16 | return math.Sqrt(v.X*v.X + v.Y*v.Y)
17 | }
18 |
19 | // or
20 |
21 | func Abs(v Vertex) float64 {
22 | return math.Sqrt(v.X*v.X + v.Y*v.Y)
23 | }
24 |
25 | type MyFloat float64
26 |
27 | func (f MyFloat) Abs() float64 {
28 | if f < 0 {
29 | return float64(-f)
30 | }
31 | return float64(f)
32 | }
33 |
34 | func main() {
35 | // Pointer --> Pointer is a variable that stores the memory address of another variable
36 | a := 200
37 | b := &a
38 | fmt.Println(a) // Output 200
39 | fmt.Println(b) // Output memory address
40 | *b++
41 | fmt.Println(a) // Output 201
42 |
43 | // Reference Variable --> Reference variable is a variable that stores the memory address of another variable
44 |
45 | // Go Allocation --> Go has automatic allocation and garbage collection
46 |
47 | // Escape Analysis --> Escape analysis is a process that determines whether a variable is allocated on the stack or heap <-- ga ada di materi
48 |
49 | // Go Garbage Collection --> Go has automatic garbage collection <-- ga ada di materi
50 |
51 | // Method --> Method is a function that is associated with a type
52 | v := Vertex{3, 4}
53 | fmt.Println(v.Abs()) // Output 5
54 | // or
55 | fmt.Println(Abs(v)) // Output 5
56 | // or with type non-struct
57 | f := MyFloat(-math.Sqrt2)
58 | fmt.Println(f.Abs()) // Output 1.4142135623730951
59 |
60 | // Go Global and Private Variable --> Global variable is a variable that can be accessed from anywhere in the program. Private variable is a variable that can only be accessed from the same package
61 | println(libraryFunction.ExtractionData(("John Wick")))
62 | println(libraryFunction.Substraction(10, 5))
63 |
64 | // Go Interface --> Interface is a collection of method signatures that can be implemented by other types.
65 | l := lingkaran{14}
66 | s := segitiga{8, 10}
67 | p := persegi{10}
68 | fmt.Println("Luas dan Keliling Lingkaran", l.luas(), l.keliling())
69 | hitungLuasKeliling(l)
70 | fmt.Println("Luas dan Keliling Segitiga", s.luas(), s.keliling())
71 | hitungLuasKeliling(s)
72 | fmt.Println("Luas dan Keliling Persegi", p.luas(), p.keliling())
73 | hitungLuasKeliling(p)
74 |
75 | // Goroutine --> Go routine is a lightweight thread managed by the Go runtime
76 | go func() {
77 | for i := 0; i < 10; i++ {
78 | fmt.Println("Hello World")
79 | }
80 | }()
81 | var input string
82 | fmt.Scanln(&input)
83 |
84 | // Goroutine with WaitGroup --> WaitGroup is a synchronization mechanism that allows you to wait for a collection of goroutines to finish.
85 | var wg sync.WaitGroup
86 | wg.Add(2)
87 | go func() {
88 | fmt.Println("Hi")
89 | wg.Done()
90 | }()
91 | go func() {
92 | fmt.Println("World")
93 | wg.Done()
94 | }()
95 | wg.Wait()
96 | }
97 |
98 | // Go Interface --> Interface is a collection of method signatures that can be implemented by other types.
99 | type lingkaran struct {
100 | diameter float64
101 | }
102 | type segitiga struct {
103 | alas float64
104 | tinggi float64
105 | }
106 | type persegi struct {
107 | sisi float64
108 | }
109 | type hitung interface {
110 | luas() float64
111 | keliling() float64
112 | }
113 |
114 | func (l lingkaran) luas() float64 {
115 | return 3.14 * l.diameter * l.diameter
116 | }
117 | func (l lingkaran) keliling() float64 {
118 | return 2 * 3.14 * l.diameter
119 | }
120 | func (s segitiga) luas() float64 {
121 | return 0.5 * s.alas * s.tinggi
122 | }
123 | func (s segitiga) keliling() float64 {
124 | return 3 * s.alas
125 | }
126 | func (p persegi) luas() float64 {
127 | return p.sisi * p.sisi
128 | }
129 | func (p persegi) keliling() float64 {
130 | return 4 * p.sisi
131 | }
132 | func hitungLuasKeliling(h hitung) {
133 | fmt.Println("Luas :", h.luas())
134 | fmt.Println("Keliling :", h.keliling())
135 | }
136 |
--------------------------------------------------------------------------------
/5. Assignment Week-1/go.mod:
--------------------------------------------------------------------------------
1 | module assignment
2 |
3 | go 1.19
4 |
--------------------------------------------------------------------------------
/5. Assignment Week-1/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "assignment/modules"
5 | "fmt"
6 | )
7 |
8 | func main() {
9 | //Assignment 1
10 | // Answer A
11 | fmt.Println(modules.GoodsFromMoney(
12 | 100000,
13 | ))
14 | // Answer B
15 | fmt.Println(modules.LowHigh())
16 |
17 | // Answer C
18 | fmt.Println(modules.GetGoodsFromPrice(
19 | 10000, // value price
20 | ))
21 |
22 | // Assignment 2
23 | fmt.Println()
24 | modules.Aggregator()
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/5. Assignment Week-1/modules/module-1.go:
--------------------------------------------------------------------------------
1 | package modules
2 |
3 | import "strconv"
4 |
5 | var EfisheryGoods = []map[string]int{
6 | {"Benih Lele": 50000},
7 | {"Pakan Lele Cap Menara": 25000},
8 | {"Probiotik": 75000},
9 | {"Probiotik Nila B": 10000},
10 | {"Pakan Nila": 20000},
11 | {"Benih Nila": 20000},
12 | {"Cupang": 5000},
13 | {"Benih Nila": 30000},
14 | {"Benih Cupang": 10000},
15 | {"Probiotik B": 10000},
16 | }
17 |
18 | // Function A
19 | func GoodsFromMoney(moneyUser int) []string {
20 | var result []string // array for result
21 | for _, goods := range EfisheryGoods {
22 | for key, price := range goods {
23 | if moneyUser >= price {
24 | moneyUser = moneyUser - price
25 | result = append(
26 | result,
27 | key,
28 | "-",
29 | strconv.Itoa(price),
30 | )
31 | } else {
32 | continue
33 | }
34 | }
35 | }
36 | return result
37 | }
38 |
39 | // Function B
40 | // return lowest price and highest price
41 | func LowHigh() []string {
42 | var lowestPrice int
43 | var highestPrice int
44 | var lowestGoods string
45 | var highestGoods string
46 |
47 | for _, goods := range EfisheryGoods {
48 | for key, price := range goods {
49 | if lowestPrice == 0 {
50 | lowestPrice = price
51 | lowestGoods = key
52 | }
53 | if highestPrice == 0 {
54 | highestPrice = price
55 | highestGoods = key
56 | }
57 | if lowestPrice > price {
58 | lowestPrice = price
59 | lowestGoods = key
60 | }
61 | if highestPrice < price {
62 | highestPrice = price
63 | highestGoods = key
64 | }
65 | }
66 | }
67 | var result = []string{
68 | lowestGoods + "- " + strconv.Itoa(lowestPrice),
69 | highestGoods + "- " + strconv.Itoa(highestPrice),
70 | }
71 | return result
72 | }
73 |
74 | // Function C
75 | // Getting key from EfisheryGoods that have 10000 value using for loop output array
76 | func GetGoodsFromPrice(value int) []string {
77 | var result []string
78 | for _, goods := range EfisheryGoods {
79 | for key, price := range goods {
80 | if price == value {
81 | result = append(result, key, "-", strconv.Itoa(price))
82 | }
83 | }
84 | }
85 | return result
86 | }
87 |
--------------------------------------------------------------------------------
/5. Assignment Week-1/modules/module-2.go:
--------------------------------------------------------------------------------
1 | package modules
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "io"
7 | "net/http"
8 | "time"
9 | )
10 |
11 | type Description struct {
12 | Description string `json:"description"`
13 | }
14 |
15 | type Job struct {
16 | Title string `json:"title"`
17 | WorkFrom string `json:"work_from"`
18 | Department string `json:"department"`
19 | }
20 | type Aggr struct {
21 | Jobs []Job
22 | Description
23 | }
24 |
25 | func fetchData(url string, d interface{}) error {
26 | var err error
27 | var resp *http.Response
28 | var b []byte
29 |
30 | resp, err = http.Get(url)
31 | b, err = io.ReadAll(resp.Body)
32 |
33 | err = json.Unmarshal(b, d)
34 |
35 | return err
36 | }
37 |
38 | type Caching struct {
39 | Aggr
40 | IsUsed bool
41 | }
42 |
43 | func CalculateTime(start time.Time) {
44 | fmt.Println("dari calculate ", start)
45 | fmt.Printf("took %v\n", time.Since(start))
46 | }
47 |
48 | func (c *Caching) Aggregate() (Aggr, error) {
49 | defer CalculateTime(time.Now())
50 |
51 | c.IsUsed = !c.IsUsed
52 | var err error
53 | if c.IsUsed {
54 | descChan := make(chan Description)
55 | descErrChan := make(chan error)
56 |
57 | go func(descChandescChan chan Description, descErrChan chan error) {
58 | var d Description
59 | err := fetchData("https://workspace-rho.vercel.app/api/description", &d)
60 |
61 | descChan <- d
62 | descErrChan <- err
63 | }(descChan, descErrChan)
64 |
65 | jobsChan := make(chan []Job)
66 | jobsErrChan := make(chan error)
67 | go func(jobsChan chan []Job, jobsErrChan chan error) {
68 | var j []Job
69 | err := fetchData("https://workspace-rho.vercel.app/api/jobs", &j)
70 |
71 | jobsChan <- j
72 | jobsErrChan <- err
73 | }(jobsChan, jobsErrChan)
74 |
75 | desc := <-descChan
76 | descErr := <-descErrChan
77 | jobs := <-jobsChan
78 | jobsErr := <-jobsErrChan
79 |
80 | if descErr != nil {
81 | err = descErr
82 | }
83 | if jobsErr != nil {
84 | err = jobsErr
85 | }
86 |
87 | c.Aggr = Aggr{
88 | Description: desc,
89 | Jobs: jobs,
90 | }
91 | }
92 | return c.Aggr, err
93 | }
94 |
95 | func (c *Caching) AggregateSec() (Aggr, error) {
96 | defer CalculateTime(time.Now())
97 |
98 | c.IsUsed = !c.IsUsed
99 |
100 | var err error
101 | if c.IsUsed {
102 | var d Description
103 | err = fetchData("https://workspace-rho.vercel.app/api/description", &d)
104 |
105 | var j []Job
106 | err = fetchData("https://workspace-rho.vercel.app/api/jobs", &j)
107 |
108 | c.Aggr = Aggr{
109 | Description: d,
110 | Jobs: j,
111 | }
112 | }
113 | return c.Aggr, err
114 | }
115 |
116 | // For checking input time to terminal console (for debugging)
117 | func Aggregator() {
118 | var c Caching
119 | aggr, err := c.AggregateSec()
120 | if err != nil {
121 | panic(err)
122 | }
123 |
124 | aggr, err = c.Aggregate()
125 | if err != nil {
126 | panic(err)
127 | }
128 |
129 | aggr, err = c.Aggregate()
130 | if err != nil {
131 | panic(err)
132 | }
133 |
134 | aggr, err = c.Aggregate()
135 | if err != nil {
136 | panic(err)
137 | }
138 |
139 | _ = aggr
140 | }
141 |
--------------------------------------------------------------------------------
/5. Assignment Week-1/pictures/exampleCode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/5. Assignment Week-1/pictures/exampleCode.png
--------------------------------------------------------------------------------
/5. Assignment Week-1/pictures/job-website.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/5. Assignment Week-1/pictures/job-website.png
--------------------------------------------------------------------------------
/6. API/go.mod:
--------------------------------------------------------------------------------
1 | module api
2 |
3 | go 1.19
4 |
5 | require (
6 | github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
7 | github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
8 | github.com/labstack/echo v3.3.10+incompatible // indirect
9 | github.com/labstack/echo/v4 v4.9.0 // indirect
10 | github.com/labstack/gommon v0.3.1 // indirect
11 | github.com/mattn/go-colorable v0.1.11 // indirect
12 | github.com/mattn/go-isatty v0.0.14 // indirect
13 | github.com/valyala/bytebufferpool v1.0.0 // indirect
14 | github.com/valyala/fasttemplate v1.2.1 // indirect
15 | golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
16 | golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
17 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
18 | golang.org/x/text v0.3.7 // indirect
19 | golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
20 | )
21 |
--------------------------------------------------------------------------------
/6. API/go.sum:
--------------------------------------------------------------------------------
1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3 | github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
4 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
5 | github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
6 | github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
7 | github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
8 | github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
9 | github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY=
10 | github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
11 | github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
12 | github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
13 | github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
14 | github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
15 | github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
16 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
17 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
18 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
19 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
20 | github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
21 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
22 | github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
23 | github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
24 | golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
25 | golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
26 | golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
27 | golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
28 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
29 | golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
30 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b h1:1VkfZQv42XQlA/jchYumAnv1UPo6RgF9rJFkTgZIxO4=
31 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
32 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
33 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
34 | golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
35 | golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
36 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
37 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
38 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
39 |
--------------------------------------------------------------------------------
/6. API/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | // http stateful
4 | // sedangkan lgin tuh stateless
5 | // HTTPS merupakan HTTP yang menggunakan enkripsi/sertifikat/SSL untuk mengamankan data yang dikirimkan untuk men-encrypt data yang dikirimkan ke server
6 | //
7 | // JSON merupakan salah satu alat percakapan/komunikasi antara server dan client
8 | import (
9 | "net/http"
10 | "strconv"
11 |
12 | "github.com/labstack/echo/v4"
13 | "github.com/labstack/echo/v4/middleware" // middleware
14 | )
15 |
16 | type Product struct {
17 | ID int `json:"id"`
18 | Product string `json:"product"`
19 | Description string `json:"description"`
20 | }
21 |
22 | var (
23 | product = map[int]*Product{}
24 | nomor = 1
25 | )
26 |
27 | func CreateProduct(c echo.Context) error {
28 | p := &Product{
29 | ID: nomor,
30 | }
31 | if err := c.Bind(p); err != nil {
32 | return err
33 | }
34 |
35 | product[p.ID] = p
36 | nomor++
37 | return c.JSON(http.StatusCreated, p)
38 |
39 | }
40 |
41 | func GetProducts(c echo.Context) error {
42 | id, _ := strconv.Atoi(c.Param("id"))
43 | return c.JSON(http.StatusOK, product[id])
44 | }
45 |
46 | func GetAllProducts(c echo.Context) error {
47 | return c.JSON(http.StatusOK, product)
48 | }
49 |
50 | func UpdateProduct(c echo.Context) error {
51 | p := new(Product)
52 | if err := c.Bind(p); err != nil {
53 | return err
54 | }
55 | id, _ := strconv.Atoi(c.Param("id"))
56 | product[id].Product = p.Product
57 | product[id].Description = p.Description
58 | return c.JSON(http.StatusOK, product[id])
59 | }
60 |
61 | func UpdateProductPatch(c echo.Context) error {
62 | id, _ := strconv.Atoi(c.Param("id"))
63 | p := product[id]
64 | if err := c.Bind(p); err != nil {
65 | return err
66 | }
67 | return c.JSON(http.StatusOK, p)
68 | }
69 | func DeleteUser(c echo.Context) error {
70 | id, _ := strconv.Atoi(c.Param("id"))
71 | delete(product, id)
72 | return c.NoContent(http.StatusNoContent)
73 | }
74 |
75 | func main() {
76 | // Echo instance
77 | e := echo.New()
78 |
79 | // Middleware
80 | e.Use((middleware.Logger()))
81 | e.Use(middleware.Recover())
82 |
83 | // Routes
84 | e.POST("/api/products", CreateProduct)
85 | e.GET("/api/products", GetAllProducts)
86 | e.GET("/api/products/:id", GetProducts)
87 | e.DELETE("/api/products/:id", DeleteUser)
88 | e.PUT("/api/products/:id", UpdateProduct)
89 | e.PATCH("/api/products/:id", UpdateProductPatch)
90 |
91 | // Start Server
92 | e.Logger.Fatal(e.Start(":1323"))
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/7. Clean Architecture/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 | .vscode
--------------------------------------------------------------------------------
/7. Clean Architecture/config/postgres.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "clean-architecture/entity"
5 | "fmt"
6 | "os"
7 |
8 | _ "github.com/joho/godotenv/autoload"
9 | "gorm.io/driver/postgres"
10 | "gorm.io/gorm"
11 | )
12 |
13 | var DB *gorm.DB
14 | var err error
15 |
16 | func Database() {
17 | DB, err = gorm.Open(postgres.Open(os.Getenv("db_url")), &gorm.Config{})
18 | if err != nil {
19 | panic(err)
20 | }
21 | fmt.Println("Database connected")
22 | }
23 |
24 | func Migrate() {
25 | DB.AutoMigrate(&entity.User{})
26 | }
27 |
--------------------------------------------------------------------------------
/7. Clean Architecture/entity/user.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type User struct {
4 | ID int `json:"id"`
5 | Username string `json:"username"`
6 | Email string `json:"email"`
7 | Phone string `json:"phone"`
8 | }
9 |
10 | type UserRequest struct {
11 | Username string `json:"username"`
12 | Email string `json:"email"`
13 | Phone string `json:"phone"`
14 | }
15 |
16 | type UserResponse struct {
17 | ID int `json:"id"`
18 | Username string `json:"username"`
19 | Email string `json:"email"`
20 | Phone string `json:"phone"`
21 | }
22 |
--------------------------------------------------------------------------------
/7. Clean Architecture/go.mod:
--------------------------------------------------------------------------------
1 | module clean-architecture
2 |
3 | go 1.18
4 |
5 | require (
6 | github.com/joho/godotenv v1.4.0
7 | github.com/labstack/echo/v4 v4.9.0
8 | gorm.io/driver/postgres v1.3.10
9 | gorm.io/gorm v1.23.10
10 | )
11 |
12 | require (
13 | github.com/jackc/chunkreader/v2 v2.0.1 // indirect
14 | github.com/jackc/pgconn v1.13.0 // indirect
15 | github.com/jackc/pgio v1.0.0 // indirect
16 | github.com/jackc/pgpassfile v1.0.0 // indirect
17 | github.com/jackc/pgproto3/v2 v2.3.1 // indirect
18 | github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
19 | github.com/jackc/pgtype v1.12.0 // indirect
20 | github.com/jackc/pgx/v4 v4.17.2 // indirect
21 | github.com/jinzhu/inflection v1.0.0 // indirect
22 | github.com/jinzhu/now v1.1.4 // indirect
23 | github.com/labstack/gommon v0.3.1 // indirect
24 | github.com/mattn/go-colorable v0.1.11 // indirect
25 | github.com/mattn/go-isatty v0.0.14 // indirect
26 | github.com/valyala/bytebufferpool v1.0.0 // indirect
27 | github.com/valyala/fasttemplate v1.2.1 // indirect
28 | golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
29 | golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
30 | golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
31 | golang.org/x/text v0.3.7 // indirect
32 | )
33 |
--------------------------------------------------------------------------------
/7. Clean Architecture/handler/user.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "clean-architecture/entity"
5 | "clean-architecture/usecase"
6 |
7 | "github.com/labstack/echo/v4"
8 | )
9 |
10 | type UserHandler struct {
11 | userUsecase *usecase.UserUsecase
12 | }
13 |
14 | func NewUserHandler(userUsecase *usecase.UserUsecase) *UserHandler {
15 | return &UserHandler{userUsecase}
16 | }
17 |
18 | func (handler UserHandler) CreateUser(c echo.Context) error {
19 | req := entity.UserRequest{}
20 | if err := c.Bind(&req); err != nil {
21 | return err
22 | }
23 | user, err := handler.userUsecase.CreateUser(req)
24 | if err != nil {
25 | return err
26 | }
27 | return c.JSON(201, user)
28 | }
29 |
--------------------------------------------------------------------------------
/7. Clean Architecture/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "clean-architecture/config"
5 | "clean-architecture/handler"
6 | "clean-architecture/repository"
7 | "clean-architecture/routes"
8 | "clean-architecture/usecase"
9 |
10 | "github.com/labstack/echo/v4"
11 | )
12 |
13 | // what the actual fuck is this.
14 | func main() {
15 | config.Database()
16 | config.Migrate()
17 |
18 | e := echo.New()
19 |
20 | userRepository := repository.NewUserRepository(config.DB)
21 | userUsecase := usecase.NewUserUsecase(userRepository)
22 | UserHandler := handler.NewUserHandler(userUsecase)
23 |
24 | routes.Routes(e, UserHandler)
25 |
26 | e.Logger.Fatal(e.Start(":8080"))
27 | }
28 |
--------------------------------------------------------------------------------
/7. Clean Architecture/repository/user.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | "clean-architecture/entity"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type IUserRepository interface {
10 | Store(user entity.User) (entity.User, error)
11 | }
12 | type UserRepository struct {
13 | db *gorm.DB
14 | }
15 |
16 | func NewUserRepository(db *gorm.DB) IUserRepository {
17 | return &UserRepository{db}
18 | }
19 | func (r UserRepository) Store(user entity.User) (entity.User, error) {
20 | if err := r.db.Debug().Create(&user).Error; err != nil {
21 | }
22 | return user, nil
23 | }
24 |
--------------------------------------------------------------------------------
/7. Clean Architecture/routes/user.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | "clean-architecture/handler"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func Routes(e *echo.Echo, userHandler *handler.UserHandler) {
10 | e.POST("/users", userHandler.CreateUser)
11 | }
12 |
--------------------------------------------------------------------------------
/7. Clean Architecture/usecase/user.go:
--------------------------------------------------------------------------------
1 | package usecase
2 |
3 | import (
4 | "clean-architecture/entity"
5 | "clean-architecture/repository"
6 | )
7 |
8 | type IUserUsecase interface {
9 | CreateUser(user entity.UserRequest) (entity.User, error)
10 | }
11 | type UserUsecase struct {
12 | userRepository repository.IUserRepository
13 | }
14 |
15 | func NewUserUsecase(userRepository repository.IUserRepository) *UserUsecase {
16 | return &UserUsecase{userRepository}
17 | }
18 | func (usecase UserUsecase) CreateUser(user entity.UserRequest) (entity.UserResponse, error) {
19 | u := entity.User{
20 | Username: user.Username,
21 | Email: user.Email,
22 | Phone: user.Phone,
23 | }
24 |
25 | users, err := usecase.userRepository.Store(u)
26 | if err != nil {
27 | return entity.UserResponse{}, err
28 | }
29 | userRes := entity.UserResponse{
30 | ID: users.ID,
31 | Username: users.Username,
32 | Email: users.Email,
33 | Phone: users.Phone,
34 | }
35 | return userRes, nil
36 | }
37 |
--------------------------------------------------------------------------------
/7.1. Exercise Clean Architecture/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | .env
3 | # .gitignore
--------------------------------------------------------------------------------
/7.1. Exercise Clean Architecture/config/postgres.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "exercise-clean-architecture/entity"
5 | "fmt"
6 | "os"
7 |
8 | _ "github.com/joho/godotenv/autoload"
9 | "gorm.io/driver/postgres"
10 | "gorm.io/gorm"
11 | )
12 |
13 | var DB *gorm.DB
14 | var err error
15 |
16 | func Connect() {
17 | DB, err = gorm.Open(postgres.Open(os.Getenv("db_url")), &gorm.Config{})
18 | if err != nil {
19 | panic(err)
20 | }
21 | fmt.Println("Database connected")
22 | }
23 |
24 | func Migrate() {
25 | DB.AutoMigrate(&entity.User{})
26 | }
27 |
--------------------------------------------------------------------------------
/7.1. Exercise Clean Architecture/entity/user.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | import (
4 | "time"
5 | )
6 |
7 | type User struct {
8 | ID int `json:"id"`
9 | UUID string `json:"uuid"`
10 | FirstName string `json:"first_name"`
11 | LastName string `json:"last_name"`
12 | Username string `json:"username"`
13 | Email string `json:"email"`
14 | Password string `json:"password" `
15 | Phone string `json:"phone"`
16 | Role string `json:"role"`
17 | CreatedAt time.Time `json:"created_at"`
18 | ModifiedAt time.Time `json:"modified_at"`
19 | }
20 |
21 | type CreateUserRequest struct {
22 | FirstName string `json:"first_name"`
23 | LastName string `json:"last_name"`
24 | Username string `json:"username"`
25 | Email string `json:"email"`
26 | Password string `json:"password"`
27 | Phone string `json:"phone"`
28 | }
29 |
30 | type UpdateUserRequest struct {
31 | FirstName string `json:"first_name"`
32 | LastName string `json:"last_name"`
33 | Username string `json:"username"`
34 | Email string `json:"email"`
35 | Phone string `json:"phone"`
36 | Password string `json:"password"`
37 | }
38 | type UserResponse struct {
39 | ID int `json:"id"`
40 | UUID string `json:"uuid"`
41 | FirstName string `json:"first_name"`
42 | LastName string `json:"last_name"`
43 | Username string `json:"username"`
44 | Email string `json:"email"`
45 | Role string `json:"role"`
46 | Phone string `json:"phone"`
47 | }
48 |
--------------------------------------------------------------------------------
/7.1. Exercise Clean Architecture/go.mod:
--------------------------------------------------------------------------------
1 | module exercise-clean-architecture
2 |
3 | go 1.18
4 |
5 | require (
6 | github.com/jackc/chunkreader/v2 v2.0.1 // indirect
7 | github.com/jackc/pgconn v1.13.0 // indirect
8 | github.com/jackc/pgio v1.0.0 // indirect
9 | github.com/jackc/pgpassfile v1.0.0 // indirect
10 | github.com/jackc/pgproto3/v2 v2.3.1 // indirect
11 | github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
12 | github.com/jackc/pgtype v1.12.0 // indirect
13 | github.com/jackc/pgx/v4 v4.17.2 // indirect
14 | github.com/jinzhu/inflection v1.0.0 // indirect
15 | github.com/jinzhu/now v1.1.4 // indirect
16 | github.com/joho/godotenv v1.4.0 // indirect
17 | github.com/labstack/echo/v4 v4.9.0 // indirect
18 | github.com/labstack/gommon v0.3.1 // indirect
19 | github.com/mattn/go-colorable v0.1.11 // indirect
20 | github.com/mattn/go-isatty v0.0.14 // indirect
21 | github.com/valyala/bytebufferpool v1.0.0 // indirect
22 | github.com/valyala/fasttemplate v1.2.1 // indirect
23 | golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
24 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
25 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
26 | golang.org/x/text v0.3.7 // indirect
27 | gorm.io/driver/postgres v1.3.10 // indirect
28 | gorm.io/gorm v1.23.10 // indirect
29 | )
30 |
--------------------------------------------------------------------------------
/7.1. Exercise Clean Architecture/handler/user.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "exercise-clean-architecture/entity"
5 | "exercise-clean-architecture/usecase"
6 |
7 | "github.com/labstack/echo/v4"
8 | )
9 |
10 | type UserHandler struct {
11 | userUsecase *usecase.UserUsecase
12 | }
13 |
14 | func NewUserHandler(userUsecase *usecase.UserUsecase) *UserHandler {
15 | return &UserHandler{userUsecase}
16 | }
17 |
18 | func (handler UserHandler) CreateUser(c echo.Context) error {
19 | req := entity.CreateUserRequest{}
20 | if err := c.Bind(&req); err != nil {
21 | return err
22 | }
23 | user, err := handler.userUsecase.CreateUser(req)
24 | if err != nil {
25 | return err
26 | }
27 | return c.JSON(201, user)
28 | }
29 |
30 | func (handler UserHandler) GetAllUser(c echo.Context) error {
31 | users, err := handler.userUsecase.GetAllUser()
32 | if err != nil {
33 | return c.JSON(500, err)
34 | }
35 | if len(users) == 0 {
36 | return c.JSON(404, "No data found")
37 | }
38 | return c.JSON(200, users)
39 | }
40 |
41 | func (handler UserHandler) GetUserByUUID(c echo.Context) error {
42 | users, err := handler.userUsecase.GetUserByUUID(c.Param("uuid"))
43 | if err != nil {
44 | return c.JSON(500, err)
45 | }
46 | if users.UUID == "" {
47 | return c.JSON(404, "No data found")
48 | }
49 | return c.JSON(200, users)
50 | }
51 |
52 | func (handler UserHandler) UpdateUserByUUID(c echo.Context) error {
53 | req := entity.UpdateUserRequest{}
54 | if err := c.Bind(&req); err != nil {
55 | return err
56 | }
57 | user, err := handler.userUsecase.UpdateUserByUUID(req, c.Param("uuid"))
58 | if err != nil {
59 | return err
60 | }
61 | return c.JSON(200, user)
62 | }
63 |
64 | func (handler UserHandler) DeleteUserByUUID(c echo.Context) error {
65 | err := handler.userUsecase.DeleteUserByUUID(c.Param("uuid"))
66 | if err != nil {
67 | return c.JSON(500, err)
68 | }
69 | return c.JSON(200, "Data has been deleted")
70 | }
71 |
--------------------------------------------------------------------------------
/7.1. Exercise Clean Architecture/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "exercise-clean-architecture/config"
5 | "exercise-clean-architecture/handler"
6 | "exercise-clean-architecture/repository"
7 | "exercise-clean-architecture/routes"
8 | "exercise-clean-architecture/usecase"
9 |
10 | "github.com/labstack/echo/v4"
11 | )
12 |
13 | func main() {
14 | config.Connect()
15 | config.Migrate()
16 |
17 | e := echo.New()
18 |
19 | userRepository := repository.NewUserRepository(config.DB)
20 | userUsecase := usecase.NewUserUsecase(userRepository)
21 | UserHandler := handler.NewUserHandler(userUsecase)
22 |
23 | routes.Routes(e, UserHandler)
24 |
25 | e.Logger.Fatal(e.Start(":8080"))
26 | }
27 |
--------------------------------------------------------------------------------
/7.1. Exercise Clean Architecture/repository/user.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | "exercise-clean-architecture/entity"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceUserRepository interface {
10 | Store(user entity.User) (entity.User, error)
11 | FindAll() ([]entity.User, error)
12 | FindByUUID(uuid string) (entity.User, error)
13 | UpdateUserByUUID(user entity.User) (entity.User, error)
14 | DeleteUserByUUID(uuid string) error
15 | }
16 | type UserRepository struct {
17 | db *gorm.DB
18 | }
19 |
20 | func NewUserRepository(db *gorm.DB) InterfaceUserRepository {
21 | return &UserRepository{db}
22 | }
23 |
24 | // Storing data to database
25 | func (r UserRepository) Store(user entity.User) (entity.User, error) {
26 | if err := r.db.Debug().Create(&user).Error; err != nil {
27 | return entity.User{}, err
28 | }
29 | return user, nil
30 | }
31 |
32 | // Read data from database
33 | func (r UserRepository) FindAll() ([]entity.User, error) {
34 | var users []entity.User
35 | if err := r.db.Debug().Find(&users).Error; err != nil {
36 | return nil, err
37 | }
38 | return users, nil
39 | }
40 |
41 | // Find user using uuid from database
42 | func (r UserRepository) FindByUUID(uuid string) (entity.User, error) {
43 | var user entity.User
44 | if err := r.db.Debug().Where("uuid = ?", uuid).First(&user).Error; err != nil {
45 | return entity.User{}, err
46 | }
47 | return user, nil
48 | }
49 |
50 | // Update user data using uuid from database
51 | func (r UserRepository) UpdateUserByUUID(user entity.User) (entity.User, error) {
52 | if err := r.db.Debug().Save(&user).Error; err != nil {
53 | return entity.User{}, err
54 | }
55 | return user, nil
56 | }
57 |
58 | // Delete user data using uuid from database
59 | func (r UserRepository) DeleteUserByUUID(uuid string) error {
60 | if err := r.db.Debug().Where("uuid = ?", uuid).Delete(&entity.User{}).Error; err != nil {
61 | return err
62 | }
63 | return nil
64 | }
65 |
--------------------------------------------------------------------------------
/7.1. Exercise Clean Architecture/routes/user.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | "exercise-clean-architecture/handler"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func Routes(e *echo.Echo, userHandler *handler.UserHandler) {
10 | e.POST("/users", userHandler.CreateUser)
11 | e.GET("/users", userHandler.GetAllUser)
12 | e.GET("/users/:uuid", userHandler.GetUserByUUID)
13 | e.PUT("/users/:uuid", userHandler.UpdateUserByUUID)
14 | e.DELETE("/users/:uuid", userHandler.DeleteUserByUUID)
15 | }
16 |
--------------------------------------------------------------------------------
/7.1. Exercise Clean Architecture/usecase/user.go:
--------------------------------------------------------------------------------
1 | package usecase
2 |
3 | import (
4 | "exercise-clean-architecture/entity"
5 | "exercise-clean-architecture/repository"
6 |
7 | "github.com/google/uuid"
8 | )
9 |
10 | type InterfaceUserUsercase interface {
11 | CreateUser(user entity.CreateUserRequest) (entity.User, error)
12 | GetAllUser() ([]entity.User, error)
13 | GetUserByUUID(uuid string) (entity.User, error)
14 | UpdateUserByUUID(userRequest entity.UpdateUserRequest, uuid string) (entity.User, error)
15 | DeleteUserByUUID(uuid string) error
16 | }
17 |
18 | type UserUsecase struct {
19 | userRepository repository.InterfaceUserRepository
20 | }
21 |
22 | func NewUserUsecase(userRepository repository.InterfaceUserRepository) *UserUsecase {
23 | return &UserUsecase{userRepository}
24 |
25 | }
26 |
27 | func (usecase UserUsecase) CreateUser(user entity.CreateUserRequest) (entity.UserResponse, error) {
28 | // passwordHash, err := config.HashPassword(user.Password)
29 | // if err != nil {
30 | // return entity.UserResponse{}, err
31 | // }
32 | // user.Password = passwordHash
33 |
34 | uuidNew := uuid.New().String()
35 | u := entity.User{
36 | UUID: uuidNew,
37 | FirstName: user.FirstName,
38 | LastName: user.LastName,
39 | Username: user.Username,
40 | Email: user.Email,
41 | Password: user.Password,
42 | Phone: user.Phone,
43 | }
44 |
45 | users, err := usecase.userRepository.Store(u)
46 | if err != nil {
47 | return entity.UserResponse{}, err
48 | }
49 | userRes := entity.UserResponse{
50 | ID: users.ID,
51 | UUID: users.UUID,
52 | Username: users.Username,
53 | Email: users.Email,
54 | Phone: users.Phone,
55 | FirstName: users.FirstName,
56 | LastName: users.LastName,
57 | }
58 |
59 | return userRes, nil
60 | }
61 |
62 | func (usecase UserUsecase) GetAllUser() ([]entity.UserResponse, error) {
63 | users, err := usecase.userRepository.FindAll()
64 | if err != nil {
65 | return nil, err
66 | }
67 | userRes := []entity.UserResponse{}
68 | for _, user := range users {
69 | userRes = append(userRes, entity.UserResponse{
70 | ID: user.ID,
71 | UUID: user.UUID,
72 | Username: user.Username,
73 | Email: user.Email,
74 | Phone: user.Phone,
75 | FirstName: user.FirstName,
76 | LastName: user.LastName,
77 | })
78 | }
79 |
80 | return userRes, nil
81 |
82 | }
83 |
84 | func (usecase UserUsecase) GetUserByUUID(uuid string) (entity.UserResponse, error) {
85 | user, err := usecase.userRepository.FindByUUID(uuid)
86 | if err != nil {
87 | return entity.UserResponse{}, err
88 | }
89 | userRes := entity.UserResponse{
90 | ID: user.ID,
91 | UUID: user.UUID,
92 | Username: user.Username,
93 | Email: user.Email,
94 | Phone: user.Phone,
95 | FirstName: user.FirstName,
96 | LastName: user.LastName,
97 | }
98 | return userRes, nil
99 | }
100 |
101 | func (usecase UserUsecase) UpdateUserByUUID(userRequest entity.UpdateUserRequest, uuid string) (entity.UserResponse, error) {
102 | user, err := usecase.userRepository.FindByUUID(uuid)
103 | if err != nil {
104 | return entity.UserResponse{}, err
105 | }
106 |
107 | dataUser := entity.User{
108 | ID: user.ID,
109 | UUID: user.UUID,
110 | FirstName: userRequest.FirstName,
111 | LastName: userRequest.LastName,
112 | Username: userRequest.Username,
113 | Email: userRequest.Email,
114 | Password: userRequest.Password,
115 | Phone: userRequest.Phone,
116 | }
117 |
118 | user, err = usecase.userRepository.UpdateUserByUUID(dataUser)
119 | if err != nil {
120 | return entity.UserResponse{}, err
121 | }
122 |
123 | userRes := entity.UserResponse{
124 | ID: user.ID,
125 | UUID: user.UUID,
126 | Username: user.Username,
127 | Email: user.Email,
128 | Phone: user.Phone,
129 | FirstName: user.FirstName,
130 | LastName: user.LastName,
131 | }
132 | return userRes, nil
133 | }
134 |
135 | func (usecase UserUsecase) DeleteUserByUUID(uuid string) error {
136 | err := usecase.userRepository.DeleteUserByUUID(uuid)
137 | if err != nil {
138 | return err
139 | }
140 | return nil
141 | }
142 |
--------------------------------------------------------------------------------
/8. Docker Example in Class/Dockerfile:
--------------------------------------------------------------------------------
1 |
2 | # Bikin dockerfile untuk membuat image
3 | # stage 1 making the app
4 | FROM golang:alpine AS builder
5 |
6 | #BUILD
7 | COPY . /app
8 | WORKDIR /app
9 | RUN apk update \
10 | && apk upgrade \
11 | && apk add --no-cache \
12 | ca-certificates \
13 | && update-ca-certificates 2>/dev/null || true
14 | RUN mkdir app && \
15 | mkdir app/resources && \
16 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o /app/echo
17 | RUN ls app
18 |
19 | # step 2 running the app
20 | # SERVE
21 | FROM busybox
22 |
23 | COPY --from=builder /app/ /app
24 | WORKDIR /app
25 | EXPOSE 1323
26 | CMD ["./echo"]
--------------------------------------------------------------------------------
/8. Docker Example in Class/go.mod:
--------------------------------------------------------------------------------
1 | module go-echo
2 |
3 | go 1.18
4 |
5 | require (
6 | github.com/labstack/echo/v4 v4.9.0 // indirect
7 | github.com/labstack/gommon v0.3.1 // indirect
8 | github.com/mattn/go-colorable v0.1.11 // indirect
9 | github.com/mattn/go-isatty v0.0.14 // indirect
10 | github.com/valyala/bytebufferpool v1.0.0 // indirect
11 | github.com/valyala/fasttemplate v1.2.1 // indirect
12 | golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
13 | golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
14 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
15 | golang.org/x/text v0.3.7 // indirect
16 | )
17 |
--------------------------------------------------------------------------------
/8. Docker Example in Class/go.sum:
--------------------------------------------------------------------------------
1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3 | github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY=
4 | github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
5 | github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
6 | github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
7 | github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
8 | github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
9 | github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
10 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
11 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
13 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
14 | github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
15 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
16 | github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
17 | github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
18 | golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
19 | golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
20 | golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY=
21 | golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
22 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
23 | golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
24 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b h1:1VkfZQv42XQlA/jchYumAnv1UPo6RgF9rJFkTgZIxO4=
25 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
26 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
27 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
28 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
29 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
30 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
31 |
--------------------------------------------------------------------------------
/8. Docker Example in Class/nomad.hcl:
--------------------------------------------------------------------------------
1 | job "hakim-echo" {
2 | datacenters = ["dc1"]
3 | type = "service"
4 |
5 | group "web" {
6 | count = 1
7 |
8 | network {
9 | port "http" {
10 | to = 1323
11 | }
12 | }
13 |
14 | task "hakim-echo" {
15 | driver = "docker"
16 |
17 | config {
18 | image = "hkimm/go-echo:v1"
19 | ports = ["http"]
20 | }
21 |
22 | resources {
23 | cpu = 100
24 | memory = 128
25 | }
26 | }
27 |
28 | service {
29 | name = "hakim-echo"
30 | port = "http"
31 | tags = [
32 | "traefik.enable=true",
33 | "traefik.http.routers.hakim-echo-demo.rule=Host(\"hakim.cupang.efishery.ai\")",
34 | ]
35 | check {
36 | port = "http"
37 | type = "tcp"
38 | interval = "15s"
39 | timeout = "14s"
40 | }
41 | }
42 |
43 | }
44 | }
--------------------------------------------------------------------------------
/8. Docker Example in Class/server.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "net/http"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func main() {
10 | e := echo.New()
11 | e.GET("/", func(c echo.Context) error {
12 | return c.String(http.StatusOK, "Hello, World!")
13 | })
14 | e.Logger.Fatal(e.Start(":1323"))
15 | }
16 |
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | .env
3 | # .gitignore
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/Dockerfile:
--------------------------------------------------------------------------------
1 |
2 | # Bikin dockerfile untuk membuat image
3 | # stage 1 making the app
4 | FROM golang:alpine AS builder
5 |
6 | #BUILD
7 | COPY . /app
8 | WORKDIR /app
9 | RUN apk update \
10 | && apk upgrade \
11 | && apk add --no-cache \
12 | ca-certificates \
13 | && update-ca-certificates 2>/dev/null || true
14 | RUN mkdir app && \
15 | mkdir app/resources && \
16 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o /app/echo
17 | RUN ls app
18 |
19 | # step 2 running the app
20 | # SERVE
21 | FROM busybox
22 |
23 | COPY --from=builder /app/ /app
24 | WORKDIR /app
25 | EXPOSE 1323
26 | CMD ["./echo"]
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/config/postgres.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "exercise-clean-architecture/entity"
5 | "fmt"
6 | "os"
7 |
8 | _ "github.com/joho/godotenv/autoload"
9 | "gorm.io/driver/postgres"
10 | "gorm.io/gorm"
11 | )
12 |
13 | var DB *gorm.DB
14 | var err error
15 |
16 | func Connect() {
17 | DB, err = gorm.Open(postgres.Open(os.Getenv("db_url")), &gorm.Config{})
18 | if err != nil {
19 | panic(err)
20 | }
21 | fmt.Println("Database connected")
22 | }
23 |
24 | func Migrate() {
25 | DB.AutoMigrate(&entity.User{})
26 | }
27 |
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/entity/user.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | import (
4 | "time"
5 | )
6 |
7 | type User struct {
8 | ID int `json:"id"`
9 | UUID string `json:"uuid"`
10 | FirstName string `json:"first_name"`
11 | LastName string `json:"last_name"`
12 | Username string `json:"username"`
13 | Email string `json:"email"`
14 | Password string `json:"password" `
15 | Phone string `json:"phone"`
16 | Role string `json:"role"`
17 | CreatedAt time.Time `json:"created_at"`
18 | ModifiedAt time.Time `json:"modified_at"`
19 | }
20 |
21 | type CreateUserRequest struct {
22 | FirstName string `json:"first_name"`
23 | LastName string `json:"last_name"`
24 | Username string `json:"username"`
25 | Email string `json:"email"`
26 | Password string `json:"password"`
27 | Phone string `json:"phone"`
28 | }
29 |
30 | type UpdateUserRequest struct {
31 | FirstName string `json:"first_name"`
32 | LastName string `json:"last_name"`
33 | Username string `json:"username"`
34 | Email string `json:"email"`
35 | Phone string `json:"phone"`
36 | Password string `json:"password"`
37 | }
38 | type UserResponse struct {
39 | ID int `json:"id"`
40 | UUID string `json:"uuid"`
41 | FirstName string `json:"first_name"`
42 | LastName string `json:"last_name"`
43 | Username string `json:"username"`
44 | Email string `json:"email"`
45 | Role string `json:"role"`
46 | Phone string `json:"phone"`
47 | }
48 |
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/go.mod:
--------------------------------------------------------------------------------
1 | module exercise-clean-architecture
2 |
3 | go 1.18
4 |
5 | require (
6 | github.com/google/uuid v1.3.0
7 | github.com/joho/godotenv v1.4.0
8 | github.com/labstack/echo/v4 v4.9.0
9 | golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
10 | gorm.io/driver/postgres v1.3.10
11 | gorm.io/gorm v1.23.10
12 | )
13 |
14 | require (
15 | github.com/jackc/chunkreader/v2 v2.0.1 // indirect
16 | github.com/jackc/pgconn v1.13.0 // indirect
17 | github.com/jackc/pgio v1.0.0 // indirect
18 | github.com/jackc/pgpassfile v1.0.0 // indirect
19 | github.com/jackc/pgproto3/v2 v2.3.1 // indirect
20 | github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
21 | github.com/jackc/pgtype v1.12.0 // indirect
22 | github.com/jackc/pgx/v4 v4.17.2 // indirect
23 | github.com/jinzhu/inflection v1.0.0 // indirect
24 | github.com/jinzhu/now v1.1.4 // indirect
25 | github.com/labstack/gommon v0.3.1 // indirect
26 | github.com/mattn/go-colorable v0.1.11 // indirect
27 | github.com/mattn/go-isatty v0.0.14 // indirect
28 | github.com/valyala/bytebufferpool v1.0.0 // indirect
29 | github.com/valyala/fasttemplate v1.2.1 // indirect
30 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
31 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
32 | golang.org/x/text v0.3.7 // indirect
33 | )
34 |
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/handler/user.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "exercise-clean-architecture/entity"
5 | "exercise-clean-architecture/usecase"
6 |
7 | "github.com/labstack/echo/v4"
8 | )
9 |
10 | type UserHandler struct {
11 | userUsecase *usecase.UserUsecase
12 | }
13 |
14 | func NewUserHandler(userUsecase *usecase.UserUsecase) *UserHandler {
15 | return &UserHandler{userUsecase}
16 | }
17 |
18 | func (handler UserHandler) CreateUser(c echo.Context) error {
19 | req := entity.CreateUserRequest{}
20 | if err := c.Bind(&req); err != nil {
21 | return err
22 | }
23 | user, err := handler.userUsecase.CreateUser(req)
24 | if err != nil {
25 | return err
26 | }
27 | return c.JSON(201, user)
28 | }
29 |
30 | func (handler UserHandler) GetAllUser(c echo.Context) error {
31 | users, err := handler.userUsecase.GetAllUser()
32 | if err != nil {
33 | return c.JSON(500, err)
34 | }
35 | if len(users) == 0 {
36 | return c.JSON(404, "No data found")
37 | }
38 | return c.JSON(200, users)
39 | }
40 |
41 | func (handler UserHandler) GetUserByUUID(c echo.Context) error {
42 | users, err := handler.userUsecase.GetUserByUUID(c.Param("uuid"))
43 | if err != nil {
44 | return c.JSON(500, err)
45 | }
46 | if users.UUID == "" {
47 | return c.JSON(404, "No data found")
48 | }
49 | return c.JSON(200, users)
50 | }
51 |
52 | func (handler UserHandler) UpdateUserByUUID(c echo.Context) error {
53 | req := entity.UpdateUserRequest{}
54 | if err := c.Bind(&req); err != nil {
55 | return err
56 | }
57 | user, err := handler.userUsecase.UpdateUserByUUID(req, c.Param("uuid"))
58 | if err != nil {
59 | return err
60 | }
61 | return c.JSON(200, user)
62 | }
63 |
64 | func (handler UserHandler) DeleteUserByUUID(c echo.Context) error {
65 | err := handler.userUsecase.DeleteUserByUUID(c.Param("uuid"))
66 | if err != nil {
67 | return c.JSON(500, err)
68 | }
69 | return c.JSON(200, "Data has been deleted")
70 | }
71 |
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/repository/user.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | "exercise-clean-architecture/entity"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceUserRepository interface {
10 | Store(user entity.User) (entity.User, error)
11 | FindAll() ([]entity.User, error)
12 | FindByUUID(uuid string) (entity.User, error)
13 | UpdateUserByUUID(user entity.User) (entity.User, error)
14 | DeleteUserByUUID(uuid string) error
15 | }
16 | type UserRepository struct {
17 | db *gorm.DB
18 | }
19 |
20 | func NewUserRepository(db *gorm.DB) InterfaceUserRepository {
21 | return &UserRepository{db}
22 | }
23 |
24 | // Storing data to database
25 | func (r UserRepository) Store(user entity.User) (entity.User, error) {
26 | if err := r.db.Debug().Create(&user).Error; err != nil {
27 | return entity.User{}, err
28 | }
29 | return user, nil
30 | }
31 |
32 | // Read data from database
33 | func (r UserRepository) FindAll() ([]entity.User, error) {
34 | var users []entity.User
35 | if err := r.db.Debug().Find(&users).Error; err != nil {
36 | return nil, err
37 | }
38 | return users, nil
39 | }
40 |
41 | // Find user using uuid from database
42 | func (r UserRepository) FindByUUID(uuid string) (entity.User, error) {
43 | var user entity.User
44 | if err := r.db.Debug().Where("uuid = ?", uuid).First(&user).Error; err != nil {
45 | return entity.User{}, err
46 | }
47 | return user, nil
48 | }
49 |
50 | // Update user data using uuid from database
51 | func (r UserRepository) UpdateUserByUUID(user entity.User) (entity.User, error) {
52 | if err := r.db.Debug().Save(&user).Error; err != nil {
53 | return entity.User{}, err
54 | }
55 | return user, nil
56 | }
57 |
58 | // Delete user data using uuid from database
59 | func (r UserRepository) DeleteUserByUUID(uuid string) error {
60 | if err := r.db.Debug().Where("uuid = ?", uuid).Delete(&entity.User{}).Error; err != nil {
61 | return err
62 | }
63 | return nil
64 | }
65 |
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/routes/user.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | "exercise-clean-architecture/handler"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func Routes(e *echo.Echo, userHandler *handler.UserHandler) {
10 | e.POST("/users", userHandler.CreateUser)
11 | e.GET("/users", userHandler.GetAllUser)
12 | e.GET("/users/:uuid", userHandler.GetUserByUUID)
13 | e.PUT("/users/:uuid", userHandler.UpdateUserByUUID)
14 | e.DELETE("/users/:uuid", userHandler.DeleteUserByUUID)
15 | }
16 |
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/server.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "exercise-clean-architecture/config"
5 | "exercise-clean-architecture/handler"
6 | "exercise-clean-architecture/repository"
7 | "exercise-clean-architecture/routes"
8 | "exercise-clean-architecture/usecase"
9 |
10 | "github.com/labstack/echo/v4"
11 | )
12 |
13 | func main() {
14 | config.Connect()
15 | config.Migrate()
16 |
17 | e := echo.New()
18 |
19 | userRepository := repository.NewUserRepository(config.DB)
20 | userUsecase := usecase.NewUserUsecase(userRepository)
21 | UserHandler := handler.NewUserHandler(userUsecase)
22 |
23 | routes.Routes(e, UserHandler)
24 |
25 | e.Logger.Fatal(e.Start(":8080"))
26 | }
27 |
--------------------------------------------------------------------------------
/8.1. Cloud Native and Infrastructure/usecase/user.go:
--------------------------------------------------------------------------------
1 | package usecase
2 |
3 | import (
4 | "exercise-clean-architecture/entity"
5 | "exercise-clean-architecture/repository"
6 |
7 | "github.com/google/uuid"
8 | )
9 |
10 | type InterfaceUserUsercase interface {
11 | CreateUser(user entity.CreateUserRequest) (entity.User, error)
12 | GetAllUser() ([]entity.User, error)
13 | GetUserByUUID(uuid string) (entity.User, error)
14 | UpdateUserByUUID(userRequest entity.UpdateUserRequest, uuid string) (entity.User, error)
15 | DeleteUserByUUID(uuid string) error
16 | }
17 |
18 | type UserUsecase struct {
19 | userRepository repository.InterfaceUserRepository
20 | }
21 |
22 | func NewUserUsecase(userRepository repository.InterfaceUserRepository) *UserUsecase {
23 | return &UserUsecase{userRepository}
24 |
25 | }
26 |
27 | func (usecase UserUsecase) CreateUser(user entity.CreateUserRequest) (entity.UserResponse, error) {
28 | // passwordHash, err := config.HashPassword(user.Password)
29 | // if err != nil {
30 | // return entity.UserResponse{}, err
31 | // }
32 | // user.Password = passwordHash
33 |
34 | uuidNew := uuid.New().String()
35 | u := entity.User{
36 | UUID: uuidNew,
37 | FirstName: user.FirstName,
38 | LastName: user.LastName,
39 | Username: user.Username,
40 | Email: user.Email,
41 | Password: user.Password,
42 | Phone: user.Phone,
43 | }
44 |
45 | users, err := usecase.userRepository.Store(u)
46 | if err != nil {
47 | return entity.UserResponse{}, err
48 | }
49 | userRes := entity.UserResponse{
50 | ID: users.ID,
51 | UUID: users.UUID,
52 | Username: users.Username,
53 | Email: users.Email,
54 | Phone: users.Phone,
55 | FirstName: users.FirstName,
56 | LastName: users.LastName,
57 | }
58 |
59 | return userRes, nil
60 | }
61 |
62 | func (usecase UserUsecase) GetAllUser() ([]entity.UserResponse, error) {
63 | users, err := usecase.userRepository.FindAll()
64 | if err != nil {
65 | return nil, err
66 | }
67 | userRes := []entity.UserResponse{}
68 | for _, user := range users {
69 | userRes = append(userRes, entity.UserResponse{
70 | ID: user.ID,
71 | UUID: user.UUID,
72 | Username: user.Username,
73 | Email: user.Email,
74 | Phone: user.Phone,
75 | FirstName: user.FirstName,
76 | LastName: user.LastName,
77 | })
78 | }
79 |
80 | return userRes, nil
81 |
82 | }
83 |
84 | func (usecase UserUsecase) GetUserByUUID(uuid string) (entity.UserResponse, error) {
85 | user, err := usecase.userRepository.FindByUUID(uuid)
86 | if err != nil {
87 | return entity.UserResponse{}, err
88 | }
89 | userRes := entity.UserResponse{
90 | ID: user.ID,
91 | UUID: user.UUID,
92 | Username: user.Username,
93 | Email: user.Email,
94 | Phone: user.Phone,
95 | FirstName: user.FirstName,
96 | LastName: user.LastName,
97 | }
98 | return userRes, nil
99 | }
100 |
101 | func (usecase UserUsecase) UpdateUserByUUID(userRequest entity.UpdateUserRequest, uuid string) (entity.UserResponse, error) {
102 | user, err := usecase.userRepository.FindByUUID(uuid)
103 | if err != nil {
104 | return entity.UserResponse{}, err
105 | }
106 |
107 | dataUser := entity.User{
108 | ID: user.ID,
109 | UUID: user.UUID,
110 | FirstName: userRequest.FirstName,
111 | LastName: userRequest.LastName,
112 | Username: userRequest.Username,
113 | Email: userRequest.Email,
114 | Password: userRequest.Password,
115 | Phone: userRequest.Phone,
116 | }
117 |
118 | user, err = usecase.userRepository.UpdateUserByUUID(dataUser)
119 | if err != nil {
120 | return entity.UserResponse{}, err
121 | }
122 |
123 | userRes := entity.UserResponse{
124 | ID: user.ID,
125 | UUID: user.UUID,
126 | Username: user.Username,
127 | Email: user.Email,
128 | Phone: user.Phone,
129 | FirstName: user.FirstName,
130 | LastName: user.LastName,
131 | }
132 | return userRes, nil
133 | }
134 |
135 | func (usecase UserUsecase) DeleteUserByUUID(uuid string) error {
136 | err := usecase.userRepository.DeleteUserByUUID(uuid)
137 | if err != nil {
138 | return err
139 | }
140 | return nil
141 | }
142 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | .env
3 | postgres
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/Dockerfile:
--------------------------------------------------------------------------------
1 | # Start from golang base image
2 | FROM golang:alpine as builder
3 |
4 | # Enable go modules
5 | ENV GO111MODULE=on
6 |
7 | # Install git. (alpine image does not have git in it)
8 | RUN apk update && apk add --no-cache git
9 |
10 | # Set current working directory
11 | WORKDIR /app
12 |
13 | # Note here: To avoid downloading dependencies every time we
14 | # build image. Here, we are caching all the dependencies by
15 | # first copying go.mod and go.sum files and downloading them,
16 | # to be used every time we build the image if the dependencies
17 | # are not changed.
18 |
19 | # Copy go mod and sum files
20 | COPY go.mod ./
21 | COPY go.sum ./
22 |
23 | # Download all dependencies.
24 | RUN go mod download
25 |
26 | # Now, copy the source code
27 | COPY . .
28 |
29 | # Note here: CGO_ENABLED is disabled for cross system compilation
30 | # It is also a common best practise.
31 |
32 | # Build the application.
33 | RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/main .
34 |
35 | # Finally our multi-stage to build a small image
36 | # Start a new stage from scratch
37 | FROM scratch
38 |
39 | # Copy the Pre-built binary file
40 | COPY --from=builder /app/bin/main .
41 |
42 | # Run executable
43 | CMD ["./main"]
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/README.md:
--------------------------------------------------------------------------------
1 | # eFishery Warehouse Management System
2 |
3 | # 1. Summary
4 |
5 | Warehouse Management System to manage user orders, warehouse inventory, in and out inventory from factory to warehouse and from warehouse to users.
6 |
7 | # 2. Problem & Motivation
8 |
9 | - Problem
10 |
11 | 1. Repeated and tedious bookkeeping
12 |
13 | You could say almost warehouse have to write how much inventory that came to warehouse and out to the users and you need to update it to supervisor in the end of the day. Every item that send to user you need to keep track record of it while writing it down sounds easy for 1 or 10 orders, it would be hard to write manually 100 orders.
14 |
15 | 2. Inconsistency through all the warehouse
16 |
17 | Every supervisor and staffs would not have the same consistency while writing down everything even if it’s already referring to some guideline from the main office.
18 |
19 | 3. Hard to monitor every warehouse
20 |
21 | If you have many warehouse in Indonesia you can’t check to every warehouse manually going there or just waiting for the report from every supervisor in each warehouse.
22 |
23 | 4. Hard to track Inventory
24 |
25 | Every product in inventory need to be organized is it by category, size, weight or even volumes. We need to know where is the item in warehouse.
26 |
27 | - Motivation
28 | By creating such system we can track how much inventory that each warehouse have, when to replenish inventory, when warehouse need to send to customer(user), and for easier sending inventory to user from the nearest warehouse.
29 |
30 | # 3. Detailed Design
31 |
32 | ## Specification
33 |
34 | 1. Listing Warehouses
35 |
36 | Inventory itu menyimpan ada produk apa, jumlahnya berapa di gudang mana
37 |
38 | 2. Inventory Management
39 |
40 | Penyimpanan produk didalam warehouse secara proksimitas tata letak posisi.
41 |
42 | 3. Stock-in/Stock-out
43 |
44 | Stock in stock out itu proses keluar masuk barang ke gudang
45 |
46 | ## Feature
47 |
48 | - Create warehouse user
49 | - Auth warehouse user
50 | - as a supervisor you can add more inventory and got notification if the stock is low
51 | - as a staff you can retrieve item from supplier and send ordered item to users
52 | - as superuser you could see all of this above without restriction
53 | - Ongoing order transaction that is in listed ascending by whos first to order (by default)
54 | - Sort order by quantity, weight, date, order process (accepted, on-process, sent from warehouse)
55 | - as a staff you could save an item into a specific aisle, row, etc of each exact system in every warehouse (every warehouse has a different system to make it easier to access from the most oredered item to least ordered item or from sheer quantity it’s up to the supervisor to make all easy)
56 |
57 | ## Entity Relationship Diagram
58 |
59 | 
60 |
61 | [efishery.warehouse_roles](https://www.notion.so/15b85e7c369d4a1ca0f1527ed7cc343c)
62 |
63 | [efishery.warehouse_categories](https://www.notion.so/25adbbccbeb14214828fa3b676dfb2e5)
64 |
65 | [efishery.supplier](https://www.notion.so/a251f565ad6545768e838d4e004081d1)
66 |
67 | [efishery.supplier_address](https://www.notion.so/354c4a981c4f48d996af4db3bdde26fb)
68 |
69 | [efishery.warehouse_address](https://www.notion.so/4d0e762887454edba687726c10cbffe3)
70 |
71 | [efishery.warehouse](https://www.notion.so/7c87375da5cb4386bbd4863857b2e528)
72 |
73 | [efishery.warehouse_sections](https://www.notion.so/9d85a8248a3d4d34a4ba4a5ad59b8f8e)
74 |
75 | [efishery.warehouse_orders](https://www.notion.so/863406d3c1474497a23289ffa9d0f36a)
76 |
77 | [efishery.workers](https://www.notion.so/e0288efea6e843b885064c7a50dbd744)
78 |
79 | [efishery.warehouse_products](https://www.notion.so/c4529a540c964272a1154a39064f1054)
80 |
81 | [efishery.warehouse_auths](https://www.notion.so/adcb62001d694c26a9c80431e3910338)
82 |
83 | ## API Contract & Documentation
84 |
85 | [API Documentation](https://documenter.getpostman.com/view/16004863/2s83zdwS77)
86 |
87 | ## Prerequisite
88 |
89 | To run this app, you might to ensure youe machine has these instance installed:
90 |
91 | 1. Go Programming Language (1.18 or higher)
92 | 2. Docker with Docker Compose (latest version)
93 | 3. Postman or other RestAPI client
94 | 4. Code / Text Editor
95 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/config/auth/hashPassword.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "golang.org/x/crypto/bcrypt"
5 | )
6 |
7 | func HashPassword(password string) (string, error) {
8 | bytes, err := bcrypt.GenerateFromPassword([]byte(password), 8)
9 | return string(bytes), err
10 | }
11 |
12 | func CheckPasswordHash(password, hash string) bool {
13 | err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
14 | return err == nil
15 | }
16 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/config/database/postgres.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "fmt"
5 | "os"
6 | supplier "warehouse-management-system-eFishery/entity/supplier"
7 | warehouse "warehouse-management-system-eFishery/entity/warehouse"
8 |
9 | _ "github.com/joho/godotenv/autoload"
10 | "gorm.io/driver/postgres"
11 | "gorm.io/gorm"
12 | )
13 |
14 | var DB *gorm.DB
15 | var err error
16 |
17 | type (
18 | dsn struct {
19 | Host string
20 | Port string
21 | User string
22 | Password string
23 | Dbname string
24 | SSLMode string
25 | Timezone string
26 | }
27 | )
28 |
29 | func Connect() {
30 | dsn := dsn{
31 | Host: os.Getenv("DB_HOST"),
32 | Port: os.Getenv("DB_PORT"),
33 | User: os.Getenv("DB_USER"),
34 | Password: os.Getenv("DB_PASSWORD"),
35 | Dbname: os.Getenv("DB_NAME"),
36 | Timezone: os.Getenv("DB_TIMEZONE"),
37 | SSLMode: os.Getenv("DB_SSLMODE"),
38 | }
39 | db_url := "host=" + dsn.Host + " user=" + dsn.User + " password=" + dsn.Password + " dbname=" + dsn.Dbname + " port=" + dsn.Port + " TimeZone=" + dsn.Timezone
40 |
41 | DB, err = gorm.Open(postgres.Open(db_url), &gorm.Config{})
42 | if err != nil {
43 | panic(err)
44 | }
45 | fmt.Println("Database connected")
46 | }
47 |
48 | func Migrate() {
49 | DB.AutoMigrate(&warehouse.WarehouseWorkers{})
50 | DB.AutoMigrate(&warehouse.WarehouseRoles{})
51 | DB.AutoMigrate(&warehouse.WarehouseAuth{})
52 | DB.AutoMigrate(&warehouse.Warehouse{})
53 | DB.AutoMigrate(&warehouse.WarehouseAddress{})
54 | DB.AutoMigrate(&warehouse.WarehouseOrders{})
55 | DB.AutoMigrate(&warehouse.WarehouseProducts{})
56 | DB.AutoMigrate(&warehouse.WarehouseCategories{})
57 |
58 | DB.AutoMigrate(&supplier.Supplier{})
59 | DB.AutoMigrate(&supplier.SupplierAddress{})
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/docker-compose.yaml:
--------------------------------------------------------------------------------
1 |
2 | version: '3.9'
3 |
4 | services:
5 | # Main postgresql database
6 | postgres:
7 | image: postgres:13
8 | container_name: postgres
9 | restart: always
10 | environment:
11 | POSTGRES_USER: postgres
12 | POSTGRES_PASSWORD: postgres
13 | POSTGRES_DB: postgres
14 | volumes:
15 | - ./postgres:/var/lib/postgresql/data
16 | ports:
17 | - 5432:5432
18 | networks:
19 | - efishery_wms_network
20 | healthcheck:
21 | test: ["CMD-SHELL", "pg_isready -U postgres"]
22 | interval: 10s
23 | timeout: 5s
24 | retries: 5
25 | # The main service
26 | efisherywms:
27 | container_name: efisherywms
28 | image: hkimm/efisherywms:latest
29 | build: .
30 | ports:
31 | - 8080:8080
32 | restart: on-failure
33 | environment:
34 | - DB_HOST=postgres
35 | - DB_PORT=5432
36 | - DB_USER=postgres
37 | - DB_PASSWORD=postgres
38 | - DB_NAME=postgres
39 | - DB_SSLMODE=disable
40 | - DB_TIMEZONE=Asia/Jakarta
41 | volumes:
42 | - .:/app
43 | networks:
44 | - efishery_wms_network
45 | depends_on:
46 | postgres :
47 | condition: service_healthy
48 |
49 | networks:
50 | efishery_wms_network:
51 | name: efishery_wms_network
52 | volumes:
53 | postgres:
54 | efisherywms:
55 |
56 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/eFishery Warehouse Management System 3aab94e0380e4d25852a111205ba3d89/warehouse_test_efishery_-_public2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/naufalhakim23/naufalhakim-efishery-academy/ea02ea3fc5de35998ce27360ae2ba56b9f459f67/9. Final Project - Warehouse Management System/eFishery Warehouse Management System 3aab94e0380e4d25852a111205ba3d89/warehouse_test_efishery_-_public2.png
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/responseJson/errorResponse.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type ErrorResponse struct {
4 | Status int `json:"status"`
5 | Message string `json:"message"`
6 | Error string `json:"error"`
7 | }
8 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/responseJson/successResponse.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type SuccessResponse struct {
4 | Message string `json:"message"`
5 | Status int `json:"status"`
6 | Data interface{} `json:"data"`
7 | }
8 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/supplier/supplier.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type Supplier struct {
4 | ID int `gorm:"primaryKey;column:id" json:"id"`
5 | SupplierName string `gorm:"column:supplier_name" json:"supplier_name"`
6 | SupplierDesc string `gorm:"column:supplier_desc" json:"supplier_desc"`
7 | Phone string `gorm:"column:phone" json:"phone"`
8 | Email string `gorm:"column:email" json:"email"`
9 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
10 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
11 | }
12 |
13 | type CreateSupplier struct {
14 | SupplierName string `gorm:"column:supplier_name" json:"supplier_name"`
15 | SupplierDesc string `gorm:"column:supplier_desc" json:"supplier_desc"`
16 | Phone string `gorm:"column:phone" json:"phone"`
17 | Email string `gorm:"column:email" json:"email"`
18 | CreateAt string `gorm:"column:created_at" json:"created_at"`
19 | }
20 |
21 | type UpdateSupplier struct {
22 | SupplierName string `gorm:"column:supplier_name" json:"supplier_name"`
23 | SupplierDesc string `gorm:"column:supplier_desc" json:"supplier_desc"`
24 | Phone string `gorm:"column:phone" json:"phone"`
25 | Email string `gorm:"column:email" json:"email"`
26 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
27 | }
28 |
29 | type SupplierResponse struct {
30 | ID int `gorm:"primaryKey;column:id" json:"id"`
31 | SupplierName string `gorm:"column:supplier_name" json:"supplier_name"`
32 | SupplierDesc string `gorm:"column:supplier_desc" json:"supplier_desc"`
33 | Phone string `gorm:"column:phone" json:"phone"`
34 | Email string `gorm:"column:email" json:"email"`
35 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
36 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
37 | }
38 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/supplier/supplier_address.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type SupplierAddress struct {
4 | ID int `gorm:"primaryKey;column:id" json:"id"`
5 | SupplierID int `gorm:"column:supplier_id" json:"supplier_id"`
6 | Supplier Supplier `gorm:"foreignKey:SupplierID;references:ID" `
7 | FullAddress string `gorm:"column:full_address" json:"full_address"`
8 | SubDistrict string `gorm:"column:sub_district" json:"sub_district"`
9 | District string `gorm:"column:district" json:"district"`
10 | City string `gorm:"column:city" json:"city"`
11 | Province string `gorm:"column:province" json:"province"`
12 | PostalCode int `gorm:"column:postal_code" json:"postal_code"`
13 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
14 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
15 | }
16 |
17 | type CreateSupplierAddress struct {
18 | SupplierID int `gorm:"column:supplier_id" json:"supplier_id"`
19 | Supplier Supplier `gorm:"foreignKey:SupplierID;references:ID" `
20 | FullAddress string `gorm:"column:full_address" json:"full_address"`
21 | SubDistrict string `gorm:"column:sub_district" json:"sub_district"`
22 | District string `gorm:"column:district" json:"district"`
23 | City string `gorm:"column:city" json:"city"`
24 | Province string `gorm:"column:province" json:"province"`
25 | PostalCode int `gorm:"column:postal_code" json:"postal_code"`
26 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
27 | }
28 | type UpdateSupplierAddress struct {
29 | SupplierID int `gorm:"column:supplier_id" json:"supplier_id"`
30 | Supplier Supplier `gorm:"foreignKey:SupplierID;references:ID" `
31 | FullAddress string `gorm:"column:full_address" json:"full_address"`
32 | SubDistrict string `gorm:"column:sub_district" json:"sub_district"`
33 | District string `gorm:"column:district" json:"district"`
34 | City string `gorm:"column:city" json:"city"`
35 | Province string `gorm:"column:province" json:"province"`
36 | PostalCode int `gorm:"column:postal_code" json:"postal_code"`
37 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
38 | }
39 |
40 | type SupplierAddressResponse struct {
41 | ID int `gorm:"primaryKey;column:id" json:"id"`
42 | SupplierID int `gorm:"column:supplier_id" json:"supplier_id"`
43 | Supplier Supplier `gorm:"foreignKey:SupplierID;references:ID" `
44 | FullAddress string `gorm:"column:full_address" json:"full_address"`
45 | SubDistrict string `gorm:"column:sub_district" json:"sub_district"`
46 | District string `gorm:"column:district" json:"district"`
47 | City string `gorm:"column:city" json:"city"`
48 | Province string `gorm:"column:province" json:"province"`
49 | PostalCode int `gorm:"column:postal_code" json:"postal_code"`
50 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
51 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
52 | }
53 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/warehouse/warehouse.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type Warehouse struct {
4 | ID int `gorm:"primaryKey;column:id" json:"id"`
5 | WarehouseName string `gorm:"column:warehouse_name" json:"warehouse_name"`
6 | WarehouseDesc string `gorm:"column:warehouse_desc" json:"warehouse_desc"`
7 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
8 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
9 | }
10 |
11 | type CreateWarehouse struct {
12 | WarehouseName string `gorm:"column:warehouse_name" json:"warehouse_name"`
13 | WarehouseDesc string `gorm:"column:warehouse_desc" json:"warehouse_desc"`
14 | }
15 |
16 | type UpdateWarehouse struct {
17 | WarehouseName string `gorm:"column:warehouse_name" json:"warehouse_name"`
18 | WarehouseDesc string `gorm:"column:warehouse_desc" json:"warehouse_desc"`
19 | }
20 |
21 | type WarehouseResponse struct {
22 | WarehouseName string `gorm:"column:warehouse_name" json:"warehouse_name"`
23 | WarehouseDesc string `gorm:"column:warehouse_desc" json:"warehouse_desc"`
24 | }
25 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/warehouse/warehouse_address.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type WarehouseAddress struct {
4 | ID int `gorm:"primaryKey;column:id" json:"id"`
5 | WarehouseID int `gorm:"column:warehouse_id" json:"warehouse_id"`
6 | Warehouse Warehouse `gorm:"foreignKey:WarehouseID"`
7 | FullAddress string `gorm:"column:full_address" json:"full_address"`
8 | SubDistrict string `gorm:"column:sub_district" json:"sub_district"`
9 | City string `gorm:"column:city" json:"city"`
10 | Province string `gorm:"column:province" json:"province"`
11 | PostalCode int `gorm:"column:postal_code" json:"postal_code"`
12 | Region string `gorm:"column:region" json:"region"`
13 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
14 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
15 | }
16 | type CreateWarehouseAddress struct {
17 | WarehouseID int `gorm:"column:warehouse_id" json:"warehouse_id"`
18 | Warehouse Warehouse `gorm:"foreignKey:WarehouseID"`
19 | FullAddress string `gorm:"column:full_address" json:"full_address"`
20 | SubDistrict string `gorm:"column:sub_district" json:"sub_district"`
21 | City string `gorm:"column:city" json:"city"`
22 | Province string `gorm:"column:province" json:"province"`
23 | Region string `gorm:"column:region" json:"region"`
24 | PostalCode int `gorm:"column:postal_code" json:"postal_code"`
25 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
26 | }
27 | type UpdateWarehouseAddress struct {
28 | WarehouseID int `gorm:"column:warehouse_id" json:"warehouse_id"`
29 | Warehouse Warehouse `gorm:"foreignKey:WarehouseID"`
30 | FullAddress string `gorm:"column:full_address" json:"full_address"`
31 | SubDistrict string `gorm:"column:sub_district" json:"sub_district"`
32 | City string `gorm:"column:city" json:"city"`
33 | Province string `gorm:"column:province" json:"province"`
34 | PostalCode int `gorm:"column:postal_code" json:"postal_code"`
35 | Region string `gorm:"column:region" json:"region"`
36 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
37 | }
38 | type WarehouseAddressesResponse struct {
39 | ID int `gorm:"column:id" json:"id"`
40 | WarehouseID int `gorm:"column:warehouse_id" json:"warehouse_id"`
41 | Warehouse Warehouse `gorm:"foreignKey:WarehouseID"`
42 | FullAddress string `gorm:"column:full_address" json:"full_address"`
43 | SubDistrict string `gorm:"column:sub_district" json:"sub_district"`
44 | City string `gorm:"column:city" json:"city"`
45 | Province string `gorm:"column:province" json:"province"`
46 | PostalCode int `gorm:"column:postal_code" json:"postal_code"`
47 | Region string `gorm:"column:region" json:"region"`
48 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
49 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
50 | }
51 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/warehouse/warehouse_auth.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type WarehouseAuth struct {
4 | // ID int `gorm:"primaryKeycolumn:id" json:"id"`
5 | UUID string `gorm:"foreignKey;column:uuid" json:"uuid"`
6 | WarehouseWorkers WarehouseWorkers `gorm:"foreignKey:UUID"`
7 | Email string `gorm:"column:email" json:"email"`
8 | Password string `gorm:"column:password" json:"password"`
9 | Token string `gorm:"column:token" json:"token"`
10 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
11 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
12 | }
13 | type CreateWarehouseAuth struct {
14 | // adding uuid from worker auth gorm
15 | Email string `gorm:"column:email" json:"email"`
16 | Password string `gorm:"column:password" json:"password"`
17 | }
18 | type UpdateWarehouseAuth struct {
19 | Email string `gorm:"column:email" json:"email"`
20 | Password string `gorm:"column:password" json:"password"`
21 | }
22 | type WarehouseAuthResponse struct {
23 | UUID string `gorm:"foreignKey;column:uuid" json:"uuid"`
24 | Email string `gorm:"column:email" json:"email"`
25 | Token string `gorm:"column:token" json:"token"`
26 | }
27 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/warehouse/warehouse_categories.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type WarehouseCategories struct {
4 | ID int `gorm:"primaryKey;column:id" json:"id"`
5 | CategoryName string `gorm:"column:category_name" json:"category_name"`
6 | CategoryDesc string `gorm:"column:category_desc" json:"category_desc"`
7 | }
8 | type CreateWarehouseCategories struct {
9 | CategoryName string `gorm:"column:category_name" json:"category_name"`
10 | CategoryDesc string `gorm:"column:category_desc" json:"category_desc"`
11 | }
12 | type UpdateWarehouseCategories struct {
13 | CategoryName string `gorm:"column:category_name" json:"category_name"`
14 | CategoryDesc string `gorm:"column:category_desc" json:"category_desc"`
15 | }
16 | type WarehouseCategoriesResponse struct {
17 | CategoryName string `gorm:"column:category_name" json:"category_name"`
18 | CategoryDesc string `gorm:"column:category_desc" json:"category_desc"`
19 | }
20 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/warehouse/warehouse_orders.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type WarehouseOrders struct {
4 | ID int `gorm:"primaryKey;column:id" json:"id"`
5 | WorkerUUID string `gorm:"column:worker_uuid"`
6 | Worker WarehouseWorkers `gorm:"foreignKey:WorkerUUID" json:"worker"`
7 | WarehouseId int `gorm:"column:warehouse_id" json:"warehouse_id"`
8 | Warehouse Warehouse `gorm:"foreignKey:WarehouseId"`
9 | OrderId int `gorm:"column:order_id" json:"order_id"`
10 | ProductStatus string `gorm:"column:product_status" json:"product_status"`
11 | ProductMark string `gorm:"column:product_mark" json:"product_mark"`
12 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
13 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
14 | }
15 |
16 | type CreateWarehouseOrders struct {
17 | WorkerUUID string `gorm:"column:worker_uuid" json:"worker_uuid"`
18 | WarehouseId int `gorm:"column:warehouse_id" json:"warehouse_id"`
19 | OrderId int `gorm:"column:order_id" json:"order_id"`
20 | ProductStatus string `gorm:"column:product_status" json:"product_status"`
21 | ProductMark string `gorm:"column:product_mark" json:"product_mark"`
22 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
23 | }
24 |
25 | type UpdateWarehouseOrders struct {
26 | WorkerUUID string `gorm:"column:worker_uuid" json:"worker_uuid"`
27 | WarehouseId int `gorm:"column:warehouse_id" json:"warehouse_id"`
28 | OrderId int `gorm:"column:order_id" json:"order_id"`
29 | ProductStatus string `gorm:"column:product_status" json:"product_status"`
30 | ProductMark string `gorm:"column:product_mark" json:"product_mark"`
31 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
32 | }
33 |
34 | type WarehouseOrdersResponse struct {
35 | ID int `gorm:"primaryKey;column:id" json:"id"`
36 | WorkerUUID string `gorm:"column:worker_uuid" json:"worker_id"`
37 | Warehouse Warehouse `gorm:"foreignKey:WarehouseId"`
38 | OrderId int `gorm:"column:order_id" json:"order_id"`
39 | ProductStatus string `gorm:"column:product_status" json:"product_status"`
40 | ProductMark string `gorm:"column:product_mark" json:"product_mark"`
41 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
42 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
43 | }
44 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/warehouse/warehouse_roles.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type WarehouseRoles struct {
4 | ID int `gorm:"primaryKey;column:id" json:"id"`
5 | Role string `gorm:"column:role" json:"role"`
6 | Description string `gorm:"column:description" json:"description"`
7 | }
8 | type CreateWarehouseRoles struct {
9 | Role string `gorm:"column:role" json:"role"`
10 | Description string `gorm:"column:description" json:"description"`
11 | }
12 | type UpdateWarehouseRoles struct {
13 | Role string `gorm:"column:role" json:"role"`
14 | Description string `gorm:"column:description" json:"description"`
15 | }
16 | type WarehouseRolesResponse struct {
17 | Role string `gorm:"column:role" json:"role"`
18 | Description string `gorm:"column:description" json:"description"`
19 | }
20 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/warehouse/warehouse_section.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type WarehouseSection struct {
4 | ID int `gorm:"primaryKey;column:id" json:"id"`
5 | WarehouseID int `gorm:"column:warehouse_id" json:"warehouse_id"`
6 | Warehouse Warehouse `gorm:"foreignKey:WarehouseID"`
7 | InventorySection int `gorm:"column:inventory_section" json:"inventory_section"`
8 | InventoryAisle int `gorm:"column:inventory_aisle" json:"inventory_aisle"`
9 | InventoryRow int `gorm:"column:inventory_row" json:"inventory_row"`
10 | InventoryTier int `gorm:"column:inventory_tier" json:"inventory_tier"`
11 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
12 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
13 | }
14 |
15 | type CreateWarehouseSection struct {
16 | WarehouseID int `gorm:"column:warehouse_id" json:"warehouse_id"`
17 | Warehouse Warehouse `gorm:"foreignKey:WarehouseID"`
18 | InventorySection int `gorm:"column:inventory_section" json:"inventory_section"`
19 | InventoryAisle int `gorm:"column:inventory_aisle" json:"inventory_aisle"`
20 | InventoryRow int `gorm:"column:inventory_row" json:"inventory_row"`
21 | InventoryTier int `gorm:"column:inventory_tier" json:"inventory_tier"`
22 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
23 | }
24 |
25 | type UpdateWarehouseSection struct {
26 | WarehouseID int `gorm:"column:warehouse_id" json:"warehouse_id"`
27 | Warehouse Warehouse `gorm:"foreignKey:WarehouseID"`
28 | InventorySection int `gorm:"column:inventory_section" json:"inventory_section"`
29 | InventoryAisle int `gorm:"column:inventory_aisle" json:"inventory_aisle"`
30 | InventoryRow int `gorm:"column:inventory_row" json:"inventory_row"`
31 | InventoryTier int `gorm:"column:inventory_tier" json:"inventory_tier"`
32 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
33 | }
34 |
35 | type WarehouseSectionResponse struct {
36 | ID int `gorm:"primaryKey;column:id" json:"id"`
37 | WarehouseID int `gorm:"column:warehouse_id" json:"warehouse_id"`
38 | Warehouse Warehouse `gorm:"foreignKey:WarehouseID"`
39 | InventorySection int `gorm:"column:inventory_section" json:"inventory_section"`
40 | InventoryAisle int `gorm:"column:inventory_aisle" json:"inventory_aisle"`
41 | InventoryRow int `gorm:"column:inventory_row" json:"inventory_row"`
42 | InventoryTier int `gorm:"column:inventory_tier" json:"inventory_tier"`
43 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
44 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
45 | }
46 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/entity/warehouse/warehouse_workers.go:
--------------------------------------------------------------------------------
1 | package entity
2 |
3 | type WarehouseWorkers struct {
4 | UUID string `gorm:"primaryKey;column:uuid" json:"uuid"`
5 | FirstName string `gorm:"not null;column:first_name" json:"first_name"`
6 | LastName string `gorm:"not null;column:last_name" json:"last_name"`
7 | Phone string `gorm:"not null;column:phone;unique" json:"phone"`
8 | Email string `gorm:"not null;column:email;unique" json:"email"`
9 | Password string `gorm:"not null;column:password" json:"password"`
10 | WarehouseId int `gorm:"column:warehouse_id" json:"warehouse_id"`
11 | Warehouse Warehouse `gorm:"foreignKey:WarehouseId"`
12 | RolesId int `gorm:"column:roles_id" json:"roles_id"`
13 | WarehouseRoles WarehouseRoles `gorm:"foreignKey:RolesId"`
14 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
15 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
16 | }
17 | type CreateWarehouseWorkers struct {
18 | // connect to worker auth gorm
19 | UUID string `gorm:"primaryKey;column:uuid" json:"uuid"`
20 | FirstName string `gorm:"column:first_name" json:"first_name"`
21 | LastName string `gorm:"column:last_name" json:"last_name"`
22 | Phone string `gorm:"not null;column:phone;unique" json:"phone"`
23 | Email string `gorm:"column:email;unique" json:"email"`
24 | Password string `gorm:"column:password" json:"password"`
25 | WarehouseId int `gorm:"column:warehouse_id;foreignKey" json:"warehouse_id"`
26 | RolesId int `gorm:"column:roles_id;foreignKey" json:"roles_id"`
27 | CreatedAt string `gorm:"column:created_at" json:"created_at"`
28 | }
29 | type UpdateWarehouseWorkers struct {
30 | FirstName string `gorm:"not null;column:first_name" json:"first_name"`
31 | LastName string `gorm:"not null;column:last_name" json:"last_name"`
32 | Phone string `gorm:"not null;column:phone;unique" json:"phone"`
33 | Email string `gorm:"not null;column:email;unique" json:"email"`
34 | Password string `gorm:"not null;column:password" json:"password"`
35 | UpdatedAt string `gorm:"column:updated_at" json:"updated_at"`
36 | }
37 | type WarehouseWorkersResponse struct {
38 | UUID string `gorm:"not null;column:uuid" json:"uuid"`
39 | FirstName string `gorm:"not null;column:first_name" json:"first_name"`
40 | LastName string `gorm:"not null;column:last_name" json:"last_name"`
41 | Phone string `gorm:"not null;column:phone;unique" json:"phone"`
42 | Email string `gorm:"not null;column:email;unique" json:"email"`
43 | WarehouseId int `gorm:"not null;column:warehouse_id;foreignKey" json:"warehouse_id"`
44 | RolesId int `gorm:"not null;column:roles_id;foreignKey" json:"roles_id"`
45 | }
46 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/go.mod:
--------------------------------------------------------------------------------
1 | module warehouse-management-system-eFishery
2 |
3 | go 1.18
4 |
5 | require github.com/labstack/echo/v4 v4.9.0
6 |
7 | require (
8 | github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
9 | github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
10 | golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
11 | )
12 |
13 | require (
14 | github.com/google/uuid v1.3.0
15 | github.com/jackc/chunkreader/v2 v2.0.1 // indirect
16 | github.com/jackc/pgconn v1.13.0 // indirect
17 | github.com/jackc/pgio v1.0.0 // indirect
18 | github.com/jackc/pgpassfile v1.0.0 // indirect
19 | github.com/jackc/pgproto3/v2 v2.3.1 // indirect
20 | github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
21 | github.com/jackc/pgtype v1.12.0 // indirect
22 | github.com/jackc/pgx/v4 v4.17.2 // indirect
23 | github.com/jinzhu/inflection v1.0.0 // indirect
24 | github.com/jinzhu/now v1.1.4 // indirect
25 | github.com/joho/godotenv v1.4.0
26 | github.com/labstack/gommon v0.3.1 // indirect
27 | github.com/mattn/go-colorable v0.1.11 // indirect
28 | github.com/mattn/go-isatty v0.0.14 // indirect
29 | github.com/valyala/bytebufferpool v1.0.0 // indirect
30 | github.com/valyala/fasttemplate v1.2.1 // indirect
31 | golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be
32 | golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
33 | golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
34 | golang.org/x/text v0.3.7 // indirect
35 | gorm.io/driver/postgres v1.3.10
36 | gorm.io/gorm v1.23.10
37 | )
38 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/handler/supplier/supplier.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "net/http"
5 | "strconv"
6 | response "warehouse-management-system-eFishery/entity/responseJson"
7 | entity "warehouse-management-system-eFishery/entity/supplier"
8 | services "warehouse-management-system-eFishery/services/supplier"
9 |
10 | "github.com/labstack/echo/v4"
11 | )
12 |
13 | type SupplierHandler struct {
14 | service *services.SupplierService
15 | }
16 |
17 | func NewSupplierHandler(service *services.SupplierService) *SupplierHandler {
18 | return &SupplierHandler{service}
19 | }
20 |
21 | func (handler *SupplierHandler) CreateSupplier(c echo.Context) error {
22 | var supplier entity.Supplier
23 | c.Bind(&supplier)
24 | supplier, err := handler.service.CreateSupplier(supplier)
25 | if err != nil {
26 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
27 | Status: http.StatusBadRequest,
28 | Message: "Failed to create supplier",
29 | Error: err.Error(),
30 | })
31 | }
32 | if supplier.ID == 0 || supplier.Email == "" || supplier.SupplierName == "" || supplier.Phone == "" || supplier.SupplierDesc == "" {
33 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
34 | Status: http.StatusBadRequest,
35 | Message: "Failed to create supplier",
36 | Error: "Please fill all the field",
37 | })
38 | }
39 |
40 | return c.JSON(http.StatusCreated, response.SuccessResponse{
41 | Status: http.StatusCreated,
42 | Message: "Success to create supplier",
43 | Data: supplier,
44 | })
45 | }
46 |
47 | func (handler *SupplierHandler) GetAllSupplier(c echo.Context) error {
48 | suppliers, err := handler.service.GetAllSupplier()
49 | if err != nil {
50 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
51 | Status: http.StatusBadRequest,
52 | Message: "Failed to get list of e-Fishery Suppliers",
53 | Error: err.Error(),
54 | })
55 | }
56 | if len(suppliers) == 0 {
57 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
58 | Status: http.StatusNotFound,
59 | Message: "No data found",
60 | })
61 | }
62 |
63 | return c.JSON(http.StatusOK, response.SuccessResponse{
64 | Status: http.StatusOK,
65 | Message: "Success to get all list of e-Fishery Suppliers",
66 | Data: suppliers,
67 | })
68 | }
69 |
70 | func (handler *SupplierHandler) GetSupplierByID(c echo.Context) error {
71 | id, _ := strconv.Atoi(c.Param("id"))
72 | supplier, err := handler.service.GetSupplierByID(id)
73 | if err != nil {
74 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
75 | Status: http.StatusBadRequest,
76 | Message: "Failed to get supplier by id",
77 | Error: err.Error(),
78 | })
79 | }
80 | return c.JSON(http.StatusOK, response.SuccessResponse{
81 | Status: http.StatusOK,
82 | Message: "Success to get supplier by id",
83 | Data: supplier,
84 | })
85 | }
86 |
87 | func (hanndler *SupplierHandler) UpdateSupplier(c echo.Context) error {
88 | id, _ := strconv.Atoi(c.Param("id"))
89 | var supplierReq entity.UpdateSupplier
90 | c.Bind(&supplierReq)
91 | supplier, err := hanndler.service.UpdateSupplier(id, supplierReq)
92 | if err != nil {
93 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
94 | Status: http.StatusBadRequest,
95 | Message: "Failed to update supplier",
96 | Error: err.Error(),
97 | })
98 | }
99 |
100 | if supplier.ID == 0 || supplier.Email == "" || supplier.SupplierName == "" || supplier.Phone == "" || supplier.SupplierDesc == "" {
101 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
102 | Status: http.StatusBadRequest,
103 | Message: "Failed to update supplier",
104 | Error: "Please fill all the field",
105 | })
106 | }
107 |
108 | return c.JSON(http.StatusOK, response.SuccessResponse{
109 | Status: http.StatusOK,
110 | Message: "Success to update supplier",
111 | Data: supplier,
112 | })
113 | }
114 |
115 | func (handler *SupplierHandler) DeleteSupplier(c echo.Context) error {
116 | id, _ := strconv.Atoi(c.Param("id"))
117 | err := handler.service.DeleteSupplier(id)
118 | if err != nil {
119 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
120 | Status: http.StatusBadRequest,
121 | Message: "Failed to delete supplier",
122 | Error: err.Error(),
123 | })
124 | }
125 | if id == 0 {
126 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
127 | Status: http.StatusBadRequest,
128 | Message: "Failed to delete supplier",
129 | })
130 | }
131 | suppliers, _ := handler.service.GetAllSupplier()
132 | if id > len(suppliers) || id < 0 {
133 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
134 | Status: http.StatusBadRequest,
135 | Message: "Failed to delete supplier",
136 | Error: "Supplier not found",
137 | })
138 | }
139 |
140 | return c.JSON(http.StatusOK, response.SuccessResponse{
141 | Status: http.StatusOK,
142 | Message: "Success to delete supplier",
143 | })
144 | }
145 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/handler/warehouse/warehouse.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "net/http"
5 | "strconv"
6 | response "warehouse-management-system-eFishery/entity/responseJson"
7 | entity "warehouse-management-system-eFishery/entity/warehouse"
8 | services "warehouse-management-system-eFishery/services/warehouse"
9 |
10 | "github.com/labstack/echo/v4"
11 | )
12 |
13 | type WarehouseHandler struct {
14 | service *services.WarehouseService
15 | }
16 |
17 | func NewWarehouseHandler(service *services.WarehouseService) *WarehouseHandler {
18 | return &WarehouseHandler{service}
19 | }
20 |
21 | func (handler WarehouseHandler) CreateWarehouse(c echo.Context) error {
22 | var warehouse entity.Warehouse
23 | c.Bind(&warehouse)
24 | warehouse, err := handler.service.CreateWarehouse(warehouse)
25 | if err != nil {
26 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
27 | Status: http.StatusBadRequest,
28 | Message: "Failed to create warehouse",
29 | Error: err.Error(),
30 | })
31 | }
32 | return c.JSON(http.StatusCreated, response.SuccessResponse{
33 | Status: http.StatusCreated,
34 | Message: "Success to create warehouse",
35 | Data: warehouse,
36 | })
37 | }
38 |
39 | func (handler WarehouseHandler) GetAllWarehouse(c echo.Context) error {
40 | warehouses, err := handler.service.GetAllWarehouse()
41 | if err != nil {
42 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
43 | Status: http.StatusBadRequest,
44 | Message: "Failed to get list of e-Fishery Warehouses",
45 | Error: err.Error(),
46 | })
47 | }
48 | if len(warehouses) == 0 {
49 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
50 | Status: http.StatusNotFound,
51 | Message: "No data found",
52 | })
53 | }
54 | return c.JSON(http.StatusOK, response.SuccessResponse{
55 | Status: http.StatusOK,
56 | Message: "Success to get all list of e-Fishery Warehouses",
57 | Data: warehouses,
58 | })
59 | }
60 |
61 | func (handler WarehouseHandler) GetWarehouseByID(c echo.Context) error {
62 | id, _ := strconv.Atoi(c.Param("id"))
63 | warehouse, err := handler.service.GetWarehouseByID(id)
64 | if err != nil {
65 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
66 | Status: http.StatusBadRequest,
67 | Message: "Failed to get warehouse by id",
68 | Error: err.Error(),
69 | })
70 | }
71 | if warehouse.ID == 0 || warehouse.ID != id {
72 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
73 | Status: http.StatusNotFound,
74 | Message: "No data found",
75 | })
76 | }
77 | return c.JSON(http.StatusOK, response.SuccessResponse{
78 | Status: http.StatusOK,
79 | Message: "Success to get warehouse by id",
80 | Data: warehouse,
81 | })
82 | }
83 |
84 | func (handler WarehouseHandler) UpdateWarehouse(c echo.Context) error {
85 | req := entity.UpdateWarehouse{}
86 | if err := c.Bind(&req); err != nil {
87 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
88 | Status: http.StatusBadRequest,
89 | Message: "Invalid Request Body",
90 | Error: err.Error(),
91 | })
92 | }
93 | id, _ := strconv.Atoi(c.Param("id"))
94 | // Searching id bugged this will not be permanent solution need to figure out where is the error
95 | w, err := handler.service.GetWarehouseByID(id)
96 | if err != nil {
97 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
98 | Status: http.StatusBadRequest,
99 | Message: "Failed to get warehouse by id",
100 | Error: err.Error(),
101 | })
102 | }
103 | if w.ID == 0 || w.ID != id {
104 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
105 | Status: http.StatusNotFound,
106 | Message: "No data found",
107 | })
108 | }
109 | warehouse, err := handler.service.UpdateWarehouse(req, id)
110 | if err != nil {
111 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
112 | Status: http.StatusBadRequest,
113 | Message: "Failed to update warehouse",
114 | Error: err.Error(),
115 | })
116 | }
117 | return c.JSON(http.StatusOK, response.SuccessResponse{
118 | Status: http.StatusOK,
119 | Message: "Success to update warehouse",
120 | Data: warehouse,
121 | })
122 | }
123 |
124 | func (handler WarehouseHandler) DeleteWarehouse(c echo.Context) error {
125 | id, _ := strconv.Atoi(c.Param("id"))
126 | err := handler.service.DeleteWarehouse(id)
127 | if err != nil {
128 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
129 | Status: http.StatusBadRequest,
130 | Message: "Failed to delete warehouse",
131 | Error: err.Error(),
132 | })
133 | }
134 | if id == 0 {
135 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
136 | Status: http.StatusNotFound,
137 | Message: "No data found",
138 | })
139 | }
140 | return c.JSON(http.StatusOK, response.SuccessResponse{
141 | Status: http.StatusOK,
142 | Message: "Success to delete warehouse",
143 | })
144 | }
145 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/handler/warehouse/warehouse_categories.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "net/http"
5 | "strconv"
6 | response "warehouse-management-system-eFishery/entity/responseJson"
7 | entity "warehouse-management-system-eFishery/entity/warehouse"
8 | services "warehouse-management-system-eFishery/services/warehouse"
9 |
10 | "github.com/labstack/echo/v4"
11 | )
12 |
13 | type WarehouseCategoryHandler struct {
14 | service *services.WarehouseCategoryService
15 | }
16 |
17 | func NewWarehouseCategoryHandler(service *services.WarehouseCategoryService) *WarehouseCategoryHandler {
18 | return &WarehouseCategoryHandler{service}
19 | }
20 |
21 | func (handler WarehouseCategoryHandler) CreateWarehouseCategory(c echo.Context) error {
22 | var warehouseCategory entity.WarehouseCategories
23 | c.Bind(&warehouseCategory)
24 | warehouseCategory, err := handler.service.CreateWarehouseCategory(warehouseCategory)
25 | if err != nil {
26 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
27 | Status: http.StatusBadRequest,
28 | Message: "Failed to create warehouse category",
29 | Error: err.Error(),
30 | })
31 | }
32 | if warehouseCategory.CategoryName == "" || warehouseCategory.CategoryName == " " {
33 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
34 | Status: http.StatusBadRequest,
35 | Message: "Failed to create warehouse category",
36 | Error: "Category name cannot be empty",
37 | })
38 | }
39 | return c.JSON(http.StatusCreated, response.SuccessResponse{
40 | Status: http.StatusCreated,
41 | Message: "Success to create warehouse category",
42 | Data: warehouseCategory,
43 | })
44 | }
45 |
46 | func (handler WarehouseCategoryHandler) GetAllWarehouseCategory(c echo.Context) error {
47 | warehouseCategory, err := handler.service.GetAllCategory()
48 | if err != nil {
49 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
50 | Status: http.StatusBadRequest,
51 | Message: "Failed to get list of e-Fishery Warehouse Categories",
52 | Error: err.Error(),
53 | })
54 | }
55 | if len(warehouseCategory) == 0 {
56 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
57 | Status: http.StatusNotFound,
58 | Message: "No data found",
59 | })
60 | }
61 | return c.JSON(http.StatusOK, response.SuccessResponse{
62 | Status: http.StatusOK,
63 | Message: "Success to get all list of e-Fishery Warehouse Categories",
64 | Data: warehouseCategory,
65 | })
66 | }
67 |
68 | func (handler WarehouseCategoryHandler) GetWarehouseCategoryByID(c echo.Context) error {
69 | id, _ := strconv.Atoi(c.Param("id"))
70 | warehouseCategory, err := handler.service.GetCategoryByID(id)
71 | if err != nil {
72 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
73 | Status: http.StatusBadRequest,
74 | Message: "Failed to get warehouse category by id",
75 | Error: err.Error(),
76 | })
77 | }
78 | if warehouseCategory.ID == 0 {
79 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
80 | Status: http.StatusNotFound,
81 | Message: "No data found",
82 | })
83 | }
84 | return c.JSON(http.StatusOK, response.SuccessResponse{
85 | Status: http.StatusOK,
86 | Message: "Success to get warehouse category by id",
87 | Data: warehouseCategory,
88 | })
89 | }
90 |
91 | func (handler WarehouseCategoryHandler) UpdateWarehouseCategory(c echo.Context) error {
92 | id, _ := strconv.Atoi(c.Param("id"))
93 | warehouseCategory := entity.WarehouseCategories{}
94 | if err := c.Bind(&warehouseCategory); err != nil {
95 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
96 | Status: http.StatusBadRequest,
97 | Message: "Failed to update warehouse category",
98 | Error: err.Error(),
99 | })
100 | }
101 | warehouseCategory, err := handler.service.UpdateWarehouseCategory(id, warehouseCategory)
102 | if err != nil {
103 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
104 | Status: http.StatusBadRequest,
105 | Message: "Failed to update warehouse category",
106 | Error: err.Error(),
107 | })
108 | }
109 | if warehouseCategory.ID == 0 || warehouseCategory.CategoryName == "" || warehouseCategory.CategoryName == " " {
110 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
111 | Status: http.StatusBadRequest,
112 | Message: "Failed to update warehouse category",
113 | Error: "Category name cannot be empty",
114 | })
115 | }
116 | return c.JSON(http.StatusOK, response.SuccessResponse{
117 | Status: http.StatusOK,
118 | Message: "Success to update warehouse category",
119 | Data: warehouseCategory,
120 | })
121 | }
122 |
123 | func (handler WarehouseCategoryHandler) DeleteWarehouseCategory(c echo.Context) error {
124 | id, _ := strconv.Atoi(c.Param("id"))
125 | err := handler.service.DeleteWarehouseCategory(id)
126 | if err != nil {
127 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
128 | Status: http.StatusBadRequest,
129 | Message: "Failed to delete warehouse category",
130 | Error: err.Error(),
131 | })
132 | }
133 | warehouseCategories, _ := handler.service.GetAllCategory()
134 | if len(warehouseCategories) == 0 {
135 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
136 | Status: http.StatusNotFound,
137 | Message: "No data found",
138 | })
139 | }
140 |
141 | if id > len(warehouseCategories) || id < 0 {
142 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
143 | Status: http.StatusNotFound,
144 | Message: "No data found",
145 | })
146 | }
147 |
148 | return c.JSON(http.StatusOK, response.SuccessResponse{
149 | Status: http.StatusOK,
150 | Message: "Success to delete warehouse category",
151 | })
152 | }
153 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/handler/warehouse/warehouse_roles.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "net/http"
5 | "strconv"
6 | response "warehouse-management-system-eFishery/entity/responseJson"
7 | entity "warehouse-management-system-eFishery/entity/warehouse"
8 | services "warehouse-management-system-eFishery/services/warehouse"
9 |
10 | "github.com/labstack/echo/v4"
11 | )
12 |
13 | type WarehouseRolesHandler struct {
14 | service *services.WarehouseRolesService
15 | }
16 |
17 | func NewWarehouseRolesHandler(service *services.WarehouseRolesService) *WarehouseRolesHandler {
18 | return &WarehouseRolesHandler{service}
19 | }
20 |
21 | func (handler WarehouseRolesHandler) CreateWarehouseRoles(c echo.Context) error {
22 | var warehouseRoles entity.WarehouseRoles
23 | c.Bind(&warehouseRoles)
24 | warehouseRoles, err := handler.service.CreateWarehouseRoles(warehouseRoles)
25 | if err != nil {
26 | return c.JSON(http.StatusInternalServerError, response.ErrorResponse{
27 | Status: http.StatusInternalServerError,
28 | Message: "Failed to create warehouse roles",
29 | Error: err.Error(),
30 | })
31 | }
32 | if warehouseRoles.Role == "" || warehouseRoles.Description == "" {
33 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
34 | Status: http.StatusBadRequest,
35 | Message: "Failed to create warehouse roles",
36 | Error: "Role or Description cannot be empty",
37 | })
38 | }
39 | return c.JSON(http.StatusCreated, response.SuccessResponse{
40 | Status: http.StatusCreated,
41 | Message: "Success to create warehouse roles",
42 | Data: warehouseRoles,
43 | })
44 | }
45 |
46 | func (handler WarehouseRolesHandler) GetAllWarehouseRoles(c echo.Context) error {
47 | warehouseRoles, err := handler.service.GetAllWarehouseRoles()
48 | if err != nil {
49 | return c.JSON(http.StatusInternalServerError, response.ErrorResponse{
50 | Status: http.StatusInternalServerError,
51 | Message: "Failed to get list of e-Fishery Warehouse Roles",
52 | Error: err.Error(),
53 | })
54 | }
55 | if len(warehouseRoles) == 0 {
56 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
57 | Status: http.StatusNotFound,
58 | Message: "No data found",
59 | })
60 | }
61 | return c.JSON(http.StatusOK, response.SuccessResponse{
62 | Status: http.StatusOK,
63 | Message: "Success to get all list of e-Fishery Warehouse Roles",
64 | Data: warehouseRoles,
65 | })
66 | }
67 |
68 | func (handler WarehouseRolesHandler) GetWarehouseRolesByID(c echo.Context) error {
69 | id, _ := strconv.Atoi(c.Param("id"))
70 | warehouseRoles, err := handler.service.GetWarehouseRolesByID(id)
71 | if err != nil {
72 | return c.JSON(http.StatusInternalServerError, response.ErrorResponse{
73 | Status: http.StatusInternalServerError,
74 | Message: "Failed to get warehouse roles by id",
75 | Error: err.Error(),
76 | })
77 | }
78 | return c.JSON(http.StatusOK, response.SuccessResponse{
79 | Status: http.StatusOK,
80 | Message: "Success to get warehouse roles by id",
81 | Data: warehouseRoles,
82 | })
83 | }
84 | func (handler WarehouseRolesHandler) UpdateWarehouseRoles(c echo.Context) error {
85 | id, _ := strconv.Atoi(c.Param("id"))
86 | warehouseRoles := entity.WarehouseRoles{}
87 | if err := c.Bind(&warehouseRoles); err != nil {
88 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
89 | Status: http.StatusBadRequest,
90 | Message: "Failed to update warehouse roles",
91 | Error: err.Error(),
92 | })
93 | }
94 | warehouseRoles, err := handler.service.UpdateWarehouseRoles(id, warehouseRoles)
95 | if err != nil {
96 | return c.JSON(http.StatusInternalServerError, response.ErrorResponse{
97 | Status: http.StatusInternalServerError,
98 | Message: "Failed to update warehouse roles",
99 | Error: err.Error(),
100 | })
101 | }
102 | if warehouseRoles.Role == "" || warehouseRoles.Description == "" {
103 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
104 | Status: http.StatusBadRequest,
105 | Message: "Failed to create warehouse roles",
106 | Error: "Role or Description cannot be empty",
107 | })
108 | }
109 | return c.JSON(http.StatusOK, response.SuccessResponse{
110 | Status: http.StatusOK,
111 | Message: "Success to update warehouse roles",
112 | Data: warehouseRoles,
113 | })
114 | }
115 |
116 | func (handler WarehouseRolesHandler) DeleteWarehouseRoles(c echo.Context) error {
117 | id, _ := strconv.Atoi(c.Param("id"))
118 | err := handler.service.DeleteWarehouseRoles(id)
119 | if err != nil {
120 | return c.JSON(http.StatusInternalServerError, response.ErrorResponse{
121 | Status: http.StatusInternalServerError,
122 | Message: "Failed to delete warehouse roles",
123 | Error: err.Error(),
124 | })
125 | }
126 | warehouseRole, _ := handler.service.GetAllWarehouseRoles()
127 | if id > len(warehouseRole) || id < 0 {
128 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
129 | Status: http.StatusBadRequest,
130 | Message: "Failed to delete warehouse roles",
131 | Error: "ID not found",
132 | })
133 | }
134 | return c.JSON(http.StatusOK, response.SuccessResponse{
135 | Status: http.StatusOK,
136 | Message: "Success to delete warehouse roles",
137 | })
138 | }
139 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/handler/warehouse/warehouse_section.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "net/http"
5 | "strconv"
6 | response "warehouse-management-system-eFishery/entity/responseJson"
7 | entity "warehouse-management-system-eFishery/entity/warehouse"
8 | services "warehouse-management-system-eFishery/services/warehouse"
9 |
10 | "github.com/labstack/echo/v4"
11 | )
12 |
13 | type WarehouseSectionHandler struct {
14 | service *services.WarehouseSectionService
15 | }
16 |
17 | func NewWarehouseSectionHandler(service *services.WarehouseSectionService) *WarehouseSectionHandler {
18 | return &WarehouseSectionHandler{service}
19 | }
20 |
21 | func (handler WarehouseSectionHandler) CreateWarehouseSection(c echo.Context) error {
22 | var warehouseSection entity.WarehouseSection
23 | c.Bind(&warehouseSection)
24 | warehouseSection, err := handler.service.CreateWarehouseSection(warehouseSection)
25 | if err != nil {
26 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
27 | Status: http.StatusBadRequest,
28 | Message: "Failed to create warehouse section",
29 | Error: err.Error(),
30 | })
31 | }
32 | if warehouseSection.InventoryAisle == 0 || warehouseSection.InventoryRow == 0 || warehouseSection.InventorySection == 0 || warehouseSection.InventoryTier == 0 || warehouseSection.WarehouseID == 0 {
33 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
34 | Status: http.StatusBadRequest,
35 | Message: "Failed to create warehouse section",
36 | Error: "Please fill all the fields",
37 | })
38 | }
39 | return c.JSON(http.StatusCreated, response.SuccessResponse{
40 | Status: http.StatusCreated,
41 | Message: "Success to create warehouse section",
42 | Data: warehouseSection,
43 | })
44 | }
45 |
46 | func (handler WarehouseSectionHandler) GetAllWarehouseSection(c echo.Context) error {
47 | warehouseSections, err := handler.service.GetAllWarehouseSection()
48 | if err != nil {
49 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
50 | Status: http.StatusBadRequest,
51 | Message: "Failed to get list of e-Fishery Warehouse Sections",
52 | Error: err.Error(),
53 | })
54 | }
55 | if len(warehouseSections) == 0 {
56 | return c.JSON(http.StatusNotFound, response.ErrorResponse{
57 | Status: http.StatusNotFound,
58 | Message: "No data found",
59 | })
60 | }
61 | return c.JSON(http.StatusOK, response.SuccessResponse{
62 | Status: http.StatusOK,
63 | Message: "Success to get all list of e-Fishery Warehouse Sections",
64 | Data: warehouseSections,
65 | })
66 | }
67 |
68 | func (handler WarehouseSectionHandler) GetWarehouseSectionByID(c echo.Context) error {
69 | id, _ := strconv.Atoi(c.Param("id"))
70 | warehouseSection, err := handler.service.GetWarehouseSectionByID(id)
71 | if err != nil {
72 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
73 | Status: http.StatusBadRequest,
74 | Message: "Failed to get e-Fishery Warehouse Section",
75 | Error: err.Error(),
76 | })
77 | }
78 | return c.JSON(http.StatusOK, response.SuccessResponse{
79 | Status: http.StatusOK,
80 | Message: "Success to get e-Fishery Warehouse Section",
81 | Data: warehouseSection,
82 | })
83 | }
84 |
85 | func (handler WarehouseSectionHandler) UpdateWarehouseSection(c echo.Context) error {
86 | request := entity.UpdateWarehouseSection{}
87 | if err := c.Bind(&request); err != nil {
88 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
89 | Status: http.StatusBadRequest,
90 | Message: "Failed to update e-Fishery Warehouse Section",
91 | Error: err.Error(),
92 | })
93 | }
94 | id, _ := strconv.Atoi(c.Param("id"))
95 | warehouseSection, err := handler.service.UpdateWarehouseSection(id, request)
96 | if err != nil {
97 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
98 | Status: http.StatusBadRequest,
99 | Message: "Failed to update e-Fishery Warehouse Section",
100 | Error: err.Error(),
101 | })
102 | }
103 | if warehouseSection.InventoryAisle == 0 || warehouseSection.InventoryRow == 0 || warehouseSection.InventorySection == 0 || warehouseSection.InventoryTier == 0 || warehouseSection.WarehouseID == 0 {
104 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
105 | Status: http.StatusBadRequest,
106 | Message: "Failed to create warehouse section",
107 | Error: "Please fill all the fields",
108 | })
109 | }
110 | return c.JSON(http.StatusOK, response.SuccessResponse{
111 | Status: http.StatusOK,
112 | Message: "Success to update e-Fishery Warehouse Section",
113 | Data: warehouseSection,
114 | })
115 | }
116 |
117 | func (handler WarehouseSectionHandler) DeleteWarehouseSection(c echo.Context) error {
118 | id, _ := strconv.Atoi(c.Param("id"))
119 | err := handler.service.DeleteWarehouseSection(id)
120 | if err != nil {
121 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
122 | Status: http.StatusBadRequest,
123 | Message: "Failed to delete e-Fishery Warehouse Section",
124 | Error: err.Error(),
125 | })
126 | }
127 | warehouseSec, _ := handler.service.GetAllWarehouseSection()
128 | if id > len(warehouseSec) || id < 0 {
129 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
130 | Status: http.StatusBadRequest,
131 | Message: "Failed to delete e-Fishery Warehouse Section",
132 | Error: "ID not found",
133 | })
134 | }
135 | return c.JSON(http.StatusOK, response.SuccessResponse{
136 | Status: http.StatusOK,
137 | Message: "Success to delete e-Fishery Warehouse Section",
138 | })
139 | }
140 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/handler/warehouse/warehouse_workers.go:
--------------------------------------------------------------------------------
1 | package handler
2 |
3 | import (
4 | "net/http"
5 | response "warehouse-management-system-eFishery/entity/responseJson"
6 | entity "warehouse-management-system-eFishery/entity/warehouse"
7 | services "warehouse-management-system-eFishery/services/warehouse"
8 |
9 | "github.com/labstack/echo/v4"
10 | )
11 |
12 | type WarehouseWorkerHandler struct {
13 | service *services.WarehouseWorkerService
14 | }
15 |
16 | func NewWarehouseWorkerHandler(service *services.WarehouseWorkerService) *WarehouseWorkerHandler {
17 | return &WarehouseWorkerHandler{service}
18 | }
19 |
20 | func (handler WarehouseWorkerHandler) CreateWarehouseWorker(c echo.Context) error {
21 | var warehouseReq entity.CreateWarehouseWorkers
22 | var warehouseAuthChan entity.CreateWarehouseAuth
23 | c.Bind(&warehouseReq)
24 | c.Bind(&warehouseAuthChan)
25 | warehouseWorker, err := handler.service.CreateWarehouseWorker(warehouseReq, warehouseAuthChan)
26 | if err != nil {
27 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
28 | Status: http.StatusBadRequest,
29 | Message: "Failed to create warehouse worker",
30 | Error: err.Error(),
31 | })
32 | }
33 | if warehouseWorker.Email == "" || warehouseWorker.FirstName == "" || warehouseWorker.LastName == "" || warehouseWorker.Phone == "" || warehouseWorker.RolesId == 0 || warehouseWorker.WarehouseId == 0 {
34 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
35 | Status: http.StatusBadRequest,
36 | Message: "Failed to create supplier address",
37 | Error: "Please fill all the field",
38 | })
39 | }
40 | return c.JSON(http.StatusCreated, response.SuccessResponse{
41 | Status: http.StatusCreated,
42 | Message: "Success to create warehouse worker",
43 | Data: warehouseWorker,
44 | })
45 | }
46 |
47 | func (handler WarehouseWorkerHandler) GetAllWarehouseWorker(c echo.Context) error {
48 | warehouseWorkers, err := handler.service.GetAllUser()
49 | if err != nil {
50 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
51 | Status: http.StatusBadRequest,
52 | Message: "Failed to get all warehouse worker",
53 | Error: err.Error(),
54 | })
55 | }
56 | return c.JSON(http.StatusOK, response.SuccessResponse{
57 | Status: http.StatusOK,
58 | Message: "Success to get all warehouse worker",
59 | Data: warehouseWorkers,
60 | })
61 | }
62 |
63 | func (handler WarehouseWorkerHandler) GetWarehouseWorkerByUUID(c echo.Context) error {
64 | uuid := c.Param("uuid")
65 | warehouseWorker, err := handler.service.GetWarehouseWorkerByUUID(uuid)
66 | if err != nil {
67 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
68 | Status: http.StatusBadRequest,
69 | Message: "Failed to get warehouse worker",
70 | Error: err.Error(),
71 | })
72 | }
73 |
74 | if uuid == "" {
75 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
76 | Status: http.StatusBadRequest,
77 | Message: "Failed to get warehouse worker",
78 | Error: "Please fill all the field",
79 | })
80 | }
81 | if uuid != warehouseWorker.UUID {
82 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
83 | Status: http.StatusBadRequest,
84 | Message: "Failed to get warehouse worker",
85 | Error: "Worker not found",
86 | })
87 | }
88 |
89 | return c.JSON(http.StatusOK, response.SuccessResponse{
90 | Status: http.StatusOK,
91 | Message: "Success to get warehouse worker by uuid",
92 | Data: warehouseWorker,
93 | })
94 | }
95 |
96 | func (handler WarehouseWorkerHandler) UpdateWarehouseWorker(c echo.Context) error {
97 | uuid := c.Param("uuid")
98 | var warehouseReq entity.CreateWarehouseWorkers
99 | c.Bind(&warehouseReq)
100 | warehouseWorker, err := handler.service.UpdateWarehouseWorker(uuid, warehouseReq)
101 | if err != nil {
102 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
103 | Status: http.StatusBadRequest,
104 | Message: "Failed to update warehouse worker",
105 | Error: err.Error(),
106 | })
107 | }
108 | if uuid != warehouseWorker.UUID {
109 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
110 | Status: http.StatusBadRequest,
111 | Message: "Failed to get warehouse worker",
112 | Error: "Worker not found",
113 | })
114 | }
115 | if warehouseWorker.Email == "" || warehouseWorker.FirstName == "" || warehouseWorker.LastName == "" || warehouseWorker.Phone == "" || warehouseWorker.RolesId == 0 || warehouseWorker.WarehouseId == 0 {
116 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
117 | Status: http.StatusBadRequest,
118 | Message: "Failed to create supplier address",
119 | Error: "Please fill all the field",
120 | })
121 | }
122 | return c.JSON(http.StatusOK, response.SuccessResponse{
123 | Status: http.StatusOK,
124 | Message: "Success to update warehouse worker",
125 | Data: warehouseWorker,
126 | })
127 | }
128 |
129 | func (handler WarehouseWorkerHandler) DeleteWarehouseWorker(c echo.Context) error {
130 | uuid := c.Param("uuid")
131 | err := handler.service.DeleteWarehouseWorker(uuid)
132 | if err != nil {
133 | return c.JSON(http.StatusBadRequest, response.ErrorResponse{
134 | Status: http.StatusBadRequest,
135 | Message: "Failed to delete warehouse worker",
136 | Error: err.Error(),
137 | })
138 | }
139 | return c.JSON(http.StatusOK, response.SuccessResponse{
140 | Status: http.StatusOK,
141 | Message: "Success to delete warehouse worker",
142 | })
143 | }
144 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/repository/supplier/supplier.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/supplier"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceSupplierRepository interface {
10 | Store(supplier entity.Supplier) (entity.Supplier, error)
11 | FindAll() ([]entity.Supplier, error)
12 | FindByID(id int) (entity.Supplier, error)
13 | Update(supplier entity.Supplier) (entity.Supplier, error)
14 | Delete(id int) error
15 | }
16 |
17 | type SupplierRepository struct {
18 | db *gorm.DB
19 | }
20 |
21 | func NewSupplierRepository(db *gorm.DB) *SupplierRepository {
22 | return &SupplierRepository{db}
23 | }
24 |
25 | // Storing supplier data to database
26 | func (sr SupplierRepository) Store(supplier entity.Supplier) (entity.Supplier, error) {
27 | if err := sr.db.Create(&supplier).Error; err != nil {
28 | return supplier, err
29 | }
30 | return supplier, nil
31 | }
32 |
33 | // Find all supplier data from database
34 | func (sr SupplierRepository) FindAll() ([]entity.Supplier, error) {
35 | var suppliers []entity.Supplier
36 | if err := sr.db.Find(&suppliers).Error; err != nil {
37 | return suppliers, err
38 | }
39 | return suppliers, nil
40 | }
41 |
42 | // Find by ID supplier data from database
43 | func (sr SupplierRepository) FindByID(id int) (entity.Supplier, error) {
44 | var supplier entity.Supplier
45 | if err := sr.db.Where("id = ?", id).Find(&supplier).Error; err != nil {
46 | return supplier, err
47 | }
48 | return supplier, nil
49 | }
50 |
51 | // Update supplier data by id from database
52 | func (sr SupplierRepository) Update(supplier entity.Supplier) (entity.Supplier, error) {
53 | if err := sr.db.Save(&supplier).Error; err != nil {
54 | return entity.Supplier{}, err
55 | }
56 | return supplier, nil
57 | }
58 |
59 | // Delete supplier data by id from database
60 | func (sr SupplierRepository) Delete(id int) error {
61 | if err := sr.db.Where("id = ?", id).Delete(&entity.Supplier{}).Error; err != nil {
62 | return err
63 | }
64 | return nil
65 | }
66 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/repository/supplier/supplier_address.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/supplier"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceSupplierAddressRepository interface {
10 | Store(supplierAddress entity.SupplierAddress) (entity.SupplierAddress, error)
11 | FindAll() ([]entity.SupplierAddress, error)
12 | FindByID(id int) (entity.SupplierAddress, error)
13 | Update(supplierAddress entity.SupplierAddress) (entity.SupplierAddress, error)
14 | Delete(id int) error
15 | }
16 |
17 | type SupplierAddressRepository struct {
18 | db *gorm.DB
19 | }
20 |
21 | func NewSupplierAddressRepository(db *gorm.DB) *SupplierAddressRepository {
22 | return &SupplierAddressRepository{db}
23 | }
24 |
25 | // Storing supplier address data to database
26 | func (sar SupplierAddressRepository) Store(supplierAddress entity.SupplierAddress) (entity.SupplierAddress, error) {
27 | var supplier []entity.Supplier
28 | if err := sar.db.Where("id = ?", supplierAddress.SupplierID).Find(&supplier).Error; err != nil {
29 | return supplierAddress, err
30 | }
31 | supplierAddress.Supplier = supplier[0]
32 | if err := sar.db.Create(&supplierAddress).Error; err != nil {
33 | return supplierAddress, err
34 | }
35 | return supplierAddress, nil
36 | }
37 |
38 | // Find all supplier address data from database
39 | func (sar SupplierAddressRepository) FindAll() ([]entity.SupplierAddress, error) {
40 | var supplierAddresses []entity.SupplierAddress
41 | var supplier []entity.Supplier
42 | if err := sar.db.Find(&supplierAddresses).Error; err != nil {
43 | return supplierAddresses, err
44 | }
45 | for i := 0; i < len(supplierAddresses); i++ {
46 | if err := sar.db.Where("id = ?", supplierAddresses[i].SupplierID).Find(&supplier).Error; err != nil {
47 | return supplierAddresses, err
48 | }
49 | supplierAddresses[i].Supplier = supplier[0]
50 | }
51 | return supplierAddresses, nil
52 | }
53 |
54 | // Find supplier address data by id from database
55 | func (sar SupplierAddressRepository) FindByID(id int) (entity.SupplierAddress, error) {
56 | var supplierAddress entity.SupplierAddress
57 | var supplier []entity.Supplier
58 | if err := sar.db.Where("id = ?", id).Find(&supplierAddress).Error; err != nil {
59 | return supplierAddress, err
60 | }
61 | if err := sar.db.Where("id = ?", supplierAddress.SupplierID).Find(&supplier).Error; err != nil {
62 | return supplierAddress, err
63 | }
64 | supplierAddress.Supplier = supplier[0]
65 | return supplierAddress, nil
66 | }
67 |
68 | // Update supplier address data by id from database
69 | func (sar SupplierAddressRepository) Update(supplierAddress entity.SupplierAddress) (entity.SupplierAddress, error) {
70 | var supplierAddressData entity.SupplierAddress
71 | var supplier []entity.Supplier
72 | if err := sar.db.Where("id = ?", supplierAddress.ID).Find(&supplierAddressData).Error; err != nil {
73 | return supplierAddress, err
74 | }
75 | if err := sar.db.Where("id = ?", supplierAddress.SupplierID).Find(&supplier).Error; err != nil {
76 | return supplierAddress, err
77 | }
78 | supplierAddress.Supplier = supplier[0]
79 | if err := sar.db.Save(&supplierAddress).Error; err != nil {
80 | return supplierAddress, err
81 | }
82 | return supplierAddress, nil
83 | }
84 |
85 | // Delete supplier address data by id from database
86 | func (sar SupplierAddressRepository) Delete(id int) error {
87 | if err := sar.db.Delete(&entity.SupplierAddress{}, id).Error; err != nil {
88 | return err
89 | }
90 | return nil
91 | }
92 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/repository/warehouse/warehouse.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/warehouse"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceWarehouseRepository interface {
10 | Store(warehouse entity.Warehouse) (entity.Warehouse, error)
11 | FindAll() ([]entity.Warehouse, error)
12 | FindByID(id int) (entity.Warehouse, error)
13 | Update(warehouse entity.Warehouse) (entity.Warehouse, error)
14 | Delete(id int) error
15 | }
16 |
17 | type WarehouseRepository struct {
18 | db *gorm.DB
19 | }
20 |
21 | func NewWarehouseRepository(db *gorm.DB) *WarehouseRepository {
22 | return &WarehouseRepository{db}
23 | }
24 |
25 | // Storing warehouse data to database
26 | func (wr WarehouseRepository) Store(warehouse entity.Warehouse) (entity.Warehouse, error) {
27 | if err := wr.db.Create(&warehouse).Error; err != nil {
28 | return warehouse, err
29 | }
30 | return warehouse, nil
31 | }
32 |
33 | // Find all warehouse data from database
34 | func (wr WarehouseRepository) FindAll() ([]entity.Warehouse, error) {
35 | var warehouses []entity.Warehouse
36 | if err := wr.db.Find(&warehouses).Error; err != nil {
37 | return warehouses, err
38 | }
39 | return warehouses, nil
40 | }
41 |
42 | // Find warehouse data by id from database
43 | func (wr WarehouseRepository) FindByID(id int) (entity.Warehouse, error) {
44 | var warehouse entity.Warehouse
45 | if err := wr.db.Where("id = ?", id).Find(&warehouse).Error; err != nil {
46 | return warehouse, err
47 | }
48 | return warehouse, nil
49 | }
50 |
51 | // Update warehouse data by id from database
52 | func (wr WarehouseRepository) Update(warehouse entity.Warehouse) (entity.Warehouse, error) {
53 | if err := wr.db.Save(&warehouse).Error; err != nil {
54 | return entity.Warehouse{}, err
55 | }
56 | return warehouse, nil
57 | }
58 |
59 | // Delete warehouse data by id from database
60 | func (wr WarehouseRepository) Delete(id int) error {
61 | if err := wr.db.Where("id = ?", id).Delete(&entity.Warehouse{}).Error; err != nil {
62 | return err
63 | }
64 | return nil
65 | }
66 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/repository/warehouse/warehouse_address.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/warehouse"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceWarehouseAddressRepository interface {
10 | Store(warehouseAddress entity.WarehouseAddress) (entity.WarehouseAddress, error)
11 | FindAll() ([]entity.WarehouseAddress, error)
12 | FindByID(id int) (entity.WarehouseAddress, error)
13 | Update(warehouseAddress entity.WarehouseAddress) (entity.WarehouseAddress, error)
14 | Delete(id int) error
15 | }
16 |
17 | type WarehouseAddressRepository struct {
18 | db *gorm.DB
19 | }
20 |
21 | func NewWarehouseAddressRepository(db *gorm.DB) *WarehouseAddressRepository {
22 | return &WarehouseAddressRepository{db}
23 | }
24 |
25 | // Creating warehouse address data to database
26 | func (war WarehouseAddressRepository) Store(warehouseAddress entity.WarehouseAddress) (entity.WarehouseAddress, error) {
27 | var warehouse []entity.Warehouse
28 | if err := war.db.Where("id = ?", warehouseAddress.WarehouseID).Find(&warehouse).Error; err != nil {
29 | return warehouseAddress, err
30 | }
31 | warehouseAddress.Warehouse = warehouse[0]
32 | if err := war.db.Create(&warehouseAddress).Error; err != nil {
33 | return warehouseAddress, err
34 | }
35 | return warehouseAddress, nil
36 | }
37 |
38 | // Find all warehouse address data from database
39 | func (war WarehouseAddressRepository) FindAll() ([]entity.WarehouseAddress, error) {
40 | var warehouseAddresses []entity.WarehouseAddress
41 | var warehouse []entity.Warehouse
42 | if err := war.db.Find(&warehouseAddresses).Error; err != nil {
43 | return warehouseAddresses, err
44 | }
45 | for i := 0; i < len(warehouseAddresses); i++ {
46 | if err := war.db.Where("id = ?", warehouseAddresses[i].WarehouseID).Find(&warehouse).Error; err != nil {
47 | return warehouseAddresses, err
48 | }
49 | warehouseAddresses[i].Warehouse = warehouse[0]
50 | }
51 | return warehouseAddresses, nil
52 | }
53 |
54 | // Find warehouse address data by id from database
55 | func (war WarehouseAddressRepository) FindByID(id int) (entity.WarehouseAddress, error) {
56 | var warehouseAddress entity.WarehouseAddress
57 | var warehouse []entity.Warehouse
58 | if err := war.db.Where("id = ?", id).Find(&warehouseAddress).Error; err != nil {
59 | return warehouseAddress, err
60 | }
61 | if err := war.db.Where("id = ?", warehouseAddress.WarehouseID).Find(&warehouse).Error; err != nil {
62 | return warehouseAddress, err
63 | }
64 | warehouseAddress.Warehouse = warehouse[0]
65 |
66 | return warehouseAddress, nil
67 | }
68 |
69 | // Update warehouse address data by id from database
70 | func (war WarehouseAddressRepository) Update(warehouseAddress entity.WarehouseAddress) (entity.WarehouseAddress, error) {
71 | var warehouse []entity.Warehouse
72 | if err := war.db.Save(&warehouseAddress).Error; err != nil {
73 | return entity.WarehouseAddress{}, err
74 | }
75 | if err := war.db.Where("id = ?", warehouseAddress.WarehouseID).Find(&warehouse).Error; err != nil {
76 | return entity.WarehouseAddress{}, err
77 | }
78 | warehouseAddress.Warehouse = warehouse[0]
79 | return warehouseAddress, nil
80 | }
81 |
82 | // Delete warehouse address data by id from database
83 | func (war WarehouseAddressRepository) Delete(id int) error {
84 | if err := war.db.Where("id = ?", id).Delete(&entity.WarehouseAddress{}).Error; err != nil {
85 | return err
86 | }
87 | return nil
88 | }
89 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/repository/warehouse/warehouse_categories.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/warehouse"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceWarehouseCategoriesRepository interface {
10 | Store(warehouseCategories entity.WarehouseCategories) (entity.WarehouseCategories, error)
11 | FindAll() ([]entity.WarehouseCategories, error)
12 | FindByID(id int) (entity.WarehouseCategories, error)
13 | Update(warehouseCategories entity.WarehouseCategories) (entity.WarehouseCategories, error)
14 | Delete(id int) error
15 | }
16 |
17 | type WarehouseCategoriesRepository struct {
18 | db *gorm.DB
19 | }
20 |
21 | func NewWarehouseCategoriesRepository(db *gorm.DB) *WarehouseCategoriesRepository {
22 | return &WarehouseCategoriesRepository{db}
23 | }
24 |
25 | // Storing warehouse categories data to database
26 | func (wcr WarehouseCategoriesRepository) Store(warehouseCategories entity.WarehouseCategories) (entity.WarehouseCategories, error) {
27 | if err := wcr.db.Create(&warehouseCategories).Error; err != nil {
28 | return warehouseCategories, err
29 | }
30 | return warehouseCategories, nil
31 | }
32 |
33 | // Find all warehouse categories data from database
34 | func (wcr WarehouseCategoriesRepository) FindAll() ([]entity.WarehouseCategories, error) {
35 | var warehouseCategories []entity.WarehouseCategories
36 | if err := wcr.db.Find(&warehouseCategories).Error; err != nil {
37 | return warehouseCategories, err
38 | }
39 | return warehouseCategories, nil
40 | }
41 |
42 | // Find by ID warehouse categories data from database
43 | func (wcr WarehouseCategoriesRepository) FindByID(id int) (entity.WarehouseCategories, error) {
44 | var warehouseCategories entity.WarehouseCategories
45 | if err := wcr.db.Where("id = ?", id).Find(&warehouseCategories).Error; err != nil {
46 | return warehouseCategories, err
47 | }
48 | return warehouseCategories, nil
49 | }
50 |
51 | // Update warehouse categories data by id from database
52 | func (wcr WarehouseCategoriesRepository) Update(warehouseCategories entity.WarehouseCategories) (entity.WarehouseCategories, error) {
53 | if err := wcr.db.Save(&warehouseCategories).Error; err != nil {
54 | return entity.WarehouseCategories{}, err
55 | }
56 | return warehouseCategories, nil
57 | }
58 |
59 | // Delete warehouse categories data by id from database
60 | func (wcr WarehouseCategoriesRepository) Delete(id int) error {
61 | if err := wcr.db.Where("id = ?", id).Delete(&entity.WarehouseCategories{}).Error; err != nil {
62 | return err
63 | }
64 | return nil
65 | }
66 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/repository/warehouse/warehouse_orders.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/warehouse"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceWarehouseOrderRepository interface {
10 | Store(entity.WarehouseOrders) (entity.WarehouseOrders, error)
11 | FindAll() ([]entity.WarehouseOrders, error)
12 | FindByID(int) (entity.WarehouseOrders, error)
13 | FindByProductStatus(string) ([]entity.WarehouseOrders, error)
14 | FindByProductMark(string) ([]entity.WarehouseOrders, error)
15 | UpdateByID(int, entity.WarehouseOrders) (entity.WarehouseOrders, error)
16 | DeleteByID(id int) error
17 | }
18 |
19 | type WarehouseOrderRepository struct {
20 | db *gorm.DB
21 | }
22 |
23 | func NewWarehouseOrderRepository(db *gorm.DB) *WarehouseOrderRepository {
24 | return &WarehouseOrderRepository{db}
25 | }
26 |
27 | // Storing warehouse order data to database
28 | func (wor WarehouseOrderRepository) Store(warehouseOrder entity.WarehouseOrders) (entity.WarehouseOrders, error) {
29 | var warehouse []entity.Warehouse
30 | if err := wor.db.Where("id = ?", warehouseOrder.WarehouseId).Find(&warehouse).Error; err != nil {
31 | return warehouseOrder, err
32 | }
33 | warehouseOrder.Warehouse = warehouse[0]
34 | if err := wor.db.Create(&warehouseOrder).Error; err != nil {
35 | return warehouseOrder, err
36 | }
37 | return warehouseOrder, nil
38 | }
39 |
40 | // Find all warehouse order data from database
41 | func (wor WarehouseOrderRepository) FindAll() ([]entity.WarehouseOrders, error) {
42 | var warehouseOrders []entity.WarehouseOrders
43 | var warehouse []entity.Warehouse
44 | if err := wor.db.Find(&warehouseOrders).Error; err != nil {
45 | return warehouseOrders, err
46 | }
47 |
48 | // Find from id of warehouse from warehouse order
49 | for i := 0; i < len(warehouseOrders); i++ {
50 | if err := wor.db.Where("id = ?", warehouseOrders[i].WarehouseId).Find(&warehouse).Error; err != nil {
51 | return warehouseOrders, err
52 | }
53 | warehouseOrders[i].Warehouse = warehouse[0]
54 | }
55 | return warehouseOrders, nil
56 | }
57 |
58 | // Find warehouse order data by ID
59 | func (wor WarehouseOrderRepository) FindByID(id int) (entity.WarehouseOrders, error) {
60 | var warehouseOrders entity.WarehouseOrders
61 | var warehouse []entity.Warehouse
62 | if err := wor.db.Where("id = ?", id).First(&warehouseOrders).Error; err != nil {
63 | return warehouseOrders, err
64 | }
65 | if err := wor.db.Where("id = ?", warehouseOrders.WarehouseId).First(&warehouse).Error; err != nil {
66 | return warehouseOrders, err
67 | }
68 | warehouseOrders.Warehouse = warehouse[0]
69 | return warehouseOrders, nil
70 | }
71 |
72 | // Find product status in order
73 | func (wor WarehouseOrderRepository) FindByProductStatus(productStatus string) ([]entity.WarehouseOrders, error) {
74 | var warehouseOrders []entity.WarehouseOrders
75 | var warehouse []entity.Warehouse
76 | if err := wor.db.Where("product_status = ?", productStatus).Find(&warehouseOrders).Error; err != nil {
77 | return warehouseOrders, err
78 | }
79 | for i := 0; i < len(warehouseOrders); i++ {
80 | if err := wor.db.Where("id = ?", warehouseOrders[i].WarehouseId).Find(&warehouse).Error; err != nil {
81 | return warehouseOrders, err
82 | }
83 | warehouseOrders[i].Warehouse = warehouse[0]
84 | }
85 | return warehouseOrders, nil
86 | }
87 |
88 | // Find warehouse order data by product marking in or out
89 | func (wor WarehouseOrderRepository) FindByProductMark(productMark string) ([]entity.WarehouseOrders, error) {
90 | var warehouseOrders []entity.WarehouseOrders
91 | var warehouse []entity.Warehouse
92 | if err := wor.db.Where("product_mark = ?", productMark).Find(&warehouseOrders).Error; err != nil {
93 | return warehouseOrders, err
94 | }
95 | for i := 0; i < len(warehouseOrders); i++ {
96 | if err := wor.db.Where("id = ?", warehouseOrders[i].WarehouseId).Find(&warehouse).Error; err != nil {
97 | return warehouseOrders, err
98 | }
99 | warehouseOrders[i].Warehouse = warehouse[0]
100 | }
101 | return warehouseOrders, nil
102 | }
103 |
104 | // Update warehouse order data by ID
105 | func (wor WarehouseOrderRepository) UpdateByID(id int, warehouseOrder entity.WarehouseOrders) (entity.WarehouseOrders, error) {
106 | if err := wor.db.Model(&warehouseOrder).Where("id = ?", id).Updates(warehouseOrder).Error; err != nil {
107 | return warehouseOrder, err
108 | }
109 | var warehouse []entity.Warehouse
110 | if err := wor.db.Where("id = ?", warehouseOrder.WarehouseId).Find(&warehouse).Error; err != nil {
111 | return warehouseOrder, err
112 | }
113 | warehouseOrder.Warehouse = warehouse[0]
114 |
115 | return warehouseOrder, nil
116 | }
117 |
118 | // Delete warehouse order data by ID
119 | func (wor WarehouseOrderRepository) DeleteByID(id int) error {
120 | if err := wor.db.Where("id = ?", id).Delete(&entity.WarehouseOrders{}).Error; err != nil {
121 | return err
122 | }
123 | return nil
124 | }
125 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/repository/warehouse/warehouse_roles.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/warehouse"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceWarehouseRolesRepository interface {
10 | Store(warehouseRoles entity.WarehouseRoles) (entity.WarehouseRoles, error)
11 | FindAll() ([]entity.WarehouseRoles, error)
12 | FindByID(id int) (entity.WarehouseRoles, error)
13 | Update(warehouseRoles entity.WarehouseRoles) (entity.WarehouseRoles, error)
14 | Delete(id int) error
15 | }
16 |
17 | type WarehouseRolesRepository struct {
18 | db *gorm.DB
19 | }
20 |
21 | func NewWarehouseRolesRepository(db *gorm.DB) *WarehouseRolesRepository {
22 | return &WarehouseRolesRepository{db}
23 | }
24 |
25 | // Storing warehouse roles data to database
26 | func (wrr WarehouseRolesRepository) Store(warehouseRoles entity.WarehouseRoles) (entity.WarehouseRoles, error) {
27 | if err := wrr.db.Create(&warehouseRoles).Error; err != nil {
28 | return warehouseRoles, err
29 | }
30 | return warehouseRoles, nil
31 | }
32 |
33 | // Find all warehouse roles data from database
34 | func (wrr WarehouseRolesRepository) FindAll() ([]entity.WarehouseRoles, error) {
35 | var warehouseRoles []entity.WarehouseRoles
36 | if err := wrr.db.Find(&warehouseRoles).Error; err != nil {
37 | return warehouseRoles, err
38 | }
39 | return warehouseRoles, nil
40 | }
41 |
42 | // Find warehouse roles data by id from database
43 | func (wrr WarehouseRolesRepository) FindByID(id int) (entity.WarehouseRoles, error) {
44 | var warehouseRoles entity.WarehouseRoles
45 | if err := wrr.db.Where("id = ?", id).Find(&warehouseRoles).Error; err != nil {
46 | return warehouseRoles, err
47 | }
48 | return warehouseRoles, nil
49 | }
50 |
51 | // Update warehouse roles data by id from database
52 | func (wrr WarehouseRolesRepository) Update(warehouseRoles entity.WarehouseRoles) (entity.WarehouseRoles, error) {
53 | if err := wrr.db.Save(&warehouseRoles).Error; err != nil {
54 | return entity.WarehouseRoles{}, err
55 | }
56 | return warehouseRoles, nil
57 | }
58 |
59 | // Delete warehouse roles data by id from database
60 | func (wrr WarehouseRolesRepository) Delete(id int) error {
61 | if err := wrr.db.Where("id = ?", id).Delete(&entity.WarehouseRoles{}).Error; err != nil {
62 | return err
63 | }
64 | return nil
65 | }
66 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/repository/warehouse/warehouse_section.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/warehouse"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceWarehouseSectionRepository interface {
10 | Store(entity.WarehouseSection) (entity.WarehouseSection, error)
11 | FindAll() ([]entity.WarehouseSection, error)
12 | FindByID(int) (entity.WarehouseSection, error)
13 | Update(entity.WarehouseSection) (entity.WarehouseSection, error)
14 | Delete(int) error
15 | }
16 |
17 | type WarehouseSectionRepository struct {
18 | db *gorm.DB
19 | }
20 |
21 | func NewWarehouseSectionRepository(db *gorm.DB) *WarehouseSectionRepository {
22 | return &WarehouseSectionRepository{db}
23 | }
24 |
25 | // Storing warehouse section data to database
26 | func (wsr WarehouseSectionRepository) Store(warehouseSection entity.WarehouseSection) (entity.WarehouseSection, error) {
27 | var warehouse []entity.Warehouse
28 | if err := wsr.db.Where("id = ?", warehouseSection.WarehouseID).Find(&warehouse).Error; err != nil {
29 | return warehouseSection, err
30 | }
31 | warehouseSection.Warehouse = warehouse[0]
32 | if err := wsr.db.Create(&warehouseSection).Error; err != nil {
33 | return warehouseSection, err
34 | }
35 | return warehouseSection, nil
36 | }
37 |
38 | // Find all warehouse section data from database
39 | func (wsr WarehouseSectionRepository) FindAll() ([]entity.WarehouseSection, error) {
40 | var warehouseSections []entity.WarehouseSection
41 | var warehouse []entity.Warehouse
42 | if err := wsr.db.Find(&warehouseSections).Error; err != nil {
43 | return warehouseSections, err
44 | }
45 | for i := 0; i < len(warehouseSections); i++ {
46 | if err := wsr.db.Where("id = ?", warehouseSections[i].WarehouseID).Find(&warehouse).Error; err != nil {
47 | return warehouseSections, err
48 | }
49 | warehouseSections[i].Warehouse = warehouse[0]
50 | }
51 | return warehouseSections, nil
52 | }
53 |
54 | // Find warehouse section data by id from database
55 | func (wsr WarehouseSectionRepository) FindByID(id int) (entity.WarehouseSection, error) {
56 | var warehouseSection entity.WarehouseSection
57 | var warehouse []entity.Warehouse
58 | if err := wsr.db.Where("id = ?", id).Find(&warehouseSection).Error; err != nil {
59 | return warehouseSection, err
60 | }
61 | if err := wsr.db.Where("id = ?", warehouseSection.WarehouseID).Find(&warehouse).Error; err != nil {
62 | return warehouseSection, err
63 | }
64 | warehouseSection.Warehouse = warehouse[0]
65 | return warehouseSection, nil
66 | }
67 |
68 | // Update warehouse section data by id from database
69 | func (wsr WarehouseSectionRepository) Update(warehouseSection entity.WarehouseSection) (entity.WarehouseSection, error) {
70 | var warehouse []entity.Warehouse
71 | if err := wsr.db.Where("id = ?", warehouseSection.WarehouseID).Find(&warehouse).Error; err != nil {
72 | return warehouseSection, err
73 | }
74 | warehouseSection.Warehouse = warehouse[0]
75 | if err := wsr.db.Save(&warehouseSection).Error; err != nil {
76 | return warehouseSection, err
77 | }
78 | return warehouseSection, nil
79 | }
80 |
81 | // Delete warehouse section data by id from database
82 | func (wsr WarehouseSectionRepository) Delete(id int) error {
83 | var warehouseSection entity.WarehouseSection
84 | if err := wsr.db.Where("id = ?", id).Delete(&warehouseSection).Error; err != nil {
85 | return err
86 | }
87 | return nil
88 | }
89 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/repository/warehouse/warehouse_workers.go:
--------------------------------------------------------------------------------
1 | package repository
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/warehouse"
5 |
6 | "gorm.io/gorm"
7 | )
8 |
9 | type InterfaceWarehouseWorkersRepository interface {
10 | Store(entity.WarehouseWorkers, entity.WarehouseAuth) (entity.WarehouseWorkers, error)
11 | FindAll() ([]entity.WarehouseWorkers, error)
12 | FindByUUID(uuid string) (entity.WarehouseWorkers, error)
13 | UpdateByUUID(uuid string, warehouseWorkers entity.WarehouseWorkers) (entity.WarehouseWorkers, error)
14 | DeleteByUUID(uuid string) error
15 | }
16 |
17 | type WarehouseWorkersRepository struct {
18 | db *gorm.DB
19 | }
20 |
21 | func NewWarehouseWorkersRepository(db *gorm.DB) *WarehouseWorkersRepository {
22 | return &WarehouseWorkersRepository{db}
23 | }
24 |
25 | // Storing warehouse workers data to database and to warehouse auth table
26 | func (wwr WarehouseWorkersRepository) Store(warehouseWorkers entity.WarehouseWorkers, warehouseWorkerAuth entity.WarehouseAuth) (entity.WarehouseWorkers, error) {
27 | if err := wwr.db.Create(&warehouseWorkers).Error; err != nil {
28 | return warehouseWorkers, err
29 | }
30 | var warehouse []entity.Warehouse
31 | if err := wwr.db.Where("id = ?", warehouseWorkers.WarehouseId).Find(&warehouse).Error; err != nil {
32 | return warehouseWorkers, err
33 | }
34 | warehouseWorkers.Warehouse = warehouse[0]
35 |
36 | if err := wwr.db.Create(&warehouseWorkerAuth).Error; err != nil {
37 | return warehouseWorkers, err
38 | }
39 | return warehouseWorkers, nil
40 |
41 | }
42 |
43 | // Find all warehouse workers data
44 | func (wwr WarehouseWorkersRepository) FindAll() ([]entity.WarehouseWorkers, error) {
45 | var warehouseWorkers []entity.WarehouseWorkers
46 | if err := wwr.db.Find(&warehouseWorkers).Error; err != nil {
47 | return warehouseWorkers, err
48 | }
49 | return warehouseWorkers, nil
50 | }
51 |
52 | // Find warehouse workers data by UUID
53 | func (wwr WarehouseWorkersRepository) FindByUUID(uuid string) (entity.WarehouseWorkers, error) {
54 | var warehouseWorkers entity.WarehouseWorkers
55 | if err := wwr.db.Where("uuid = ?", uuid).Find(&warehouseWorkers).Error; err != nil {
56 | return entity.WarehouseWorkers{}, err
57 | }
58 | return warehouseWorkers, nil
59 | }
60 |
61 | // Update warehouse workers data by UUID
62 | func (wwr WarehouseWorkersRepository) UpdateByUUID(uuid string, warehouseWorkers entity.WarehouseWorkers) (entity.WarehouseWorkers, error) {
63 | if err := wwr.db.Where("uuid = ?", uuid).First(&warehouseWorkers).Error; err != nil {
64 | return warehouseWorkers, err
65 | }
66 | if err := wwr.db.Save(&warehouseWorkers).Error; err != nil {
67 | return warehouseWorkers, err
68 | }
69 | return warehouseWorkers, nil
70 | }
71 |
72 | // Delete warehouse workers data by UUID
73 | func (wwr WarehouseWorkersRepository) DeleteByUUID(uuid string) error {
74 | var warehouseWorkerAuth entity.WarehouseAuth
75 | if err := wwr.db.Where("uuid = ?", uuid).Delete(&warehouseWorkerAuth).Error; err != nil {
76 | return err
77 | }
78 | var warehouseWorkers entity.WarehouseWorkers
79 | if err := wwr.db.Where("uuid = ?", uuid).Delete(&warehouseWorkers).Error; err != nil {
80 | return err
81 | }
82 | return nil
83 | }
84 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/supplier/supplier.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/supplier"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func RoutesSupplier(e *echo.Echo, supplierHandler *handler.SupplierHandler) {
10 | e.POST("/api/supplier", supplierHandler.CreateSupplier)
11 | e.GET("/api/supplier", supplierHandler.GetAllSupplier)
12 | e.GET("/api/supplier/:id", supplierHandler.GetSupplierByID)
13 | e.PUT("/api/supplier/:id", supplierHandler.UpdateSupplier)
14 | e.DELETE("/api/supplier/:id", supplierHandler.DeleteSupplier)
15 | }
16 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/supplier/supplier_address.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/supplier"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func RoutesSupplierAddress(e *echo.Echo, supplierAddressHandler *handler.SupplierAddressHandler) {
10 | e.POST("/api/supplier/address", supplierAddressHandler.CreateSupplierAddress)
11 | e.GET("/api/supplier/address", supplierAddressHandler.GetAllSupplierAddress)
12 | e.GET("/api/supplier/address/:id", supplierAddressHandler.GetSupplierAddressById)
13 | e.PUT("/api/supplier/address/:id", supplierAddressHandler.UpdateSupplierAddress)
14 | e.DELETE("/api/supplier/address/:id", supplierAddressHandler.DeleteSupplierAddress)
15 | }
16 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/warehouse/warehouse.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/warehouse"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func Routes(e *echo.Echo, warehouseHandler *handler.WarehouseHandler) {
10 | e.POST("/api/warehouse", warehouseHandler.CreateWarehouse)
11 | e.GET("/api/warehouse", warehouseHandler.GetAllWarehouse)
12 | e.GET("/api/warehouse/:id", warehouseHandler.GetWarehouseByID)
13 | e.PUT("/api/warehouse/:id", warehouseHandler.UpdateWarehouse)
14 | e.DELETE("/api/warehouse/:id", warehouseHandler.DeleteWarehouse)
15 | }
16 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/warehouse/warehouse_address.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/warehouse"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func RoutesAddress(e *echo.Echo, warehouseAddressHandler *handler.WarehouseAddressHandler) {
10 | e.POST("/api/warehouse/address", warehouseAddressHandler.CreateWarehouseAddress)
11 | e.GET("/api/warehouse/address", warehouseAddressHandler.GetAllWarehouseAddress)
12 | e.GET("/api/warehouse/address/:id", warehouseAddressHandler.GetWarehouseAddressByID)
13 | e.PUT("/api/warehouse/address/:id", warehouseAddressHandler.UpdateWarehouseAddress)
14 | e.DELETE("/api/warehouse/address/:id", warehouseAddressHandler.DeleteWarehouseAddress)
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/warehouse/warehouse_categories.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/warehouse"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func RoutesCategory(e *echo.Echo, warehouseCategoryHandler *handler.WarehouseCategoryHandler) {
10 | e.POST("/api/warehouse/category", warehouseCategoryHandler.CreateWarehouseCategory)
11 | e.GET("/api/warehouse/category", warehouseCategoryHandler.GetAllWarehouseCategory)
12 | e.GET("/api/warehouse/category/:id", warehouseCategoryHandler.GetWarehouseCategoryByID)
13 | e.PUT("/api/warehouse/category/:id", warehouseCategoryHandler.UpdateWarehouseCategory)
14 | e.DELETE("/api/warehouse/category/:id", warehouseCategoryHandler.DeleteWarehouseCategory)
15 | }
16 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/warehouse/warehouse_orders.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/warehouse"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func RouteOreders(e *echo.Echo, warehouseOrderHandler *handler.WarehouseOrdersHandler) {
10 | e.POST("/api/warehouse/order", warehouseOrderHandler.CreateWarehouseOrder)
11 | e.GET("/api/warehouse/order", warehouseOrderHandler.GetAllWarehouseOrder)
12 | e.GET("/api/warehouse/order/:id", warehouseOrderHandler.GetWarehouseOrderById)
13 | e.GET("/api/warehouse/order/status/:product_status", warehouseOrderHandler.GetWarehouseOrderByProductStatus)
14 | e.GET("/api/warehouse/order/mark/:product_mark", warehouseOrderHandler.GetWarehouseOrderByProductMark)
15 | e.PUT("/api/warehouse/order/:id", warehouseOrderHandler.UpdateWarehouseOrderById)
16 | e.DELETE("/api/warehouse/order/:id", warehouseOrderHandler.DeleteWarehouseOrderById)
17 | }
18 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/warehouse/warehouse_product.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/warehouse"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func RoutesProducts(e *echo.Echo, warehouseProductHandler *handler.WarehouseProductHandler) {
10 | e.POST("/api/warehouse/product", warehouseProductHandler.CreateWarehouseProduct)
11 | e.GET("/api/warehouse/product", warehouseProductHandler.GetAllWarehouseProduct)
12 | e.GET("/api/warehouse/product/:id", warehouseProductHandler.GetWarehouseProductByID)
13 | e.GET("/api/warehouse/product/:minPrice/:maxPrice", warehouseProductHandler.GetWarehouseProductByPrice)
14 | e.PUT("/api/warehouse/product/:id", warehouseProductHandler.UpdateWarehouseProduct)
15 | e.DELETE("/api/warehouse/product/:id", warehouseProductHandler.DeleteWarehouseProduct)
16 | }
17 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/warehouse/warehouse_roles.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/warehouse"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func RoutesRoles(e *echo.Echo, warehouseRolesHandler *handler.WarehouseRolesHandler) {
10 | e.POST("/api/warehouse/roles", warehouseRolesHandler.CreateWarehouseRoles)
11 | e.GET("/api/warehouse/roles", warehouseRolesHandler.GetAllWarehouseRoles)
12 | e.GET("/api/warehouse/roles/:id", warehouseRolesHandler.GetWarehouseRolesByID)
13 | e.PUT("/api/warehouse/roles/:id", warehouseRolesHandler.UpdateWarehouseRoles)
14 | e.DELETE("/api/warehouse/roles/:id", warehouseRolesHandler.DeleteWarehouseRoles)
15 | }
16 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/warehouse/warehouse_section.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/warehouse"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func RoutesSection(e *echo.Echo, warehouseSectionHandler *handler.WarehouseSectionHandler) {
10 | e.POST("/api/warehouse/section", warehouseSectionHandler.CreateWarehouseSection)
11 | e.GET("/api/warehouse/section", warehouseSectionHandler.GetAllWarehouseSection)
12 | e.GET("/api/warehouse/section/:id", warehouseSectionHandler.GetWarehouseSectionByID)
13 | e.PUT("/api/warehouse/section/:id", warehouseSectionHandler.UpdateWarehouseSection)
14 | e.DELETE("/api/warehouse/section/:id", warehouseSectionHandler.DeleteWarehouseSection)
15 | }
16 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/routes/warehouse/warehouse_worker.go:
--------------------------------------------------------------------------------
1 | package routes
2 |
3 | import (
4 | handler "warehouse-management-system-eFishery/handler/warehouse"
5 |
6 | "github.com/labstack/echo/v4"
7 | )
8 |
9 | func RoutesWorkers(e *echo.Echo, warehouseWorkerHandler *handler.WarehouseWorkerHandler) {
10 | e.POST("/api/warehouse/worker", warehouseWorkerHandler.CreateWarehouseWorker)
11 | e.GET("/api/warehouse/worker", warehouseWorkerHandler.GetAllWarehouseWorker)
12 | e.GET("/api/warehouse/worker/:uuid", warehouseWorkerHandler.GetWarehouseWorkerByUUID)
13 | e.PUT("/api/warehouse/worker/:uuid", warehouseWorkerHandler.UpdateWarehouseWorker)
14 | e.DELETE("/api/warehouse/worker/:uuid", warehouseWorkerHandler.DeleteWarehouseWorker)
15 | }
16 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/server.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | config "warehouse-management-system-eFishery/config/database"
5 |
6 | handlerSupplier "warehouse-management-system-eFishery/handler/supplier"
7 | repositorySupplier "warehouse-management-system-eFishery/repository/supplier"
8 | routesSupplier "warehouse-management-system-eFishery/routes/supplier"
9 | servicesSupplier "warehouse-management-system-eFishery/services/supplier"
10 |
11 | handlerWarehouse "warehouse-management-system-eFishery/handler/warehouse"
12 | repositoryWarehouse "warehouse-management-system-eFishery/repository/warehouse"
13 | routesWarehouse "warehouse-management-system-eFishery/routes/warehouse"
14 | servicesWarehouse "warehouse-management-system-eFishery/services/warehouse"
15 |
16 | "github.com/labstack/echo/v4"
17 | "github.com/labstack/echo/v4/middleware"
18 | )
19 |
20 | func main() {
21 | config.Connect()
22 | config.Migrate()
23 | e := echo.New()
24 |
25 | e.Use((middleware.Logger()))
26 | e.Use(middleware.Recover())
27 |
28 | // Warehouse Section
29 | warehouseProductRepository := repositoryWarehouse.NewWarehouseProductRepository(config.DB)
30 | warehouseProductService := servicesWarehouse.NewWarehouseProductService(warehouseProductRepository)
31 | warehouseProductHandler := handlerWarehouse.NewWarehouseProductHandler(warehouseProductService)
32 | routesWarehouse.RoutesProducts(e, warehouseProductHandler)
33 |
34 | warehouseWorkerRepository := repositoryWarehouse.NewWarehouseWorkersRepository(config.DB)
35 | warehouseWorkerService := servicesWarehouse.NewWarehouseWorkerService(warehouseWorkerRepository)
36 | warehouseWorkerHandler := handlerWarehouse.NewWarehouseWorkerHandler(warehouseWorkerService)
37 | routesWarehouse.RoutesWorkers(e, warehouseWorkerHandler)
38 |
39 | warehouseOrderRepository := repositoryWarehouse.NewWarehouseOrderRepository(config.DB)
40 | warehouseOrderService := servicesWarehouse.NewWarehouseOrderService(warehouseOrderRepository)
41 | warehouseOrderHandler := handlerWarehouse.NewWarehouseOrdersHandler(warehouseOrderService)
42 | routesWarehouse.RouteOreders(e, warehouseOrderHandler)
43 |
44 | warehouseRepository := repositoryWarehouse.NewWarehouseRepository(config.DB)
45 | warehouseService := servicesWarehouse.NewWarehouseService(warehouseRepository)
46 | warehouseHandler := handlerWarehouse.NewWarehouseHandler(warehouseService)
47 | routesWarehouse.Routes(e, warehouseHandler)
48 |
49 | warehouseAddressRepository := repositoryWarehouse.NewWarehouseAddressRepository(config.DB)
50 | warehouseAddressService := servicesWarehouse.NewWarehouseAddressService(warehouseAddressRepository)
51 | warehouseAddressHandler := handlerWarehouse.NewWarehouseAddressHandler(warehouseAddressService)
52 | routesWarehouse.RoutesAddress(e, warehouseAddressHandler)
53 |
54 | warehouseCategoryRepository := repositoryWarehouse.NewWarehouseCategoriesRepository(config.DB)
55 | warehouseCategoryService := servicesWarehouse.NewWarehouseCategoryService(warehouseCategoryRepository)
56 | warehouseCategoryHandler := handlerWarehouse.NewWarehouseCategoryHandler(warehouseCategoryService)
57 | routesWarehouse.RoutesCategory(e, warehouseCategoryHandler)
58 |
59 | warehouseRolesRepository := repositoryWarehouse.NewWarehouseRolesRepository(config.DB)
60 | warehouseRolesService := servicesWarehouse.NewWarehouseRolesService(warehouseRolesRepository)
61 | warehouseRolesHandler := handlerWarehouse.NewWarehouseRolesHandler(warehouseRolesService)
62 | routesWarehouse.RoutesRoles(e, warehouseRolesHandler)
63 |
64 | warehouseSectionRepository := repositoryWarehouse.NewWarehouseSectionRepository(config.DB)
65 | warehouseSectionService := servicesWarehouse.NewWarehouseSectionService(warehouseSectionRepository)
66 | warehouseSectionHandler := handlerWarehouse.NewWarehouseSectionHandler(warehouseSectionService)
67 | routesWarehouse.RoutesSection(e, warehouseSectionHandler)
68 |
69 | supplierRepository := repositorySupplier.NewSupplierRepository(config.DB)
70 | supplierService := servicesSupplier.NewSupplierService(supplierRepository)
71 | supplierHandler := handlerSupplier.NewSupplierHandler(supplierService)
72 | routesSupplier.RoutesSupplier(e, supplierHandler)
73 |
74 | supplierAddressRepository := repositorySupplier.NewSupplierAddressRepository(config.DB)
75 | supplierAddressService := servicesSupplier.NewSupplierAddressService(supplierAddressRepository)
76 | supplierAddressHandler := handlerSupplier.NewSupplierAddressHandler(supplierAddressService)
77 | routesSupplier.RoutesSupplierAddress(e, supplierAddressHandler)
78 |
79 | e.Logger.Fatal(e.Start(":8080"))
80 | }
81 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/services/supplier/supplier.go:
--------------------------------------------------------------------------------
1 | package services
2 |
3 | import (
4 | "time"
5 | entity "warehouse-management-system-eFishery/entity/supplier"
6 | repository "warehouse-management-system-eFishery/repository/supplier"
7 | )
8 |
9 | type InterfaceSupplierService interface {
10 | CreateSupplier(supplier entity.Supplier) (entity.Supplier, error)
11 | GetAllSupplier() ([]entity.Supplier, error)
12 | GetSupplierByID(id int) (entity.Supplier, error)
13 | UpdateSupplier(id int, supplierReq entity.UpdateSupplier) (entity.Supplier, error)
14 | DeleteSupplier(id int) error
15 | }
16 |
17 | type SupplierService struct {
18 | supplierRepository repository.InterfaceSupplierRepository
19 | }
20 |
21 | func NewSupplierService(supplierRepository repository.InterfaceSupplierRepository) *SupplierService {
22 | return &SupplierService{supplierRepository}
23 | }
24 |
25 | func (service SupplierService) CreateSupplier(supplier entity.Supplier) (entity.Supplier, error) {
26 | sup := entity.Supplier{
27 | SupplierName: supplier.SupplierName,
28 | SupplierDesc: supplier.SupplierDesc,
29 | Phone: supplier.Phone,
30 | Email: supplier.Email,
31 | CreatedAt: time.Now().Format(time.RFC3339Nano),
32 | }
33 | supplier, err := service.supplierRepository.Store(sup)
34 | if err != nil {
35 | return supplier, err
36 | }
37 | return supplier, nil
38 | }
39 |
40 | func (service SupplierService) GetAllSupplier() ([]entity.Supplier, error) {
41 | supplier, err := service.supplierRepository.FindAll()
42 | if err != nil {
43 | return supplier, nil
44 | }
45 | return supplier, nil
46 | }
47 |
48 | func (service SupplierService) GetSupplierByID(id int) (entity.Supplier, error) {
49 | supplier, err := service.supplierRepository.FindByID(id)
50 | if err != nil {
51 | return supplier, err
52 | }
53 | return supplier, nil
54 | }
55 |
56 | func (service SupplierService) UpdateSupplier(id int, supplierReq entity.UpdateSupplier) (entity.Supplier, error) {
57 | supplier, err := service.supplierRepository.FindByID(id)
58 | if err != nil {
59 | return entity.Supplier{}, err
60 | }
61 | s := entity.Supplier{
62 | ID: supplier.ID,
63 | SupplierName: supplierReq.SupplierName,
64 | SupplierDesc: supplierReq.SupplierDesc,
65 | Phone: supplierReq.Phone,
66 | Email: supplierReq.Email,
67 | CreatedAt: supplier.CreatedAt,
68 | UpdatedAt: time.Now().Format(time.RFC3339Nano),
69 | }
70 | supplier, err = service.supplierRepository.Update(s)
71 | if err != nil {
72 | return entity.Supplier{}, err
73 | }
74 | return supplier, nil
75 |
76 | }
77 |
78 | func (service SupplierService) DeleteSupplier(id int) error {
79 | err := service.supplierRepository.Delete(id)
80 | if err != nil {
81 | return err
82 | }
83 | return nil
84 | }
85 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/services/supplier/supplier_address.go:
--------------------------------------------------------------------------------
1 | package services
2 |
3 | import (
4 | "time"
5 | entity "warehouse-management-system-eFishery/entity/supplier"
6 | repository "warehouse-management-system-eFishery/repository/supplier"
7 | )
8 |
9 | type InterfaceSupplierAddressService interface {
10 | }
11 |
12 | type SupplierAddressService struct {
13 | supplierAddressRepository repository.InterfaceSupplierAddressRepository
14 | }
15 |
16 | func NewSupplierAddressService(supplierAddressRepository repository.InterfaceSupplierAddressRepository) *SupplierAddressService {
17 | return &SupplierAddressService{supplierAddressRepository}
18 | }
19 |
20 | func (service SupplierAddressService) CreateSupplierAddress(supplierAddressRequest entity.SupplierAddress) (entity.SupplierAddress, error) {
21 | sas := entity.SupplierAddress{
22 | SupplierID: supplierAddressRequest.SupplierID,
23 | FullAddress: supplierAddressRequest.FullAddress,
24 | SubDistrict: supplierAddressRequest.SubDistrict,
25 | District: supplierAddressRequest.District,
26 | City: supplierAddressRequest.City,
27 | Province: supplierAddressRequest.Province,
28 | PostalCode: supplierAddressRequest.PostalCode,
29 | CreatedAt: time.Now().Format(time.RFC3339Nano),
30 | }
31 | supplierAddress, err := service.supplierAddressRepository.Store(sas)
32 | if err != nil {
33 | return supplierAddress, err
34 | }
35 | return supplierAddress, nil
36 | }
37 |
38 | func (service SupplierAddressService) GetAllSupplierAddress() ([]entity.SupplierAddress, error) {
39 | supplierAddresses, err := service.supplierAddressRepository.FindAll()
40 | if err != nil {
41 | return supplierAddresses, err
42 | }
43 | return supplierAddresses, nil
44 | }
45 |
46 | func (service SupplierAddressService) GetSupplierAddressByID(id int) (entity.SupplierAddress, error) {
47 | supplierAddress, err := service.supplierAddressRepository.FindByID(id)
48 | if err != nil {
49 | return supplierAddress, err
50 | }
51 | return supplierAddress, nil
52 | }
53 |
54 | func (service SupplierAddressService) UpdateSupplierAddress(supplierAddressRequest entity.UpdateSupplierAddress, id int) (entity.SupplierAddressResponse, error) {
55 | supplierAddress, err := service.supplierAddressRepository.FindByID(id)
56 | if err != nil {
57 | return entity.SupplierAddressResponse{}, err
58 | }
59 | supplierAddressData := entity.SupplierAddress{
60 | ID: supplierAddress.ID,
61 | SupplierID: supplierAddress.SupplierID,
62 | FullAddress: supplierAddressRequest.FullAddress,
63 | SubDistrict: supplierAddressRequest.SubDistrict,
64 | District: supplierAddressRequest.District,
65 | City: supplierAddressRequest.City,
66 | Province: supplierAddressRequest.Province,
67 | PostalCode: supplierAddressRequest.PostalCode,
68 | CreatedAt: supplierAddress.CreatedAt,
69 | UpdatedAt: time.Now().Format(time.RFC3339Nano),
70 | }
71 | supplierAddress, err = service.supplierAddressRepository.Update(supplierAddressData)
72 | if err != nil {
73 | return entity.SupplierAddressResponse{}, err
74 | }
75 | supplierAddressResponse := entity.SupplierAddressResponse{
76 | ID: supplierAddress.ID,
77 | SupplierID: supplierAddress.SupplierID,
78 | FullAddress: supplierAddress.FullAddress,
79 | SubDistrict: supplierAddress.SubDistrict,
80 | District: supplierAddress.District,
81 | City: supplierAddress.City,
82 | Province: supplierAddress.Province,
83 | PostalCode: supplierAddress.PostalCode,
84 | CreatedAt: supplierAddress.CreatedAt,
85 | UpdatedAt: supplierAddress.UpdatedAt,
86 | }
87 | return supplierAddressResponse, nil
88 | }
89 |
90 | func (service SupplierAddressService) DeleteSupplierAddress(id int) error {
91 | err := service.supplierAddressRepository.Delete(id)
92 | if err != nil {
93 | return err
94 | }
95 | return nil
96 | }
97 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/services/warehouse/warehouse.go:
--------------------------------------------------------------------------------
1 | package services
2 |
3 | import (
4 | "time"
5 | entity "warehouse-management-system-eFishery/entity/warehouse"
6 | repository "warehouse-management-system-eFishery/repository/warehouse"
7 | )
8 |
9 | type InterfaceWarehouseService interface {
10 | CreateWarehouse(warehouse entity.Warehouse) (entity.Warehouse, error)
11 | GetAllWarehouse() ([]entity.Warehouse, error)
12 | GetWarehouseByID(id int) (entity.Warehouse, error)
13 | UpdateWarehouse(warehouse entity.Warehouse, id int) (entity.Warehouse, error)
14 | DeleteWarehouse(id int) error
15 | }
16 |
17 | type WarehouseService struct {
18 | warehouseRepository repository.InterfaceWarehouseRepository
19 | }
20 |
21 | func NewWarehouseService(warehouseRepository repository.InterfaceWarehouseRepository) *WarehouseService {
22 | return &WarehouseService{warehouseRepository}
23 | }
24 |
25 | func (service WarehouseService) CreateWarehouse(warehouse entity.Warehouse) (entity.Warehouse, error) {
26 | w := entity.Warehouse{
27 | WarehouseName: warehouse.WarehouseName,
28 | WarehouseDesc: warehouse.WarehouseDesc,
29 | CreatedAt: time.Now().Format(time.RFC3339Nano),
30 | }
31 | warehouse, err := service.warehouseRepository.Store(w)
32 | if err != nil {
33 | return warehouse, err
34 | }
35 | return warehouse, nil
36 | }
37 |
38 | func (service WarehouseService) GetAllWarehouse() ([]entity.Warehouse, error) {
39 | warehouses, err := service.warehouseRepository.FindAll()
40 | if err != nil {
41 | return warehouses, err
42 | }
43 | return warehouses, nil
44 | }
45 |
46 | func (service WarehouseService) GetWarehouseByID(id int) (entity.Warehouse, error) {
47 | warehouse, err := service.warehouseRepository.FindByID(id)
48 | if err != nil {
49 | return warehouse, err
50 | }
51 | return warehouse, nil
52 | }
53 |
54 | func (service WarehouseService) UpdateWarehouse(warehouseReq entity.UpdateWarehouse, id int) (entity.WarehouseResponse, error) {
55 | warehouse, err := service.warehouseRepository.FindByID(id)
56 | if err != nil {
57 | return entity.WarehouseResponse{}, err
58 | }
59 | warehouseData := entity.Warehouse{
60 | ID: warehouse.ID,
61 | WarehouseName: warehouseReq.WarehouseName,
62 | WarehouseDesc: warehouseReq.WarehouseDesc,
63 | CreatedAt: warehouse.CreatedAt,
64 | UpdatedAt: time.Now().Format(time.RFC3339Nano),
65 | }
66 | warehouse, err = service.warehouseRepository.Update(warehouseData)
67 | if err != nil {
68 | return entity.WarehouseResponse{}, err
69 | }
70 | warehouseResponse := entity.WarehouseResponse{
71 | WarehouseName: warehouse.WarehouseName,
72 | WarehouseDesc: warehouse.WarehouseDesc,
73 | }
74 | return warehouseResponse, nil
75 | }
76 |
77 | func (service WarehouseService) DeleteWarehouse(id int) error {
78 | err := service.warehouseRepository.Delete(id)
79 | if err != nil {
80 | return err
81 | }
82 | return nil
83 | }
84 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/services/warehouse/warehouse_address.go:
--------------------------------------------------------------------------------
1 | package services
2 |
3 | import (
4 | "time"
5 | entity "warehouse-management-system-eFishery/entity/warehouse"
6 | repository "warehouse-management-system-eFishery/repository/warehouse"
7 | )
8 |
9 | type InterfaceWarehouseAddressService interface {
10 | CreateWarehouseAddress(warehouseAddress entity.WarehouseAddress) (entity.WarehouseAddress, error)
11 | GetAllWarehouseAddress() ([]entity.WarehouseAddress, error)
12 | GetWarehouseAddressByID(id int) (entity.WarehouseAddress, error)
13 | UpdateWarehouseAddress(warehouseAddress entity.WarehouseAddress, id int) (entity.WarehouseAddress, error)
14 | DeleteWarehouseAddress(id int) error
15 | }
16 |
17 | type WarehouseAddressService struct {
18 | warehouseAddressRepository repository.InterfaceWarehouseAddressRepository
19 | }
20 |
21 | func NewWarehouseAddressService(warehouseAddressRepository repository.InterfaceWarehouseAddressRepository) *WarehouseAddressService {
22 | return &WarehouseAddressService{warehouseAddressRepository}
23 | }
24 |
25 | func (service WarehouseAddressService) CreateWarehouseAddress(warehouse entity.WarehouseAddress) (entity.WarehouseAddress, error) {
26 | was := entity.WarehouseAddress{
27 | WarehouseID: warehouse.WarehouseID,
28 | FullAddress: warehouse.FullAddress,
29 | SubDistrict: warehouse.SubDistrict,
30 | City: warehouse.City,
31 | Province: warehouse.Province,
32 | Region: warehouse.Region,
33 | PostalCode: warehouse.PostalCode,
34 | CreatedAt: time.Now().Format(time.RFC3339Nano),
35 | }
36 | warehouseAddress, err := service.warehouseAddressRepository.Store(was)
37 | if err != nil {
38 | return warehouseAddress, err
39 | }
40 | return warehouseAddress, nil
41 | }
42 |
43 | func (service WarehouseAddressService) GetAllAddress() ([]entity.WarehouseAddress, error) {
44 | warehouseAddress, err := service.warehouseAddressRepository.FindAll()
45 | if err != nil {
46 | return warehouseAddress, nil
47 | }
48 | return warehouseAddress, nil
49 | }
50 |
51 | func (service WarehouseAddressService) GetAddressByID(id int) (entity.WarehouseAddress, error) {
52 | warehouseAddress, err := service.warehouseAddressRepository.FindByID(id)
53 | if err != nil {
54 | return warehouseAddress, err
55 | }
56 | return warehouseAddress, nil
57 | }
58 |
59 | func (service WarehouseAddressService) UpdateWarehouseAddress(id int, warehouseReq entity.UpdateWarehouseAddress) (entity.WarehouseAddressesResponse, error) {
60 | warehouseAddress, err := service.warehouseAddressRepository.FindByID(id)
61 | if err != nil {
62 | return entity.WarehouseAddressesResponse{}, err
63 | }
64 | was := entity.WarehouseAddress{
65 | ID: warehouseAddress.ID,
66 | WarehouseID: warehouseReq.WarehouseID,
67 | FullAddress: warehouseReq.FullAddress,
68 | SubDistrict: warehouseReq.SubDistrict,
69 | City: warehouseReq.City,
70 | Province: warehouseReq.Province,
71 | Region: warehouseReq.Region,
72 | PostalCode: warehouseReq.PostalCode,
73 | CreatedAt: warehouseAddress.CreatedAt,
74 | UpdatedAt: time.Now().Format(time.RFC3339Nano),
75 | }
76 | warehouseAddress, err = service.warehouseAddressRepository.Update(was)
77 | if err != nil {
78 | return entity.WarehouseAddressesResponse{}, err
79 | }
80 | warehouseAddressResponse := entity.WarehouseAddressesResponse{
81 | ID: warehouseAddress.ID,
82 | FullAddress: warehouseAddress.FullAddress,
83 | SubDistrict: warehouseAddress.SubDistrict,
84 | City: warehouseAddress.City,
85 | Province: warehouseAddress.Province,
86 | Region: warehouseAddress.Region,
87 | PostalCode: warehouseAddress.PostalCode,
88 | CreatedAt: warehouseAddress.CreatedAt,
89 | UpdatedAt: warehouseAddress.UpdatedAt,
90 | }
91 | return warehouseAddressResponse, nil
92 | }
93 |
94 | func (service WarehouseAddressService) DeleteWarehouseAddress(id int) error {
95 | err := service.warehouseAddressRepository.Delete(id)
96 | if err != nil {
97 | return err
98 | }
99 | return nil
100 | }
101 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/services/warehouse/warehouse_categories.go:
--------------------------------------------------------------------------------
1 | package services
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/warehouse"
5 | repository "warehouse-management-system-eFishery/repository/warehouse"
6 | )
7 |
8 | type InterfaceWarehouseCategoryService interface {
9 | CreateWarehouseCategory(warehouseCategory entity.WarehouseCategories) (entity.WarehouseCategories, error)
10 | GetAllWarehouseCategory() ([]entity.WarehouseCategories, error)
11 | GetCategoryByID(id int) (entity.WarehouseCategories, error)
12 | UpdateWarehouseCategory(id int, warehouseCategories entity.WarehouseCategories) (entity.WarehouseCategories, error)
13 | DeleteWarehouseCategory(id int) error
14 | }
15 |
16 | type WarehouseCategoryService struct {
17 | warehouseCategoryRepository repository.InterfaceWarehouseCategoriesRepository
18 | }
19 |
20 | func NewWarehouseCategoryService(warehouseCategoryRepository repository.InterfaceWarehouseCategoriesRepository) *WarehouseCategoryService {
21 | return &WarehouseCategoryService{warehouseCategoryRepository}
22 | }
23 |
24 | func (service WarehouseCategoryService) CreateWarehouseCategory(warehouse entity.WarehouseCategories) (entity.WarehouseCategories, error) {
25 | was := entity.WarehouseCategories{
26 | ID: warehouse.ID,
27 | CategoryName: warehouse.CategoryName,
28 | CategoryDesc: warehouse.CategoryDesc,
29 | }
30 | warehouseCategory, err := service.warehouseCategoryRepository.Store(was)
31 | if err != nil {
32 | return warehouseCategory, err
33 | }
34 | return warehouseCategory, nil
35 | }
36 |
37 | func (service WarehouseCategoryService) GetAllCategory() ([]entity.WarehouseCategories, error) {
38 | warehouseCategory, err := service.warehouseCategoryRepository.FindAll()
39 | if err != nil {
40 | return warehouseCategory, nil
41 | }
42 | return warehouseCategory, nil
43 | }
44 |
45 | func (service WarehouseCategoryService) GetCategoryByID(id int) (entity.WarehouseCategories, error) {
46 | warehouseCategory, err := service.warehouseCategoryRepository.FindByID(id)
47 | if err != nil {
48 | return warehouseCategory, err
49 | }
50 | return warehouseCategory, nil
51 | }
52 |
53 | func (service WarehouseCategoryService) UpdateWarehouseCategory(id int, warehouseReq entity.WarehouseCategories) (entity.WarehouseCategories, error) {
54 | warehouseCategory, err := service.warehouseCategoryRepository.FindByID(id)
55 | if err != nil {
56 | return entity.WarehouseCategories{}, err
57 | }
58 | was := entity.WarehouseCategories{
59 | ID: warehouseCategory.ID,
60 | CategoryName: warehouseReq.CategoryName,
61 | CategoryDesc: warehouseReq.CategoryDesc,
62 | }
63 | warehouseCategory, err = service.warehouseCategoryRepository.Update(was)
64 | if err != nil {
65 | return entity.WarehouseCategories{}, err
66 | }
67 | return warehouseCategory, nil
68 | }
69 |
70 | func (service WarehouseCategoryService) DeleteWarehouseCategory(id int) error {
71 | err := service.warehouseCategoryRepository.Delete(id)
72 | if err != nil {
73 | return err
74 | }
75 | return nil
76 | }
77 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/services/warehouse/warehouse_product.go:
--------------------------------------------------------------------------------
1 | package services
2 |
3 | import (
4 | "time"
5 | entity "warehouse-management-system-eFishery/entity/warehouse"
6 | repository "warehouse-management-system-eFishery/repository/warehouse"
7 | )
8 |
9 | type InterfaceWarehouseProductService interface {
10 | CreateWarehouseProduct(entity.WarehouseProducts) (entity.WarehouseProducts, error)
11 | GetAllWarehouseProduct() ([]entity.WarehouseProducts, error)
12 | GetWarehouseProductByID(int) (entity.WarehouseProducts, error)
13 | GetWarehouseProductByPrice(int, int) ([]entity.WarehouseProducts, error)
14 | UpdateWarehouseProduct(id int, warehouseReq entity.UpdateWarehouseProducts) (entity.WarehouseProductsResponse, error)
15 | DeleteWarehouseProduct(id int) error
16 | }
17 |
18 | type WarehouseProductService struct {
19 | warehouseProductRepository repository.InterfaceWarehouseProductRepository
20 | }
21 |
22 | func NewWarehouseProductService(warehouseProductRepository repository.InterfaceWarehouseProductRepository) *WarehouseProductService {
23 | return &WarehouseProductService{warehouseProductRepository}
24 | }
25 |
26 | func (service WarehouseProductService) CreateWarehouseProduct(warehouseReq entity.WarehouseProducts) (entity.WarehouseProducts, error) {
27 | wps := entity.WarehouseProducts{
28 | SKU: warehouseReq.SKU,
29 | ProductName: warehouseReq.ProductName,
30 | ProductDesc: warehouseReq.ProductDesc,
31 | Image: warehouseReq.Image,
32 | Price: warehouseReq.Price,
33 | Stock: warehouseReq.Stock,
34 | Weight: warehouseReq.Weight,
35 | SectionPlaceID: warehouseReq.SectionPlaceID,
36 | CategoryID: warehouseReq.CategoryID,
37 | SupplierID: warehouseReq.SupplierID,
38 | WarehouseID: warehouseReq.WarehouseID,
39 | CreatedAt: time.Now().Format(time.RFC3339Nano),
40 | }
41 | warehouseProduct, err := service.warehouseProductRepository.Store(wps)
42 | if err != nil {
43 | return warehouseProduct, err
44 | }
45 | return warehouseProduct, nil
46 | }
47 |
48 | func (service WarehouseProductService) GetAllWarehouseProduct() ([]entity.WarehouseProducts, error) {
49 | warehouseProduct, err := service.warehouseProductRepository.GetAll()
50 | if err != nil {
51 | return warehouseProduct, err
52 | }
53 | return warehouseProduct, nil
54 | }
55 |
56 | func (service WarehouseProductService) GetWarehouseProductByID(id int) (entity.WarehouseProducts, error) {
57 | warehouseProduct, err := service.warehouseProductRepository.GetbyID(id)
58 | if err != nil {
59 | return warehouseProduct, err
60 | }
61 | return warehouseProduct, nil
62 | }
63 |
64 | func (service WarehouseProductService) GetWarehouseProductByPrice(minPrice int, maxPrice int) ([]entity.WarehouseProducts, error) {
65 | warehouseProduct, err := service.warehouseProductRepository.GetByPrice(minPrice, maxPrice)
66 | if err != nil {
67 | return warehouseProduct, err
68 | }
69 | return warehouseProduct, nil
70 | }
71 |
72 | func (service WarehouseProductService) UpdateWarehouseProduct(id int, warehouseReq entity.UpdateWarehouseProducts) (entity.WarehouseProductsResponse, error) {
73 | warehouseProduct, err := service.warehouseProductRepository.GetbyID(id)
74 | if err != nil {
75 | return entity.WarehouseProductsResponse{}, err
76 | }
77 |
78 | wps := entity.WarehouseProducts{
79 | ID: warehouseProduct.ID,
80 | SKU: warehouseReq.SKU,
81 | ProductName: warehouseReq.ProductName,
82 | ProductDesc: warehouseReq.ProductDesc,
83 | Image: warehouseReq.Image,
84 | Price: warehouseReq.Price,
85 | Stock: warehouseReq.Stock,
86 | Weight: warehouseReq.Weight,
87 | SectionPlaceID: warehouseReq.SectionPlaceID,
88 | CategoryID: warehouseReq.CategoryID,
89 | SupplierID: warehouseReq.SupplierID,
90 | WarehouseID: warehouseReq.WarehouseID,
91 | CreatedAt: warehouseProduct.CreatedAt,
92 | UpdatedAt: time.Now().Format(time.RFC3339Nano),
93 | }
94 |
95 | warehouseProduct, err = service.warehouseProductRepository.Update(wps)
96 | warehouseProductResponse := entity.WarehouseProductsResponse{
97 | // ID: warehouseProduct.ID,
98 | SKU: warehouseProduct.SKU,
99 | ProductName: warehouseProduct.ProductName,
100 | ProductDesc: warehouseProduct.ProductDesc,
101 | Image: warehouseProduct.Image,
102 | Price: warehouseProduct.Price,
103 | Stock: warehouseProduct.Stock,
104 | Weight: warehouseProduct.Weight,
105 | SectionPlaceID: warehouseProduct.SectionPlaceID,
106 | CategoryID: warehouseProduct.CategoryID,
107 | SupplierID: warehouseProduct.SupplierID,
108 | WarehouseID: warehouseProduct.WarehouseID,
109 | CreatedAt: warehouseProduct.CreatedAt,
110 | UpdatedAt: warehouseProduct.UpdatedAt,
111 | }
112 | if err != nil {
113 | return warehouseProductResponse, err
114 | }
115 |
116 | return warehouseProductResponse, nil
117 |
118 | }
119 |
120 | func (service WarehouseProductService) DeleteWarehouseProduct(id int) error {
121 | err := service.warehouseProductRepository.Delete(id)
122 | if err != nil {
123 | return err
124 | }
125 | return nil
126 | }
127 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/services/warehouse/warehouse_roles.go:
--------------------------------------------------------------------------------
1 | package services
2 |
3 | import (
4 | entity "warehouse-management-system-eFishery/entity/warehouse"
5 | repository "warehouse-management-system-eFishery/repository/warehouse"
6 | )
7 |
8 | type InterfaceWarehouseRolesService interface {
9 | CreateWarehouseRoles(warehouseRoles entity.WarehouseRoles) (entity.WarehouseRoles, error)
10 | GetAllWarehouseRoles() ([]entity.WarehouseRoles, error)
11 | GetWarehouseRolesByID(id int) (entity.WarehouseRoles, error)
12 | UpdateWarehouseRoles(id int, warehouseRoles entity.WarehouseRoles) (entity.WarehouseRoles, error)
13 | DeleteWarehouseRoles(id int) error
14 | }
15 |
16 | type WarehouseRolesService struct {
17 | warehouseRolesRepository repository.InterfaceWarehouseRolesRepository
18 | }
19 |
20 | func NewWarehouseRolesService(warehouseRolesRepository repository.InterfaceWarehouseRolesRepository) *WarehouseRolesService {
21 | return &WarehouseRolesService{warehouseRolesRepository}
22 | }
23 |
24 | func (service WarehouseRolesService) CreateWarehouseRoles(warehouseRoles entity.WarehouseRoles) (entity.WarehouseRoles, error) {
25 | warehouseRoles, err := service.warehouseRolesRepository.Store(warehouseRoles)
26 | if err != nil {
27 | return warehouseRoles, err
28 | }
29 | return warehouseRoles, nil
30 | }
31 |
32 | func (service WarehouseRolesService) GetAllWarehouseRoles() ([]entity.WarehouseRoles, error) {
33 | warehouseRoles, err := service.warehouseRolesRepository.FindAll()
34 | if err != nil {
35 | return warehouseRoles, err
36 | }
37 | return warehouseRoles, nil
38 | }
39 |
40 | func (service WarehouseRolesService) GetWarehouseRolesByID(id int) (entity.WarehouseRoles, error) {
41 | warehouseRoles, err := service.warehouseRolesRepository.FindByID(id)
42 | if err != nil {
43 | return warehouseRoles, err
44 | }
45 | return warehouseRoles, nil
46 | }
47 |
48 | func (service WarehouseRolesService) UpdateWarehouseRoles(id int, warehouseReq entity.WarehouseRoles) (entity.WarehouseRoles, error) {
49 | warehouseRoles, err := service.warehouseRolesRepository.FindByID(id)
50 | if err != nil {
51 | return entity.WarehouseRoles{}, err
52 | }
53 | wrs := entity.WarehouseRoles{
54 | ID: warehouseRoles.ID,
55 | Role: warehouseReq.Role,
56 | Description: warehouseReq.Description,
57 | }
58 | warehouseRoles, err = service.warehouseRolesRepository.Update(wrs)
59 | if err != nil {
60 | return entity.WarehouseRoles{}, err
61 | }
62 | return warehouseRoles, nil
63 | }
64 |
65 | func (service WarehouseRolesService) DeleteWarehouseRoles(id int) error {
66 | err := service.warehouseRolesRepository.Delete(id)
67 | if err != nil {
68 | return err
69 | }
70 | return nil
71 | }
72 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/services/warehouse/warehouse_section.go:
--------------------------------------------------------------------------------
1 | package services
2 |
3 | import (
4 | "time"
5 | entity "warehouse-management-system-eFishery/entity/warehouse"
6 | repository "warehouse-management-system-eFishery/repository/warehouse"
7 | )
8 |
9 | type InterfaceWarehouseSectionService interface {
10 | CreateWarehouseSection(warehouseRequest entity.WarehouseSection) (entity.WarehouseSection, error)
11 | GetAllWarehouseSection() ([]entity.WarehouseSection, error)
12 | GetWarehouseSectionByID(id int) (entity.WarehouseSection, error)
13 | UpdateWarehouseSection(id int, warehouseRequest entity.UpdateWarehouseSection) (entity.WarehouseSectionResponse, error)
14 | DeleteWarehouseSection(id int) error
15 | }
16 |
17 | type WarehouseSectionService struct {
18 | warehouseSectionRepository repository.InterfaceWarehouseSectionRepository
19 | }
20 |
21 | func NewWarehouseSectionService(warehouseSectionRepository repository.InterfaceWarehouseSectionRepository) *WarehouseSectionService {
22 | return &WarehouseSectionService{warehouseSectionRepository}
23 | }
24 |
25 | // WarehouseSectionService is a service that handles all business logic related to warehouse section
26 |
27 | func (service WarehouseSectionService) CreateWarehouseSection(warehouseRequest entity.WarehouseSection) (entity.WarehouseSection, error) {
28 | wss := entity.WarehouseSection{
29 | WarehouseID: warehouseRequest.WarehouseID,
30 | InventorySection: warehouseRequest.InventorySection,
31 | InventoryAisle: warehouseRequest.InventoryAisle,
32 | InventoryRow: warehouseRequest.InventoryRow,
33 | InventoryTier: warehouseRequest.InventoryTier,
34 | CreatedAt: time.Now().Format(time.RFC3339Nano),
35 | }
36 | warehouseSection, err := service.warehouseSectionRepository.Store(wss)
37 | if err != nil {
38 | return warehouseSection, err
39 | }
40 | return warehouseSection, nil
41 | }
42 |
43 | func (service WarehouseSectionService) GetAllWarehouseSection() ([]entity.WarehouseSection, error) {
44 | warehouseSection, err := service.warehouseSectionRepository.FindAll()
45 | if err != nil {
46 | return warehouseSection, nil
47 | }
48 | return warehouseSection, nil
49 | }
50 |
51 | func (service WarehouseSectionService) GetWarehouseSectionByID(id int) (entity.WarehouseSection, error) {
52 | warehouseSection, err := service.warehouseSectionRepository.FindByID(id)
53 | if err != nil {
54 | return warehouseSection, err
55 | }
56 | return warehouseSection, nil
57 | }
58 |
59 | func (service WarehouseSectionService) UpdateWarehouseSection(id int, warehouseRequest entity.UpdateWarehouseSection) (entity.WarehouseSectionResponse, error) {
60 | warehouseSection, err := service.warehouseSectionRepository.FindByID(id)
61 | if err != nil {
62 | return entity.WarehouseSectionResponse{}, err
63 | }
64 | wss := entity.WarehouseSection{
65 | ID: warehouseSection.ID,
66 | WarehouseID: warehouseRequest.WarehouseID,
67 | InventorySection: warehouseRequest.InventorySection,
68 | InventoryAisle: warehouseRequest.InventoryAisle,
69 | InventoryRow: warehouseRequest.InventoryRow,
70 | InventoryTier: warehouseRequest.InventoryTier,
71 | CreatedAt: warehouseSection.CreatedAt,
72 | UpdatedAt: time.Now().Format(time.RFC3339Nano),
73 | }
74 | warehouseSection, err = service.warehouseSectionRepository.Update(wss)
75 | if err != nil {
76 | return entity.WarehouseSectionResponse{}, err
77 | }
78 | return entity.WarehouseSectionResponse{
79 | ID: warehouseSection.ID,
80 | WarehouseID: warehouseSection.WarehouseID,
81 | InventorySection: warehouseSection.InventorySection,
82 | InventoryAisle: warehouseSection.InventoryAisle,
83 | InventoryRow: warehouseSection.InventoryRow,
84 | InventoryTier: warehouseSection.InventoryTier,
85 | CreatedAt: warehouseSection.CreatedAt,
86 | UpdatedAt: warehouseSection.UpdatedAt,
87 | }, nil
88 |
89 | }
90 |
91 | func (service WarehouseSectionService) DeleteWarehouseSection(id int) error {
92 | err := service.warehouseSectionRepository.Delete(id)
93 | if err != nil {
94 | return err
95 | }
96 | return nil
97 | }
98 |
--------------------------------------------------------------------------------
/9. Final Project - Warehouse Management System/services/warehouse/warehouse_workers.go:
--------------------------------------------------------------------------------
1 | package services
2 |
3 | import (
4 | "time"
5 | config "warehouse-management-system-eFishery/config/auth"
6 | entity "warehouse-management-system-eFishery/entity/warehouse"
7 | repository "warehouse-management-system-eFishery/repository/warehouse"
8 |
9 | "github.com/google/uuid"
10 | )
11 |
12 | type InterfaceWarehouseWorkerService interface {
13 | CreateWarehouseWorkerWarehouseAuth(entity.CreateWarehouseWorkers, entity.CreateWarehouseAuth) (entity.WarehouseWorkersResponse, error)
14 | GetAllUser() ([]entity.WarehouseWorkersResponse, error)
15 | GetWarehouseWorkerByUUID(uuid string) (entity.WarehouseWorkersResponse, error)
16 | UpdateWarehouseWorker(uuid string, warehouseReq entity.CreateWarehouseWorkers) (entity.WarehouseWorkersResponse, error)
17 | DeleteWarehouseWorker(uuid string) error
18 | }
19 |
20 | type WarehouseWorkerService struct {
21 | warehouseWorkerRepository repository.InterfaceWarehouseWorkersRepository
22 | }
23 |
24 | func NewWarehouseWorkerService(warehouseWorkerRepository repository.InterfaceWarehouseWorkersRepository) *WarehouseWorkerService {
25 | return &WarehouseWorkerService{warehouseWorkerRepository}
26 | }
27 |
28 | func (service WarehouseWorkerService) CreateWarehouseWorker(warehouseReq entity.CreateWarehouseWorkers, warehouseAuthChan entity.CreateWarehouseAuth) (entity.WarehouseWorkersResponse, error) {
29 | newUUID := uuid.New().String()
30 | hashedPassword, _ := config.HashPassword(warehouseReq.Password)
31 | warehouseWorker := entity.WarehouseWorkers{
32 | UUID: newUUID,
33 | FirstName: warehouseReq.FirstName,
34 | LastName: warehouseReq.LastName,
35 | Phone: warehouseReq.Phone,
36 | Email: warehouseReq.Email,
37 | Password: hashedPassword,
38 | WarehouseId: warehouseReq.WarehouseId,
39 | RolesId: warehouseReq.RolesId,
40 | CreatedAt: time.Now().Format(time.RFC3339Nano),
41 | }
42 | wssAuth := entity.WarehouseAuth{
43 | UUID: newUUID,
44 | Email: warehouseReq.Email,
45 | Password: hashedPassword,
46 | CreatedAt: time.Now().Format(time.RFC3339Nano),
47 | }
48 | warehouseWorker, err := service.warehouseWorkerRepository.Store(warehouseWorker, wssAuth)
49 |
50 | wssResponse := entity.WarehouseWorkersResponse{
51 | UUID: warehouseWorker.UUID,
52 | FirstName: warehouseWorker.FirstName,
53 | LastName: warehouseWorker.LastName,
54 | Phone: warehouseWorker.Phone,
55 | Email: warehouseWorker.Email,
56 | WarehouseId: warehouseWorker.WarehouseId,
57 | RolesId: warehouseWorker.RolesId,
58 | }
59 | if err != nil {
60 | return wssResponse, err
61 | }
62 | return wssResponse, nil
63 |
64 | }
65 | func (service WarehouseWorkerService) GetAllUser() ([]entity.WarehouseWorkersResponse, error) {
66 | warehouseWorkers, err := service.warehouseWorkerRepository.FindAll()
67 | if err != nil {
68 | return nil, err
69 | }
70 | var warehouseWorkersResponse []entity.WarehouseWorkersResponse
71 | for _, warehouseWorker := range warehouseWorkers {
72 | warehouseWorkerResponse := entity.WarehouseWorkersResponse{
73 | UUID: warehouseWorker.UUID,
74 | FirstName: warehouseWorker.FirstName,
75 | LastName: warehouseWorker.LastName,
76 | Phone: warehouseWorker.Phone,
77 | Email: warehouseWorker.Email,
78 | WarehouseId: warehouseWorker.WarehouseId,
79 | RolesId: warehouseWorker.RolesId,
80 | }
81 | warehouseWorkersResponse = append(warehouseWorkersResponse, warehouseWorkerResponse)
82 | }
83 | return warehouseWorkersResponse, nil
84 | }
85 |
86 | func (service WarehouseWorkerService) GetWarehouseWorkerByUUID(uuid string) (entity.WarehouseWorkersResponse, error) {
87 | warehouseWorker, err := service.warehouseWorkerRepository.FindByUUID(uuid)
88 | if err != nil {
89 | return entity.WarehouseWorkersResponse{}, err
90 | }
91 | warehouseWorkerResponse := entity.WarehouseWorkersResponse{
92 | UUID: warehouseWorker.UUID,
93 | FirstName: warehouseWorker.FirstName,
94 | LastName: warehouseWorker.LastName,
95 | Phone: warehouseWorker.Phone,
96 | Email: warehouseWorker.Email,
97 | WarehouseId: warehouseWorker.WarehouseId,
98 | RolesId: warehouseWorker.RolesId,
99 | }
100 | return warehouseWorkerResponse, nil
101 | }
102 |
103 | func (service WarehouseWorkerService) UpdateWarehouseWorker(uuid string, warehouseReq entity.CreateWarehouseWorkers) (entity.WarehouseWorkersResponse, error) {
104 | warehouseWorker := entity.WarehouseWorkers{
105 | UUID: uuid,
106 | FirstName: warehouseReq.FirstName,
107 | LastName: warehouseReq.LastName,
108 | Phone: warehouseReq.Phone,
109 | Email: warehouseReq.Email,
110 | WarehouseId: warehouseReq.WarehouseId,
111 | RolesId: warehouseReq.RolesId,
112 | }
113 | warehouseWorker, err := service.warehouseWorkerRepository.UpdateByUUID(uuid, warehouseWorker)
114 | if err != nil {
115 | return entity.WarehouseWorkersResponse{}, err
116 | }
117 | warehouseWorkerResponse := entity.WarehouseWorkersResponse{
118 | UUID: warehouseWorker.UUID,
119 | FirstName: warehouseWorker.FirstName,
120 | LastName: warehouseWorker.LastName,
121 | Phone: warehouseWorker.Phone,
122 | Email: warehouseWorker.Email,
123 | WarehouseId: warehouseWorker.WarehouseId,
124 | RolesId: warehouseWorker.RolesId,
125 | }
126 | return warehouseWorkerResponse, nil
127 |
128 | }
129 |
130 | func (service WarehouseWorkerService) DeleteWarehouseWorker(uuid string) error {
131 | err := service.warehouseWorkerRepository.DeleteByUUID(uuid)
132 | if err != nil {
133 | return err
134 | }
135 | return nil
136 | }
137 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # naufalhakim eFishery Academy Batch 2
2 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module example/learngo
2 |
3 | go 1.19
4 |
--------------------------------------------------------------------------------
/learngo.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "strconv" // for converting integer to string
6 | )
7 |
8 | var (
9 | actorName string = "Elisabeth Sladen"
10 | companion string = "Sarah Jane Smith"
11 | doctorNumber int = 3
12 | season int = 11
13 | minutes string = "32:23"
14 | // theURL string = "https://www.google.com"
15 | // requestHTTP string = "GET"
16 | )
17 |
18 | // Hello returns a greeting for the named person.
19 | func variables() {
20 | dark := "bar"
21 |
22 | fmt.Println(dark)
23 | fmt.Println("Hello, my name is", actorName)
24 | fmt.Println("I played", companion, "in Doctor Who season", season)
25 | fmt.Println("I was the", doctorNumber, "doctor")
26 | fmt.Println("I'm in the", minutes, "mark")
27 | // Conversion method from int to string
28 | var (
29 | i int = 42
30 | j float32 = 32.5
31 | )
32 | fmt.Printf("%v, %T\n", i, i)
33 | // fmt.Println()
34 | fmt.Printf("%v, %T\n", j, j)
35 | // fmt.Println()
36 | fmt.Printf("%v, %T\n", i, i)
37 | var k string = strconv.Itoa(i) // <--- string conversion using strconv I to ascii
38 | // fmt.Println()
39 | fmt.Printf("%v, %T\n", k, k)
40 | }
41 | func differentDataTypes() {
42 | var (
43 | a int = 32
44 | b int8 = 64
45 | c int16 = 128
46 | d uint32 = 256 // maximum value of uint32 is 4,294,967,295
47 | )
48 | fmt.Printf("%v, %T\n", a, a)
49 | fmt.Printf("%v, %T\n", b, b)
50 | fmt.Printf("%v, %T\n", c, c)
51 | fmt.Printf("%v, %T\n", d, d)
52 | // fmt.Println(a+b) --> invalid operation because different data types
53 | fmt.Println(int8(a) + b) // --> valid operation because same data type
54 | }
55 | func operationInt() {
56 | a := 10 // 1010
57 | b := 3 // 0011
58 | fmt.Println(a & b) // 0010 = 2
59 | fmt.Println(a | b) // 1011 = 11
60 | fmt.Println(a ^ b) // 1001 = 9
61 | fmt.Println(a &^ b) // 0100 = 4
62 | // bit shifting only in integer
63 | c := 8 // 2^3
64 | fmt.Println(c << 3) // 2^3 * 2^3 = 2^6 = 64
65 | fmt.Println(c >> 3) // 2^3 / 2^3 = 2^0 = 1
66 | }
67 | func floatingPoint() {
68 | n := 3.14
69 | fmt.Printf("%v, %T\n", n, n)
70 | n = 13.7e72
71 | fmt.Printf("%v, %T\n", n, n)
72 | n = 2.1e14
73 | fmt.Printf("%v, %T\n", n, n)
74 | // but if we want to convert float to int
75 | // we need to use the math package
76 | fmt.Println(int64(n))
77 |
78 | a := -12.5
79 | b := -3.75
80 | fmt.Println(a + b)
81 | fmt.Println(a - b)
82 | fmt.Println(a * b)
83 | fmt.Println(a / b)
84 | }
85 | func complex() {
86 | var x complex64 = 1 + 2i
87 | var y complex64 = 2 + 5.2i
88 | fmt.Printf("%v, %T\n", x, x)
89 | fmt.Printf("%v, %T\n", y, y)
90 | fmt.Println(x + y)
91 | fmt.Println(x - y)
92 | fmt.Println(x * y) // (1+2i)(2+5.2i) = 2+12.4i+4.2i+10.4i^2 = 2+16.6i-10.4 = -8.2+16.6i
93 | fmt.Println(x / y) // (1+2i)/(2+5.2i) = (1+2i)(2-5.2i)/(2+5.2i)(2-5.2i) = 1/29+4/29i-2/29-10/29i = 29/29-20/29i
94 | fmt.Printf("%v, %T\n", real(x), real(x)) // -> complex64 is a float32
95 | fmt.Printf("%v, %T\n", imag(x), imag(x)) // -> complex64 is a float32
96 | // var z complex128 = complex(5, 12) // -> not working
97 | // fmt.Printf("%v, %T\n", z, z)
98 | }
99 | func strings() {
100 | var a string = "this is a string"
101 | var b string = "much a string"
102 | fmt.Printf("%v, %T\n", a, a)
103 | fmt.Printf("%v, %T\n", a[2], a[2]) // -> 105
104 | fmt.Printf("%v, %T\n", string(a[2]), string(a[2])) // -> i
105 | fmt.Printf("%v, %T\n", a+b, a+b) // -> this is a stringmuch a string
106 | var c = []byte(a)
107 | fmt.Printf("%v, %T\n", c, c)
108 | }
109 | func rune() {
110 | // rune is an alias for int32
111 | r := 'a'
112 | fmt.Printf("%v, %T\n", r, r)
113 | }
114 | func main() {
115 | variables()
116 | differentDataTypes()
117 | operationInt()
118 | floatingPoint()
119 | complex()
120 | strings()
121 | rune()
122 | }
123 |
--------------------------------------------------------------------------------