🐛 Bug fixes on publishers and removal of dealer

This commit is contained in:
2024-10-31 22:48:51 +08:00
parent 001c9a8140
commit 1bd2da2850
11 changed files with 99 additions and 157 deletions

View File

@@ -2,29 +2,40 @@ package grpc
import (
"context"
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
"strconv"
)
func (v *Server) BroadcastDeletion(ctx context.Context, request *proto.DeletionRequest) (*proto.DeletionResponse, error) {
switch request.GetResourceType() {
case "account":
numericId, err := strconv.Atoi(request.GetResourceId())
if err != nil {
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 {
break
}
for _, model := range database.AutoMaintainRange {
switch model.(type) {
case *models.Post:
database.C.Delete(model, "author_id = ?", numericId)
default:
database.C.Delete(model, "account_id = ?", numericId)
switch resType {
case "account":
id, ok := data["id"].(string)
if !ok {
break
}
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()
}
database.C.Delete(&models.Publisher{}, "id = ?", numericId)
}
return &proto.DeletionResponse{}, nil
return &proto.EventResponse{}, nil
}