-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_dbc_file.go
39 lines (29 loc) · 949 Bytes
/
update_dbc_file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package commands
import (
"context"
"github.com/DIMO-Network/shared/db"
"github.com/DIMO-Network/vehicle-signal-decoding/internal/infrastructure/db/models"
"github.com/volatiletech/sqlboiler/v4/boil"
"google.golang.org/protobuf/types/known/emptypb"
)
type UpdateDbcCommandHandler struct {
DBS func() *db.ReaderWriter
}
func NewUpsertDbcCommandHandler(dbs func() *db.ReaderWriter) UpdateDbcCommandHandler {
return UpdateDbcCommandHandler{DBS: dbs}
}
type UpsertDbcCommandRequest struct {
TemplateName string
DbcFile string
}
func (h UpdateDbcCommandHandler) Execute(ctx context.Context, req *UpsertDbcCommandRequest) (*emptypb.Empty, error) {
dbcFile := models.DBCFile{
TemplateName: req.TemplateName,
DBCFile: req.DbcFile,
}
err := dbcFile.Upsert(ctx, h.DBS().Writer, true, []string{"template_name"}, boil.Whitelist("dbc_file"), boil.Infer())
if err != nil {
return nil, err
}
return &emptypb.Empty{}, nil
}