grain/server/db/mongo/kinds/regular.go

24 lines
651 B
Go
Raw Permalink Normal View History

package kinds
import (
"context"
"fmt"
"grain/server/handlers/response"
relay "grain/server/types"
"go.mongodb.org/mongo-driver/mongo"
2024-07-27 14:06:34 +00:00
"golang.org/x/net/websocket"
)
2024-07-27 14:06:34 +00:00
func HandleRegularKind(ctx context.Context, evt relay.Event, collection *mongo.Collection, ws *websocket.Conn) error {
_, 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")
return fmt.Errorf("error inserting event kind %d into MongoDB: %v", evt.Kind, err)
}
fmt.Printf("Inserted event kind %d into MongoDB: %s\n", evt.Kind, evt.ID)
2024-07-27 14:06:34 +00:00
response.SendOK(ws, evt.ID, true, "")
return nil
2024-07-27 14:06:34 +00:00
}