Skip to content
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

Merged
merged 67 commits into from
May 23, 2024

Conversation

rhvivancoeffio
Copy link
Contributor

No description provided.

Copy link

linear bot commented Apr 5, 2024

Copy link
Contributor

@KevinJoiner KevinJoiner left a 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.

internal/config/settings.go Outdated Show resolved Hide resolved
Comment on lines 4 to 15
"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"
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The references was updated

internal/repositories/devicedefinition/devicedefinition.go Outdated Show resolved Hide resolved
internal/repositories/devicedefinition/devicedefinition.go Outdated Show resolved Hide resolved
graph/schema/devicedefinition.graphqls Outdated Show resolved Hide resolved
internal/repositories/devicedefinition/devicedefinition.go Outdated Show resolved Hide resolved
internal/repositories/devicedefinition/devicedefinition.go Outdated Show resolved Hide resolved
internal/repositories/devicedefinition/devicedefinition.go Outdated Show resolved Hide resolved
graph/schema/devicedefinition.graphqls Show resolved Hide resolved
func ToAPI(v *DeviceDefinitionTablelandModel) *gmodel.DeviceDefinition {
var result = gmodel.DeviceDefinition{}

result.ID = v.ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@rhvivancoeffio rhvivancoeffio marked this pull request as ready for review April 24, 2024 12:42
.gitignore Outdated
@@ -23,3 +23,5 @@ settings.yaml

.idea

# Desktop Service Store (macOS)
.DS_Store
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it.

}

logger.Info().Msg("Contract events consumer started.")
//kc := kafka.Config{
Copy link
Member

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!!

)

// Devicedefinition is the resolver for the devicedefinition field.
func (r *queryResolver) Devicedefinition(ctx context.Context, by model.DevicedefinitionBy) (*model.DeviceDefinition, error) {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition was updated

}

// NewResolver creates a new Resolver with allocated repositories.
func NewResolver(baseRepo *base.Repository) *Resolver {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Member

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.

Comment on lines 55 to 75
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
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property was updated

Comment on lines 235 to 238
if errList != nil {
return res, errList
}
return res, nil
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The func was updated

Comment on lines 35 to 36
contractAddress := common.HexToAddress(m.settings.DIMORegistryAddr)
queryInstance, err := contracts.NewRegistry(contractAddress, m.client)
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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.

Comment on lines 48 to 54
if err != nil {
return fmt.Errorf("failed to complete request: %w", err)
}

if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why two of these?

Copy link
Contributor Author

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)
Copy link
Member

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"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition was updated

}

logger.Info().Msg("Contract events consumer started.")
//kc := kafka.Config{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please uncomment this function


ethClient, err := ethclient.Dial(baseRepo.Settings.EthereumRPCURL)
if err != nil {
fmt.Print("Failed to create Ethereum client.")
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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())

Copy link
Contributor Author

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)
Copy link
Contributor

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) {
Copy link
Contributor

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() {
Copy link
Contributor

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

@elffjs
Copy link
Member

elffjs commented May 2, 2024

Will take a look tomorrow. Sorry about the delay.

.gitignore Outdated
@@ -23,3 +23,5 @@ settings.yaml

.idea

# Desktop Service Store (macOS)
.DS_Store
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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()
Copy link
Member

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 {
Copy link
Member

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.

}

// NewResolver creates a new Resolver with allocated repositories.
func NewResolver(baseRepo *base.Repository) *Resolver {

Copy link
Member

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.

@@ -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 {
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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?

Copy link
Member

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!
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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 {
Copy link
Member

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.

@JamesReate JamesReate merged commit 5f5caf8 into main May 23, 2024
2 checks passed
@JamesReate JamesReate deleted the feature/identity-api-devicedefinition-query-tableland branch May 23, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants