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

feat: Add advanced filtering capabilities #522

Merged
merged 8 commits into from
Sep 25, 2024
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
25 changes: 25 additions & 0 deletions .bruno/cards/advanced-query.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
meta {
name: Advanced Query
type: http
seq: 1
}

get {
url: {{BASE_URL}}/v2/en/cards?name=eq:Pikachu&hp=gte:60&hp=lt:70&localId=5&localId=not:tg&id=neq:cel25-5
body: none
auth: none
}

params:query {
name: eq:Pikachu
hp: gte:60
hp: lt:70
localId: 5
localId: not:tg
id: neq:cel25-5
}

assert {
res.status: eq 200
res.body: length 14
}
2 changes: 1 addition & 1 deletion .bruno/environments/Developpement.bru
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vars {
BASE_URL: http://localhost:3000
BASE_URL: http://127.0.0.1:3000
}
21 changes: 21 additions & 0 deletions .bruno/sets/Advanced Query.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
meta {
name: Advanced Query
type: http
seq: 4
}

get {
url: {{BASE_URL}}/v2/en/sets?cardCount.official=gt:64&id=swsh
body: none
auth: none
}

params:query {
cardCount.official:gt: 64
id: swsh
}

assert {
res.status: eq 200
res.body: length 17
}
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:

- name: Install deps
run: |
bun install -g @usebruno/cli
bun install --frozen-lockfile
cd server
bun install --frozen-lockfile
Expand All @@ -31,3 +32,11 @@ jobs:
bun run validate
cd server
bun run validate

- name: Validate some requests
run: |
cd server
bun run start &
sleep 10
cd ../.bruno
bru run --env Developpement
Binary file modified server/bun.lockb
Binary file not shown.
64 changes: 31 additions & 33 deletions server/src/V2/Components/Card.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
import { objectLoop } from '@dzeio/object-util'
import { CardResume, Card as SDKCard, SupportedLanguages } from '@tcgdex/sdk'
import { Query } from '../../interfaces'
import { handlePagination, handleSort, handleValidation } from '../../util'
import Set from './Set'
import type { CardResume, Card as SDKCard, SupportedLanguages } from '@tcgdex/sdk'
import { executeQuery, type Query } from '../../libs/QueryEngine/filter'
import TCGSet from './Set'

import de from '../../../generated/de/cards.json'
import en from '../../../generated/en/cards.json'
import fr from '../../../generated/fr/cards.json'
import es from '../../../generated/es/cards.json'
import fr from '../../../generated/fr/cards.json'
import id from '../../../generated/id/cards.json'
import it from '../../../generated/it/cards.json'
import pt from '../../../generated/pt/cards.json'
import ptbr from '../../../generated/pt-br/cards.json'
import ptpt from '../../../generated/pt-pt/cards.json'
import de from '../../../generated/de/cards.json'
import ja from '../../../generated/ja/cards.json'
import ko from '../../../generated/ko/cards.json'
import nl from '../../../generated/nl/cards.json'
import pl from '../../../generated/pl/cards.json'
import ptbr from '../../../generated/pt-br/cards.json'
import ptpt from '../../../generated/pt-pt/cards.json'
import pt from '../../../generated/pt/cards.json'
import ru from '../../../generated/ru/cards.json'
import ja from '../../../generated/ja/cards.json'
import ko from '../../../generated/ko/cards.json'
import zhtw from '../../../generated/zh-tw/cards.json'
import id from '../../../generated/id/cards.json'
import th from '../../../generated/th/cards.json'
import zhcn from '../../../generated/zh-cn/cards.json'
import zhtw from '../../../generated/zh-tw/cards.json'

const cards = {
'en': en,
'fr': fr,
'es': es,
'it': it,
'pt': pt,
en: en,
fr: fr,
es: es,
it: it,
pt: pt,
'pt-br': ptbr,
'pt-pt': ptpt,
'de': de,
'nl': nl,
'pl': pl,
'ru': ru,
'ja': ja,
'ko': ko,
de: de,
nl: nl,
pl: pl,
ru: ru,
ja: ja,
ko: ko,
'zh-tw': zhtw,
'id': id,
'th': th,
id: id,
th: th,
'zh-cn': zhcn,
} as const

type LocalCard = Omit<SDKCard, 'set'> & {set: () => Set}
type LocalCard = Omit<SDKCard, 'set'> & {set: () => TCGSet}

interface variants {
normal?: boolean;
Expand Down Expand Up @@ -93,25 +92,24 @@ export default class Card implements LocalCard {
})
}

public set(): Set {
return Set.findOne(this.lang, {filters: { id: this.card.set.id }}) as Set
public set(): TCGSet {
return TCGSet.findOne(this.lang, { id: this.card.set.id }) as TCGSet
}

public static getAll(lang: SupportedLanguages): Array<SDKCard> {
return cards[lang]
}

public static find(lang: SupportedLanguages, query: Query<SDKCard>) {
return handlePagination(handleSort(handleValidation(this.getAll(lang), query), query), query)
.map((it) => new Card(lang, it))
return executeQuery(Card.getAll(lang), query).data.map((it) => new Card(lang, it))
}

public static findOne(lang: SupportedLanguages, query: Query<SDKCard>) {
const res = handleSort(handleValidation(this.getAll(lang), query), query)
const res = Card.find(lang, query)
if (res.length === 0) {
return undefined
}
return new Card(lang, res[0])
return res[0]
}

public resume(): CardResume {
Expand Down
64 changes: 31 additions & 33 deletions server/src/V2/Components/Serie.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
import { objectLoop } from '@dzeio/object-util'
import { Serie as SDKSerie, SerieResume, SupportedLanguages } from '@tcgdex/sdk'
import { Query } from '../../interfaces'
import { handlePagination, handleSort, handleValidation } from '../../util'
import Set from './Set'
import type { Serie as SDKSerie, SerieResume, SupportedLanguages } from '@tcgdex/sdk'
import { executeQuery, type Query } from '../../libs/QueryEngine/filter'
import TCGSet from './Set'

import de from '../../../generated/de/series.json'
import en from '../../../generated/en/series.json'
import fr from '../../../generated/fr/series.json'
import es from '../../../generated/es/series.json'
import fr from '../../../generated/fr/series.json'
import id from '../../../generated/id/series.json'
import it from '../../../generated/it/series.json'
import pt from '../../../generated/pt/series.json'
import ptbr from '../../../generated/pt-br/series.json'
import ptpt from '../../../generated/pt-pt/series.json'
import de from '../../../generated/de/series.json'
import ja from '../../../generated/ja/series.json'
import ko from '../../../generated/ko/series.json'
import nl from '../../../generated/nl/series.json'
import pl from '../../../generated/pl/series.json'
import ptbr from '../../../generated/pt-br/series.json'
import ptpt from '../../../generated/pt-pt/series.json'
import pt from '../../../generated/pt/series.json'
import ru from '../../../generated/ru/series.json'
import ja from '../../../generated/ja/series.json'
import ko from '../../../generated/ko/series.json'
import zhtw from '../../../generated/zh-tw/series.json'
import id from '../../../generated/id/series.json'
import th from '../../../generated/th/series.json'
import zhcn from '../../../generated/zh-cn/series.json'
import zhtw from '../../../generated/zh-tw/series.json'


const series = {
'en': en,
'fr': fr,
'es': es,
'it': it,
'pt': pt,
en: en,
fr: fr,
es: es,
it: it,
pt: pt,
'pt-br': ptbr,
'pt-pt': ptpt,
'de': de,
'nl': nl,
'pl': pl,
'ru': ru,
'ja': ja,
'ko': ko,
de: de,
nl: nl,
pl: pl,
ru: ru,
ja: ja,
ko: ko,
'zh-tw': zhtw,
'id': id,
'th': th,
id: id,
th: th,
'zh-cn': zhcn,
} as const

type LocalSerie = Omit<SDKSerie, 'sets'> & {sets: () => Array<Set>}
type LocalSerie = Omit<SDKSerie, 'sets'> & {sets: () => Array<TCGSet>}

export default class Serie implements LocalSerie {

Expand All @@ -63,25 +62,24 @@ export default class Serie implements LocalSerie {
})
}

public sets(): Array<Set> {
return this.serie.sets.map((s) => Set.findOne(this.lang, {filters: { id: s.id }}) as Set)
public sets(): Array<TCGSet> {
return this.serie.sets.map((s) => TCGSet.findOne(this.lang, { id: s.id }) as TCGSet)
}

public static getAll(lang: SupportedLanguages): Array<SDKSerie> {
return series[lang]
}

public static find(lang: SupportedLanguages, query: Query<SDKSerie>) {
return handlePagination(handleSort(handleValidation(this.getAll(lang), query), query), query)
.map((it) => new Serie(lang, it))
return executeQuery(Serie.getAll(lang), query).data.map((it) => new Serie(lang, it))
}

public static findOne(lang: SupportedLanguages, query: Query<SDKSerie>) {
const res = handleValidation(this.getAll(lang), query)
const res = Serie.find(lang, query)
if (res.length === 0) {
return undefined
}
return new Serie(lang, res[0])
return res[0]
}

public resume(): SerieResume {
Expand Down
60 changes: 29 additions & 31 deletions server/src/V2/Components/Set.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
import { objectLoop } from '@dzeio/object-util'
import { Set as SDKSet, SetResume, SupportedLanguages } from '@tcgdex/sdk'
import { Query } from '../../interfaces'
import { handlePagination, handleSort, handleValidation } from '../../util'
import type { Set as SDKSet, SetResume, SupportedLanguages } from '@tcgdex/sdk'
import { executeQuery, type Query } from '../../libs/QueryEngine/filter'
import Card from './Card'
import Serie from './Serie'

import de from '../../../generated/de/sets.json'
import en from '../../../generated/en/sets.json'
import fr from '../../../generated/fr/sets.json'
import es from '../../../generated/es/sets.json'
import fr from '../../../generated/fr/sets.json'
import id from '../../../generated/id/sets.json'
import it from '../../../generated/it/sets.json'
import pt from '../../../generated/pt/sets.json'
import ptbr from '../../../generated/pt-br/sets.json'
import ptpt from '../../../generated/pt-pt/sets.json'
import de from '../../../generated/de/sets.json'
import ja from '../../../generated/ja/sets.json'
import ko from '../../../generated/ko/sets.json'
import nl from '../../../generated/nl/sets.json'
import pl from '../../../generated/pl/sets.json'
import ptbr from '../../../generated/pt-br/sets.json'
import ptpt from '../../../generated/pt-pt/sets.json'
import pt from '../../../generated/pt/sets.json'
import ru from '../../../generated/ru/sets.json'
import ja from '../../../generated/ja/sets.json'
import ko from '../../../generated/ko/sets.json'
import zhtw from '../../../generated/zh-tw/sets.json'
import id from '../../../generated/id/sets.json'
import th from '../../../generated/th/sets.json'
import zhcn from '../../../generated/zh-cn/sets.json'
import zhtw from '../../../generated/zh-tw/sets.json'

const sets = {
'en': en,
'fr': fr,
'es': es,
'it': it,
'pt': pt,
en: en,
fr: fr,
es: es,
it: it,
pt: pt,
'pt-br': ptbr,
'pt-pt': ptpt,
'de': de,
'nl': nl,
'pl': pl,
'ru': ru,
'ja': ja,
'ko': ko,
de: de,
nl: nl,
pl: pl,
ru: ru,
ja: ja,
ko: ko,
'zh-tw': zhtw,
'id': id,
'th': th,
id: id,
th: th,
'zh-cn': zhcn,
} as const

Expand Down Expand Up @@ -77,28 +76,27 @@ export default class Set implements LocalSet {
symbol?: string | undefined

public serie(): Serie {
return Serie.findOne(this.lang, {filters: { id: this.set.serie.id }}) as Serie
return Serie.findOne(this.lang, { id: this.set.serie.id }) as Serie
}

public cards(): Array<Card> {
return this.set.cards.map((s) => Card.findOne(this.lang, { filters: { id: s.id }}) as Card)
return this.set.cards.map((s) => Card.findOne(this.lang, { id: s.id }) as Card)
}

public static getAll(lang: SupportedLanguages): Array<SDKSet> {
return sets[lang]
}

public static find(lang: SupportedLanguages, query: Query<SDKSet>) {
return handlePagination(handleSort(handleValidation(this.getAll(lang), query), query), query)
.map((it) => new Set(lang, it))
return executeQuery(Set.getAll(lang), query).data.map((it) => new Set(lang, it))
}

public static findOne(lang: SupportedLanguages, query: Query<SDKSet>) {
const res = handleValidation(this.getAll(lang), query)
const res = Set.find(lang, query)
if (res.length === 0) {
return undefined
}
return new Set(lang, res[0])
return res[0]
}

public resume(): SetResume {
Expand Down
Loading
Loading