TransactionItem - backend only
This commit is contained in:
@@ -48,7 +48,7 @@ public class Event implements Serializable {
|
||||
private Set<Registration> registrations = new HashSet<>();
|
||||
|
||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "event")
|
||||
@JsonIgnoreProperties(value = { "event" }, allowSetters = true)
|
||||
@JsonIgnoreProperties(value = { "event", "transactionItem" }, allowSetters = true)
|
||||
private Set<Transaction> transactions = new HashSet<>();
|
||||
|
||||
// jhipster-needle-entity-add-field - JHipster will add fields here
|
||||
|
||||
@@ -36,6 +36,10 @@ public class Transaction implements Serializable {
|
||||
@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() {
|
||||
@@ -103,6 +107,19 @@ public class Transaction implements Serializable {
|
||||
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
|
||||
|
||||
@@ -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() + "'" +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sasiedzi.event.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
@@ -32,6 +33,10 @@ public class UserAccount implements Serializable {
|
||||
)
|
||||
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() {
|
||||
@@ -83,6 +88,37 @@ public class UserAccount implements Serializable {
|
||||
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
|
||||
|
||||
@@ -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,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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user