Skip to content

Commit

Permalink
add manufacturer to device def
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesReate committed Oct 1, 2024
1 parent 6e1b10a commit 0e8fa31
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Run `make help` to see some helpful sub-commands:

## If you're using MacOS, install latest make

`brew install make`

`make` will now be called `gmake`

```
% make help
Expand Down
2 changes: 1 addition & 1 deletion graph/aftermarket.resolvers.go

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

2 changes: 1 addition & 1 deletion graph/dcn.resolvers.go

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

2 changes: 1 addition & 1 deletion graph/devicedefinition.resolvers.go

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

2 changes: 1 addition & 1 deletion graph/manufacturer.resolvers.go

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

2 changes: 1 addition & 1 deletion graph/reward.resolvers.go

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

2 changes: 1 addition & 1 deletion graph/schema.resolvers.go

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

2 changes: 1 addition & 1 deletion graph/synthetic.resolvers.go

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

2 changes: 1 addition & 1 deletion graph/vehicle.resolvers.go

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

14 changes: 11 additions & 3 deletions internal/repositories/devicedefinition/devicedefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/DIMO-Network/identity-api/internal/repositories/manufacturer"
"slices"
"strings"

Expand Down Expand Up @@ -73,13 +74,20 @@ type Repository struct {
TablelandApiService *services.TablelandApiService
}

func ToAPI(v *DeviceDefinitionTablelandModel) (*gmodel.DeviceDefinition, error) {
func ToAPI(v *DeviceDefinitionTablelandModel, mfr *models.Manufacturer) (*gmodel.DeviceDefinition, error) {
var result = gmodel.DeviceDefinition{
DeviceDefinitionID: v.ID,
LegacyID: &v.KSUID,
Year: v.Year,
Model: v.Model,
}
if mfr != nil {
gmfr, err := manufacturer.ToAPI(mfr)
if err != nil {
return nil, err
}
result.Manufacturer = gmfr
}

if v.ImageURI != "" {
result.ImageURI = &v.ImageURI
Expand Down Expand Up @@ -141,7 +149,7 @@ func (r *Repository) GetDeviceDefinition(ctx context.Context, by gmodel.DeviceDe
return nil, errors.New("no device definition found with that id")
}

return ToAPI(&modelTableland[0])
return ToAPI(&modelTableland[0], mfr)
}

func (r *Repository) GetDeviceDefinitions(ctx context.Context, tableID, first *int, after *string, last *int, before *string, filterBy *gmodel.DeviceDefinitionFilter) (*gmodel.DeviceDefinitionConnection, error) {
Expand Down Expand Up @@ -254,7 +262,7 @@ func (r *Repository) GetDeviceDefinitions(ctx context.Context, tableID, first *i
nodes := make([]*gmodel.DeviceDefinition, len(all))

for i, dv := range all {
gv, err := ToAPI(&dv)
gv, err := ToAPI(&dv, nil)
if err != nil {
errList = append(errList, gqlerror.Wrap(err))
continue
Expand Down

0 comments on commit 0e8fa31

Please sign in to comment.