Commit 3236f1d7 authored by roxane.carraux's avatar roxane.carraux
Browse files

add pagination

parent fbcd93ca
Loading
Loading
Loading
Loading
+15 −16
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo.model.HelpProposition;
@@ -25,7 +23,6 @@ import com.example.demo.model.User;
import com.example.demo.repository.HelpPropositionRepository;
import com.example.demo.service.IUserService;
import com.example.demo.validator.HelpPropositionValidator;
import com.example.demo.validator.UserRegisterValidator;

@Controller
public class HelpPropositionController {
@@ -39,11 +36,15 @@ public class HelpPropositionController {
    @Autowired
    private HelpPropositionValidator helpPropositionValidator;
    

    /**
     * Source : https://attacomsian.com/blog/spring-boot-thymeleaf-pagination 
     */
    @GetMapping("/allHelpProposition")
    public String getAll(HttpServletRequest request, Model model) {
     
            int page = 0; //default page number is 0 (yes it is weird)
            int size = 3; //default page size is 10
        int page = 0; 
        int size = 3; 
        
        if (request.getParameter("page") != null && !request.getParameter("page").isEmpty()) {
            page = Integer.parseInt(request.getParameter("page")) - 1;
@@ -54,9 +55,7 @@ public class HelpPropositionController {
        }
        
        model.addAttribute("helpPropositions", helpPropositionRepository.findAll(PageRequest.of(page, size)));
        
        return "allHelpProposition";  

    }

    @GetMapping("/formHelpProposition")
+7 −7
Original line number Diff line number Diff line
@@ -36,12 +36,13 @@ public class HelpRequestController {
    @Autowired
    private HelpRequestValidator helpRequestValidator;
    
    
    /**
     * Source : https://attacomsian.com/blog/spring-boot-thymeleaf-pagination 
     */
    @GetMapping("/allHelpRequest")
    public String getAll(HttpServletRequest request, Model model) {
        int page = 0; //default page number is 0 (yes it is weird)
        int size = 3; //default page size is 10

        int page = 0; 
        int size = 3;
   
        if (request.getParameter("page") != null && !request.getParameter("page").isEmpty()) {
            page = Integer.parseInt(request.getParameter("page")) - 1;
@@ -50,9 +51,8 @@ public class HelpRequestController {
        if (request.getParameter("size") != null && !request.getParameter("size").isEmpty()) {
            size = Integer.parseInt(request.getParameter("size"));
        }
        model.addAttribute("helpRequests", helpRequestRepository.findAll(PageRequest.of(page, size)));

        
        model.addAttribute("helpRequests", helpRequestRepository.findAll(PageRequest.of(page, size)));
        return "allHelpRequest";
    }
    
+2 −0
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ public class UserController {
    @RequestMapping(value = { "/login" }, method = RequestMethod.GET)
    public ModelAndView login() {
        


        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("login"); // resources/template/login.html
        return modelAndView;
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
    <body>
        <header th:insert="fragments/nav.html :: nav"> </header>
        <div class="container">
            <h1 class="teal-text text-darken-4">Your help Proposition</h1>
            <h1 class="teal-text text-darken-4">Your help Propositions</h1>
            <div th:each="help: ${helpPropositions}">
                <div class="row">
                    <div class="col s12 m6">
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
    <body>
        <header th:insert="fragments/nav.html :: nav"> </header>
        <div class="container">
            <h1 class="teal-text text-darken-4">Your help request</h1>
            <h1 class="teal-text text-darken-4">Your help requests</h1>
            <div th:each="help: ${helpRequests}">
                <div class="row">
                    <div class="col s12 m6">
Loading