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