|
|
- package Seeder
-
- import (
- "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: encryptWithPublicKey(friendUser.ID.Bytes(), decodedPublicKey),
- AcceptedAt: time.Now(),
- }
-
- err = Database.CreateFriendRequest(&friend)
- if err != nil {
- return err
- }
-
- friend = Models.Friend{
- UserID: friendUser.ID,
- FriendID: encryptWithPublicKey(user.ID.Bytes(), 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)
- }
- }
- }
|