This commit is contained in:
Николай 2023-04-07 19:39:29 +04:00
parent b908b68951
commit 13c1c40aa5
10 changed files with 133 additions and 76 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
package com.LabWork.app.MangaStore.controller; 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 com.LabWork.app.MangaStore.service.CreatorService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -16,34 +16,34 @@ public class CreatorController {
} }
@GetMapping("/{id}") @GetMapping("/{id}")
public CreatorDto getCreator(@PathVariable Long id) { public CreatorMangaDto getCreator(@PathVariable Long id) {
return new CreatorDto(creatorService.findCreator(id)); return new CreatorMangaDto(creatorService.findCreator(id));
} }
@GetMapping @GetMapping
public List<CreatorDto> getCreators() { public List<CreatorMangaDto> getCreators() {
return creatorService.findAllCreators().stream() return creatorService.findAllCreators().stream()
.map(CreatorDto::new) .map(CreatorMangaDto::new)
.toList(); .toList();
} }
@PostMapping @PostMapping
public CreatorDto createCreator(@RequestParam("creatorName") String creatorName, public CreatorMangaDto createCreator(@RequestParam("creatorName") String creatorName,
@RequestParam("password") String password) { @RequestParam("password") String password) {
return new CreatorDto(creatorService.addCreator(creatorName, password)); return new CreatorMangaDto(creatorService.addCreator(creatorName, password));
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public CreatorDto updateCreator(@PathVariable Long id, public CreatorMangaDto updateCreator(@PathVariable Long id,
@RequestParam("creatorName") String creatorName, @RequestParam("creatorName") String creatorName,
@RequestParam("password") String password) { @RequestParam("password") String password) {
return new CreatorDto(creatorService.updateCreator(id, creatorName, password)); return new CreatorMangaDto(creatorService.updateCreator(id, creatorName, password));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public CreatorDto deleteCreator(@PathVariable Long id) { public CreatorMangaDto deleteCreator(@PathVariable Long id) {
//creatorService.deleteAllCreators(); //creatorService.deleteAllCreators();
return new CreatorDto(creatorService.deleteCreator(id)); return new CreatorMangaDto(creatorService.deleteCreator(id));
} }
@DeleteMapping @DeleteMapping

View File

@ -1,8 +1,8 @@
package com.LabWork.app.MangaStore.controller; package com.LabWork.app.MangaStore.controller;
import com.LabWork.app.MangaStore.model.Default.Creator; import com.LabWork.app.MangaStore.model.Dto.MangaReaderDto;
import com.LabWork.app.MangaStore.model.Dto.MangaDto; import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
import com.LabWork.app.MangaStore.service.MangaService; import com.LabWork.app.MangaStore.service.MangaService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -18,28 +18,28 @@ public class MangaController {
} }
@GetMapping("/{id}") @GetMapping("/{id}")
public MangaDto getManga(@PathVariable Long id) { public MangaReaderDto getManga(@PathVariable Long id) {
return new MangaDto(mangaService.findManga(id), mangaService.getReader(id)); return new MangaReaderDto(mangaService.findManga(id), mangaService.getReader(id));
} }
@GetMapping @GetMapping
public List<MangaDto> getMangas() { public List<MangaReaderDto> getMangas() {
return mangaService.findAllMangas().stream() return mangaService.findAllMangas().stream()
.map(x -> new MangaDto(x, mangaService.getReader(x.getId()))) .map(x -> new MangaReaderDto(x, mangaService.getReader(x.getId())))
.toList(); .toList();
} }
@PostMapping @PostMapping
public MangaDto createManga(@RequestParam("creatorId") Long creatorId, public MangaReaderDto createManga(@RequestParam("creatorId") Long creatorId,
@RequestParam("chapterCount") Integer chapterCount, @RequestParam("chapterCount") Integer chapterCount,
@RequestParam("mangaName") String mangaName) { @RequestParam("mangaName") String mangaName) {
return new MangaDto(mangaService.addManga(creatorId, chapterCount, mangaName), mangaService.getReader(creatorId)); return new MangaReaderDto(mangaService.addManga(creatorId, chapterCount, mangaName), mangaService.getReader(creatorId));
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public MangaDto updateManga(@PathVariable Long id, public MangaReaderDto updateManga(@PathVariable Long id,
@RequestParam("chapterCount") Integer chapterCount) { @RequestParam("chapterCount") Integer chapterCount) {
return new MangaDto(mangaService.updateManga(id, chapterCount), mangaService.getReader(id)); return new MangaReaderDto(mangaService.updateManga(id, chapterCount), mangaService.getReader(id));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")

View File

@ -1,7 +1,7 @@
package com.LabWork.app.MangaStore.controller; 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 com.LabWork.app.MangaStore.service.ReaderService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -17,44 +17,44 @@ public class ReaderController {
} }
@GetMapping("/{id}") @GetMapping("/{id}")
public ReaderDto getReader(@PathVariable Long id) { public ReaderMangaDto getReader(@PathVariable Long id) {
return new ReaderDto(readerService.findReader(id)); return new ReaderMangaDto(readerService.findReader(id));
} }
@GetMapping @GetMapping
public List<ReaderDto> getReaders() { public List<ReaderMangaDto> getReaders() {
return readerService.findAllReaders().stream() return readerService.findAllReaders().stream()
.map(ReaderDto::new) .map(ReaderMangaDto::new)
.toList(); .toList();
} }
@PostMapping @PostMapping
public ReaderDto createReader(@RequestParam("readerName") String readerName, public ReaderMangaDto createReader(@RequestParam("readerName") String readerName,
@RequestParam("password") String password) { @RequestParam("password") String password) {
return new ReaderDto(readerService.addReader(readerName, password)); return new ReaderMangaDto(readerService.addReader(readerName, password));
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public ReaderDto updateReader(@PathVariable Long id, public ReaderMangaDto updateReader(@PathVariable Long id,
@RequestParam("readerName") String readerName, @RequestParam("readerName") String readerName,
@RequestParam("password") String password) { @RequestParam("password") String password) {
return new ReaderDto(readerService.updateReader(id, readerName, password)); return new ReaderMangaDto(readerService.updateReader(id, readerName, password));
} }
@PutMapping("/{id}/addManga") @PutMapping("/{id}/addManga")
public ReaderDto addManga(@PathVariable Long id, public ReaderMangaDto addManga(@PathVariable Long id,
@RequestParam("mangaId") Long mangaId) { @RequestParam("mangaId") Long mangaId) {
return new ReaderDto(readerService.addManga(mangaId, id)); return new ReaderMangaDto(readerService.addManga(mangaId, id));
} }
@PutMapping("/{id}/removeManga") @PutMapping("/{id}/removeManga")
public ReaderDto removeManga(@PathVariable Long id, public ReaderMangaDto removeManga(@PathVariable Long id,
@RequestParam("mangaId") Long mangaId) { @RequestParam("mangaId") Long mangaId) {
return new ReaderDto(readerService.removeManga(mangaId, id)); return new ReaderMangaDto(readerService.removeManga(mangaId, id));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public ReaderDto deleteReader(@PathVariable Long id) { public ReaderMangaDto deleteReader(@PathVariable Long id) {
return new ReaderDto(readerService.deleteReader(id)); return new ReaderMangaDto(readerService.deleteReader(id));
} }
} }

View File

@ -1,5 +1,7 @@
package com.LabWork.app.MangaStore.model.Default; 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 jakarta.persistence.*;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,17 +1,17 @@
package com.LabWork.app.MangaStore.model.Dto; package com.LabWork.app.MangaStore.model.Dto;
import com.LabWork.app.MangaStore.model.Default.Creator; import com.LabWork.app.MangaStore.model.Default.Creator;
import com.LabWork.app.MangaStore.model.Default.Manga; import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
import java.util.List;
import java.util.Objects;
public class CreatorDto { import java.util.List;
public class CreatorMangaDto {
private final long id; private final long id;
private final String creatorName; private final String creatorName;
private final String hashedPassword; private final String hashedPassword;
private final List<MangaDto> mangas; private final List<MangaDto> mangas;
public CreatorDto(Creator creator) { public CreatorMangaDto(Creator creator) {
this.id = creator.getId(); this.id = creator.getId();
this.creatorName = creator.getCreatorName(); this.creatorName = creator.getCreatorName();
this.hashedPassword = creator.getHashedPassword(); this.hashedPassword = creator.getHashedPassword();

View File

@ -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.Creator;
import com.LabWork.app.MangaStore.model.Default.Manga; import com.LabWork.app.MangaStore.model.Default.Manga;
import com.LabWork.app.MangaStore.model.Default.Reader; 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.List;
import java.util.Objects;
public class MangaDto { public class MangaReaderDto {
private final Long id; private final Long id;
private final Long creatorId; private final Long creatorId;
private final String mangaName; private final String mangaName;
private final Integer chapterCount; 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.id = manga.getId();
this.creatorId = manga.getCreator().getId(); this.creatorId = manga.getCreator().getId();
this.mangaName = manga.getMangaName(); this.mangaName = manga.getMangaName();
this.chapterCount = manga.getChapterCount(); this.chapterCount = manga.getChapterCount();
this.readers = listReader.stream() this.readers = listReader.stream()
.map(y -> new String(y.getReaderName())) .map(y -> new ReaderDto(y))
.toList(); .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() { public Long getId() {
return id; return id;
} }
@ -44,7 +34,7 @@ public class MangaDto {
return mangaName; return mangaName;
} }
public List<String> getReaders() { public List<ReaderDto> getReaders() {
return readers; return readers;
} }

View File

@ -1,25 +1,25 @@
package com.LabWork.app.MangaStore.model.Dto; package com.LabWork.app.MangaStore.model.Dto;
import com.LabWork.app.MangaStore.model.Default.Manga;
import com.LabWork.app.MangaStore.model.Default.Reader; import com.LabWork.app.MangaStore.model.Default.Reader;
import java.util.List; import com.LabWork.app.MangaStore.model.Dto.SupportDto.MangaDto;
import java.util.Objects;
public class ReaderDto { import java.util.List;
public class ReaderMangaDto {
private Long id; private Long id;
private String readerName; private String readerName;
private String hashedPassword; private String hashedPassword;
private List<String> mangas; private List<MangaDto> mangas;
public ReaderDto(Reader reader) { public ReaderMangaDto(Reader reader) {
this.id = reader.getId(); this.id = reader.getId();
this.readerName = reader.getReaderName(); this.readerName = reader.getReaderName();
this.hashedPassword = reader.getHashedPassword(); this.hashedPassword = reader.getHashedPassword();
this.mangas = reader.getMangas().stream() this.mangas = reader.getMangas().stream()
.map(y -> new String(y.getMangaName())) .map(y -> new MangaDto(y))
.toList(); .toList();
} }
@ -31,6 +31,6 @@ public class ReaderDto {
public String getHashedPassword() { return hashedPassword; } public String getHashedPassword() { return hashedPassword; }
public List<String> getMangas() { return mangas; } public List<MangaDto> getMangas() { return mangas; }
} }

View File

@ -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;
}
}

View File

@ -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; }
}