diff --git a/pom.xml b/pom.xml
index 25078037b1cb2fa734730779e6ae70cf863d7221..d186d924cd7f594eb9043812089ab89058ba8fb5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>java2-koz01</groupId>
- <artifactId>lab11</artifactId>
+ <artifactId>lab12</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
@@ -94,15 +94,15 @@
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- <version>${log4j.version}</version>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <version>${log4j.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <version>${log4j.version}</version>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <version>${log4j.version}</version>
</dependency>
</dependencies>
diff --git a/src/main/java/java2/lab12/client/Course.java b/src/main/java/java2/lab12/client/Course.java
index 59e2572e952de6caed5407efa7f24e8f99229f01..80e7c76fd45435f63d685f6c31a564ece89ac209 100644
--- a/src/main/java/java2/lab12/client/Course.java
+++ b/src/main/java/java2/lab12/client/Course.java
@@ -1,9 +1,5 @@
package java2.lab12.client;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Getter;
@@ -11,13 +7,11 @@ import lombok.Setter;
import lombok.ToString;
@XmlRootElement
-@Entity
@ToString
public class Course {
- @Id
+ @Setter
@Getter
- @GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Getter
diff --git a/src/main/java/java2/lab12/client/TableViewSample.java b/src/main/java/java2/lab12/client/TableViewSample.java
index 6ec290d75ae2902f4529a5471bf35c67268d5c58..76a23c090d00533e4a578b1fc621b19a53ee9814 100644
--- a/src/main/java/java2/lab12/client/TableViewSample.java
+++ b/src/main/java/java2/lab12/client/TableViewSample.java
@@ -122,6 +122,7 @@ public class TableViewSample extends Application {
p.setCredits(addCredits.getText());
p.setSemester(addSemester.getText());
data.add(p);
+ createCourse(p);
addName.clear();
addDescription.clear();
addCredits.clear();
@@ -161,6 +162,11 @@ public class TableViewSample extends Application {
return Collections.emptyList();
}
+ private void createCourse(Course p) {
+ // TODO Auto-generated method stub
+
+ }
+
private void updateCourse(Course p) {
// TODO Auto-generated method stub
diff --git a/src/main/java/java2/lab12/server/Course.java b/src/main/java/java2/lab12/server/Course.java
index ee768fd676862bc08f35ebfc3ccd7f304df978bc..237c07d78cca63a33469c8f9283b9bc8f757b549 100644
--- a/src/main/java/java2/lab12/server/Course.java
+++ b/src/main/java/java2/lab12/server/Course.java
@@ -17,6 +17,7 @@ public class Course {
@Id
@Getter
+ @Setter
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
diff --git a/src/main/java/java2/lab12/server/CourseResource.java b/src/main/java/java2/lab12/server/CourseResource.java
index dce538ed57cc9e5b885bb1a9d6e07d2967134908..b7c5dd9b1f3da80e145d05b48473da819897496b 100644
--- a/src/main/java/java2/lab12/server/CourseResource.java
+++ b/src/main/java/java2/lab12/server/CourseResource.java
@@ -8,11 +8,15 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
+import lombok.extern.log4j.Log4j2;
+
+@Log4j2
@Path("/")
public class CourseResource {
@@ -39,11 +43,27 @@ public class CourseResource {
@Transactional
@Consumes(MediaType.APPLICATION_JSON)
public Long createCourse(Course course) {
+ log.info("Create course: {}", course);
Course temp = course;
courseRepository.persist(temp);
return temp.getId();
}
+ @PUT
+ @Path("course")
+ @Transactional
+ @Consumes(MediaType.APPLICATION_JSON)
+ public void updateCourse(Course course) {
+ log.info("Update course: {}", course);
+ var temp = courseRepository.findById(course.getId());
+ temp.setName(course.getName());
+ temp.setDescription(course.getDescription());
+ temp.setCredits(course.getCredits());
+ temp.setSemester(course.getSemester());
+ courseRepository.getEntityManager().merge(course);
+ return;
+ }
+
@DELETE
@Transactional
@Path("course/{id}")