-
Notifications
You must be signed in to change notification settings - Fork 0
/
user-repository.go
48 lines (37 loc) · 1.13 KB
/
user-repository.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
package database
import (
"github.com/Devops-2022-Group-R/itu-minitwit/src/models"
"gorm.io/gorm"
)
const userTable = "user"
type UserDTO struct {
gorm.Model
Username string `gorm:"not null;index"`
Email string `gorm:"not null"`
PasswordHash string `gorm:"not null"`
Followed []FollowDTO `gorm:"foreignkey:WhoId"`
Followers []FollowDTO `gorm:"foreignkey:WhomId"`
}
func (UserDTO) TableName() string {
return userTable
}
type FollowDTO struct {
WhoId int64 `gorm:"not null;index;index:who_id_whom_id"`
Who UserDTO `gorm:"primaryKey;foreignkey:WhoId"`
WhomId int64 `gorm:"not null;index:who_id_whom_id"`
Whom UserDTO `gorm:"primaryKey;foreignkey:WhomId"`
}
func (FollowDTO) TableName() string {
return "follower"
}
type IUserRepository interface {
Migrate() error
Create(users models.User) error
GetByID(id int64) (*models.User, error)
GetByUsername(username string) (*models.User, error)
NumUsers() (int64, error)
Follow(whoId int64, whomId int64) error
Unfollow(whoId int64, whomId int64) error
IsFollowing(whoId int64, whomId int64) (bool, error)
AllFollowed(whoId int64) ([]*models.User, error)
}