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>
|
||||
<groupId>de.tilman</groupId>
|
||||
<artifactId>next-transactions</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<version>1.9.2</version>
|
||||
|
||||
<parent>
|
||||
<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.Category;
|
||||
import de.tilman.transactions.domain.Transaction;
|
||||
import de.tilman.transactions.domain.User;
|
||||
import de.tilman.transactions.domain.Appuser;
|
||||
|
||||
@Component
|
||||
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.
|
||||
@Override
|
||||
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;
|
||||
|
||||
@ManyToOne(optional = false)
|
||||
private User owner;
|
||||
private Appuser owner;
|
||||
|
||||
@OneToMany(mappedBy = "account")
|
||||
private List<Category> categories;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "account_user", joinColumns = @JoinColumn(name = "account_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"))
|
||||
private List<User> users;
|
||||
@JoinTable(name = "account_user", joinColumns = @JoinColumn(name = "account_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "appuser_id", referencedColumnName = "id"))
|
||||
private List<Appuser> appusers;
|
||||
|
||||
|
||||
|
||||
@@ -44,11 +44,11 @@ public class Account {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public User getOwner() {
|
||||
public Appuser getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(User owner) {
|
||||
public void setOwner(Appuser owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@@ -60,12 +60,12 @@ public class Account {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
public List<User> getUsers() {
|
||||
return users;
|
||||
public List<Appuser> getAppusers() {
|
||||
return appusers;
|
||||
}
|
||||
|
||||
public void setUsers(List<User> users) {
|
||||
this.users = users;
|
||||
public void setAppusers(List<Appuser> appusers) {
|
||||
this.appusers = appusers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
public class Appuser {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@@ -22,7 +22,7 @@ public class User {
|
||||
private String username;
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ public class Transaction {
|
||||
private String description;
|
||||
|
||||
@ManyToOne
|
||||
private User creditor;
|
||||
private Appuser creditor;
|
||||
|
||||
@ManyToOne
|
||||
private Account account;
|
||||
@@ -77,11 +77,11 @@ public class Transaction {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public User getCreditor() {
|
||||
public Appuser getCreditor() {
|
||||
return creditor;
|
||||
}
|
||||
|
||||
public void setCreditor(User creditor) {
|
||||
public void setCreditor(Appuser creditor) {
|
||||
this.creditor = creditor;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import de.tilman.transactions.domain.Account;
|
||||
public interface AccountRepository extends CrudRepository<Account, Long> {
|
||||
|
||||
// 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
|
||||
//@PostFilter("filterObject.user.getId() == principal.id") // http://stackoverflow.com/a/30877376/3761783
|
||||
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.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
|
||||
@@ -21,7 +21,7 @@ public interface TransactionInlineProjection {
|
||||
public Date getLastChange();
|
||||
public String getDescription();
|
||||
|
||||
public User getCreditor();
|
||||
public Appuser getCreditor();
|
||||
public Category getCategory();
|
||||
|
||||
// --> 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.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'))")
|
||||
@Query("SELECT u FROM User u WHERE u.username = :username")
|
||||
User findByUsername(@Param("username") String username);
|
||||
@Query("SELECT u FROM Appuser u WHERE u.username = :username")
|
||||
Appuser findByUsername(@Param("username") String username);
|
||||
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@Override
|
||||
User save(User user);
|
||||
Appuser save(Appuser user);
|
||||
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@Override
|
||||
void delete(User user);
|
||||
void delete(Appuser user);
|
||||
|
||||
@Override
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
public Page<User> findAll(Pageable pageable);
|
||||
public Page<Appuser> findAll(Pageable pageable);
|
||||
|
||||
@RestResource(exported = false)
|
||||
User findByName(String name);
|
||||
Appuser findByName(String name);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user