теперь точно работает
This commit is contained in:
parent
1117bed0cd
commit
5e9c107b87
@ -18,7 +18,7 @@ public class Reader {
|
|||||||
@Column
|
@Column
|
||||||
private String hashedPassword;
|
private String hashedPassword;
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
|
@ManyToMany(fetch = FetchType.EAGER)
|
||||||
private List<Manga> mangas;
|
private List<Manga> mangas;
|
||||||
|
|
||||||
public Reader() {
|
public Reader() {
|
||||||
|
@ -20,16 +20,16 @@ import java.util.Optional;
|
|||||||
@Service
|
@Service
|
||||||
public class MangaService {
|
public class MangaService {
|
||||||
public final MangaRepository mangaRepository;
|
public final MangaRepository mangaRepository;
|
||||||
public final CreatorService creatorService;
|
public final CreatorRepository creatorRepository;
|
||||||
public final ReaderService readerService;
|
public final ReaderService readerService;
|
||||||
public final ReaderRepository readerRepository;
|
public final ReaderRepository readerRepository;
|
||||||
private final ValidatorUtil validatorUtil;
|
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) {
|
ValidatorUtil validatorUtil) {
|
||||||
this.mangaRepository = mangaRepository;
|
this.mangaRepository = mangaRepository;
|
||||||
this.readerService = readerService;
|
this.readerService = readerService;
|
||||||
this.creatorService = creatorService;
|
this.creatorRepository = creatorRepository;
|
||||||
this.readerRepository = readerRepository;
|
this.readerRepository = readerRepository;
|
||||||
this.validatorUtil = validatorUtil;
|
this.validatorUtil = validatorUtil;
|
||||||
}
|
}
|
||||||
@ -52,10 +52,15 @@ public class MangaService {
|
|||||||
return mangaRepository.findAll();
|
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
|
@Transactional
|
||||||
public Manga addManga(Long creatorId, Integer chapterCount, String mangaName) {
|
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);
|
final Manga manga = new Manga(currentCreator, mangaName, chapterCount);
|
||||||
validatorUtil.validate(manga);
|
validatorUtil.validate(manga);
|
||||||
return mangaRepository.save(manga);
|
return mangaRepository.save(manga);
|
||||||
@ -63,7 +68,7 @@ public class MangaService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Manga addManga(MangaDto mangaDto) {
|
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);
|
final Manga manga = new Manga(currentCreator, mangaDto);
|
||||||
validatorUtil.validate(manga);
|
validatorUtil.validate(manga);
|
||||||
return mangaRepository.save(manga);
|
return mangaRepository.save(manga);
|
||||||
|
Loading…
Reference in New Issue
Block a user