Skip to content

Commit 7cb4f5a

Browse files
committed
Add base /products and /opportunities endpoint
1 parent 62ca280 commit 7cb4f5a

File tree

3 files changed

+143
-152
lines changed

3 files changed

+143
-152
lines changed

src/components/ProductDropdown/ProductsDropdown.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const Dropdown = () => {
2424
useEffect(() => {
2525

2626
if (_productsData.length > 0) {
27-
setSelectedProductId(_productsData[2].id);
27+
setSelectedProductId(_productsData[0].id);
2828
}
2929
}, [_productsData])
3030

src/services/get-products-service.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@ import { setProductsData } from "../redux/slices/mainSlice"
22
import { store } from '../redux/store'
33

44
export async function GetProductsService() {
5-
await fetch(
6-
'/landsat/products',
7-
{
8-
method: 'GET'
9-
}
10-
)
11-
.then((response) => {
12-
return response.json
13-
});
14-
155
// const allProductRequests = ALL_PROVIDERS.map(async provider => {
166
// return fetch('/api/products', {
177
// headers: new Headers({
@@ -458,7 +448,7 @@ export async function GetProductsService() {
458448
}
459449
}
460450
]
461-
const umbraProducts = [
451+
let umbraProducts = [
462452
{
463453
"type": "Product",
464454
"conformsTo": [
@@ -623,6 +613,18 @@ export async function GetProductsService() {
623613
}
624614
]
625615

626-
store.dispatch(setProductsData([...eusiProducts, ...umbraProducts, ...planetProducts]))
616+
// TODO: PUT ENDPOINT HERE
617+
const endpoint = '/landsat/products'
618+
await fetch(
619+
endpoint,
620+
{
621+
method: 'GET'
622+
}
623+
).then(async res => await res.json())
624+
.then((data) => {
625+
console.log(data)
626+
umbraProducts = data.products
627+
store.dispatch(setProductsData([...eusiProducts, ...umbraProducts, ...planetProducts]))
628+
});
627629

628630
}

src/services/get-search-service.js

Lines changed: 128 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -10,144 +10,133 @@ import {
1010
import { addDataToLayer, footprintLayerStyle } from '../utils/mapHelper'
1111

1212
export async function SearchService(searchParams, typeOfSearch) {
13-
const fakeOpportunities = {
14-
"type": "FeatureCollection",
15-
"features": [
16-
{
17-
"type": "Feature",
18-
"geometry": {
19-
"type": "Point",
20-
"coordinates": [
21-
0,
22-
0
23-
]
24-
},
25-
"properties": {
26-
"start_datetime": "2023-03-01T13:00:00Z",
27-
"end_datetime": "2023-03-2T15:30:00Z",
28-
"product_id": "EO",
29-
"constraints": {
30-
"gsd": [
31-
1.0,
32-
10.0
33-
],
34-
"view:off_nadir": [
35-
0,
36-
30
37-
],
38-
"sat_elevation": [
39-
60,
40-
90
41-
],
42-
"view:sun_elevation": [
43-
10,
44-
90
45-
],
46-
"sat_azimuth": [
47-
0,
48-
360
49-
],
50-
"view:sun_azimuth": [
51-
0,
52-
360
53-
]
54-
}
55-
}
56-
},
57-
{
58-
"type": "Feature",
59-
"geometry": {
60-
"type": "Point",
61-
"coordinates": [
62-
0,
63-
0
64-
]
65-
},
66-
"properties": {
67-
"start_datetime": "2023-03-02T13:00:00Z",
68-
"end_datetime": "2023-03-03T15:30:00Z",
69-
"product_id": "EO",
70-
"constraints": {
71-
"gsd": [
72-
1.0,
73-
10.0
74-
],
75-
"view:off_nadir": [
76-
0,
77-
30
78-
],
79-
"sat_elevation": [
80-
60,
81-
90
82-
],
83-
"view:sun_elevation": [
84-
10,
85-
90
86-
],
87-
"sat_azimuth": [
88-
0,
89-
360
90-
],
91-
"view:sun_azimuth": [
92-
0,
93-
360
94-
]
95-
}
96-
}
97-
}
98-
],
99-
"links": {
100-
"rel": "next",
101-
"title": "Next page of Opportunities",
102-
"method": "GET",
103-
"type": "application/geo+json",
104-
"href": "stat-api.example.com?page=2"
13+
// const fakeOpportunities = {
14+
// "type": "FeatureCollection",
15+
// "features": [
16+
// {
17+
// "type": "Feature",
18+
// "geometry": {
19+
// "type": "Point",
20+
// "coordinates": [
21+
// 0,
22+
// 0
23+
// ]
24+
// },
25+
// "properties": {
26+
// "start_datetime": "2023-03-01T13:00:00Z",
27+
// "end_datetime": "2023-03-2T15:30:00Z",
28+
// "product_id": "EO",
29+
// "constraints": {
30+
// "gsd": [
31+
// 1.0,
32+
// 10.0
33+
// ],
34+
// "view:off_nadir": [
35+
// 0,
36+
// 30
37+
// ],
38+
// "sat_elevation": [
39+
// 60,
40+
// 90
41+
// ],
42+
// "view:sun_elevation": [
43+
// 10,
44+
// 90
45+
// ],
46+
// "sat_azimuth": [
47+
// 0,
48+
// 360
49+
// ],
50+
// "view:sun_azimuth": [
51+
// 0,
52+
// 360
53+
// ]
54+
// }
55+
// }
56+
// },
57+
// {
58+
// "type": "Feature",
59+
// "geometry": {
60+
// "type": "Point",
61+
// "coordinates": [
62+
// 0,
63+
// 0
64+
// ]
65+
// },
66+
// "properties": {
67+
// "start_datetime": "2023-03-02T13:00:00Z",
68+
// "end_datetime": "2023-03-03T15:30:00Z",
69+
// "product_id": "EO",
70+
// "constraints": {
71+
// "gsd": [
72+
// 1.0,
73+
// 10.0
74+
// ],
75+
// "view:off_nadir": [
76+
// 0,
77+
// 30
78+
// ],
79+
// "sat_elevation": [
80+
// 60,
81+
// 90
82+
// ],
83+
// "view:sun_elevation": [
84+
// 10,
85+
// 90
86+
// ],
87+
// "sat_azimuth": [
88+
// 0,
89+
// 360
90+
// ],
91+
// "view:sun_azimuth": [
92+
// 0,
93+
// 360
94+
// ]
95+
// }
96+
// }
97+
// }
98+
// ],
99+
// "links": {
100+
// "rel": "next",
101+
// "title": "Next page of Opportunities",
102+
// "method": "GET",
103+
// "type": "application/geo+json",
104+
// "href": "stat-api.example.com?page=2"
105+
// }
106+
// };
107+
108+
// TODO: PUT ENDPOINT HERE
109+
// check for selected product and map endpoint
110+
const endpoint = '/landsat/opportunities'
111+
await fetch(
112+
endpoint,
113+
{
114+
method: 'GET'
105115
}
106-
};
107-
store.dispatch(setSearchResults(fakeOpportunities))
108-
// store.dispatch(setmappedScenes(fakeOpportunities.features))
109-
const options = {
110-
style: footprintLayerStyle
111-
}
112-
store.dispatch(setSearchLoading(false))
113-
addDataToLayer(fakeOpportunities, 'searchResultsLayer', options, true)
114-
// store.dispatch(setClickResults(fakeOpportunities.features))
115-
store.dispatch(settabSelected('details'))
116-
store.dispatch(sethasLeftPanelTabChanged(true))
117-
// await fetch(
118-
// `${
119-
// store.getState().mainSlice.appConfig.STAC_API_URL
120-
// }/search?${searchParams}`,
121-
// {
122-
// method: 'GET'
123-
// }
124-
// )
125-
// .then((response) => {
126-
// if (response.ok) {
127-
// return response.json()
128-
// }
129-
// throw new Error()
130-
// })
131-
// .then((json) => {
132-
// if (typeOfSearch === 'scene') {
133-
// store.dispatch(setSearchResults(json))
134-
// store.dispatch(setmappedScenes(json.features))
135-
// const options = {
136-
// style: footprintLayerStyle
137-
// }
138-
// store.dispatch(setSearchLoading(false))
139-
// addDataToLayer(json, 'searchResultsLayer', options, true)
140-
// } else {
141-
// store.dispatch(setSearchLoading(false))
142-
// store.dispatch(setClickResults(json.features))
143-
// store.dispatch(settabSelected('details'))
144-
// store.dispatch(sethasLeftPanelTabChanged(true))
145-
// }
146-
// })
147-
// .catch((error) => {
148-
// store.dispatch(setSearchLoading(false))
149-
// const message = 'Error Fetching Search Results'
150-
// // log full error for diagnosing client side errors if needed
151-
// console.error(message, error)
152-
// })
116+
)
117+
.then((response) => {
118+
if (response.ok) {
119+
return response.json()
120+
}
121+
throw new Error()
122+
})
123+
.then((json) => {
124+
const opportunities = json.response()
125+
store.dispatch(setSearchResults(opportunities))
126+
// store.dispatch(setmappedScenes(fakeOpportunities.features))
127+
const options = {
128+
style: footprintLayerStyle
129+
}
130+
store.dispatch(setSearchLoading(false))
131+
addDataToLayer(opportunities, 'searchResultsLayer', options, true)
132+
// store.dispatch(setClickResults(fakeOpportunities.features))
133+
store.dispatch(settabSelected('details'))
134+
store.dispatch(sethasLeftPanelTabChanged(true))
135+
})
136+
.catch((error) => {
137+
store.dispatch(setSearchLoading(false))
138+
const message = 'Error Fetching Search Results'
139+
// log full error for diagnosing client side errors if needed
140+
console.error(message, error)
141+
})
153142
}

0 commit comments

Comments
 (0)