-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SI-2544 - Feature/identity api devicedefinition query tableland #88
SI-2544 - Feature/identity api devicedefinition query tableland #88
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to change the name from device definition to vehicle definitions since these queries only relate to vehicles and would not make sense for other devices in the future.
"context" | ||
"encoding/json" | ||
"fmt" | ||
gmodel "github.com/DIMO-Network/identity-api/graph/model" | ||
"github.com/DIMO-Network/identity-api/internal/helpers" | ||
"github.com/DIMO-Network/identity-api/internal/repositories/base" | ||
"github.com/vektah/gqlparser/v2/gqlerror" | ||
"golang.org/x/exp/slices" | ||
"net/http" | ||
"net/url" | ||
"path" | ||
"strings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std lib vars should be separate from external imports if you are using vscode this can be done by changing the golang formater to goimports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The references was updated
func ToAPI(v *DeviceDefinitionTablelandModel) *gmodel.DeviceDefinition { | ||
var result = gmodel.DeviceDefinition{} | ||
|
||
result.ID = v.ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result.ID = v.ID | |
globalID, err := base.EncodeGlobalTokenID(TokenPrefix, v.ID) | |
if err != nil { | |
return nil, fmt.Errorf("error encoding device definition id: %w", err) | |
} | |
result.ID = globalID | |
result.DefinitionID = v.ID |
.gitignore
Outdated
@@ -23,3 +23,5 @@ settings.yaml | |||
|
|||
.idea | |||
|
|||
# Desktop Service Store (macOS) | |||
.DS_Store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do a newline at the end of these ppc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do it.
cmd/identity-api/main.go
Outdated
} | ||
|
||
logger.Info().Msg("Contract events consumer started.") | ||
//kc := kafka.Config{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not commit this commenting out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!!
graph/devicedefinition.resolvers.go
Outdated
) | ||
|
||
// Devicedefinition is the resolver for the devicedefinition field. | ||
func (r *queryResolver) Devicedefinition(ctx context.Context, by model.DevicedefinitionBy) (*model.DeviceDefinition, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We seem split in the Go and the GraphQL on whether it's devicedefinition
or deviceDefinition
. I would vote for deviceDefinition
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The definition was updated
graph/resolver.go
Outdated
} | ||
|
||
// NewResolver creates a new Resolver with allocated repositories. | ||
func NewResolver(baseRepo *base.Repository) *Resolver { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will run around deleting these newlines.
ksuid: String | ||
|
||
""" | ||
Model for this device definition. | ||
""" | ||
model: String | ||
|
||
""" | ||
Year for this device definition. | ||
""" | ||
year: Int | ||
|
||
""" | ||
Device Type for this device definition. | ||
""" | ||
deviceType: String | ||
|
||
""" | ||
Image URI for this device definition. | ||
""" | ||
imageURI: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are some of these required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think we would follow JavaScript casing and do imageUri
. What do we do elsewhere in this repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property was updated
if errList != nil { | ||
return res, errList | ||
} | ||
return res, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd get the same result by writing return res, errList
yeah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The func was updated
contractAddress := common.HexToAddress(m.settings.DIMORegistryAddr) | ||
queryInstance, err := contracts.NewRegistry(contractAddress, m.client) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could initialize these two things just once, in the New
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The func was updated
return fmt.Errorf("failed to create request: %w", err) | ||
} | ||
|
||
resp, err := http.DefaultClient.Do(req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should use a client with a timeout, or use a context with some deadline.
if err != nil { | ||
return fmt.Errorf("failed to complete request: %w", err) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why two of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The definition was updated
} | ||
|
||
func (r *TablelandApiService) Query(ctx context.Context, queryParams map[string]string, result interface{}) error { | ||
fullURL, err := url.Parse(r.settings.TablelandAPIGateway) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do this in the "constructor"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The definition was updated
cmd/identity-api/main.go
Outdated
} | ||
|
||
logger.Info().Msg("Contract events consumer started.") | ||
//kc := kafka.Config{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please uncomment this function
graph/resolver.go
Outdated
|
||
ethClient, err := ethclient.Dial(baseRepo.Settings.EthereumRPCURL) | ||
if err != nil { | ||
fmt.Print("Failed to create Ethereum client.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error should be handled more severely, maybe a log.Fatal
or something
""" | ||
Legacy ID for this device definition. | ||
""" | ||
ksuid: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we name this something else, maybe LegacyID
. KSUID doesn't describe what the variable does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proeprty was updated
|
||
tableName, err := r.ManufacturerContractService.GetTableName(ctx, manufacturer.ID) | ||
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we wrap this error fmt.Errorf("...", err.Error())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The func was updated
var errList gqlerror.List | ||
var endCur, startCur *string | ||
//if len(all) != 0 { | ||
// //ec := helpers.IDToCursor(all[len(all)-1].ID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove comment
|
||
manufacturers, err := models.Manufacturers().All(ctx, m.PDB.DBS().Reader) | ||
if err != nil { | ||
if errors.Is(err, sql.ErrNoRows) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think .All()
returns this error (I'm not sure). You should rather check if the returned manufacturers
variable is empty
suite.Run(t, new(ManufacturerCacheServiceTestSuite)) | ||
} | ||
|
||
func (o *ManufacturerCacheServiceTestSuite) Test_Manufacturer_All_Success() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two tests that I see missing here
- Since you want to return an error when manufacturers are not found, can you write a test for that scenario too.
- Can we verify the cache data is actually being returned early as implemented here
Will take a look tomorrow. Sorry about the delay. |
.gitignore
Outdated
@@ -23,3 +23,5 @@ settings.yaml | |||
|
|||
.idea | |||
|
|||
# Desktop Service Store (macOS) | |||
.DS_Store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do it.
""" | ||
Device Definition ID for this device definition. | ||
""" | ||
deviceDefinitionID: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do deviceDefinitionId
. See "tokenId
" elsewhere.
""" | ||
Legacy ID for this device definition. | ||
""" | ||
legacyID: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, legacyId
.
//const xmigrationsDir = "../../../migrations" | ||
|
||
func TestGetDeviceDefinition(t *testing.T) { | ||
//ctx := context.Background() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still curious about this!
"github.com/rs/zerolog" | ||
) | ||
|
||
type TablelandApiService struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name this TablelandAPIService
and so one. Go casing.
graph/resolver.go
Outdated
} | ||
|
||
// NewResolver creates a new Resolver with allocated repositories. | ||
func NewResolver(baseRepo *base.Repository) *Resolver { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will run around deleting these newlines.
internal/helpers/helpers.go
Outdated
@@ -44,3 +53,17 @@ func GetAftermarketDeviceImageUrl(baseURL string, tokenID int) string { | |||
func GetVehicleDataURI(baseURL string, tokenID int) string { | |||
return fmt.Sprintf("%s%d", baseURL, tokenID) | |||
} | |||
|
|||
func SlugString(term string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe some tests would be good too.
|
||
manufacturerSlug := splitID[0] | ||
|
||
manufactures, err := r.ManufacturerCacheService.GetAllManufacturers(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix these for you.
|
||
manufacturerSlug := splitID[0] | ||
|
||
manufacturers, err := r.ManufacturerCacheService.GetAllManufacturers(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to pull and cache these? We have a manufacturers table—can we store the information we need there, using chain events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, one call you're making is to getManufacturerIdByName
, but we already have this information in the manufacturers
table. Let me think about the other part.
""" | ||
The manufacturer for the device definition. | ||
""" | ||
manufacturer: String! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still curious about this. I think this will prove difficult to use.
If we're requiring the manufacturer, maybe we make this a sub-query of the Manufacturer
object?
return nil, err | ||
} | ||
|
||
fmt.Print(statement) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's turn this into a real log statement, or delete it, something.
|
||
fmt.Print(statement) | ||
|
||
var cont = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we using this to construct the "global id" on line 49, and it's always 1? That seems odd.
fmt.Print(statement) | ||
|
||
var cont = 1 | ||
for _, item := range modelTableland { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We expect this to always have one element in it? This is a bit hard to follow.
* Reinstate and populate Vehicle.image as a @deprecated field * Regular expressions are great * Fix one image
* Present this in the API if we have it * Remove old "Definition URI" that we never used
No description provided.