From 2f3d2be7d99859a244d0d63b1716ef17200bff25 Mon Sep 17 00:00:00 2001 From: Chris kerr Date: Mon, 22 Jul 2024 21:15:36 -0400 Subject: [PATCH] event type added to server , removed from query --- server/query.go | 7 +++---- server/types/event.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 server/types/event.go diff --git a/server/query.go b/server/query.go index d68f9d5..8849d02 100644 --- a/server/query.go +++ b/server/query.go @@ -4,7 +4,6 @@ import ( "context" "fmt" - "grain/events" server "grain/server/types" "go.mongodb.org/mongo-driver/bson" @@ -13,10 +12,10 @@ import ( ) // QueryEvents queries events from the MongoDB collection based on filters -func QueryEvents(filters []server.Filter, client *mongo.Client, databaseName, collectionName string) ([]events.Event, error) { +func QueryEvents(filters []server.Filter, client *mongo.Client, databaseName, collectionName string) ([]server.Event, error) { collection := client.Database(databaseName).Collection(collectionName) - var results []events.Event + var results []server.Event for _, filter := range filters { filterBson := bson.M{} @@ -56,7 +55,7 @@ func QueryEvents(filters []server.Filter, client *mongo.Client, databaseName, co defer cursor.Close(context.TODO()) for cursor.Next(context.TODO()) { - var event events.Event + var event server.Event if err := cursor.Decode(&event); err != nil { return nil, fmt.Errorf("error decoding event: %v", err) } diff --git a/server/types/event.go b/server/types/event.go new file mode 100644 index 0000000..df62b57 --- /dev/null +++ b/server/types/event.go @@ -0,0 +1,11 @@ +package server + +type Event struct { + ID string `json:"id"` + PubKey string `json:"pubkey"` + CreatedAt int64 `json:"created_at"` + Kind int `json:"kind"` + Tags [][]string `json:"tags"` + Content string `json:"content"` + Sig string `json:"sig"` +}