Paperclip/pkg/internal/grpc/services.go

48 lines
1023 B
Go
Raw Normal View History

2024-09-19 14:25:53 +00:00
package grpc
import (
"context"
2024-10-27 05:13:40 +00:00
"git.solsynth.dev/hypernet/nexus/pkg/nex"
2024-09-19 14:25:53 +00:00
"strconv"
2024-10-27 05:13:40 +00:00
"git.solsynth.dev/hypernet/nexus/pkg/proto"
2024-11-02 02:41:31 +00:00
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
2024-09-19 14:25:53 +00:00
)
2024-10-27 05:13:40 +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:25:53 +00:00
break
}
2024-10-27 05:13:40 +00:00
switch resType {
case "account":
id, ok := data["id"].(string)
if !ok {
break
2024-09-19 14:25:53 +00:00
}
2024-10-27 05:13:40 +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)
}
}
if tx.Delete(&models.Account{}, "id = ?", numericId).Error != nil {
tx.Rollback()
break
}
tx.Commit()
2024-09-19 14:25:53 +00:00
}
}
2024-10-27 05:13:40 +00:00
return &proto.EventResponse{}, nil
2024-09-19 14:25:53 +00:00
}