- Timestamp:
- 09/22/22 21:16:07 (2 years ago)
- Branches:
- master
- Parents:
- 3692f0d
- Location:
- src/main
- Files:
-
- 1 added
- 15 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 } -
src/main/resources/application.properties
r3692f0d r6791e89 1 server.port=909 11 server.port=9090 2 2 3 3 # Datasource configuration 4 spring.datasource.url=jdbc:postgresql://localhost: 5432/parkingDB5 spring.datasource.username= parkDB6 spring.datasource.password= parkdb1234 spring.datasource.url=jdbc:postgresql://localhost:9999/db_202122z_va_prj_vintagelibrary 5 spring.datasource.username=db_202122z_va_prj_vintagelibrary_owner 6 spring.datasource.password=45dc6bb3181a 7 7 8 8 # Default connection pool … … 16 16 spring.jpa.show-sql=true 17 17 18 19 spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategy ComponentPathImpl18 spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 19 spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl 20 20 21 21 spring.jpa.open-in-view=false -
src/main/resources/templates/book.html
r3692f0d r6791e89 61 61 <th scope="col">Цена</th> 62 62 <th scope="col">Цена со задоцнување</th> 63 <th scope="col">Автор</th> 64 <th scope="col">Жанр</th> 63 <!-- <th scope="col">Автор</th> --> 64 <!-- <th scope="col">Жанр</th> --> 65 <th scope="col"></th> 65 66 <th scope="col"></th> 66 67 </thead> … … 71 72 <td th:text="${book.getBookPrice()}"></td> 72 73 <td th:text="${book.getBookPriceLate()}"></td> 73 < td th:each="writer : ${writers}" th:if="${book.getWriters().contains(writer)}" th:text="${writer.getWriterName()}"></td>74 < td th:each="genre : ${genres}" th:if="${book.getGenre().contains(genre)}" th:text="${genre.getGenreName()}"></td>74 <!-- <td th:each="writer : ${writers}" th:if="${book.getWriters().contains(writer)}" th:text="${writer.getWriterName()}"></td> --> 75 <!-- <td th:each="genre : ${genres}" th:if="${book.getGenre().contains(genre)}" th:text="${genre.getGenreName()}"></td> --> 75 76 <td><a class="btn btn-primary btn-sm ml-3" href="/resBook">Резервација</a> 76 77 <a class="btn btn-primary btn-sm ml-3" href="/online">Симнување</a></td> -
src/main/resources/templates/login.html
r3692f0d r6791e89 36 36 </nav> 37 37 38 <section class="jumbotron text-center"> 38 39 <div class="container"> 39 40 <form class="form-signin mt-xl-5" method="post" action="/login"> 40 <h2 class="form-signin-heading"> Најава</h2>41 <h2 class="form-signin-heading"><b>Најава</b></h2> 41 42 <p> 42 43 <label for="username" class="sr-only">Корисничко име:</label> … … 53 54 <button class="btn btn-lg btn-primary btn-block" type="submit">Најави се</button> 54 55 </form> 56 <br> 55 57 <a href="/register" class="btn btn-block btn-light">Регистрирај се тука</a> 56 58 </div> 59 </section> 57 60 58 61 <!-- Footer --> -
src/main/resources/templates/register.html
r3692f0d r6791e89 43 43 <div class="container"> 44 44 45 <form class="form-signin mt-xl- 2 col-md-8" method="post" action="/register">46 <h2 class="form-signin-heading"> Регистрација</h2>45 <form class="form-signin mt-xl-5" method="post" action="/register"> 46 <h2 class="form-signin-heading"><b>Регистрација</b></h2> 47 47 <br> 48 48 <p> … … 94 94 95 95 </div> 96 </section> 96 97 97 98 98 <!-- Footer --> -
src/main/resources/templates/resBook.html
r3692f0d r6791e89 42 42 43 43 <!--Main--> 44 <div class="container"> 45 <section class="jumbotron text-center"> 46 <h2 class="jumbotron-heading"><b>Резервација на книга</b></h2> 47 </section> 44 <section class="jumbotron text-center"> 45 48 46 49 47 <div th:if="${hasError}"> … … 51 49 </div> 52 50 53 <div class="container mb-4">54 < div class="row">51 <div class="container"> 52 <form class="form-signin mt-xl-5" method="post" action="/resBook"> 55 53 56 </div> 54 <h2 class="jumbotron-heading"><b>Резервација на книга</b></h2> 55 56 <div class="container mb-4"> 57 <div class="row"> 58 <p> 59 <label for="bookName" class="sr-only" th:text="${book.getId()}"></label> 60 <input type="text" id="bookName" name="bookName" class="form-control" th:placeholder="${book.getBookName()}" required="" disabled > 61 </p> 62 </div> 63 </div> 64 65 <div class="container mb-4"> 66 <div class="row"> 67 <p>Датум земање книга 68 <label for="takeDate" class="sr-only">Датум земање книга</label> 69 <input type="date" id="takeDate" name="takeDate" class="form-control" placeholder="Take Date" required="" autofocus=""> 70 </p> 71 <br> 72 <p>Датум враќање книга 73 <label for="returnDate" class="sr-only">Датум враќање книга</label> 74 <input type="date" id="returnDate" name="returnDate" class="form-control" placeholder="Return Date" required="" autofocus=""> 75 </p> 76 </div> 77 </div> 78 </form> 79 <button class="btn btn-lg btn-primary btn-block" type="submit">ПОТВРДИ РЕЗЕРВАЦИЈА</button> 80 <br> 81 <a href="/book" class="btn btn-block btn-light">ОТКАЖИ РЕЗЕРВАЦИЈА</a> 57 82 </div> 58 83 59 </ div>84 </section> 60 85 61 86 <!-- Footer -->
Note:
See TracChangeset
for help on using the changeset viewer.