From 64d2153de6bab551c22f8179c3ed23ac00c037b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ko=C5=BEusznik?= <jan@kozusznik.cz> Date: Mon, 26 Apr 2021 11:02:31 +0200 Subject: [PATCH] Fix --- pom.xml | 14 ++++++------- src/main/java/java2/lab12/client/Course.java | 8 +------- .../java2/lab12/client/TableViewSample.java | 6 ++++++ src/main/java/java2/lab12/server/Course.java | 1 + .../java2/lab12/server/CourseResource.java | 20 +++++++++++++++++++ 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 2507803..d186d92 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 59e2572..80e7c76 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 6ec290d..76a23c0 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 ee768fd..237c07d 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 dce538e..b7c5dd9 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}") -- GitLab