diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 00000000..2b63946d --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/practice-app/backend/disasterresponse/src/main/java/com/a1/disasterresponse/controller/NASAImageController.java b/practice-app/backend/disasterresponse/src/main/java/com/a1/disasterresponse/controller/NASAImageController.java new file mode 100644 index 00000000..8572e9bd --- /dev/null +++ b/practice-app/backend/disasterresponse/src/main/java/com/a1/disasterresponse/controller/NASAImageController.java @@ -0,0 +1,23 @@ +package com.a1.disasterresponse.controller; + +import com.a1.disasterresponse.service.NASAImageService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/nasa") +public class NASAImageController { + + @Autowired + private NASAImageService nasaImageService; + + @GetMapping("/search") + public String searchImages(@RequestParam String text) { + return nasaImageService.searchImages(text); + } +} + diff --git a/practice-app/backend/disasterresponse/src/main/java/com/a1/disasterresponse/service/NASAImageService.java b/practice-app/backend/disasterresponse/src/main/java/com/a1/disasterresponse/service/NASAImageService.java new file mode 100644 index 00000000..6c8c253e --- /dev/null +++ b/practice-app/backend/disasterresponse/src/main/java/com/a1/disasterresponse/service/NASAImageService.java @@ -0,0 +1,26 @@ +package com.a1.disasterresponse.service; + + +import org.springframework.http.*; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class NASAImageService { + + public String searchImages(String text) { + String endpoint = "https://images-api.nasa.gov/search"; + String searchUrl = endpoint + "?q=" + text + "&media_type=image"; + + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + HttpEntity entity = new HttpEntity<>(headers); + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.exchange(searchUrl, HttpMethod.GET, entity, String.class); + + return response.getBody(); + } +} \ No newline at end of file diff --git a/practice-app/frontend/disasterresponse/src/App.js b/practice-app/frontend/disasterresponse/src/App.js index e403c8f9..1fd88337 100644 --- a/practice-app/frontend/disasterresponse/src/App.js +++ b/practice-app/frontend/disasterresponse/src/App.js @@ -8,6 +8,7 @@ import GoogleGeocodePage from './pages/GoogleGeocodeApi/GoogleGeocodePage'; import ImdbPage from './pages/ImdbApi/ImdbPage'; import GeoJsPage from './pages/GeoJsApi/GeoJsPage'; import GoogleTranslationPage from './pages/TranslationApi/GoogleTranslationPage'; +import NasaImage from './pages/NASAImageApi/NasaImage'; import WikidataPage from "./pages/WikidataApi/WikidataPage"; const navLinks = [ @@ -17,7 +18,9 @@ const navLinks = [ { path: '/ImdbPage', label: ' IMDB API', component: ImdbPage, icon: }, { path: '/geoJsPage', label: ' GeoJs API', component: GeoJsPage, icon: }, { path: '/googleTranslationPage', label: ' Google Translation API', component: GoogleTranslationPage, icon: }, + { path: '/nasaImage', label: ' NASA Image API', component: NasaImage, icon: }, { path: '/wikidataPage', label: ' Wikidata Api', component: WikidataPage, icon: }, + // add the rest of APIs ]; diff --git a/practice-app/frontend/disasterresponse/src/pages/NASAImageApi/NasaImage.js b/practice-app/frontend/disasterresponse/src/pages/NASAImageApi/NasaImage.js new file mode 100644 index 00000000..4f67274c --- /dev/null +++ b/practice-app/frontend/disasterresponse/src/pages/NASAImageApi/NasaImage.js @@ -0,0 +1,52 @@ +import React, { useState } from 'react'; + +export default function Kubra() { + const [inputText, setInputText] = useState('moon'); + const [responseText, setResponseText] = useState(''); + + const handleInputChange = (event) => { + setInputText(event.target.value); + }; + + const [text, setText] = useState('moon'); + + const handleRequest = () => { + fetch(`api/nasa/search?text=${inputText}`, { + method: 'GET', + + }) + .then((response) => { + console.log('Success:', response); + return response.json(); + }) + .then((data) => { + setResponseText(data); + console.log('Success: sadfasd', data); + }) + .catch((error) => { + console.error('Error:', error); + }); + }; + + return ( + + + + Send Request + + { + responseText?.collection?.items?.map((item) => { + return + {item.data[0].title} + + + }) + } + + ); +}; \ No newline at end of file