mirror of
https://github.com/wisplite/tether.git
synced 2026-05-01 06:22:41 -05:00
mutation proof of concept
client can now send mutations and server properly executes them TODO: implement query execution, add auth, add storage
This commit is contained in:
+11
-5
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/google/uuid"
|
||||
"github.com/wisplite/tether"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -16,11 +17,11 @@ type User struct {
|
||||
}
|
||||
|
||||
type Messages struct {
|
||||
ID string `gorm:"primaryKey"`
|
||||
Message string
|
||||
SenderID string
|
||||
ReceiverID string
|
||||
CreatedAt time.Time
|
||||
ID string `gorm:"primaryKey"`
|
||||
Message string
|
||||
SenderID string
|
||||
RoomID string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -42,6 +43,11 @@ func main() {
|
||||
return nil
|
||||
})
|
||||
|
||||
engine.RegisterMutation("createMessage", func(ctx *tether.MutationCtx) error {
|
||||
ctx.DB.Create(&Messages{ID: uuid.NewString(), Message: ctx.Params["message"].(string), SenderID: ctx.AuthCtx.UserID, RoomID: ctx.Params["room"].(string)})
|
||||
return nil
|
||||
})
|
||||
|
||||
http.HandleFunc("/tether", engine.Handle)
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user