Skip to content

Commit

Permalink
feat: add emoteHasSound and emoteHasGeometry filters (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
meelrossi committed Sep 6, 2023
1 parent aa726d5 commit a4b68de
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 13 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"printWidth": 80
},
"dependencies": {
"@dcl/schemas": "^9.1.0",
"@dcl/schemas": "^9.5.0",
"@well-known-components/env-config-provider": "^1.2.0",
"@well-known-components/http-requests-logger-component": "^2.1.0",
"@well-known-components/http-server": "^1.1.6",
Expand Down
4 changes: 3 additions & 1 deletion src/adapters/handlers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const getItemsParams = (params: Params) => {
? ethers.utils.parseEther(minPrice).toString()
: undefined,
urns: params.getList('urn'),
ids: params.getList('id')
ids: params.getList('id'),
emoteHasSound: params.getBoolean('emoteHasSound'),
emoteHasGeometry: params.getBoolean('emoteHasGeometry'),
}
}
4 changes: 4 additions & 0 deletions src/logic/nfts/collections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ describe('when building a result from the collections subgraph fragment', () =>
rarity: Rarity.LEGENDARY,
bodyShapes: [BodyShape.MALE, BodyShape.FEMALE],
loop: false,
hasSound: false,
hasGeometry: false,
},
}
})
Expand All @@ -82,6 +84,8 @@ describe('when building a result from the collections subgraph fragment', () =>
bodyShapes: [BodyShape.MALE, BodyShape.FEMALE],
rarity: Rarity.LEGENDARY,
loop: false,
hasGeometry: false,
hasSound: false
})
})
})
Expand Down
8 changes: 7 additions & 1 deletion src/logic/nfts/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const getCollectionsFields = () => `
rarity
bodyShapes
loop
hasSound
hasGeometry
}
}
createdAt
Expand Down Expand Up @@ -105,7 +107,9 @@ export type CollectionsFields = Omit<
category: EmoteCategory
rarity: Rarity
bodyShapes: BodyShape[]
loop: boolean
loop: boolean,
hasSound: boolean,
hasGeometry: boolean
} | null
}
createdAt: string
Expand Down Expand Up @@ -177,6 +181,8 @@ export function fromCollectionsFragment(
description: fragment.metadata.emote!.description,
rarity: fragment.metadata.emote!.rarity,
loop: fragment.metadata.emote!.loop,
hasSound: fragment.metadata.emote!.hasSound,
hasGeometry: fragment.metadata.emote!.hasGeometry
},
}
break
Expand Down
17 changes: 14 additions & 3 deletions src/ports/catalog/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ export const getIdsWhere = (filters: CatalogFilters) => {
return SQL`items.id = ANY(${filters.ids})`
}

export const getHasSoundWhere = () => {
return SQL`items.search_emote_has_sound = true`
}

export const getHasGeometryWhere = () => {
return SQL`items.search_emote_has_geometry = true`
}

export const getUrnsWhere = (filters: CatalogFilters) => {
return SQL`items.urn = ANY(${filters.urns})`
}
Expand Down Expand Up @@ -228,6 +236,8 @@ export const getCollectionsQueryWhere = (filters: CatalogFilters) => {
filters.onlyListing ? getOnlyListingsWhere() : undefined,
filters.onlyMinting ? getOnlyMintingWhere() : undefined,
filters.ids?.length ? getIdsWhere(filters) : undefined,
filters.emoteHasSound ? getHasSoundWhere() : undefined,
filters.emoteHasGeometry ? getHasGeometryWhere() : undefined,
filters.urns?.length ? getUrnsWhere(filters) : undefined,
].filter(Boolean)

Expand Down Expand Up @@ -394,9 +404,10 @@ export const getCollectionsItemsCatalogQuery = (
emote.body_shapes,
emote.rarity,
emote.name,
emote.loop
FROM
`
emote.loop,
emote.has_sound,
emote.has_geometry
FROM `
)
.append(schemaVersion)
.append(
Expand Down
2 changes: 2 additions & 0 deletions src/ports/catalog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export type CollectionsItemDBResult = {
rarity: string
name: string
loop?: boolean
has_sound: boolean,
has_geometry: boolean
}
urn: string
}
Expand Down
4 changes: 4 additions & 0 deletions src/ports/catalog/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export function fromCollectionsItemDbResultToCatalogItem(
rarity,
loop,
category: emoteCategory,
has_sound,
has_geometry
} = dbItem.metadata
;(name = emoteName), (category = NFTCategory.EMOTE)
data = {
Expand All @@ -109,6 +111,8 @@ export function fromCollectionsItemDbResultToCatalogItem(
bodyShapes: body_shapes as BodyShape[],
rarity: rarity as Rarity,
loop: !!loop,
hasSound: !!has_sound,
hasGeometry: !!has_geometry
},
}
break
Expand Down
2 changes: 2 additions & 0 deletions src/ports/items/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export type ItemFragment = {
description: string
category: EmoteCategory
loop: boolean
hasSound: boolean
hasGeometry: boolean
} | null
}
searchWearableBodyShapes: BodyShape[] | null
Expand Down
2 changes: 2 additions & 0 deletions src/ports/items/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ describe('#fromItemFragment', () => {
description: 'description',
loop: false,
name: 'name',
hasGeometry: false,
hasSound: false
},
},
searchWearableBodyShapes: null,
Expand Down
4 changes: 4 additions & 0 deletions src/ports/items/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export function fromItemFragment(
bodyShapes: fragment.searchEmoteBodyShapes!,
rarity: fragment.rarity,
loop: fragment.metadata.emote!.loop,
hasGeometry: fragment.metadata.emote!.hasGeometry,
hasSound: fragment.metadata.emote!.hasSound
},
}
break
Expand Down Expand Up @@ -123,6 +125,8 @@ export const getItemFragment = () => `
description
category
loop
hasSound
hasGeometry
}
}
searchWearableBodyShapes
Expand Down
2 changes: 2 additions & 0 deletions src/tests/adapters/handlers/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ describe('getItemsParams', () => {
urns: [],
wearableCategory: undefined,
wearableGenders: [],
emoteHasSound: false,
emoteHasGeometry: false,
})
})
})
Expand Down
30 changes: 30 additions & 0 deletions src/tests/ports/catalog-queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,36 @@ test('catalog utils', () => {
])
})
})

describe('and passing emoteHasSound as true', () => {
beforeEach(() => {
filters = {
emoteCategory,
emoteHasSound: true,
}
})

it('should add the sound related definition to the WHERE', () => {
expect(getCollectionsQueryWhere(filters).text).toContain(
'items.search_emote_has_sound = true'
)
})
})

describe('and passing emoteHasGeometry as true', () => {
beforeEach(() => {
filters = {
emoteCategory,
emoteHasGeometry: true,
}
})

it('should add the geometry related definition to the WHERE', () => {
expect(getCollectionsQueryWhere(filters).text).toContain(
'items.search_emote_has_geometry = true'
)
})
})
})
})

Expand Down
4 changes: 4 additions & 0 deletions src/tests/ports/catalog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const mockedDBItemResponse: CollectionsItemDBResult = {
rarity: 'legendary',
name: 'Descension',
loop: false,
has_geometry: false,
has_sound: false
},
image:
'https://peer-lb.decentraland.org/lambdas/collections/contents/urn:decentraland:matic:collections-v2:0xe42257bb4aada439179d736a64a736be0693a4ec:2/thumbnail',
Expand Down Expand Up @@ -130,6 +132,8 @@ test('catalog component', function () {
rarity: 'legendary',
name: 'Descension',
loop: false,
has_geometry: false,
has_sound: false
},
image:
'https://peer-lb.decentraland.org/lambdas/collections/contents/urn:decentraland:matic:collections-v2:0xe42257bb4aada439179d736a64a736be0693a4ec:2/thumbnail',
Expand Down
4 changes: 4 additions & 0 deletions src/tests/ports/nfts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ describe('when fetching emotes', () => {
rarity: Rarity.COMMON,
bodyShapes: [BodyShape.MALE, BodyShape.FEMALE],
loop: false,
hasGeometry: false,
hasSound: false
},
},
createdAt: Date.now().toString(),
Expand Down Expand Up @@ -257,6 +259,8 @@ describe('when fetching nfts', () => {
rarity: Rarity.COMMON,
bodyShapes: [BodyShape.MALE, BodyShape.FEMALE],
loop: false,
hasGeometry: false,
hasSound: false
},
},
createdAt: Date.now().toString(),
Expand Down

0 comments on commit a4b68de

Please sign in to comment.