-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnote.txt
76 lines (61 loc) · 1.48 KB
/
note.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
1 . CRUD TODO API
2. TODO ROUTING
Models
struct atau blueprint untuk migrasi ke database
/models
//user.go
Auto Migrate
mengatur migrasi dari model ke database secara auto
/database
//migration.go
Connection
mengatur pengkoneksian ke database
>>> root:@tcp(127.0.0.1:3306)/dumbmerch
/pkg
//mysql
///mysql.go
Data Transfer Object (DTO)
A data transfer object (DTO) is an object that carries data between processes. You can use this technique to facilitate communication between two systems (like an API and your server) without potentially exposing sensitive information.
/dto
//result
///result.go
//users
///user_request.go
///user_response.go
Fetching Query with Gorm
melakukan fetching query ke database
/repositories
//users.go
Handlers
sejenis controller
yang mengatur response dan request , serta pengkoneksian database
/handlers
//users.go
Routes
end point yang mengarahkan ke handlers/controller
Find User all data using Find method
Get User data by ID using First method
Add User data using Create method
Update User data using Save method
// `User` belongs to `Company`, `CompanyID` is the foreign key
type User struct {
gorm.Model
Name string
CompanyID int
Company Company `gorm:"foreignKey:CompanyRefer"`
// use CompanyRefer as foreign key
}
type Company struct {
ID int
Name string
}
// User has one CreditCard, UserID is the foreign key
type User struct {
gorm.Model
CreditCard CreditCard
}
type CreditCard struct {
gorm.Model
Number string
UserID uint
}