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.

68 lines
1.3 KiB

package Seeder
import (
"encoding/base64"
"time"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
)
func seedFriend(user, friendUser Models.User) error {
var (
friend Models.Friend
err error
)
friend = Models.Friend{
UserID: user.ID,
FriendID: base64.StdEncoding.EncodeToString(encryptWithPublicKey([]byte(friendUser.ID.String()), decodedPublicKey)),
AcceptedAt: time.Now(),
}
err = Database.CreateFriendRequest(&friend)
if err != nil {
return err
}
friend = Models.Friend{
UserID: friendUser.ID,
FriendID: base64.StdEncoding.EncodeToString(encryptWithPublicKey([]byte(user.ID.String()), decodedPublicKey)),
AcceptedAt: time.Now(),
}
return Database.CreateFriendRequest(&friend)
}
func SeedFriends() {
var (
primaryUser Models.User
secondaryUser Models.User
i int
err error
)
primaryUser, err = Database.GetUserByUsername("testUser")
if err != nil {
panic(err)
}
secondaryUser, err = Database.GetUserByUsername("testUser2")
if err != nil {
panic(err)
}
err = seedFriend(primaryUser, secondaryUser)
for i = 0; i <= 3; i++ {
secondaryUser, err = Database.GetUserByUsername(userNames[i])
if err != nil {
panic(err)
}
err = seedFriend(primaryUser, secondaryUser)
if err != nil {
panic(err)
}
}
}