Everytime I check with CURL if there is a respone like “curl localhost:4001/traveladventures/bycountry/Greece”,
I only get this: “{“timestamp”:“2022-09-13T11:24:46.005+00:00”,“status”:404,“error”:“Not Found”,“message”:“No message available”,“path”:”/tr", and not any adventures from the data, can you help me?
Thanks a lot
package com.codecademy.plants.controllers;
import com.codecademy.plants.entities.Adventure;
import com.codecademy.plants.repositories.AdventureRepository;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.*;
@RestController("/traveladventures")
public class TravelAdventuresController {
private final AdventureRepository adventureRepository;
public TravelAdventuresController(AdventureRepository adventureRepo) {
this.adventureRepository = adventureRepo;
}
// Add controller methods below:
// Get all Aventures
@GetMapping
public Iterable<Adventure> getAdventures(){
return this.adventureRepository.findAll();
}
// Get Request to get adventures by country
@GetMapping("/bycountry/{country}")
public List<Adventure> getByCountry(@PathVariable("country") String country){
return this.adventureRepository.findByCountry(country);
}
// Get Request to get adventures by state
@GetMapping("/bystate")
public List<Adventure> getByState(@RequestParam(name="state") String state){
return this.adventureRepository.findByState(state);
}
// Post Request to add a new Adventure
@PostMapping
public Adventure addAdventure(@RequestBody Adventure adventure){
Adventure newAdventure = this.adventureRepository.save(adventure);
return newAdventure;
}
}
PLS NOTE: I COULDN’t SELECT JAVA FOR THE CODEBYTE
Hello blog1935286952 it seems that @RequestMapping(“/traveladventures”) at the top of the class and is correspondent import are missing: import org.springframework.web.bind.annotation.RequestMapping;
@RestController annotation shouldn’t have any path on it
I am getting a curl error as well but it’s saying this: curl: (1) Protocol “localhost4001” not supported or disabled in libcurl
I’m trying to follow the video walkthrough but I can’t even run the first curl command…