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.

55 lines
859 B

  1. package Seeder
  2. import (
  3. "git.tovijaeschke.xyz/tovi/SuddenImpactRecords/Database"
  4. "git.tovijaeschke.xyz/tovi/SuddenImpactRecords/Models"
  5. )
  6. func createPost(userData Models.User) (Models.Post, error) {
  7. var (
  8. postData Models.Post
  9. err error
  10. )
  11. postData = Models.Post{
  12. UserID: userData.ID,
  13. Title: "Test post",
  14. Content: "Test content",
  15. FrontPage: true,
  16. Order: 1,
  17. PostLinks: []Models.PostLink{
  18. {
  19. Type: "Facebook",
  20. Link: "http://facebook.com/",
  21. },
  22. },
  23. }
  24. err = Database.CreatePost(&postData)
  25. return postData, err
  26. }
  27. func SeedPosts() {
  28. var (
  29. userData Models.User
  30. i int
  31. err error
  32. )
  33. err = Database.DB.
  34. Model(Models.User{}).
  35. First(&userData).
  36. Error
  37. if err != nil {
  38. panic(err)
  39. }
  40. for i = 0; i <= 20; i++ {
  41. _, err = createPost(userData)
  42. if err != nil {
  43. panic(err)
  44. }
  45. }
  46. }