New search for members + contacts on list + csv export
This commit is contained in:
parent
d8662a32d1
commit
04bd096019
5 changed files with 133 additions and 271 deletions
|
|
@ -45,15 +45,7 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
|
|||
|
||||
// SQL qeury for results
|
||||
sqlQuery := `--sql
|
||||
SELECT people.id,
|
||||
people.is_member,
|
||||
people.is_contact,
|
||||
people.first_name,
|
||||
people.last_name,
|
||||
people.address1,
|
||||
people.postal_code,
|
||||
people.city,
|
||||
people.section_id,
|
||||
SELECT people.*,
|
||||
sections.name AS Section__name
|
||||
FROM people
|
||||
INNER JOIN sections
|
||||
|
|
@ -328,6 +320,16 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
|
|||
params.PageNumber,
|
||||
)
|
||||
|
||||
var sqlPagination string
|
||||
if params.PageSize > 0 {
|
||||
sqlPagination = `--sql
|
||||
LIMIT @pagination_limit
|
||||
OFFSET @pagination_offset
|
||||
`
|
||||
sqlParams = append(sqlParams, sql.Named("pagination_limit", results.Pagination.PageSize))
|
||||
sqlParams = append(sqlParams, sql.Named("pagination_offset", results.Pagination.Offset))
|
||||
}
|
||||
|
||||
// Build and run paginated result query
|
||||
sqlQuery = fmt.Sprintf(`--sql
|
||||
%s
|
||||
|
|
@ -335,12 +337,8 @@ func PeopleSearch(params PeopleSearchParams) (PeopleSearchResults, error) {
|
|||
%s
|
||||
GROUP BY people.id
|
||||
ORDER BY CONCAT(people.last_name, people.first_name) COLLATE NOCASE ASC
|
||||
LIMIT @pagination_limit
|
||||
OFFSET @pagination_offset
|
||||
`, sqlQuery, sqlFieldJoins, sqlFilters)
|
||||
|
||||
sqlParams = append(sqlParams, sql.Named("pagination_limit", results.Pagination.PageSize))
|
||||
sqlParams = append(sqlParams, sql.Named("pagination_offset", results.Pagination.Offset))
|
||||
%s
|
||||
`, sqlQuery, sqlFieldJoins, sqlFilters, sqlPagination)
|
||||
|
||||
sqlResult := db.Raw(sqlQuery, sqlParams...).Scan(&results.Results)
|
||||
if sqlResult.Error != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue