✨ Support broadcast deletion
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
health "google.golang.org/grpc/health/grpc_health_v1"
|
||||
@ -9,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
proto.UnimplementedServiceDirectoryServer
|
||||
}
|
||||
|
||||
var S *grpc.Server
|
||||
@ -17,6 +19,7 @@ func NewGRPC() {
|
||||
S = grpc.NewServer()
|
||||
|
||||
health.RegisterHealthServer(S, &Server{})
|
||||
proto.RegisterServiceDirectoryServer(S, &Server{})
|
||||
|
||||
reflection.Register(S)
|
||||
}
|
||||
|
30
pkg/internal/grpc/services.go
Normal file
30
pkg/internal/grpc/services.go
Normal file
@ -0,0 +1,30 @@
|
||||
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"
|
||||
"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 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
database.C.Delete(&models.Account{}, "id = ?", numericId)
|
||||
}
|
||||
|
||||
return &proto.DeletionResponse{}, nil
|
||||
}
|
Reference in New Issue
Block a user