Skip to content

Commit

Permalink
AB#25 added rating feature
Browse files Browse the repository at this point in the history
  • Loading branch information
SvanBoxel committed Mar 21, 2019
1 parent b7fde83 commit e826b43
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
23 changes: 22 additions & 1 deletion src/main/java/com/github/demo/model/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ public class Book {

private String cover;

private long rating;

public Book() {

}

public Book(String author, String title) {
String tempAuthor;
this.author = author;
this.title = title;
}

public Book(String author, String title, String cover) {
public Book(String author, String title, String cover, int rating) {
this.author = author;
this.title = title;
this.cover = cover;
this.setRating(rating);
}

public String getTitle() {
Expand Down Expand Up @@ -53,4 +57,21 @@ public String getCover() {
public void setCover(String cover) {
this.cover = cover;
}

public long getRating() {
return rating;
}

public void setRating(long rating) {

String tempRating = "";

if (rating < 0) {
this.rating = 0;
} else if (rating > 5) {
this.rating = 5;
} else {
this.rating = 0;
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/com/github/demo/service/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class BookService {
private static List<Book> books = new ArrayList<Book>(5);

static {
books.add(new Book("Jeff Sutherland","Scrum: The Art of Doing Twice the Work in Half the Time", "scrum.jpg"));
books.add(new Book("Eric Ries","The Lean Startup: How Constant Innovation Creates Radically Successful Businesses", "lean.jpg"));
books.add(new Book("Geoffrey A. Moore","Crossing the Chasm", "chasm.jpg"));
//books.add(new Book("David Thomas","The Pragmatic Programmer: From Journeyman to Master", "pragmatic.jpg"));
//books.add(new Book("Frederick P. Brooks Jr.", "The Mythical Man-Month: Essays on Software Engineering", "month.jpg"));
books.add(new Book("Steve Krug","Don't Make Me Think, Revisited: A Common Sense Approach to Web Usability", "think.jpg"));
books.add(new Book("Jeff Sutherland","Scrum: The Art of Doing Twice the Work in Half the Time", "scrum.jpg", 3));
books.add(new Book("Eric Ries","The Lean Startup: How Constant Innovation Creates Radically Successful Businesses", "lean.jpg", 5));
books.add(new Book("Geoffrey A. Moore","Crossing the Chasm", "chasm.jpg", 4));
//books.add(new Book("David Thomas","The Pragmatic Programmer: From Journeyman to Master", "pragmatic.jpg", 3));
//books.add(new Book("Frederick P. Brooks Jr.", "The Mythical Man-Month: Essays on Software Engineering", "month.jpg", 3));
books.add(new Book("Steve Krug","Don't Make Me Think, Revisited: A Common Sense Approach to Web Usability", "think.jpg", 5));
}

public List<Book> getBooks() {
Expand Down
9 changes: 8 additions & 1 deletion src/main/webapp/books.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@
<div class="media-body" th:inline="text">
<h4 class="media-heading"><a href="#">[[${book.title}]]</a></h4>
<h5 class="media-heading"> by <a href="#">[[${book.author}]]</a></h5>
<span>Status: </span><span class="text-success"><strong>In Stock</strong></span>
<span>Status: </span>
<span class="text-success"><strong>In Stock</strong></span>
<div>
<span>Rating: </span>
<span th:each="i : ${#numbers.sequence(1, book.rating)}">
<img src="/images/star.png" style="width: 12px; height: 12px;"/>
</span>
</div>
</div>
</div></td>
<td class="col-sm-1 col-md-1 text-center"><strong>$13.99</strong></td>
Expand Down
Binary file modified src/main/webapp/images/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e826b43

Please sign in to comment.