pt. 1 - REST API
This commit is contained in:
@@ -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