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.

67 lines
1.2 KiB

  1. package Seeder
  2. import (
  3. "time"
  4. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
  5. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
  6. )
  7. func seedFriend(user, friendUser Models.User) error {
  8. var (
  9. friend Models.Friend
  10. err error
  11. )
  12. friend = Models.Friend{
  13. UserID: user.ID,
  14. FriendID: encryptWithPublicKey(friendUser.ID.Bytes(), decodedPublicKey),
  15. AcceptedAt: time.Now(),
  16. }
  17. err = Database.CreateFriendRequest(&friend)
  18. if err != nil {
  19. return err
  20. }
  21. friend = Models.Friend{
  22. UserID: friendUser.ID,
  23. FriendID: encryptWithPublicKey(user.ID.Bytes(), decodedPublicKey),
  24. AcceptedAt: time.Now(),
  25. }
  26. return Database.CreateFriendRequest(&friend)
  27. }
  28. func SeedFriends() {
  29. var (
  30. primaryUser Models.User
  31. secondaryUser Models.User
  32. i int
  33. err error
  34. )
  35. primaryUser, err = Database.GetUserByUsername("testUser")
  36. if err != nil {
  37. panic(err)
  38. }
  39. secondaryUser, err = Database.GetUserByUsername("testUser2")
  40. if err != nil {
  41. panic(err)
  42. }
  43. err = seedFriend(primaryUser, secondaryUser)
  44. for i = 0; i <= 3; i++ {
  45. secondaryUser, err = Database.GetUserByUsername(userNames[i])
  46. if err != nil {
  47. panic(err)
  48. }
  49. err = seedFriend(primaryUser, secondaryUser)
  50. if err != nil {
  51. panic(err)
  52. }
  53. }
  54. }