Merge tag 'transactionModelJhipster' into ver3
This commit is contained in:
@@ -38,7 +38,7 @@ public class Charge implements Serializable {
|
||||
private BigDecimal amount;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JsonIgnoreProperties(value = { "registrations" }, allowSetters = true)
|
||||
@JsonIgnoreProperties(value = { "registrations", "transactions" }, allowSetters = true)
|
||||
private Event event;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
|
||||
@@ -47,6 +47,10 @@ public class Event implements Serializable {
|
||||
@JsonIgnoreProperties(value = { "event" }, allowSetters = true)
|
||||
private Set<Registration> registrations = new HashSet<>();
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "event")
|
||||
@JsonIgnoreProperties(value = { "event", "transactionItem" }, allowSetters = true)
|
||||
private Set<Transaction> transactions = new HashSet<>();
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here
|
||||
|
||||
public Long getId() {
|
||||
@@ -158,6 +162,37 @@ public class Event implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<Transaction> getTransactions() {
|
||||
return this.transactions;
|
||||
}
|
||||
|
||||
public void setTransactions(Set<Transaction> transactions) {
|
||||
if (this.transactions != null) {
|
||||
this.transactions.forEach(i -> i.setEvent(null));
|
||||
}
|
||||
if (transactions != null) {
|
||||
transactions.forEach(i -> i.setEvent(this));
|
||||
}
|
||||
this.transactions = transactions;
|
||||
}
|
||||
|
||||
public Event transactions(Set<Transaction> transactions) {
|
||||
this.setTransactions(transactions);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Event addTransaction(Transaction transaction) {
|
||||
this.transactions.add(transaction);
|
||||
transaction.setEvent(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Event removeTransaction(Transaction transaction) {
|
||||
this.transactions.remove(transaction);
|
||||
transaction.setEvent(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Registration implements Serializable {
|
||||
private User user;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JsonIgnoreProperties(value = { "registrations" }, allowSetters = true)
|
||||
@JsonIgnoreProperties(value = { "registrations", "transactions" }, allowSetters = true)
|
||||
private Event event;
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.sasiedzi.event.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.sasiedzi.event.domain.enumeration.TransactionType;
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* A Transaction.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "transaction")
|
||||
@SuppressWarnings("common-java:DuplicatedBlocks")
|
||||
public class Transaction implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = "type")
|
||||
private TransactionType type;
|
||||
|
||||
@Column(name = "date")
|
||||
private LocalDate date;
|
||||
|
||||
@Column(name = "comment")
|
||||
private String comment;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JsonIgnoreProperties(value = { "registrations", "transactions" }, allowSetters = true)
|
||||
private Event event;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JsonIgnoreProperties(value = { "userAccounts", "transactions" }, allowSetters = true)
|
||||
private TransactionItem transactionItem;
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Transaction id(Long id) {
|
||||
this.setId(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public TransactionType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public Transaction type(TransactionType type) {
|
||||
this.setType(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setType(TransactionType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public Transaction date(LocalDate date) {
|
||||
this.setDate(date);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
public Transaction comment(String comment) {
|
||||
this.setComment(comment);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public Event getEvent() {
|
||||
return this.event;
|
||||
}
|
||||
|
||||
public void setEvent(Event event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public Transaction event(Event event) {
|
||||
this.setEvent(event);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TransactionItem getTransactionItem() {
|
||||
return this.transactionItem;
|
||||
}
|
||||
|
||||
public void setTransactionItem(TransactionItem transactionItem) {
|
||||
this.transactionItem = transactionItem;
|
||||
}
|
||||
|
||||
public Transaction transactionItem(TransactionItem transactionItem) {
|
||||
this.setTransactionItem(transactionItem);
|
||||
return this;
|
||||
}
|
||||
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof Transaction)) {
|
||||
return false;
|
||||
}
|
||||
return getId() != null && getId().equals(((Transaction) o).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
|
||||
return getClass().hashCode();
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Transaction{" +
|
||||
"id=" + getId() +
|
||||
", type='" + getType() + "'" +
|
||||
", date='" + getDate() + "'" +
|
||||
", comment='" + getComment() + "'" +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package com.sasiedzi.event.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A TransactionItem.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "transaction_item")
|
||||
@SuppressWarnings("common-java:DuplicatedBlocks")
|
||||
public class TransactionItem implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "amount", precision = 21, scale = 2)
|
||||
private BigDecimal amount;
|
||||
|
||||
@Column(name = "date")
|
||||
private LocalDate date;
|
||||
|
||||
@Column(name = "comment")
|
||||
private String comment;
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(
|
||||
name = "rel_transaction_item__user_account",
|
||||
joinColumns = @JoinColumn(name = "transaction_item_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "user_account_id")
|
||||
)
|
||||
@JsonIgnoreProperties(value = { "users", "transactionItems" }, allowSetters = true)
|
||||
private Set<UserAccount> userAccounts = new HashSet<>();
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "transactionItem")
|
||||
@JsonIgnoreProperties(value = { "event", "transactionItem" }, allowSetters = true)
|
||||
private Set<Transaction> transactions = new HashSet<>();
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public TransactionItem id(Long id) {
|
||||
this.setId(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public TransactionItem amount(BigDecimal amount) {
|
||||
this.setAmount(amount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public TransactionItem date(LocalDate date) {
|
||||
this.setDate(date);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
public TransactionItem comment(String comment) {
|
||||
this.setComment(comment);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public Set<UserAccount> getUserAccounts() {
|
||||
return this.userAccounts;
|
||||
}
|
||||
|
||||
public void setUserAccounts(Set<UserAccount> userAccounts) {
|
||||
this.userAccounts = userAccounts;
|
||||
}
|
||||
|
||||
public TransactionItem userAccounts(Set<UserAccount> userAccounts) {
|
||||
this.setUserAccounts(userAccounts);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TransactionItem addUserAccount(UserAccount userAccount) {
|
||||
this.userAccounts.add(userAccount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TransactionItem removeUserAccount(UserAccount userAccount) {
|
||||
this.userAccounts.remove(userAccount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<Transaction> getTransactions() {
|
||||
return this.transactions;
|
||||
}
|
||||
|
||||
public void setTransactions(Set<Transaction> transactions) {
|
||||
if (this.transactions != null) {
|
||||
this.transactions.forEach(i -> i.setTransactionItem(null));
|
||||
}
|
||||
if (transactions != null) {
|
||||
transactions.forEach(i -> i.setTransactionItem(this));
|
||||
}
|
||||
this.transactions = transactions;
|
||||
}
|
||||
|
||||
public TransactionItem transactions(Set<Transaction> transactions) {
|
||||
this.setTransactions(transactions);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TransactionItem addTransaction(Transaction transaction) {
|
||||
this.transactions.add(transaction);
|
||||
transaction.setTransactionItem(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TransactionItem removeTransaction(Transaction transaction) {
|
||||
this.transactions.remove(transaction);
|
||||
transaction.setTransactionItem(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof TransactionItem)) {
|
||||
return false;
|
||||
}
|
||||
return getId() != null && getId().equals(((TransactionItem) o).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
|
||||
return getClass().hashCode();
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TransactionItem{" +
|
||||
"id=" + getId() +
|
||||
", amount=" + getAmount() +
|
||||
", date='" + getDate() + "'" +
|
||||
", comment='" + getComment() + "'" +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.sasiedzi.event.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A UserAccount.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "user_account")
|
||||
@SuppressWarnings("common-java:DuplicatedBlocks")
|
||||
public class UserAccount implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(
|
||||
name = "rel_user_account__user",
|
||||
joinColumns = @JoinColumn(name = "user_account_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "user_id")
|
||||
)
|
||||
private Set<User> users = new HashSet<>();
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "userAccounts")
|
||||
@JsonIgnoreProperties(value = { "userAccounts", "transactions" }, allowSetters = true)
|
||||
private Set<TransactionItem> transactionItems = new HashSet<>();
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public UserAccount id(Long id) {
|
||||
this.setId(id);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public UserAccount name(String name) {
|
||||
this.setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Set<User> getUsers() {
|
||||
return this.users;
|
||||
}
|
||||
|
||||
public void setUsers(Set<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public UserAccount users(Set<User> users) {
|
||||
this.setUsers(users);
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserAccount addUser(User user) {
|
||||
this.users.add(user);
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserAccount removeUser(User user) {
|
||||
this.users.remove(user);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<TransactionItem> getTransactionItems() {
|
||||
return this.transactionItems;
|
||||
}
|
||||
|
||||
public void setTransactionItems(Set<TransactionItem> transactionItems) {
|
||||
if (this.transactionItems != null) {
|
||||
this.transactionItems.forEach(i -> i.removeUserAccount(this));
|
||||
}
|
||||
if (transactionItems != null) {
|
||||
transactionItems.forEach(i -> i.addUserAccount(this));
|
||||
}
|
||||
this.transactionItems = transactionItems;
|
||||
}
|
||||
|
||||
public UserAccount transactionItems(Set<TransactionItem> transactionItems) {
|
||||
this.setTransactionItems(transactionItems);
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserAccount addTransactionItem(TransactionItem transactionItem) {
|
||||
this.transactionItems.add(transactionItem);
|
||||
transactionItem.getUserAccounts().add(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserAccount removeTransactionItem(TransactionItem transactionItem) {
|
||||
this.transactionItems.remove(transactionItem);
|
||||
transactionItem.getUserAccounts().remove(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof UserAccount)) {
|
||||
return false;
|
||||
}
|
||||
return getId() != null && getId().equals(((UserAccount) o).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
|
||||
return getClass().hashCode();
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserAccount{" +
|
||||
"id=" + getId() +
|
||||
", name='" + getName() + "'" +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.sasiedzi.event.domain.enumeration;
|
||||
|
||||
/**
|
||||
* The TransactionType enumeration.
|
||||
*/
|
||||
public enum TransactionType {
|
||||
PURCHASE,
|
||||
MATCH,
|
||||
FIELDPAYMENT,
|
||||
INTERNALTRANSFER,
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.sasiedzi.event.repository;
|
||||
|
||||
import com.sasiedzi.event.domain.TransactionItem;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA repository for the TransactionItem entity.
|
||||
*
|
||||
* When extending this class, extend TransactionItemRepositoryWithBagRelationships too.
|
||||
* For more information refer to https://github.com/jhipster/generator-jhipster/issues/17990.
|
||||
*/
|
||||
@Repository
|
||||
public interface TransactionItemRepository extends TransactionItemRepositoryWithBagRelationships, JpaRepository<TransactionItem, Long> {
|
||||
default Optional<TransactionItem> findOneWithEagerRelationships(Long id) {
|
||||
return this.fetchBagRelationships(this.findById(id));
|
||||
}
|
||||
|
||||
default List<TransactionItem> findAllWithEagerRelationships() {
|
||||
return this.fetchBagRelationships(this.findAll());
|
||||
}
|
||||
|
||||
default Page<TransactionItem> findAllWithEagerRelationships(Pageable pageable) {
|
||||
return this.fetchBagRelationships(this.findAll(pageable));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.sasiedzi.event.repository;
|
||||
|
||||
import com.sasiedzi.event.domain.TransactionItem;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public interface TransactionItemRepositoryWithBagRelationships {
|
||||
Optional<TransactionItem> fetchBagRelationships(Optional<TransactionItem> transactionItem);
|
||||
|
||||
List<TransactionItem> fetchBagRelationships(List<TransactionItem> transactionItems);
|
||||
|
||||
Page<TransactionItem> fetchBagRelationships(Page<TransactionItem> transactionItems);
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.sasiedzi.event.repository;
|
||||
|
||||
import com.sasiedzi.event.domain.TransactionItem;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.IntStream;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
|
||||
/**
|
||||
* Utility repository to load bag relationships based on https://vladmihalcea.com/hibernate-multiplebagfetchexception/
|
||||
*/
|
||||
public class TransactionItemRepositoryWithBagRelationshipsImpl implements TransactionItemRepositoryWithBagRelationships {
|
||||
|
||||
private static final String ID_PARAMETER = "id";
|
||||
private static final String TRANSACTIONITEMS_PARAMETER = "transactionItems";
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
public Optional<TransactionItem> fetchBagRelationships(Optional<TransactionItem> transactionItem) {
|
||||
return transactionItem.map(this::fetchUserAccounts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<TransactionItem> fetchBagRelationships(Page<TransactionItem> transactionItems) {
|
||||
return new PageImpl<>(
|
||||
fetchBagRelationships(transactionItems.getContent()),
|
||||
transactionItems.getPageable(),
|
||||
transactionItems.getTotalElements()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TransactionItem> fetchBagRelationships(List<TransactionItem> transactionItems) {
|
||||
return Optional.of(transactionItems).map(this::fetchUserAccounts).orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
TransactionItem fetchUserAccounts(TransactionItem result) {
|
||||
return entityManager
|
||||
.createQuery(
|
||||
"select transactionItem from TransactionItem transactionItem left join fetch transactionItem.userAccounts where transactionItem.id = :id",
|
||||
TransactionItem.class
|
||||
)
|
||||
.setParameter(ID_PARAMETER, result.getId())
|
||||
.getSingleResult();
|
||||
}
|
||||
|
||||
List<TransactionItem> fetchUserAccounts(List<TransactionItem> transactionItems) {
|
||||
HashMap<Object, Integer> order = new HashMap<>();
|
||||
IntStream.range(0, transactionItems.size()).forEach(index -> order.put(transactionItems.get(index).getId(), index));
|
||||
List<TransactionItem> result = entityManager
|
||||
.createQuery(
|
||||
"select transactionItem from TransactionItem transactionItem left join fetch transactionItem.userAccounts where transactionItem in :transactionItems",
|
||||
TransactionItem.class
|
||||
)
|
||||
.setParameter(TRANSACTIONITEMS_PARAMETER, transactionItems)
|
||||
.getResultList();
|
||||
Collections.sort(result, (o1, o2) -> Integer.compare(order.get(o1.getId()), order.get(o2.getId())));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.sasiedzi.event.repository;
|
||||
|
||||
import com.sasiedzi.event.domain.Transaction;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.*;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA repository for the Transaction entity.
|
||||
*/
|
||||
@Repository
|
||||
public interface TransactionRepository extends JpaRepository<Transaction, Long> {
|
||||
default Optional<Transaction> findOneWithEagerRelationships(Long id) {
|
||||
return this.findOneWithToOneRelationships(id);
|
||||
}
|
||||
|
||||
default List<Transaction> findAllWithEagerRelationships() {
|
||||
return this.findAllWithToOneRelationships();
|
||||
}
|
||||
|
||||
default Page<Transaction> findAllWithEagerRelationships(Pageable pageable) {
|
||||
return this.findAllWithToOneRelationships(pageable);
|
||||
}
|
||||
|
||||
@Query(
|
||||
value = "select transaction from Transaction transaction left join fetch transaction.event",
|
||||
countQuery = "select count(transaction) from Transaction transaction"
|
||||
)
|
||||
Page<Transaction> findAllWithToOneRelationships(Pageable pageable);
|
||||
|
||||
@Query("select transaction from Transaction transaction left join fetch transaction.event")
|
||||
List<Transaction> findAllWithToOneRelationships();
|
||||
|
||||
@Query("select transaction from Transaction transaction left join fetch transaction.event where transaction.id =:id")
|
||||
Optional<Transaction> findOneWithToOneRelationships(@Param("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.sasiedzi.event.repository;
|
||||
|
||||
import com.sasiedzi.event.domain.UserAccount;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.*;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Spring Data JPA repository for the UserAccount entity.
|
||||
*
|
||||
* When extending this class, extend UserAccountRepositoryWithBagRelationships too.
|
||||
* For more information refer to https://github.com/jhipster/generator-jhipster/issues/17990.
|
||||
*/
|
||||
@Repository
|
||||
public interface UserAccountRepository extends UserAccountRepositoryWithBagRelationships, JpaRepository<UserAccount, Long> {
|
||||
default Optional<UserAccount> findOneWithEagerRelationships(Long id) {
|
||||
return this.fetchBagRelationships(this.findById(id));
|
||||
}
|
||||
|
||||
default List<UserAccount> findAllWithEagerRelationships() {
|
||||
return this.fetchBagRelationships(this.findAll());
|
||||
}
|
||||
|
||||
default Page<UserAccount> findAllWithEagerRelationships(Pageable pageable) {
|
||||
return this.fetchBagRelationships(this.findAll(pageable));
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.sasiedzi.event.repository;
|
||||
|
||||
import com.sasiedzi.event.domain.UserAccount;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public interface UserAccountRepositoryWithBagRelationships {
|
||||
Optional<UserAccount> fetchBagRelationships(Optional<UserAccount> userAccount);
|
||||
|
||||
List<UserAccount> fetchBagRelationships(List<UserAccount> userAccounts);
|
||||
|
||||
Page<UserAccount> fetchBagRelationships(Page<UserAccount> userAccounts);
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.sasiedzi.event.repository;
|
||||
|
||||
import com.sasiedzi.event.domain.UserAccount;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.IntStream;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
|
||||
/**
|
||||
* Utility repository to load bag relationships based on https://vladmihalcea.com/hibernate-multiplebagfetchexception/
|
||||
*/
|
||||
public class UserAccountRepositoryWithBagRelationshipsImpl implements UserAccountRepositoryWithBagRelationships {
|
||||
|
||||
private static final String ID_PARAMETER = "id";
|
||||
private static final String USERACCOUNTS_PARAMETER = "userAccounts";
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
public Optional<UserAccount> fetchBagRelationships(Optional<UserAccount> userAccount) {
|
||||
return userAccount.map(this::fetchUsers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<UserAccount> fetchBagRelationships(Page<UserAccount> userAccounts) {
|
||||
return new PageImpl<>(
|
||||
fetchBagRelationships(userAccounts.getContent()),
|
||||
userAccounts.getPageable(),
|
||||
userAccounts.getTotalElements()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserAccount> fetchBagRelationships(List<UserAccount> userAccounts) {
|
||||
return Optional.of(userAccounts).map(this::fetchUsers).orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
UserAccount fetchUsers(UserAccount result) {
|
||||
return entityManager
|
||||
.createQuery(
|
||||
"select userAccount from UserAccount userAccount left join fetch userAccount.users where userAccount.id = :id",
|
||||
UserAccount.class
|
||||
)
|
||||
.setParameter(ID_PARAMETER, result.getId())
|
||||
.getSingleResult();
|
||||
}
|
||||
|
||||
List<UserAccount> fetchUsers(List<UserAccount> userAccounts) {
|
||||
HashMap<Object, Integer> order = new HashMap<>();
|
||||
IntStream.range(0, userAccounts.size()).forEach(index -> order.put(userAccounts.get(index).getId(), index));
|
||||
List<UserAccount> result = entityManager
|
||||
.createQuery(
|
||||
"select userAccount from UserAccount userAccount left join fetch userAccount.users where userAccount in :userAccounts",
|
||||
UserAccount.class
|
||||
)
|
||||
.setParameter(USERACCOUNTS_PARAMETER, userAccounts)
|
||||
.getResultList();
|
||||
Collections.sort(result, (o1, o2) -> Integer.compare(order.get(o1.getId()), order.get(o2.getId())));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package com.sasiedzi.event.web.rest;
|
||||
|
||||
import com.sasiedzi.event.domain.TransactionItem;
|
||||
import com.sasiedzi.event.repository.TransactionItemRepository;
|
||||
import com.sasiedzi.event.web.rest.errors.BadRequestAlertException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tech.jhipster.web.util.HeaderUtil;
|
||||
import tech.jhipster.web.util.ResponseUtil;
|
||||
|
||||
/**
|
||||
* REST controller for managing {@link com.sasiedzi.event.domain.TransactionItem}.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/transaction-items")
|
||||
@Transactional
|
||||
public class TransactionItemResource {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TransactionItemResource.class);
|
||||
|
||||
private static final String ENTITY_NAME = "transactionItem";
|
||||
|
||||
@Value("${jhipster.clientApp.name}")
|
||||
private String applicationName;
|
||||
|
||||
private final TransactionItemRepository transactionItemRepository;
|
||||
|
||||
public TransactionItemResource(TransactionItemRepository transactionItemRepository) {
|
||||
this.transactionItemRepository = transactionItemRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code POST /transaction-items} : Create a new transactionItem.
|
||||
*
|
||||
* @param transactionItem the transactionItem to create.
|
||||
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new transactionItem, or with status {@code 400 (Bad Request)} if the transactionItem has already an ID.
|
||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||
*/
|
||||
@PostMapping("")
|
||||
public ResponseEntity<TransactionItem> createTransactionItem(@RequestBody TransactionItem transactionItem) throws URISyntaxException {
|
||||
LOG.debug("REST request to save TransactionItem : {}", transactionItem);
|
||||
if (transactionItem.getId() != null) {
|
||||
throw new BadRequestAlertException("A new transactionItem cannot already have an ID", ENTITY_NAME, "idexists");
|
||||
}
|
||||
transactionItem = transactionItemRepository.save(transactionItem);
|
||||
return ResponseEntity.created(new URI("/api/transaction-items/" + transactionItem.getId()))
|
||||
.headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, transactionItem.getId().toString()))
|
||||
.body(transactionItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code PUT /transaction-items/:id} : Updates an existing transactionItem.
|
||||
*
|
||||
* @param id the id of the transactionItem to save.
|
||||
* @param transactionItem the transactionItem to update.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated transactionItem,
|
||||
* or with status {@code 400 (Bad Request)} if the transactionItem is not valid,
|
||||
* or with status {@code 500 (Internal Server Error)} if the transactionItem couldn't be updated.
|
||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<TransactionItem> updateTransactionItem(
|
||||
@PathVariable(value = "id", required = false) final Long id,
|
||||
@RequestBody TransactionItem transactionItem
|
||||
) throws URISyntaxException {
|
||||
LOG.debug("REST request to update TransactionItem : {}, {}", id, transactionItem);
|
||||
if (transactionItem.getId() == null) {
|
||||
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
|
||||
}
|
||||
if (!Objects.equals(id, transactionItem.getId())) {
|
||||
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
|
||||
}
|
||||
|
||||
if (!transactionItemRepository.existsById(id)) {
|
||||
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
|
||||
}
|
||||
|
||||
transactionItem = transactionItemRepository.save(transactionItem);
|
||||
return ResponseEntity.ok()
|
||||
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, transactionItem.getId().toString()))
|
||||
.body(transactionItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code PATCH /transaction-items/:id} : Partial updates given fields of an existing transactionItem, field will ignore if it is null
|
||||
*
|
||||
* @param id the id of the transactionItem to save.
|
||||
* @param transactionItem the transactionItem to update.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated transactionItem,
|
||||
* or with status {@code 400 (Bad Request)} if the transactionItem is not valid,
|
||||
* or with status {@code 404 (Not Found)} if the transactionItem is not found,
|
||||
* or with status {@code 500 (Internal Server Error)} if the transactionItem couldn't be updated.
|
||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||
*/
|
||||
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
|
||||
public ResponseEntity<TransactionItem> partialUpdateTransactionItem(
|
||||
@PathVariable(value = "id", required = false) final Long id,
|
||||
@RequestBody TransactionItem transactionItem
|
||||
) throws URISyntaxException {
|
||||
LOG.debug("REST request to partial update TransactionItem partially : {}, {}", id, transactionItem);
|
||||
if (transactionItem.getId() == null) {
|
||||
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
|
||||
}
|
||||
if (!Objects.equals(id, transactionItem.getId())) {
|
||||
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
|
||||
}
|
||||
|
||||
if (!transactionItemRepository.existsById(id)) {
|
||||
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
|
||||
}
|
||||
|
||||
Optional<TransactionItem> result = transactionItemRepository
|
||||
.findById(transactionItem.getId())
|
||||
.map(existingTransactionItem -> {
|
||||
if (transactionItem.getAmount() != null) {
|
||||
existingTransactionItem.setAmount(transactionItem.getAmount());
|
||||
}
|
||||
if (transactionItem.getDate() != null) {
|
||||
existingTransactionItem.setDate(transactionItem.getDate());
|
||||
}
|
||||
if (transactionItem.getComment() != null) {
|
||||
existingTransactionItem.setComment(transactionItem.getComment());
|
||||
}
|
||||
|
||||
return existingTransactionItem;
|
||||
})
|
||||
.map(transactionItemRepository::save);
|
||||
|
||||
return ResponseUtil.wrapOrNotFound(
|
||||
result,
|
||||
HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, transactionItem.getId().toString())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code GET /transaction-items} : get all the transactionItems.
|
||||
*
|
||||
* @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of transactionItems in body.
|
||||
*/
|
||||
@GetMapping("")
|
||||
public List<TransactionItem> getAllTransactionItems(
|
||||
@RequestParam(name = "eagerload", required = false, defaultValue = "true") boolean eagerload
|
||||
) {
|
||||
LOG.debug("REST request to get all TransactionItems");
|
||||
if (eagerload) {
|
||||
return transactionItemRepository.findAllWithEagerRelationships();
|
||||
} else {
|
||||
return transactionItemRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code GET /transaction-items/:id} : get the "id" transactionItem.
|
||||
*
|
||||
* @param id the id of the transactionItem to retrieve.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the transactionItem, or with status {@code 404 (Not Found)}.
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<TransactionItem> getTransactionItem(@PathVariable("id") Long id) {
|
||||
LOG.debug("REST request to get TransactionItem : {}", id);
|
||||
Optional<TransactionItem> transactionItem = transactionItemRepository.findOneWithEagerRelationships(id);
|
||||
return ResponseUtil.wrapOrNotFound(transactionItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code DELETE /transaction-items/:id} : delete the "id" transactionItem.
|
||||
*
|
||||
* @param id the id of the transactionItem to delete.
|
||||
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteTransactionItem(@PathVariable("id") Long id) {
|
||||
LOG.debug("REST request to delete TransactionItem : {}", id);
|
||||
transactionItemRepository.deleteById(id);
|
||||
return ResponseEntity.noContent()
|
||||
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, false, ENTITY_NAME, id.toString()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package com.sasiedzi.event.web.rest;
|
||||
|
||||
import com.sasiedzi.event.domain.Transaction;
|
||||
import com.sasiedzi.event.repository.TransactionRepository;
|
||||
import com.sasiedzi.event.web.rest.errors.BadRequestAlertException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tech.jhipster.web.util.HeaderUtil;
|
||||
import tech.jhipster.web.util.ResponseUtil;
|
||||
|
||||
/**
|
||||
* REST controller for managing {@link com.sasiedzi.event.domain.Transaction}.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/transactions")
|
||||
@Transactional
|
||||
public class TransactionResource {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TransactionResource.class);
|
||||
|
||||
private static final String ENTITY_NAME = "transaction";
|
||||
|
||||
@Value("${jhipster.clientApp.name}")
|
||||
private String applicationName;
|
||||
|
||||
private final TransactionRepository transactionRepository;
|
||||
|
||||
public TransactionResource(TransactionRepository transactionRepository) {
|
||||
this.transactionRepository = transactionRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code POST /transactions} : Create a new transaction.
|
||||
*
|
||||
* @param transaction the transaction to create.
|
||||
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new transaction, or with status {@code 400 (Bad Request)} if the transaction has already an ID.
|
||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||
*/
|
||||
@PostMapping("")
|
||||
public ResponseEntity<Transaction> createTransaction(@RequestBody Transaction transaction) throws URISyntaxException {
|
||||
LOG.debug("REST request to save Transaction : {}", transaction);
|
||||
if (transaction.getId() != null) {
|
||||
throw new BadRequestAlertException("A new transaction cannot already have an ID", ENTITY_NAME, "idexists");
|
||||
}
|
||||
transaction = transactionRepository.save(transaction);
|
||||
return ResponseEntity.created(new URI("/api/transactions/" + transaction.getId()))
|
||||
.headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, transaction.getId().toString()))
|
||||
.body(transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code PUT /transactions/:id} : Updates an existing transaction.
|
||||
*
|
||||
* @param id the id of the transaction to save.
|
||||
* @param transaction the transaction to update.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated transaction,
|
||||
* or with status {@code 400 (Bad Request)} if the transaction is not valid,
|
||||
* or with status {@code 500 (Internal Server Error)} if the transaction couldn't be updated.
|
||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Transaction> updateTransaction(
|
||||
@PathVariable(value = "id", required = false) final Long id,
|
||||
@RequestBody Transaction transaction
|
||||
) throws URISyntaxException {
|
||||
LOG.debug("REST request to update Transaction : {}, {}", id, transaction);
|
||||
if (transaction.getId() == null) {
|
||||
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
|
||||
}
|
||||
if (!Objects.equals(id, transaction.getId())) {
|
||||
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
|
||||
}
|
||||
|
||||
if (!transactionRepository.existsById(id)) {
|
||||
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
|
||||
}
|
||||
|
||||
transaction = transactionRepository.save(transaction);
|
||||
return ResponseEntity.ok()
|
||||
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, transaction.getId().toString()))
|
||||
.body(transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code PATCH /transactions/:id} : Partial updates given fields of an existing transaction, field will ignore if it is null
|
||||
*
|
||||
* @param id the id of the transaction to save.
|
||||
* @param transaction the transaction to update.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated transaction,
|
||||
* or with status {@code 400 (Bad Request)} if the transaction is not valid,
|
||||
* or with status {@code 404 (Not Found)} if the transaction is not found,
|
||||
* or with status {@code 500 (Internal Server Error)} if the transaction couldn't be updated.
|
||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||
*/
|
||||
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
|
||||
public ResponseEntity<Transaction> partialUpdateTransaction(
|
||||
@PathVariable(value = "id", required = false) final Long id,
|
||||
@RequestBody Transaction transaction
|
||||
) throws URISyntaxException {
|
||||
LOG.debug("REST request to partial update Transaction partially : {}, {}", id, transaction);
|
||||
if (transaction.getId() == null) {
|
||||
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
|
||||
}
|
||||
if (!Objects.equals(id, transaction.getId())) {
|
||||
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
|
||||
}
|
||||
|
||||
if (!transactionRepository.existsById(id)) {
|
||||
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
|
||||
}
|
||||
|
||||
Optional<Transaction> result = transactionRepository
|
||||
.findById(transaction.getId())
|
||||
.map(existingTransaction -> {
|
||||
if (transaction.getType() != null) {
|
||||
existingTransaction.setType(transaction.getType());
|
||||
}
|
||||
if (transaction.getDate() != null) {
|
||||
existingTransaction.setDate(transaction.getDate());
|
||||
}
|
||||
if (transaction.getComment() != null) {
|
||||
existingTransaction.setComment(transaction.getComment());
|
||||
}
|
||||
|
||||
return existingTransaction;
|
||||
})
|
||||
.map(transactionRepository::save);
|
||||
|
||||
return ResponseUtil.wrapOrNotFound(
|
||||
result,
|
||||
HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, transaction.getId().toString())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code GET /transactions} : get all the transactions.
|
||||
*
|
||||
* @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of transactions in body.
|
||||
*/
|
||||
@GetMapping("")
|
||||
public List<Transaction> getAllTransactions(
|
||||
@RequestParam(name = "eagerload", required = false, defaultValue = "true") boolean eagerload
|
||||
) {
|
||||
LOG.debug("REST request to get all Transactions");
|
||||
if (eagerload) {
|
||||
return transactionRepository.findAllWithEagerRelationships();
|
||||
} else {
|
||||
return transactionRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code GET /transactions/:id} : get the "id" transaction.
|
||||
*
|
||||
* @param id the id of the transaction to retrieve.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the transaction, or with status {@code 404 (Not Found)}.
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Transaction> getTransaction(@PathVariable("id") Long id) {
|
||||
LOG.debug("REST request to get Transaction : {}", id);
|
||||
Optional<Transaction> transaction = transactionRepository.findOneWithEagerRelationships(id);
|
||||
return ResponseUtil.wrapOrNotFound(transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code DELETE /transactions/:id} : delete the "id" transaction.
|
||||
*
|
||||
* @param id the id of the transaction to delete.
|
||||
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteTransaction(@PathVariable("id") Long id) {
|
||||
LOG.debug("REST request to delete Transaction : {}", id);
|
||||
transactionRepository.deleteById(id);
|
||||
return ResponseEntity.noContent()
|
||||
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, false, ENTITY_NAME, id.toString()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package com.sasiedzi.event.web.rest;
|
||||
|
||||
import com.sasiedzi.event.domain.UserAccount;
|
||||
import com.sasiedzi.event.repository.UserAccountRepository;
|
||||
import com.sasiedzi.event.web.rest.errors.BadRequestAlertException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import tech.jhipster.web.util.HeaderUtil;
|
||||
import tech.jhipster.web.util.ResponseUtil;
|
||||
|
||||
/**
|
||||
* REST controller for managing {@link com.sasiedzi.event.domain.UserAccount}.
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/user-accounts")
|
||||
@Transactional
|
||||
public class UserAccountResource {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UserAccountResource.class);
|
||||
|
||||
private static final String ENTITY_NAME = "userAccount";
|
||||
|
||||
@Value("${jhipster.clientApp.name}")
|
||||
private String applicationName;
|
||||
|
||||
private final UserAccountRepository userAccountRepository;
|
||||
|
||||
public UserAccountResource(UserAccountRepository userAccountRepository) {
|
||||
this.userAccountRepository = userAccountRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code POST /user-accounts} : Create a new userAccount.
|
||||
*
|
||||
* @param userAccount the userAccount to create.
|
||||
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new userAccount, or with status {@code 400 (Bad Request)} if the userAccount has already an ID.
|
||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||
*/
|
||||
@PostMapping("")
|
||||
public ResponseEntity<UserAccount> createUserAccount(@RequestBody UserAccount userAccount) throws URISyntaxException {
|
||||
LOG.debug("REST request to save UserAccount : {}", userAccount);
|
||||
if (userAccount.getId() != null) {
|
||||
throw new BadRequestAlertException("A new userAccount cannot already have an ID", ENTITY_NAME, "idexists");
|
||||
}
|
||||
userAccount = userAccountRepository.save(userAccount);
|
||||
return ResponseEntity.created(new URI("/api/user-accounts/" + userAccount.getId()))
|
||||
.headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, userAccount.getId().toString()))
|
||||
.body(userAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code PUT /user-accounts/:id} : Updates an existing userAccount.
|
||||
*
|
||||
* @param id the id of the userAccount to save.
|
||||
* @param userAccount the userAccount to update.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated userAccount,
|
||||
* or with status {@code 400 (Bad Request)} if the userAccount is not valid,
|
||||
* or with status {@code 500 (Internal Server Error)} if the userAccount couldn't be updated.
|
||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<UserAccount> updateUserAccount(
|
||||
@PathVariable(value = "id", required = false) final Long id,
|
||||
@RequestBody UserAccount userAccount
|
||||
) throws URISyntaxException {
|
||||
LOG.debug("REST request to update UserAccount : {}, {}", id, userAccount);
|
||||
if (userAccount.getId() == null) {
|
||||
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
|
||||
}
|
||||
if (!Objects.equals(id, userAccount.getId())) {
|
||||
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
|
||||
}
|
||||
|
||||
if (!userAccountRepository.existsById(id)) {
|
||||
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
|
||||
}
|
||||
|
||||
userAccount = userAccountRepository.save(userAccount);
|
||||
return ResponseEntity.ok()
|
||||
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, userAccount.getId().toString()))
|
||||
.body(userAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code PATCH /user-accounts/:id} : Partial updates given fields of an existing userAccount, field will ignore if it is null
|
||||
*
|
||||
* @param id the id of the userAccount to save.
|
||||
* @param userAccount the userAccount to update.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated userAccount,
|
||||
* or with status {@code 400 (Bad Request)} if the userAccount is not valid,
|
||||
* or with status {@code 404 (Not Found)} if the userAccount is not found,
|
||||
* or with status {@code 500 (Internal Server Error)} if the userAccount couldn't be updated.
|
||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||
*/
|
||||
@PatchMapping(value = "/{id}", consumes = { "application/json", "application/merge-patch+json" })
|
||||
public ResponseEntity<UserAccount> partialUpdateUserAccount(
|
||||
@PathVariable(value = "id", required = false) final Long id,
|
||||
@RequestBody UserAccount userAccount
|
||||
) throws URISyntaxException {
|
||||
LOG.debug("REST request to partial update UserAccount partially : {}, {}", id, userAccount);
|
||||
if (userAccount.getId() == null) {
|
||||
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
|
||||
}
|
||||
if (!Objects.equals(id, userAccount.getId())) {
|
||||
throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid");
|
||||
}
|
||||
|
||||
if (!userAccountRepository.existsById(id)) {
|
||||
throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound");
|
||||
}
|
||||
|
||||
Optional<UserAccount> result = userAccountRepository
|
||||
.findById(userAccount.getId())
|
||||
.map(existingUserAccount -> {
|
||||
if (userAccount.getName() != null) {
|
||||
existingUserAccount.setName(userAccount.getName());
|
||||
}
|
||||
|
||||
return existingUserAccount;
|
||||
})
|
||||
.map(userAccountRepository::save);
|
||||
|
||||
return ResponseUtil.wrapOrNotFound(
|
||||
result,
|
||||
HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, userAccount.getId().toString())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code GET /user-accounts} : get all the userAccounts.
|
||||
*
|
||||
* @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of userAccounts in body.
|
||||
*/
|
||||
@GetMapping("")
|
||||
public List<UserAccount> getAllUserAccounts(
|
||||
@RequestParam(name = "eagerload", required = false, defaultValue = "true") boolean eagerload
|
||||
) {
|
||||
LOG.debug("REST request to get all UserAccounts");
|
||||
if (eagerload) {
|
||||
return userAccountRepository.findAllWithEagerRelationships();
|
||||
} else {
|
||||
return userAccountRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code GET /user-accounts/:id} : get the "id" userAccount.
|
||||
*
|
||||
* @param id the id of the userAccount to retrieve.
|
||||
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the userAccount, or with status {@code 404 (Not Found)}.
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<UserAccount> getUserAccount(@PathVariable("id") Long id) {
|
||||
LOG.debug("REST request to get UserAccount : {}", id);
|
||||
Optional<UserAccount> userAccount = userAccountRepository.findOneWithEagerRelationships(id);
|
||||
return ResponseUtil.wrapOrNotFound(userAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code DELETE /user-accounts/:id} : delete the "id" userAccount.
|
||||
*
|
||||
* @param id the id of the userAccount to delete.
|
||||
* @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteUserAccount(@PathVariable("id") Long id) {
|
||||
LOG.debug("REST request to delete UserAccount : {}", id);
|
||||
userAccountRepository.deleteById(id);
|
||||
return ResponseEntity.noContent()
|
||||
.headers(HeaderUtil.createEntityDeletionAlert(applicationName, false, ENTITY_NAME, id.toString()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user