Changeset 3692f0d for src


Ignore:
Timestamp:
09/22/22 18:11:04 (2 years ago)
Author:
Leona <leona@…>
Branches:
master
Children:
6791e89
Parents:
e5de1b0
Message:

books & rooms showing

Location:
src/main
Files:
3 added
1 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/mk/ukim/finki/db/library/config/DataInitializer.java

    re5de1b0 r3692f0d  
    66
    77import javax.annotation.PostConstruct;
     8import java.util.Collections;
    89import java.util.List;
    910
     
    3637    public void initData(){
    3738        Person member = this.userService.register("MemberName", "MemberSurname",
    38                 "MemberAddres", "MemberTown", "071/111/222", "memberemail@hotmail.com", "baza123!");
     39                "MemberAddress", "MemberTown", "071/111/222", "memberemail@hotmail.com", "baza123!");
    3940
    4041        //LIBRARIES
    4142        Library library = this.libraryService.create(1L,"Grigor Prlicev", "Ohrid");
    42         this.libraryService.create(2L, "Braka Miladinovci", "Struga");
    43         this.libraryService.create(3L, "Braka Miladinovci", "Skopje");
     43//        this.libraryService.create(2L, "Braka Miladinovci", "Struga");
     44//        this.libraryService.create(3L, "Braka Miladinovci", "Skopje");
    4445
    4546        //GENRES
     
    6364        this.bookService.create(1113L, "No time for goodbye",0, false, 30, 50);
    6465
    65         if("thriller".equals(genreService.findById(1L).toString()) && "Inferno".equals(bookService.findById(1L).getBookName())){
    66             Genre genre1 = genreService.findById(1L);
    67             Writer writer1 = writerService.findById(1L);
    68             this.bookService.update(1111L, "Inferno",3, true, 30, 50, List.of(genre1.getId()), List.of(writer1.getId()), 1L);
    69         }
     66//        this.bookService.createB(1114L,"Seat 7A", 5, true, 30, 50, Collections.singletonList(((Long) bookService.findById(2L).getGenre().getId())),
     67//                List.of(3L), 1L);
    7068
    7169        //SCHOOLTYPES
     
    8482        this.priceListService.create(3L, 300); //yearly - other
    8583        this.priceListService.create(5L, 150); //yearly - primary school
    86         this.priceListService.create(6L, 250); //yearly - high school
     84        this.priceListService.create(6L, 300); //yearly - high school
    8785
    8886        //ROOMS
  • src/main/java/mk/ukim/finki/db/library/model/Library.java

    re5de1b0 r3692f0d  
    3333    private List<Book> books;
    3434
     35    public String getLibraryName() {
     36        return libraryName;
     37    }
     38
    3539    public void addBook(Book book) {
    3640        this.books.add(book);
  • src/main/java/mk/ukim/finki/db/library/model/Room.java

    re5de1b0 r3692f0d  
    5555        this.freePlaces = freePlaces;
    5656    }
     57
     58    public String getName() {
     59        return name;
     60    }
    5761}
  • src/main/java/mk/ukim/finki/db/library/repository/BookRepository.java

    re5de1b0 r3692f0d  
    55import org.springframework.stereotype.Repository;
    66
     7import java.util.List;
     8
    79@Repository
    810public interface BookRepository extends JpaRepository<Book, Long> {
    911
    10     //TODO: listBooksByName, listBooksByNameAndGenre, listBooksByNameAndGenreAndWriter, listBooksByNameAndWriter
     12    //TODO: listBooksByNameAndGenre, listBooksByNameAndGenreAndWriter, listBooksByNameAndWriter
    1113    //TODO: listBooksByGenre, listBooksByWriter
     14
     15    List<Book> findByBookName(String bookName);
    1216}
  • src/main/java/mk/ukim/finki/db/library/repository/RoomRepository.java

    re5de1b0 r3692f0d  
    11package mk.ukim.finki.db.library.repository;
    22
     3import mk.ukim.finki.db.library.model.Book;
    34import mk.ukim.finki.db.library.model.Room;
    45import org.springframework.data.jpa.repository.JpaRepository;
    56import org.springframework.stereotype.Repository;
    67
     8import java.util.List;
     9
    710@Repository
    811public interface RoomRepository extends JpaRepository<Room, Long> {
     12
     13    List<Room> findByName(String name);
    914}
  • src/main/java/mk/ukim/finki/db/library/service/BookService.java

    re5de1b0 r3692f0d  
    2020    Book createB(Long id, String bookName, int bookNumber, boolean isFree, int bookPrice, int bookPriceLate, List<Long> genreIds, List<Long> writerIds, Long libraryId); //, List<Long> genreIds, List<Long> writerIds
    2121
     22    List<Book> findByBookName(String bookName);
    2223}
  • src/main/java/mk/ukim/finki/db/library/service/RoomService.java

    re5de1b0 r3692f0d  
    1212
    1313    Room create(Long id, String name, int places, int freePlaces);
     14
     15    List<Room> findByName(String name);
    1416}
  • src/main/java/mk/ukim/finki/db/library/service/impl/BookServiceImpl.java

    re5de1b0 r3692f0d  
    22
    33import mk.ukim.finki.db.library.model.*;
     4import mk.ukim.finki.db.library.model.exception.InvalidArgumentsException;
    45import mk.ukim.finki.db.library.model.exception.InvalidBookIdException;
    56import mk.ukim.finki.db.library.model.exception.LibraryNotFoundException;
     
    9495    }
    9596
     97    @Override
     98    public List<Book> findByBookName(String bookName) {
     99        if(bookName == null || bookName.isEmpty()){
     100            throw new InvalidArgumentsException();
     101        }
     102
     103        return this.bookRepository.findByBookName(bookName);
     104    }
     105
    96106    //in bookRepository
    97     //TODO: listBooksByName, listBooksByNameAndGenre, listBooksByNameAndGenreAndWriter, listBooksByNameAndWriter
     107    //TODO: listBooksByNameAndGenre, listBooksByNameAndGenreAndWriter, listBooksByNameAndWriter
    98108    //TODO: listBooksByGenre, listBooksByWriter
    99109}
  • src/main/java/mk/ukim/finki/db/library/service/impl/RoomServiceImpl.java

    re5de1b0 r3692f0d  
    11package mk.ukim.finki.db.library.service.impl;
    22
     3import mk.ukim.finki.db.library.model.Book;
    34import mk.ukim.finki.db.library.model.Room;
     5import mk.ukim.finki.db.library.model.exception.InvalidArgumentsException;
    46import mk.ukim.finki.db.library.model.exception.InvalidRoomIdException;
    57import mk.ukim.finki.db.library.repository.RoomRepository;
     
    3335        return this.roomRepository.save(room);
    3436    }
     37
     38    @Override
     39    public List<Room> findByName(String name) {
     40        if(name == null || name.isEmpty()){
     41            throw new InvalidArgumentsException();
     42        }
     43
     44        return this.roomRepository.findByName(name);
     45    }
    3546}
  • src/main/java/mk/ukim/finki/db/library/web/BookController.java

    re5de1b0 r3692f0d  
    11package mk.ukim.finki.db.library.web;
    22
     3import mk.ukim.finki.db.library.model.Book;
     4import mk.ukim.finki.db.library.model.Genre;
     5import mk.ukim.finki.db.library.model.Library;
     6import mk.ukim.finki.db.library.model.Writer;
    37import mk.ukim.finki.db.library.service.BookService;
     8import mk.ukim.finki.db.library.service.GenreService;
     9import mk.ukim.finki.db.library.service.LibraryService;
     10import mk.ukim.finki.db.library.service.WriterService;
    411import org.springframework.stereotype.Controller;
     12import org.springframework.ui.Model;
     13import org.springframework.web.bind.annotation.GetMapping;
    514import org.springframework.web.bind.annotation.RequestMapping;
     15import org.springframework.web.bind.annotation.RequestParam;
     16
     17import java.util.List;
    618
    719@Controller
     
    1022
    1123    private final BookService bookService;
     24    private final WriterService writerService;
     25    private final GenreService genreService;
     26    private final LibraryService libraryService;
    1227
    13     public BookController(BookService bookService) {
     28    public BookController(BookService bookService, WriterService writerService, GenreService genreService, LibraryService libraryService) {
    1429        this.bookService = bookService;
     30        this.writerService = writerService;
     31        this.genreService = genreService;
     32        this.libraryService = libraryService;
    1533    }
    1634
     35    //List<Long> genreIds, List<Long> writerIds, Long libraryId
     36    //will show all books that are available in a library
     37    @GetMapping
     38    public String showBooks(@RequestParam(required = false) String bookName,
     39                            Model model){
    1740
     41        List<Book> books;
     42        //List<Writer> writers;
     43        //List<Genre> genres;
     44        //List<Library> libraries;
    1845
     46        if(bookName == null){
     47            books = this.bookService.listAllBooks();
     48           // writers = this.writerService.listAll();
     49           // genres = this.genreService.listAll();
     50
     51        } else {
     52            books = this.bookService.findByBookName(bookName);
     53//            writers = this.writerService.listAll();
     54//            genres = this.genreService.listAll();
     55        }
     56
     57        model.addAttribute("books", books);
     58//        model.addAttribute("writers", writers);
     59//        model.addAttribute("genres", genres);
     60        //model.addAttribute("libraries", libraries);
     61
     62        return "book.html";
     63    }
    1964}
  • src/main/java/mk/ukim/finki/db/library/web/LoginController.java

    re5de1b0 r3692f0d  
    3535                    request.getParameter("password"));
    3636            request.getSession().setAttribute("username", member);
    37             return "redirect:/books";
     37            return "redirect:/book";
    3838        }
    3939        catch (InvalidUserCredentialsException exception) {
  • src/main/java/mk/ukim/finki/db/library/web/ReservationBookController.java

    re5de1b0 r3692f0d  
    55
    66@Controller
    7 @RequestMapping("/reservationBook")
     7@RequestMapping("/resBook")
    88public class ReservationBookController {
     9
     10
    911}
  • src/main/resources/templates/book.html

    re5de1b0 r3692f0d  
    2525        </li>
    2626        <li class="nav-item m-auto">
    27           <a class="nav-link active" href="/info">ИНФОРМАЦИИ</a>
     27          <a class="nav-link active" href="/book">КНИГИ</a>
    2828        </li>
    2929        <li class="nav-item m-auto">
    30           <a class="nav-link active" href="/guide">УПАТСТВО</a>
    31         </li>
    32         <li class="nav-item m-auto">
    33           <a class="nav-link active" href="/book">КНИГИ</a>
     30          <a class="nav-link active" href="/room">ПРОСТОРИИ</a>
    3431        </li>
    3532      </ul>
     
    4744<div class="container">
    4845  <section class="jumbotron text-center">
    49     <h2 class="jumbotron-heading">Достапни книги</h2>
     46    <h2 class="jumbotron-heading"><b>Достапни книги</b></h2>
    5047  </section>
    5148
     
    6057          <table class="table table-striped">
    6158            <thead>
    62             <th scope="col">Book Name</th>
    63             <th scope="col">Price</th>
    64             <th scope="col">Price Late</th>
    65             <th scope="col">Genre</th>
    66             <th scope="col">Library</th>
     59            <th scope="col">Име на книга</th>
     60            <th scope="col">Број на книга</th>
     61            <th scope="col">Цена</th>
     62            <th scope="col">Цена со задоцнување</th>
     63            <th scope="col">Автор</th>
     64            <th scope="col">Жанр</th>
     65            <th scope="col"></th>
    6766            </thead>
    6867            <tbody>
    69             <tr>
    70               <td></td>
     68            <tr th:each="book : ${books}" class="book">
     69              <td th:text="${book.getBookName()}"></td>
     70              <td th:text="${book.getBookNumber()}"></td>
     71              <td th:text="${book.getBookPrice()}"></td>
     72              <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>
     75              <td><a class="btn btn-primary btn-sm ml-3" href="/resBook">Резервација</a>
     76                <a class="btn btn-primary btn-sm ml-3" href="/online">Симнување</a></td>
    7177            </tr>
    7278            </tbody>
     
    7682      </div>
    7783    </div>
    78   </div>
    79 
    80   <div>
    81     <table>
    82 
    83       <!-- For each news you should have one <tr> like below -->
    84       <tr class="item" th:each="book:${book}">
    85         <td th:text="${book.bookName}">[book.bookName]</td>
    86         <td th:text="${book.bookPrice}">[book.bookPrice]</td>
    87         <td th:text="${book.bookPriceLate}">[book.bookPriceLate]</td>
    88         <td th:text="${book.getGenreOfBook()}">[book.genreOfBook]</td>
    89         <td th:text="${book.getLibraryOfBook()}">[book.libraryOfBook]</td>\
    90 
    91       </tr>
    92     </table>
    9384  </div>
    9485
  • src/main/resources/templates/register.html

    re5de1b0 r3692f0d  
    2525                </li>
    2626                <li class="nav-item m-auto">
    27                     <a class="nav-link active" href="info.html">ИНФОРМАЦИИ</a>
     27                    <a class="nav-link active" href="/info">ИНФОРМАЦИИ</a>
    2828                </li>
    2929                <li class="nav-item m-auto">
    30                     <a class="nav-link active" href="guide.html">УПАТСТВО</a>
     30                    <a class="nav-link active" href="/guide">УПАТСТВО</a>
    3131                </li>
    3232            </ul>
Note: See TracChangeset for help on using the changeset viewer.