🐛 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

@ -6,13 +6,13 @@ import (
"time"
)
func (v *Server) Check(ctx context.Context, request *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
func (v *App) Check(ctx context.Context, request *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
return &health.HealthCheckResponse{
Status: health.HealthCheckResponse_SERVING,
}, nil
}
func (v *Server) Watch(request *health.HealthCheckRequest, server health.Health_WatchServer) error {
func (v *App) Watch(request *health.HealthCheckRequest, server health.Health_WatchServer) error {
for {
if server.Send(&health.HealthCheckResponse{
Status: health.HealthCheckResponse_SERVING,

View File

@ -9,14 +9,14 @@ import (
"net"
)
type Server struct {
type App struct {
proto.UnimplementedDirectoryServiceServer
srv *grpc.Server
}
func NewGrpc() *Server {
server := &Server{
func NewGrpc() *App {
server := &App{
srv: grpc.NewServer(),
}
@ -28,7 +28,7 @@ func NewGrpc() *Server {
return server
}
func (v *Server) Listen() error {
func (v *App) Listen() error {
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
if err != nil {
return err

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
}