transactional add
This commit is contained in:
@@ -2,6 +2,7 @@ package ru.ip.example.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ip.example.domain.AddSeazonDto;
|
||||
import ru.ip.example.domain.FilmDto;
|
||||
import ru.ip.example.domain.entity.FilmEntity;
|
||||
@@ -25,6 +26,7 @@ public class FilmServiceImpl implements FilmService {
|
||||
|
||||
private final SeazonRepository seazonRepository;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public FilmDto saveFilm(FilmDto dto) {
|
||||
FilmEntity entity = filmMapper.toEntity(dto);
|
||||
@@ -32,6 +34,7 @@ public class FilmServiceImpl implements FilmService {
|
||||
return filmMapper.toDto(savedFilm);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public FilmDto updateFilm(Integer id, FilmDto dto) {
|
||||
FilmEntity filmEntity = filmMapper.toEntity(dto);
|
||||
@@ -40,6 +43,7 @@ public class FilmServiceImpl implements FilmService {
|
||||
return filmMapper.toDto(updatedEntity);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public List<FilmDto> findAllFilms() {
|
||||
Iterable<FilmEntity> filmEntities = filmRepository.findAll();
|
||||
@@ -51,17 +55,20 @@ public class FilmServiceImpl implements FilmService {
|
||||
return films;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public FilmDto findFilmById(Integer id) {
|
||||
FilmEntity film = filmRepository.findById(id).orElseThrow();
|
||||
return filmMapper.toDto(film);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void deleteById(Integer id) {
|
||||
filmRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public FilmDto addSeazon(AddSeazonDto addSeazonDto) {
|
||||
var film = filmRepository.findById(addSeazonDto.getFilmId());
|
||||
|
||||
@@ -2,6 +2,7 @@ package ru.ip.example.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ip.example.domain.AddSeriesDto;
|
||||
import ru.ip.example.domain.SeazonDto;
|
||||
import ru.ip.example.domain.entity.SeazonEntity;
|
||||
@@ -25,6 +26,7 @@ public class SeazonServiceImpl implements SeazonService {
|
||||
|
||||
private final SeriesRepository seriesRepository;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public List<SeazonDto> findAll() {
|
||||
Iterable<SeazonEntity> seazons = seazonRepository.findAll();
|
||||
@@ -35,12 +37,14 @@ public class SeazonServiceImpl implements SeazonService {
|
||||
return seazonDtos;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public SeazonDto findById(Integer id) {
|
||||
SeazonEntity seazon = seazonRepository.findById(id).orElseThrow();
|
||||
return seazonMapper.toDto(seazon);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public SeazonDto save(SeazonDto dto) {
|
||||
SeazonEntity entity = seazonMapper.toEntity(dto);
|
||||
@@ -48,6 +52,7 @@ public class SeazonServiceImpl implements SeazonService {
|
||||
return seazonMapper.toDto(savedEntity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public SeazonDto update(Integer id, SeazonDto dto) {
|
||||
SeazonEntity entity = seazonMapper.toEntity(dto);
|
||||
@@ -56,12 +61,14 @@ public class SeazonServiceImpl implements SeazonService {
|
||||
return seazonMapper.toDto(savedEntity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void delete(Integer id) {
|
||||
Optional<SeazonEntity> seazon = seazonRepository.findById(id);
|
||||
seazon.ifPresent(seazonRepository::delete);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public SeazonDto addSeries(AddSeriesDto dto) {
|
||||
var series = seriesRepository.findById(dto.getSeriesId());
|
||||
|
||||
@@ -2,6 +2,7 @@ package ru.ip.example.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ip.example.domain.SeazonDto;
|
||||
import ru.ip.example.domain.SeriesDto;
|
||||
import ru.ip.example.domain.entity.SeazonEntity;
|
||||
@@ -21,6 +22,7 @@ public class SeriesServiceImpl implements SeriesService {
|
||||
|
||||
private final SeriesRepository seriesRepository;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public List<SeriesDto> findAll() {
|
||||
Iterable<SeriesEntity> series = seriesRepository.findAll();
|
||||
@@ -31,12 +33,14 @@ public class SeriesServiceImpl implements SeriesService {
|
||||
return seriesDtos;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public SeriesDto findById(Integer id) {
|
||||
SeriesEntity series = seriesRepository.findById(id).orElseThrow();
|
||||
return seriesMapper.toDto(series);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public SeriesDto save(SeriesDto dto) {
|
||||
SeriesEntity entity = seriesMapper.toEntity(dto);
|
||||
@@ -44,6 +48,7 @@ public class SeriesServiceImpl implements SeriesService {
|
||||
return seriesMapper.toDto(savedEntity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public SeriesDto update(Integer id, SeriesDto dto) {
|
||||
SeriesEntity entity = seriesMapper.toEntity(dto);
|
||||
@@ -52,6 +57,7 @@ public class SeriesServiceImpl implements SeriesService {
|
||||
return seriesMapper.toDto(savedEntity);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void delete(Integer id) {
|
||||
seriesRepository.findById(id)
|
||||
|
||||
@@ -2,6 +2,7 @@ package ru.ip.example.service.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ip.example.domain.SubscribeDto;
|
||||
import ru.ip.example.domain.entity.SubscribeEntity;
|
||||
import ru.ip.example.mapper.SubscribeMapper;
|
||||
@@ -19,6 +20,7 @@ public class SubscribeServiceImpl implements SubscribeService {
|
||||
|
||||
private final SubscribeMapper subscribeMapper;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public SubscribeDto saveSubscribe(SubscribeDto dto) {
|
||||
SubscribeEntity entity = subscribeMapper.toEntity(dto);
|
||||
@@ -26,6 +28,7 @@ public class SubscribeServiceImpl implements SubscribeService {
|
||||
return subscribeMapper.toDto(savedSubscribe);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public SubscribeDto updateSubscribe(Integer id, SubscribeDto dto) {
|
||||
SubscribeEntity subscribeEntity = subscribeMapper.toEntity(dto);
|
||||
@@ -34,6 +37,7 @@ public class SubscribeServiceImpl implements SubscribeService {
|
||||
return subscribeMapper.toDto(updatedEntity);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public List<SubscribeDto> findAllSubscribes() {
|
||||
Iterable<SubscribeEntity> subscribeEntities = subscribeRepository.findAll();
|
||||
@@ -45,12 +49,14 @@ public class SubscribeServiceImpl implements SubscribeService {
|
||||
return subscribes;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Override
|
||||
public SubscribeDto findSubscribeById(Integer id) {
|
||||
SubscribeEntity subscribe = subscribeRepository.findById(id).orElseThrow();
|
||||
return subscribeMapper.toDto(subscribe);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void deleteById(Integer id) {
|
||||
subscribeRepository.deleteById(id);
|
||||
|
||||
Reference in New Issue
Block a user