Dto fix
This commit is contained in:
parent
b908b68951
commit
13c1c40aa5
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -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<CreatorDto> getCreators() {
|
||||
public List<CreatorMangaDto> 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
|
||||
|
@ -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<MangaDto> getMangas() {
|
||||
public List<MangaReaderDto> 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}")
|
||||
|
@ -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<ReaderDto> getReaders() {
|
||||
public List<ReaderMangaDto> 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));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<MangaDto> mangas;
|
||||
|
||||
public CreatorDto(Creator creator) {
|
||||
public CreatorMangaDto(Creator creator) {
|
||||
this.id = creator.getId();
|
||||
this.creatorName = creator.getCreatorName();
|
||||
this.hashedPassword = creator.getHashedPassword();
|
@ -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<String> readers;
|
||||
private final List<ReaderDto> readers;
|
||||
|
||||
public MangaDto(Manga manga, List<Reader> listReader) {
|
||||
public MangaReaderDto(Manga manga, List<Reader> 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<String> getReaders() {
|
||||
public List<ReaderDto> getReaders() {
|
||||
return readers;
|
||||
}
|
||||
|
@ -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<String> mangas;
|
||||
private List<MangaDto> 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<String> getMangas() { return mangas; }
|
||||
public List<MangaDto> getMangas() { return mangas; }
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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; }
|
||||
}
|
Loading…
Reference in New Issue
Block a user