BandStormTeam / BandStormProject

Bandstorm is a social network for music lovers
https://m2dl-bandstorm.herokuapp.com/
GNU General Public License v2.0
2 stars 1 forks source link

Sprint02/5 recherche #52

Closed steve-anthony closed 9 years ago

steve-anthony commented 9 years ago

Recherche des utilisateurs Recherche des groupes

aroquemaurel commented 9 years ago

Ton build ne passe pas…

No signature of method: bandstorm.service.BandService.getAllBandsByKeywords() is applicable for argument types: () values: []

Possible solutions: getAllBandsByKeywords(java.lang.String, java.lang.Integer, java.lang.Integer)

    at bandstorm.service.BandServiceSpec.test getAllBandsByKeywords method(BandServiceSpec.groovy:15)

aroquemaurel commented 9 years ago

Ajouté dans le DaoService

 /**
     * Get all users corresponding to keywords
     * @param keywords : a string input for the research
     * @param maxItemsForSearch : max item for pagination
     * @param page : value for the pagination
     * @return a Map containing the list of Users and the total number of result
     */
    Map getAllUsersByKeywords(String keywords,Integer maxItemsForSearch,Integer page){

        Integer max = maxItemsForSearch*page+maxItemsForSearch
        Integer offset =(maxItemsForSearch*page)

        def resultsList = User.createCriteria().list {
            or {
                keywords.split(" ").each { keyword ->
                    ilike("username", "%" + keyword + "%")
                    ilike("firstName", "%" + keyword + "%")
                    ilike("lastName", "%" + keyword + "%")
                }
            }
            maxResults(max)
            firstResult(offset)
        }

        def resultsCount = User.createCriteria().count() {
            or {
                keywords.split(" ").each { keyword ->
                    ilike("username", "%" + keyword + "%")
                    ilike("firstName", "%" + keyword + "%")
                    ilike("lastName", "%" + keyword + "%")
                }
            }
        }

        def result = new HashMap()
        result.totalOfUser = resultsCount.toInteger()
        result.userList = resultsList.toList()

        return result;
    }