pt. 1, step 2 - repositories and test data

This commit is contained in:
2016-03-02 13:54:21 +01:00
parent bbfd923e43
commit b6fc5edc17
10 changed files with 85 additions and 7 deletions
+1
View File
@@ -12,6 +12,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
+2 -2
View File
@@ -24,10 +24,10 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<!-- dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependency -->
</dependencies>
<properties>
@@ -20,10 +20,10 @@ public class Account {
private String name;
@ManyToOne
@ManyToOne(optional = false)
private User owner;
@OneToMany
@OneToMany(mappedBy = "account")
private List<Category> categories;
@ManyToMany
@@ -5,7 +5,9 @@ import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
@Entity
public class User {
@@ -16,7 +18,8 @@ public class User {
private String name;
@OneToMany
@ManyToMany
@JoinTable(name = "account_user", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "account_id", referencedColumnName = "id"))
private List<Account> accounts;
@@ -37,4 +40,5 @@ public class User {
}
}
@@ -0,0 +1,8 @@
package de.tilman.transactions.repository;
import org.springframework.data.repository.CrudRepository;
import de.tilman.transactions.domain.Account;
public interface AccountRepository extends CrudRepository<Account, Long> {
}
@@ -0,0 +1,9 @@
package de.tilman.transactions.repository;
import org.springframework.data.repository.PagingAndSortingRepository;
import de.tilman.transactions.domain.Category;
public interface CategoryRepository extends PagingAndSortingRepository<Category, Long> {
}
@@ -0,0 +1,9 @@
package de.tilman.transactions.repository;
import org.springframework.data.repository.PagingAndSortingRepository;
import de.tilman.transactions.domain.Transaction;
public interface TransactionRepository extends PagingAndSortingRepository<Transaction, Long> {
}
@@ -0,0 +1,13 @@
package de.tilman.transactions.repository;
import org.springframework.data.repository.PagingAndSortingRepository;
import de.tilman.transactions.domain.User;
public interface UserRepository extends PagingAndSortingRepository<User, Long> {
// @Override
// @PreAuthorize("hasRole('ROLE_ADMIN')")
// public Page<User> findAll(Pageable pageable);
}
@@ -0,0 +1,5 @@
spring.datasource.platform=h2
security.user.name=sa
security.user.password=
server.port=8080
+29
View File
@@ -0,0 +1,29 @@
INSERT INTO User (id, name) VALUES (1, 'Tilman'), (2, 'Anica');
INSERT INTO Account (id, name, owner_id) VALUES (1, 'Gemeinschaftskonto', 1), (2, 'Konto Tilman', 1);
INSERT INTO Category (id, name, account_id, position) VALUES (1, 'Essen - Lebensmittel', 1, 2), (2, 'Einnahmen - Gehalt', 1, 1), (3, 'Essen - Arbeit', 1, 3), (4, 'Einnahmen - Gehalt', 2, 1), (5, 'Technik - Server und Hosting', 2, 2);
INSERT INTO Account_User (account_id, user_id) VALUES (1, 1), (1, 2), (2, 1);
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES
(NULL, 1280.81, 1, 1, '2014-06-01', 'Gehalt', null),
(NULL, -2.21, 1, 2, '2014-06-10', 'Brot', null),
(NULL, -3.41, 1, 2, '2014-06-12', 'Gemüse', null),
(NULL, -7.81, 1, 3, '2014-06-19', 'Kantine', null),
(NULL, -4.81, 1, 3, '2014-06-18', 'Currywurst', 1),
(NULL, -4.50, 1, 3, '2014-06-19', 'Currywurst', null),
(NULL, -4.50, 1, 3, '2014-06-20', 'Currywurst', null),
(NULL, -4.50, 2, 3, '2014-06-20', 'Currywurst', null),
(NULL, -4.09, 1, 3, '2014-06-18', 'Currywurst-Frühstück', null),
(NULL, -4.90, 1, 3, '2014-06-18', 'Currywurst (Auslage Anica)', 2),
(NULL, -8.90, 1, 3, '2014-06-18', 'Curry beim Inder (Auslage Tilman)', 1),
(NULL, -12.00, 2, 3, '2014-06-18', 'Curry Thai', null),
(NULL, 1340.22, 2, 4, '2014-06-02', 'Gehalt Tilman', null),
(NULL, -12.90, 2, 5, '2014-06-16', 'Host Europe', null);
-- add as many transactions as needed
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 2, CURRENT_TIMESTAMP(), 'Transaction', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, -1.50, 1, 3, CURRENT_TIMESTAMP(), 'Transaction', null); Commit;
INSERT INTO Transaction (id, amount, account_id, category_id, date, description, creditor_id) VALUES (NULL, 1.50, 1, 4, CURRENT_TIMESTAMP()+1, 'LAST Transaction', null); Commit;