Skip to content

Instantly share code, notes, and snippets.

@devindianushika
Last active November 17, 2019 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devindianushika/f20f2c1dfc5b3f4ab40ed3d549386f5d to your computer and use it in GitHub Desktop.
Save devindianushika/f20f2c1dfc5b3f4ab40ed3d549386f5d to your computer and use it in GitHub Desktop.
Add rest controllers
package com.audelia.first.controlers;
import com.audelia.first.Domain.UserDTO;
import com.audelia.first.Services.UserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/user")
public class User {
@Autowired
private UserServices userServices;
@GetMapping("/all")
public List<UserDTO> allUsers() {
return userServices.findAllUsers();
}
@PostMapping("/add")
public String addUser(@RequestBody UserDTO userdata) {
return userServices.saveUser(userdata);
}
@PutMapping("/update")
public String updateUser(@RequestBody UserDTO newUserData) {
return userServices.updateUser(newUserData);
}
@GetMapping("/find/{id}")
public UserDTO getUserById(@PathVariable Integer id) {
return userServices.findById(id);
}
@DeleteMapping("/delete")
public String deleteUser(@RequestBody UserDTO deleteUserData){
return userServices.deleteUser(deleteUserData);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment