Skip to content

Commit

Permalink
Build export layer
Browse files Browse the repository at this point in the history
  • Loading branch information
amishas157 committed Nov 19, 2024
1 parent 7e4bc5b commit 7e2951a
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 26 deletions.
27 changes: 3 additions & 24 deletions internal/input/retool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,7 @@ const (
apiKey = "test-api-key"
)

// RetoolEntityDataTransformInput is a representation of the input for the TransformRetoolEntityData function
type RetoolEntityDataTransformInput struct {
ID int `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
CreatedAt int64 `json:"created_at"`
UpdatedAt *int64 `json:"updated_at"`
Custodial bool `json:"custodial"`
NonCustodial bool `json:"non_custodial"`
HomeDomainsID int `json:"home_domains_id"`
Description string `json:"description"`
WebsiteURL string `json:"website_url"`
SdpEnabled bool `json:"sdp_enabled"`
SorobanEnabled bool `json:"soroban_enabled"`
Notes string `json:"notes"`
Verified bool `json:"verified"`
FeeSponsor bool `json:"fee_sponsor"`
AccountSponsor bool `json:"account_sponsor"`
Live bool `json:"live"`
}

func GetRetoolData(client *apiclient.APIClient) ([]RetoolEntityDataTransformInput, error) {
func GetRetoolData(client *apiclient.APIClient) ([]utils.RetoolEntityDataTransformInput, error) {
if client == nil {
client = &apiclient.APIClient{
BaseURL: baseUrl,
Expand All @@ -60,11 +39,11 @@ func GetRetoolData(client *apiclient.APIClient) ([]RetoolEntityDataTransformInpu
if !ok {
return nil, fmt.Errorf("Result is not a slice of interface")
}
retoolDataSlice := []RetoolEntityDataTransformInput{}
retoolDataSlice := []utils.RetoolEntityDataTransformInput{}

for i, item := range resultSlice {
if itemMap, ok := item.(map[string]interface{}); ok {
var resp RetoolEntityDataTransformInput
var resp utils.RetoolEntityDataTransformInput
err := utils.MapToStruct(itemMap, &resp)
if err != nil {
log.Printf("Error converting map to struct: %v", err)
Expand Down
96 changes: 94 additions & 2 deletions internal/input/retool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/stellar/go/support/http/httptest"
"github.com/stellar/go/utils/apiclient"
"github.com/stellar/stellar-etl/internal/utils"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -34,7 +35,53 @@ func TestGetRetoolData(t *testing.T) {
"fee_sponsor": false,
"account_sponsor": false,
"live": true,
"status": "live"
"status": "live",
"_home_domain": {
"id": 240,
"created_at": 1706749903897,
"home_domain": "eldorado.io",
"updated_at": 1706749903897
},
"_app_geographies_details": [
{
"id": 39,
"apps_id": 16,
"created_at": 1707887845605,
"geographies_id": [
{
"id": 176,
"created_at": 1691020699576,
"updated_at": 1706650713745,
"name": "Argentina",
"official_name": "The Argentine Republic"
},
{
"id": 273,
"created_at": 1691020699834,
"updated_at": 1706650708355,
"name": "Brazil",
"official_name": "The Federative Republic of Brazil"
}
],
"retail": false,
"enterprise": false
}
],
"_app_to_ramps_integrations": [
{
"id": 18,
"created_at": 1707617027154,
"anchors_id": 28,
"apps_id": 16,
"_anchor": {
"id": 28,
"created_at": 1705423531705,
"name": "MoneyGram",
"updated_at": 1706596979487,
"home_domains_id": 203
}
}
]
}
]`,
Header: nil,
Expand All @@ -54,7 +101,7 @@ func TestGetRetoolData(t *testing.T) {
t.Fatalf("Error calling GetRetoolData: %v", err)
}

expected := []RetoolEntityDataTransformInput{
expected := []utils.RetoolEntityDataTransformInput{
{
ID: 16,
Name: "El Dorado",
Expand All @@ -73,6 +120,51 @@ func TestGetRetoolData(t *testing.T) {
FeeSponsor: false,
AccountSponsor: false,
Live: true,
HomeDomain: utils.HomeDomain{
ID: 240,
CreatedAt: 1706749903897,
UpdatedAt: 1706749903897,
HomeDomain: "eldorado.io",
},
AppGeographiesDetails: []utils.AppGeographyDetail{
{
ID: 39,
AppsID: 16,
CreatedAt: 1707887845605,
GeographiesID: []utils.Geography{
{
ID: 176,
CreatedAt: 1691020699576,
UpdatedAt: 1706650713745,
Name: "Argentina",
OfficialName: "The Argentine Republic",
},
{
ID: 273,
CreatedAt: 1691020699834,
UpdatedAt: 1706650708355,
Name: "Brazil",
OfficialName: "The Federative Republic of Brazil",
},
},
Retail: false,
Enterprise: false,
},
},
AppToRampsIntegrations: []utils.AppToRampIntegration{
{
ID: 18,
CreatedAt: 1707617027154,
AnchorsID: 28,
AppsID: 16,
Anchor: utils.Anchor{
ID: 28,
CreatedAt: 1705423531705,
UpdatedAt: 1706596979487,
Name: "MoneyGram",
},
},
},
},
}

Expand Down
50 changes: 50 additions & 0 deletions internal/transform/retool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package transform

import (
"github.com/stellar/stellar-etl/internal/utils"
)

func TransformRetoolEntityData(entityData utils.RetoolEntityDataTransformInput) (EntityDataTransformOutput, error) {
transformedRetoolEntityData := EntityDataTransformOutput{
ID: entityData.ID,
Name: entityData.Name,
HomeDomain: entityData.HomeDomain.HomeDomain,
Status: entityData.Status,
CreatedAt: entityData.CreatedAt,
UpdatedAt: entityData.UpdatedAt,
Custodial: entityData.Custodial,
NonCustodial: entityData.NonCustodial,
HomeDomainsID: entityData.HomeDomainsID,
Description: entityData.Description,
WebsiteURL: entityData.WebsiteURL,
SdpEnabled: entityData.SdpEnabled,
SorobanEnabled: entityData.SorobanEnabled,
Notes: entityData.Notes,
Verified: entityData.Verified,
FeeSponsor: entityData.FeeSponsor,
AccountSponsor: entityData.AccountSponsor,
Live: entityData.Live,
AppGeographies: mapGeographies(entityData.AppGeographiesDetails),
Ramps: mapRamps(entityData.AppToRampsIntegrations),
}

return transformedRetoolEntityData, nil
}

func mapGeographies(appGeographies []utils.AppGeographyDetail) []string {
var geographies []string
for _, geoDetail := range appGeographies {
for _, geo := range geoDetail.GeographiesID {
geographies = append(geographies, geo.Name)
}
}
return geographies
}

func mapRamps(appRamps []utils.AppToRampIntegration) []string {
var ramps []string
for _, ramp := range appRamps {
ramps = append(ramps, ramp.Anchor.Name)
}
return ramps
}
99 changes: 99 additions & 0 deletions internal/transform/retool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package transform

import (
"testing"

"github.com/stellar/stellar-etl/internal/utils"
"github.com/stretchr/testify/assert"
)

func TestTransformRetoolEntityData(t *testing.T) {
output, _ := TransformRetoolEntityData(utils.RetoolEntityDataTransformInput{
ID: 16,
Name: "El Dorado",
Status: "live",
CreatedAt: 1706749912776,
UpdatedAt: nil,
Custodial: true,
NonCustodial: true,
HomeDomainsID: 240,
Description: "",
WebsiteURL: "",
SdpEnabled: false,
SorobanEnabled: false,
Notes: "",
Verified: false,
FeeSponsor: false,
AccountSponsor: false,
Live: true,
HomeDomain: utils.HomeDomain{
ID: 240,
CreatedAt: 1706749903897,
UpdatedAt: 1706749903897,
HomeDomain: "eldorado.io",
},
AppGeographiesDetails: []utils.AppGeographyDetail{
{
ID: 39,
AppsID: 16,
CreatedAt: 1707887845605,
GeographiesID: []utils.Geography{
{
ID: 176,
CreatedAt: 1691020699576,
UpdatedAt: 1706650713745,
Name: "Argentina",
OfficialName: "The Argentine Republic",
},
{
ID: 273,
CreatedAt: 1691020699834,
UpdatedAt: 1706650708355,
Name: "Brazil",
OfficialName: "The Federative Republic of Brazil",
},
},
Retail: false,
Enterprise: false,
},
},
AppToRampsIntegrations: []utils.AppToRampIntegration{
{
ID: 18,
CreatedAt: 1707617027154,
AnchorsID: 28,
AppsID: 16,
Anchor: utils.Anchor{
ID: 28,
CreatedAt: 1705423531705,
UpdatedAt: 1706596979487,
Name: "MoneyGram",
},
},
},
},
)
expectedOutput := EntityDataTransformOutput{
ID: 16,
Name: "El Dorado",
Status: "live",
CreatedAt: 1706749912776,
UpdatedAt: nil,
Custodial: true,
NonCustodial: true,
HomeDomainsID: 240,
Description: "",
WebsiteURL: "",
SdpEnabled: false,
SorobanEnabled: false,
Notes: "",
Verified: false,
FeeSponsor: false,
AccountSponsor: false,
Live: true,
HomeDomain: "eldorado.io",
AppGeographies: []string{"Argentina", "Brazil"},
Ramps: []string{"MoneyGram"},
}
assert.Equal(t, expectedOutput, output)
}
23 changes: 23 additions & 0 deletions internal/transform/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,26 @@ type ContractEventOutput struct {
DataDecoded map[string]string `json:"data_decoded"`
ContractEventXDR string `json:"contract_event_xdr"`
}

type EntityDataTransformOutput struct {
ID int `json:"id"`
Name string `json:"name"`
HomeDomain string `json:"home_domain"`
Status string `json:"status"`
CreatedAt int64 `json:"created_at"`
UpdatedAt *int64 `json:"updated_at"`
Custodial bool `json:"custodial"`
NonCustodial bool `json:"non_custodial"`
HomeDomainsID int `json:"home_domains_id"`
Description string `json:"description"`
WebsiteURL string `json:"website_url"`
SdpEnabled bool `json:"sdp_enabled"`
SorobanEnabled bool `json:"soroban_enabled"`
Notes string `json:"notes"`
Verified bool `json:"verified"`
FeeSponsor bool `json:"fee_sponsor"`
AccountSponsor bool `json:"account_sponsor"`
Live bool `json:"live"`
AppGeographies []string `json:"app_geographies"`
Ramps []string `json:"ramps"`
}
Loading

0 comments on commit 7e2951a

Please sign in to comment.