👽 Update account delete handler

This commit is contained in:
LittleSheep 2025-03-01 14:10:45 +08:00
parent 625e86a7fd
commit 4a7e41d4a9

View File

@ -2,10 +2,11 @@ package grpc
import ( import (
"context" "context"
"git.solsynth.dev/hypernet/interactive/pkg/internal/database" "git.solsynth.dev/hypernet/interactive/pkg/internal/database"
"git.solsynth.dev/hypernet/nexus/pkg/nex" "git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/proto" "git.solsynth.dev/hypernet/nexus/pkg/proto"
"strconv" jsoniter "github.com/json-iterator/go"
) )
func (v *App) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*proto.EventResponse, error) { func (v *App) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*proto.EventResponse, error) {
@ -18,19 +19,17 @@ func (v *App) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*proto.E
} }
switch resType { switch resType {
case "account": case "account":
id, ok := data["id"].(string) var data struct {
if !ok { ID int `json:"id"`
break
} }
numericId, err := strconv.Atoi(id) if err := jsoniter.Unmarshal(in.GetData(), &data); err != nil {
if err != nil {
break break
} }
tx := database.C.Begin() tx := database.C.Begin()
for _, model := range database.AutoMaintainRange { for _, model := range database.AutoMaintainRange {
switch model.(type) { switch model.(type) {
default: default:
tx.Delete(model, "account_id = ?", numericId) tx.Delete(model, "account_id = ?", data)
} }
} }
tx.Commit() tx.Commit()