Guest User

Untitled

a guest
Jan 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. @Id
  2. //@GeneratedValue(strategy= GenerationType.IDENTITY)
  3. private ObjectId id;
  4. @NotNull
  5. @Length(min=4)
  6. @Field("name")
  7. private String name;
  8. @NotNull
  9. @Length(min=5)
  10. @Field("teamName")
  11. private String teamName;
  12. @NotNull
  13. @Field("salary")
  14. @Max(52125)
  15. private Long salary;
  16.  
  17. public Users()
  18. {
  19.  
  20. }
  21. public Users(ObjectId id, String name, String teamName, Long salary) {
  22. this.id = id;
  23. this.name = name;
  24. this.teamName = teamName;
  25. this.salary = salary;
  26. }
  27.  
  28. public ObjectId getId() {
  29. return id;
  30. }
  31.  
  32. public void setId(ObjectId id) {
  33. this.id = id;
  34. }
  35.  
  36. public String getName() {
  37. return name;
  38. }
  39.  
  40. public void setName(String name) {
  41. this.name = name;
  42. }
  43.  
  44. public String getTeamName() {
  45. return teamName;
  46. }
  47.  
  48. public void setTeamName(String teamName) {
  49. this.teamName = teamName;
  50. }
  51.  
  52. public Long getSalary() {
  53. return salary;
  54. }
  55.  
  56. public void setSalary(Long salary) {
  57. this.salary = salary;
  58. }
  59.  
  60. private UserRepository userRepository;
  61.  
  62. private MongoTemplate mongoTemplate =
  63. new MongoTemplate(new MongoClient("localhost"),"db");
  64.  
  65. public UsersResource(UserRepository userRepository) {
  66. this.userRepository = userRepository;
  67. }
  68.  
  69. @PostMapping("/createuser")
  70. public HttpStatus createUser(@RequestBody Users user) {
  71. userRepository.save(user);
  72. return HttpStatus.CREATED;
  73. }
  74.  
  75. @GetMapping("/getallusers")
  76. public List<Users> getAll() {
  77.  
  78. return userRepository.findAll();
  79. }
  80.  
  81. @PostMapping("/deleteuser")
  82. public void deleteUser(@RequestParam (value = "userid")Integer id) {
  83. userRepository.delete(id);
  84. }
Add Comment
Please, Sign In to add comment