Add Transactional
This commit is contained in:
@@ -5,6 +5,7 @@ import de.htwsaar.webshop.repository.CustomerRepository;
|
||||
import de.htwsaar.webshop.repository.entities.Account;
|
||||
import de.htwsaar.webshop.service.AccountService;
|
||||
import de.htwsaar.webshop.service.PasswordService;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -29,11 +30,13 @@ public class AccountServiceImpl implements AccountService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Account save(Account account) {
|
||||
return accountRepository.save(account);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Account saveNew(Account account) {
|
||||
if (account.getCustomer() != null) {
|
||||
account.getCustomer().setId(null); // Ensure new customer
|
||||
@@ -44,6 +47,7 @@ public class AccountServiceImpl implements AccountService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteIfExists(Account account) {
|
||||
Account tbd = accountRepository.getAccountByEmail(account.getEmail());
|
||||
if (tbd == null) {
|
||||
@@ -54,6 +58,7 @@ public class AccountServiceImpl implements AccountService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean deleteIfExists(Long id) {
|
||||
Account tbd = accountRepository.getAccountById(id);
|
||||
if (tbd == null) {
|
||||
@@ -78,6 +83,7 @@ public class AccountServiceImpl implements AccountService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean setAdmin(Long id, boolean admin) {
|
||||
if (id == null) {
|
||||
return false;
|
||||
|
||||
@@ -52,11 +52,13 @@ public class ArticleServiceImpl implements ArticleService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(Long id) {
|
||||
articleRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(UUID uuid) {
|
||||
articleRepository.deleteByUuid(uuid);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.htwsaar.webshop.service.impl;
|
||||
import de.htwsaar.webshop.repository.CustomerRepository;
|
||||
import de.htwsaar.webshop.repository.entities.Customer;
|
||||
import de.htwsaar.webshop.service.CustomerService;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -18,11 +19,13 @@ public class CustomerServiceImpl implements CustomerService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Customer save(Customer customer) {
|
||||
return customerRepository.save(customer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(Customer customer) {
|
||||
customerRepository.delete(customer);
|
||||
}
|
||||
|
||||
@@ -12,9 +12,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -55,11 +53,13 @@ public class FarmImageServiceImpl implements FarmImageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public FarmImage save(FarmImageModel model) {
|
||||
return save(new FarmImage(model.getId(), articleService.findByUUID(model.getArticleUuid()), model.getBase64(), model.getStandard()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public FarmImage save(UUID uuid, String base64, boolean standard) {
|
||||
if (uuid == null) {
|
||||
log.warn("Got no UUID, aborting");
|
||||
|
||||
@@ -51,11 +51,13 @@ public class ImageServiceImpl implements ImageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Image save(ImageModel model) {
|
||||
return save(new Image(model.getId(), articleService.findByUUID(model.getArticleUuid()), model.getBase64()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Image save(UUID uuid, MultipartFile file) {
|
||||
if (uuid == null) {
|
||||
log.warn("Got no UUID, aborting");
|
||||
@@ -85,6 +87,7 @@ public class ImageServiceImpl implements ImageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Image save(UUID uuid, String base64) {
|
||||
if (uuid == null) {
|
||||
log.warn("Got no UUID, aborting");
|
||||
|
||||
@@ -13,6 +13,7 @@ import de.htwsaar.webshop.util.TimeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -41,11 +42,13 @@ public class OrderServiceImpl implements OrderService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Order saveNew(Order order) {
|
||||
return orderRepository.save(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Order saveNew(OrderModel model) {
|
||||
Order order = saveNew(new Order(
|
||||
model.getId(),
|
||||
@@ -75,6 +78,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(Long orderId) {
|
||||
orderRepository.deleteById(orderId);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import de.htwsaar.webshop.service.ReviewService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -25,12 +26,14 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Review save(Review review) {
|
||||
review.setTimestamp(System.currentTimeMillis());
|
||||
return reviewRepository.save(review);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Review save(UUID articleUuid, int rating, String content) {
|
||||
if (articleUuid == null) {
|
||||
return null;
|
||||
@@ -40,6 +43,7 @@ public class ReviewServiceImpl implements ReviewService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(Long reviewId) {
|
||||
reviewRepository.deleteById(reviewId);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import de.htwsaar.webshop.util.TimeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -26,6 +27,7 @@ public class SessionServiceImpl implements SessionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Session create(Account account) {
|
||||
long timeout = TimeUtil.nowPlusDays(7);
|
||||
UUID token = UUID.randomUUID();
|
||||
@@ -34,6 +36,7 @@ public class SessionServiceImpl implements SessionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(Session session) {
|
||||
sessionRepository.delete(session);
|
||||
}
|
||||
@@ -59,7 +62,6 @@ public class SessionServiceImpl implements SessionService {
|
||||
}
|
||||
if (session.getTimeout() <= System.currentTimeMillis()) {
|
||||
log.info("Session with email {} is expired", email);
|
||||
delete(session);
|
||||
return false;
|
||||
}
|
||||
log.info("Session with email {} is valid", email);
|
||||
@@ -94,6 +96,7 @@ public class SessionServiceImpl implements SessionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteExpired() {
|
||||
sessionRepository.deleteSessionsByTimeoutBefore(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user