Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
855 B

package Database
import (
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
func GetFriendById(id string) (Models.Friend, error) {
var (
friend Models.Friend
err error
)
err = DB.Preload(clause.Associations).
First(&friend, "id = ?", id).
Error
return friend, err
}
func GetFriendsByUserId(userID string) ([]Models.Friend, error) {
var (
friends []Models.Friend
err error
)
err = DB.Model(Models.Friend{}).
Where("user_id = ?", userID).
Find(&friends).
Error
return friends, err
}
func CreateFriendRequest(friend *Models.Friend) error {
return DB.Session(&gorm.Session{FullSaveAssociations: true}).
Create(friend).
Error
}
func DeleteFriend(friend *Models.Friend) error {
return DB.Session(&gorm.Session{FullSaveAssociations: true}).
Delete(friend).
Error
}