Skip to content

Added transactional annotations to the service classes. #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.HashSet;
Expand All @@ -34,6 +35,7 @@

@Service
@RequiredArgsConstructor
@Transactional
public class AuthenticationServiceImpl implements AuthenticationService {

private static final Log LOG = LogFactory.getLog(AuthenticationServiceImpl.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

Expand All @@ -29,6 +30,7 @@
import static com.projects.aeroplannerrestapi.constants.SecurityRoleConstants.HEADER;

@Service
@Transactional
@RequiredArgsConstructor
public class EmailServiceImpl implements EmailService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class FlightServiceImpl implements FlightService {

private static final Log LOG = LogFactory.getLog(FlightServiceImpl.class);

private final FlightRepository flightRepository;

@Override
@Transactional
public FlightResponse createFlight(FlightRequest flightRequest) {
Flight flight = FlightMapper.INSTANCE.flightRequestToFlight(flightRequest);
flight.setCurrentAvailableSeat(flightRequest.getSeatAvailability());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;
Expand All @@ -25,6 +26,7 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class PassengerServiceImpl implements PassengerService {

private static final Log LOG = LogFactory.getLog(PassengerServiceImpl.class);
Expand Down Expand Up @@ -60,6 +62,7 @@ public UserResponse getPassenger(Long id) {
}

@Override
@Transactional
public void deletePassenger(Long id) {
if (!userRepository.existsByIdAndRoles_Name(id, RoleEnum.USER)) {
throw new ResourceNotFoundException(PASSENGER, ID, id.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class PaymentServiceImpl implements PaymentService {

private static final Log LOG = LogFactory.getLog(PaymentServiceImpl.class);
Expand Down Expand Up @@ -67,7 +68,6 @@ public PaymentResponse processPayment(PaymentRequest paymentRequest) {
}

@Override
@Transactional(readOnly = true)
public Payment getPaymentDetails(Long id) {
return paymentRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(PAYMENT, ID, id.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ReservationServiceImpl implements ReservationService {

private static final Log LOG = LogFactory.getLog(ReservationServiceImpl.class);
Expand All @@ -36,6 +37,7 @@ public class ReservationServiceImpl implements ReservationService {
private final FlightRepository flightRepository;

@Override
@Transactional
public ReservationResponse createReservation(ReservationRequest reservationRequest) {
Reservation reservation = ReservationMapper.INSTANCE.reservationRequestToReservation(reservationRequest);
Long flightId = reservationRequest.getFlightId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class SuperAdminServiceImpl implements SuperAdminService {

private static final Log LOG = LogFactory.getLog(SuperAdminServiceImpl.class);
Expand All @@ -36,6 +37,7 @@ public class SuperAdminServiceImpl implements SuperAdminService {
private final PasswordEncoder passwordEncoder;

@Override
@Transactional
public UserResponse createAdministrator(RegisterRequest registerRequest) {
String email = registerRequest.getEmail();
Optional<Role> role = roleRepository.findByName(RoleEnum.ADMIN);
Expand All @@ -54,14 +56,14 @@ public UserResponse createAdministrator(RegisterRequest registerRequest) {
}

@Override
@Transactional(readOnly = true)
public UserResponse getAdministrator(Long id) {
User user = findByIdAndRole(id);
LOG.debug(String.format("Administrator %d : %s", id, user.getEmail()));
return UserMapper.INSTANCE.userToUserResponse(user);
}

@Override
@Transactional
public UserResponse updateAdministrator(Long id, RegisterRequest registerRequest) {
User user = findByIdAndRole(id);
user.setUpdatedAt(LocalDateTime.now());
Expand All @@ -74,6 +76,7 @@ public UserResponse updateAdministrator(Long id, RegisterRequest registerRequest
}

@Override
@Transactional
public void deleteAdministrator(Long id) {
User user = findByIdAndRole(id);
userRepository.delete(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -23,6 +24,7 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class TicketServiceImpl implements TicketService {

private static final Log LOG = LogFactory.getLog(TicketServiceImpl.class);
Expand All @@ -31,6 +33,7 @@ public class TicketServiceImpl implements TicketService {
private final ReservationRepository reservationRepository;

@Override
@Transactional
public TicketResponse createTicket(TicketRequest ticketRequest) {
Long reservationId = ticketRequest.getReservationId();
Reservation reservation = reservationRepository.findById(reservationId)
Expand Down Expand Up @@ -61,6 +64,7 @@ public TicketResponse getTicket(Long id) {
}

@Override
@Transactional
public void cancelTicket(Long id) {
Ticket ticket = ticketRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException(TICKET, ID, id.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class UserServiceImpl implements UserService {

private static final Log LOG = LogFactory.getLog(UserServiceImpl.class);

private final UserRepository userRepository;

@Override
@Transactional(readOnly = true)
public UserResponse getAuthenticatedUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String email = authentication.getName();
Expand All @@ -43,7 +43,6 @@ public UserResponse getAuthenticatedUser() {
}

@Override
@Transactional(readOnly = true)
public PaginatedAndSortedUserResponse getAllUsers(int pageNumber, int pageSize, String sortBy, String sortDirection) {
Sort sort = sortDirection.equalsIgnoreCase(Sort.Direction.ASC.name()) ? Sort.by(sortBy).ascending() :
Sort.by(sortBy).descending();
Expand Down
Loading