-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_job_status_by_etherum_address.go
61 lines (46 loc) · 1.5 KB
/
update_job_status_by_etherum_address.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package commands
import (
"context"
"database/sql"
"fmt"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/DIMO-Network/vehicle-signal-decoding/internal/infrastructure/exceptions"
"github.com/pkg/errors"
"github.com/DIMO-Network/shared/db"
"github.com/DIMO-Network/vehicle-signal-decoding/internal/infrastructure/db/models"
)
type UpdateJobStatusByEtherumAddressCommandHandler struct {
DBS func() *db.ReaderWriter
}
func NewUpdateJobStatusByEtherumAddressCommandHandler(dbs func() *db.ReaderWriter) UpdateJobStatusByEtherumAddressCommandHandler {
return UpdateJobStatusByEtherumAddressCommandHandler{DBS: dbs}
}
type UpdateJobStatusCommandRequest struct {
ID string
Status string
}
type UpdateJobStatusCommandResponse struct {
Status bool
}
func (h UpdateJobStatusByEtherumAddressCommandHandler) Execute(ctx context.Context, command *UpdateJobStatusCommandRequest) (*UpdateJobStatusCommandResponse, error) {
job, err := models.Jobs(models.JobWhere.ID.EQ(command.ID)).One(ctx, h.DBS().Reader)
if err != nil {
if !errors.Is(err, sql.ErrNoRows) {
return nil, &exceptions.InternalError{
Err: err,
}
}
if errors.Is(err, sql.ErrNoRows) {
return nil, &exceptions.NotFoundError{
Err: fmt.Errorf("could not find job id: %s", command.ID),
}
}
}
job.Status = command.Status
if _, err := job.Update(ctx, h.DBS().Writer.DB, boil.Infer()); err != nil {
return nil, &exceptions.InternalError{
Err: err,
}
}
return &UpdateJobStatusCommandResponse{Status: true}, nil
}