Skip to content

Commit

Permalink
SI-2707-vehicle-by-sd (#109)
Browse files Browse the repository at this point in the history
* query vehicle from synthetic device

* clean up

* not a pointer

* not a pointer prt 2

* update comment

* Edit vehicle link doc

---------

Co-authored-by: Dylan Moreland <dylan@dimo.zone>
  • Loading branch information
Allyson-English and elffjs committed Jun 17, 2024
1 parent 18eaeb5 commit cfbd94d
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 9 deletions.
7 changes: 7 additions & 0 deletions gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ models:
type: "*int"
ManufacturerID:
type: "int"
SyntheticDevice:
fields:
vehicle:
resolver: true
extraFields:
VehicleID:
type: "int"
Vehicle:
fields:
manufacturer:
Expand Down
146 changes: 140 additions & 6 deletions graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions graph/schema/synthetic.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ type SyntheticDevice implements Node {
The block timestamp at which this device was minted.
"""
mintedAt: Time!
"""
The vehicle with which the synthetic device is paired.
"""
vehicle: Vehicle!
}

"""
Expand Down
11 changes: 11 additions & 0 deletions graph/synthetic.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions internal/repositories/synthetic/synthetic_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func ToAPI(sd *models.SyntheticDevice) (*gmodel.SyntheticDevice, error) {
IntegrationID: sd.IntegrationID,
Address: common.BytesToAddress(sd.DeviceAddress),
MintedAt: sd.MintedAt,
VehicleID: sd.VehicleID,
}, nil
}

Expand Down Expand Up @@ -101,15 +102,15 @@ func (r *Repository) GetSyntheticDevices(ctx context.Context, first *int, last *
queryMods = append(queryMods, models.SyntheticDeviceWhere.ID.GT(beforeID))
}

orderBy := "DESC"
orderBy := " DESC"
if last != nil {
orderBy = "ASC"
orderBy = " ASC"
}

queryMods = append(queryMods,
// Use limit + 1 here to check if there's another page.
qm.Limit(limit+1),
qm.OrderBy(models.SyntheticDeviceColumns.ID+" "+orderBy),
qm.OrderBy(models.SyntheticDeviceColumns.ID+orderBy),
)

all, err := models.SyntheticDevices(queryMods...).All(ctx, r.PDB.DBS().Reader)
Expand Down
1 change: 1 addition & 0 deletions internal/repositories/synthetic/synthetic_devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func Test_SyntheticDeviceToAPI(t *testing.T) {
IntegrationID: 2,
Address: *wallet,
MintedAt: currTime,
VehicleID: sd.VehicleID,
}, res)
}

Expand Down

0 comments on commit cfbd94d

Please sign in to comment.