f-21: refactor: add dispatcher layer for MQTT migration
Introduce internal/dispatcher package with a Command interface and typed commands (CreateVPC, DeleteVPC, CreateSubnet, DeleteSubnet). The API handlers now call dispatcher.Dispatch() instead of enqueuing closures directly, decoupling transport (HTTP today, MQTT tomorrow) from execution. Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
40fa49d3a9
commit
064b90f5e4
9 changed files with 114 additions and 39 deletions
35
internal/dispatcher/vpc_commands.go
Normal file
35
internal/dispatcher/vpc_commands.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package dispatcher
|
||||
|
||||
import (
|
||||
"git.g3e.fr/syonad/two/internal/vpc"
|
||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
type CreateVPCCommand struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (c CreateVPCCommand) Execute(db *badger.DB) error {
|
||||
kv.AddInDB(db, "vpc/"+c.Name+"/state", "creating")
|
||||
return vpc.CreateVPC(db, c.Name)
|
||||
}
|
||||
|
||||
type DeleteVPCCommand struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (c DeleteVPCCommand) Execute(db *badger.DB) error {
|
||||
kv.AddInDB(db, "vpc/"+c.Name+"/state", "deleting")
|
||||
if err := vpc.DeleteVPC(db, c.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
state, err := kv.GetFromDB(db, "vpc/"+c.Name+"/state")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if state == "deleted" {
|
||||
kv.DeleteInDB(db, "vpc/"+c.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue