diff --git a/.idea/.gitignore b/.idea/.gitignore index 13566b8..a9d7db9 100644 --- a/.idea/.gitignore +++ b/.idea/.gitignore @@ -6,3 +6,5 @@ # Datasource local storage ignored files /dataSources/ /dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/readme.md b/readme.md index f0dc2a7..3008a7b 100644 --- a/readme.md +++ b/readme.md @@ -30,3 +30,5 @@ Stellen Sie sicher, dass die folgenden Tools auf Ihrem System installiert sind: ``` 4. Öffne deinen Webbrowser und gehe zu `http://localhost:3333`, um das Projekt zu sehen. + +# Todo diff --git a/src/main.go b/src/main.go index 3004789..4e4b05f 100644 --- a/src/main.go +++ b/src/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "gibb165lb2/util" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" @@ -25,7 +26,7 @@ func main() { } defer util.Client.Disconnect(ctx) r := GetRouter() - + fmt.Println("Server is running on port 3333") err = http.ListenAndServe(":3333", r) if err != nil { log.Fatal(err) diff --git a/src/router.go b/src/router.go index b91e96e..c2bd4d5 100644 --- a/src/router.go +++ b/src/router.go @@ -21,5 +21,6 @@ func GetRouter() *mux.Router { r.HandleFunc("/debts/{id}", router.GetDebt).Methods("GET") r.HandleFunc("/debts/{id}", router.UpdateDebt).Methods("PUT") r.HandleFunc("/init", util.Init).Methods("GET") + r.HandleFunc("/biginit", util.BigInit).Methods("GET") return r } diff --git a/src/util/util.go b/src/util/util.go index c7058e8..94c9da4 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -76,8 +76,59 @@ func InsertRandomData(client *mongo.Client) { } } } +func InsertRandomData2(client *mongo.Client) { + persons := []string{ + "John Smith", "Jane Doe", "Michael Johnson", "Emily Davis", "Christopher Wilson", + "Sarah Brown", "Matthew Anderson", "Jessica Miller", "William Taylor", "Olivia Garcia", + "David Martinez", "Ashley Jackson", "James White", "Emma Harris", "Daniel Thomas", + "Sophia Lee", "Joseph Moore", "Chloe Taylor", "Ryan Harris", "Mia Davis", + "Benjamin Clark", "Ava Williams", "Alexander Walker", "Grace Lewis", "Samuel Turner", + "Lily Martin", "Nicholas Harris", "Ella Thompson", "Tyler Baker", "Natalie Wright", + "Andrew Carter", "Aria Rodriguez", "Ethan Robinson", "Addison Turner", "Christopher Wright", + "Zoey Phillips", "Daniel Turner", "Victoria Brooks", "Nicholas Mitchell", "Scarlett Davis", + "Logan Wilson", "Penelope Anderson", "Caleb Baker", "Harper Martinez", "Dylan Turner", + "Layla Johnson", "Isaac Harris", "Stella Miller", "Nathan Jackson", "Sofia Clark", + "Brandon Walker", "Aurora Taylor", "Jackson Lewis", "Leah Anderson", "Owen Thompson", + "Maya Williams", "Caleb Lewis", "Addison Garcia", "Zachary Turner", "Brooklyn Wright", + "Christopher Davis", "Ellie Robinson", "Matthew Taylor", "Amelia Harris", "Gabriel Turner", + "Peyton Robinson", "Wyatt Anderson", "Zoe Martin", "Henry Harris", "Eva Phillips", + "Connor Wilson", "Scarlett Lee", "Dylan Baker", "Isabella Taylor", "Samuel Davis", + "Ava Turner", "Caleb Martinez", "Mia Walker", "Owen Lewis", "Abigail Johnson", + "Logan Clark", "Grace Harris", "Lucas Turner", "Madison Robinson", "Brayden Taylor", + "Lillian Anderson", "Jackson Martin", "Lily Harris", "Daniel Turner", "Riley Wright", + "Sebastian Turner", "Harper Davis", "Elijah Walker", "Addison Phillips", "Owen Harris", + "Chloe Robinson", "Ethan Anderson", "Zoe Taylor", "Gabriel Wilson", "Aurora Davis", + } + debts := []Debt{} + for i := 0; i < 100; i++ { + person := Person{Name: persons[i]} + collection := client.Database("debtlist").Collection("persons") + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + result, err := collection.InsertOne(ctx, person) + if err != nil { + log.Fatal(err) + } + for j := 0; j < 6; j++ { + debts = append(debts, Debt{PersonID: result.InsertedID.(primitive.ObjectID), Amount: j * 100, Description: "Test", Datetime: time.Now()}) + } + } + collection := client.Database("debtlist").Collection("debts") + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + for _, debt := range debts { + _, err := collection.InsertOne(ctx, debt) + if err != nil { + log.Fatal(err) + } + } +} func Init(w http.ResponseWriter, r *http.Request) { InsertRandomData(Client) w.Write([]byte("Init")) } +func BigInit(w http.ResponseWriter, r *http.Request) { + InsertRandomData2(Client) + w.Write([]byte("Init")) +}