diff --git a/data.mv.db b/data.mv.db index c494343..b203c2e 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/src/main/java/com/LabWork/app/MangaStore/controller/CreatorController.java b/src/main/java/com/LabWork/app/MangaStore/controller/CreatorController.java index 2f6ed4b..5b99465 100644 --- a/src/main/java/com/LabWork/app/MangaStore/controller/CreatorController.java +++ b/src/main/java/com/LabWork/app/MangaStore/controller/CreatorController.java @@ -1,6 +1,6 @@ package com.LabWork.app.MangaStore.controller; -import com.LabWork.app.MangaStore.model.Dto.CreatorDto; +import com.LabWork.app.MangaStore.model.Dto.CreatorMangaDto; import com.LabWork.app.MangaStore.service.CreatorService; import org.springframework.web.bind.annotation.*; @@ -16,34 +16,34 @@ public class CreatorController { } @GetMapping("/{id}") - public CreatorDto getCreator(@PathVariable Long id) { - return new CreatorDto(creatorService.findCreator(id)); + public CreatorMangaDto getCreator(@PathVariable Long id) { + return new CreatorMangaDto(creatorService.findCreator(id)); } @GetMapping - public List getCreators() { + public List getCreators() { return creatorService.findAllCreators().stream() - .map(CreatorDto::new) + .map(CreatorMangaDto::new) .toList(); } @PostMapping - public CreatorDto createCreator(@RequestParam("creatorName") String creatorName, - @RequestParam("password") String password) { - return new CreatorDto(creatorService.addCreator(creatorName, password)); + public CreatorMangaDto createCreator(@RequestParam("creatorName") String creatorName, + @RequestParam("password") String password) { + return new CreatorMangaDto(creatorService.addCreator(creatorName, password)); } @PutMapping("/{id}") - public CreatorDto updateCreator(@PathVariable Long id, - @RequestParam("creatorName") String creatorName, - @RequestParam("password") String password) { - return new CreatorDto(creatorService.updateCreator(id, creatorName, password)); + public CreatorMangaDto updateCreator(@PathVariable Long id, + @RequestParam("creatorName") String creatorName, + @RequestParam("password") String password) { + return new CreatorMangaDto(creatorService.updateCreator(id, creatorName, password)); } @DeleteMapping("/{id}") - public CreatorDto deleteCreator(@PathVariable Long id) { + public CreatorMangaDto deleteCreator(@PathVariable Long id) { //creatorService.deleteAllCreators(); - return new CreatorDto(creatorService.deleteCreator(id)); + return new CreatorMangaDto(creatorService.deleteCreator(id)); } @DeleteMapping diff --git a/src/main/java/com/LabWork/app/MangaStore/controller/MangaController.java b/src/main/java/com/LabWork/app/MangaStore/controller/MangaController.java index 1f909b5..4f6aa9c 100644 --- a/src/main/java/com/LabWork/app/MangaStore/controller/MangaController.java +++ b/src/main/java/com/LabWork/app/MangaStore/controller/MangaController.java @@ -1,8 +1,8 @@ package com.LabWork.app.MangaStore.controller; -import com.LabWork.app.MangaStore.model.Default.Creator; -import com.LabWork.app.MangaStore.model.Dto.MangaDto; +import com.LabWork.app.MangaStore.model.Dto.MangaReaderDto; +import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto; import com.LabWork.app.MangaStore.service.MangaService; import org.springframework.web.bind.annotation.*; @@ -18,28 +18,28 @@ public class MangaController { } @GetMapping("/{id}") - public MangaDto getManga(@PathVariable Long id) { - return new MangaDto(mangaService.findManga(id), mangaService.getReader(id)); + public MangaReaderDto getManga(@PathVariable Long id) { + return new MangaReaderDto(mangaService.findManga(id), mangaService.getReader(id)); } @GetMapping - public List getMangas() { + public List getMangas() { return mangaService.findAllMangas().stream() - .map(x -> new MangaDto(x, mangaService.getReader(x.getId()))) + .map(x -> new MangaReaderDto(x, mangaService.getReader(x.getId()))) .toList(); } @PostMapping - public MangaDto createManga(@RequestParam("creatorId") Long creatorId, - @RequestParam("chapterCount") Integer chapterCount, - @RequestParam("mangaName") String mangaName) { - return new MangaDto(mangaService.addManga(creatorId, chapterCount, mangaName), mangaService.getReader(creatorId)); + public MangaReaderDto createManga(@RequestParam("creatorId") Long creatorId, + @RequestParam("chapterCount") Integer chapterCount, + @RequestParam("mangaName") String mangaName) { + return new MangaReaderDto(mangaService.addManga(creatorId, chapterCount, mangaName), mangaService.getReader(creatorId)); } @PutMapping("/{id}") - public MangaDto updateManga(@PathVariable Long id, - @RequestParam("chapterCount") Integer chapterCount) { - return new MangaDto(mangaService.updateManga(id, chapterCount), mangaService.getReader(id)); + public MangaReaderDto updateManga(@PathVariable Long id, + @RequestParam("chapterCount") Integer chapterCount) { + return new MangaReaderDto(mangaService.updateManga(id, chapterCount), mangaService.getReader(id)); } @DeleteMapping("/{id}") diff --git a/src/main/java/com/LabWork/app/MangaStore/controller/ReaderController.java b/src/main/java/com/LabWork/app/MangaStore/controller/ReaderController.java index 5b7a76f..e9b44d9 100644 --- a/src/main/java/com/LabWork/app/MangaStore/controller/ReaderController.java +++ b/src/main/java/com/LabWork/app/MangaStore/controller/ReaderController.java @@ -1,7 +1,7 @@ package com.LabWork.app.MangaStore.controller; -import com.LabWork.app.MangaStore.model.Dto.ReaderDto; +import com.LabWork.app.MangaStore.model.Dto.ReaderMangaDto; import com.LabWork.app.MangaStore.service.ReaderService; import org.springframework.web.bind.annotation.*; @@ -17,44 +17,44 @@ public class ReaderController { } @GetMapping("/{id}") - public ReaderDto getReader(@PathVariable Long id) { - return new ReaderDto(readerService.findReader(id)); + public ReaderMangaDto getReader(@PathVariable Long id) { + return new ReaderMangaDto(readerService.findReader(id)); } @GetMapping - public List getReaders() { + public List getReaders() { return readerService.findAllReaders().stream() - .map(ReaderDto::new) + .map(ReaderMangaDto::new) .toList(); } @PostMapping - public ReaderDto createReader(@RequestParam("readerName") String readerName, - @RequestParam("password") String password) { - return new ReaderDto(readerService.addReader(readerName, password)); + public ReaderMangaDto createReader(@RequestParam("readerName") String readerName, + @RequestParam("password") String password) { + return new ReaderMangaDto(readerService.addReader(readerName, password)); } @PutMapping("/{id}") - public ReaderDto updateReader(@PathVariable Long id, - @RequestParam("readerName") String readerName, - @RequestParam("password") String password) { - return new ReaderDto(readerService.updateReader(id, readerName, password)); + public ReaderMangaDto updateReader(@PathVariable Long id, + @RequestParam("readerName") String readerName, + @RequestParam("password") String password) { + return new ReaderMangaDto(readerService.updateReader(id, readerName, password)); } @PutMapping("/{id}/addManga") - public ReaderDto addManga(@PathVariable Long id, - @RequestParam("mangaId") Long mangaId) { - return new ReaderDto(readerService.addManga(mangaId, id)); + public ReaderMangaDto addManga(@PathVariable Long id, + @RequestParam("mangaId") Long mangaId) { + return new ReaderMangaDto(readerService.addManga(mangaId, id)); } @PutMapping("/{id}/removeManga") - public ReaderDto removeManga(@PathVariable Long id, - @RequestParam("mangaId") Long mangaId) { - return new ReaderDto(readerService.removeManga(mangaId, id)); + public ReaderMangaDto removeManga(@PathVariable Long id, + @RequestParam("mangaId") Long mangaId) { + return new ReaderMangaDto(readerService.removeManga(mangaId, id)); } @DeleteMapping("/{id}") - public ReaderDto deleteReader(@PathVariable Long id) { - return new ReaderDto(readerService.deleteReader(id)); + public ReaderMangaDto deleteReader(@PathVariable Long id) { + return new ReaderMangaDto(readerService.deleteReader(id)); } } diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Default/Manga.java b/src/main/java/com/LabWork/app/MangaStore/model/Default/Manga.java index 6d06411..8900735 100644 --- a/src/main/java/com/LabWork/app/MangaStore/model/Default/Manga.java +++ b/src/main/java/com/LabWork/app/MangaStore/model/Default/Manga.java @@ -1,5 +1,7 @@ package com.LabWork.app.MangaStore.model.Default; +import com.LabWork.app.MangaStore.service.CreatorService; +import com.LabWork.app.MangaStore.service.MangaService; import jakarta.persistence.*; import java.util.ArrayList; diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Dto/CreatorDto.java b/src/main/java/com/LabWork/app/MangaStore/model/Dto/CreatorMangaDto.java similarity index 84% rename from src/main/java/com/LabWork/app/MangaStore/model/Dto/CreatorDto.java rename to src/main/java/com/LabWork/app/MangaStore/model/Dto/CreatorMangaDto.java index c311f4b..4c8bf5a 100644 --- a/src/main/java/com/LabWork/app/MangaStore/model/Dto/CreatorDto.java +++ b/src/main/java/com/LabWork/app/MangaStore/model/Dto/CreatorMangaDto.java @@ -1,17 +1,17 @@ package com.LabWork.app.MangaStore.model.Dto; import com.LabWork.app.MangaStore.model.Default.Creator; -import com.LabWork.app.MangaStore.model.Default.Manga; -import java.util.List; -import java.util.Objects; +import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto; -public class CreatorDto { +import java.util.List; + +public class CreatorMangaDto { private final long id; private final String creatorName; private final String hashedPassword; private final List mangas; - public CreatorDto(Creator creator) { + public CreatorMangaDto(Creator creator) { this.id = creator.getId(); this.creatorName = creator.getCreatorName(); this.hashedPassword = creator.getHashedPassword(); diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Dto/MangaDto.java b/src/main/java/com/LabWork/app/MangaStore/model/Dto/MangaReaderDto.java similarity index 61% rename from src/main/java/com/LabWork/app/MangaStore/model/Dto/MangaDto.java rename to src/main/java/com/LabWork/app/MangaStore/model/Dto/MangaReaderDto.java index 27369fc..0f3ba4b 100644 --- a/src/main/java/com/LabWork/app/MangaStore/model/Dto/MangaDto.java +++ b/src/main/java/com/LabWork/app/MangaStore/model/Dto/MangaReaderDto.java @@ -3,39 +3,29 @@ package com.LabWork.app.MangaStore.model.Dto; import com.LabWork.app.MangaStore.model.Default.Creator; import com.LabWork.app.MangaStore.model.Default.Manga; import com.LabWork.app.MangaStore.model.Default.Reader; -import com.LabWork.app.MangaStore.service.MangaService; +import com.LabWork.app.MangaStore.model.Dto.SupportDto.ReaderDto; -import java.util.ArrayList; import java.util.List; -import java.util.Objects; -public class MangaDto { +public class MangaReaderDto { private final Long id; private final Long creatorId; private final String mangaName; private final Integer chapterCount; - private final List readers; + private final List readers; - public MangaDto(Manga manga, List listReader) { + public MangaReaderDto(Manga manga, List listReader) { this.id = manga.getId(); this.creatorId = manga.getCreator().getId(); this.mangaName = manga.getMangaName(); this.chapterCount = manga.getChapterCount(); this.readers = listReader.stream() - .map(y -> new String(y.getReaderName())) + .map(y -> new ReaderDto(y)) .toList(); } - public MangaDto(Manga manga) { - this.id = manga.getId(); - this.creatorId = manga.getCreator().getId(); - this.mangaName = manga.getMangaName(); - this.chapterCount = manga.getChapterCount(); - this.readers = null; - } - public Long getId() { return id; } @@ -44,7 +34,7 @@ public class MangaDto { return mangaName; } - public List getReaders() { + public List getReaders() { return readers; } diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Dto/ReaderDto.java b/src/main/java/com/LabWork/app/MangaStore/model/Dto/ReaderMangaDto.java similarity index 68% rename from src/main/java/com/LabWork/app/MangaStore/model/Dto/ReaderDto.java rename to src/main/java/com/LabWork/app/MangaStore/model/Dto/ReaderMangaDto.java index a343a50..f1adc6c 100644 --- a/src/main/java/com/LabWork/app/MangaStore/model/Dto/ReaderDto.java +++ b/src/main/java/com/LabWork/app/MangaStore/model/Dto/ReaderMangaDto.java @@ -1,25 +1,25 @@ package com.LabWork.app.MangaStore.model.Dto; -import com.LabWork.app.MangaStore.model.Default.Manga; import com.LabWork.app.MangaStore.model.Default.Reader; -import java.util.List; -import java.util.Objects; +import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto; -public class ReaderDto { +import java.util.List; + +public class ReaderMangaDto { private Long id; private String readerName; private String hashedPassword; - private List mangas; + private List mangas; - public ReaderDto(Reader reader) { + public ReaderMangaDto(Reader reader) { this.id = reader.getId(); this.readerName = reader.getReaderName(); this.hashedPassword = reader.getHashedPassword(); this.mangas = reader.getMangas().stream() - .map(y -> new String(y.getMangaName())) + .map(y -> new MangaDto(y)) .toList(); } @@ -31,6 +31,6 @@ public class ReaderDto { public String getHashedPassword() { return hashedPassword; } - public List getMangas() { return mangas; } + public List getMangas() { return mangas; } } diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Dto/SupportDto/MangaDto.java b/src/main/java/com/LabWork/app/MangaStore/model/Dto/SupportDto/MangaDto.java new file mode 100644 index 0000000..5ed9887 --- /dev/null +++ b/src/main/java/com/LabWork/app/MangaStore/model/Dto/SupportDto/MangaDto.java @@ -0,0 +1,38 @@ +package com.LabWork.app.MangaStore.model.Dto.SupportDto; + +import com.LabWork.app.MangaStore.model.Default.Manga; +import com.LabWork.app.MangaStore.model.Default.Reader; + +import java.util.List; + +public class MangaDto { + private final Long id; + + private final Long creatorId; + private final String mangaName; + private final Integer chapterCount; + + public MangaDto(Manga manga) { + this.id = manga.getId(); + this.creatorId = manga.getCreator().getId(); + this.mangaName = manga.getMangaName(); + this.chapterCount = manga.getChapterCount(); + } + + public Long getId() { + return id; + } + + public String getMangaName() { + return mangaName; + } + + public Integer getChapterCount() { + return chapterCount; + } + + public Long getCreatorId() { + return creatorId; + } + +} diff --git a/src/main/java/com/LabWork/app/MangaStore/model/Dto/SupportDto/ReaderDto.java b/src/main/java/com/LabWork/app/MangaStore/model/Dto/SupportDto/ReaderDto.java new file mode 100644 index 0000000..1e9539e --- /dev/null +++ b/src/main/java/com/LabWork/app/MangaStore/model/Dto/SupportDto/ReaderDto.java @@ -0,0 +1,27 @@ +package com.LabWork.app.MangaStore.model.Dto.SupportDto; + +import com.LabWork.app.MangaStore.model.Default.Reader; + +import java.util.List; + +public class ReaderDto { + private Long id; + + private String readerName; + + private String hashedPassword; + + public ReaderDto(Reader reader) { + this.id = reader.getId(); + this.readerName = reader.getReaderName(); + this.hashedPassword = reader.getHashedPassword(); + } + + public Long getId() { + return id; + } + + public String getReaderName() { return readerName; } + + public String getHashedPassword() { return hashedPassword; } +}