Skip to content

Commit 83688d0

Browse files
committed
feat: return user's books when get detail
1 parent c847f0f commit 83688d0

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

entity/user.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package entity
22

33
type User struct {
4-
ID uint64 `gorm:"primary_key:auto_increment" json:"id"`
5-
Name string `gorm:"type:varchar(255)" json:"name"`
6-
Email string `gorm:"type:varchar(255);unique" json:"email"`
7-
Password string `gorm:"->;<-;not null" json:"-"`
8-
Token string `gorm:"-" json:"token,omitempty"`
4+
ID uint64 `gorm:"primary_key:auto_increment" json:"id"`
5+
Name string `gorm:"type:varchar(255)" json:"name"`
6+
Email string `gorm:"type:varchar(255);unique" json:"email"`
7+
Password string `gorm:"->;<-;not null" json:"-"`
8+
Token string `gorm:"-" json:"token,omitempty"`
9+
Books *[]Book `json:"books,omitempty"`
910
}

repository/user-repository.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (db *userConnection) UpdateUser(user entity.User) entity.User {
4848

4949
func (db *userConnection) GetUser(userID string) entity.User {
5050
var user entity.User
51-
db.connection.Find(&user, userID)
51+
db.connection.Preload("Books.User").Find(&user, userID)
5252
return user
5353
}
5454

0 commit comments

Comments
 (0)