1 |
9c55d3bb
|
Schwobik
|
import { axiosInstance } from "./api"
|
2 |
e49b1f44
|
Schwobik
|
import { log } from "../logging/logger"
|
3 |
9c55d3bb
|
Schwobik
|
|
4 |
|
|
export interface SearchParams {
|
5 |
e49b1f44
|
Schwobik
|
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
|
21 |
ca44ce3d
|
Schwobik
|
page?: number
|
22 |
|
|
cursor?: string
|
23 |
9c55d3bb
|
Schwobik
|
//TODO: add other search params
|
24 |
|
|
}
|
25 |
|
|
|
26 |
e49b1f44
|
Schwobik
|
const composeSearchParams = (array: string[] | undefined, identifier: string) => {
|
27 |
|
|
log.debug("composeSearchParams", array, identifier)
|
28 |
|
|
|
29 |
|
|
if (array && array.length > 0) {
|
30 |
|
|
return array.map((item) => `&${identifier}=${item}`).join("")
|
31 |
|
|
}
|
32 |
|
|
return ""
|
33 |
|
|
}
|
34 |
|
|
|
35 |
ca44ce3d
|
Schwobik
|
const composeBooleanSearchParams = (value: boolean | undefined, identifier: string) => {
|
36 |
|
|
log.debug("composeBooleanSearchParams", value, identifier)
|
37 |
|
|
|
38 |
|
|
if (value) {
|
39 |
|
|
return `&${identifier}=on`
|
40 |
|
|
}
|
41 |
|
|
return ""
|
42 |
|
|
}
|
43 |
|
|
|
44 |
9c55d3bb
|
Schwobik
|
export const searchRequest = async (params: SearchParams) => {
|
45 |
e49b1f44
|
Schwobik
|
const url = "/search_v2"
|
46 |
|
|
+ "?search=" + (params.searchQuery ? params.searchQuery : "")
|
47 |
|
|
+ composeSearchParams(params.inventories, "inventory")
|
48 |
|
|
+ composeSearchParams(params.rooms, "room")
|
49 |
|
|
+ composeSearchParams(params.artists, "persname")
|
50 |
|
|
+ composeSearchParams(params.nationalities, "nationality")
|
51 |
ca44ce3d
|
Schwobik
|
+ composeSearchParams(params.subjects, "subject")
|
52 |
|
|
+ composeSearchParams(params.techniques, "technique")
|
53 |
|
|
+ composeBooleanSearchParams(params.isSchoolOfPrague, "shool_of_prague")
|
54 |
|
|
+ composeBooleanSearchParams(params.isOriginal, "original")
|
55 |
|
|
+ composeBooleanSearchParams(params.isCopy, "copy")
|
56 |
|
|
+ composeBooleanSearchParams(params.isLowQuality, "quality_low")
|
57 |
|
|
+ composeBooleanSearchParams(params.isHighQuality, "quality_high")
|
58 |
|
|
+ composeBooleanSearchParams(params.isIdentified, "identified_art")
|
59 |
|
|
+ composeSearchParams(params.institutions, "institution")
|
60 |
|
|
+ composeSearchParams(params.cities, "city")
|
61 |
|
|
+ composeSearchParams(params.countries, "country")
|
62 |
|
|
+ (params.page ? `&page=${params.page}` : "")
|
63 |
|
|
+ (params.cursor ? `&cursor=${params.cursor}` : "")
|
64 |
|
|
|
65 |
e49b1f44
|
Schwobik
|
// TODO add other search params
|
66 |
|
|
log.debug("searchRequest url: " + url)
|
67 |
|
|
return await axiosInstance.get(url)
|
68 |
|
|
|
69 |
9c55d3bb
|
Schwobik
|
}
|