Changeset 6791e89 for src


Ignore:
Timestamp:
09/22/22 21:16:07 (2 years ago)
Author:
Leona <leona@…>
Branches:
master
Parents:
3692f0d
Message:

working on reservations part

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  
    7474    private List<Writer> writers;
    7575
     76    public Long getId() {
     77        return id;
     78    }
     79
    7680    public Library getLibrary() {
    7781        return library;
  • src/main/java/mk/ukim/finki/db/library/model/ReservationBook.java

    r3692f0d r6791e89  
    1818    }
    1919
    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;
    2322        this.takeDate = takeDate;
    2423        this.returnDate = returnDate;
    25         this.isReservedBook = isReservedBook;
    2624    }
    2725
  • src/main/java/mk/ukim/finki/db/library/repository/MemberRepository.java

    r3692f0d r6791e89  
    11package mk.ukim.finki.db.library.repository;
    22
     3import mk.ukim.finki.db.library.model.Book;
     4import mk.ukim.finki.db.library.model.Member;
    35import org.springframework.stereotype.Repository;
     6
     7import java.util.List;
    48
    59@Repository
  • src/main/java/mk/ukim/finki/db/library/repository/UserRepository.java

    r3692f0d r6791e89  
    66import org.springframework.stereotype.Repository;
    77
     8import java.util.List;
    89import java.util.Optional;
    910
     
    1314
    1415    Optional<Person> findByEmailAndPassword(String email, String password);
     16
     17    List<Person> findByEmail(String email);
    1518}
  • src/main/java/mk/ukim/finki/db/library/service/ReservationBookService.java

    r3692f0d r6791e89  
    1010public interface ReservationBookService {
    1111
    12     ReservationBook findById(Long id);
     12    //ReservationBook getActiveResBookUser(String username);
    1313
    1414    List<ReservationBook> listAll();
    1515
    16     ReservationBook reserveBook(Long memberId, Long bookId, Date takeDate, Date returnDate, boolean isReservedBook);
     16    ReservationBook reserveBook(Long bookId, Date takeDate, Date returnDate);
    1717}
  • src/main/java/mk/ukim/finki/db/library/service/UserService.java

    r3692f0d r6791e89  
    22
    33import mk.ukim.finki.db.library.model.Person;
     4
     5import java.util.List;
    46
    57public interface UserService {
     
    1012    Person login(String username, String password);
    1113
     14    List<Person> findByEmail(String email);
     15
    1216}
  • src/main/java/mk/ukim/finki/db/library/service/impl/ReservationBookServiceImpl.java

    r3692f0d r6791e89  
    22
    33import mk.ukim.finki.db.library.model.*;
    4 import mk.ukim.finki.db.library.model.exception.InvalidReservationBookIdException;
     4import mk.ukim.finki.db.library.model.exception.MemberNotFoundException;
    55import mk.ukim.finki.db.library.repository.BookRepository;
    66import mk.ukim.finki.db.library.repository.MemberRepository;
    77import mk.ukim.finki.db.library.repository.ReservationBookRepository;
     8import mk.ukim.finki.db.library.repository.UserRepository;
    89import mk.ukim.finki.db.library.service.ReservationBookService;
    910import org.springframework.stereotype.Service;
     
    1617
    1718    private final ReservationBookRepository reservationBookRepository;
    18     private final MemberRepository memberRepository;
     19    private final UserRepository userRepository;
    1920    private final BookRepository bookRepository;
    2021
    2122    public ReservationBookServiceImpl(ReservationBookRepository reservationBookRepository, MemberRepository memberRepository, BookRepository bookRepository) {
    2223        this.reservationBookRepository = reservationBookRepository;
    23         this.memberRepository = memberRepository;
     24        this.userRepository = memberRepository;
    2425        this.bookRepository = bookRepository;
    25     }
    26 
    27 
    28     @Override
    29     public ReservationBook findById(Long id) {
    30         return this.reservationBookRepository.findById(id).orElseThrow(InvalidReservationBookIdException::new);
    3126    }
    3227
     
    3732
    3833    @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) {
    4235
    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 edno
     36
     37        ReservationBook reservationBook = new ReservationBook(takeDate, returnDate); //bookId,
    4538
    4639        return this.reservationBookRepository.save(reservationBook);
    4740    }
     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
    4855}
  • src/main/java/mk/ukim/finki/db/library/service/impl/UserServiceImpl.java

    r3692f0d r6791e89  
    88import mk.ukim.finki.db.library.service.UserService;
    99import org.springframework.stereotype.Service;
     10
     11import java.util.List;
    1012
    1113
     
    3537        return userRepository.findByEmailAndPassword(email, password).orElseThrow(InvalidUserCredentialsException::new);
    3638    }
     39
     40    @Override
     41    public List<Person> findByEmail(String email) {
     42        return this.userRepository.findByEmail(email);
     43    }
    3744}
  • src/main/java/mk/ukim/finki/db/library/web/BookController.java

    r3692f0d r6791e89  
    4040
    4141        List<Book> books;
    42         //List<Writer> writers;
     42//        List<Writer> writers;
    4343        //List<Genre> genres;
    4444        //List<Library> libraries;
     
    4646        if(bookName == null){
    4747            books = this.bookService.listAllBooks();
    48            // writers = this.writerService.listAll();
     48//            writers = this.writerService.listAll();
    4949           // genres = this.genreService.listAll();
    5050
     
    6262        return "book.html";
    6363    }
     64
     65
     66
     67
    6468}
  • src/main/java/mk/ukim/finki/db/library/web/ReservationBookController.java

    r3692f0d r6791e89  
    11package mk.ukim.finki.db.library.web;
    22
     3import mk.ukim.finki.db.library.model.exception.InvalidArgumentsException;
     4import mk.ukim.finki.db.library.model.exception.PasswordsDoNotMatchException;
     5import mk.ukim.finki.db.library.service.ReservationBookService;
    36import org.springframework.stereotype.Controller;
    4 import org.springframework.web.bind.annotation.RequestMapping;
     7import org.springframework.ui.Model;
     8import org.springframework.web.bind.annotation.*;
     9
     10import java.util.Date;
    511
    612@Controller
     
    814public class ReservationBookController {
    915
     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    }
    1050
    1151}
  • src/main/resources/application.properties

    r3692f0d r6791e89  
    1 server.port=9091
     1server.port=9090
    22
    33# Datasource configuration
    4 spring.datasource.url=jdbc:postgresql://localhost:5432/parkingDB
    5 spring.datasource.username=parkDB
    6 spring.datasource.password=parkdb123
     4spring.datasource.url=jdbc:postgresql://localhost:9999/db_202122z_va_prj_vintagelibrary
     5spring.datasource.username=db_202122z_va_prj_vintagelibrary_owner
     6spring.datasource.password=45dc6bb3181a
    77
    88# Default connection pool
     
    1616spring.jpa.show-sql=true
    1717
    18 
    19 spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl
     18spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
     19spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
    2020
    2121spring.jpa.open-in-view=false
  • src/main/resources/templates/book.html

    r3692f0d r6791e89  
    6161            <th scope="col">Цена</th>
    6262            <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>
    6566            <th scope="col"></th>
    6667            </thead>
     
    7172              <td th:text="${book.getBookPrice()}"></td>
    7273              <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> -->
    7576              <td><a class="btn btn-primary btn-sm ml-3" href="/resBook">Резервација</a>
    7677                <a class="btn btn-primary btn-sm ml-3" href="/online">Симнување</a></td>
  • src/main/resources/templates/login.html

    r3692f0d r6791e89  
    3636</nav>
    3737
     38<section class="jumbotron text-center">
    3839<div class="container">
    3940    <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>
    4142        <p>
    4243            <label for="username" class="sr-only">Корисничко име:</label>
     
    5354        <button class="btn btn-lg btn-primary btn-block" type="submit">Најави се</button>
    5455    </form>
     56    <br>
    5557    <a href="/register" class="btn btn-block btn-light">Регистрирај се тука</a>
    5658</div>
     59</section>
    5760
    5861<!-- Footer -->
  • src/main/resources/templates/register.html

    r3692f0d r6791e89  
    4343    <div class="container">
    4444
    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>
    4747            <br>
    4848            <p>
     
    9494
    9595    </div>
    96 </section>
     96
    9797
    9898<!-- Footer -->
  • src/main/resources/templates/resBook.html

    r3692f0d r6791e89  
    4242
    4343<!--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
    4846
    4947  <div th:if="${hasError}">
     
    5149  </div>
    5250
    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">
    5553
    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>
    5782  </div>
    5883
    59 </div>
     84</section>
    6085
    6186<!-- Footer -->
Note: See TracChangeset for help on using the changeset viewer.