update 07.03.24
This commit is contained in:
parent
1334429590
commit
d7a1c59bec
5 changed files with 58 additions and 1 deletions
2
.idea/.gitignore
generated
vendored
2
.idea/.gitignore
generated
vendored
|
@ -6,3 +6,5 @@
|
|||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue