Icon support for library and shelf

This commit is contained in:
aditya.chandel
2024-12-26 16:55:11 -07:00
parent 6e8d978d6e
commit aba11ecaa8
28 changed files with 205 additions and 84 deletions
@@ -11,7 +11,6 @@ import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
@@ -14,6 +14,7 @@ public class LibraryDTO {
private Long id;
private String name;
private Sort sort;
private String icon;
private List<String> paths;
}
@@ -13,5 +13,6 @@ import java.time.Instant;
public class ShelfDTO {
private Long id;
private String name;
private String icon;
private Sort sort;
}
@@ -1,6 +1,8 @@
package com.adityachandel.booklore.model.dto.request;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Builder;
import lombok.Data;
@@ -10,6 +12,10 @@ import java.util.List;
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class CreateLibraryRequest {
@NotBlank
private String name;
@NotBlank
private String icon;
@NotEmpty
private List<String> paths;
}
@@ -12,4 +12,7 @@ public class ShelfCreateRequest {
@NotBlank(message = "Shelf name must not be empty.")
private String name;
@NotBlank(message = "Shelf icon must not be empty.")
private String icon;
}
@@ -31,4 +31,6 @@ public class Library {
@OneToMany(mappedBy = "library", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Book> books;
private String icon;
}
@@ -28,4 +28,6 @@ public class Shelf {
@ManyToMany(mappedBy = "shelves", fetch = FetchType.LAZY)
private Set<Book> books = new HashSet<>();
private String icon;
}
@@ -29,7 +29,11 @@ public class LibraryService {
private final LibraryProcessingService libraryProcessingService;
public LibraryDTO createLibrary(CreateLibraryRequest request) {
Library library = Library.builder().name(request.getName()).paths(request.getPaths()).build();
Library library = Library.builder()
.name(request.getName())
.paths(request.getPaths())
.icon(request.getIcon())
.build();
library = libraryRepository.save(library);
Long libraryId = library.getId();
Thread.startVirtualThread(() -> {
@@ -28,7 +28,7 @@ public class ShelfService {
if (exists) {
throw ApiError.SHELF_ALREADY_EXISTS.createException(request.getName());
}
Shelf shelf = Shelf.builder().name(request.getName()).build();
Shelf shelf = Shelf.builder().icon(request.getIcon()).name(request.getName()).build();
return ShelfTransformer.convertToShelfDTO(shelfRepository.save(shelf));
}
@@ -11,6 +11,7 @@ public class LibraryTransformer {
.id(library.getId())
.name(library.getName())
.sort(library.getSort())
.icon(library.getIcon())
.paths(library.getPaths())
.build();
}
@@ -10,6 +10,7 @@ public class ShelfTransformer {
.id(shelf.getId())
.name(shelf.getName())
.sort(shelf.getSort())
.icon(shelf.getIcon())
.build();
}
}
@@ -2,8 +2,9 @@ CREATE TABLE IF NOT EXISTS library
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) UNIQUE NOT NULL,
paths TEXT,
sort VARCHAR(255) NULL
sort VARCHAR(255) NULL,
icon VARCHAR(64) NOT NULL,
paths TEXT
);
CREATE TABLE IF NOT EXISTS book
@@ -85,7 +86,8 @@ CREATE TABLE IF NOT EXISTS shelf
(
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
sort VARCHAR(255) NULL
sort VARCHAR(255) NULL,
icon VARCHAR(64) NOT NULL
);
CREATE TABLE IF NOT EXISTS book_shelf_mapping
@@ -1,2 +1 @@
INSERT INTO booklore.shelf (name) VALUES ('Favorites');
INSERT INTO booklore.shelf (name) VALUES ('Read Later');
INSERT INTO booklore.shelf (name, icon) VALUES ('Favorites', 'heart');