103 lines
2.2 KiB
Go
103 lines
2.2 KiB
Go
package controllers
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand/v2"
|
|
|
|
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
|
"git.readonly.ch/bouzoure/pop-camarades/models"
|
|
"github.com/brianvoe/gofakeit/v7"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func DebugFakeMembers(c *fiber.Ctx) error {
|
|
number, _ := c.ParamsInt("number")
|
|
|
|
db, err := helpers.GetDatabase()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var sections []models.Section
|
|
result := db.Find(§ions, "contains_members = ?", true)
|
|
|
|
if result.Error != nil {
|
|
return result.Error
|
|
}
|
|
|
|
if result.RowsAffected < 1 {
|
|
return fiber.NewError(400, "cannot create members because no sections")
|
|
}
|
|
|
|
for i := 0; i < number; i++ {
|
|
section := sections[rand.IntN(len(sections))]
|
|
address := gofakeit.Address()
|
|
address2 := fmt.Sprintf("C/O %s", gofakeit.Name())
|
|
|
|
person := models.Person{
|
|
IsMember: true,
|
|
FirstName: gofakeit.FirstName(),
|
|
LastName: gofakeit.LastName(),
|
|
Email: gofakeit.Email(),
|
|
Phone: gofakeit.Phone(),
|
|
Mobile: gofakeit.Phone(),
|
|
Address1: address.Street,
|
|
Address2: address2,
|
|
PostalCode: address.Zip[:4],
|
|
City: address.City,
|
|
SectionID: section.ID,
|
|
}
|
|
|
|
db.Create(&person)
|
|
}
|
|
|
|
return c.SendString(fmt.Sprintf(
|
|
"Created %d member(s)", number,
|
|
))
|
|
}
|
|
|
|
func DebugFakeContacts(c *fiber.Ctx) error {
|
|
number, _ := c.ParamsInt("number")
|
|
|
|
db, err := helpers.GetDatabase()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var sections []models.Section
|
|
result := db.Find(§ions, "contains_contacts = ?", true)
|
|
|
|
if result.Error != nil {
|
|
return result.Error
|
|
}
|
|
|
|
if result.RowsAffected < 1 {
|
|
return fiber.NewError(400, "cannot create contacts because no sections")
|
|
}
|
|
|
|
for i := 0; i < number; i++ {
|
|
section := sections[rand.IntN(len(sections))]
|
|
address := gofakeit.Address()
|
|
address2 := fmt.Sprintf("C/O %s", gofakeit.Name())
|
|
|
|
person := models.Person{
|
|
IsContact: true,
|
|
FirstName: gofakeit.FirstName(),
|
|
LastName: gofakeit.LastName(),
|
|
Email: gofakeit.Email(),
|
|
Phone: gofakeit.Phone(),
|
|
Mobile: gofakeit.Phone(),
|
|
Address1: address.Street,
|
|
Address2: address2,
|
|
PostalCode: address.Zip[:4],
|
|
City: address.City,
|
|
SectionID: section.ID,
|
|
}
|
|
|
|
db.Create(&person)
|
|
}
|
|
|
|
return c.SendString(fmt.Sprintf(
|
|
"Created %d contact(s)", number,
|
|
))
|
|
}
|