Projekt

Obecné

Profil

« Předchozí | Další » 

Revize e49b1f44

Přidáno uživatelem Schwobik před téměř 2 roky(ů)

Implementation of multiselect component, search page finished with listview
re #10478

Zobrazit rozdíly:

src/api/searchService.ts
1 1
import { axiosInstance } from "./api"
2
import { log } from "../logging/logger"
2 3

  
3 4
export interface SearchParams {
4
    inventory?: string
5
    inventories?: string[]
6
    rooms?: string[]
7
    artists?: string[]
8
    nationalities?: string[]
9
    subjects?: string[]
10
    techniques?: string[]
11
    isSchoolOfPrague?: boolean
12
    isOriginal?: boolean
13
    isCopy?: boolean
14
    isLowQuality?: boolean
15
    isHighQuality?: boolean
16
    isIdentified?: boolean
17
    institutions?: string[]
18
    cities?: string[]
19
    countries?: string[]
20
    searchQuery?: string
5 21
    //TODO: add other search params
6 22
}
7 23

  
24
const composeSearchParams = (array: string[] | undefined, identifier: string) => {
25
    log.debug("composeSearchParams", array, identifier)
26

  
27
    if (array && array.length > 0) {
28
        return array.map((item) => `&${identifier}=${item}`).join("")
29
    }
30
    return ""
31
}
32

  
8 33
export const searchRequest = async (params: SearchParams) => {
9
    return await axiosInstance.get(`/search_v2${ (params.inventory ? `?inventory=${ params.inventory }` : "")}`)
34
    const url = "/search_v2"
35
    + "?search=" + (params.searchQuery ? params.searchQuery : "")
36
    + composeSearchParams(params.inventories, "inventory")
37
    + composeSearchParams(params.rooms, "room")
38
    + composeSearchParams(params.artists, "persname")
39
    + composeSearchParams(params.nationalities, "nationality")
40
    // TODO add other search params
41
    log.debug("searchRequest url: " + url)
42
    return await axiosInstance.get(url)
43

  
10 44
}

Také k dispozici: Unified diff