теперь точно работает

This commit is contained in:
Николай 2023-04-10 20:04:29 +04:00
parent 1117bed0cd
commit 5e9c107b87
2 changed files with 11 additions and 6 deletions

View File

@ -18,7 +18,7 @@ public class Reader {
@Column
private String hashedPassword;
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
@ManyToMany(fetch = FetchType.EAGER)
private List<Manga> mangas;
public Reader() {

View File

@ -20,16 +20,16 @@ import java.util.Optional;
@Service
public class MangaService {
public final MangaRepository mangaRepository;
public final CreatorService creatorService;
public final CreatorRepository creatorRepository;
public final ReaderService readerService;
public final ReaderRepository readerRepository;
private final ValidatorUtil validatorUtil;
public MangaService(MangaRepository mangaRepository, CreatorService creatorService , ReaderService readerService, ReaderRepository readerRepository,
public MangaService(MangaRepository mangaRepository, CreatorRepository creatorRepository, ReaderService readerService, ReaderRepository readerRepository,
ValidatorUtil validatorUtil) {
this.mangaRepository = mangaRepository;
this.readerService = readerService;
this.creatorService = creatorService;
this.creatorRepository = creatorRepository;
this.readerRepository = readerRepository;
this.validatorUtil = validatorUtil;
}
@ -52,10 +52,15 @@ public class MangaService {
return mangaRepository.findAll();
}
@Transactional(readOnly = true)
public Creator findCreator(Long id) {
final Optional<Creator> creator = creatorRepository.findById(id);
return creator.orElseThrow(() -> new CreatorNotFoundException(id));
}
@Transactional
public Manga addManga(Long creatorId, Integer chapterCount, String mangaName) {
final Creator currentCreator = creatorService.findCreator(creatorId);
final Creator currentCreator = findCreator(creatorId);
final Manga manga = new Manga(currentCreator, mangaName, chapterCount);
validatorUtil.validate(manga);
return mangaRepository.save(manga);
@ -63,7 +68,7 @@ public class MangaService {
@Transactional
public Manga addManga(MangaDto mangaDto) {
final Creator currentCreator = creatorService.findCreator(mangaDto.getCreatorId());
final Creator currentCreator = findCreator(mangaDto.getCreatorId());
final Manga manga = new Manga(currentCreator, mangaDto);
validatorUtil.validate(manga);
return mangaRepository.save(manga);