✨ Support broadcast deletion
This commit is contained in:
		
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @@ -3,7 +3,7 @@ module git.solsynth.dev/hydrogen/interactive | |||||||
| go 1.21.6 | go 1.21.6 | ||||||
|  |  | ||||||
| require ( | require ( | ||||||
| 	git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f | 	git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827 | ||||||
| 	github.com/go-playground/validator/v10 v10.17.0 | 	github.com/go-playground/validator/v10 v10.17.0 | ||||||
| 	github.com/gofiber/fiber/v2 v2.52.4 | 	github.com/gofiber/fiber/v2 v2.52.4 | ||||||
| 	github.com/json-iterator/go v1.1.12 | 	github.com/json-iterator/go v1.1.12 | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							| @@ -2,6 +2,8 @@ git.solsynth.dev/hydrogen/dealer v0.0.0-20240914133539-4a48b980f0b3 h1:ucko8l9rC | |||||||
| git.solsynth.dev/hydrogen/dealer v0.0.0-20240914133539-4a48b980f0b3/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI= | git.solsynth.dev/hydrogen/dealer v0.0.0-20240914133539-4a48b980f0b3/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI= | ||||||
| git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f h1:3jLpcws4/zmNUA60w1RtAtGNjcQd5NZCcbW5HQcUcvw= | git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f h1:3jLpcws4/zmNUA60w1RtAtGNjcQd5NZCcbW5HQcUcvw= | ||||||
| git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI= | git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI= | ||||||
|  | git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827 h1:1ACMPm2ArRpVNYrND/y/R6oPiuMfKe49fP+lG3mcNug= | ||||||
|  | git.solsynth.dev/hydrogen/dealer v0.0.0-20240919131945-00c52eba6827/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI= | ||||||
| github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= | github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= | ||||||
| github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= | ||||||
| github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| package grpc | package grpc | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
|  | 	"git.solsynth.dev/hydrogen/dealer/pkg/proto" | ||||||
| 	"github.com/spf13/viper" | 	"github.com/spf13/viper" | ||||||
| 	"google.golang.org/grpc" | 	"google.golang.org/grpc" | ||||||
| 	health "google.golang.org/grpc/health/grpc_health_v1" | 	health "google.golang.org/grpc/health/grpc_health_v1" | ||||||
| @@ -9,6 +10,7 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type Server struct { | type Server struct { | ||||||
|  | 	proto.UnimplementedServiceDirectoryServer | ||||||
| } | } | ||||||
|  |  | ||||||
| var S *grpc.Server | var S *grpc.Server | ||||||
| @@ -17,6 +19,7 @@ func NewGRPC() { | |||||||
| 	S = grpc.NewServer() | 	S = grpc.NewServer() | ||||||
|  |  | ||||||
| 	health.RegisterHealthServer(S, &Server{}) | 	health.RegisterHealthServer(S, &Server{}) | ||||||
|  | 	proto.RegisterServiceDirectoryServer(S, &Server{}) | ||||||
|  |  | ||||||
| 	reflection.Register(S) | 	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