2024-07-27 14:06:34 +00:00
|
|
|
// kinds/kind1.go
|
2024-07-23 17:22:55 +00:00
|
|
|
package kinds
|
2024-07-20 01:09:42 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2024-07-31 18:12:33 +00:00
|
|
|
"grain/server/handlers/response"
|
|
|
|
relay "grain/server/types"
|
2024-07-23 14:53:01 +00:00
|
|
|
|
2024-07-20 01:09:42 +00:00
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
2024-07-27 14:06:34 +00:00
|
|
|
"golang.org/x/net/websocket"
|
2024-07-20 01:09:42 +00:00
|
|
|
)
|
|
|
|
|
2024-07-27 14:06:34 +00:00
|
|
|
func HandleKind1(ctx context.Context, evt relay.Event, collection *mongo.Collection, ws *websocket.Conn) error {
|
2024-07-20 01:09:42 +00:00
|
|
|
_, err := collection.InsertOne(ctx, evt)
|
|
|
|
if err != nil {
|
2024-07-27 14:06:34 +00:00
|
|
|
response.SendOK(ws, evt.ID, false, "error: could not connect to the database")
|
2024-07-24 14:16:26 +00:00
|
|
|
return fmt.Errorf("error inserting event into MongoDB: %v", err)
|
2024-07-20 01:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Inserted event kind 1 into MongoDB:", evt.ID)
|
2024-07-27 14:06:34 +00:00
|
|
|
response.SendOK(ws, evt.ID, true, "")
|
2024-07-20 01:09:42 +00:00
|
|
|
return nil
|
|
|
|
}
|