event type added to server , removed from query

This commit is contained in:
Chris kerr 2024-07-22 21:15:36 -04:00
parent 29875a560d
commit 2f3d2be7d9
2 changed files with 14 additions and 4 deletions

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"grain/events"
server "grain/server/types" server "grain/server/types"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
@ -13,10 +12,10 @@ import (
) )
// QueryEvents queries events from the MongoDB collection based on filters // 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) collection := client.Database(databaseName).Collection(collectionName)
var results []events.Event var results []server.Event
for _, filter := range filters { for _, filter := range filters {
filterBson := bson.M{} filterBson := bson.M{}
@ -56,7 +55,7 @@ func QueryEvents(filters []server.Filter, client *mongo.Client, databaseName, co
defer cursor.Close(context.TODO()) defer cursor.Close(context.TODO())
for cursor.Next(context.TODO()) { for cursor.Next(context.TODO()) {
var event events.Event var event server.Event
if err := cursor.Decode(&event); err != nil { if err := cursor.Decode(&event); err != nil {
return nil, fmt.Errorf("error decoding event: %v", err) return nil, fmt.Errorf("error decoding event: %v", err)
} }

11
server/types/event.go Normal file
View File

@ -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"`
}