// Path: src/main/java/mobi/qubits/ex/library/domain/events/BorrowEvent.java
// public class BorrowEvent implements LibraryEvent{
// 
// 	private final String libraryId;
// 	
// 	private final String borrowerId;//reader
// 	
// 	private final String bookId;
// 
// 	public BorrowEvent(String libraryId, String bookId, String borrowerId) {
// 		super();
// 		this.libraryId = libraryId;
// 		this.borrowerId = borrowerId;
// 		this.bookId = bookId;
// 	}
// 
// 
// 	public String getLibraryId() {
// 		return libraryId;
// 	}
// 
// 
// 	public String getBorrowerId() {
// 		return borrowerId;
// 	}
// 
// 
// 	public String getBookId() {
// 		return bookId;
// 	}
// 	
// }
// 
// Path: src/main/java/mobi/qubits/ex/library/domain/events/MarkBookHotEvent.java
// public class MarkBookHotEvent implements LibraryEvent{
// 
// 	private final String libraryId;
// 	
// 	private final String id;
// 
// 	public MarkBookHotEvent(String libraryId, String id) {
// 		super();
// 		this.libraryId = libraryId;
// 		this.id = id;
// 	}
// 
// 	public String getLibraryId() {
// 		return libraryId;
// 	}
// 
// 	public String getId() {
// 		return id;
// 	}
// 
// 	
// 
// 	
// }
// 
// Path: src/main/java/mobi/qubits/ex/library/domain/events/NewBookRegisteredEvent.java
// public class NewBookRegisteredEvent implements LibraryEvent{
// 	
// 	private final String libraryId;
// 	
// 	private final String bookId;
// 	
// 	private String title;
// 	private String author;
// 	
// 	public NewBookRegisteredEvent(String libraryId, String bookId,
// 			String title, String author) {
// 		super();
// 		this.libraryId = libraryId;
// 		this.bookId = bookId;
// 		this.title = title;
// 		this.author = author;
// 	}
// 	public String getLibraryId() {
// 		return libraryId;
// 	}
// 	public String getBookId() {
// 		return bookId;
// 	}
// 	public String getTitle() {
// 		return title;
// 	}
// 	public String getAuthor() {
// 		return author;
// 	}
// 	
// 
// 
// }
// 
// Path: src/main/java/mobi/qubits/ex/library/domain/events/ReturnEvent.java
// public class ReturnEvent implements LibraryEvent{
// 
// 	private final String libraryId;
// 	
// 	
// 	private final String bookId;
// 	
// 	private final String borrowerId;
// 
// 	public ReturnEvent(String libraryId, String bookId, String borrowerId) {
// 		super();
// 		this.libraryId = libraryId;
// 		this.bookId = bookId;
// 		this.borrowerId = borrowerId;
// 	}
// 
// 	public String getLibraryId() {
// 		return libraryId;
// 	}
// 
// 	public String getBookId() {
// 		return bookId;
// 	}
// 
// 	public String getBorrowerId() {
// 		return borrowerId;
// 	}
// 	
// 
// 
// }


import mobi.qubits.ex.library.domain.events.BorrowEvent;
import mobi.qubits.ex.library.domain.events.MarkBookHotEvent;
import mobi.qubits.ex.library.domain.events.NewBookRegisteredEvent;
import mobi.qubits.ex.library.domain.events.ReturnEvent;
import org.axonframework.eventhandling.annotation.EventHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

package mobi.qubits.ex.library.query;



/**
 * 
 * @author yizhuan
 *
 */
@Component
public class BookEventListener {

	@Autowired
	private BookEntryRepository bookEntryRepository;

	@EventHandler
	void on(NewBookRegisteredEvent event) {
		BookEntry book = new BookEntry();
		book.setId(event.getBookId());
		book.setLibraryId(event.getLibraryId());
		book.setTitle(event.getTitle());
		book.setAuthor(event.getAuthor());
		book.setBorrowerId(null);
		bookEntryRepository.save(book);
	}
	
	@EventHandler
	void on(MarkBookHotEvent event) {
		BookEntry book = bookEntryRepository.findOne(event.getId());

// Path: src/main/java/mobi/qubits/ex/library/domain/events/BorrowEvent.java
// public class BorrowEvent implements LibraryEvent{
// 
// 	private final String libraryId;
// 	
// 	private final String borrowerId;//reader
// 	
// 	private final String bookId;
// 
// 	public BorrowEvent(String libraryId, String bookId, String borrowerId) {
// 		super();
// 		this.libraryId = libraryId;
// 		this.borrowerId = borrowerId;
// 		this.bookId = bookId;
// 	}
// 
// 
// 	public String getLibraryId() {
// 		return libraryId;
// 	}
// 
// 
// 	public String getBorrowerId() {
// 		return borrowerId;
// 	}
// 
// 
// 	public String getBookId() {
// 		return bookId;
// 	}
// 	
// }
// 
// Path: src/main/java/mobi/qubits/ex/library/domain/events/MarkBookHotEvent.java
// public class MarkBookHotEvent implements LibraryEvent{
// 
// 	private final String libraryId;
// 	
// 	private final String id;
// 
// 	public MarkBookHotEvent(String libraryId, String id) {
// 		super();
// 		this.libraryId = libraryId;
// 		this.id = id;
// 	}
// 
// 	public String getLibraryId() {
// 		return libraryId;
// 	}
// 
// 	public String getId() {
// 		return id;
// 	}
// 
// 	
// 
// 	
// }
// 
// Path: src/main/java/mobi/qubits/ex/library/domain/events/NewBookRegisteredEvent.java
// public class NewBookRegisteredEvent implements LibraryEvent{
// 	
// 	private final String libraryId;
// 	
// 	private final String bookId;
// 	
// 	private String title;
// 	private String author;
// 	
// 	public NewBookRegisteredEvent(String libraryId, String bookId,
// 			String title, String author) {
// 		super();
// 		this.libraryId = libraryId;
// 		this.bookId = bookId;
// 		this.title = title;
// 		this.author = author;
// 	}
// 	public String getLibraryId() {
// 		return libraryId;
// 	}
// 	public String getBookId() {
// 		return bookId;
// 	}
// 	public String getTitle() {
// 		return title;
// 	}
// 	public String getAuthor() {
// 		return author;
// 	}
// 	
// 
// 
// }
// 
// Path: src/main/java/mobi/qubits/ex/library/domain/events/ReturnEvent.java
// public class ReturnEvent implements LibraryEvent{
// 
// 	private final String libraryId;
// 	
// 	
// 	private final String bookId;
// 	
// 	private final String borrowerId;
// 
// 	public ReturnEvent(String libraryId, String bookId, String borrowerId) {
// 		super();
// 		this.libraryId = libraryId;
// 		this.bookId = bookId;
// 		this.borrowerId = borrowerId;
// 	}
// 
// 	public String getLibraryId() {
// 		return libraryId;
// 	}
// 
// 	public String getBookId() {
// 		return bookId;
// 	}
// 
// 	public String getBorrowerId() {
// 		return borrowerId;
// 	}
// 	
// 
// 
// }


// Path: src/main/java/mobi/qubits/ex/library/query/BookEventListener.java
import mobi.qubits.ex.library.domain.events.BorrowEvent;
import mobi.qubits.ex.library.domain.events.MarkBookHotEvent;
import mobi.qubits.ex.library.domain.events.NewBookRegisteredEvent;
import mobi.qubits.ex.library.domain.events.ReturnEvent;
import org.axonframework.eventhandling.annotation.EventHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

package mobi.qubits.ex.library.query;



/**
 * 
 * @author yizhuan
 *
 */
@Component
public class BookEventListener {

	@Autowired
	private BookEntryRepository bookEntryRepository;

	@EventHandler
	void on(NewBookRegisteredEvent event) {
		BookEntry book = new BookEntry();
		book.setId(event.getBookId());
		book.setLibraryId(event.getLibraryId());
		book.setTitle(event.getTitle());
		book.setAuthor(event.getAuthor());
		book.setBorrowerId(null);
		bookEntryRepository.save(book);
	}
	
	@EventHandler
	void on(MarkBookHotEvent event) {
		BookEntry book = bookEntryRepository.findOne(event.getId());

		book.setIsHot(true);
