🐛 Bug fixes on publishers and removal of dealer
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user