Add file upload functionality
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.service.FileUploadService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/files")
|
||||
public class FileUploadController {
|
||||
|
||||
private final FileUploadService fileUploadService;
|
||||
|
||||
@PostMapping("/upload")
|
||||
public ResponseEntity<Void> uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("libraryId") long libraryId, @RequestParam("filePath") String filePath) {
|
||||
fileUploadService.uploadFile(file, libraryId, filePath);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
+12
-8
@@ -23,6 +23,16 @@ public class LibraryController {
|
||||
private LibraryService libraryService;
|
||||
private BooksService booksService;
|
||||
|
||||
@GetMapping("/{libraryId}")
|
||||
public ResponseEntity<LibraryDTO> getLibrary(@PathVariable long libraryId) {
|
||||
return ResponseEntity.ok(libraryService.getLibrary(libraryId));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Page<LibraryDTO>> getLibraries(@RequestParam(defaultValue = "0") @Min(0) int page, @RequestParam(defaultValue = "25") @Min(1) @Max(100) int size) {
|
||||
return ResponseEntity.ok(libraryService.getLibraries(page, size));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<LibraryDTO> createLibraryNew(@RequestBody CreateLibraryRequest request) {
|
||||
return ResponseEntity.ok(libraryService.createLibrary(request));
|
||||
@@ -33,10 +43,7 @@ public class LibraryController {
|
||||
return libraryService.parseLibraryBooks(libraryId, force);
|
||||
}
|
||||
|
||||
@GetMapping("/{libraryId}")
|
||||
public ResponseEntity<LibraryDTO> getLibrary(@PathVariable long libraryId) {
|
||||
return ResponseEntity.ok(libraryService.getLibrary(libraryId));
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/{libraryId}")
|
||||
public ResponseEntity<?> deleteLibrary(@PathVariable long libraryId) {
|
||||
@@ -44,10 +51,7 @@ public class LibraryController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Page<LibraryDTO>> getLibraries(@RequestParam(defaultValue = "0") @Min(0) int page, @RequestParam(defaultValue = "25") @Min(1) @Max(100) int size) {
|
||||
return ResponseEntity.ok(libraryService.getLibraries(page, size));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/{libraryId}/book/{bookId}/withNeighbors")
|
||||
public ResponseEntity<BookWithNeighborsDTO> getBookWithNeighbours(@PathVariable long libraryId, @PathVariable long bookId) {
|
||||
|
||||
+7
-3
@@ -5,20 +5,24 @@ import org.springframework.http.HttpStatus;
|
||||
|
||||
|
||||
@Getter
|
||||
public enum ErrorCode {
|
||||
public enum ApiError {
|
||||
AUTHOR_NOT_FOUND(HttpStatus.NOT_FOUND, "Author not found with ID: %d"),
|
||||
BOOK_NOT_FOUND(HttpStatus.NOT_FOUND, "Book not found with ID: %d"),
|
||||
FILE_READ_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Error reading files from path"),
|
||||
IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "Image not found or not readable"),
|
||||
INVALID_FILE_FORMAT(HttpStatus.BAD_REQUEST, "Invalid file format"),
|
||||
INVALID_FILE_FORMAT(HttpStatus.BAD_REQUEST, "Invalid file format, only pdf and epub are supported"),
|
||||
LIBRARY_NOT_FOUND(HttpStatus.NOT_FOUND, "Library not found with ID: %d"),
|
||||
BAD_REQUEST(HttpStatus.BAD_REQUEST, "Bad request"),
|
||||
FILE_TOO_LARGE(HttpStatus.BAD_REQUEST, "File size exceeds the limit: 100 MB"),
|
||||
DIRECTORY_CREATION_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create the directory: %s"),
|
||||
INVALID_LIBRARY_PATH(HttpStatus.BAD_REQUEST, "Invalid library path"),
|
||||
FILE_ALREADY_EXISTS(HttpStatus.CONFLICT, "File already exists"),
|
||||
INVALID_QUERY_PARAMETERS(HttpStatus.BAD_REQUEST, "Query parameters are required for the search.");
|
||||
|
||||
private final HttpStatus status;
|
||||
private final String message;
|
||||
|
||||
ErrorCode(HttpStatus status, String message) {
|
||||
ApiError(HttpStatus status, String message) {
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package com.adityachandel.booklore.model;
|
||||
|
||||
import com.adityachandel.booklore.model.entity.Library;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class LibraryFile {
|
||||
|
||||
@@ -4,11 +4,14 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class LibraryDTO {
|
||||
private Long id;
|
||||
private String name;
|
||||
private List<String> paths;
|
||||
}
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.adityachandel.booklore.model.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Data
|
||||
public class FileUploadRequest {
|
||||
private String libraryId;
|
||||
private String filePath;
|
||||
private MultipartFile file;
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.adityachandel.booklore.model.dto.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ApiResponseMessage {
|
||||
private String message;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.AuthorDTO;
|
||||
import com.adityachandel.booklore.model.entity.Author;
|
||||
import com.adityachandel.booklore.exception.ErrorCode;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.repository.AuthorRepository;
|
||||
import com.adityachandel.booklore.repository.BookRepository;
|
||||
import com.adityachandel.booklore.transformer.AuthorTransformer;
|
||||
@@ -19,12 +19,12 @@ public class AuthorService {
|
||||
private final BookRepository bookRepository;
|
||||
|
||||
public AuthorDTO getAuthorById(Long id) {
|
||||
Author author = authorRepository.findById(id).orElseThrow(() -> ErrorCode.AUTHOR_NOT_FOUND.createException(id));
|
||||
Author author = authorRepository.findById(id).orElseThrow(() -> ApiError.AUTHOR_NOT_FOUND.createException(id));
|
||||
return AuthorTransformer.toAuthorDTO(author);
|
||||
}
|
||||
|
||||
public List<AuthorDTO> getAuthorsByBookId(Long bookId) {
|
||||
bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
List<Author> authors = authorRepository.findAuthorsByBookId(bookId);
|
||||
return authors.stream().map(AuthorTransformer::toAuthorDTO).toList();
|
||||
}
|
||||
|
||||
+8
-10
@@ -44,23 +44,21 @@ public class BookCreatorService {
|
||||
}
|
||||
|
||||
public void addAuthorsToBook(Set<String> authors, Book book) {
|
||||
for (String authorSrt : authors) {
|
||||
Optional<Author> authorOptional = authorRepository.findByName(authorSrt);
|
||||
for (String authorStr : authors) {
|
||||
Optional<Author> authorOptional = authorRepository.findByName(authorStr);
|
||||
Author author;
|
||||
if (authorOptional.isPresent()) {
|
||||
author = authorOptional.get();
|
||||
if(book.getMetadata().getAuthors() == null) {
|
||||
book.getMetadata().setAuthors(new ArrayList<>());
|
||||
}
|
||||
book.getMetadata().getAuthors().add(author);
|
||||
} else {
|
||||
author = Author.builder()
|
||||
.name(authorSrt)
|
||||
.name(authorStr)
|
||||
.build();
|
||||
author.setBookMetadataList(new ArrayList<>());
|
||||
book.getMetadata().setAuthors(new ArrayList<>());
|
||||
book.getMetadata().getAuthors().add(author);
|
||||
author = authorRepository.save(author);
|
||||
}
|
||||
if (book.getMetadata().getAuthors() == null) {
|
||||
book.getMetadata().setAuthors(new ArrayList<>());
|
||||
}
|
||||
book.getMetadata().getAuthors().add(author);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.adityachandel.booklore.model.dto.BookWithNeighborsDTO;
|
||||
import com.adityachandel.booklore.model.dto.response.GoogleBooksMetadata;
|
||||
import com.adityachandel.booklore.model.dto.BookViewerSettingDTO;
|
||||
import com.adityachandel.booklore.model.dto.request.SetMetadataRequest;
|
||||
import com.adityachandel.booklore.exception.ErrorCode;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.model.entity.*;
|
||||
import com.adityachandel.booklore.repository.*;
|
||||
import com.adityachandel.booklore.transformer.BookSettingTransformer;
|
||||
@@ -52,7 +52,7 @@ public class BooksService {
|
||||
|
||||
|
||||
public BookDTO getBook(long bookId) {
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
return BookTransformer.convertToBookDTO(book);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class BooksService {
|
||||
}
|
||||
|
||||
public void saveBookViewerSetting(long bookId, BookViewerSettingDTO bookViewerSettingDTO) {
|
||||
BookViewerSetting bookViewerSetting = bookViewerSettingRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookViewerSetting bookViewerSetting = bookViewerSettingRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
bookViewerSetting.setPageNumber(bookViewerSettingDTO.getPageNumber());
|
||||
bookViewerSetting.setZoom(bookViewerSettingDTO.getZoom());
|
||||
bookViewerSetting.setSpread(bookViewerSettingDTO.getSpread());
|
||||
@@ -81,7 +81,7 @@ public class BooksService {
|
||||
}
|
||||
|
||||
public Resource getBookCover(long bookId) {
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
String thumbPath = appProperties.getPathConfig() + "/thumbs/" + getFileNameWithoutExtension(book.getFileName()) + ".jpg";
|
||||
Path filePath = Paths.get(thumbPath);
|
||||
try {
|
||||
@@ -89,15 +89,15 @@ public class BooksService {
|
||||
if (resource.exists() && resource.isReadable()) {
|
||||
return resource;
|
||||
} else {
|
||||
throw ErrorCode.IMAGE_NOT_FOUND.createException(thumbPath);
|
||||
throw ApiError.IMAGE_NOT_FOUND.createException(thumbPath);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw ErrorCode.IMAGE_NOT_FOUND.createException(thumbPath);
|
||||
throw ApiError.IMAGE_NOT_FOUND.createException(thumbPath);
|
||||
}
|
||||
}
|
||||
|
||||
public ResponseEntity<byte[]> getBookData(long bookId) throws IOException {
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
byte[] pdfBytes = Files.readAllBytes(new File(book.getPath()).toPath());
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_TYPE, "application/pdf")
|
||||
@@ -110,18 +110,18 @@ public class BooksService {
|
||||
}
|
||||
|
||||
public BookViewerSettingDTO getBookViewerSetting(long bookId) {
|
||||
BookViewerSetting bookViewerSetting = bookViewerSettingRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
BookViewerSetting bookViewerSetting = bookViewerSettingRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
return BookSettingTransformer.convertToDTO(bookViewerSetting);
|
||||
}
|
||||
|
||||
public void updateLastReadTime(long bookId) {
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
book.setLastReadTime(Instant.now());
|
||||
bookRepository.save(book);
|
||||
}
|
||||
|
||||
public List<GoogleBooksMetadata> fetchProspectiveMetadataListByBookId(long bookId) {
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
StringBuilder searchString = new StringBuilder();
|
||||
if (!book.getMetadata().getTitle().isEmpty()) {
|
||||
searchString.append(book.getMetadata().getTitle());
|
||||
@@ -145,7 +145,7 @@ public class BooksService {
|
||||
}
|
||||
|
||||
public void setMetadata(SetMetadataRequest setMetadataRequest, long bookId) {
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
GoogleBooksMetadata gMetadata = googleBookMetadataService.getByGoogleBookId(setMetadataRequest.getGoogleBookId());
|
||||
BookMetadata metadata = book.getMetadata();
|
||||
metadata.setGoogleBookId(gMetadata.getGoogleBookId());
|
||||
@@ -214,8 +214,8 @@ public class BooksService {
|
||||
}
|
||||
|
||||
public BookWithNeighborsDTO getBookWithNeighbours(long libraryId, long bookId) {
|
||||
libraryRepository.findById(libraryId).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
Book book = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
Book previousBook = bookRepository.findFirstByLibraryIdAndIdLessThanOrderByIdDesc(libraryId, bookId).orElse(null);
|
||||
Book nextBook = bookRepository.findFirstByLibraryIdAndIdGreaterThanOrderByIdAsc(libraryId, bookId).orElse(null);
|
||||
return BookWithNeighborsDTO.builder()
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.adityachandel.booklore.service;
|
||||
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.model.LibraryFile;
|
||||
import com.adityachandel.booklore.model.entity.Library;
|
||||
import com.adityachandel.booklore.repository.LibraryRepository;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
@Slf4j
|
||||
public class FileUploadService {
|
||||
|
||||
private final LibraryRepository libraryRepository;
|
||||
private final PdfFileProcessor fileProcessor;
|
||||
|
||||
public void uploadFile(MultipartFile file, long libraryId, String filePath) {
|
||||
Library library = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
if (!library.getPaths().contains(filePath)) {
|
||||
throw ApiError.INVALID_LIBRARY_PATH.createException();
|
||||
}
|
||||
String fileType = file.getContentType();
|
||||
if (!"application/pdf".equals(fileType) && !"application/epub+zip".equals(fileType)) {
|
||||
throw ApiError.INVALID_FILE_FORMAT.createException();
|
||||
}
|
||||
if (file.getSize() > 100 * 1024 * 1024) {
|
||||
throw ApiError.FILE_TOO_LARGE.createException();
|
||||
}
|
||||
try {
|
||||
Path storagePath = Paths.get(filePath, file.getOriginalFilename());
|
||||
File storageFile = storagePath.toFile();
|
||||
if (storageFile.exists()) {
|
||||
throw ApiError.FILE_ALREADY_EXISTS.createException();
|
||||
}
|
||||
file.transferTo(storageFile);
|
||||
LibraryFile libraryFile = LibraryFile.builder()
|
||||
.library(library)
|
||||
.fileType(getFileType(fileType))
|
||||
.filePath(storageFile.getAbsolutePath())
|
||||
.build();
|
||||
fileProcessor.processFile(libraryFile, false);
|
||||
log.info("File uploaded successfully: {}", storageFile.getAbsolutePath());
|
||||
|
||||
} catch (IOException e) {
|
||||
throw ApiError.FILE_READ_ERROR.createException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getFileType(String f) {
|
||||
if (f.equalsIgnoreCase("application/pdf")) {
|
||||
return "pdf";
|
||||
} else if (f.equalsIgnoreCase("application/epub+zip")) {
|
||||
return "epub";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import com.adityachandel.booklore.model.dto.*;
|
||||
import com.adityachandel.booklore.model.dto.request.CreateLibraryRequest;
|
||||
import com.adityachandel.booklore.model.entity.Book;
|
||||
import com.adityachandel.booklore.model.entity.Library;
|
||||
import com.adityachandel.booklore.exception.ErrorCode;
|
||||
import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.repository.*;
|
||||
import com.adityachandel.booklore.transformer.BookTransformer;
|
||||
import com.adityachandel.booklore.transformer.LibraryTransformer;
|
||||
@@ -45,7 +45,7 @@ public class LibraryService {
|
||||
}
|
||||
|
||||
public LibraryDTO getLibrary(long libraryId) {
|
||||
Library library = libraryRepository.findById(libraryId).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
Library library = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
return LibraryTransformer.convertToLibraryDTO(library);
|
||||
}
|
||||
|
||||
@@ -56,25 +56,25 @@ public class LibraryService {
|
||||
}
|
||||
|
||||
public void deleteLibrary(long id) {
|
||||
libraryRepository.findById(id).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(id));
|
||||
libraryRepository.findById(id).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(id));
|
||||
libraryRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public BookDTO getBook(long libraryId, long bookId) {
|
||||
libraryRepository.findById(libraryId).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
Book book = bookRepository.findBookByIdAndLibraryId(bookId, libraryId).orElseThrow(() -> ErrorCode.BOOK_NOT_FOUND.createException(bookId));
|
||||
libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
Book book = bookRepository.findBookByIdAndLibraryId(bookId, libraryId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
return BookTransformer.convertToBookDTO(book);
|
||||
}
|
||||
|
||||
public Page<BookDTO> getBooks(long libraryId, int page, int size) {
|
||||
libraryRepository.findById(libraryId).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
PageRequest pageRequest = PageRequest.of(page, size);
|
||||
Page<Book> bookPage = bookRepository.findBooksByLibraryId(libraryId, pageRequest);
|
||||
return bookPage.map(BookTransformer::convertToBookDTO);
|
||||
}
|
||||
|
||||
public SseEmitter parseLibraryBooks(long libraryId, boolean force) {
|
||||
Library library = libraryRepository.findById(libraryId).orElseThrow(() -> ErrorCode.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
Library library = libraryRepository.findById(libraryId).orElseThrow(() -> ApiError.LIBRARY_NOT_FOUND.createException(libraryId));
|
||||
SseEmitter emitter = new SseEmitter();
|
||||
ExecutorService sseMvcExecutor = Executors.newSingleThreadExecutor();
|
||||
sseMvcExecutor.execute(() -> {
|
||||
|
||||
+1
@@ -10,6 +10,7 @@ public class LibraryTransformer {
|
||||
return LibraryDTO.builder()
|
||||
.id(library.getId())
|
||||
.name(library.getName())
|
||||
.paths(library.getPaths())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,11 @@ app:
|
||||
path-config: '/Users/aditya.chandel/my-library-temp/config'
|
||||
|
||||
spring:
|
||||
servlet:
|
||||
multipart:
|
||||
enabled: true
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
mvc:
|
||||
async:
|
||||
request-timeout: 600000
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
<p-toast></p-toast>
|
||||
<router-outlet></router-outlet>
|
||||
|
||||
@@ -17,13 +17,11 @@ import {InputIconModule} from 'primeng/inputicon';
|
||||
import {ToggleButtonModule} from 'primeng/togglebutton';
|
||||
import {PasswordModule} from 'primeng/password';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
import {LibraryBrowserComponent} from './book/component/library-browser/library-browser.component';
|
||||
import {InfiniteScrollDirective} from 'ngx-infinite-scroll';
|
||||
import {SearchComponent} from './book/component/search/search.component';
|
||||
import { BookMetadataComponent } from './book/component/book-metadata/book-metadata.component';
|
||||
import { BooksMetadataDialogComponent } from './book/component/books-metadata-dialog/books-metadata-dialog.component';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import { NotificationComponent } from './book/component/notification/notification.component';
|
||||
import {FileUploadComponent} from './book/component/file-upload/file-upload.component';
|
||||
import {DropdownModule} from 'primeng/dropdown';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -47,6 +45,7 @@ import { NotificationComponent } from './book/component/notification/notificatio
|
||||
ToastModule,
|
||||
InfiniteScrollDirective,
|
||||
SearchComponent,
|
||||
DropdownModule,
|
||||
],
|
||||
providers: [DialogService, MessageService],
|
||||
bootstrap: [AppComponent]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
.book-metadata-container {
|
||||
height: calc(100vh - 10rem); /* Full height minus header and footer */
|
||||
overflow-y: auto; /* Enable vertical scrolling */
|
||||
transition: transform 0.2s, left 0.2s; /* Smooth transition for movements */
|
||||
height: calc(100vh - 10rem);
|
||||
overflow-y: auto;
|
||||
transition: transform 0.2s, left 0.2s;
|
||||
background-color: var(--surface-card);
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem 2rem; /* Adjust padding */
|
||||
padding: 1.5rem 2rem;
|
||||
}
|
||||
|
||||
.book-metadata {
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
.title-row {
|
||||
display: flex;
|
||||
justify-content: space-between; /* Ensures title and buttons are spaced out */
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 0.6rem;
|
||||
}
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
.button-group {
|
||||
display: flex;
|
||||
gap: 1.5rem; /* Spacing between buttons */
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.p-button-sm {
|
||||
|
||||
+4
-1
@@ -1,7 +1,10 @@
|
||||
<div *ngIf="!isLoading && bookMetadataList.length > 0" class="search-container">
|
||||
<div class="input-group">
|
||||
<input type="text" [(ngModel)]="searchText" placeholder="Enter book title"/>
|
||||
<p-button severity="success" (click)="populateTitle()">Search</p-button>
|
||||
<p-button
|
||||
severity="success"
|
||||
[disabled]="isButtonDisabled"
|
||||
(click)="populateTitle()">Search</p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+11
-11
@@ -5,13 +5,13 @@
|
||||
.input-group {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 10px; /* Add space between the text box and button */
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
padding: 10px;
|
||||
font-size: 1rem;
|
||||
width: 90%; /* Adjust width as necessary */
|
||||
width: 90%;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 5px;
|
||||
}
|
||||
@@ -43,22 +43,22 @@ button:focus {
|
||||
|
||||
.metadata-header {
|
||||
display: flex;
|
||||
gap: 20px; /* Space between image and text */
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.book-image {
|
||||
width: 100px; /* Adjust the width as needed */
|
||||
height: 150px; /* Adjust the height as needed */
|
||||
object-fit: cover; /* Ensure the image covers the area without distorting */
|
||||
width: 100px;
|
||||
height: 150px;
|
||||
object-fit: cover;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 10px; /* Add spacing between the image and the button */
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.select-button {
|
||||
width: auto; /* Button width adjusts to content */
|
||||
padding: 8px 15px; /* Adjust the button padding */
|
||||
margin-top: 10px; /* Space between the image and button */
|
||||
text-align: center; /* Ensure text is centered in the button */
|
||||
width: auto;
|
||||
padding: 8px 15px;
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.book-metadata {
|
||||
|
||||
+14
-1
@@ -23,6 +23,7 @@ export class BooksMetadataDialogComponent implements OnInit {
|
||||
isLoading = true;
|
||||
errorMessage: string | null = null;
|
||||
searchText: string = '';
|
||||
isButtonDisabled = false;
|
||||
bookId: number = 0;
|
||||
libraryId: number = 0;
|
||||
|
||||
@@ -64,15 +65,27 @@ export class BooksMetadataDialogComponent implements OnInit {
|
||||
}
|
||||
|
||||
populateTitle() {
|
||||
this.isButtonDisabled = true;
|
||||
|
||||
setTimeout(() => {
|
||||
if (this.isButtonDisabled) {
|
||||
this.isButtonDisabled = false;
|
||||
this.errorMessage = 'Request timed out. Please try again.';
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
this.bookService.fetchBookMetadataByTerm(this.searchText).subscribe({
|
||||
next: (metadataList) => {
|
||||
this.bookMetadataList = metadataList;
|
||||
this.isLoading = false;
|
||||
this.isButtonDisabled = false;
|
||||
},
|
||||
error: (error) => {
|
||||
this.errorMessage = 'Failed to load metadata';
|
||||
this.isLoading = false;
|
||||
this.isButtonDisabled = false;
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export class DashboardComponent {
|
||||
createNewLibrary(event: MouseEvent) {
|
||||
const buttonRect = (event.target as HTMLElement).getBoundingClientRect();
|
||||
|
||||
const dialogWidthPercentage = 50; // Use percentage-based width
|
||||
const dialogWidthPercentage = 50;
|
||||
const viewportWidth = window.innerWidth;
|
||||
const dialogWidth = (dialogWidthPercentage / 100) * viewportWidth;
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<div class="card">
|
||||
|
||||
<div class="flex">
|
||||
<p-dropdown
|
||||
[options]="libraries"
|
||||
optionLabel="name"
|
||||
placeholder="Select Library"
|
||||
[(ngModel)]="selectedLibrary">
|
||||
</p-dropdown>
|
||||
</div>
|
||||
|
||||
<div class="flex">
|
||||
<p-dropdown
|
||||
[options]="selectedLibrary?.paths"
|
||||
placeholder="Select Upload Location"
|
||||
[(ngModel)]="selectedPath"
|
||||
[disabled]="!selectedLibrary">
|
||||
</p-dropdown>
|
||||
</div>
|
||||
|
||||
<div class="flex">
|
||||
<div class="button-container">
|
||||
<p-button
|
||||
severity="info"
|
||||
label="Choose"
|
||||
icon="pi pi-file"
|
||||
(click)="triggerFileInput(fileInput)"
|
||||
[disabled]="!selectedPath || isUploading">
|
||||
</p-button>
|
||||
<span *ngIf="selectedFileName" class="file-name">{{ selectedFileName }}</span>
|
||||
</div>
|
||||
<input
|
||||
type="file"
|
||||
#fileInput
|
||||
style="display: none;"
|
||||
(change)="onFileSelected($event)"
|
||||
[disabled]="!selectedPath || isUploading"/>
|
||||
</div>
|
||||
|
||||
<div class="flex">
|
||||
<p-button
|
||||
[label]="isUploading ? 'Uploading...' : 'Upload'"
|
||||
[disabled]="!isFormValid() || isUploading"
|
||||
icon="pi pi-cloud-upload"
|
||||
(click)="uploadFile()">
|
||||
</p-button>
|
||||
<div class="error-message-container">
|
||||
<span *ngIf="errorMessage" class="error-message">{{ errorMessage }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,28 @@
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.flex + .flex {
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
.button-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.file-name {
|
||||
font-weight: bold;
|
||||
color: var(--text-color-secondary);
|
||||
}
|
||||
|
||||
.error-message-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
color: var(--red-600);
|
||||
margin-left: 10px;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Library} from '../../model/library.model';
|
||||
import {LibraryService} from '../../service/library.service';
|
||||
import {FileUploadService} from '../../../file-upload.service';
|
||||
import {Button} from 'primeng/button';
|
||||
import {NgIf} from '@angular/common';
|
||||
import {DropdownModule} from 'primeng/dropdown';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ToastService} from '../../../toast.service';
|
||||
import {DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
|
||||
@Component({
|
||||
selector: 'app-file-upload-v2',
|
||||
templateUrl: './file-upload.component.html',
|
||||
styleUrls: ['./file-upload.component.scss'],
|
||||
imports: [
|
||||
Button,
|
||||
NgIf,
|
||||
DropdownModule,
|
||||
FormsModule
|
||||
],
|
||||
})
|
||||
export class FileUploadComponent implements OnInit {
|
||||
libraries: Library[] = [];
|
||||
selectedLibrary: Library | null = null;
|
||||
selectedPath: string = '';
|
||||
selectedFileName: string = '';
|
||||
isUploading: boolean = false;
|
||||
errorMessage: string | null = null;
|
||||
|
||||
constructor(
|
||||
private libraryService: LibraryService,
|
||||
private fileUploadService: FileUploadService,
|
||||
private toastService: ToastService,
|
||||
private dynamicDialogRef: DynamicDialogRef
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.libraries = this.libraryService.libraries();
|
||||
}
|
||||
|
||||
triggerFileInput(fileInput: HTMLInputElement): void {
|
||||
fileInput.click();
|
||||
}
|
||||
|
||||
onFileSelected(event: Event): void {
|
||||
const input = event.target as HTMLInputElement;
|
||||
if (input && input.files) {
|
||||
const file = input.files[0];
|
||||
if (file) {
|
||||
this.selectedFileName = file.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isFormValid(): boolean {
|
||||
return !!this.selectedLibrary && !!this.selectedPath && !!this.selectedFileName;
|
||||
}
|
||||
|
||||
uploadFile(): void {
|
||||
this.errorMessage = null;
|
||||
if (!this.isFormValid()) {
|
||||
return;
|
||||
}
|
||||
const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
|
||||
if (!fileInput || !fileInput.files || fileInput.files.length === 0) {
|
||||
return;
|
||||
}
|
||||
const file = fileInput.files[0];
|
||||
const libraryId = this.selectedLibrary?.id ? this.selectedLibrary.id.toString() : '';
|
||||
const path = this.selectedPath || '';
|
||||
this.isUploading = true;
|
||||
this.fileUploadService.uploadFile(file, libraryId, path)
|
||||
.subscribe(
|
||||
(response) => {
|
||||
console.log('File uploaded successfully');
|
||||
this.toastService.showSuccess("File uploaded", file.name);
|
||||
this.isUploading = false;
|
||||
this.dynamicDialogRef.close();
|
||||
},
|
||||
(error) => {
|
||||
this.isUploading = false;
|
||||
this.toastService.showError("Upload failed", error.error.message);
|
||||
this.errorMessage = "Upload failed. " + error.error.message + ".";
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
<div class="layout-wrapper" [ngClass]="containerClass">
|
||||
<app-topbar></app-topbar>
|
||||
<div class="layout-sidebar layout-sidebar-custom">
|
||||
<app-sidebar></app-sidebar>
|
||||
<app-topbar></app-topbar>
|
||||
<div class="layout-sidebar layout-sidebar-custom">
|
||||
<app-sidebar></app-sidebar>
|
||||
</div>
|
||||
<div class="layout-main-container layout-main-container-custom">
|
||||
<div class="layout-main">
|
||||
<router-outlet></router-outlet>
|
||||
</div>
|
||||
<div class="layout-main-container layout-main-container-custom">
|
||||
<div class="layout-main" >
|
||||
<router-outlet ></router-outlet>
|
||||
</div>
|
||||
<app-footer></app-footer>
|
||||
</div>
|
||||
<app-config></app-config>
|
||||
<div class="layout-mask"></div>
|
||||
<app-footer></app-footer>
|
||||
</div>
|
||||
<app-config></app-config>
|
||||
<div class="layout-mask"></div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { AppTopBarComponent } from './app.topbar.component';
|
||||
import {AppFooterComponent} from "./app.footer.component";
|
||||
import {AppConfigComponent} from "./config/app.config.component";
|
||||
import {NgClass} from '@angular/common';
|
||||
import {ToastModule} from 'primeng/toast';
|
||||
|
||||
@Component({
|
||||
selector: 'app-layout',
|
||||
@@ -16,7 +17,8 @@ import {NgClass} from '@angular/common';
|
||||
AppConfigComponent,
|
||||
AppSidebarComponent,
|
||||
AppTopBarComponent,
|
||||
NgClass
|
||||
NgClass,
|
||||
ToastModule
|
||||
],
|
||||
templateUrl: './app.layout.component.html'
|
||||
})
|
||||
|
||||
@@ -123,22 +123,16 @@ export class AppMenuitemComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
itemClick(event: Event) {
|
||||
// avoid processing disabled items
|
||||
if (this.item.disabled) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// execute command
|
||||
if (this.item.command) {
|
||||
this.item.command({ originalEvent: event, item: this.item });
|
||||
}
|
||||
|
||||
// toggle active state
|
||||
if (this.item.items) {
|
||||
this.active = !this.active;
|
||||
}
|
||||
|
||||
this.menuService.onMenuStateChange({ key: this.key });
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
tooltipPosition="top">
|
||||
<i class="pi pi-plus-circle"></i>
|
||||
</button>
|
||||
<button class="p-link layout-topbar-button">
|
||||
<i class="pi pi-user"></i>
|
||||
<button
|
||||
(click)="openFileUploadDialog()"
|
||||
class="p-link layout-topbar-button">
|
||||
<i class="pi pi-upload"></i>
|
||||
<span>Profile</span>
|
||||
</button>
|
||||
<button class="p-link layout-topbar-button" [routerLink]="'/documentation'">
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { Component, ElementRef, OnDestroy, ViewChild } from '@angular/core';
|
||||
import { MenuItem } from 'primeng/api';
|
||||
import { LayoutService } from './service/app.layout.service';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import { DialogService as PrimeDialogService, DynamicDialogRef } from 'primeng/dynamicdialog';
|
||||
import { LibraryCreatorComponent } from '../library-creator/library-creator.component';
|
||||
import { TooltipModule } from 'primeng/tooltip';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { InputTextModule } from 'primeng/inputtext';
|
||||
import { SearchComponent } from '../search/search.component';
|
||||
import { NotificationComponent } from '../notification/notification.component'; // Import the NotificationComponent
|
||||
import {Component, ElementRef, OnDestroy, ViewChild} from '@angular/core';
|
||||
import {MenuItem} from 'primeng/api';
|
||||
import {LayoutService} from './service/app.layout.service';
|
||||
import {RouterLink} from '@angular/router';
|
||||
import {DialogService as PrimeDialogService, DynamicDialogRef} from 'primeng/dynamicdialog';
|
||||
import {LibraryCreatorComponent} from '../library-creator/library-creator.component';
|
||||
import {TooltipModule} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {InputTextModule} from 'primeng/inputtext';
|
||||
import {SearchComponent} from '../search/search.component';
|
||||
import {NotificationComponent} from '../notification/notification.component';
|
||||
import {FileUploadComponent} from '../file-upload/file-upload.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-topbar',
|
||||
@@ -18,7 +19,7 @@ import { NotificationComponent } from '../notification/notification.component';
|
||||
FormsModule,
|
||||
InputTextModule,
|
||||
SearchComponent,
|
||||
NotificationComponent // Add NotificationComponent to imports
|
||||
NotificationComponent
|
||||
],
|
||||
templateUrl: './app.topbar.component.html',
|
||||
})
|
||||
@@ -30,7 +31,8 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
@ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef;
|
||||
@ViewChild('topbarmenu') menu!: ElementRef;
|
||||
|
||||
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService) {}
|
||||
constructor(public layoutService: LayoutService, public dialogService: PrimeDialogService) {
|
||||
}
|
||||
|
||||
openLibraryCreatorDialog(): void {
|
||||
this.ref = this.dialogService.open(LibraryCreatorComponent, {
|
||||
@@ -46,4 +48,14 @@ export class AppTopBarComponent implements OnDestroy {
|
||||
this.ref.close();
|
||||
}
|
||||
}
|
||||
|
||||
openFileUploadDialog() {
|
||||
this.ref = this.dialogService.open(FileUploadComponent, {
|
||||
header: 'Upload Book',
|
||||
modal: false,
|
||||
width: '45%',
|
||||
height: '40%',
|
||||
style: { bottom: '20%' }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,21 +15,20 @@
|
||||
height: auto;
|
||||
background-color: var(--surface-card);
|
||||
border-radius: 8px;
|
||||
position: relative; /* Positioning container for the buttons and overlay */
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.book-cover {
|
||||
width: 100%;
|
||||
height: 225px; /* Adjust this as per the image height */
|
||||
height: 225px;
|
||||
object-fit: cover;
|
||||
background-color: #444;
|
||||
transition: background-color 0.3s ease, filter 0.3s ease; /* Add transition for blur effect */
|
||||
position: relative; /* Make this the reference point for the overlay and buttons */
|
||||
transition: background-color 0.3s ease, filter 0.3s ease;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Blur and overlay effect */
|
||||
.book-item:hover .book-cover {
|
||||
filter: blur(2px); /* Apply blur effect to the image */
|
||||
filter: blur(2px);
|
||||
}
|
||||
|
||||
.book-item:hover .book-cover::after {
|
||||
@@ -39,8 +38,8 @@
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: rgba(0, 0, 0, 0.5); /* Semi-transparent black overlay */
|
||||
z-index: 0; /* Put overlay behind the buttons */
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.book-info {
|
||||
@@ -50,7 +49,7 @@
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
flex-grow: 1;
|
||||
z-index: 1; /* Ensure the text stays above the overlay */
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
h4 {
|
||||
@@ -85,23 +84,22 @@ p {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* PrimeNG button styling */
|
||||
.view-btn, .read-btn {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -20%); /* Center buttons within the book-cover */
|
||||
display: none; /* Hide by default */
|
||||
margin: -60px 0; /* Add spacing between the buttons */
|
||||
transform: translate(-50%, -20%);
|
||||
display: none;
|
||||
margin: -60px 0;
|
||||
}
|
||||
|
||||
.book-item:hover .view-btn {
|
||||
display: block; /* Show the View button when the card is hovered */
|
||||
display: block;
|
||||
}
|
||||
|
||||
.book-item:hover .read-btn {
|
||||
display: block; /* Show the Read button when the card is hovered */
|
||||
top: 75%; /* Slightly adjust the position to be below the View button */
|
||||
display: block;
|
||||
top: 75%;
|
||||
}
|
||||
|
||||
.infinite-scroll {
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
height: 100%; /* Fills the parent container */
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.textbox {
|
||||
padding: 10px;
|
||||
margin-bottom: 20px; /* Space between textbox and button */
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.button {
|
||||
@@ -35,10 +35,10 @@
|
||||
}
|
||||
|
||||
.mt-3 {
|
||||
margin-top: 1rem; /* Adds spacing between the button and the table */
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.w-100 {
|
||||
width: 100%; /* Ensures full-width alignment for consistent layout */
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
.search-container {
|
||||
margin-left: 20px;
|
||||
position: relative; /* Ensure the dropdown is positioned relative to the container */
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.search-dropdown {
|
||||
position: absolute;
|
||||
left: 0; /* Align the dropdown to the left of the container */
|
||||
background-color: var(--surface-overlay); /* Use theme's background color */
|
||||
left: 0;
|
||||
background-color: var(--surface-overlay);
|
||||
border: 1px solid var(--surface-border);
|
||||
border-radius: var(--border-radius);
|
||||
z-index: 1000;
|
||||
max-height: 300px; /* Limit the height of the dropdown */
|
||||
overflow-y: auto; /* Scroll if the content exceeds max-height */
|
||||
width: 600px; /* Ensures the dropdown has the same width as the search bar */
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
width: 600px;
|
||||
opacity: 0;
|
||||
height: 0;
|
||||
transition: opacity 0.3s ease, height 0.3s ease;
|
||||
}
|
||||
|
||||
/* Show the dropdown */
|
||||
.search-dropdown.show {
|
||||
opacity: 1;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* Dropdown item styles */
|
||||
.search-dropdown-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -32,32 +30,28 @@
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
|
||||
/* Hover effect */
|
||||
&:hover {
|
||||
background-color: var(--surface-hover);
|
||||
}
|
||||
}
|
||||
|
||||
/* Book cover styling */
|
||||
.search-book-cover {
|
||||
width: 25px; /* Set a fixed width */
|
||||
height: 37px; /* Set a fixed height */
|
||||
object-fit: cover; /* Ensure the image fits the area without distortion */
|
||||
max-width: 100px; /* Max width to prevent images from becoming too big */
|
||||
max-height: 150px; /* Max height to maintain consistency */
|
||||
border-radius: 4px; /* Rounded corners */
|
||||
margin-right: 10px; /* Space between the image and the title */
|
||||
width: 25px;
|
||||
height: 37px;
|
||||
object-fit: cover;
|
||||
max-width: 100px;
|
||||
max-height: 150px;
|
||||
border-radius: 4px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
/* Book title styling */
|
||||
.search-book-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--text-color);
|
||||
flex-grow: 1; /* Allow the title to take up the remaining space */
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
/* Optionally customize the transition duration or timing */
|
||||
.search-dropdown.show {
|
||||
opacity: 1;
|
||||
height: auto;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class FileUploadService {
|
||||
|
||||
private uploadUrl = 'http://localhost:8080/api/v1/files/upload';
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
uploadFile(file: File, libraryId: string, filePath: string): Observable<any> {
|
||||
const formData: FormData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('libraryId', libraryId);
|
||||
formData.append('filePath', filePath);
|
||||
return this.http.post(this.uploadUrl, formData).pipe(
|
||||
catchError((error) => {
|
||||
throw error;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {MessageService} from 'primeng/api';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ToastService {
|
||||
|
||||
constructor(private messageService: MessageService) {}
|
||||
|
||||
showSuccess(summary: string, detail: string) {
|
||||
this.messageService.add({ severity: 'success', summary, detail });
|
||||
}
|
||||
|
||||
showError(summary: string, detail: string) {
|
||||
this.messageService.add({ severity: 'error', summary, detail });
|
||||
}
|
||||
|
||||
showInfo(summary: string, detail: string) {
|
||||
this.messageService.add({ severity: 'info', summary, detail });
|
||||
}
|
||||
|
||||
showWarning(summary: string, detail: string) {
|
||||
this.messageService.add({ severity: 'warn', summary, detail });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user