Delete MainController.java

This commit is contained in:
Ceren Ugurlu
2019-03-17 20:45:22 +00:00
parent 874b0bcd72
commit e0f0e38241

View File

@@ -1,44 +0,0 @@
package greenify.server.rest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import greenify.server.data.model.User;
import greenify.server.data.repository.UserRepository;
@Controller // This means that this class is a Controller
@RequestMapping(path = "/demo") // This means URL's start with /demo (after Application path)
public class MainController {
@Autowired // This means to get the bean called userRepository
// Which is auto-generated by Spring, we will use it to handle the data
private UserRepository userRepository;
/**
* getmapping for adding a user.
* @param name the username of the user
* @param password the password of the user
* @return a response for adding the user, "saved", if it succeeded
*/
@GetMapping(path = "/add") // Map ONLY GET Requests
public @ResponseBody String addNewUser(@RequestParam String name,
@RequestParam String password) {
// @ResponseBody means the returned String is the response, not a view name
// @RequestParam means it is a parameter from the GET or POST request
User newuser = new User();
newuser.setName(name);
newuser.setPassword(password);
userRepository.save(newuser);
return "Saved";
}
@GetMapping(path = "/all")
public @ResponseBody Iterable<User> getAllUsers() {
// This returns a JSON or XML with the users
return userRepository.findAll();
}
}