Interactive/pkg/internal/grpc/services.go

42 lines
858 B
Go
Raw Normal View History

2024-09-19 13:57:09 +00:00
package grpc
import (
"context"
2024-11-02 05:41:51 +00:00
"git.solsynth.dev/hypernet/interactive/pkg/internal/database"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
2024-09-19 13:57:09 +00:00
"strconv"
)
func (v *App) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*proto.EventResponse, error) {
switch in.GetEvent() {
case "deletion":
data := nex.DecodeMap(in.GetData())
resType, ok := data["type"].(string)
if !ok {
2024-09-19 13:57:09 +00:00
break
}
switch resType {
case "account":
id, ok := data["id"].(string)
if !ok {
break
2024-09-19 13:57:09 +00:00
}
numericId, err := strconv.Atoi(id)
if err != nil {
break
}
tx := database.C.Begin()
for _, model := range database.AutoMaintainRange {
switch model.(type) {
default:
tx.Delete(model, "account_id = ?", numericId)
}
}
tx.Commit()
2024-09-19 13:57:09 +00:00
}
}
return &proto.EventResponse{}, nil
2024-09-19 13:57:09 +00:00
}