app/controllers/TravellersController.java
@Security.Authenticated(SecureSession.class)
    public CompletionStage<Result> search(Http.Request request, Integer offset){
        Integer profId = SessionController.getCurrentUserId(request);
        return profileRepository.findById(profId).thenApplyAsync(profile -> {
            if (profile.isPresent()) {
                Form<PartnerFormData> searchForm = form.bindFromRequest(request);
                PartnerFormData formData = searchForm.get();
                Date lowerDate;
                Date upperDate;

                // Show error if no search filters are filled, prevent needless search operation
                if (formData.searchAgeRange == null && formData.searchGender.equals("") &&
                        formData.searchNationality.equals("") && formData.searchTravellerTypes.equals("")) {
                    return redirect("/travellers/0").flashing("error", "Please enter at least one search filter");
                }

                if (formData.searchAgeRange == null) {
                    formData.setSearchAgeRange(0);
                }
                switch (formData.searchAgeRange) {
                    case 1:
                        lowerDate = getDateFromAge(0);
                        upperDate = getDateFromAge(18);
                        break;
                    case 2:
                        lowerDate = getDateFromAge(18);
                        upperDate = getDateFromAge(25);
                        break;
                    case 3:
                        lowerDate = getDateFromAge(25);
                        upperDate = getDateFromAge(35);
                        break;
                    case 4:
                        lowerDate = getDateFromAge(35);
                        upperDate = getDateFromAge(50);
                        break;
                    case 5:
                        lowerDate = getDateFromAge(50);
                        upperDate = getDateFromAge(65);
                        break;
                    case 6:
                        lowerDate = getDateFromAge(65);
                        upperDate = getDateFromAge(500);
                        break;
                    default:
                        lowerDate = getDateFromAge(0);
                        upperDate = getDateFromAge(500);
                        break;
                }

                List<Profile> searchedProfiles = profileRepository.searchProfiles(formData.searchTravellerTypes, lowerDate, upperDate, formData.searchGender, formData.searchNationality, offset);
                int sizeOfSearchResults = profileRepository.getNumSearchProfiles(formData.searchTravellerTypes, lowerDate, upperDate, formData.searchGender, formData.searchNationality);

                PaginationHelper paginationHelper = new PaginationHelper(offset, offset, offset, true, true, sizeOfSearchResults);
                paginationHelper.alterNext(12);
                paginationHelper.alterPrevious(12);
                paginationHelper.checkButtonsEnabled();

                return ok(travellers.render(form, searchedProfiles, photoList, profile.get(), Country.getInstance().getAllCountries(), formData, paginationHelper, request, messagesApi.preferred(request)));
            } else {
                return redirect("/travellers");
            }
        });
    }
/**
     * Function to search travellers n gender nationality, age and traveller type fields, calls search functions for
     * each field
     * @param request http request
     * @param offset, the index at which to get the first traveller (ie 0 = start of first page)
     * @return renders traveller view with queried list of travellers
     */
Function to search travellers n gender nationality, age and traveller type fields, calls search functions for
each field
@param request http request
@param offset, the index at which to get the first traveller
@return renders traveller view with queried list of travellers
Function to search travellers n gender nationality age and traveller type fields calls search functions for each field @param request http request @param offset the index at which to get the first traveller @return renders traveller view with queried list of travellers
@Security.Authenticated(SecureSession.class)
    public CompletionStage<Result> search(Http.Request request, Integer offset){
        Integer profId = SessionController.getCurrentUserId(request);
        return profileRepository.findById(profId).thenApplyAsync(profile -> {
            if (profile.isPresent()) {
                Form<PartnerFormData> searchForm = form.bindFromRequest(request);
                PartnerFormData formData = searchForm.get();
                Date lowerDate;
                Date upperDate;
                if (formData.searchAgeRange == null && formData.searchGender.equals("") &&
                        formData.searchNationality.equals("") && formData.searchTravellerTypes.equals("")) {
                    return redirect("/travellers/0").flashing("error", "Please enter at least one search filter");
                }
                if (formData.searchAgeRange == null) {
                    formData.setSearchAgeRange(0);
                }
                switch (formData.searchAgeRange) {
                    case 1:
                        lowerDate = getDateFromAge(0);
                        upperDate = getDateFromAge(18);
                        break;
                    case 2:
                        lowerDate = getDateFromAge(18);
                        upperDate = getDateFromAge(25);
                        break;
                    case 3:
                        lowerDate = getDateFromAge(25);
                        upperDate = getDateFromAge(35);
                        break;
                    case 4:
                        lowerDate = getDateFromAge(35);
                        upperDate = getDateFromAge(50);
                        break;
                    case 5:
                        lowerDate = getDateFromAge(50);
                        upperDate = getDateFromAge(65);
                        break;
                    case 6:
                        lowerDate = getDateFromAge(65);
                        upperDate = getDateFromAge(500);
                        break;
                    default:
                        lowerDate = getDateFromAge(0);
                        upperDate = getDateFromAge(500);
                        break;
                }
                List<Profile> searchedProfiles = profileRepository.searchProfiles(formData.searchTravellerTypes, lowerDate, upperDate, formData.searchGender, formData.searchNationality, offset);
                int sizeOfSearchResults = profileRepository.getNumSearchProfiles(formData.searchTravellerTypes, lowerDate, upperDate, formData.searchGender, formData.searchNationality);
                PaginationHelper paginationHelper = new PaginationHelper(offset, offset, offset, true, true, sizeOfSearchResults);
                paginationHelper.alterNext(12);
                paginationHelper.alterPrevious(12);
                paginationHelper.checkButtonsEnabled();
                return ok(travellers.render(form, searchedProfiles, photoList, profile.get(), Country.getInstance().getAllCountries(), formData, paginationHelper, request, messagesApi.preferred(request)));
            } else {
                return redirect("/travellers");
            }
        });
    }
@ Security . Authenticated ( SecureSession . class ) public CompletionStage < Result > search ( Http . Request request , Integer offset ) { Integer profId = SessionController . getCurrentUserId ( request ) ; return profileRepository . findById ( profId ) . thenApplyAsync ( profile -> { if ( profile . isPresent ( ) ) { Form < PartnerFormData > searchForm = form . bindFromRequest ( request ) ; PartnerFormData formData = searchForm . get ( ) ; Date lowerDate ; Date upperDate ; if ( formData . searchAgeRange == null && formData . searchGender . equals ( "" ) && formData . searchNationality . equals ( "" ) && formData . searchTravellerTypes . equals ( "" ) ) { return redirect ( "/travellers/0" ) . flashing ( "error" , "Please enter at least one search filter" ) ; } if ( formData . searchAgeRange == null ) { formData . setSearchAgeRange ( 0 ) ; } switch ( formData . searchAgeRange ) { case 1 : lowerDate = getDateFromAge ( 0 ) ; upperDate = getDateFromAge ( 18 ) ; break ; case 2 : lowerDate = getDateFromAge ( 18 ) ; upperDate = getDateFromAge ( 25 ) ; break ; case 3 : lowerDate = getDateFromAge ( 25 ) ; upperDate = getDateFromAge ( 35 ) ; break ; case 4 : lowerDate = getDateFromAge ( 35 ) ; upperDate = getDateFromAge ( 50 ) ; break ; case 5 : lowerDate = getDateFromAge ( 50 ) ; upperDate = getDateFromAge ( 65 ) ; break ; case 6 : lowerDate = getDateFromAge ( 65 ) ; upperDate = getDateFromAge ( 500 ) ; break ; default : lowerDate = getDateFromAge ( 0 ) ; upperDate = getDateFromAge ( 500 ) ; break ; } List < Profile > searchedProfiles = profileRepository . searchProfiles ( formData . searchTravellerTypes , lowerDate , upperDate , formData . searchGender , formData . searchNationality , offset ) ; int sizeOfSearchResults = profileRepository . getNumSearchProfiles ( formData . searchTravellerTypes , lowerDate , upperDate , formData . searchGender , formData . searchNationality ) ; PaginationHelper paginationHelper = new PaginationHelper ( offset , offset , offset , true , true , sizeOfSearchResults ) ; paginationHelper . alterNext ( 12 ) ; paginationHelper . alterPrevious ( 12 ) ; paginationHelper . checkButtonsEnabled ( ) ; return ok ( travellers . render ( form , searchedProfiles , photoList , profile . get ( ) , Country . getInstance ( ) . getAllCountries ( ) , formData , paginationHelper , request , messagesApi . preferred ( request ) ) ) ; } else { return redirect ( "/travellers" ) ; } } ) ; }
Function to search travellers n gender nationality, age and traveller type fields, calls search functions for
 each field
 @param request http request
 @param offset, the index at which to get the first traveller (ie 0 = start of first page)
 @return renders traveller view with queried list of travellers
Function to search travellers n gender nationality age and traveller type fields calls search functions for each field @param request http request @param offset the index at which to get the first traveller ( ie 0 = start of first page ) @return renders traveller view with queried list of travellers
// Show error if no search filters are filled, prevent needless search operation