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
3 changes: 3 additions & 0 deletions BackEnd/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "automatic"
}
6 changes: 0 additions & 6 deletions BackEnd/Library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
<version>1.8</version>
</dependency>

<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>2.4.0</version>
</dependency>



</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,5 @@ public List<Object[]> getcountByCategoryId() {

}

//book search

@GetMapping("/admin/searchBooks")
public ResponseEntity<Page<Books>> getAllBookStockSearch(
@RequestParam(defaultValue = "") String keyword,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(defaultValue = "id") String sortBy) {
System.out.println("paage size" + pageSize);
Page<Books> list = service.getAllBookStocks(keyword, pageNo - 1, pageSize, sortBy);
return new ResponseEntity<Page<Books>>(list, new HttpHeaders(),
HttpStatus.OK);

}


}
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
package com.innovature.Library.controller;

import java.io.IOException;
import java.security.Principal;
import java.security.Principal;
import java.util.Collection;
import java.sql.Date;

import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
//import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
// import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import org.supercsv.io.CsvBeanWriter;
import org.supercsv.io.ICsvBeanWriter;
import org.supercsv.prefs.CsvPreference;


import com.innovature.Library.entity.Borrow;
import com.innovature.Library.form.BorrowForm;
import com.innovature.Library.service.BorrowService;
import com.innovature.Library.service.impl.BorrowServiceImpl;
import com.innovature.Library.view.BorrowDetailView;
import com.innovature.Library.view.rentChartView;
//import com.innovature.Library.view.BorrowListView;
import com.innovature.Library.view.BorrowListView;


Expand All @@ -61,6 +47,20 @@ public Collection<Borrow> list() {
return bService.listAll();
}

@GetMapping("/user/statusFilter/")
public ResponseEntity<Page<Borrow>>getAllBorrByStat(
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "5") Integer pageSize,
@RequestParam(defaultValue = "borrowId") String sortBy,
@RequestParam(defaultValue = "1") Integer direction,
@RequestParam(defaultValue = "1") Integer status)
{
Page<Borrow> list = bService.getAllBorrByStat(pageNo-1, pageSize, sortBy,direction,status);
return new ResponseEntity<Page<Borrow>>(list,new HttpHeaders(),
HttpStatus.OK);

}


//pagenated borrow list at admin borrow
// @GetMapping("/pagenated/")
Expand Down Expand Up @@ -279,44 +279,16 @@ public rentChartView getchart(){
return test;
}


@GetMapping("admin/export")
public void Exportcsv(HttpServletResponse httpServletResponse) throws IOException {
httpServletResponse.setContentType("text/csv");
java.text.DateFormat datefFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String currentDateTime = datefFormat.format(new java.util.Date());
String headerKey = "Content-Disposition";
String headerValue = "attachment; filename=users_" + currentDateTime + ".csv";
httpServletResponse.setHeader(headerKey, headerValue);
List<Borrow> rents = bService.listcsv();

ICsvBeanWriter csvWriter = new CsvBeanWriter(httpServletResponse.getWriter(),
CsvPreference.STANDARD_PREFERENCE);
String[] csvHeader = { "borrow_id","first_name","books_name", "issue_date", "return_date","due_date","book_returned_date","reason","due_days","fine","status"};
String[] nameMapping = { "borrowId","firstName","booksName", "issueDate", "returnDate", "dueDate","bookReturnedDate","reason","dueDays","fine","status" };
csvWriter.writeHeader(csvHeader);
for (Borrow rent : rents) {
// System.out.println(" :"+rent.getStatus());
csvWriter.write(rent, nameMapping);
}
csvWriter.flush();
csvWriter.close();
@PutMapping("user/paymentStatus/{borrowId}")
public BorrowDetailView updatePaymentStatus(
@PathVariable("borrowId") Integer borrowId,
@Valid @RequestBody BorrowForm form
) {
return bService.updatePaymentStatus(borrowId, form);
}


@GetMapping("/admin/searchUser")
public ResponseEntity<Page<Borrow>> getAllBorrowedUserSearch(
@RequestParam(defaultValue = "") String keyword,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize)
// @RequestParam(defaultValue = "user_id") String sortBy)
{
System.out.println("paage size" + pageSize);
Page<Borrow> list = bService.getAllBorrowedUserSearch(keyword, pageNo - 1, pageSize);
return new ResponseEntity<Page<Borrow>>(list, new HttpHeaders(),
HttpStatus.OK);

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.innovature.Library.repository.UserRepository;
import com.innovature.Library.service.EmailService;


// tgsrhyrsrthr
@RestController
@RequestMapping("/email")
public class EmailController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public ResponseEntity<ResponseMessage> uploadFile(@RequestParam("file") Multipar
message = "Please upload a csv file!";
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseMessage(message,""));
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,22 @@ public static boolean hasCSVFormat(MultipartFile file){
Integer.parseInt(csvRecord.get("booksCopies")),
Integer.parseInt(csvRecord.get("categoryId")),
Integer.parseInt(csvRecord.get("status"))
//csvRecord.get("image")
//csvRecord.get("image")


);
csvList.add(csvob);

}
return csvList;

}catch(IOException e){
throw new RuntimeException("fail to parse csv file"+e.getMessage());
}

}







}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private Status(byte value) {
private User user;

private String status;
private String paymentStatus;
private String reason;
public Long fine;
public Long dueDays;
Expand All @@ -74,6 +75,7 @@ public Borrow(BorrowForm form, Books books, User user2) {
this.books = books;
this.user = user2;
this.status = getStatus();
this.paymentStatus=getPaymentStatus();
this.reason = form.getReason();

LocalDateTime dt =LocalDateTime.now();
Expand All @@ -90,6 +92,7 @@ public Borrow(Books book, User user) {
this.books = book;
this.user = user;
this.status = "REQUESTED";
this.paymentStatus="UNBILLED";
this.dueDays=(long) 0;
this.fine=(long) 0;
}
Expand Down Expand Up @@ -181,11 +184,12 @@ public void setFine(Long fine) {
this.fine = fine;
}

public String getFirstName(){
return user.getFirstName();
public String getPaymentStatus() {
return paymentStatus;
}

public String getBooksName(){
return books.getBooksName();
public void setPaymentStatus(String paymentStatus) {
this.paymentStatus = paymentStatus;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,5 @@ public interface BooksRepository extends Repository<Books, Integer> {
// @Query(value = "select sum(books_copies)", nativeQuery = true)
// List<Object[]> findbyBooksId1();

@Query(value = "Select * from books where status = 1 AND books_name like %?1% order by books_name like ?2% DESC,books_name like %?3 DESC,books_name like %?4% ", nativeQuery = true)
public Page<Books> findByKeywords(String keyword, String k, String k1, String k2, Pageable pageable);


}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface BorrowRepository extends PagingAndSortingRepository<Borrow, Int


//To select user by due date expired
@Query(value = "select * from borrow where borrow_id in(select borrow_id from borrow where due_date<curdate() and status='APPROVED' and user_id=?1 )", nativeQuery = true)
@Query(value = "select * from borrow where borrow_id in(select borrow_id from borrow where due_date<curdate() and status='APPROVED' and payment_status!='PAID' and user_id=?1 )", nativeQuery = true)
Collection<Borrow> findbyUserIdandStatus(Integer userId);


Expand Down Expand Up @@ -109,23 +109,26 @@ public interface BorrowRepository extends PagingAndSortingRepository<Borrow, Int
// @Query(value = "select * from borrow where issue_date between date_sub(curdate(),interval 7 day) and curdate()",nativeQuery = true)
// List<Borrow>findAllC();

// @Query(value = "Select * from borrow where books_name like %?1% order by books_name like ?2% DESC,books_name like %?3 DESC,books_name like %?4% ", nativeQuery = true)
// public Page<Borrow> findByKeywords(String keyword, String k, String k1, String k2, Pageable pageable);

// filter by approved
@Query(value = "select * from borrow where status='APPROVED' and user_id=?", nativeQuery = true)
public Page<Borrow> findByAppStatusUser(Integer userId,Pageable paging);

// filter by rejected
@Query(value = "select * from borrow where status='REJECTED' and user_id=?", nativeQuery = true)
public Page<Borrow> findByRejStatusUser(Integer userId,Pageable paging);

//filter by returned
@Query(value = "select * from borrow where status='RETURNED' and user_id=?", nativeQuery = true)
public Page<Borrow> findByRetStatusUser(Integer userId,Pageable paging);

//filter by requested
@Query(value = "select * from borrow where status='REQUESTED' and user_id=?", nativeQuery = true)
public Page<Borrow> findByReqStatusUser(Integer userId,Pageable paging);



// @Query(value = "SELECT * FROM borrow INNER JOIN user ON borrow.user_id = user.user_id where first_name like %?1% order by first_name like ?2% DESC,first_name like %?3 DESC,first_name like %?4% ", nativeQuery = true)
// public Page<Borrow> findByKeywords(String keyword, String k, String k1, String k2, Pageable pageable);

@Query(value = "select * from borrow where user_id in(select user_id from user where first_name like %?%", nativeQuery = true)
public Page<Borrow> findByKeywords(String keyword, String k, String k1, String k2, Pageable pageable);


}

//mysql> select count(borrow_id) from borrow where book_returned_date between '2023-01-01' and '2023-01-07';
//select count(borrow_id) from borrow where book_returned_date='2022-12-27';

// inner join eg = SELECT user.first_name FROM borrow INNER JOIN user ON borrow.user_id = user.user_id
// >no innerjoin= select user.first_name from user,borrow where user.user_id=borrow.user_id;
//>select * from borrow where user_id in(select user_id from user where first_name like 'ashwin');

//select count(borrow_id) from borrow where book_returned_date='2022-12-27';
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public interface BooksService {

List<Object[]> getBookCountByCategory();

Page<Books>getAllBookStocks(String keyword, Integer pageNo,Integer pageSize,String sortBy);

}


Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public interface BorrowService {

Integer BorrowBlock();

// public RentCharView getChart();

List<Borrow>listcsv();
Page<Borrow>getAllBorrByStat(Integer pageNo, Integer pageSize, String sortBy,Integer direction,Integer status);
BorrowDetailView updatePaymentStatus(Integer borrowId, BorrowForm form);

Page<Borrow>getAllBorrowedUserSearch(String keyword, Integer pageNo,Integer pageSize);

// public RentCharView getChart();


}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public void save(MultipartFile file){
}





public List<csvUpload>getAll(){
return repository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,6 @@ public List<Object[]> getBookCountByCategory() {
return booksRepository.findCountByCategoryId();
}

//book search

@Override
public Page<Books> getAllBookStocks(String keyword, Integer pageNo, Integer pageSize, String sortBy) {
Pageable paging = PageRequest.of(pageNo, pageSize, Sort.by(sortBy));
System.out.println(keyword);
String k = keyword;
String k1 = keyword;
String k2 = keyword;
Page<Books> pagedResult = booksRepository.findByKeywords(keyword, k, k1, k2, paging);
return pagedResult;

}


}

Expand Down
Loading