Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update App.js #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Empty file modified Database/Insertdata.sql
100644 → 100755
Empty file.
Empty file modified Database/createDatabase.sql
100644 → 100755
Empty file.
Empty file modified Project/.gitignore
100644 → 100755
Empty file.
Empty file modified Project/nbactions.xml
100644 → 100755
Empty file.
Empty file modified Project/pom.xml
100644 → 100755
Empty file.
Empty file modified Project/src/main/java/com/store/book/BookApplication.java
100644 → 100755
Empty file.
79 changes: 72 additions & 7 deletions Project/src/main/java/com/store/book/controller/BookController.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,41 @@
*/
package com.store.book.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.store.book.model.Book;
import com.store.book.model.Category;
import com.store.book.model.Feature;
import com.store.book.model.Role;
import com.store.book.model.User;
import com.store.book.repository.BookRepository;
import com.store.book.repository.CategoryRepository;
import com.store.book.repository.FeatureRepository;
import com.store.book.repository.RoleRepository;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.nio.file.Files;
import org.springframework.http.MediaType;

/**
*
Expand All @@ -29,32 +47,79 @@
@CrossOrigin(origins = {"*"})
@RestController
public class BookController {

@Autowired
BookRepository bookRepository;

@Autowired
CategoryRepository categoryRepository;

@Autowired
StorageService storageService;



// public BookController(EntityManager entityManager, CategoryRepository categoryRepository) {
// this.categoryRepository = categoryRepository;
// }
@RequestMapping(value = "book", method = RequestMethod.GET)
public List<Book> getAllFeature() {
List<Book> list = bookRepository.findAll();
return list;
}

@RequestMapping(value = "book/user/{username}", method = RequestMethod.GET)
public List<Book> getByUser(@PathVariable String username) {
List<Book> books = bookRepository.findByUsername(username);
return books;
}
public List<Book> getByUser(@PathVariable String username) {
List<Book> books = bookRepository.findByUsername(username);
return books;
}

@RequestMapping(value = "book/category/{categoryId}", method = RequestMethod.GET)
public List<Book> getByCategory(@PathVariable int categoryId) {
List<Book> books = bookRepository.getByCategoryId(categoryId);
return books;
}

@RequestMapping(value = "book/bookDetail/{bookId}", method = RequestMethod.GET)
public Book getByBookId(@PathVariable int bookId) {
Book book = bookRepository.getByBookId(bookId);
return book;
}
}

// @PostMapping("/book/add")
// public ResponseEntity<Book> addNewBook(@RequestBody Book book,@RequestParam("coverPath") MultipartFile cover,
// @RequestParam("pdfPath") MultipartFile pdf) {
// bookRepository.save(book);
//// String coverPath = StorageService.store(cover);
//// String pdfPath = storageService.storeFile(pdf);
//
// // Set the cover and pdf paths on the book object
//// book.setCoverPath(coverPath);
//// book.setPdfPath(pdfPath);
// for (Category category : book.getCategories()) {
// categoryRepository.saveBook_Category(book.getBookId(), category.getCategoryId());
// }
// return ResponseEntity.ok(book);
// }
@PostMapping(value="/book/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Book> addNewBook(@RequestParam("coverPath") MultipartFile file,
@RequestParam("pdfPath") MultipartFile pdf,
@RequestBody Book book) throws Exception {
String coverFilename = StringUtils.cleanPath(file.getOriginalFilename());
storageService.saveImg(file, coverFilename);
book.setCoverPath(coverFilename);

// Save PDF
String pdfFilename = StringUtils.cleanPath(pdf.getOriginalFilename());
storageService.savePdf(pdf, pdfFilename);
book.setPdfPath(pdfFilename);

bookRepository.save(book);

for (Category category : book.getCategories()) {
categoryRepository.saveBook_Category(book.getBookId(), category.getCategoryId());
}

return ResponseEntity.ok(book);
}
}
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.store.book.controller;

import java.io.IOException;

/**
*
* @author nhat
*/
public class StorageException extends RuntimeException {

public StorageException(String message) {
super(message);
}

public StorageException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
*/
package com.store.book.controller;

/**
*
* @author nhat
*/
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;

import java.nio.file.Path;
import java.util.stream.Stream;

public interface StorageService {

void init();

void store(MultipartFile file);

Stream<Path> loadAll();

Path load(String filename);

Resource loadAsResource(String filename);

void deleteAll();

public void saveImg(MultipartFile file, String coverFilename);

public void savePdf(MultipartFile pdf, String pdfFilename);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package com.store.book.controller;

/**
*
* @author nhat
*/
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.stream.Stream;
import org.springframework.core.io.Resource;

/**
*
* @author nhat
*/
@Service
public class StorageServiceImpl implements StorageService {

private final Path pdfPath = Paths.get("/home/nhat/GitHub/project/Book-Store-Management/react-app/book-store/public/images/pdf");
private final Path coverPath = Paths.get("/home/nhat/GitHub/project/Book-Store-Management/react-app/book-store/public/images/cover");

/**
* Saves a PDF file to the file system.
*
* @param file the MultipartFile object representing the file to be saved
* @param filename the name of the file to be saved
* @throws IOException if an I/O error occurs during the file copying process
*/
@Override
public void savePdf(MultipartFile file, String filename) {
String originalFilename = StringUtils.cleanPath(file.getOriginalFilename());
Path targetPath = pdfPath.resolve(filename);
try {
Files.createDirectories(targetPath.getParent());
Files.copy(file.getInputStream(), targetPath, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new StorageException("Failed to store file " + filename, e);
}
}

/**
* Saves an image file to the file system.
*
* @param file the MultipartFile object representing the file to be saved
* @param filename the name of the file to be saved
* @throws IOException if an I/O error occurs during the file copying process
*/
@Override
public void saveImg(MultipartFile file, String filename) {
String originalFilename = StringUtils.cleanPath(file.getOriginalFilename());
Path targetPath = coverPath.resolve(filename);
try {
Files.createDirectories(targetPath.getParent());
Files.copy(file.getInputStream(), targetPath);
} catch (IOException e) {
throw new RuntimeException("Failed to store image file " + filename, e);
}
}

@Override
public void init() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public void store(MultipartFile file) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Stream<Path> loadAll() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Path load(String filename) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public Resource loadAsResource(String filename) {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}

@Override
public void deleteAll() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}
Empty file.
Empty file modified Project/src/main/java/com/store/book/model/Book.java
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions Project/src/main/java/com/store/book/model/Category.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
*/
package com.store.book.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import java.io.Serializable;
import java.util.List;
Expand Down Expand Up @@ -43,5 +45,14 @@ public class Category implements Serializable {
@JoinTable(name = "Book_Category", joinColumns = @JoinColumn(name = "categoryId"), inverseJoinColumns = @JoinColumn(name = "bookId"))
@JsonIgnore
private List<Book> books;
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public static Category fromInt(int categoryId) {
Category category = new Category();
category.setCategoryId(categoryId);
return category;
}

public Category(int categoryId) {
this.categoryId = categoryId;
}
}
Empty file modified Project/src/main/java/com/store/book/model/Feature.java
100644 → 100755
Empty file.
Empty file modified Project/src/main/java/com/store/book/model/Role.java
100644 → 100755
Empty file.
Empty file modified Project/src/main/java/com/store/book/model/User.java
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file modified Project/src/main/java/com/store/book/modelkey/User_RoleKey.java
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions Project/src/main/java/com/store/book/repository/BookRepository.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface BookRepository extends JpaRepository<Book, Integer> {

@Query(value = "SELECT * FROM Book where bookId = ?", nativeQuery = true)
Book getByBookId(int bookId);


}
10 changes: 10 additions & 0 deletions Project/src/main/java/com/store/book/repository/CategoryRepository.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
package com.store.book.repository;

import com.store.book.model.Category;
import java.util.Optional;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
*
* @author nhat
*/
public interface CategoryRepository extends JpaRepository<Category, Integer>{
Optional<Category> findById(int categoryId);

@Modifying
@Transactional
@Query(value = "INSERT INTO Book_Category (bookId, categoryId) VALUES (:bookId, :categoryId)",nativeQuery = true)
public void saveBook_Category(@Param("bookId") Integer bookId, @Param("categoryId") Integer categoryId);
}
Empty file.
Empty file.
Empty file.
3 changes: 1 addition & 2 deletions Project/src/main/resources/application.properties
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
server.port= 9999

spring.servlet.multipart.enabled=true
spring.mvc.view.prefix=/WEB-INF/
spring.mvc.view.suffix=.jsp
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/FU_LABIA_BookStoreManagement
spring.datasource.username=root
spring.datasource.password=123
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.ddl-auto = none
Expand Down
Empty file modified Project/src/main/webapp/WEB-INF/authorization/login.jsp
100644 → 100755
Empty file.
Empty file modified Project/src/test/java/com/store/book/BookApplicationTests.java
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/.cache/.eslintcache
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified React/react-frontend/node_modules/.package-lock.json
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/@adobe/css-tools/History.md
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/@adobe/css-tools/LICENSE
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/@adobe/css-tools/Readme.md
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified React/react-frontend/node_modules/@adobe/css-tools/package.json
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/@ampproject/remapping/LICENSE
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified React/react-frontend/node_modules/@babel/code-frame/LICENSE
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/@babel/code-frame/README.md
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified React/react-frontend/node_modules/@babel/compat-data/LICENSE
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/@babel/compat-data/README.md
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified React/react-frontend/node_modules/@babel/compat-data/plugins.js
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/@babel/core/LICENSE
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/@babel/core/README.md
100644 → 100755
Empty file.
Empty file modified React/react-frontend/node_modules/@babel/core/cjs-proxy.cjs
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading