Renamed entity User to Appuser due to H2 problems with reserved word
"User" (https://stackoverflow.com/a/50954456/3761783)
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.tilman</groupId>
|
<groupId>de.tilman</groupId>
|
||||||
<artifactId>next-transactions</artifactId>
|
<artifactId>next-transactions</artifactId>
|
||||||
<version>1.9.1</version>
|
<version>1.9.2</version>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import de.tilman.transactions.domain.Account;
|
import de.tilman.transactions.domain.Account;
|
||||||
import de.tilman.transactions.domain.Category;
|
import de.tilman.transactions.domain.Category;
|
||||||
import de.tilman.transactions.domain.Transaction;
|
import de.tilman.transactions.domain.Transaction;
|
||||||
import de.tilman.transactions.domain.User;
|
import de.tilman.transactions.domain.Appuser;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter {
|
public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter {
|
||||||
@@ -15,6 +15,6 @@ public class SpringDataRestCustomization extends RepositoryRestConfigurerAdapter
|
|||||||
// TODO Ask someone who knows better how to do all of this without exposing the IDs. Parsing URLs can't be the answer.
|
// TODO Ask someone who knows better how to do all of this without exposing the IDs. Parsing URLs can't be the answer.
|
||||||
@Override
|
@Override
|
||||||
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
|
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
|
||||||
config.exposeIdsFor(Account.class, Category.class, Transaction.class, User.class);
|
config.exposeIdsFor(Account.class, Category.class, Transaction.class, Appuser.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ public class Account {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
private User owner;
|
private Appuser owner;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "account")
|
@OneToMany(mappedBy = "account")
|
||||||
private List<Category> categories;
|
private List<Category> categories;
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinTable(name = "account_user", joinColumns = @JoinColumn(name = "account_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"))
|
@JoinTable(name = "account_user", joinColumns = @JoinColumn(name = "account_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "appuser_id", referencedColumnName = "id"))
|
||||||
private List<User> users;
|
private List<Appuser> appusers;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -44,11 +44,11 @@ public class Account {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getOwner() {
|
public Appuser getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOwner(User owner) {
|
public void setOwner(Appuser owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,12 +60,12 @@ public class Account {
|
|||||||
this.categories = categories;
|
this.categories = categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getUsers() {
|
public List<Appuser> getAppusers() {
|
||||||
return users;
|
return appusers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsers(List<User> users) {
|
public void setAppusers(List<Appuser> appusers) {
|
||||||
this.users = users;
|
this.appusers = appusers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -10,7 +10,7 @@ import javax.persistence.JoinTable;
|
|||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class User {
|
public class Appuser {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
@@ -22,7 +22,7 @@ public class User {
|
|||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinTable(name = "account_user", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "account_id", referencedColumnName = "id"))
|
@JoinTable(name = "account_user", joinColumns = @JoinColumn(name = "appuser_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "account_id", referencedColumnName = "id"))
|
||||||
private List<Account> accounts;
|
private List<Account> accounts;
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ public class Transaction {
|
|||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private User creditor;
|
private Appuser creditor;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private Account account;
|
private Account account;
|
||||||
@@ -77,11 +77,11 @@ public class Transaction {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getCreditor() {
|
public Appuser getCreditor() {
|
||||||
return creditor;
|
return creditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreditor(User creditor) {
|
public void setCreditor(Appuser creditor) {
|
||||||
this.creditor = creditor;
|
this.creditor = creditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import de.tilman.transactions.domain.Account;
|
|||||||
public interface AccountRepository extends CrudRepository<Account, Long> {
|
public interface AccountRepository extends CrudRepository<Account, Long> {
|
||||||
|
|
||||||
// http://localhost:8080/accounts/search/findByUserName?username=betty@mail.com
|
// http://localhost:8080/accounts/search/findByUserName?username=betty@mail.com
|
||||||
@Query("SELECT a FROM Account a INNER JOIN a.users u WHERE u.username = :username")
|
@Query("SELECT a FROM Account a INNER JOIN a.appusers u WHERE u.username = :username")
|
||||||
@PreAuthorize("isFullyAuthenticated() && ((#username == principal.username) || hasRole('ROLE_ADMIN'))") // http://stackoverflow.com/q/23640487/3761783
|
@PreAuthorize("isFullyAuthenticated() && ((#username == principal.username) || hasRole('ROLE_ADMIN'))") // http://stackoverflow.com/q/23640487/3761783
|
||||||
//@PostFilter("filterObject.user.getId() == principal.id") // http://stackoverflow.com/a/30877376/3761783
|
//@PostFilter("filterObject.user.getId() == principal.id") // http://stackoverflow.com/a/30877376/3761783
|
||||||
List<Account> findByUserName(@Param("username") String username);
|
List<Account> findByUserName(@Param("username") String username);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.springframework.data.rest.core.config.Projection;
|
|||||||
|
|
||||||
import de.tilman.transactions.domain.Category;
|
import de.tilman.transactions.domain.Category;
|
||||||
import de.tilman.transactions.domain.Transaction;
|
import de.tilman.transactions.domain.Transaction;
|
||||||
import de.tilman.transactions.domain.User;
|
import de.tilman.transactions.domain.Appuser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see http://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.excerpting-commonly-accessed-data
|
* @see http://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts.excerpting-commonly-accessed-data
|
||||||
@@ -21,7 +21,7 @@ public interface TransactionInlineProjection {
|
|||||||
public Date getLastChange();
|
public Date getLastChange();
|
||||||
public String getDescription();
|
public String getDescription();
|
||||||
|
|
||||||
public User getCreditor();
|
public Appuser getCreditor();
|
||||||
public Category getCategory();
|
public Category getCategory();
|
||||||
|
|
||||||
// --> account wird direkt per Parameter gefiltert
|
// --> account wird direkt per Parameter gefiltert
|
||||||
|
|||||||
@@ -8,27 +8,27 @@ import org.springframework.data.repository.query.Param;
|
|||||||
import org.springframework.data.rest.core.annotation.RestResource;
|
import org.springframework.data.rest.core.annotation.RestResource;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
|
||||||
import de.tilman.transactions.domain.User;
|
import de.tilman.transactions.domain.Appuser;
|
||||||
|
|
||||||
public interface UserRepository extends PagingAndSortingRepository<User, Long> {
|
public interface UserRepository extends PagingAndSortingRepository<Appuser, Long> {
|
||||||
|
|
||||||
@PreAuthorize("isFullyAuthenticated() && ((#username == principal.username) || hasRole('ROLE_ADMIN'))")
|
@PreAuthorize("isFullyAuthenticated() && ((#username == principal.username) || hasRole('ROLE_ADMIN'))")
|
||||||
@Query("SELECT u FROM User u WHERE u.username = :username")
|
@Query("SELECT u FROM Appuser u WHERE u.username = :username")
|
||||||
User findByUsername(@Param("username") String username);
|
Appuser findByUsername(@Param("username") String username);
|
||||||
|
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
@Override
|
@Override
|
||||||
User save(User user);
|
Appuser save(Appuser user);
|
||||||
|
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
@Override
|
@Override
|
||||||
void delete(User user);
|
void delete(Appuser user);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
public Page<User> findAll(Pageable pageable);
|
public Page<Appuser> findAll(Pageable pageable);
|
||||||
|
|
||||||
@RestResource(exported = false)
|
@RestResource(exported = false)
|
||||||
User findByName(String name);
|
Appuser findByName(String name);
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user