Last active
November 17, 2019 16:08
-
-
Save devindianushika/f20f2c1dfc5b3f4ab40ed3d549386f5d to your computer and use it in GitHub Desktop.
Add rest controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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