Skip to content

Commit 20a8db5

Browse files
committed
Merge pull request #6 from josedab/book-entities
Book entities
2 parents 05d1628 + c96ab42 commit 20a8db5

File tree

22 files changed

+1089
-0
lines changed

22 files changed

+1089
-0
lines changed

.jhipster/Book.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"relationships": [
3+
{
4+
"relationshipId": 1,
5+
"relationshipName": "author",
6+
"relationshipNameCapitalized": "Author",
7+
"relationshipFieldName": "author",
8+
"otherEntityName": "author",
9+
"relationshipType": "many-to-one",
10+
"otherEntityNameCapitalized": "Author",
11+
"otherEntityField": "name"
12+
}
13+
],
14+
"fields": [
15+
{
16+
"fieldId": 1,
17+
"fieldName": "title",
18+
"fieldType": "String",
19+
"fieldNameCapitalized": "Title",
20+
"fieldNameUnderscored": "title",
21+
"fieldInJavaBeanMethod": "Title",
22+
"fieldValidate": true,
23+
"fieldValidateRules": []
24+
},
25+
{
26+
"fieldId": 2,
27+
"fieldName": "description",
28+
"fieldType": "String",
29+
"fieldNameCapitalized": "Description",
30+
"fieldNameUnderscored": "description",
31+
"fieldInJavaBeanMethod": "Description",
32+
"fieldValidate": true,
33+
"fieldValidateRules": []
34+
},
35+
{
36+
"fieldId": 3,
37+
"fieldName": "publicationDate",
38+
"fieldType": "LocalDate",
39+
"fieldNameCapitalized": "PublicationDate",
40+
"fieldNameUnderscored": "publication_date",
41+
"fieldInJavaBeanMethod": "PublicationDate",
42+
"fieldValidate": true,
43+
"fieldValidateRules": []
44+
},
45+
{
46+
"fieldId": 4,
47+
"fieldName": "price",
48+
"fieldType": "BigDecimal",
49+
"fieldNameCapitalized": "Price",
50+
"fieldNameUnderscored": "price",
51+
"fieldInJavaBeanMethod": "Price",
52+
"fieldValidate": true,
53+
"fieldValidateRules": []
54+
}
55+
],
56+
"fieldsContainOwnerManyToMany": false,
57+
"fieldsContainOwnerOneToOne": false,
58+
"fieldsContainOneToMany": false,
59+
"fieldsContainLocalDate": true,
60+
"fieldsContainCustomTime": true,
61+
"fieldsContainBigDecimal": true,
62+
"fieldsContainDateTime": false,
63+
"fieldsContainDate": false,
64+
"changelogDate": "20150627201451",
65+
"dto": "no",
66+
"pagination": "pagination",
67+
"validation": true
68+
}

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
README for bookstore
22
==========================
3+
[![Build Status](https://travis-ci.org/josedab/angularjs-springboot-bookstore.svg)](https://travis-ci.org/josedab/angularjs-springboot-bookstore)
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package com.bookstore.domain;
2+
3+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
4+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
5+
import com.bookstore.domain.util.CustomLocalDateSerializer;
6+
import com.bookstore.domain.util.ISO8601LocalDateDeserializer;
7+
import org.hibernate.annotations.Cache;
8+
import org.hibernate.annotations.CacheConcurrencyStrategy;
9+
import org.hibernate.annotations.Type;
10+
import org.joda.time.LocalDate;
11+
12+
import javax.persistence.*;
13+
import javax.validation.constraints.*;
14+
import java.io.Serializable;
15+
import java.math.BigDecimal;
16+
import java.util.HashSet;
17+
import java.util.Set;
18+
import java.util.Objects;
19+
20+
/**
21+
* A Book.
22+
*/
23+
@Entity
24+
@Table(name = "BOOK")
25+
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
26+
public class Book implements Serializable {
27+
28+
@Id
29+
@GeneratedValue(strategy = GenerationType.AUTO)
30+
private Long id;
31+
32+
@Column(name = "title")
33+
private String title;
34+
35+
@Column(name = "description")
36+
private String description;
37+
38+
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
39+
@JsonSerialize(using = CustomLocalDateSerializer.class)
40+
@JsonDeserialize(using = ISO8601LocalDateDeserializer.class)
41+
@Column(name = "publication_date")
42+
private LocalDate publicationDate;
43+
44+
@Column(name = "price", precision=10, scale=2)
45+
private BigDecimal price;
46+
47+
@ManyToOne
48+
private Author author;
49+
50+
public Long getId() {
51+
return id;
52+
}
53+
54+
public void setId(Long id) {
55+
this.id = id;
56+
}
57+
58+
public String getTitle() {
59+
return title;
60+
}
61+
62+
public void setTitle(String title) {
63+
this.title = title;
64+
}
65+
66+
public String getDescription() {
67+
return description;
68+
}
69+
70+
public void setDescription(String description) {
71+
this.description = description;
72+
}
73+
74+
public LocalDate getPublicationDate() {
75+
return publicationDate;
76+
}
77+
78+
public void setPublicationDate(LocalDate publicationDate) {
79+
this.publicationDate = publicationDate;
80+
}
81+
82+
public BigDecimal getPrice() {
83+
return price;
84+
}
85+
86+
public void setPrice(BigDecimal price) {
87+
this.price = price;
88+
}
89+
90+
public Author getAuthor() {
91+
return author;
92+
}
93+
94+
public void setAuthor(Author author) {
95+
this.author = author;
96+
}
97+
98+
@Override
99+
public boolean equals(Object o) {
100+
if (this == o) {
101+
return true;
102+
}
103+
if (o == null || getClass() != o.getClass()) {
104+
return false;
105+
}
106+
107+
Book book = (Book) o;
108+
109+
if ( ! Objects.equals(id, book.id)) return false;
110+
111+
return true;
112+
}
113+
114+
@Override
115+
public int hashCode() {
116+
return Objects.hashCode(id);
117+
}
118+
119+
@Override
120+
public String toString() {
121+
return "Book{" +
122+
"id=" + id +
123+
", title='" + title + "'" +
124+
", description='" + description + "'" +
125+
", publicationDate='" + publicationDate + "'" +
126+
", price='" + price + "'" +
127+
'}';
128+
}
129+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.bookstore.repository;
2+
3+
import com.bookstore.domain.Book;
4+
import org.springframework.data.jpa.repository.*;
5+
6+
import java.util.List;
7+
8+
/**
9+
* Spring Data JPA repository for the Book entity.
10+
*/
11+
public interface BookRepository extends JpaRepository<Book,Long> {
12+
13+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.bookstore.web.rest;
2+
3+
import com.codahale.metrics.annotation.Timed;
4+
import com.bookstore.domain.Book;
5+
import com.bookstore.repository.BookRepository;
6+
import com.bookstore.web.rest.util.PaginationUtil;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
import org.springframework.data.domain.Page;
10+
import org.springframework.http.HttpHeaders;
11+
import org.springframework.http.HttpStatus;
12+
import org.springframework.http.MediaType;
13+
import org.springframework.http.ResponseEntity;
14+
import org.springframework.web.bind.annotation.*;
15+
16+
import javax.inject.Inject;
17+
import javax.validation.Valid;
18+
import java.net.URI;
19+
import java.net.URISyntaxException;
20+
import javax.servlet.http.HttpServletResponse;
21+
import java.util.List;
22+
23+
/**
24+
* REST controller for managing Book.
25+
*/
26+
@RestController
27+
@RequestMapping("/api")
28+
public class BookResource {
29+
30+
private final Logger log = LoggerFactory.getLogger(BookResource.class);
31+
32+
@Inject
33+
private BookRepository bookRepository;
34+
35+
/**
36+
* POST /books -> Create a new book.
37+
*/
38+
@RequestMapping(value = "/books",
39+
method = RequestMethod.POST,
40+
produces = MediaType.APPLICATION_JSON_VALUE)
41+
@Timed
42+
public ResponseEntity<Void> create(@Valid @RequestBody Book book) throws URISyntaxException {
43+
log.debug("REST request to save Book : {}", book);
44+
if (book.getId() != null) {
45+
return ResponseEntity.badRequest().header("Failure", "A new book cannot already have an ID").build();
46+
}
47+
bookRepository.save(book);
48+
return ResponseEntity.created(new URI("/api/books/" + book.getId())).build();
49+
}
50+
51+
/**
52+
* PUT /books -> Updates an existing book.
53+
*/
54+
@RequestMapping(value = "/books",
55+
method = RequestMethod.PUT,
56+
produces = MediaType.APPLICATION_JSON_VALUE)
57+
@Timed
58+
public ResponseEntity<Void> update(@Valid @RequestBody Book book) throws URISyntaxException {
59+
log.debug("REST request to update Book : {}", book);
60+
if (book.getId() == null) {
61+
return create(book);
62+
}
63+
bookRepository.save(book);
64+
return ResponseEntity.ok().build();
65+
}
66+
67+
/**
68+
* GET /books -> get all the books.
69+
*/
70+
@RequestMapping(value = "/books",
71+
method = RequestMethod.GET,
72+
produces = MediaType.APPLICATION_JSON_VALUE)
73+
@Timed
74+
public ResponseEntity<List<Book>> getAll(@RequestParam(value = "page" , required = false) Integer offset,
75+
@RequestParam(value = "per_page", required = false) Integer limit)
76+
throws URISyntaxException {
77+
Page<Book> page = bookRepository.findAll(PaginationUtil.generatePageRequest(offset, limit));
78+
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/books", offset, limit);
79+
return new ResponseEntity<List<Book>>(page.getContent(), headers, HttpStatus.OK);
80+
}
81+
82+
/**
83+
* GET /books/:id -> get the "id" book.
84+
*/
85+
@RequestMapping(value = "/books/{id}",
86+
method = RequestMethod.GET,
87+
produces = MediaType.APPLICATION_JSON_VALUE)
88+
@Timed
89+
public ResponseEntity<Book> get(@PathVariable Long id, HttpServletResponse response) {
90+
log.debug("REST request to get Book : {}", id);
91+
Book book = bookRepository.findOne(id);
92+
if (book == null) {
93+
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
94+
}
95+
return new ResponseEntity<>(book, HttpStatus.OK);
96+
}
97+
98+
/**
99+
* DELETE /books/:id -> delete the "id" book.
100+
*/
101+
@RequestMapping(value = "/books/{id}",
102+
method = RequestMethod.DELETE,
103+
produces = MediaType.APPLICATION_JSON_VALUE)
104+
@Timed
105+
public void delete(@PathVariable Long id) {
106+
log.debug("REST request to delete Book : {}", id);
107+
bookRepository.delete(id);
108+
}
109+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<databaseChangeLog
3+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
6+
7+
<property name="now" value="now()" dbms="mysql,h2"/>
8+
<property name="now" value="current_timestamp" dbms="postgresql"/>
9+
<property name="now" value="sysdate" dbms="oracle"/>
10+
11+
<property name="autoIncrement" value="true" dbms="mysql,h2,postgresql"/>
12+
<property name="autoIncrement" value="false" dbms="oracle"/>
13+
<!--
14+
Added the entity Book.
15+
-->
16+
<changeSet id="20150627201451" author="jhipster">
17+
<createTable tableName="BOOK">
18+
<column name="id" type="bigint" autoIncrement="${autoIncrement}" >
19+
<constraints primaryKey="true" nullable="false"/>
20+
</column>
21+
<column name="title" type="varchar(255)"/>
22+
<column name="description" type="varchar(255)"/>
23+
<column name="publication_date" type="date"/>
24+
<column name="price" type="decimal(10,2)"/>
25+
<column name="author_id" type="bigint"/>
26+
</createTable>
27+
28+
<addForeignKeyConstraint baseColumnNames="author_id"
29+
baseTableName="BOOK"
30+
constraintName="fk_book_author_id"
31+
referencedColumnNames="id"
32+
referencedTableName="AUTHOR"/>
33+
34+
</changeSet>
35+
</databaseChangeLog>

src/main/resources/config/liquibase/master.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66

77
<include file="classpath:config/liquibase/changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="false"/>
88
<include file="classpath:config/liquibase/changelog/20150627193612_added_entity_Author.xml" relativeToChangelogFile="false"/>
9+
<include file="classpath:config/liquibase/changelog/20150627201451_added_entity_Book.xml" relativeToChangelogFile="false"/>
910
<!-- JHipster will add liquibase changelogs here -->
1011
</databaseChangeLog>

src/main/webapp/i18n/en/book.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"bookstoreApp": {
3+
"book" : {
4+
"home": {
5+
"title": "Books",
6+
"createLabel": "Create a new Book",
7+
"createOrEditLabel": "Create or edit a Book"
8+
},
9+
"delete": {
10+
"question": "Are you sure you want to delete Book {{ id }}?"
11+
},
12+
"detail": {
13+
"title": "Book"
14+
},
15+
"title": "Title",
16+
"description": "Description",
17+
"publicationDate": "PublicationDate",
18+
"price": "Price",
19+
"author": "author"
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)