diff --git a/build.gradle b/build.gradle index 84de6e12687c3be7913e15972e9491d3a13c2458..802ad86ec4b5ec162522d2577ac1b707b7e5c510 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok' + compile 'org.springframework.boot:spring-boot-starter-data-jpa' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'mysql:mysql-connector-java' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' diff --git a/src/main/java/com/RESTAPI/RESTAPI/Controllers/UserController.java b/src/main/java/com/RESTAPI/RESTAPI/Controllers/UserController.java index 1c68e4e5e7e0c5eb12dd8b3c2ffd625ea8b470bc..15fe3d5a5e0f69632c439b9433ea16609a9f2ce8 100644 --- a/src/main/java/com/RESTAPI/RESTAPI/Controllers/UserController.java +++ b/src/main/java/com/RESTAPI/RESTAPI/Controllers/UserController.java @@ -4,10 +4,7 @@ import com.RESTAPI.RESTAPI.Entities.User; import com.RESTAPI.RESTAPI.Repositories.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; @Controller // This means that this class is a Controller @RequestMapping(path="/user") // This means URL's start with /demo (after Application path) @@ -16,7 +13,7 @@ public class UserController { // Which is auto-generated by Spring, we will use it to handle the data private UserRepository userRepository; - @GetMapping(path="/add") // Map ONLY GET Requests + @PutMapping(path="/add") // Map ONLY GET Requests public @ResponseBody String addNewUser (@RequestParam String name , @RequestParam String email) { diff --git a/src/main/java/com/RESTAPI/RESTAPI/Entities/User.java b/src/main/java/com/RESTAPI/RESTAPI/Entities/User.java index a8e181ce7ecb896de4c8bc5a4c7195c13a6438e4..5c6438294ba8ccd5159ac91d51a4186b593a880e 100644 --- a/src/main/java/com/RESTAPI/RESTAPI/Entities/User.java +++ b/src/main/java/com/RESTAPI/RESTAPI/Entities/User.java @@ -1,44 +1,21 @@ package com.RESTAPI.RESTAPI.Entities; +import lombok.Getter; +import lombok.Setter; + import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity // This tells Hibernate to make a table out of this class +@Getter +@Setter public class User { @Id @GeneratedValue(strategy= GenerationType.IDENTITY) private Integer id; - private String name; - private String email; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - } \ No newline at end of file