всё работает
This commit is contained in:
parent
bc84497586
commit
0c89bb621d
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -37,58 +37,58 @@ public class CreatorActionMvcController {
|
||||
if(creatorId != null){
|
||||
model.addAttribute("currentCreator", new CreatorMangaDto(creatorService.findCreator(creatorId)));
|
||||
}
|
||||
model.addAttribute("creatorId", 0);
|
||||
model.addAttribute("creatorId", creatorId);
|
||||
return "creatorAction";
|
||||
}
|
||||
|
||||
@GetMapping("/edit/{id}")
|
||||
public String editManga(@PathVariable(required = false) Long id, Model model) {
|
||||
model.addAttribute("mangaId", id);
|
||||
model.addAttribute("MangaDto", new MangaDto(mangaService.findManga(id)));
|
||||
model.addAttribute("creators",
|
||||
creatorService.findAllCreators().stream()
|
||||
.map(CreatorMangaDto::new)
|
||||
.toList());
|
||||
public String editManga(@PathVariable Long id, Model model) {
|
||||
model.addAttribute("Id", id);
|
||||
model.addAttribute("mangaDto", new MangaDto(mangaService.findManga(id)));
|
||||
model.addAttribute("controller", "manga/");
|
||||
return "creatorAction-edit";
|
||||
}
|
||||
|
||||
@GetMapping("/create")
|
||||
public String createManga(@RequestParam(value = "creatorId", required = false) Long creatorId, Model model) {
|
||||
model.addAttribute("creatorId", 0);
|
||||
model.addAttribute("MangaDto", new MangaDto());
|
||||
model.addAttribute("creators",
|
||||
creatorService.findAllCreators().stream()
|
||||
.map(CreatorMangaDto::new)
|
||||
.toList());
|
||||
@GetMapping("/create/{id}")
|
||||
public String createManga(@PathVariable Long id, Model model) {
|
||||
model.addAttribute("Id", id);
|
||||
model.addAttribute("mangaDto", new MangaDto());
|
||||
model.addAttribute("controller", "creator/");
|
||||
return "creatorAction-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/manga/", "/manga/{mangaId}"})
|
||||
public String saveManga(@PathVariable(value = "mangaId", required = false) Long mangaId, @RequestParam("image") MultipartFile multipartFile,
|
||||
@RequestParam(value = "creatorId", required = false) Long creatorId,
|
||||
@ModelAttribute @Valid MangaDto MangaDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) throws IOException {
|
||||
/* if (bindingResult.hasErrors()) {
|
||||
@PostMapping( "/creator/{creatorId}")
|
||||
public String saveManga(@PathVariable(value = "creatorId", required = false) Long creatorId,
|
||||
@RequestParam("multipartFile") MultipartFile multipartFile,
|
||||
@ModelAttribute @Valid MangaDto mangaDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) throws IOException {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "creatorAction-edit";
|
||||
}*/
|
||||
MangaDto.setImage("data:image/jpeg;base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes()));
|
||||
log.info(MangaDto.getMangaName());
|
||||
MangaDto.setCreatorId(creatorId);
|
||||
if (mangaId == null || mangaId <= 0) {
|
||||
mangaService.addManga(MangaDto);
|
||||
} else {
|
||||
mangaService.updateManga(mangaId, MangaDto.getChapterCount(), MangaDto.getImage());
|
||||
}
|
||||
if (creatorId != null){
|
||||
return "redirect:/creatorAction?creatorId=" + creatorId;
|
||||
} else {
|
||||
return "redirect:/creatorAction?creatorId=" + mangaService.findManga(mangaId).getCreatorId();
|
||||
}
|
||||
mangaDto.setImage("data:image/jpeg;base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes()));
|
||||
log.info(mangaDto.getMangaName());
|
||||
mangaDto.setCreatorId(creatorId);
|
||||
mangaService.addManga(mangaDto);
|
||||
return "redirect:/creatorAction?creatorId=" + creatorId;
|
||||
|
||||
}
|
||||
|
||||
@PostMapping( "/manga/{mangaId}")
|
||||
public String updateManga(@PathVariable(value = "mangaId", required = false) Long mangaId, @RequestParam("multipartFile") MultipartFile multipartFile,
|
||||
@ModelAttribute @Valid MangaDto mangaDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) throws IOException {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "creatorAction-edit";
|
||||
}
|
||||
mangaDto.setImage("data:image/jpeg;base64," + Base64.getEncoder().encodeToString(multipartFile.getBytes()));
|
||||
mangaService.updateManga(mangaId, mangaDto.getChapterCount(), mangaDto.getImage());
|
||||
return "redirect:/creatorAction?creatorId=" + mangaService.findManga(mangaId).getCreatorId();
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteCreator(@PathVariable Long id) {
|
||||
Long creatorId = mangaService.findManga(id).getCreatorId();
|
||||
|
@ -49,13 +49,12 @@ public class ReaderActionMvcController {
|
||||
@RequestParam("mangaId") Long mangaId,
|
||||
@ModelAttribute @Valid MangaDto MangaDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) throws IOException {
|
||||
/* if (bindingResult.hasErrors()) {
|
||||
Model model){
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "readerAction-edit";
|
||||
}*/
|
||||
return "readerAction";
|
||||
}
|
||||
readerService.addManga(mangaId, readerId);
|
||||
System.out.println(mangaId + " " + readerId);
|
||||
return "redirect:/readerAction/?readerId=" + readerId;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,9 @@ public class MangaDto {
|
||||
private Integer chapterCount;
|
||||
private String image;
|
||||
|
||||
public MangaDto() {
|
||||
}
|
||||
|
||||
public MangaDto(Manga manga) {
|
||||
this.id = manga.getId();
|
||||
this.creatorId = manga.getCreator().getId();
|
||||
@ -21,9 +24,6 @@ public class MangaDto {
|
||||
this.chapterCount = manga.getChapterCount();
|
||||
this.image = new String(manga.getImage(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public MangaDto() {
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ public class ReaderDto {
|
||||
|
||||
private String hashedPassword;
|
||||
|
||||
public ReaderDto() {
|
||||
}
|
||||
|
||||
public ReaderDto(Reader reader) {
|
||||
this.id = reader.getId();
|
||||
this.readerName = reader.getReaderName();
|
||||
|
@ -10,7 +10,7 @@
|
||||
<div class = "catalog_wrapper">
|
||||
<h1>Каталог</h1>
|
||||
<div class="p-2 d-flex flex-wrap">
|
||||
<a th:each="manga: ${mangaList}" th:href="@{/manga/{id}(id=${manga.id})}"><img th:src="@{'data:image/jpeg;base64,' + ${manga.image}}" class="slideshow"/></a>
|
||||
<a th:each="manga: ${mangaList}" th:href="@{/manga/{id}(id=${manga.id})}"><img th:src="${manga.image}" class="slideshow"/></a>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
@ -10,11 +10,11 @@
|
||||
<form action="#" th:action="@{/creator/{id}(id=${id})}" th:object="${CreatorMangaDto}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="creatorName" class="form-label">creatorName</label>
|
||||
<input id="creatorName" type='text' value class="form-control" th:field="${CreatorMangaDto.creatorName}" required="true"/>
|
||||
<input id="creatorName" type='text' class="form-control" th:field="${CreatorMangaDto.creatorName}" required="true"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="hashedPassword" class="form-label">hashedPassword</label>
|
||||
<input id="hashedPassword" type='text' value class="form-control" th:field="${CreatorMangaDto.hashedPassword}" required="true"/>
|
||||
<input id="hashedPassword" type='text' class="form-control" th:field="${CreatorMangaDto.hashedPassword}" required="true"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
|
@ -7,30 +7,28 @@
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/creatorAction/manga/{id}(id=${mangaId})}" th:object="${MangaDto}" enctype="multipart/form-data" method="post">
|
||||
<div class="mb-3" th:if="${mangaId == null}">
|
||||
<label for="creatorId" class="form-label">Создатель</label>
|
||||
<select th:name="creatorId" id="creatorId" class="form-select">
|
||||
<option th:each="creator: ${creators}" th:value="${creator.id}" th:text="${creator.creatorName}"/>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3" th:if="${mangaId == null}">
|
||||
<label for="chapterCount" class="form-label">mangaName</label>
|
||||
<input id="mangaName" type='text' value class="form-control" th:field="${MangaDto.mangaName}" required="true"/>
|
||||
<form action="#" th:action="@{'/creatorAction/' + ${controller} + ${id}}" th:object="${mangaDto}" enctype="multipart/form-data" method="post">
|
||||
<div class="mb-3" th:if="${controller == 'creator/'}">
|
||||
<label for="mangaName" class="form-label">mangaName</label>
|
||||
<input id="mangaName" type='text' class="form-control" th:field="${mangaDto.mangaName}" required="true"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="chapterCount" class="form-label">chapterCount</label>
|
||||
<input id="chapterCount" type='number' value class="form-control" th:field="${MangaDto.chapterCount}" required="true"/>
|
||||
<input id="chapterCount" type='number' class="form-control" th:field="${mangaDto.chapterCount}" required="true"/>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="image" class="form-label">image</label>
|
||||
<input type="file" id="image" name="image" accept="image/png, image/jpeg" class="form-control" th:value="@{'data:image/jpeg;base64,' + ${MangaDto.image}}"/>
|
||||
<!--<input id="image" type="file" name="image" class="form-control text-white" accept="image/png, image/jpeg" th:field="${MangaDto.image}" required="true"/>-->
|
||||
<label for="multipartFile" class="form-label">image</label>
|
||||
<input type="file" id="multipartFile" th:name="multipartFile" accept="image/png, image/jpeg" class="form-control" required="true"/>
|
||||
</div>
|
||||
<!-- <div class="mb-3">
|
||||
<label for="image" class="form-label">image</label>
|
||||
<input type="file" id="image" accept="image/png, image/jpeg" class="form-control" th:field="${mangaDto.image}" required="true"/>
|
||||
</div>-->
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${mangaId == null}">Добавить</span>
|
||||
<span th:if="${mangaId != null}">Обновить</span>
|
||||
<span th:if="${controller == 'creator/'}">Добавить</span>
|
||||
<span th:if="${controller != 'creator/'}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/creator}">
|
||||
Назад
|
||||
|
@ -13,7 +13,7 @@
|
||||
<div class="d-flex mt-3">
|
||||
<div class="d-grid col-sm-2">
|
||||
<a class="btn btn-success"
|
||||
th:href="@{/creatorAction/create}">
|
||||
th:href="@{/creatorAction/create/{id}(id=${creatorId})}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
|
@ -8,7 +8,7 @@
|
||||
<div layout:fragment="content">
|
||||
<div class="container d-flex" >
|
||||
<div class="d-flex flex-column">
|
||||
<img class="img_style01" style={{borderRadius:"3%"}} th:src="@{'data:image/jpeg;base64,' + ${manga.image}}" th:alt="${manga.mangaName}"/>
|
||||
<img class="img_style01" style={{borderRadius:"3%"}} th:src="${manga.image}" th:alt="${manga.mangaName}"/>
|
||||
</div>
|
||||
<div class="container table text-white fs-4 ms-4">
|
||||
<div class="row text-white fw-bold fs-3">О манге</div>
|
||||
|
@ -49,7 +49,7 @@
|
||||
<div class="row table-responsive text-white">
|
||||
<div th:each="manga: ${reader?.mangas}" class="d-flex flex-row flex-wrap flex-grow-1 align-items-center mt-3">
|
||||
<div class="me-3">
|
||||
<a th:href="@{/manga/{id}(id=${manga.id})}"><img th:src="@{'data:image/jpeg;base64,' + ${manga.image}}" th:alt="${manga.mangaName}" class="slideshow"/></a>
|
||||
<a th:href="@{/manga/{id}(id=${manga.id})}"><img th:src="${manga.image}" th:alt="${manga.mangaName}" class="slideshow"/></a>
|
||||
</div>
|
||||
<div>
|
||||
<div class="pt-3 description d-flex flex-column justify-content-start mb-3 fs-6 fw-bold">
|
||||
|
Loading…
Reference in New Issue
Block a user