diff --git a/BackEnd/Library/src/main/java/com/innovature/Library/controller/BorrowController.java b/BackEnd/Library/src/main/java/com/innovature/Library/controller/BorrowController.java index 1c9bcc4f..1633bad8 100644 --- a/BackEnd/Library/src/main/java/com/innovature/Library/controller/BorrowController.java +++ b/BackEnd/Library/src/main/java/com/innovature/Library/controller/BorrowController.java @@ -33,22 +33,20 @@ @RestController @RequestMapping("/borrow") -public class BorrowController { - +public class BorrowController { @Autowired private BorrowService bService; + //load all borrow list + @GetMapping + public Collection list() { + return bService.listAll(); + } -//borrow list @admin - - -// @GetMapping("/fetching/{string}/{date1}/{date2}") -// public Collection listinguserdropdown(@PathVariable String string,@PathVariable Date date1, @PathVariable Date date2) { -// return bookingService.listinguserdropdown(string,date1, date2); -// } +//pagenated borrow list at admin borrow @GetMapping("/pagenated/") public ResponseEntity>getAllBorrows( @RequestParam(defaultValue = "1") Integer pageNo, @@ -62,6 +60,26 @@ public class BorrowController { } +//load results of issuedate filter +@GetMapping("/loadByIssueDate/{date1}/{date2}") +public ResponseEntity> loadByIssueDate( +@PathVariable("date1") Date date1, + @PathVariable("date2") Date date2) +// { +// return bService.loadtAllByIssueDate(Date date1, Date date2); +// } +{ + List list = bService.loadtAllByIssueDate(date1, date2); + return new ResponseEntity>(list,new HttpHeaders(), + HttpStatus.OK); +} + + + + + + +//Load filtered pagenated borrow list [on filtering] @GetMapping("/{date1}/{date2}") public ResponseEntity>getFilterBorrow( // @PathVariable Date date1, @PathVariable Date date2, @@ -78,19 +96,13 @@ public class BorrowController { } - // @PutMapping("/{borrowId}") - // public BorrowDetailView updateApprove( - // @PathVariable("borrowId") Integer borrowId, - // @Valid @RequestBody BorrowForm form - // ) { - // return bService.updates(borrowId, form); - // } +//pagenation+sort at user borrow history @GetMapping("/userBorrow/pagenated/") public ResponseEntity>getBorrowHistory( @RequestParam(defaultValue = "1") Integer pageNo, - @RequestParam(defaultValue = "2") Integer pageSize, + @RequestParam(defaultValue = "5") Integer pageSize, @RequestParam(defaultValue = "id") String sortBy) { List list = bService.getBorrowHistory(pageNo-1, pageSize, sortBy); @@ -104,11 +116,6 @@ public class BorrowController { - - - - - @PostMapping public BorrowDetailView add(@Valid @RequestBody BorrowForm form) { return bService.add(form); @@ -128,10 +135,7 @@ public Collection listUserNotification(Principal p) { return bService.listNotification(); } - @GetMapping - public Collection list() { - return bService.listAll(); - } + @GetMapping("/due") public Collection listDue() { diff --git a/BackEnd/Library/src/main/java/com/innovature/Library/repository/BorrowRepository.java b/BackEnd/Library/src/main/java/com/innovature/Library/repository/BorrowRepository.java index 63d485d7..6c52deb1 100644 --- a/BackEnd/Library/src/main/java/com/innovature/Library/repository/BorrowRepository.java +++ b/BackEnd/Library/src/main/java/com/innovature/Library/repository/BorrowRepository.java @@ -2,6 +2,7 @@ import java.sql.Date; import java.util.Collection; +import java.util.List; //import org.springframework.data.repository.Repository; import org.springframework.data.repository.PagingAndSortingRepository; @@ -24,11 +25,13 @@ public interface BorrowRepository extends PagingAndSortingRepository findAllByUserUserId(Integer userId); - +//load all @ pagenation public Page findAll(Pageable paging); + +//load all with userId(in user-login) public Page findAllByUserUserId(Integer userId,Pageable paging); - // public Page findAll(org.springframework.data.domain.Pageable paging); + //To select borrow details with user_id,a day before due day @Query(value = "select * from borrow where borrow_id in(select borrow_id from borrow where due_date=date_add(curdate(),interval 1 day) and status='APPROVED' and user_id=?1)", nativeQuery = true) @@ -69,25 +72,23 @@ public interface BorrowRepository extends PagingAndSortingRepository borrow); - //total sum of fine /user // @Query(value=" select sum(fine) from borrow where user_id=?",nativeQuery=true) // void findFineByUserId(Integer userId); public Page findAll(Pageable paging); - // @Query(value = "select * from borrow where issue_date between '2022-12-12' and '2022-12-20' ", nativeQuery = true) - // public Page findbyIssuDate(Pageable paging); + //Load Filterd results + @Query(value = "select * from borrow where issue_date between DATE(?1) and DATE(?2) and status!='REQUESTED'", nativeQuery = true) + List findbyIssuDate(java.sql.Date date1,java.sql.Date date2); - +//pagenated filtered results @Query(value = "select * from borrow where issue_date between DATE(?1) and DATE(?2) and status!='REQUESTED'", nativeQuery = true) public Page findbyIssuDate( java.sql.Date date1,java.sql.Date date2,Pageable paging); // public Page findbyIssuDate(java.util.Date date1, java.util.Date date2, Pageable paging); - // @Query(value = "select * from booking where booked_date BETWEEN DATE(?2) AND DATE(?3) and vaccine_id in(select vaccine_id from vaccine where vaccine_type=?1);",nativeQuery = true) - // Collection findAll(String string, Date date1, Date date2); + diff --git a/BackEnd/Library/src/main/java/com/innovature/Library/service/BorrowService.java b/BackEnd/Library/src/main/java/com/innovature/Library/service/BorrowService.java index 0e77ed7d..ef8754ba 100644 --- a/BackEnd/Library/src/main/java/com/innovature/Library/service/BorrowService.java +++ b/BackEnd/Library/src/main/java/com/innovature/Library/service/BorrowService.java @@ -15,6 +15,7 @@ public interface BorrowService { BorrowDetailView add(BorrowForm form); Collection listAll(); + List loadtAllByIssueDate(Date date1, Date date2); BorrowDetailView list(Integer borrowId); diff --git a/BackEnd/Library/src/main/java/com/innovature/Library/service/impl/BorrowServiceImpl.java b/BackEnd/Library/src/main/java/com/innovature/Library/service/impl/BorrowServiceImpl.java index a979efa3..e34ba534 100644 --- a/BackEnd/Library/src/main/java/com/innovature/Library/service/impl/BorrowServiceImpl.java +++ b/BackEnd/Library/src/main/java/com/innovature/Library/service/impl/BorrowServiceImpl.java @@ -72,8 +72,13 @@ public BorrowDetailView add(BorrowForm form){ @Override public Collection listAll() { - return borrowRepository.findAll(); - + return borrowRepository.findAll(); + } + + + @Override + public List loadtAllByIssueDate(java.sql.Date date1, java.sql.Date date2) { + return borrowRepository.findbyIssuDate(date1,date2); } @@ -213,7 +218,7 @@ public BorrowDetailView listByUser(Integer borrowId, BorrowForm form) { @Transactional public ListgetAllBorrow( java.sql.Date date1, java.sql.Date date2,Integer pageNo, Integer pageSize, String sortBy){ - Pageable paging = PageRequest.of(pageNo, pageSize, Sort.by(sortBy)); + Pageable paging = PageRequest.of(pageNo, pageSize, Sort .by(sortBy)); Page pagedResult = borrowRepository.findbyIssuDate(date1,date2,paging); diff --git a/FrontEnd/iprjt/src/app/borrow.service.ts b/FrontEnd/iprjt/src/app/borrow.service.ts index 58ef5925..51cf4faa 100644 --- a/FrontEnd/iprjt/src/app/borrow.service.ts +++ b/FrontEnd/iprjt/src/app/borrow.service.ts @@ -32,13 +32,14 @@ export class BorrowService { return this.http.get("http://localhost:8080/borrow/pagenated/?pageNo="+page+"&pageSize="+tableSize+"&sortBy="+sort) } - filterBorrowPagination(date1:any,date2:any,page:any,tableSize:any,sort:any){ - // return this.http.get("http://localhost:8080/borrow/"+date1+"/"+date2+"?page="+page+"&pageSize="+tableSize+"&sortBy="+sort) + filterBorrowPagination(date1:any,date2:any,page:any,tableSize:any,sort:any){ console.log(date1) return this.http.get(this.apiurl + "/borrow/"+date1+"/"+date2+"/?pageNo="+page+"&pageSize="+tableSize+"&sortBy="+sort) } // return this.http.get(this.apiurl + `/users/fetching/${type}/${date1}/${date2}`, httpOptions) - + LoadByIssueDate(date1:any,date2:any){ + return this.http.get(this.apiurl + "/borrow/loadByIssueDate/"+date1+"/"+date2); + } Load(){ return this.http.get('http://localhost:8080/borrow'); diff --git a/FrontEnd/iprjt/src/app/borrow/borrow.component.html b/FrontEnd/iprjt/src/app/borrow/borrow.component.html index aff535a9..48d5120b 100644 --- a/FrontEnd/iprjt/src/app/borrow/borrow.component.html +++ b/FrontEnd/iprjt/src/app/borrow/borrow.component.html @@ -14,7 +14,9 @@

Borrow Details

-
+
          + +
diff --git a/FrontEnd/iprjt/src/app/borrow/borrow.component.ts b/FrontEnd/iprjt/src/app/borrow/borrow.component.ts index fde8b397..b6361b8b 100644 --- a/FrontEnd/iprjt/src/app/borrow/borrow.component.ts +++ b/FrontEnd/iprjt/src/app/borrow/borrow.component.ts @@ -36,6 +36,7 @@ export class BorrowComponent implements OnInit { searchData:any sort:string="status"; len: any; + flag:number=0; //borrow_id:any; constructor(private router:Router ,private service:BorrowService,private booksService:BooksService) { @@ -51,7 +52,6 @@ export class BorrowComponent implements OnInit { this.len=result; console.log(result) this.count=this.len.length; - console.log(this.count) //this.data=result; }) @@ -84,96 +84,69 @@ export class BorrowComponent implements OnInit { this.sort=a; this.page=this.page; this.tableSize; - this.ngOnInit(); - + this.ngOnInit(); + // this.getFilter(); } getFilter() { console.log(this.ObjSampleForm) - // this.page=1 - + // this.page=1 + this.flag=1; + this.service.LoadByIssueDate(this.ObjSampleForm.controls['date1'].value,this.ObjSampleForm.controls['date2'].value).subscribe(result=>{ + this.len=result; + console.log(result) + this.count=this.len.length; + }) + + if(this.searchData==null || this.searchData==""){ + this.sort="borrow_id"; this.service.filterBorrowPagination(this.ObjSampleForm.controls['date1'].value,this.ObjSampleForm.controls['date2'].value,this.page,this.tableSize,this.sort).subscribe({ next: (res: any) => { - console.log("infilter") - console.log(res); - console.log("endfilter") - this.len=res; - this.count=this.len.length; - this.data=res; - - }, - error: (error: any) => { - console.log(error); - } - }) - // } - // this.service.Load().subscribe(result=>{ - // this.len=result; - // console.log(result) - // this.count=this.len.length; - // // console.log(this.count) - // //this.data=result; + //console.log("--------") + console.log(res); + this.data=res; + }, + }); - // }) - //this.onTableDataChange(this.page); - - // if(this.searchData==null || this.searchData==""){ - // this.service.borrowPagination(this.page,this.tableSize,this.sort).subscribe((result=>{ - // this.data=result; - // console.log('OnloadPagenation') - // console.log(this.data) - // })); - // } - // else{ - - // this.data=this.searchData - // } - - } - + else{ + this.data=this.searchData + } + } - // LoadBorrow(){ - // // this.service.Load().subscribe((data: any)=>{ - // // this.borrowdata=data; - // // console.log(data);}); - // this.service.Load().subscribe( - // (response) => { - // //this.POSTS = response; - // this.borrowdata=response; - // console.log(response); - // }, - // (error) => { - // console.log(error); - // } - // ); - // } + clearFilter(){ + this.flag=0; + window.location.reload(); + } + onTableDataChange(event: any) { - console.log(event) + console.log(event) + if(this.flag==0){ + console.log('flag=',this.flag) this.service.borrowPagination(event,this.tableSize,this.sort).subscribe((result=>{ this.data=result; console.log('sorted') }), ); + } + else if(this.flag==1){ + console.log('flag=',this.flag) + this.service.filterBorrowPagination(this.ObjSampleForm.controls['date1'].value,this.ObjSampleForm.controls['date2'].value,this.page,this.tableSize,this.sort).subscribe({ + next: (res: any) => { + console.log("--------") + console.log(res); + this.data=res; + }, + }); + } } - // onTableSizeChange(event: any): void { - // this.tableSize = event.target.value; - // this.page = 1; - // this.LoadBorrow(); - // } - - - - - - - - + ///////////////////////////////////////////////- C R U D -//////////////////////////////////////////////////// + home() { this.router.navigate(['/body'])