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-2056 Different images for Macaron NFTs #210

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Settings struct {
VehicleNFTAddress string `yaml:"VEHICLE_NFT_ADDRESS"`
ContractsEventTopic string `yaml:"CONTRACT_EVENT_TOPIC"`
AutoPiNFTImage string `yaml:"AUTOPI_NFT_IMAGE"`
MacaronNFTImage string `yaml:"MACARON_NFT_IMAGE"`
VincarioAPIURL string `yaml:"VINCARIO_API_URL"`
VincarioAPISecret string `yaml:"VINCARIO_API_SECRET"`
VincarioAPIKey string `yaml:"VINCARIO_API_KEY"`
Expand Down
25 changes: 20 additions & 5 deletions internal/controllers/nft_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,20 +419,35 @@ func (nc *NFTController) GetAftermarketDeviceNFTImage(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("Couldn't parse token id %q.", tis))
}

exists, err := models.AftermarketDevices(
ad, err := models.AftermarketDevices(
models.AftermarketDeviceWhere.TokenID.EQ(types.NewNullDecimal(new(decimal.Big).SetBigMantScale(ti, 0))),
).Exists(c.Context(), nc.DBS().Reader)
).One(c.Context(), nc.DBS().Reader)
if err != nil {
if err == sql.ErrNoRows {
return fiber.NewError(fiber.StatusNotFound, "No device with id.")
}
return err
}

dm, err := nc.deviceDefSvc.GetMakeByTokenID(c.Context(), ad.DeviceManufacturerTokenID.Int(nil))
if err != nil {
return err
}

if !exists {
return fiber.NewError(fiber.StatusNotFound, "No device with id.")
var key string

switch dm.Name {
case constants.AutoPiVendor:
key = nc.Settings.AutoPiNFTImage
case "Hashdog":
key = nc.Settings.MacaronNFTImage
default:
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("No NFT image for manufacturer %s.", dm.Name))
}

s3o, err := nc.s3.GetObject(c.Context(), &s3.GetObjectInput{
Bucket: aws.String(nc.Settings.NFTS3Bucket),
Key: aws.String(nc.Settings.AutoPiNFTImage),
Key: aws.String(key),
})
if err != nil {
nc.log.Err(err).Msg("Failure communicating with S3.")
Expand Down
Loading