Changeset 6791e89 for src/main/java
- Timestamp:
- 09/22/22 21:16:07 (2 years ago)
- Branches:
- master
- Parents:
- 3692f0d
- Location:
- src/main/java/mk/ukim/finki/db/library
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/mk/ukim/finki/db/library/model/Book.java
r3692f0d r6791e89 74 74 private List<Writer> writers; 75 75 76 public Long getId() { 77 return id; 78 } 79 76 80 public Library getLibrary() { 77 81 return library; -
src/main/java/mk/ukim/finki/db/library/model/ReservationBook.java
r3692f0d r6791e89 18 18 } 19 19 20 public ReservationBook(Member member, Book book, Date takeDate, Date returnDate, boolean isReservedBook) { 21 this.member = member; 22 this.book = book; 20 public ReservationBook( Date takeDate, Date returnDate) { //Long id, 21 //(Long) this.book.getId() = id; 23 22 this.takeDate = takeDate; 24 23 this.returnDate = returnDate; 25 this.isReservedBook = isReservedBook;26 24 } 27 25 -
src/main/java/mk/ukim/finki/db/library/repository/MemberRepository.java
r3692f0d r6791e89 1 1 package mk.ukim.finki.db.library.repository; 2 2 3 import mk.ukim.finki.db.library.model.Book; 4 import mk.ukim.finki.db.library.model.Member; 3 5 import org.springframework.stereotype.Repository; 6 7 import java.util.List; 4 8 5 9 @Repository -
src/main/java/mk/ukim/finki/db/library/repository/UserRepository.java
r3692f0d r6791e89 6 6 import org.springframework.stereotype.Repository; 7 7 8 import java.util.List; 8 9 import java.util.Optional; 9 10 … … 13 14 14 15 Optional<Person> findByEmailAndPassword(String email, String password); 16 17 List<Person> findByEmail(String email); 15 18 } -
src/main/java/mk/ukim/finki/db/library/service/ReservationBookService.java
r3692f0d r6791e89 10 10 public interface ReservationBookService { 11 11 12 ReservationBook findById(Long id);12 //ReservationBook getActiveResBookUser(String username); 13 13 14 14 List<ReservationBook> listAll(); 15 15 16 ReservationBook reserveBook(Long memberId, Long bookId, Date takeDate, Date returnDate, boolean isReservedBook);16 ReservationBook reserveBook(Long bookId, Date takeDate, Date returnDate); 17 17 } -
src/main/java/mk/ukim/finki/db/library/service/UserService.java
r3692f0d r6791e89 2 2 3 3 import mk.ukim.finki.db.library.model.Person; 4 5 import java.util.List; 4 6 5 7 public interface UserService { … … 10 12 Person login(String username, String password); 11 13 14 List<Person> findByEmail(String email); 15 12 16 } -
src/main/java/mk/ukim/finki/db/library/service/impl/ReservationBookServiceImpl.java
r3692f0d r6791e89 2 2 3 3 import mk.ukim.finki.db.library.model.*; 4 import mk.ukim.finki.db.library.model.exception. InvalidReservationBookIdException;4 import mk.ukim.finki.db.library.model.exception.MemberNotFoundException; 5 5 import mk.ukim.finki.db.library.repository.BookRepository; 6 6 import mk.ukim.finki.db.library.repository.MemberRepository; 7 7 import mk.ukim.finki.db.library.repository.ReservationBookRepository; 8 import mk.ukim.finki.db.library.repository.UserRepository; 8 9 import mk.ukim.finki.db.library.service.ReservationBookService; 9 10 import org.springframework.stereotype.Service; … … 16 17 17 18 private final ReservationBookRepository reservationBookRepository; 18 private final MemberRepository memberRepository;19 private final UserRepository userRepository; 19 20 private final BookRepository bookRepository; 20 21 21 22 public ReservationBookServiceImpl(ReservationBookRepository reservationBookRepository, MemberRepository memberRepository, BookRepository bookRepository) { 22 23 this.reservationBookRepository = reservationBookRepository; 23 this. memberRepository = memberRepository;24 this.userRepository = memberRepository; 24 25 this.bookRepository = bookRepository; 25 }26 27 28 @Override29 public ReservationBook findById(Long id) {30 return this.reservationBookRepository.findById(id).orElseThrow(InvalidReservationBookIdException::new);31 26 } 32 27 … … 37 32 38 33 @Override 39 public ReservationBook reserveBook(Long memberId, Long bookId, Date takeDate, Date returnDate, boolean isReservedBook) { 40 Person member = memberId!=null ? this.memberRepository.findById(memberId).orElse((Member) null) : null; 41 Book book = bookId!=null ? this.bookRepository.findById(bookId).orElse((Book) null) : null; 34 public ReservationBook reserveBook(Long bookId, Date takeDate, Date returnDate) { 42 35 43 ReservationBook reservationBook = new ReservationBook((Member) member, book, takeDate, returnDate, isReservedBook); 44 //TODO: treba da se zemat site izdanija od knigata, da se proveri dali ima slobodna i ako ima, od vkupnoto da se namali za edno36 37 ReservationBook reservationBook = new ReservationBook(takeDate, returnDate); //bookId, 45 38 46 39 return this.reservationBookRepository.save(reservationBook); 47 40 } 41 42 43 44 // @Override 45 // public ReservationBook reserveBook(Long memberId, Long bookId, Date takeDate, Date returnDate, boolean isReservedBook) { 46 // Person member = memberId!=null ? this.userRepository.findById(memberId).orElse((Member) null) : null; 47 // Book book = bookId!=null ? this.bookRepository.findById(bookId).orElse((Book) null) : null; 48 // 49 // ReservationBook reservationBook = new ReservationBook((Member) member, book, takeDate, returnDate, isReservedBook); 50 // //TODO: treba da se zemat site izdanija od knigata, da se proveri dali ima slobodna i ako ima, od vkupnoto da se namali za edno 51 // 52 // return this.reservationBookRepository.save(reservationBook); 53 // } 54 48 55 } -
src/main/java/mk/ukim/finki/db/library/service/impl/UserServiceImpl.java
r3692f0d r6791e89 8 8 import mk.ukim.finki.db.library.service.UserService; 9 9 import org.springframework.stereotype.Service; 10 11 import java.util.List; 10 12 11 13 … … 35 37 return userRepository.findByEmailAndPassword(email, password).orElseThrow(InvalidUserCredentialsException::new); 36 38 } 39 40 @Override 41 public List<Person> findByEmail(String email) { 42 return this.userRepository.findByEmail(email); 43 } 37 44 } -
src/main/java/mk/ukim/finki/db/library/web/BookController.java
r3692f0d r6791e89 40 40 41 41 List<Book> books; 42 //List<Writer> writers;42 // List<Writer> writers; 43 43 //List<Genre> genres; 44 44 //List<Library> libraries; … … 46 46 if(bookName == null){ 47 47 books = this.bookService.listAllBooks(); 48 //writers = this.writerService.listAll();48 // writers = this.writerService.listAll(); 49 49 // genres = this.genreService.listAll(); 50 50 … … 62 62 return "book.html"; 63 63 } 64 65 66 67 64 68 } -
src/main/java/mk/ukim/finki/db/library/web/ReservationBookController.java
r3692f0d r6791e89 1 1 package mk.ukim.finki.db.library.web; 2 2 3 import mk.ukim.finki.db.library.model.exception.InvalidArgumentsException; 4 import mk.ukim.finki.db.library.model.exception.PasswordsDoNotMatchException; 5 import mk.ukim.finki.db.library.service.ReservationBookService; 3 6 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.RequestMapping; 7 import org.springframework.ui.Model; 8 import org.springframework.web.bind.annotation.*; 9 10 import java.util.Date; 5 11 6 12 @Controller … … 8 14 public class ReservationBookController { 9 15 16 private final ReservationBookService reservationBookService; 17 18 public ReservationBookController(ReservationBookService reservationBookService) { 19 this.reservationBookService = reservationBookService; 20 } 21 22 @GetMapping("/resBook") 23 public String showRes(){ 24 return "resBook"; 25 } 26 27 @GetMapping 28 public String getReservationBook(@RequestParam(required = false) String error, Model model) { 29 if(error != null && !error.isEmpty()) { 30 model.addAttribute("hasError", true); 31 model.addAttribute("error", error); 32 } 33 //ReservationBook reservationBook = this.reservationBookService.getCurrentUserId(id); 34 model.addAttribute("books", this.reservationBookService.listAll()); 35 return "resBook"; 36 } 37 38 @PostMapping("/reserve/{id}") 39 public String reserve(@PathVariable Long id, 40 @RequestParam Date takeDate, 41 @RequestParam Date returnDate 42 ) { 43 try{ 44 this.reservationBookService.reserveBook(id, takeDate, returnDate); 45 return "redirect:/book"; 46 } catch (InvalidArgumentsException | PasswordsDoNotMatchException exception) { 47 return "redirect:/resBook?error=" + exception.getMessage(); 48 } 49 } 10 50 11 51 }
Note:
See TracChangeset
for help on using the changeset viewer.