Skip to content
Snippets Groups Projects
Commit 64d2153d authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Fix

parent f3d74b90
No related merge requests found
......@@ -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>
......
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
......
......@@ -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
......
......@@ -17,6 +17,7 @@ public class Course {
@Id
@Getter
@Setter
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
......
......@@ -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}")
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment