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
@@ -1,8 +1,11 @@
package com.innovature.Library.controller;

import java.io.IOException;
import java.util.Collection;
import java.util.List;

import javax.validation.Valid;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -20,13 +23,15 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.innovature.Library.entity.Books;
import com.innovature.Library.form.BooksForm;
import com.innovature.Library.repository.BooksRepository;
import com.innovature.Library.service.BooksService;
import com.innovature.Library.util.FileUtil;
import com.innovature.Library.view.BooksDetailView;


@RestController
@RequestMapping("/books")
public class BooksController {
Expand All @@ -37,6 +42,8 @@ public class BooksController {
@Autowired
private BooksRepository booksRepository;



@PostMapping
public BooksDetailView add(@Valid @RequestBody BooksForm form) {
return service.add(form);
Expand All @@ -53,6 +60,7 @@ public Collection<Books> listByCategory(
{
return service.listByCategory(categoryId);
}


@GetMapping("/{booksId}")
public BooksDetailView list(
Expand All @@ -62,6 +70,7 @@ public BooksDetailView list(
return service.list(booksId);
}


@DeleteMapping("/{booksId}")
public void deletes(
@PathVariable("booksId") Integer booksId) {
Expand All @@ -76,6 +85,8 @@ public BooksDetailView update(
return service.updates(booksId, form);
}



@GetMapping("admin/pagenated/")
public ResponseEntity<Page<Books>>getAllBooks(
@RequestParam(defaultValue = "1") Integer pageNo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
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;
Expand Down Expand Up @@ -64,8 +69,27 @@ public Collection<Borrow> list() {
return new ResponseEntity<Page<Borrow>>(list,new HttpHeaders(),
HttpStatus.OK);



}

@GetMapping("/admin/statusFilter/")
public ResponseEntity<Page<Borrow>>getAllBorrowByStatus(
@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);



}



//BORROW @ADMIN //pagenated borrow list at admin VIEW borrow single api
@GetMapping("/admin/pagenated/")
Expand Down Expand Up @@ -99,8 +123,13 @@ public Collection<Borrow> list() {

}






//load results of issuedate filter at User BorrowHistory
@GetMapping("/user/loadByIssueDate/{date1}/{date2}")
@GetMapping("user/loadByIssueDate/{date1}/{date2}")
public ResponseEntity<List<Borrow>> loadByIssueDateUser(
@PathVariable("date1") Date date1,
@PathVariable("date2") Date date2)
Expand All @@ -124,6 +153,11 @@ public ResponseEntity<List<Borrow>> loadByIssueDateUser(
HttpStatus.OK);

}





@PostMapping
public BorrowDetailView add(@Valid @RequestBody BorrowForm form) {
return bService.add(form);
Expand All @@ -143,13 +177,28 @@ public Collection<Borrow> listUserNotification(Principal p) {
return bService.listNotification();
}



@GetMapping("user/due")
public Collection<Borrow> listDue() {
return bService.listDue();
}


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

}


@GetMapping("admin/fine")
public Collection<Borrow> listfine() {
return bService.fine();
Expand Down Expand Up @@ -222,7 +271,7 @@ public BorrowDetailView undo(




//chart
@GetMapping("/admin/chart")
public rentChartView getchart(){
rentChartView test =borrowServices.getChart();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.innovature.Library.controller;


import java.util.Random;

import java.time.LocalTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -11,21 +14,17 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import com.innovature.Library.form.EmailForm;
import com.innovature.Library.form.OtpForm;
import com.innovature.Library.repository.EmailRepository;
import com.innovature.Library.service.BorrowService;
import com.innovature.Library.service.EmailService;



import com.innovature.Library.entity.Email;
import com.innovature.Library.entity.User;
import com.innovature.Library.repository.UserRepository;


// tgsrhyrsrthr
@RestController
@RequestMapping("/email")
public class EmailController {
Expand Down Expand Up @@ -58,43 +57,138 @@ public String sendMail(@PathVariable("userId") Integer userId) {


@PostMapping("/emailsentotp")
public ResponseEntity<?>sendOtpEmail(@RequestBody EmailForm form){
public ResponseEntity sendOtpEmail(@RequestBody EmailForm form){
String emailid=form.getSentto();

if("".equals(emailid) ){

return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body("NULL VALUE EXCEPTION-");
}
else{
User user=userRepository.findByEmailId(form.getSentto());
if(user!=null){
emailRepository.deleteAll();

Random random = new Random();
int otp = 100000 + random.nextInt(900000);
Email otp2= new Email();
otp2.setOtp(otp);
otp2.setEmail(form.getSentto());
otp2.setEmail(form.getSentto());

LocalTime myObj = LocalTime.now();
LocalTime exp=myObj;
otp2.setExpiry(exp);

emailRepository.save(otp2);
var email=form.getSentto();
Email email2= emailRepository.findByEmail(email);

if(email2!=null){
email2.setOtp(otp);
email2.setExpiry(exp);
emailRepository.save(email2);
}
else
emailRepository.save(otp2);

boolean result = this.emailService.sendEmail("OTP Verification","Your OTP to change your password is \t"+ otp +"\tuse it to create a new password.", form.getSentto());
// "OTP Verification", "Your OTP to change your password is "+"otp"+"use it to create a new password."
if(result){
return new ResponseEntity(null,HttpStatus.ACCEPTED);
}
else{
return new ResponseEntity(null,HttpStatus.BAD_REQUEST);
return new ResponseEntity(null,HttpStatus.EXPECTATION_FAILED);
}
}
else{
return new ResponseEntity(null,HttpStatus.NOT_ACCEPTABLE);
return new ResponseEntity(null,HttpStatus.BAD_REQUEST);

}

}


}


@PostMapping("verify")
public ResponseEntity add(@RequestBody OtpForm form){
var otp=form.getOtp();
if(otp==null){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("NULL VALUE EXCEPTION");
}
else{

ResponseEntity result = emailService.add(form);

@PostMapping("verify")
public boolean add(@RequestBody OtpForm form){
if(result.getStatusCodeValue()==202){
return new ResponseEntity(HttpStatus.ACCEPTED);

}
else if(result.getStatusCodeValue()==504){
return ResponseEntity.status(HttpStatus.GATEWAY_TIMEOUT).body("OTP EXPIRED");
}

else
return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body("OTP VERIFICATION FAILED");
}
}


// @PostMapping("verify")
// public ResponseEntity add(@RequestBody OtpForm form){
// var otp=form.getOtp();
// if(otp==null){
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("NULL VALUE EXCEPTION");
// }
// else{

return emailService.add(form);
// boolean result = emailService.add(form);
// if(result)
// {
// return new ResponseEntity(null,HttpStatus.ACCEPTED);
// // return new ResponseEntity.status(HttpStatus.ACCEPTED).body("OTP VERIFICATION SUCCESS");
// }
// else
// {
// // return new ResponseEntity(null,HttpStatus.BAD_REQUEST);

// return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body("OTP VERIFICATION FAILED");
// }
// }
// }



@PostMapping("verifyPassword")
public ResponseEntity addPassword(@RequestBody OtpForm form){

var psd=form.getNewPassword();
var npsd=form.getCnewPassword();

if(psd==null || npsd==null){
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("NULL VALUE EXCEPTION");
}
else if(!psd.equals(npsd) ){
return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body("PASSWORD MISSMATCH");
}
else{

boolean result = emailService.addPassword(form);
if(result)
{
return new ResponseEntity(null,HttpStatus.ACCEPTED);
}
else
{
// return new ResponseEntity(null,HttpStatus.BAD_REQUEST);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("PASSWORD CHANGE FAILED");
}
}






}


Expand Down
Loading