-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.go
61 lines (54 loc) · 1.54 KB
/
db.go
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
package main
import (
"github.com/ahmdrz/goinsta"
)
type User struct {
Id int64 `gorm:"primary_key"`
Username string `gorm:"type:varchar(32);not null"`
FullName string `gorm:"type:varchar(64)"`
Biography string `gorm:"size:255"`
Email string `gorm:"type:varchar(64)"`
Phone string `gorm:"type:varchar(20)"`
Media int
MediaCount int // objects in database
Followers int
Following int
Highlights int
IsPrivate bool
}
func copyGuserToUser(guser *goinsta.User, user *User) {
user.Id = guser.ID
user.Username = guser.Username
user.FullName = guser.FullName
user.Biography = guser.Biography
user.Email = guser.PublicEmail
user.Phone = guser.PublicPhoneNumber
user.Media = guser.MediaCount
user.Followers = guser.FollowerCount
user.Following = guser.FollowingCount
user.IsPrivate = guser.IsPrivate
}
type Feed struct {
//User User `gorm:"foreignkey:UserId"`
UserId int64 `gorm:"primary_key" sql:"TYPE:int not null REFERENCES users(id)"`
Id int64 `gorm:"primary_key" sql:"TYPE:int not null"`
Username string `gorm:"type:varchar(32);NOT NULL"`
Path string `gorm:"size:2048"`
Url string `gorm:"size:2048"`
Deleted bool
}
func copyItemToFeed(item *goinsta.Item, feed *Feed) {
feed.UserId = item.User.ID
feed.Id = item.Pk
feed.Username = item.User.Username
}
type Stories struct {
Feed
Title string `gorm:"varchar(32)"`
Highlight bool
}
func copyItemToStory(item *goinsta.Item, story *Stories) {
story.Id = item.Pk
story.UserId = item.User.ID
story.Username = item.User.Username
}