Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.library.model.entity.User;
import com.library.service.ActivityService;
import com.library.service.BookService;
import com.library.service.ExtendBookService;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
Expand All @@ -32,16 +33,18 @@ public class AdminDashboardController extends HttpServlet {

private final ActivityService activityService = ServiceFactory.getActivityService();
private final BookService bookService = ServiceFactory.getBookService();
private final ExtendBookService extendSerivce = ServiceFactory.getExtendBookService();

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

Map<String, Integer> map = bookService.getNumberBorrowedBookByCategory();

int total = extendSerivce.getNumberOfRequest();
AdminDashBoardDTO dto = activityService.adminDashBoard();
request.setAttribute("dto", dto);
request.setAttribute("map", map);
request.setAttribute("total", total);
request.getRequestDispatcher("/WEB-INF/views/admin/dashboard.jsp").forward(request, response);

}
Expand Down
16 changes: 15 additions & 1 deletion src/java/com/library/controller/book/BookListController.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,24 @@ public BookListController() {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String cursorParam = request.getParameter("cursor");
String limitParam = request.getParameter("limit");

int cursor = (cursorParam == null) ? 0 : Integer.parseInt(cursorParam);
int limit = (limitParam == null) ? 20 : Integer.parseInt(limitParam);

try {
List<Book> bookList = bookDao.getAllBook();

List<Book> bookList = bookDao.getBooksByCursor(cursor, limit);

int nextCursor = bookList.isEmpty() ? 0 : bookList.get(bookList.size() - 1).getBookID();

request.setAttribute("bookList", bookList);
request.setAttribute("nextCursor", nextCursor);
request.setAttribute("limit", limit);

request.getRequestDispatcher("/WEB-INF/views/book/booklist.jsp").forward(request, response);

} catch (BookDataAccessException b) {
logger.error("Error loading books", b);
}
Expand Down
2 changes: 2 additions & 0 deletions src/java/com/library/dao/AdminDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
* @author hieuchu
*/
public interface AdminDao {

public List<UserBorrowRecordDTO> getAllUserInformation();

}
1 change: 1 addition & 0 deletions src/java/com/library/dao/AdminDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ public List<UserBorrowRecordDTO> getAllUserInformation() {
}
return list;
}


}
4 changes: 2 additions & 2 deletions src/java/com/library/dao/BookDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ public List<Book> getBooksByCursor(int cursor, int limit) {

try (Connection conn = DBConnection.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) {

ps.setInt(1, cursor); // ID cuối của trang trước (0 = trang đầu)
ps.setInt(2, limit); // số bản ghi muốn lấy
ps.setInt(1, cursor);
ps.setInt(2, limit);

try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
Expand Down
12 changes: 9 additions & 3 deletions src/java/com/library/dao/ExtendRequestDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
* @author hieuchu
*/
public interface ExtendRequestDao {
boolean insertExtendRequest(ExtendRequestDTO request) ;

boolean insertExtendRequest(ExtendRequestDTO request);

List<ExtendRequestViewDTO> getAllExtendRequests();
boolean hasUserSentRequest(int borrowingID , int userID );
void updateStatus(int userID, String status);

boolean hasUserSentRequest(int borrowingID, int userID);

void updateStatus(int userID, String status);

int countingRequest();
}
14 changes: 14 additions & 0 deletions src/java/com/library/dao/ExtendRequestDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,18 @@ public void updateStatus(int userID, String status) {
}
}

@Override
public int countingRequest() {
String sql = "select count(*) as totalRequest from extend_requests\n"
+ "where status = 'pending'";
try (
Connection conn = DBConnection.getInstance().getConnection(); PreparedStatement ps = conn.prepareStatement(sql)) {
ResultSet rs = ps.executeQuery();
if(rs.next()) return rs.getInt("totalRequest");
} catch (SQLException e) {
e.printStackTrace();
}
return -1 ;
}

}
41 changes: 20 additions & 21 deletions src/java/com/library/service/ActivityService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public ActivityService(ActivityDao activityDao, ActionDao actionDao, UserDao use
this.bookDao = bookDao;

}


public String getBookTitle(int bookID) {
return this.bookDao.getBookTitleByID(bookID);
Expand All @@ -54,7 +53,7 @@ public void ActivityUser(int actionID, String account) {
}
if (actionName.equalsIgnoreCase("update profile")) {
detail = account + " has just updated their profile ";
}
}
logger.info("userid {} is logging ", userId);
this.activityDao.insertData(userId, actionID, detail, LocalDateTime.now());
}
Expand All @@ -69,37 +68,37 @@ public void BookActivityOfUser(String account, int actionID, int bookID) {
if (actionName.equalsIgnoreCase("return book")) {
detail = account + " has just returned " + getBookTitle(bookID);
}
this.activityDao.insertData(userID, actionID, detail, LocalDateTime.now());
this.activityDao.insertData(userID, actionID, detail, LocalDateTime.now());

}

public UserActivityDTO getLatestActivityByAction(int actionID) {
Activity activity = activityDao.getLatestByAction(actionID);
if (activity != null) {
UserActivityDTO dto = new UserActivityDTO();
dto.setAccount(activity.getUser().getAccount());
Action a = new Action();
a.setType(activity.getAction().getType());
dto.setAction(a);
dto.setDetail(activity.getDetail());
dto.setLog_time(TimeFormatter.timeAgo(activity.getLogTime()));
return dto;
}
return null;
public UserActivityDTO getLatestActivityByAction(int actionID) {
Activity activity = activityDao.getLatestByAction(actionID);
if (activity != null) {
UserActivityDTO dto = new UserActivityDTO();
dto.setAccount(activity.getUser().getAccount());
Action a = new Action();
a.setType(activity.getAction().getType());
dto.setAction(a);
dto.setDetail(activity.getDetail());
dto.setLog_time(TimeFormatter.timeAgo(activity.getLogTime()));
return dto;
}
return null;
}

public AdminDashBoardDTO adminDashBoard(){
public AdminDashBoardDTO adminDashBoard() {
AdminDashBoardDTO dto = new AdminDashBoardDTO();
dto.setTotalOnlineUser(TrackingUserService.getSize());
dto.setTotalOnlineUser(TrackingUserService.getSize());
dto.setTotalBook(this.bookDao.totalBook());
List<Action> list = this.actionDao.getAllAction();
List<UserActivityDTO> listActivities = new ArrayList<>();
for(Action a : list){
for (Action a : list) {
UserActivityDTO act = getLatestActivityByAction(a.getActionID()); // take new log of a user
listActivities.add(act); /// add log user into list
}
}
dto.setActionList(listActivities); // set list
return dto ;
return dto;
}

}
3 changes: 3 additions & 0 deletions src/java/com/library/service/ExtendBookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ public void updateRequestStatus(int userID, String status){
this.extendDao.updateStatus(userID, status);
}

public int getNumberOfRequest(){
return this.extendDao.countingRequest();
}
}
4 changes: 2 additions & 2 deletions web/WEB-INF/views/admin/dashboard.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@
<div class="stat-card" style="cursor:pointer;">
<div class="stat-icon orange"><i class="fa-solid fa-book-open-reader"></i></div>
<div class="stat-info">
<h4></h4>
<p>Active Borrowings</p>
<h4>${total}</h4>
<p>Number of Request</p>
</div>
</div>
</a>
Expand Down
12 changes: 11 additions & 1 deletion web/WEB-INF/views/book/booklist.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
<i class="fa-solid fa-heart"></i> Favorite
</a>
<a href="${pageContext.request.contextPath}/user/setting" class="dropdown-item">
<i class="fa-solid fa-gear"></i> Setting
<i class="fa-solid fa-gear"></i> Setting
</a>
<a href="${pageContext.request.contextPath}/LogOut" class="dropdown-item logout">
<i class="fa-solid fa-right-from-bracket"></i> Logout
Expand All @@ -347,6 +347,16 @@
</c:forEach>
</div>
</div>
<!-- Pagination Cursor -->
<div class="pagination" style="margin: 30px auto; text-align: center;">
<c:if test="${nextCursor > 0}">
<a href="${pageContext.request.contextPath}/book/list?cursor=${nextCursor}&limit=${limit}"
style="padding: 12px 20px; background: #4f46e5; color: white;
border-radius: 8px; text-decoration:none; font-weight:600;">
Load More <i class="fa-solid fa-chevron-down"></i>
</a>
</c:if>
</div>

<!-- ======= FOOTER ======= -->
<footer class="footer">
Expand Down