package com.ShelfSpace.ShelfSpace.rest.model.controllers; import java.awt.print.Book; import java.time.LocalDateTime; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ShelfSpace.ShelfSpace.rest.model.IssuedBooks; import com.ShelfSpace.ShelfSpace.rest.model.User; import com.ShelfSpace.ShelfSpace.rest.model.repository.IssuedBooksRepository; import com.ShelfSpace.ShelfSpace.rest.model.repository.UserDetailsRepository; @RestController @RequestMapping("/api/user") public class RestApplication { private final UserDetailsRepository detailsRepository; private final IssuedBooksRepository booksRepository; @Autowired public RestApplication(UserDetailsRepository detailsRepository , IssuedBooksRepository booksRepository) { this.detailsRepository = detailsRepository; this.booksRepository = booksRepository; } @GetMapping("/getAllUsers") public Iterable getAllBooks() { IssuedBooks user = new IssuedBooks(); Long user2 = user.getUser().getRoll_no(); if (user2==null) { System.out.println("its null"); } System.out.println(user.getUser().getRoll_no()); return detailsRepository.findAll(); } @PostMapping("/addUser") public User addUser(@RequestBody User user) { for(IssuedBooks books : user.getIssuedBooks()) { books.setIssueDate(LocalDateTime.now()); } return detailsRepository.save(user); } @PostMapping("/addBook") public void addBook(@RequestBody IssuedBooks detailsPojo) { System.out.println(detailsPojo.getUser().getRoll_no()); booksRepository.save(detailsPojo); } }