pt. 1 - REST API
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1 @@
|
||||
/target/
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>bayer-ubiquitous-rating-platform</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
@@ -0,0 +1,5 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,57 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.bayer</groupId>
|
||||
<artifactId>burp</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.2.4.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-milestone</id>
|
||||
<url>https://repo.spring.io/libs-release</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-milestone</id>
|
||||
<url>https://repo.spring.io/libs-release</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.bayer.burp;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.bayer.burp.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class Burp {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
private String text;
|
||||
|
||||
private Date timestamp;
|
||||
|
||||
@ManyToOne
|
||||
private User user;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "burp_tag", joinColumns = @JoinColumn(name = "burp_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id"))
|
||||
private List<Tag> tags;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Date getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Date timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public List<Tag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.bayer.burp.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
|
||||
@Entity
|
||||
public class Tag {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "burp_tag", joinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "burp_id", referencedColumnName = "id"))
|
||||
private List<Burp> burps;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Burp> getBurps() {
|
||||
return burps;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.bayer.burp.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@OneToMany
|
||||
private List<Burp> burps;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Burp> getBurps() {
|
||||
return burps;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.bayer.burp.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
|
||||
import com.bayer.burp.domain.Burp;
|
||||
|
||||
public interface BurpRepository extends PagingAndSortingRepository<Burp, Long> {
|
||||
|
||||
// http://localhost:8080/burps/search/findByUserName?username=Adam
|
||||
List<Burp> findByUserName(@Param("username") String username);
|
||||
|
||||
// http://localhost:8080/burps/search/findByUserNameIn?usernames=Adam,Ben
|
||||
List<Burp> findByUserNameIn(Collection<String> usernames);
|
||||
|
||||
// http://localhost:8080/burps/search/searchBurpsStartingWith?prefix=Best
|
||||
@Query("select b from Burp b where b.text like :prefix%")
|
||||
List<Burp> searchBurpsStartingWith(@Param("prefix") String prefix);
|
||||
|
||||
// http://localhost:8080/burps/search/findFirst3ByOrderByTimestampDesc
|
||||
List<Burp> findFirst3ByOrderByTimestampDesc();
|
||||
|
||||
// @RestResource(exported = false)
|
||||
// Page<Burp> findAll(Pageable pageable);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.bayer.burp.repository;
|
||||
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
import com.bayer.burp.domain.Tag;
|
||||
|
||||
public interface TagRepository extends PagingAndSortingRepository<Tag, Long> {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.bayer.burp.repository;
|
||||
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
import com.bayer.burp.domain.User;
|
||||
|
||||
public interface UserRepository extends PagingAndSortingRepository<User, Long> {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
spring.datasource.platform=h2
|
||||
security.user.name=sa
|
||||
security.user.password=
|
||||
|
||||
server.port=8081
|
||||
@@ -0,0 +1,16 @@
|
||||
INSERT INTO User (id, name) VALUES (1, 'Adam'), (2, 'Betty'), (3, 'Curtis');
|
||||
INSERT INTO Tag (id, name) VALUES (1, 'left'), (2, 'right'), (3, 'vital');
|
||||
|
||||
INSERT INTO Burp (id, text, timestamp, user_id) VALUES
|
||||
(NULL, 'Waiting at the entrance', CONCAT(CURRENT_DATE(),' ','11:41:00.000'), 1),
|
||||
(NULL, 'Did anybody check the menu? The screen''s not working.', CONCAT(CURRENT_DATE(),' ','11:42:00.000'), 2),
|
||||
(NULL, 'Still not open. I''m huuuuungry!', CONCAT(CURRENT_DATE(),' ','11:45:00.001'), 3),
|
||||
(NULL, 'Stay away from the #right side today!', DATEADD('SECOND', -650, CURRENT_TIMESTAMP()), 2),
|
||||
(NULL, 'Katina #vital is delicious ♥', DATEADD('SECOND', -620, CURRENT_TIMESTAMP()), 1),
|
||||
(NULL, 'The schnitzel on both sides is quite OK #left #right', DATEADD('SECOND', -463, CURRENT_TIMESTAMP()), 3),
|
||||
(NULL, 'I''m all for the healthy kantina vital, but does it always have to have this oriental touch? #vital', DATEADD('SECOND', -318, CURRENT_TIMESTAMP()), 1),
|
||||
(NULL, 'If nothing else works, there''s still the potato gratin #left and #right', DATEADD('SECOND', -10, CURRENT_TIMESTAMP()), 2),
|
||||
(NULL, '...but then again, what''s the side dish? #left #right', CURRENT_TIMESTAMP(), 2);
|
||||
|
||||
INSERT INTO Burp_Tag (burp_id, tag_id) VALUES (4, 2), (5, 3), (6, 1), (6, 2), (7, 3), (8, 1), (8, 2), (9, 1), (9, 2);
|
||||
|
||||
Reference in New Issue
Block a user