mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-11-22 08:37:13 +00:00
event type added to server , removed from query
This commit is contained in:
parent
29875a560d
commit
2f3d2be7d9
@ -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
11
server/types/event.go
Normal 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"`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user