Skip to content

Commit 05d1628

Browse files
committed
Merge pull request #5 from josedab/author-entities
Author entities
2 parents 0e069a0 + 0e9159e commit 05d1628

File tree

20 files changed

+1023
-0
lines changed

20 files changed

+1023
-0
lines changed

.jhipster/Author.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"relationships": [],
3+
"fields": [
4+
{
5+
"fieldId": 1,
6+
"fieldName": "name",
7+
"fieldType": "String",
8+
"fieldNameCapitalized": "Name",
9+
"fieldNameUnderscored": "name",
10+
"fieldInJavaBeanMethod": "Name",
11+
"fieldValidate": true,
12+
"fieldValidateRules": []
13+
},
14+
{
15+
"fieldId": 2,
16+
"fieldName": "surname",
17+
"fieldType": "String",
18+
"fieldNameCapitalized": "Surname",
19+
"fieldNameUnderscored": "surname",
20+
"fieldInJavaBeanMethod": "Surname",
21+
"fieldValidate": true,
22+
"fieldValidateRules": []
23+
},
24+
{
25+
"fieldId": 3,
26+
"fieldName": "description",
27+
"fieldType": "String",
28+
"fieldNameCapitalized": "Description",
29+
"fieldNameUnderscored": "description",
30+
"fieldInJavaBeanMethod": "Description",
31+
"fieldValidate": false
32+
},
33+
{
34+
"fieldId": 4,
35+
"fieldName": "birthDate",
36+
"fieldType": "LocalDate",
37+
"fieldNameCapitalized": "BirthDate",
38+
"fieldNameUnderscored": "birth_date",
39+
"fieldInJavaBeanMethod": "BirthDate",
40+
"fieldValidate": false
41+
}
42+
],
43+
"fieldsContainOwnerManyToMany": false,
44+
"fieldsContainOwnerOneToOne": false,
45+
"fieldsContainOneToMany": false,
46+
"fieldsContainLocalDate": true,
47+
"fieldsContainCustomTime": true,
48+
"fieldsContainBigDecimal": false,
49+
"fieldsContainDateTime": false,
50+
"fieldsContainDate": false,
51+
"changelogDate": "20150627193612",
52+
"dto": "no",
53+
"pagination": "pagination",
54+
"validation": true
55+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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.util.Objects;
16+
17+
/**
18+
* A Author.
19+
*/
20+
@Entity
21+
@Table(name = "AUTHOR")
22+
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
23+
public class Author implements Serializable {
24+
25+
@Id
26+
@GeneratedValue(strategy = GenerationType.AUTO)
27+
private Long id;
28+
29+
@Column(name = "name")
30+
private String name;
31+
32+
@Column(name = "surname")
33+
private String surname;
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 = "birth_date")
42+
private LocalDate birthDate;
43+
44+
public Long getId() {
45+
return id;
46+
}
47+
48+
public void setId(Long id) {
49+
this.id = id;
50+
}
51+
52+
public String getName() {
53+
return name;
54+
}
55+
56+
public void setName(String name) {
57+
this.name = name;
58+
}
59+
60+
public String getSurname() {
61+
return surname;
62+
}
63+
64+
public void setSurname(String surname) {
65+
this.surname = surname;
66+
}
67+
68+
public String getDescription() {
69+
return description;
70+
}
71+
72+
public void setDescription(String description) {
73+
this.description = description;
74+
}
75+
76+
public LocalDate getBirthDate() {
77+
return birthDate;
78+
}
79+
80+
public void setBirthDate(LocalDate birthDate) {
81+
this.birthDate = birthDate;
82+
}
83+
84+
@Override
85+
public boolean equals(Object o) {
86+
if (this == o) {
87+
return true;
88+
}
89+
if (o == null || getClass() != o.getClass()) {
90+
return false;
91+
}
92+
93+
Author author = (Author) o;
94+
95+
if ( ! Objects.equals(id, author.id)) return false;
96+
97+
return true;
98+
}
99+
100+
@Override
101+
public int hashCode() {
102+
return Objects.hashCode(id);
103+
}
104+
105+
@Override
106+
public String toString() {
107+
return "Author{" +
108+
"id=" + id +
109+
", name='" + name + "'" +
110+
", surname='" + surname + "'" +
111+
", description='" + description + "'" +
112+
", birthDate='" + birthDate + "'" +
113+
'}';
114+
}
115+
}
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.Author;
4+
import org.springframework.data.jpa.repository.*;
5+
6+
import java.util.List;
7+
8+
/**
9+
* Spring Data JPA repository for the Author entity.
10+
*/
11+
public interface AuthorRepository extends JpaRepository<Author,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.Author;
5+
import com.bookstore.repository.AuthorRepository;
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 Author.
25+
*/
26+
@RestController
27+
@RequestMapping("/api")
28+
public class AuthorResource {
29+
30+
private final Logger log = LoggerFactory.getLogger(AuthorResource.class);
31+
32+
@Inject
33+
private AuthorRepository authorRepository;
34+
35+
/**
36+
* POST /authors -> Create a new author.
37+
*/
38+
@RequestMapping(value = "/authors",
39+
method = RequestMethod.POST,
40+
produces = MediaType.APPLICATION_JSON_VALUE)
41+
@Timed
42+
public ResponseEntity<Void> create(@Valid @RequestBody Author author) throws URISyntaxException {
43+
log.debug("REST request to save Author : {}", author);
44+
if (author.getId() != null) {
45+
return ResponseEntity.badRequest().header("Failure", "A new author cannot already have an ID").build();
46+
}
47+
authorRepository.save(author);
48+
return ResponseEntity.created(new URI("/api/authors/" + author.getId())).build();
49+
}
50+
51+
/**
52+
* PUT /authors -> Updates an existing author.
53+
*/
54+
@RequestMapping(value = "/authors",
55+
method = RequestMethod.PUT,
56+
produces = MediaType.APPLICATION_JSON_VALUE)
57+
@Timed
58+
public ResponseEntity<Void> update(@Valid @RequestBody Author author) throws URISyntaxException {
59+
log.debug("REST request to update Author : {}", author);
60+
if (author.getId() == null) {
61+
return create(author);
62+
}
63+
authorRepository.save(author);
64+
return ResponseEntity.ok().build();
65+
}
66+
67+
/**
68+
* GET /authors -> get all the authors.
69+
*/
70+
@RequestMapping(value = "/authors",
71+
method = RequestMethod.GET,
72+
produces = MediaType.APPLICATION_JSON_VALUE)
73+
@Timed
74+
public ResponseEntity<List<Author>> getAll(@RequestParam(value = "page" , required = false) Integer offset,
75+
@RequestParam(value = "per_page", required = false) Integer limit)
76+
throws URISyntaxException {
77+
Page<Author> page = authorRepository.findAll(PaginationUtil.generatePageRequest(offset, limit));
78+
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/authors", offset, limit);
79+
return new ResponseEntity<List<Author>>(page.getContent(), headers, HttpStatus.OK);
80+
}
81+
82+
/**
83+
* GET /authors/:id -> get the "id" author.
84+
*/
85+
@RequestMapping(value = "/authors/{id}",
86+
method = RequestMethod.GET,
87+
produces = MediaType.APPLICATION_JSON_VALUE)
88+
@Timed
89+
public ResponseEntity<Author> get(@PathVariable Long id, HttpServletResponse response) {
90+
log.debug("REST request to get Author : {}", id);
91+
Author author = authorRepository.findOne(id);
92+
if (author == null) {
93+
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
94+
}
95+
return new ResponseEntity<>(author, HttpStatus.OK);
96+
}
97+
98+
/**
99+
* DELETE /authors/:id -> delete the "id" author.
100+
*/
101+
@RequestMapping(value = "/authors/{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 Author : {}", id);
107+
authorRepository.delete(id);
108+
}
109+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 Author.
15+
-->
16+
<changeSet id="20150627193612" author="jhipster">
17+
<createTable tableName="AUTHOR">
18+
<column name="id" type="bigint" autoIncrement="${autoIncrement}" >
19+
<constraints primaryKey="true" nullable="false"/>
20+
</column>
21+
<column name="name" type="varchar(255)"/>
22+
<column name="surname" type="varchar(255)"/>
23+
<column name="description" type="varchar(255)"/>
24+
<column name="birth_date" type="date"/>
25+
</createTable>
26+
27+
</changeSet>
28+
</databaseChangeLog>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
66

77
<include file="classpath:config/liquibase/changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="false"/>
8+
<include file="classpath:config/liquibase/changelog/20150627193612_added_entity_Author.xml" relativeToChangelogFile="false"/>
89
<!-- JHipster will add liquibase changelogs here -->
910
</databaseChangeLog>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"bookstoreApp": {
3+
"author" : {
4+
"home": {
5+
"title": "Authors",
6+
"createLabel": "Create a new Author",
7+
"createOrEditLabel": "Create or edit a Author"
8+
},
9+
"delete": {
10+
"question": "Are you sure you want to delete Author {{ id }}?"
11+
},
12+
"detail": {
13+
"title": "Author"
14+
},
15+
"name": "Name",
16+
"surname": "Surname",
17+
"description": "Description",
18+
"birthDate": "BirthDate"
19+
}
20+
}
21+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"home": "Home",
77
"entities": {
88
"main": "Entities",
9+
"author": "Author",
910
"additionalEntity": "JHipster will add additional entities here (do not translate!)"
1011
},
1112
"account": {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"bookstoreApp": {
3+
"author" : {
4+
"home": {
5+
"title": "Authors",
6+
"createLabel": "Créer un nouveau Author",
7+
"createOrEditLabel": "Créer ou éditer un Author"
8+
},
9+
"delete": {
10+
"question": "Etes-vous certain de vouloir supprimer le Author {{ id }} ?"
11+
},
12+
"detail": {
13+
"title": "Author"
14+
},
15+
"name": "Name",
16+
"surname": "Surname",
17+
"description": "Description",
18+
"birthDate": "BirthDate"
19+
}
20+
}
21+
}
22+

src/main/webapp/i18n/fr/global.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"home": "Accueil",
77
"entities": {
88
"main": "Entités",
9+
"author": "Author",
910
"additionalEntity": "JHipster will add additional entities here (do not translate!)"
1011
},
1112
"account": {

0 commit comments

Comments
 (0)