Messaging/pkg/internal/grpc/services.go

43 lines
860 B
Go
Raw Normal View History

2024-09-19 14:23:32 +00:00
package grpc
import (
"context"
2024-11-02 05:23:27 +00:00
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
2024-09-19 14:23:32 +00:00
"strconv"
2024-11-02 05:24:37 +00:00
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
2024-09-19 14:23:32 +00:00
)
2024-11-02 05:23:27 +00:00
func (v *Server) 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 14:23:32 +00:00
break
}
2024-11-02 05:23:27 +00:00
switch resType {
case "account":
id, ok := data["id"].(string)
if !ok {
break
2024-09-19 14:23:32 +00:00
}
2024-11-02 05:23:27 +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 14:23:32 +00:00
}
}
2024-11-02 05:23:27 +00:00
return &proto.EventResponse{}, nil
2024-09-19 14:23:32 +00:00
}